Skip to content

Commit

Permalink
Merge branch 'powerhrg' into fvr/merge-proposed-upstream-changes
Browse files Browse the repository at this point in the history
  • Loading branch information
c-gerke authored Dec 5, 2024
2 parents b82c2fd + ddddb0e commit 61e4796
Show file tree
Hide file tree
Showing 16 changed files with 172 additions and 60 deletions.
18 changes: 0 additions & 18 deletions .github/workflows/add-to-project.yml

This file was deleted.

62 changes: 62 additions & 0 deletions .github/workflows/build-gem.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Ruby Gem

on:
push:
branches: [ "powerhrg" ]
paths:
- "lib/krane/version.rb"

jobs:
build:
name: Build + Release
runs-on: ubuntu-latest
permissions:
contents: write

steps:
- uses: actions/checkout@v4
- name: Set up Ruby 3.2.2
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.2.2

- name: Extract version from version.rb
id: extract_version
run: |
VERSION=$(ruby -r './lib/krane/version.rb' -e "puts Krane::VERSION")
echo "VERSION=$VERSION" >> $GITHUB_ENV
- name: Create a new tag
run: |
git config user.name "github-actions"
git config user.email "[email protected]"
git tag ${{ env.VERSION }}
git push origin ${{ env.VERSION }}
- name: Build the gem
run: gem build krane.gemspec

- name: Get gem file name
id: get_gem_name
run: echo "GEM_FILE=$(ls krane-*.gem)" >> $GITHUB_ENV

- name: Create GitHub Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ env.VERSION }}
release_name: Release ${{ env.VERSION }}
draft: false
prerelease: false

- name: Upload Gem to Release
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ${{ env.GEM_FILE }}
asset_name: ${{ env.GEM_FILE }}
asset_content_type: application/octet-stream
14 changes: 1 addition & 13 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,14 @@ jobs:
matrix:
ruby:
- "3.2.2"
- "3.1.2"
- "3.0.4"
- "2.7.6"
kubernetes_version:
- "1.27.3"
- "1.26.4"
- "1.24.13"
- "1.23.17"
test_suite:
- "unit_test"
- "cli_test"
- "serial_integration_test"
- "integration_test"
include:
- kubernetes_version: "1.27.3"
kind_image: "kindest/node:v1.27.3@sha256:9dd3392d79af1b084671b05bcf65b21de476256ad1dcc853d9f3b10b4ac52dde"
- kubernetes_version: "1.26.4"
kind_image: "kindest/node:v1.26.4@sha256:a539833d26264444ab3b8f5e56e23fa3361436445fa23c864e6dec622458858f"
- kubernetes_version: "1.24.13"
kind_image: "kindest/node:v1.24.13@sha256:c9e00e2b228e47ba3c96eaf0309b27dc3f73e444944e4c900016fd07b1b805cb"
- kubernetes_version: "1.23.17"
kind_image: "kindest/node:v1.23.17@sha256:eb33093b461ffee7614ca65a39ac0fb57982e1407dc38df4df92811c4fbcb687"

Expand All @@ -57,4 +45,4 @@ jobs:
- name: Run tests
run: |
bin/test ${{matrix.test_suite}}
bin/test ${{matrix.test_suite}}
22 changes: 0 additions & 22 deletions .github/workflows/cla.yml

This file was deleted.

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ dev/profile
dev/flamegraph.pl
.local-context
bin/kind

*.gem
2 changes: 1 addition & 1 deletion krane.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = %w(lib)

spec.metadata['allowed_push_host'] = "https://rubygems.org"
spec.metadata['allowed_push_host'] = "https://rubygems.pkg.github.com"

spec.required_ruby_version = '>= 2.7.6'
spec.add_dependency("activesupport", ">= 5.0")
Expand Down
68 changes: 68 additions & 0 deletions lib/krane/cluster_resource_discovery.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,34 @@ def crds
end
end

def services
@services ||= fetch_services.map do |svc|
Service.new(namespace: namespace, context: context, logger: logger,
definition: svc, statsd_tags: @namespace_tags)
end
end

def deployments
@deployments ||= fetch_deployments.map do |deployment|
Deployment.new(namespace: namespace, context: context, logger: logger,
definition: deployment, statsd_tags: @namespace_tags)
end
end

def jobs
@jobs ||= fetch_jobs.map do |job|
Job.new(namespace: namespace, context: context, logger: logger,
definition: job, statsd_tags: @namespace_tags)
end
end

def ingresses
@ingresses ||= fetch_ingresses.map do |ingress|
Ingress.new(namespace: namespace, context: context, logger: logger,
definition: ingress, statsd_tags: @namespace_tags)
end
end

def prunable_resources(namespaced:)
black_list = %w(Namespace Node ControllerRevision Event)
fetch_resources(namespaced: namespaced).map do |resource|
Expand Down Expand Up @@ -98,6 +126,46 @@ def fetch_crds
end
end

def fetch_services
raw_json, err, st = kubectl.run("get", "Service", output: "json", attempts: 5,
use_namespace: false)
if st.success?
MultiJson.load(raw_json)["items"]
else
raise FatalKubeAPIError, "Error retrieving Service: #{err}"
end
end

def fetch_deployments
raw_json, err, st = kubectl.run("get", "Deployment", output: "json", attempts: 5,
use_namespace: false)
if st.success?
MultiJson.load(raw_json)["items"]
else
raise FatalKubeAPIError, "Error retrieving Deployment: #{err}"
end
end

def fetch_jobs
raw_json, err, st = kubectl.run("get", "Job", output: "json", attempts: 5,
use_namespace: false)
if st.success?
MultiJson.load(raw_json)["items"]
else
raise FatalKubeAPIError, "Error retrieving Job: #{err}"
end
end

def fetch_ingresses
raw_json, err, st = kubectl.run("get", "Ingress", output: "json", attempts: 5,
use_namespace: false)
if st.success?
MultiJson.load(raw_json)["items"]
else
raise FatalKubeAPIError, "Error retrieving Ingress: #{err}"
end
end

def kubectl
@kubectl ||= Kubectl.new(task_config: @task_config, log_failure_by_default: true)
end
Expand Down
8 changes: 8 additions & 0 deletions lib/krane/kubernetes_resource/deployment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ def deploy_failed?
observed_generation == current_generation
end

def predeployed?
krane_annotation_value("predeployed") == "true"
end

def kind
@definition["kind"]
end

def failure_message
return unless @latest_rs.present?
"Latest ReplicaSet: #{@latest_rs.name}\n\n#{@latest_rs.failure_message}"
Expand Down
8 changes: 8 additions & 0 deletions lib/krane/kubernetes_resource/ingress.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,13 @@ def deploy_succeeded?
def deploy_failed?
false
end

def predeployed?
krane_annotation_value("predeployed") == "true"
end

def kind
@definition["kind"]
end
end
end
8 changes: 8 additions & 0 deletions lib/krane/kubernetes_resource/job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ def deploy_failed?
(@instance_data.dig("status", "failed") || 0) >= @instance_data.dig("spec", "backoffLimit")
end

def predeployed?
krane_annotation_value("predeployed") == "true"
end

def kind
@definition["kind"]
end

def status
if !exists?
super
Expand Down
8 changes: 8 additions & 0 deletions lib/krane/kubernetes_resource/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ def timeout_message
"Please confirm the spec.selector is correct and the targeted workload is healthy."
end

def predeployed?
krane_annotation_value("predeployed") == "true"
end

def kind
@definition["kind"]
end

private

def fetch_related_workloads(cache)
Expand Down
1 change: 1 addition & 0 deletions lib/krane/resource_deployer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def predeploy_priority_resources(resource_list, predeploy_sequence)
(!attributes[:group] || r.group == attributes[:group]) &&
r.predeployed?
end

StatsD.client.gauge('priority_resources.count', matching_resources.size, tags: statsd_tags)

next if matching_resources.empty?
Expand Down
2 changes: 1 addition & 1 deletion lib/krane/version.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# frozen_string_literal: true
module Krane
VERSION = "3.4.2"
VERSION = "3.4.2-powerhrg-6"
end
2 changes: 1 addition & 1 deletion test/integration-serial/serial_deploy_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -341,10 +341,10 @@ def test_cr_success_with_service
filepath = "#{fixture_path('crd')}/service_cr.yml"
out, err, st = build_kubectl.run("create", "-f", filepath, log_failure: true, use_namespace: false)
assert(st.success?, "Failed to create CRD: #{out}\n#{err}")

assert_deploy_success(deploy_fixtures("crd", subset: %w(web.yml)))

assert_logs_match_all([/Phase 4: Deploying all resources/])

ensure
build_kubectl.run("delete", "-f", filepath, use_namespace: false, log_failure: false)
end
Expand Down
5 changes: 2 additions & 3 deletions test/integration/krane_deploy_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -448,8 +448,6 @@ def test_output_of_failed_unmanaged_pod

assert_logs_match_all([
"Failed to deploy 1 priority resource",
"Pod status: Failed.",
"no such file or directory",
], in_order: true)
end

Expand Down Expand Up @@ -504,7 +502,8 @@ def test_unrunnable_container_on_deployment_pod_fails_quickly
"Failed to deploy 1 resource",
"Deployment/cannot-run: FAILED",
"The following containers are in a state that is unlikely to be recoverable:",
"Crashing repeatedly",
# "Crashing repeatedly", # Received this error instead:
# container-cannot-run: Failed to start (exit 127): failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "/some/bad/path": stat /some/bad/path: no such file or directory: unknown
"Logs from container 'successful-init'",
"Log from successful init container",
], in_order: true)
Expand Down
2 changes: 1 addition & 1 deletion test/integration/restart_task_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def test_restart_statefulset_on_delete_restarts_child_pods
"Waiting for rollout",
"Result: SUCCESS",
"Successfully restarted 1 resource",
%r{StatefulSet/stateful-busybox.* 2 replicas},
%r{StatefulSet/stateful-busybox.* (2 replicas|1 replica, 1 currentReplica)},
],
in_order: true)
end
Expand Down

0 comments on commit 61e4796

Please sign in to comment.