-
Notifications
You must be signed in to change notification settings - Fork 305
✨ Support Node Auto Placement and Node AF/AAF #3655
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
Open
zhanggbj
wants to merge
16
commits into
kubernetes-sigs:main
Choose a base branch
from
zhanggbj:node_auto_placement
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,236
−40
Open
Changes from 12 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
fa60556
Bump VMOP and add NodeAutoPlacement Feature Gate
zhanggbj b52056f
Add VMG controller of node auto placement
zhanggbj 72fad61
Updates logic for VMG creation
srm09 124623a
Initial impl for VSphereMachine AAF changes
srm09 9f261d5
Removes cluster-name label from affinity rules
srm09 22d7db0
Selectively add node-pool AAF constraint
srm09 8474942
Refine VMG controller when generate per-MD zone labels (#71)
zhanggbj 833cdb5
Sync VSphereMachines in VMG controller
zhanggbj 36c3550
Add VMG reconciler unit test and bump VMOP
zhanggbj 189f6d2
Surface error when VM is waiting for VMG
zhanggbj 8cc8e8a
Update dependency in packaging&test
zhanggbj 2a21acc
Fix UT errors
zhanggbj 947dffa
Fix annotations
zhanggbj 5847119
Fix vmg UT errors
zhanggbj e3078c9
Refine VMG controller
zhanggbj 5b4bfc9
Address review comments
zhanggbj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,138 @@ | ||
| /* | ||
| Copyright 2025 The Kubernetes Authors. | ||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| package vmware | ||
|
|
||
| import ( | ||
| "context" | ||
|
|
||
| vmoprv1 "github.com/vmware-tanzu/vm-operator/api/v1alpha2" | ||
| apitypes "k8s.io/apimachinery/pkg/types" | ||
| clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta2" | ||
| "sigs.k8s.io/cluster-api/util/predicates" | ||
| ctrl "sigs.k8s.io/controller-runtime" | ||
| ctrlbldr "sigs.k8s.io/controller-runtime/pkg/builder" | ||
| ctrlclient "sigs.k8s.io/controller-runtime/pkg/client" | ||
| "sigs.k8s.io/controller-runtime/pkg/controller" | ||
| "sigs.k8s.io/controller-runtime/pkg/event" | ||
| "sigs.k8s.io/controller-runtime/pkg/handler" | ||
| "sigs.k8s.io/controller-runtime/pkg/manager" | ||
| "sigs.k8s.io/controller-runtime/pkg/predicate" | ||
| "sigs.k8s.io/controller-runtime/pkg/reconcile" | ||
|
|
||
| vmwarev1 "sigs.k8s.io/cluster-api-provider-vsphere/apis/vmware/v1beta1" | ||
| capvcontext "sigs.k8s.io/cluster-api-provider-vsphere/pkg/context" | ||
| ) | ||
|
|
||
| // +kubebuilder:rbac:groups=cluster.x-k8s.io,resources=clusters,verbs=get;list;watch | ||
| // +kubebuilder:rbac:groups=cluster.x-k8s.io,resources=clusters/status,verbs=get | ||
| // +kubebuilder:rbac:groups=vmoperator.vmware.com,resources=virtualmachinegroups,verbs=get;list;watch;create;update;patch;delete | ||
| // +kubebuilder:rbac:groups=vmoperator.vmware.com,resources=virtualmachinegroups/status,verbs=get | ||
| // +kubebuilder:rbac:groups=vmware.infrastructure.cluster.x-k8s.io,resources=vspheremachines,verbs=get;list;watch | ||
| // +kubebuilder:rbac:groups=cluster.x-k8s.io,resources=machinedeployments,verbs=get;list;watch | ||
| // +kubebuilder:rbac:groups=cluster.x-k8s.io,resources=machines,verbs=get;list;watch | ||
|
|
||
| // AddVirtualMachineGroupControllerToManager adds the VirtualMachineGroup controller to the provided | ||
| // manager. | ||
| func AddVirtualMachineGroupControllerToManager(ctx context.Context, controllerManagerCtx *capvcontext.ControllerManagerContext, mgr manager.Manager, options controller.Options) error { | ||
| predicateLog := ctrl.LoggerFrom(ctx).WithValues("controller", "virtualmachinegroup") | ||
|
|
||
| reconciler := &VirtualMachineGroupReconciler{ | ||
| Client: controllerManagerCtx.Client, | ||
| Recorder: mgr.GetEventRecorderFor("virtualmachinegroup-controller"), | ||
| } | ||
|
|
||
| // Predicate: only allow VMG with the cluster-name label. Ensures the controller only works on VMG objects created by CAPV. | ||
| hasClusterNameLabel := predicate.NewPredicateFuncs(func(obj ctrlclient.Object) bool { | ||
| labels := obj.GetLabels() | ||
| if labels == nil { | ||
| return false | ||
| } | ||
| _, ok := labels[clusterv1.ClusterNameLabel] | ||
| return ok | ||
| }) | ||
|
|
||
| builder := ctrl.NewControllerManagedBy(mgr). | ||
| For(&vmoprv1.VirtualMachineGroup{}). | ||
zhanggbj marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| WithOptions(options). | ||
| WithEventFilter(hasClusterNameLabel). | ||
| Watches( | ||
| &clusterv1.Cluster{}, | ||
| handler.EnqueueRequestsFromMapFunc(reconciler.ClusterToVirtualMachineGroup), | ||
| ). | ||
| Watches( | ||
| &vmwarev1.VSphereMachine{}, | ||
| handler.EnqueueRequestsFromMapFunc(reconciler.VSphereMachineToVirtualMachineGroup), | ||
| ctrlbldr.WithPredicates( | ||
| predicate.Funcs{ | ||
| UpdateFunc: func(event.UpdateEvent) bool { return false }, | ||
| CreateFunc: func(event.CreateEvent) bool { return true }, | ||
| DeleteFunc: func(event.DeleteEvent) bool { return true }, | ||
| GenericFunc: func(event.GenericEvent) bool { return false }, | ||
| }), | ||
| ). | ||
| WithEventFilter(predicates.ResourceHasFilterLabel(mgr.GetScheme(), predicateLog, controllerManagerCtx.WatchFilterValue)) | ||
|
|
||
| return builder.Complete(reconciler) | ||
| } | ||
|
|
||
| // ClusterToVirtualMachineGroup maps Cluster events to VirtualMachineGroup reconcile requests. | ||
| func (r *VirtualMachineGroupReconciler) ClusterToVirtualMachineGroup(_ context.Context, a ctrlclient.Object) []reconcile.Request { | ||
| cluster, ok := a.(*clusterv1.Cluster) | ||
| if !ok { | ||
| return nil | ||
| } | ||
|
|
||
| // Always enqueue a request for the "would-be VMG" | ||
| return []reconcile.Request{{ | ||
| NamespacedName: apitypes.NamespacedName{ | ||
| Namespace: cluster.Namespace, | ||
| Name: cluster.Name, | ||
| }, | ||
| }} | ||
| } | ||
|
|
||
| // VSphereMachineToVirtualMachineGroup maps VSphereMachine events to VirtualMachineGroup reconcile requests. | ||
| // This handler only processes VSphereMachine objects for Day-2 operations when VMG could be found, ensuring | ||
| // VMG member list in sync with VSphereMachines. If no corresponding VMG is found, this is a no-op. | ||
| func (r *VirtualMachineGroupReconciler) VSphereMachineToVirtualMachineGroup(ctx context.Context, a ctrlclient.Object) []reconcile.Request { | ||
| vSphereMachine, ok := a.(*vmwarev1.VSphereMachine) | ||
| if !ok { | ||
| return nil | ||
| } | ||
|
|
||
| clusterName, ok := vSphereMachine.Labels[clusterv1.ClusterNameLabel] | ||
| if !ok || clusterName == "" { | ||
| return nil | ||
| } | ||
|
|
||
| vmg := &vmoprv1.VirtualMachineGroup{} | ||
| err := r.Client.Get(ctx, apitypes.NamespacedName{ | ||
| Namespace: vSphereMachine.Namespace, | ||
| Name: clusterName, | ||
| }, vmg) | ||
|
|
||
| if err != nil { | ||
| return nil | ||
| } | ||
zhanggbj marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| return []reconcile.Request{{ | ||
| NamespacedName: apitypes.NamespacedName{ | ||
| Namespace: vmg.Namespace, | ||
| Name: vmg.Name, | ||
| }, | ||
| }} | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's just add all verbs on the marker for virtualmachineservices/status so it will be grouped in the RBAC rule above
(not sure how much sense this permission even makes, nobody does a get status :), but let's align to what we do for the other vmop resources)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated virtualmachineservices/status with all markers so it could be grouped.
Question: Seems CAPV has permission it doesn't truly use. Should we keep the permission minimal just as what controller used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feel free to open a follow-up issue
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Filed an issue for tracking: #3681