@@ -25,8 +25,10 @@ import (
2525
2626 ignition "github.com/flatcar/ignition/config/v2_3"
2727 . "github.com/onsi/gomega"
28+ apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
2829 corev1 "k8s.io/api/core/v1"
2930 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
31+ "k8s.io/apimachinery/pkg/runtime"
3032 "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
3133 "k8s.io/apimachinery/pkg/types"
3234 bootstrapapi "k8s.io/cluster-bootstrap/token/api"
@@ -2787,8 +2789,23 @@ func TestKubeadmConfigReconciler_Reconcile_v1beta2_conditions(t *testing.T) {
27872789 condition := conditions .Get (newConfig , conditionType )
27882790 g .Expect (condition ).ToNot (BeNil (), "condition %s is missing" , conditionType )
27892791 g .Expect (condition .Status ).To (Equal (metav1 .ConditionTrue ))
2790- g .Expect (condition .Message ).To (BeEmpty ())
2792+ if conditionType == bootstrapv1 .KubeadmConfigControlPlaneKubernetesVersionAvailableCondition {
2793+ g .Expect (condition .Reason ).To (Equal (bootstrapv1 .KubeadmConfigControlPlaneKubernetesVersionFromMachineReason ))
2794+ g .Expect (condition .Message ).To (ContainSubstring ("Machine" ))
2795+ } else {
2796+ g .Expect (condition .Message ).To (BeEmpty ())
2797+ }
27912798 }
2799+ foundCPKubeVer := false
2800+ for _ , c := range newConfig .GetV1Beta1Conditions () {
2801+ if c .Type == bootstrapv1 .ControlPlaneKubernetesVersionAvailableV1Beta1Condition {
2802+ g .Expect (c .Status ).To (Equal (corev1 .ConditionTrue ))
2803+ g .Expect (c .Reason ).To (Equal (bootstrapv1 .ControlPlaneKubernetesVersionFromMachineV1Beta1Reason ))
2804+ foundCPKubeVer = true
2805+ break
2806+ }
2807+ }
2808+ g .Expect (foundCPKubeVer ).To (BeTrue ())
27922809 for _ , conditionType := range []string {clusterv1 .PausedCondition } {
27932810 condition := conditions .Get (newConfig , conditionType )
27942811 g .Expect (condition ).ToNot (BeNil (), "condition %s is missing" , conditionType )
@@ -2798,3 +2815,72 @@ func TestKubeadmConfigReconciler_Reconcile_v1beta2_conditions(t *testing.T) {
27982815 })
27992816 }
28002817}
2818+
2819+ func TestKubeadmConfigReconciler_Reconcile_v1beta2_conditions_ControlPlaneKubernetesVersionFromControlPlaneRef (t * testing.T ) {
2820+ g := NewWithT (t )
2821+ scheme := runtime .NewScheme ()
2822+ g .Expect (apiextensionsv1 .AddToScheme (scheme )).To (Succeed ())
2823+ g .Expect (clusterv1 .AddToScheme (scheme )).To (Succeed ())
2824+ g .Expect (bootstrapv1 .AddToScheme (scheme )).To (Succeed ())
2825+
2826+ clusterName := "my-cluster-cp"
2827+ cluster := builder .Cluster (metav1 .NamespaceDefault , clusterName ).Build ()
2828+ cluster .Status .Conditions = []metav1.Condition {{Type : clusterv1 .ClusterControlPlaneInitializedCondition , Status : metav1 .ConditionTrue }}
2829+ cluster .Status .Initialization .InfrastructureProvisioned = ptr .To (true )
2830+ cluster .Spec .ControlPlaneEndpoint = clusterv1.APIEndpoint {Host : "example.com" , Port : 6443 }
2831+ cluster .Spec .ControlPlaneRef = clusterv1.ContractVersionedObjectReference {
2832+ APIGroup : builder .ControlPlaneGroupVersion .Group ,
2833+ Kind : builder .TestControlPlaneKind ,
2834+ Name : "cp" ,
2835+ }
2836+ cp := builder .TestControlPlane (metav1 .NamespaceDefault , "cp" ).WithVersion (testSkewK8sVersion ).Build ()
2837+ crd := builder .TestControlPlaneCRD .DeepCopy ()
2838+
2839+ machine := builder .Machine (metav1 .NamespaceDefault , "my-machine" ).
2840+ WithVersion (testK8sVersion ).
2841+ WithClusterName (cluster .Name ).
2842+ WithBootstrapTemplate (bootstrapbuilder .KubeadmConfig (metav1 .NamespaceDefault , "" ).Unstructured ()).
2843+ Build ()
2844+ kubeadmConfig := newKubeadmConfig (metav1 .NamespaceDefault , "kubeadmconfig" )
2845+ kubeadmConfig .SetOwnerReferences ([]metav1.OwnerReference {{
2846+ APIVersion : clusterv1 .GroupVersion .String (),
2847+ Kind : "Machine" ,
2848+ Name : machine .Name ,
2849+ }})
2850+
2851+ objects := []client.Object {cluster , machine , kubeadmConfig , cp , crd }
2852+ objects = append (objects , createSecrets (t , cluster , kubeadmConfig )... )
2853+
2854+ myclient := fake .NewClientBuilder ().WithScheme (scheme ).WithObjects (objects ... ).WithStatusSubresource (& bootstrapv1.KubeadmConfig {}).Build ()
2855+
2856+ r := & KubeadmConfigReconciler {
2857+ Client : myclient ,
2858+ SecretCachingClient : myclient ,
2859+ ClusterCache : clustercache .NewFakeClusterCache (myclient , client.ObjectKey {Name : cluster .Name , Namespace : cluster .Namespace }),
2860+ KubeadmInitLock : & myInitLocker {},
2861+ }
2862+
2863+ key := client .ObjectKeyFromObject (kubeadmConfig )
2864+ _ , err := r .Reconcile (ctx , ctrl.Request {NamespacedName : key })
2865+ g .Expect (err ).ToNot (HaveOccurred ())
2866+
2867+ newConfig := & bootstrapv1.KubeadmConfig {}
2868+ g .Expect (myclient .Get (ctx , key , newConfig )).To (Succeed ())
2869+
2870+ c := conditions .Get (newConfig , bootstrapv1 .KubeadmConfigControlPlaneKubernetesVersionAvailableCondition )
2871+ g .Expect (c ).ToNot (BeNil ())
2872+ g .Expect (c .Status ).To (Equal (metav1 .ConditionTrue ))
2873+ g .Expect (c .Reason ).To (Equal (bootstrapv1 .KubeadmConfigControlPlaneKubernetesVersionFromControlPlaneReason ))
2874+ g .Expect (c .Message ).To (ContainSubstring ("control plane reference" ))
2875+
2876+ foundCPKubeVer := false
2877+ for _ , cond := range newConfig .GetV1Beta1Conditions () {
2878+ if cond .Type == bootstrapv1 .ControlPlaneKubernetesVersionAvailableV1Beta1Condition {
2879+ g .Expect (cond .Status ).To (Equal (corev1 .ConditionTrue ))
2880+ g .Expect (cond .Reason ).To (Equal (bootstrapv1 .ControlPlaneKubernetesVersionFromControlPlaneV1Beta1Reason ))
2881+ foundCPKubeVer = true
2882+ break
2883+ }
2884+ }
2885+ g .Expect (foundCPKubeVer ).To (BeTrue ())
2886+ }
0 commit comments