@@ -38,6 +38,7 @@ import (
38
38
ctrl "sigs.k8s.io/controller-runtime"
39
39
"sigs.k8s.io/controller-runtime/pkg/client"
40
40
"sigs.k8s.io/controller-runtime/pkg/client/fake"
41
+ "sigs.k8s.io/controller-runtime/pkg/handler"
41
42
"sigs.k8s.io/controller-runtime/pkg/runtime/log"
42
43
)
43
44
@@ -889,6 +890,45 @@ func TestCACertHashesAndUnsafeCAVerifySkip(t *testing.T) {
889
890
}
890
891
}
891
892
893
+ // If a cluster object changes then all associated KubeadmConfigs should be re-reconciled.
894
+ // This allows us to not requeue a kubeadm config while we wait for InfrastructureReady.
895
+ func TestKubeadmConfigReconciler_ClusterToKubeadmConfigs (t * testing.T ) {
896
+ cluster := newCluster ("my-cluster" )
897
+ objs := []runtime.Object {cluster }
898
+ expectedNames := []string {}
899
+ for i := 0 ; i < 3 ; i ++ {
900
+ m := newMachine (cluster , fmt .Sprintf ("my-machine-%d" , i ))
901
+ configName := fmt .Sprintf ("my-config-%d" , i )
902
+ c := newKubeadmConfig (m , configName )
903
+ expectedNames = append (expectedNames , configName )
904
+ objs = append (objs , m , c )
905
+ }
906
+ fakeClient := fake .NewFakeClientWithScheme (setupScheme (), objs ... )
907
+ reconciler := & KubeadmConfigReconciler {
908
+ Log : log .Log ,
909
+ Client : fakeClient ,
910
+ }
911
+ o := handler.MapObject {
912
+ Object : cluster ,
913
+ }
914
+ configs := reconciler .ClusterToKubeadmConfigs (o )
915
+ names := make ([]string , 3 )
916
+ for i := range configs {
917
+ names [i ] = configs [i ].Name
918
+ }
919
+ for _ , name := range expectedNames {
920
+ found := false
921
+ for _ , foundName := range names {
922
+ if foundName == name {
923
+ found = true
924
+ }
925
+ }
926
+ if ! found {
927
+ t .Fatalf ("did not find %s in %v" , name , names )
928
+ }
929
+ }
930
+ }
931
+
892
932
// test utils
893
933
894
934
// newCluster return a CAPI cluster object
@@ -920,7 +960,7 @@ func newMachine(cluster *clusterv1.Cluster, name string) *clusterv1.Machine {
920
960
Bootstrap : clusterv1.Bootstrap {
921
961
ConfigRef : & corev1.ObjectReference {
922
962
Kind : "KubeadmConfig" ,
923
- APIVersion : "v1alpha2" ,
963
+ APIVersion : bootstrapv1 . GroupVersion . String () ,
924
964
},
925
965
},
926
966
},
@@ -964,6 +1004,8 @@ func newKubeadmConfig(machine *clusterv1.Machine, name string) *bootstrapv1.Kube
964
1004
UID : types .UID (fmt .Sprintf ("%s uid" , machine .Name )),
965
1005
},
966
1006
}
1007
+ machine .Spec .Bootstrap .ConfigRef .Name = config .Name
1008
+ machine .Spec .Bootstrap .ConfigRef .Namespace = config .Namespace
967
1009
}
968
1010
return config
969
1011
}
0 commit comments