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

🌱 Allow SRM to change network of a registered VM for test failover #803

Conversation

aruneshpa
Copy link
Contributor

@aruneshpa aruneshpa commented Nov 15, 2024

What does this PR do, and why is it needed?

SRM (Site Reliability Manager) needs to be able to change a VM's network interface to connect to the test failover network. This change skips part of the validation webhook if a predefined test failover label is present on the VM resource. This change introduces a label (as opposed to an annotation) because we want to allow server side indexing so clients can filter and operate on all VMs that are part of a test failover. This will help with debuggability, and cleanup of test failed over VMs.

A test failover does not need to add new interfaces, so keep that check as is.

Testing Done

  • Existing unit tests as well as newly added tests
  • Manually tested by loading VM operator in an env
    • Without the label
root@4214a043bbff661bcddbde32adee61b3 [ ~ ]# kubectl patch vm -n parunesh-ns srm-vm --type='json' -p='[{"op": "replace", "path": "/spec/network/interfaces/1/network/name", "value": "my-subnet-2"}]' 
Error from server (spec.network.interfaces[1].network: Forbidden: field is immutable): admission webhook "default.validating.virtualmachine.v1alpha3.vmoperator.vmware.com" denied the request: spec.network.interfaces[1].network: Forbidden: field is immutable
  • Edit the VM to apply the label
root@4214a043bbff661bcddbde32adee61b3 [ ~ ]# k edit vm -n parunesh-ns srm-vm virtualmachine.vmoperator.vmware.com/srm-vm edited
  • Verify that edits are allowed
root@4214a043bbff661bcddbde32adee61b3 [ ~ ]# kubectl patch vm -n parunesh-ns srm-vm --type='json' -p='[{"op": "replace", "path": "/spec/network/interfaces/1/network/name", "value": "my-subnet-2"}]' virtualmachine.vmoperator.vmware.com/srm-vm patched

Are there any special notes for your reviewer:

This is needed specifically for SRM (and possibly other vendors exercising a test failover). As such, I have called out in the API docs that it is not an otherwise supported workflow.

Please add a release note if necessary:

Allow SRM to change network of a registered VM for test failover

SRM (Site Reliability Manager) needs to be able to change a VM's
network interface to connect to the test failover network.  This
change skips part of the validation webhook if a predefined test
failover label is present on the VM resource.

A test failover does not need to add new interfaces, so keep that
check as is.

Testing Done:
- Existing unit tests as well as newly added tests
- Manually tested by loading VM operator in an env
  Without the label:
  root@4214a043bbff661bcddbde32adee61b3 [ ~ ]# kubectl patch vm -n parunesh-ns srm-vm --type='json' -p='[{"op": "replace", "path": "/spec/network/interfaces/1/network/name", "value": "my-subnet-2"}]'
  Error from server (spec.network.interfaces[1].network: Forbidden: field is immutable): admission webhook "default.validating.virtualmachine.v1alpha3.vmoperator.vmware.com" denied the request: spec.network.interfaces[1].network: Forbidden: field is immutable

  Edit the VM to apply the label
  root@4214a043bbff661bcddbde32adee61b3 [ ~ ]# k edit vm -n parunesh-ns srm-vm
  virtualmachine.vmoperator.vmware.com/srm-vm edited

  Verify that edits are allowed
  root@4214a043bbff661bcddbde32adee61b3 [ ~ ]# kubectl patch vm -n parunesh-ns srm-vm --type='json' -p='[{"op": "replace", "path": "/spec/network/interfaces/1/network/name", "value": "my-subnet-2"}]'
  virtualmachine.vmoperator.vmware.com/srm-vm patched
@github-actions github-actions bot added the size/M Denotes a PR that changes 30-99 lines. label Nov 15, 2024
@akutz
Copy link
Collaborator

akutz commented Nov 15, 2024

Why a label and not annotation? Unless the intent is to find resources with this label, then please change to an annotation.

Copy link

Code Coverage

Package Line Rate Health
github.com/vmware-tanzu/vm-operator/controllers/contentlibrary/clustercontentlibraryitem 82%
github.com/vmware-tanzu/vm-operator/controllers/contentlibrary/contentlibraryitem 85%
github.com/vmware-tanzu/vm-operator/controllers/contentlibrary/utils 97%
github.com/vmware-tanzu/vm-operator/controllers/infra/capability/configmap 86%
github.com/vmware-tanzu/vm-operator/controllers/infra/capability/crd 93%
github.com/vmware-tanzu/vm-operator/controllers/infra/configmap 71%
github.com/vmware-tanzu/vm-operator/controllers/infra/node 77%
github.com/vmware-tanzu/vm-operator/controllers/infra/secret 77%
github.com/vmware-tanzu/vm-operator/controllers/infra/validatingwebhookconfiguration 85%
github.com/vmware-tanzu/vm-operator/controllers/infra/zone 76%
github.com/vmware-tanzu/vm-operator/controllers/storageclass 95%
github.com/vmware-tanzu/vm-operator/controllers/storagepolicyquota 97%
github.com/vmware-tanzu/vm-operator/controllers/util/encoding 73%
github.com/vmware-tanzu/vm-operator/controllers/virtualmachine/storagepolicyusage 99%
github.com/vmware-tanzu/vm-operator/controllers/virtualmachine/virtualmachine 86%
github.com/vmware-tanzu/vm-operator/controllers/virtualmachine/volume 87%
github.com/vmware-tanzu/vm-operator/controllers/virtualmachineclass 75%
github.com/vmware-tanzu/vm-operator/controllers/virtualmachinepublishrequest 81%
github.com/vmware-tanzu/vm-operator/controllers/virtualmachinereplicaset 68%
github.com/vmware-tanzu/vm-operator/controllers/virtualmachineservice 83%
github.com/vmware-tanzu/vm-operator/controllers/virtualmachineservice/providers 92%
github.com/vmware-tanzu/vm-operator/controllers/virtualmachinesetresourcepolicy 80%
github.com/vmware-tanzu/vm-operator/controllers/virtualmachinewebconsolerequest/v1alpha1 72%
github.com/vmware-tanzu/vm-operator/controllers/virtualmachinewebconsolerequest/v1alpha1/conditions 88%
github.com/vmware-tanzu/vm-operator/controllers/virtualmachinewebconsolerequest/v1alpha1/patch 78%
github.com/vmware-tanzu/vm-operator/controllers/virtualmachinewebconsolerequest/v1alpha2 72%
github.com/vmware-tanzu/vm-operator/pkg/bitmask 100%
github.com/vmware-tanzu/vm-operator/pkg/builder 95%
github.com/vmware-tanzu/vm-operator/pkg/conditions 88%
github.com/vmware-tanzu/vm-operator/pkg/config 100%
github.com/vmware-tanzu/vm-operator/pkg/config/capabilities 100%
github.com/vmware-tanzu/vm-operator/pkg/config/env 100%
github.com/vmware-tanzu/vm-operator/pkg/context/generic 100%
github.com/vmware-tanzu/vm-operator/pkg/context/operation 100%
github.com/vmware-tanzu/vm-operator/pkg/patch 78%
github.com/vmware-tanzu/vm-operator/pkg/prober 91%
github.com/vmware-tanzu/vm-operator/pkg/prober/probe 90%
github.com/vmware-tanzu/vm-operator/pkg/prober/worker 77%
github.com/vmware-tanzu/vm-operator/pkg/providers/vsphere 75%
github.com/vmware-tanzu/vm-operator/pkg/providers/vsphere/client 80%
github.com/vmware-tanzu/vm-operator/pkg/providers/vsphere/clustermodules 71%
github.com/vmware-tanzu/vm-operator/pkg/providers/vsphere/config 89%
github.com/vmware-tanzu/vm-operator/pkg/providers/vsphere/contentlibrary 74%
github.com/vmware-tanzu/vm-operator/pkg/providers/vsphere/credentials 100%
github.com/vmware-tanzu/vm-operator/pkg/providers/vsphere/network 80%
github.com/vmware-tanzu/vm-operator/pkg/providers/vsphere/placement 79%
github.com/vmware-tanzu/vm-operator/pkg/providers/vsphere/session 71%
github.com/vmware-tanzu/vm-operator/pkg/providers/vsphere/storage 44%
github.com/vmware-tanzu/vm-operator/pkg/providers/vsphere/sysprep 100%
github.com/vmware-tanzu/vm-operator/pkg/providers/vsphere/vcenter 82%
github.com/vmware-tanzu/vm-operator/pkg/providers/vsphere/virtualmachine 84%
github.com/vmware-tanzu/vm-operator/pkg/providers/vsphere/vmlifecycle 68%
github.com/vmware-tanzu/vm-operator/pkg/record 87%
github.com/vmware-tanzu/vm-operator/pkg/topology 91%
github.com/vmware-tanzu/vm-operator/pkg/util 87%
github.com/vmware-tanzu/vm-operator/pkg/util/annotations 100%
github.com/vmware-tanzu/vm-operator/pkg/util/cloudinit 89%
github.com/vmware-tanzu/vm-operator/pkg/util/cloudinit/validate 91%
github.com/vmware-tanzu/vm-operator/pkg/util/image 100%
github.com/vmware-tanzu/vm-operator/pkg/util/kube 89%
github.com/vmware-tanzu/vm-operator/pkg/util/kube/cource 100%
github.com/vmware-tanzu/vm-operator/pkg/util/kube/internal 100%
github.com/vmware-tanzu/vm-operator/pkg/util/kube/proxyaddr 75%
github.com/vmware-tanzu/vm-operator/pkg/util/kube/spq 100%
github.com/vmware-tanzu/vm-operator/pkg/util/paused 100%
github.com/vmware-tanzu/vm-operator/pkg/util/ptr 100%
github.com/vmware-tanzu/vm-operator/pkg/util/resize 97%
github.com/vmware-tanzu/vm-operator/pkg/util/vmopv1 92%
github.com/vmware-tanzu/vm-operator/pkg/util/vsphere/client 64%
github.com/vmware-tanzu/vm-operator/pkg/util/vsphere/vm 79%
github.com/vmware-tanzu/vm-operator/pkg/util/vsphere/watcher 86%
github.com/vmware-tanzu/vm-operator/pkg/vmconfig 95%
github.com/vmware-tanzu/vm-operator/pkg/vmconfig/crypto 98%
github.com/vmware-tanzu/vm-operator/pkg/webconsolevalidation 100%
github.com/vmware-tanzu/vm-operator/services/vm-watcher 91%
github.com/vmware-tanzu/vm-operator/webhooks/common 100%
github.com/vmware-tanzu/vm-operator/webhooks/persistentvolumeclaim/validation 95%
github.com/vmware-tanzu/vm-operator/webhooks/unifiedstoragequota/validation 89%
github.com/vmware-tanzu/vm-operator/webhooks/virtualmachine/mutation 87%
github.com/vmware-tanzu/vm-operator/webhooks/virtualmachine/validation 95%
github.com/vmware-tanzu/vm-operator/webhooks/virtualmachineclass/mutation 62%
github.com/vmware-tanzu/vm-operator/webhooks/virtualmachineclass/validation 89%
github.com/vmware-tanzu/vm-operator/webhooks/virtualmachinepublishrequest/validation 92%
github.com/vmware-tanzu/vm-operator/webhooks/virtualmachinereplicaset/validation 90%
github.com/vmware-tanzu/vm-operator/webhooks/virtualmachineservice/mutation 67%
github.com/vmware-tanzu/vm-operator/webhooks/virtualmachineservice/validation 92%
github.com/vmware-tanzu/vm-operator/webhooks/virtualmachinesetresourcepolicy/validation 89%
github.com/vmware-tanzu/vm-operator/webhooks/virtualmachinewebconsolerequest/v1alpha1/validation 92%
github.com/vmware-tanzu/vm-operator/webhooks/virtualmachinewebconsolerequest/v1alpha2/validation 92%
Summary 83% (10581 / 12713)

Minimum allowed line rate is 79%

@aruneshpa
Copy link
Contributor Author

Why a label and not annotation? Unless the intent is to find resources with this label, then please change to an annotation.

Andrew, the label here is intentional. This allows a user (admin) to identify the VMs that are test failed over. This can specially be helpful if we want to round up these VMs for cleanup after a test failover is complete. I will add this in the MR description for posterity.

@aruneshpa aruneshpa requested a review from akutz November 15, 2024 22:34
Copy link
Collaborator

@akutz akutz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm, thank you sir!

@aruneshpa aruneshpa merged commit 77f305f into vmware-tanzu:main Nov 18, 2024
10 checks passed
@aruneshpa aruneshpa deleted the feature/allow-network-change-for-test-failover branch November 18, 2024 19:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla-not-required size/M Denotes a PR that changes 30-99 lines.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants