From bc773296985dfdfc0bf2bc212af04e8712a03d7d Mon Sep 17 00:00:00 2001 From: Stefan Budeanu Date: Mon, 7 Mar 2022 18:12:45 -0500 Subject: [PATCH 1/4] Add new test for STS restart --- test/fixtures/hello-cloud/unmanaged-pod.yml | 18 ++++++++++++++++++ test/integration/restart_task_test.rb | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/hello-cloud/unmanaged-pod.yml diff --git a/test/fixtures/hello-cloud/unmanaged-pod.yml b/test/fixtures/hello-cloud/unmanaged-pod.yml new file mode 100644 index 000000000..8ea1dfe9e --- /dev/null +++ b/test/fixtures/hello-cloud/unmanaged-pod.yml @@ -0,0 +1,18 @@ +apiVersion: v1 +kind: Pod +metadata: + name: unmanaged-pod-0 + annotations: + krane.shopify.io/timeout-override: 60s + labels: + type: unmanaged-pod + name: unmanaged-pod-0 + app: hello-cloud +spec: + activeDeadlineSeconds: 60 + restartPolicy: Never + containers: + - name: hello-cloud + image: busybox + imagePullPolicy: IfNotPresent + command: ["sh", "-c", "echo 'Hello from the command runner!' && test 1 -eq 1"] diff --git a/test/integration/restart_task_test.rb b/test/integration/restart_task_test.rb index a6c7a89b2..5894a5597 100644 --- a/test/integration/restart_task_test.rb +++ b/test/integration/restart_task_test.rb @@ -36,7 +36,7 @@ def test_restart_by_annotation end def test_restart_statefulset_on_delete_restarts_child_pods - result = deploy_fixtures("hello-cloud", subset: "stateful_set.yml") do |fixtures| + result = deploy_fixtures("hello-cloud", subset: ["unmanaged-pod.yml", "stateful_set.yml"]) do |fixtures| statefulset = fixtures["stateful_set.yml"]["StatefulSet"].first statefulset["spec"]["updateStrategy"] = { "type" => "OnDelete" } end From c8dc4cc7d55dc0b21ef9e05feff8a18913a4cee1 Mon Sep 17 00:00:00 2001 From: Stefan Budeanu Date: Mon, 7 Mar 2022 19:35:35 -0500 Subject: [PATCH 2/4] Prevent crash on nil value --- lib/krane/restart_task.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/krane/restart_task.rb b/lib/krane/restart_task.rb index 780bcef94..d729ae12b 100644 --- a/lib/krane/restart_task.rb +++ b/lib/krane/restart_task.rb @@ -213,7 +213,7 @@ def patch_daemonset_with_restart(record) def delete_statefulset_pods(record) pods = kubeclient.get_pods(namespace: record.metadata.namespace) pods.select! do |pod| - pod.metadata.ownerReferences.find { |ref| ref.uid == record.metadata.uid } + pod.metadata&.ownerReferences&.find { |ref| ref.uid == record.metadata.uid } end pods.each { |pod| kubeclient.delete_pod(pod.metadata.name, pod.metadata.namespace) } end From 6e8bf2b887c429a43a66723350d51c29a5ec10a6 Mon Sep 17 00:00:00 2001 From: Stefan Budeanu Date: Mon, 7 Mar 2022 19:36:26 -0500 Subject: [PATCH 3/4] Adjust logic for OnDelete STS Readiness --- lib/krane/kubernetes_resource/stateful_set.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/krane/kubernetes_resource/stateful_set.rb b/lib/krane/kubernetes_resource/stateful_set.rb index 95d40336b..26a8aa9ef 100644 --- a/lib/krane/kubernetes_resource/stateful_set.rb +++ b/lib/krane/kubernetes_resource/stateful_set.rb @@ -19,6 +19,9 @@ def status end def deploy_succeeded? + success = observed_generation == current_generation && + desired_replicas == status_data['readyReplicas'].to_i && + status_data['currentRevision'] == status_data['updateRevision'] if update_strategy == ONDELETE # Gem cannot monitor update since it doesn't occur until delete unless @success_assumption_warning_shown @@ -27,11 +30,10 @@ def deploy_succeeded? "Consider switching to rollingUpdate.") @success_assumption_warning_shown = true end + else + success &= desired_replicas == status_data['currentReplicas'].to_i end - observed_generation == current_generation && - status_data['currentRevision'] == status_data['updateRevision'] && - desired_replicas == status_data['readyReplicas'].to_i && - desired_replicas == status_data['currentReplicas'].to_i + success end def deploy_failed? From 4fb61d8282e8c1ee62e9a4b05279ab59823f4da8 Mon Sep 17 00:00:00 2001 From: Stefan Budeanu Date: Mon, 7 Mar 2022 21:32:09 -0500 Subject: [PATCH 4/4] use existing test --- test/fixtures/hello-cloud/unmanaged-pod.yml | 18 ------------------ test/integration/restart_task_test.rb | 3 ++- 2 files changed, 2 insertions(+), 19 deletions(-) delete mode 100644 test/fixtures/hello-cloud/unmanaged-pod.yml diff --git a/test/fixtures/hello-cloud/unmanaged-pod.yml b/test/fixtures/hello-cloud/unmanaged-pod.yml deleted file mode 100644 index 8ea1dfe9e..000000000 --- a/test/fixtures/hello-cloud/unmanaged-pod.yml +++ /dev/null @@ -1,18 +0,0 @@ -apiVersion: v1 -kind: Pod -metadata: - name: unmanaged-pod-0 - annotations: - krane.shopify.io/timeout-override: 60s - labels: - type: unmanaged-pod - name: unmanaged-pod-0 - app: hello-cloud -spec: - activeDeadlineSeconds: 60 - restartPolicy: Never - containers: - - name: hello-cloud - image: busybox - imagePullPolicy: IfNotPresent - command: ["sh", "-c", "echo 'Hello from the command runner!' && test 1 -eq 1"] diff --git a/test/integration/restart_task_test.rb b/test/integration/restart_task_test.rb index 5894a5597..d13a78193 100644 --- a/test/integration/restart_task_test.rb +++ b/test/integration/restart_task_test.rb @@ -36,7 +36,8 @@ def test_restart_by_annotation end def test_restart_statefulset_on_delete_restarts_child_pods - result = deploy_fixtures("hello-cloud", subset: ["unmanaged-pod.yml", "stateful_set.yml"]) do |fixtures| + result = deploy_fixtures("hello-cloud", subset: ["configmap-data.yml", "unmanaged-pod-1.yml.erb", + "stateful_set.yml"], render_erb: true) do |fixtures| statefulset = fixtures["stateful_set.yml"]["StatefulSet"].first statefulset["spec"]["updateStrategy"] = { "type" => "OnDelete" } end