@@ -18,12 +18,15 @@ package controllers
1818
1919import (
2020 "context"
21+ "reflect"
2122 "time"
2223
2324 "github.com/pkg/errors"
2425 corev1 "k8s.io/api/core/v1"
2526 apierrors "k8s.io/apimachinery/pkg/api/errors"
27+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2628 "k8s.io/apimachinery/pkg/runtime"
29+ "k8s.io/apimachinery/pkg/runtime/schema"
2730 kerrors "k8s.io/apimachinery/pkg/util/errors"
2831 "k8s.io/client-go/tools/record"
2932 infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1"
6063 Timeouts reconciler.Timeouts
6164 WatchFilterValue string
6265 createAzureMachinePoolService azureMachinePoolServiceCreator
66+ BootstrapConfigGVK schema.GroupVersionKind
6367 }
6468
6569 // annotationReaderWriter provides an interface to read and write annotations.
@@ -72,12 +76,20 @@ type (
7276type azureMachinePoolServiceCreator func (machinePoolScope * scope.MachinePoolScope ) (* azureMachinePoolService , error )
7377
7478// NewAzureMachinePoolReconciler returns a new AzureMachinePoolReconciler instance.
75- func NewAzureMachinePoolReconciler (client client.Client , recorder record.EventRecorder , timeouts reconciler.Timeouts , watchFilterValue string ) * AzureMachinePoolReconciler {
79+ func NewAzureMachinePoolReconciler (client client.Client , recorder record.EventRecorder , timeouts reconciler.Timeouts , watchFilterValue , bootstrapConfigGVK string ) * AzureMachinePoolReconciler {
80+ gvk := schema .FromAPIVersionAndKind (kubeadmv1 .GroupVersion .String (), reflect .TypeFor [kubeadmv1.KubeadmConfig ]().Name ())
81+ userGVK , _ := schema .ParseKindArg (bootstrapConfigGVK )
82+
83+ if userGVK != nil {
84+ gvk = * userGVK
85+ }
86+
7687 ampr := & AzureMachinePoolReconciler {
77- Client : client ,
78- Recorder : recorder ,
79- Timeouts : timeouts ,
80- WatchFilterValue : watchFilterValue ,
88+ Client : client ,
89+ Recorder : recorder ,
90+ Timeouts : timeouts ,
91+ WatchFilterValue : watchFilterValue ,
92+ BootstrapConfigGVK : gvk ,
8193 }
8294
8395 ampr .createAzureMachinePoolService = newAzureMachinePoolService
@@ -108,6 +120,8 @@ func (ampr *AzureMachinePoolReconciler) SetupWithManager(ctx context.Context, mg
108120 return errors .Wrapf (err , "failed to create AzureManagedCluster to AzureMachinePools mapper" )
109121 }
110122
123+ config := & metav1.PartialObjectMetadata {}
124+ config .SetGroupVersionKind (ampr .BootstrapConfigGVK )
111125 c , err := ctrl .NewControllerManagedBy (mgr ).
112126 WithOptions (options .Options ).
113127 For (& infrav1exp.AzureMachinePool {}).
@@ -127,10 +141,10 @@ func (ampr *AzureMachinePoolReconciler) SetupWithManager(ctx context.Context, mg
127141 & infrav1.AzureManagedControlPlane {},
128142 handler .EnqueueRequestsFromMapFunc (azureManagedControlPlaneMapper ),
129143 ).
130- // watch for changes in KubeadmConfig to sync bootstrap token
144+ // watch for changes in KubeadmConfig (or any BootstrapConfig) to sync bootstrap token
131145 Watches (
132- & kubeadmv1. KubeadmConfig {} ,
133- handler .EnqueueRequestsFromMapFunc (KubeadmConfigToInfrastructureMapFunc (ctx , ampr .Client , log )),
146+ config ,
147+ handler .EnqueueRequestsFromMapFunc (BootstrapperConfigToInfrastructureMapFunc (ctx , ampr .Client , log )),
134148 builder .WithPredicates (predicate.ResourceVersionChangedPredicate {}),
135149 ).
136150 Build (r )
0 commit comments