Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make kubevirt.core.kubevirt_vm idempotence #145

Open
rabin-io opened this issue Nov 5, 2024 · 4 comments
Open

Make kubevirt.core.kubevirt_vm idempotence #145

rabin-io opened this issue Nov 5, 2024 · 4 comments

Comments

@rabin-io
Copy link

rabin-io commented Nov 5, 2024

SUMMARY

Running the same task with the same input, show the VM changed. While nothing significant was change only some timestamps.

ISSUE TYPE
  • Bug Report
ANSIBLE VERSION
❯ ansible --version
ansible [core 2.17.5]
  config file = None
  configured module search path = ['/home/rabin/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/rabin/.local/lib/python3.13/site-packages/ansible
  ansible collection location = /home/rabin/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/rabin/.local/bin/ansible
  python version = 3.13.0 (main, Oct  8 2024, 00:00:00) [GCC 14.2.1 20240912 (Red Hat 14.2.1-3)] (/usr/bin/python)
  jinja version = 3.1.4
  libyaml = True
COLLECTION VERSION

# /home/rabin/.ansible/collections/ansible_collections
Collection                               Version
---------------------------------------- -------
ansible.netcommon                        7.1.0  
ansible.posix                            1.6.2  
ansibleguy.opnsense                      1.2.9  
community.general                        9.5.0  
community.zabbix                         3.1.2  
dellemc.openmanage                       9.7.0  
kubevirt.core                            2.1.0  
unistra.glpi                             1.1.1  

# /home/rabin/.local/lib/python3.13/site-packages/ansible_collections
Collection                               Version
---------------------------------------- -------
amazon.aws                               8.2.1  
ansible.netcommon                        6.1.3  
ansible.posix                            1.5.4  
ansible.utils                            4.1.0  
ansible.windows                          2.5.0  
arista.eos                               9.0.0  
awx.awx                                  24.6.1 
azure.azcollection                       2.7.0  
check_point.mgmt                         5.2.3  
chocolatey.chocolatey                    1.5.3  
cisco.aci                                2.10.1 
cisco.asa                                5.0.1  
cisco.dnac                               6.20.0 
cisco.intersight                         2.0.20 
cisco.ios                                8.0.0  
cisco.iosxr                              9.0.0  
cisco.ise                                2.9.3  
cisco.meraki                             2.18.2 
cisco.mso                                2.9.0  
cisco.nxos                               8.1.0  
cisco.ucs                                1.14.0 
cloud.common                             3.0.0  
cloudscale_ch.cloud                      2.4.0  
community.aws                            8.0.0  
community.ciscosmb                       1.0.9  
community.crypto                         2.22.1 
community.digitalocean                   1.27.0 
community.dns                            3.0.5  
community.docker                         3.13.0 
community.general                        9.5.0  
community.grafana                        1.9.1  
community.hashi_vault                    6.2.0  
community.hrobot                         2.0.2  
community.library_inventory_filtering_v1 1.0.1  
community.libvirt                        1.3.0  
community.mongodb                        1.7.7  
community.mysql                          3.10.3 
community.network                        5.0.3  
community.okd                            3.0.1  
community.postgresql                     3.6.1  
community.proxysql                       1.6.0  
community.rabbitmq                       1.3.0  
community.routeros                       2.19.0 
community.sap_libs                       1.4.2  
community.sops                           1.9.1  
community.vmware                         4.7.1  
community.windows                        2.3.0  
community.zabbix                         2.5.1  
containers.podman                        1.16.1 
cyberark.conjur                          1.3.0  
cyberark.pas                             1.0.27 
dellemc.enterprise_sonic                 2.5.1  
dellemc.openmanage                       9.7.0  
dellemc.powerflex                        2.5.0  
dellemc.unity                            2.0.0  
f5networks.f5_modules                    1.31.0 
fortinet.fortimanager                    2.7.0  
fortinet.fortios                         2.3.7  
frr.frr                                  2.0.2  
google.cloud                             1.4.1  
grafana.grafana                          5.5.1  
hetzner.hcloud                           3.1.1  
ibm.qradar                               3.0.0  
ibm.spectrum_virtualize                  2.0.0  
ibm.storage_virtualize                   2.5.0  
ieisystem.inmanage                       2.0.0  
infinidat.infinibox                      1.4.5  
infoblox.nios_modules                    1.7.0  
inspur.ispim                             2.2.3  
inspur.sm                                2.3.0  
junipernetworks.junos                    8.0.0  
kaytus.ksmanage                          1.2.2  
kubernetes.core                          3.2.0  
kubevirt.core                            1.5.0  
lowlydba.sqlserver                       2.3.4  
microsoft.ad                             1.7.1  
netapp.cloudmanager                      21.22.1
netapp.ontap                             22.12.0
netapp.storagegrid                       21.12.0
netapp_eseries.santricity                1.4.1  
netbox.netbox                            3.20.0 
ngine_io.cloudstack                      2.5.0  
ngine_io.exoscale                        1.1.0  
openstack.cloud                          2.2.0  
openvswitch.openvswitch                  2.1.1  
ovirt.ovirt                              3.2.0  
purestorage.flasharray                   1.31.1 
purestorage.flashblade                   1.18.0 
sensu.sensu_go                           1.14.0 
splunk.es                                3.0.0  
t_systems_mms.icinga_director            2.0.1  
telekom_mms.icinga_director              2.1.2  
theforeman.foreman                       4.2.0  
vmware.vmware                            1.5.0  
vmware.vmware_rest                       3.2.0  
vultr.cloud                              1.13.0 
vyos.vyos                                4.1.0  
wti.remote                               1.0.10 
STEPS TO REPRODUCE

From the examples

- name: Playbook describing a virtual machine
  hosts: localhost
  tasks:
    - name: Create a VirtualMachine
      kubevirt.core.kubevirt_vm:
        state: present
        name: testvm
        namespace: default
        labels:
          app: test
        instancetype:
          name: u1.medium
        preference:
          name: fedora
        spec:
          domain:
            devices:
              interfaces:
                - name: default
                  masquerade: {}
                - name: bridge-network
                  bridge: {}
          networks:
            - name: default
              pod: {}
            - name: bridge-network
              multus:
                networkName: kindexgw
          volumes:
            - containerDisk:
                image: quay.io/containerdisks/fedora:latest
              name: containerdisk
            - cloudInitNoCloud:
                userData: |-
                  #cloud-config
                  # The default username is: fedora
                  ssh_authorized_keys:
                    - ssh-ed25519 AAAA...
              name: cloudinit
EXPECTED RESULTS

First run should create the VM (if the vm dose not exist)
Second run should report nothing change for the same input.

ACTUAL RESULTS
❯ ansible-playbook -i ./inventroy.kubevirt.yaml test.yaml --diff

PLAY [Playbook describing a virtual machine] *****************************************************************************************************************************************

TASK [Gathering Facts] ***************************************************************************************************************************************************************
ok: [localhost]

TASK [Create a VirtualMachine] *******************************************************************************************************************************************************
changed: [localhost]

PLAY RECAP ***************************************************************************************************************************************************************************
localhost                  : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

❯ ansible-playbook -i ./inventroy.kubevirt.yaml test.yaml --diff

PLAY [Playbook describing a virtual machine] *****************************************************************************************************************************************

TASK [Gathering Facts] ***************************************************************************************************************************************************************
ok: [localhost]

TASK [Create a VirtualMachine] *******************************************************************************************************************************************************
--- before
+++ after
@@ -1,9 +1,56 @@
 {
     "metadata": {
         "annotations": {
-            "kubemacpool.io/transaction-timestamp": "2024-11-05T08:47:07.331081722Z"
+            "kubemacpool.io/transaction-timestamp": "2024-11-05T08:47:18.418483066Z"
         },
         "managedFields": [
+            {
+                "apiVersion": "kubevirt.io/v1",
+                "fieldsType": "FieldsV1",
+                "fieldsV1": {
+                    "f:metadata": {
+                        "f:annotations": {
+                            "f:kubevirt.io/latest-observed-api-version": {},
+                            "f:kubevirt.io/storage-observed-api-version": {}
+                        },
+                        "f:finalizers": {
+                            ".": {},
+                            "v:\"kubevirt.io/virtualMachineControllerFinalize\"": {}
+                        }
+                    },
+                    "f:spec": {
+                        "f:instancetype": {
+                            "f:revisionName": {}
+                        },
+                        "f:preference": {
+                            "f:revisionName": {}
+                        }
+                    }
+                },
+                "manager": "virt-controller",
+                "operation": "Update",
+                "time": "2024-11-05T08:47:07Z"
+            },
+            {
+                "apiVersion": "kubevirt.io/v1",
+                "fieldsType": "FieldsV1",
+                "fieldsV1": {
+                    "f:status": {
+                        ".": {},
+                        "f:conditions": {},
+                        "f:created": {},
+                        "f:desiredGeneration": {},
+                        "f:observedGeneration": {},
+                        "f:printableStatus": {},
+                        "f:runStrategy": {},
+                        "f:volumeSnapshotStatuses": {}
+                    }
+                },
+                "manager": "virt-controller",
+                "operation": "Update",
+                "subresource": "status",
+                "time": "2024-11-05T08:47:07Z"
+            },
             {
                 "apiVersion": "kubevirt.io/v1",
                 "fieldsType": "FieldsV1",
@@ -51,56 +98,9 @@
                 },
                 "manager": "OpenAPI-Generator",
                 "operation": "Update",
-                "time": "2024-11-05T08:47:07Z"
-            },
-            {
-                "apiVersion": "kubevirt.io/v1",
-                "fieldsType": "FieldsV1",
-                "fieldsV1": {
-                    "f:metadata": {
-                        "f:annotations": {
-                            "f:kubevirt.io/latest-observed-api-version": {},
-                            "f:kubevirt.io/storage-observed-api-version": {}
-                        },
-                        "f:finalizers": {
-                            ".": {},
-                            "v:\"kubevirt.io/virtualMachineControllerFinalize\"": {}
-                        }
-                    },
-                    "f:spec": {
-                        "f:instancetype": {
-                            "f:revisionName": {}
-                        },
-                        "f:preference": {
-                            "f:revisionName": {}
-                        }
-                    }
-                },
-                "manager": "virt-controller",
-                "operation": "Update",
-                "time": "2024-11-05T08:47:07Z"
-            },
-            {
-                "apiVersion": "kubevirt.io/v1",
-                "fieldsType": "FieldsV1",
-                "fieldsV1": {
-                    "f:status": {
-                        ".": {},
-                        "f:conditions": {},
-                        "f:created": {},
-                        "f:desiredGeneration": {},
-                        "f:observedGeneration": {},
-                        "f:printableStatus": {},
-                        "f:runStrategy": {},
-                        "f:volumeSnapshotStatuses": {}
-                    }
-                },
-                "manager": "virt-controller",
-                "operation": "Update",
-                "subresource": "status",
-                "time": "2024-11-05T08:47:07Z"
+                "time": "2024-11-05T08:47:18Z"
             }
         ],
-        "resourceVersion": "4102438476"
+        "resourceVersion": "4102439269"
     }
 }

changed: [localhost]

PLAY RECAP ***************************************************************************************************************************************************************************
localhost                  : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

@0xFelix
Copy link
Member

0xFelix commented Nov 7, 2024

We could choose to ignore changes to managedFields. But changes to annotations could be an issue. However, I see that you did not specify annotations in your call to kubevirt.core.kubevirt_vm, so indeed, it should not care about those.

Will need to test this myself.

@rabin-io
Copy link
Author

rabin-io commented Nov 7, 2024

This issue with managedFields happens with other resources as well, so I think this one should be resolved with k8s module. But the kubemacpool.io/transaction-timestamp I think come from some pre-hook which inject the MAC if it's not in the request.

@0xFelix
Copy link
Member

0xFelix commented Nov 19, 2024

I was not able to reproduce it on the KubeVirt cluster provided by hack/e2e-setup.sh. I noticed though that your are using 3.2.0 of kubernetes.core. Can you try again with version 5.0.0 of kubernetes.core?

@0xFelix
Copy link
Member

0xFelix commented Nov 19, 2024

Ok, I can reproduce on OCP clusters. I'll see what I can do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants