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

✨ VirtualMachineReplicaSet CRUD/Scale Up Scale Down support #528

Merged
merged 1 commit into from
May 31, 2024

Conversation

aruneshpa
Copy link
Contributor

@aruneshpa aruneshpa commented May 21, 2024

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

This commit adds support for creating, deleting and scaling a VirtualMachineReplicaSet resource. When a VirtualMachineReplicaSet is created, it is reconciled to create the desired number of virtual machine replicas specified in its spec.

Similarly, during scale out/scale in, the controller reconciles the replicas to match the desired state by either creating or deleting VirtualMachine objects. Note that a new replica is only created when the controller detect that it requires a new replica (as opposed to a rollout that is triggered via modification of the template spec in a Deployment).

When the VirtualMachineReplicaSet resource is deleted, all of its owned virtual machine replicas are also cleaned up. The controller relies on the Kubernetes garbage collection mechanism for this.

This change also adds support for deletion policies which can used used to determine how the controller picks a virtual machine to delete from the list of replicas that it controls during a scale in/down. The only supported policy for now is "Random" where all VMs that are not in deleting state get equal weight and the controller can pick any one of them randomly. If a VM is already marked for deletion, that gets the highest deletion priority.

In several places, I have added a TODO to revisit since ReplicaSets offer an ability to signal when an application can be considered "available". That is dependent on a "Ready" condition that is exposed by the replicas. Since we don't have a consistent way to do that, I have removed the support for indicating availability of a VM replica set in the Status. Consequently, the MinReadySeconds field from the spec is also removed since that is used to signal availability. These can be added in a followup.

Testing Done:

  1. Create a VirtualMachineReplicaSet

  2. Get the resource to ensure all replicas ready

k get vmreplicaset -n parunesh-ns test-rs
NAME      REPLICAS   READY   AGE
test-rs   3          3       3m57s
  1. Scale down the replica set
k scale vmreplicaset -n parunesh-ns test-rs --replicas=1
virtualmachinereplicaset.vmoperator.vmware.com/test-rs scaled
  1. Ensure scale down has cleaned up replicas:
k get vmreplicaset -n parunesh-ns test-rs  -o wide
NAME      REPLICAS   READY   AGE
test-rs   1          1       5m15s

k get vm -n parunesh-ns
NAME            POWER-STATE   AGE
test-rs-zmdmm   PoweredOn     3m38s
  1. Scale up the replica set
k scale vmreplicaset -n parunesh-ns test-rs --replicas=2
virtualmachinereplicaset.vmoperator.vmware.com/test-rs scaled
  1. Ensure scaled up has created new replicas
k get vmreplicaset -n parunesh-ns test-rs  -o wide
NAME      REPLICAS   READY   AGE
test-rs   2          2       7m1s

k get vm -n parunesh-ns
NAME            POWER-STATE   AGE
test-rs-r9slq   PoweredOn     44s
test-rs-zmdmm   PoweredOn     4m57s
  1. Delete the replica set and ensure all replicas are deleted.
k delete vmreplicaset -n parunesh-ns test-rs
virtualmachinereplicaset.vmoperator.vmware.com "test-rs" deleted

k get vm -n parunesh-ns
No resources found in parunesh-ns namespace.

Are there any special notes for your reviewer:

None.

Please add a release note if necessary:

Add support for VirtualMachineReplicaSet CRUD and Scale up/down

@github-actions github-actions bot added the size/XL Denotes a PR that changes 500-999 lines. label May 21, 2024
@aruneshpa aruneshpa changed the title WIP: ✨ VirtualMachineReplicaSet CRUD/Scale Up Scale Down support ✨ VirtualMachineReplicaSet CRUD/Scale Up Scale Down support May 22, 2024
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.

First pass

@github-actions github-actions bot added size/XXL Denotes a PR that changes 1000+ lines. and removed size/XL Denotes a PR that changes 500-999 lines. labels May 23, 2024
Copy link
Member

@dilyar85 dilyar85 left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks for addressing all the review comments.

pkg/util/replicaset_label_test.go Show resolved Hide resolved
pkg/util/replicaset_label_test.go Outdated Show resolved Hide resolved
@aruneshpa aruneshpa force-pushed the feature/vm-replicaset-api branch 4 times, most recently from 1aa8d27 to 7be3273 Compare May 31, 2024 01:17
This commit adds support for creating, deleting and scaling a
VirtualMachineReplicaSet resource.  When a VirtualMachineReplicaSet is
created, it is reconciled to create the desired number of virtual
machine replicas specified in its spec.

Similarly, during scale out/scale in, the controller reconciles the
replicas to match the desired state by either creating or deleting
VirtualMachine objects.  Note that a new replica is only created when
the controller detect that it requires a new replica (as opposed to a
rollout that is triggered via modification of the template spec in a
Deployment).

When the VirtualMachineReplicaSet resource is deleted, all of its
owned virtual machine replicas are also cleaned up.  The controller
relies on the Kubernetes garbage collection mechanism for this.

This change also adds support for deletion policies which can used
used to determine how the controller picks a virtual machine to delete
from the list of replicas that it controls during a scale in/down.
The only supported policy for now is "Random" where all VMs that are
not in deleting state get equal weight and the controller can pick any
one of them randomly.  If a VM is already marked for deletion, that
gets the highest deletion priority.

In several places, I have added a TODO to revisit since ReplicaSets
offer an ability to signal when an application can be considered
"available".  That is dependent on a "Ready" condition that is exposed
by the replicas.  Since we don't have a consistent way to do that, I
have removed the support for indicating availability of a VM replica
set in the Status.  Consequently, the `MinReadySeconds` field from the
spec is also removed since that is used to signal availability.
These can be added in a followup.

Testing Done:

1. Create a VirtualMachineReplicaSet

2. Get the resource to ensure all replicas ready
```
k get vmreplicaset -n parunesh-ns test-rs
NAME      REPLICAS   READY   AGE
test-rs   3          3       3m57s
```

3. Scale down the replica set
```
 k scale vmreplicaset -n parunesh-ns test-rs --replicas=1
virtualmachinereplicaset.vmoperator.vmware.com/test-rs scaled
```

4. Ensure scale down has cleaned up replicas:
```
k get vmreplicaset -n parunesh-ns test-rs  -o wide
NAME      REPLICAS   READY   AGE
test-rs   1          1       5m15s

k get vm -n parunesh-ns
NAME            POWER-STATE   AGE
test-rs-zmdmm   PoweredOn     3m38s
```

5. Scale up the replica set
```
k scale vmreplicaset -n parunesh-ns test-rs --replicas=2
virtualmachinereplicaset.vmoperator.vmware.com/test-rs scaled
```

6. Ensure scaled up has created new replicas
```
k get vmreplicaset -n parunesh-ns test-rs  -o wide
NAME      REPLICAS   READY   AGE
test-rs   2          2       7m1s

k get vm -n parunesh-ns
NAME            POWER-STATE   AGE
test-rs-r9slq   PoweredOn     44s
test-rs-zmdmm   PoweredOn     4m57s
```

7. Delete the replica set and ensure all replicas are deleted.
```
k delete vmreplicaset -n parunesh-ns test-rs
virtualmachinereplicaset.vmoperator.vmware.com "test-rs" deleted

 k get vm -n parunesh-ns
No resources found in parunesh-ns namespace.
```
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!

Copy link

Code Coverage

Package Line Rate Health
github.com/vmware-tanzu/vm-operator/controllers/contentlibrary/clustercontentlibraryitem 81%
github.com/vmware-tanzu/vm-operator/controllers/contentlibrary/contentlibraryitem 85%
github.com/vmware-tanzu/vm-operator/controllers/contentlibrary/utils 32%
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/util/encoding 73%
github.com/vmware-tanzu/vm-operator/controllers/virtualmachine 77%
github.com/vmware-tanzu/vm-operator/controllers/virtualmachineclass 21%
github.com/vmware-tanzu/vm-operator/controllers/virtualmachinepublishrequest 81%
github.com/vmware-tanzu/vm-operator/controllers/virtualmachinereplicaset 67%
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 73%
github.com/vmware-tanzu/vm-operator/controllers/volume 85%
github.com/vmware-tanzu/vm-operator/pkg/builder 15%
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/env 100%
github.com/vmware-tanzu/vm-operator/pkg/patch 78%
github.com/vmware-tanzu/vm-operator/pkg/prober 54%
github.com/vmware-tanzu/vm-operator/pkg/prober/probe 91%
github.com/vmware-tanzu/vm-operator/pkg/prober/worker 77%
github.com/vmware-tanzu/vm-operator/pkg/providers/vsphere 72%
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 72%
github.com/vmware-tanzu/vm-operator/pkg/providers/vsphere/contentlibrary 72%
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 77%
github.com/vmware-tanzu/vm-operator/pkg/providers/vsphere/session 33%
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 74%
github.com/vmware-tanzu/vm-operator/pkg/providers/vsphere/vmlifecycle 66%
github.com/vmware-tanzu/vm-operator/pkg/record 78%
github.com/vmware-tanzu/vm-operator/pkg/topology 91%
github.com/vmware-tanzu/vm-operator/pkg/util 78%
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 81%
github.com/vmware-tanzu/vm-operator/pkg/util/ptr 100%
github.com/vmware-tanzu/vm-operator/pkg/util/resize 100%
github.com/vmware-tanzu/vm-operator/pkg/util/vmopv1 93%
github.com/vmware-tanzu/vm-operator/pkg/util/vsphere/client 68%
github.com/vmware-tanzu/vm-operator/pkg/util/vsphere/vm 78%
github.com/vmware-tanzu/vm-operator/pkg/webconsolevalidation 51%
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/virtualmachine/mutation 86%
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 76% (7203 / 9430)

@aruneshpa aruneshpa merged commit e7c9bb7 into vmware-tanzu:main May 31, 2024
11 checks passed
@aruneshpa aruneshpa deleted the feature/vm-replicaset-api branch May 31, 2024 23:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla-not-required size/XXL Denotes a PR that changes 1000+ lines.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants