ansible-collections / kubernetes.core

The collection includes a variety of Ansible content to help automate the management of applications in Kubernetes and OpenShift clusters, as well as the provisioning and maintenance of clusters themselves.
Other
214 stars 133 forks source link

Fix waiting for daemonset when desired number of pods is 0 #756

Closed azaleski9 closed 2 months ago

azaleski9 commented 3 months ago

Fixes https://github.com/ansible-collections/kubernetes.core/issues/755

SUMMARY

Because we don't have any node with non_exisiting_label (see code below) desired number of Pods will be 0. Kubernetes won't create .status.updatedNumberScheduled field (at least on version v1.27), because we still are not going to create any Pods. So that if .status.updatedNumberScheduled doesn't exist we should assume that number is 0

Code to reproduce:

- name: Create daemonset
  kubernetes.core.k8s:
    state: present
    wait: true
    definition:
      apiVersion: apps/v1
      kind: DaemonSet
      metadata:
        name: my-daemonset
        namespace: default
      spec:
        selector:
          matchLabels:
            app: my-app
        template:
          metadata:
            labels:
              app: my-app
          spec:
            containers:
              - name: my-container
                image: nginx
            nodeSelector:
              non_exisiting_label: 1
ISSUE TYPE
COMPONENT NAME

kubernetes.core.plugins.module_utils.k8s.waiter

ADDITIONAL INFORMATION
TASK [Create daemonset] **********************************************************************************************************************************
changed: [controlplane] => {"changed": true, "duration": 5, "method": "create", "result": {"apiVersion": "apps/v1", "kind": "DaemonSet", "metadata": {"annotations": {"deprecated.daemonset.template.generation": "1"}, "creationTimestamp": "2024-06-28T08:23:41Z", "generation": 1, "managedFields": [{"apiVersion": "apps/v1", "fieldsType": "FieldsV1", "fieldsV1": {"f:metadata": {"f:annotations": {".": {}, "f:deprecated.daemonset.template.generation": {}}}, "f:spec": {"f:revisionHistoryLimit": {}, "f:selector": {}, "f:template": {"f:metadata": {"f:labels": {".": {}, "f:app": {}}}, "f:spec": {"f:containers": {"k:{\"name\":\"my-container\"}": {".": {}, "f:image": {}, "f:imagePullPolicy": {}, "f:name": {}, "f:resources": {}, "f:terminationMessagePath": {}, "f:terminationMessagePolicy": {}}}, "f:dnsPolicy": {}, "f:nodeSelector": {}, "f:restartPolicy": {}, "f:schedulerName": {}, "f:securityContext": {}, "f:terminationGracePeriodSeconds": {}}}, "f:updateStrategy": {"f:rollingUpdate": {".": {}, "f:maxSurge": {}, "f:maxUnavailable": {}}, "f:type": {}}}}, "manager": "OpenAPI-Generator", "operation": "Update", "time": "2024-06-28T08:23:41Z"}, {"apiVersion": "apps/v1", "fieldsType": "FieldsV1", "fieldsV1": {"f:status": {"f:observedGeneration": {}}}, "manager": "kube-controller-manager", "operation": "Update", "subresource": "status", "time": "2024-06-28T08:23:41Z"}], "name": "my-daemonset", "namespace": "default", "resourceVersion": "1088421", "uid": "faafdbf7-4388-4cec-88d5-84657966312d"}, "spec": {"revisionHistoryLimit": 10, "selector": {"matchLabels": {"app": "my-app"}}, "template": {"metadata": {"creationTimestamp": null, "labels": {"app": "my-app"}}, "spec": {"containers": [{"image": "nginx", "imagePullPolicy": "Always", "name": "my-container", "resources": {}, "terminationMessagePath": "/dev/termination-log", "terminationMessagePolicy": "File"}], "dnsPolicy": "ClusterFirst", "nodeSelector": {"non_exisiting_label": "1"}, "restartPolicy": "Always", "schedulerName": "default-scheduler", "securityContext": {}, "terminationGracePeriodSeconds": 30}}, "updateStrategy": {"rollingUpdate": {"maxSurge": 0, "maxUnavailable": 1}, "type": "RollingUpdate"}}, "status": {"currentNumberScheduled": 0, "desiredNumberScheduled": 0, "numberMisscheduled": 0, "numberReady": 0, "observedGeneration": 1}}}
~$ kubectl get ds
NAME           DESIRED   CURRENT   READY   UP-TO-DATE   AVAILABLE   NODE SELECTOR           AGE
my-daemonset   0         0         0       0            0           non_exisiting_label=1   30s
softwarefactory-project-zuul[bot] commented 3 months ago

Build succeeded. https://ansible.softwarefactory-project.io/zuul/buildset/2b00bf0319a143d7a1684cf0a2a00006

:heavy_check_mark: ansible-galaxy-importer SUCCESS in 4m 21s :heavy_check_mark: build-ansible-collection SUCCESS in 6m 54s

softwarefactory-project-zuul[bot] commented 3 months ago

Build succeeded. https://ansible.softwarefactory-project.io/zuul/buildset/272f403abb8d407cade4f9fa18c94e8e

:heavy_check_mark: ansible-galaxy-importer SUCCESS in 3m 39s :heavy_check_mark: build-ansible-collection SUCCESS in 7m 04s

softwarefactory-project-zuul[bot] commented 2 months ago

Build succeeded. https://ansible.softwarefactory-project.io/zuul/buildset/58b148dd22844b278dc611d9c6a24f1d

:heavy_check_mark: ansible-galaxy-importer SUCCESS in 3m 31s :heavy_check_mark: build-ansible-collection SUCCESS in 6m 48s

softwarefactory-project-zuul[bot] commented 2 months ago

Build succeeded. https://ansible.softwarefactory-project.io/zuul/buildset/c492c04715db4269937ff3f22e679ed7

:heavy_check_mark: ansible-galaxy-importer SUCCESS in 4m 30s :heavy_check_mark: build-ansible-collection SUCCESS in 6m 45s

azaleski9 commented 2 months ago

Could you add an integration test for this?

@gravesm Sure, I've just pushed new commit with integration tests

softwarefactory-project-zuul[bot] commented 2 months ago

Build succeeded. https://ansible.softwarefactory-project.io/zuul/buildset/c531a9a1b8194b768f7adf4edf022744

:heavy_check_mark: ansible-galaxy-importer SUCCESS in 4m 17s :heavy_check_mark: build-ansible-collection SUCCESS in 6m 41s

softwarefactory-project-zuul[bot] commented 2 months ago

Build succeeded (gate pipeline). https://ansible.softwarefactory-project.io/zuul/buildset/fda9edc6ef0a427dbe7c10e7f6f4286c

:heavy_check_mark: ansible-galaxy-importer SUCCESS in 2m 58s :heavy_check_mark: build-ansible-collection SUCCESS in 7m 11s

patchback[bot] commented 2 months ago

Backport to stable-3: 💚 backport PR created

✅ Backport PR branch: patchback/backports/stable-3/b07fbd627194a6655300309429877ae82433ae66/pr-756

Backported as https://github.com/ansible-collections/kubernetes.core/pull/761

🤖 @patchback I'm built with octomachinery and my source is open — https://github.com/sanitizers/patchback-github-app.

patchback[bot] commented 2 months ago

Backport to stable-5: 💚 backport PR created

✅ Backport PR branch: patchback/backports/stable-5/b07fbd627194a6655300309429877ae82433ae66/pr-756

Backported as https://github.com/ansible-collections/kubernetes.core/pull/762

🤖 @patchback I'm built with octomachinery and my source is open — https://github.com/sanitizers/patchback-github-app.