openshift / community.okd

OKD/Openshift collection for Ansible
http://galaxy.ansible.com/community/okd
GNU General Public License v3.0
56 stars 36 forks source link

Attempting to patch annotations results in not changed #164

Closed jbpratt closed 2 years ago

jbpratt commented 2 years ago

I'm trying to patch disable the default storage class as shown below, but when doing so the annotations are not applied. Perhaps I'm doing it wrong. Also not sure if this is an issue in the upstream k8s modules that we redirect to?

(oc patch storageclass standard -p '{"metadata": {"annotations": {"storageclass.kubernetes.io/is-default-class": "false"}}}')

❯ oc get storageclass -o json standard
{
    "allowVolumeExpansion": true,
    "apiVersion": "storage.k8s.io/v1",
    "kind": "StorageClass",
    "metadata": {
        "annotations": {
            "storageclass.kubernetes.io/is-default-class": "true"
        },
        "creationTimestamp": "2022-05-09T08:15:10Z",
        "name": "standard",
        "resourceVersion": "44960",
        "uid": "a4b9a1a4-f66a-41d8-9cca-18f486f76945"
    },
    "provisioner": "kubernetes.io/cinder",
    "reclaimPolicy": "Delete",
    "volumeBindingMode": "WaitForFirstConsumer"
}
    - name: Disable default storage class
      community.okd.k8s:
        state: patched
        definition:
          apiVersion: storage.k8s.io/v1
          kind: StorageClass
          metadata:
            name: standard
          annotations:
            "storageclass.kubernetes.io/is-default-class": "false"
TASK [Disable default storage class] ***************************************************************************************************************************************************
redirecting (type: action) community.okd.k8s to kubernetes.core.k8s_info
redirecting (type: action) community.okd.k8s to kubernetes.core.k8s_info
ok: [localhost] => changed=false
  method: patch
  result:
    allowVolumeExpansion: true
    apiVersion: storage.k8s.io/v1
    kind: StorageClass
    metadata:
      annotations:
        storageclass.kubernetes.io/is-default-class: 'true'
      creationTimestamp: '2022-05-09T08:15:10Z'
      managedFields:
      - apiVersion: storage.k8s.io/v1
        fieldsType: FieldsV1
        fieldsV1:
          f:allowVolumeExpansion: {}
          f:metadata:
            f:annotations: {}
          f:provisioner: {}
          f:reclaimPolicy: {}
          f:volumeBindingMode: {}
        manager: Go-http-client
        operation: Update
        time: '2022-05-09T08:15:10Z'
      - apiVersion: storage.k8s.io/v1
        fieldsType: FieldsV1
        fieldsV1:
          f:metadata:
            f:annotations:
              f:storageclass.kubernetes.io/is-default-class: {}
        manager: kubectl-patch
        operation: Update
        time: '2022-05-09T09:24:22Z'
      name: standard
      resourceVersion: '44960'
      uid: a4b9a1a4-f66a-41d8-9cca-18f486f76945
    provisioner: kubernetes.io/cinder
    reclaimPolicy: Delete
    volumeBindingMode: WaitForFirstConsumer
gravesm commented 2 years ago

@jbpratt I am unable to reproduce this using the following playbook:

- hosts: localhost
  gather_facts: false
  tasks:
    - community.okd.k8s:
        definition:
          apiVersion: storage.k8s.io/v1
          kind: StorageClass
          metadata:
            name: standard
            annotations:
              storageclass.kubernetes.io/is-default-class: "true"
          provisioner: kubernetes.io/cinder

    - community.okd.k8s:
        state: patched
        definition:
          apiVersion: storage.k8s.io/v1
          kind: StorageClass
          metadata:
            name: standard
            annotations:
              storageclass.kubernetes.io/is-default-class: "false"
TASK [community.okd.k8s] ********************************************************************************************************************
redirecting (type: action) community.okd.k8s to kubernetes.core.k8s_info
redirecting (type: action) community.okd.k8s to kubernetes.core.k8s_info
changed: [localhost] => {
    "changed": true,
    "method": "create",
    "result": {
        "apiVersion": "storage.k8s.io/v1",
        "kind": "StorageClass",
        "metadata": {
            "annotations": {
                "storageclass.kubernetes.io/is-default-class": "true"
            },
            "creationTimestamp": "2022-05-10T14:35:56Z",
            "managedFields": [
                {
                    "apiVersion": "storage.k8s.io/v1",
                    "fieldsType": "FieldsV1",
                    "fieldsV1": {
                        "f:metadata": {
                            "f:annotations": {
                                ".": {},
                                "f:storageclass.kubernetes.io/is-default-class": {}
                            }
                        },
                        "f:provisioner": {},
                        "f:reclaimPolicy": {},
                        "f:volumeBindingMode": {}
                    },
                    "manager": "OpenAPI-Generator",
                    "operation": "Update",
                    "time": "2022-05-10T14:35:56Z"
                }
            ],
            "name": "standard",
            "resourceVersion": "66545",
            "uid": "e0094f26-59dc-48ee-9d64-e2abc2aa901f"
        },
        "provisioner": "kubernetes.io/cinder",
        "reclaimPolicy": "Delete",
        "volumeBindingMode": "Immediate"
    }
}
TASK [community.okd.k8s] ********************************************************************************************************************
redirecting (type: action) community.okd.k8s to kubernetes.core.k8s_info
redirecting (type: action) community.okd.k8s to kubernetes.core.k8s_info
changed: [localhost] => {
    "changed": true,
    "method": "patch",
    "result": {
        "apiVersion": "storage.k8s.io/v1",
        "kind": "StorageClass",
        "metadata": {
            "annotations": {
                "storageclass.kubernetes.io/is-default-class": "false"
            },
            "creationTimestamp": "2022-05-10T14:35:56Z",
            "managedFields": [
                {
                    "apiVersion": "storage.k8s.io/v1",
                    "fieldsType": "FieldsV1",
                    "fieldsV1": {
                        "f:metadata": {
                            "f:annotations": {
                                ".": {},
                                "f:storageclass.kubernetes.io/is-default-class": {}
                            }
                        },
                        "f:provisioner": {},
                        "f:reclaimPolicy": {},
                        "f:volumeBindingMode": {}
                    },
                    "manager": "OpenAPI-Generator",
                    "operation": "Update",
                    "time": "2022-05-10T14:35:56Z"
                }
            ],
            "name": "standard",
            "resourceVersion": "66546",
            "uid": "e0094f26-59dc-48ee-9d64-e2abc2aa901f"
        },
        "provisioner": "kubernetes.io/cinder",
        "reclaimPolicy": "Delete",
        "volumeBindingMode": "Immediate"
    }
}

Openshift 4.10.9 community.okd 2.2.0 kubernetes.core 2.3.1

jbpratt commented 2 years ago

Hey @gravesm , thanks for taking a look. I'll try updating my community.okd version. I figured I'm just doing something wrong but it isn't obvious to me yet.

kubernetes.core    2.3.1
community.okd                 2.1.0
OpenShift 4.10.13
jbpratt commented 2 years ago

Oh no, silly mistake on my part. annotations just isn't indented far enough. Sorry for the noise :facepalm:

gravesm commented 2 years ago

Ahhh, now I see it and wonder how I missed it. Glad it's sorted.