-
Notifications
You must be signed in to change notification settings - Fork 306
✨ 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
base: main
Are you sure you want to change the base?
Changes from 15 commits
fa60556
b52056f
72fad61
124623a
9f261d5
22d7db0
8474942
833cdb5
36c3550
189f6d2
8cc8e8a
2a21acc
947dffa
5847119
e3078c9
dc441f6
9cc5762
b981168
2ac47d4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,109 @@ | ||||||||
| /* | ||||||||
| 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"), | ||||||||
| } | ||||||||
|
|
||||||||
| builder := ctrl.NewControllerManagedBy(mgr). | ||||||||
| For(&clusterv1.Cluster{}). | ||||||||
| WithOptions(options). | ||||||||
| // Set the controller's name explicitly to virtualmachinegroup. | ||||||||
| Named("virtualmachinegroup"). | ||||||||
| Watches( | ||||||||
| &vmoprv1.VirtualMachineGroup{}, | ||||||||
| handler.EnqueueRequestForOwner(mgr.GetScheme(), reconciler.Client.RESTMapper(), &clusterv1.Cluster{}), | ||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
We have not been using this in CAPV up until now, but let's use it here to already improve this new reconciler (I have a task to follow-up for others soon'ish). Per default the reconciler will get resyncs from all informers. i.e. every 10m everything gets reconciled because of the Cluster resync and additionally every 10m everything gets reconciled because of the VirtualMachineGroup resync. In core CAPI we drop events from resyncs of secondary watches to avoid this issue (it's not needed for VSphereMachine below as we already drop all updates)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch. This help to reduce the resync noices. |
||||||||
| ). | ||||||||
| Watches( | ||||||||
| &vmwarev1.VSphereMachine{}, | ||||||||
| handler.EnqueueRequestsFromMapFunc(reconciler.VSphereMachineToCluster), | ||||||||
| 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) | ||||||||
| } | ||||||||
|
|
||||||||
| // VSphereMachineToCluster maps VSphereMachine events to Cluster 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) VSphereMachineToCluster(ctx context.Context, a ctrlclient.Object) []reconcile.Request { | ||||||||
zhanggbj marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||
| 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 | ||||||||
| } | ||||||||
|
||||||||
|
|
||||||||
| return []reconcile.Request{{ | ||||||||
| NamespacedName: apitypes.NamespacedName{ | ||||||||
| Namespace: vmg.Namespace, | ||||||||
| Name: vmg.Name, | ||||||||
| }, | ||||||||
| }} | ||||||||
| } | ||||||||
Uh oh!
There was an error while loading. Please reload this page.