@@ -27,10 +27,11 @@ import (
2727 "github.com/siderolabs/talos/pkg/machinery/constants"
2828 "gopkg.in/yaml.v2"
2929 apierrors "k8s.io/apimachinery/pkg/api/errors"
30+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
31+ v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3032 "k8s.io/apimachinery/pkg/runtime"
31- capiv1 "sigs.k8s.io/cluster-api/api/v1beta1 "
33+ capiv1 "sigs.k8s.io/cluster-api/api/core/v1beta2 "
3234 bsutil "sigs.k8s.io/cluster-api/bootstrap/util"
33- expv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1"
3435 "sigs.k8s.io/cluster-api/feature"
3536 "sigs.k8s.io/cluster-api/util"
3637 "sigs.k8s.io/cluster-api/util/annotations"
@@ -90,7 +91,7 @@ func (r *TalosConfigReconciler) SetupWithManager(ctx context.Context, mgr ctrl.M
9091
9192 if feature .Gates .Enabled (feature .MachinePool ) {
9293 b = b .Watches (
93- & expv1 .MachinePool {},
94+ & capiv1 .MachinePool {},
9495 handler .EnqueueRequestsFromMapFunc (r .MachinePoolToBootstrapMapFunc ),
9596 ).WithEventFilter (predicates .ResourceNotPausedAndHasFilterLabel (r .Scheme , ctrl .LoggerFrom (ctx ), r .WatchFilterValue ))
9697 }
@@ -100,7 +101,7 @@ func (r *TalosConfigReconciler) SetupWithManager(ctx context.Context, mgr ctrl.M
100101 handler .EnqueueRequestsFromMapFunc (r .ClusterToTalosConfigs ),
101102 builder .WithPredicates (
102103 predicates .All (r .Scheme , ctrl .LoggerFrom (ctx ),
103- predicates .ClusterPausedTransitionsOrInfrastructureReady (r .Scheme , ctrl .LoggerFrom (ctx )),
104+ predicates .ClusterPausedTransitionsOrInfrastructureProvisioned (r .Scheme , ctrl .LoggerFrom (ctx )),
104105 predicates .ResourceHasFilterLabel (r .Scheme , ctrl .LoggerFrom (ctx ), r .WatchFilterValue ),
105106 ),
106107 ),
@@ -144,16 +145,12 @@ func (r *TalosConfigReconciler) Reconcile(ctx context.Context, req ctrl.Request)
144145 // Always attempt to Patch the TalosConfig object and status after each reconciliation.
145146 defer func () {
146147 // always update the readyCondition; the summary is represented using the "1 of x completed" notation.
147- conditions .SetSummary (config ,
148- conditions .WithConditions (
149- bootstrapv1alpha3 .DataSecretAvailableCondition ,
150- ),
151- )
148+ conditions .SetSummaryCondition (config , config , string (bootstrapv1alpha3 .DataSecretAvailableCondition ))
152149
153150 patchOpts := []patch.Option {
154151 patch.WithOwnedConditions {
155- Conditions : []capiv1. ConditionType {
156- bootstrapv1alpha3 .DataSecretAvailableCondition ,
152+ Conditions : []string {
153+ string ( bootstrapv1alpha3 .DataSecretAvailableCondition ) ,
157154 },
158155 },
159156 }
@@ -223,24 +220,41 @@ func (r *TalosConfigReconciler) Reconcile(ctx context.Context, req ctrl.Request)
223220 // bail super early if it's already ready
224221 if config .Status .Ready {
225222 log .Info ("ignoring an already ready config" )
226- conditions .MarkTrue (config , bootstrapv1alpha3 .DataSecretAvailableCondition )
223+ conditions .Set (config , v1.Condition {
224+ Type : bootstrapv1alpha3 .DataSecretAvailableCondition ,
225+ Status : metav1 .ConditionTrue ,
226+ })
227227
228228 // reconcile cluster-wide talosconfig
229229 err = r .reconcileClientConfig (ctx , log , tcScope )
230230
231231 if err == nil {
232- conditions .MarkTrue (config , bootstrapv1alpha3 .ClientConfigAvailableCondition )
232+ conditions .Set (config , v1.Condition {
233+ Type : bootstrapv1alpha3 .ClientConfigAvailableCondition ,
234+ Status : metav1 .ConditionTrue ,
235+ })
233236 } else {
234- conditions .MarkFalse (config , bootstrapv1alpha3 .ClientConfigAvailableCondition , bootstrapv1alpha3 .ClientConfigGenerationFailedReason , capiv1 .ConditionSeverityError , "talosconfig generation failure: %s" , err )
237+ conditions .Set (config , v1.Condition {
238+ Type : bootstrapv1alpha3 .ClientConfigAvailableCondition ,
239+ Status : metav1 .ConditionFalse ,
240+ Reason : bootstrapv1alpha3 .ClientConfigGenerationFailedReason ,
241+ Message : fmt .Sprintf ("talosconfig generation failure: %s" , err ),
242+ })
235243 }
236244
237245 return ctrl.Result {}, err
238246 }
239247
240248 // Wait patiently for the infrastructure to be ready
241- if ! cluster . Status . InfrastructureReady {
249+ if ! conditions . IsTrue ( cluster , string ( capiv1 . InfrastructureReadyV1Beta1Condition )) {
242250 log .Info ("Infrastructure is not ready, waiting until ready." )
243- conditions .MarkFalse (config , bootstrapv1alpha3 .DataSecretAvailableCondition , bootstrapv1alpha3 .WaitingForClusterInfrastructureReason , capiv1 .ConditionSeverityInfo , "" )
251+
252+ conditions .Set (config , v1.Condition {
253+ Type : bootstrapv1alpha3 .DataSecretAvailableCondition ,
254+ Status : metav1 .ConditionFalse ,
255+ Reason : bootstrapv1alpha3 .WaitingForClusterInfrastructureReason ,
256+ Message : "Waiting for the cluster infrastructure to be ready" ,
257+ })
244258
245259 return ctrl.Result {}, nil
246260 }
@@ -250,19 +264,31 @@ func (r *TalosConfigReconciler) Reconcile(ctx context.Context, req ctrl.Request)
250264 if owner .DataSecretName () != nil && (! config .Status .Ready || config .Status .DataSecretName == nil ) {
251265 config .Status .Ready = true
252266 config .Status .DataSecretName = owner .DataSecretName ()
253- conditions .MarkTrue (config , bootstrapv1alpha3 .DataSecretAvailableCondition )
267+
268+ conditions .Set (config , v1.Condition {
269+ Type : bootstrapv1alpha3 .DataSecretAvailableCondition ,
270+ Status : metav1 .ConditionTrue ,
271+ })
254272
255273 return ctrl.Result {}, nil
256274 }
257275
258276 if err = r .reconcileGenerate (ctx , tcScope ); err != nil {
259- conditions .MarkFalse (config , bootstrapv1alpha3 .DataSecretAvailableCondition , bootstrapv1alpha3 .DataSecretGenerationFailedReason , capiv1 .ConditionSeverityError , "%s" , err .Error ())
277+ conditions .Set (config , v1.Condition {
278+ Type : bootstrapv1alpha3 .DataSecretAvailableCondition ,
279+ Status : metav1 .ConditionFalse ,
280+ Reason : bootstrapv1alpha3 .DataSecretGenerationFailedReason ,
281+ Message : fmt .Sprintf ("Data secret generation failed: %s" , err ),
282+ })
260283
261284 return ctrl.Result {}, err
262285 }
263286
264287 config .Status .Ready = true
265- conditions .MarkTrue (config , bootstrapv1alpha3 .DataSecretAvailableCondition )
288+ conditions .Set (config , v1.Condition {
289+ Type : bootstrapv1alpha3 .DataSecretAvailableCondition ,
290+ Status : metav1 .ConditionTrue ,
291+ })
266292
267293 return ctrl.Result {}, nil
268294}
@@ -353,7 +379,7 @@ func (r *TalosConfigReconciler) reconcileGenerate(ctx context.Context, tcScope *
353379 // Packet acts a fool if you don't prepend #!talos to the userdata
354380 // so we try to suss out if that's the type of machine/machinePool getting created.
355381 if tcScope .ConfigOwner .IsMachinePool () {
356- mp := & expv1 .MachinePool {}
382+ mp := & capiv1 .MachinePool {}
357383 if err := runtime .DefaultUnstructuredConverter .FromUnstructured (tcScope .ConfigOwner .Object , mp ); err != nil {
358384 return err
359385 }
@@ -461,25 +487,25 @@ func (r *TalosConfigReconciler) genConfigs(ctx context.Context, scope *TalosConf
461487 // TrimPrefix returns the string unchanged if the prefix isn't present.
462488 k8sVersion := constants .DefaultKubernetesVersion
463489 if scope .ConfigOwner .IsMachinePool () {
464- mp := & expv1 .MachinePool {}
490+ mp := & capiv1 .MachinePool {}
465491 if err := runtime .DefaultUnstructuredConverter .FromUnstructured (scope .ConfigOwner .Object , mp ); err != nil {
466492 return retBundle , err
467493 }
468- if mp .Spec .Template .Spec .Version != nil {
469- k8sVersion = strings .TrimPrefix (* mp .Spec .Template .Spec .Version , "v" )
494+ if mp .Spec .Template .Spec .Version != "" {
495+ k8sVersion = strings .TrimPrefix (mp .Spec .Template .Spec .Version , "v" )
470496 }
471497 } else {
472498 machine := & capiv1.Machine {}
473499 if err := runtime .DefaultUnstructuredConverter .FromUnstructured (scope .ConfigOwner .Object , machine ); err != nil {
474500 return retBundle , err
475501 }
476- if machine .Spec .Version != nil {
477- k8sVersion = strings .TrimPrefix (* machine .Spec .Version , "v" )
502+ if machine .Spec .Version != "" {
503+ k8sVersion = strings .TrimPrefix (machine .Spec .Version , "v" )
478504 }
479505 }
480506
481507 clusterDNS := constants .DefaultDNSDomain
482- if scope .Cluster .Spec .ClusterNetwork != nil && scope . Cluster . Spec . ClusterNetwork .ServiceDomain != "" {
508+ if scope .Cluster .Spec .ClusterNetwork .ServiceDomain != "" {
483509 clusterDNS = scope .Cluster .Spec .ClusterNetwork .ServiceDomain
484510 }
485511
@@ -538,10 +564,10 @@ func (r *TalosConfigReconciler) genConfigs(ctx context.Context, scope *TalosConf
538564 return retBundle , err
539565 }
540566
541- if scope .Cluster .Spec .ClusterNetwork != nil && scope . Cluster . Spec . ClusterNetwork . Pods != nil {
567+ if scope .Cluster .Spec .ClusterNetwork . Pods . CIDRBlocks != nil {
542568 data .RawV1Alpha1 ().ClusterConfig .ClusterNetwork .PodSubnet = scope .Cluster .Spec .ClusterNetwork .Pods .CIDRBlocks
543569 }
544- if scope .Cluster .Spec .ClusterNetwork != nil && scope . Cluster . Spec . ClusterNetwork . Services != nil {
570+ if scope .Cluster .Spec .ClusterNetwork . Services . CIDRBlocks != nil {
545571 data .RawV1Alpha1 ().ClusterConfig .ClusterNetwork .ServiceSubnet = scope .Cluster .Spec .ClusterNetwork .Services .CIDRBlocks
546572 }
547573
@@ -582,7 +608,7 @@ func (r *TalosConfigReconciler) MachineToBootstrapMapFunc(_ context.Context, o c
582608 }
583609
584610 result := []ctrl.Request {}
585- if m .Spec .Bootstrap .ConfigRef != nil && m .Spec .Bootstrap .ConfigRef .GroupVersionKind () == bootstrapv1alpha3 .GroupVersion .WithKind ("TalosConfig" ) {
611+ if m .Spec .Bootstrap .ConfigRef . IsDefined () && m .Spec .Bootstrap .ConfigRef .GroupKind () == bootstrapv1alpha3 .GroupVersion .WithKind ("TalosConfig" ). GroupKind ( ) {
586612 name := client.ObjectKey {Namespace : m .Namespace , Name : m .Spec .Bootstrap .ConfigRef .Name }
587613 result = append (result , ctrl.Request {NamespacedName : name })
588614 }
@@ -592,14 +618,14 @@ func (r *TalosConfigReconciler) MachineToBootstrapMapFunc(_ context.Context, o c
592618// MachinePoolToBootstrapMapFunc is a handler.ToRequestsFunc to be used to enqueue
593619// request for reconciliation of TalosConfig.
594620func (r * TalosConfigReconciler ) MachinePoolToBootstrapMapFunc (_ context.Context , o client.Object ) []ctrl.Request {
595- m , ok := o .(* expv1 .MachinePool )
621+ m , ok := o .(* capiv1 .MachinePool )
596622 if ! ok {
597623 panic (fmt .Sprintf ("Expected a MachinePool but got a %T" , o ))
598624 }
599625
600626 result := []ctrl.Request {}
601627 configRef := m .Spec .Template .Spec .Bootstrap .ConfigRef
602- if configRef != nil && configRef . GroupVersionKind () .GroupKind () == bootstrapv1alpha3 .GroupVersion .WithKind ("TalosConfig" ).GroupKind () {
628+ if configRef . IsDefined () && configRef .GroupKind () == bootstrapv1alpha3 .GroupVersion .WithKind ("TalosConfig" ).GroupKind () {
603629 name := client.ObjectKey {Namespace : m .Namespace , Name : configRef .Name }
604630 result = append (result , ctrl.Request {NamespacedName : name })
605631 }
@@ -629,22 +655,22 @@ func (r *TalosConfigReconciler) ClusterToTalosConfigs(ctx context.Context, o cli
629655 }
630656
631657 for _ , m := range machineList .Items {
632- if m .Spec .Bootstrap .ConfigRef != nil &&
633- m .Spec .Bootstrap .ConfigRef .GroupVersionKind (). GroupKind () == bootstrapv1alpha3 .GroupVersion .WithKind ("TalosConfig" ).GroupKind () {
658+ if m .Spec .Bootstrap .ConfigRef . IsDefined () &&
659+ m .Spec .Bootstrap .ConfigRef .GroupKind () == bootstrapv1alpha3 .GroupVersion .WithKind ("TalosConfig" ).GroupKind () {
634660 name := client.ObjectKey {Namespace : m .Namespace , Name : m .Spec .Bootstrap .ConfigRef .Name }
635661 result = append (result , ctrl.Request {NamespacedName : name })
636662 }
637663 }
638664
639665 if feature .Gates .Enabled (feature .MachinePool ) {
640- machinePoolList := & expv1 .MachinePoolList {}
666+ machinePoolList := & capiv1 .MachinePoolList {}
641667 if err := r .Client .List (ctx , machinePoolList , selectors ... ); err != nil {
642668 return nil
643669 }
644670
645671 for _ , mp := range machinePoolList .Items {
646- if mp .Spec .Template .Spec .Bootstrap .ConfigRef != nil &&
647- mp .Spec .Template .Spec .Bootstrap .ConfigRef .GroupVersionKind (). GroupKind () == bootstrapv1alpha3 .GroupVersion .WithKind ("TalosConfig" ).GroupKind () {
672+ if mp .Spec .Template .Spec .Bootstrap .ConfigRef . IsDefined () &&
673+ mp .Spec .Template .Spec .Bootstrap .ConfigRef .GroupKind () == bootstrapv1alpha3 .GroupVersion .WithKind ("TalosConfig" ).GroupKind () {
648674 name := client.ObjectKey {Namespace : mp .Namespace , Name : mp .Spec .Template .Spec .Bootstrap .ConfigRef .Name }
649675 result = append (result , ctrl.Request {NamespacedName : name })
650676 }
0 commit comments