From 45331cb4db8abf2d746d99c41e1e2c0fd9ffffc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Artur=20Za=C5=82=C4=99ski?= Date: Tue, 9 Jul 2024 00:44:13 +0200 Subject: [PATCH] Add integration test for case when desired number of Pods in DaemonSet is 0 --- .../targets/k8s_waiter/defaults/main.yml | 3 ++ .../targets/k8s_waiter/tasks/main.yml | 42 +++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/tests/integration/targets/k8s_waiter/defaults/main.yml b/tests/integration/targets/k8s_waiter/defaults/main.yml index 04c873ce36..002c00238c 100644 --- a/tests/integration/targets/k8s_waiter/defaults/main.yml +++ b/tests/integration/targets/k8s_waiter/defaults/main.yml @@ -5,6 +5,7 @@ k8s_pod_metadata: k8s_pod_spec: serviceAccount: "{{ k8s_pod_service_account }}" + nodeSelector: "{{ k8s_pod_node_selector }}" containers: - image: "{{ k8s_pod_image }}" imagePullPolicy: Always @@ -33,6 +34,8 @@ k8s_pod_ports: [] k8s_pod_env: [] +k8s_pod_node_selector: {} + k8s_pod_template: metadata: "{{ k8s_pod_metadata }}" spec: "{{ k8s_pod_spec }}" diff --git a/tests/integration/targets/k8s_waiter/tasks/main.yml b/tests/integration/targets/k8s_waiter/tasks/main.yml index 1cb7e4c405..3bfb668bb6 100644 --- a/tests/integration/targets/k8s_waiter/tasks/main.yml +++ b/tests/integration/targets/k8s_waiter/tasks/main.yml @@ -127,6 +127,48 @@ - ds.result.status.currentNumberScheduled == ds.result.status.desiredNumberScheduled - updated_ds_pods.resources[0].spec.containers[0].image.endswith(":3") + - name: Create daemonset with nodeSelector and not existing label + k8s: + definition: + apiVersion: apps/v1 + kind: DaemonSet + metadata: + name: wait-daemonset-not-existing-label + namespace: "{{ wait_namespace }}" + spec: + selector: + matchLabels: + app: "{{ k8s_pod_name }}" + template: "{{ k8s_pod_template }}" + wait: yes + wait_sleep: 5 + wait_timeout: "{{ k8s_wait_timeout | default(omit) }}" + vars: + k8s_pod_name: wait-daemonset-not-existing-label + k8s_pod_image: gcr.io/kuar-demo/kuard-amd64:1 + k8s_pod_command: + - sleep + - "600" + k8s_pod_node_selector: + nonExisitingLabel: test-not-exiting-label + register: ds_not_existing_label + + - name: Get updated pods + k8s_info: + api_version: v1 + kind: Pod + namespace: "{{ wait_namespace }}" + label_selectors: + - app=wait-daemonset-not-existing-label + register: updated_ds_pods_not_existing_label + + - name: Check that daemonset wait worked (when desired number is 0) + assert: + that: + - ds_not_existing_label.result.status.currentNumberScheduled == ds_not_existing_label.result.status.desiredNumberScheduled + - ds_not_existing_label.result.status.desiredNumberScheduled == 0 + - updated_ds_pods_not_existing_label.resources | length == 0 + - name: Add a statefulset k8s: definition: