@@ -27,10 +27,11 @@ import (
27
27
"github.com/siderolabs/talos/pkg/machinery/constants"
28
28
"gopkg.in/yaml.v2"
29
29
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"
30
32
"k8s.io/apimachinery/pkg/runtime"
31
- capiv1 "sigs.k8s.io/cluster-api/api/v1beta1 "
33
+ capiv1 "sigs.k8s.io/cluster-api/api/core/v1beta2 "
32
34
bsutil "sigs.k8s.io/cluster-api/bootstrap/util"
33
- expv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1"
34
35
"sigs.k8s.io/cluster-api/feature"
35
36
"sigs.k8s.io/cluster-api/util"
36
37
"sigs.k8s.io/cluster-api/util/annotations"
@@ -90,7 +91,7 @@ func (r *TalosConfigReconciler) SetupWithManager(ctx context.Context, mgr ctrl.M
90
91
91
92
if feature .Gates .Enabled (feature .MachinePool ) {
92
93
b = b .Watches (
93
- & expv1 .MachinePool {},
94
+ & capiv1 .MachinePool {},
94
95
handler .EnqueueRequestsFromMapFunc (r .MachinePoolToBootstrapMapFunc ),
95
96
).WithEventFilter (predicates .ResourceNotPausedAndHasFilterLabel (r .Scheme , ctrl .LoggerFrom (ctx ), r .WatchFilterValue ))
96
97
}
@@ -100,7 +101,7 @@ func (r *TalosConfigReconciler) SetupWithManager(ctx context.Context, mgr ctrl.M
100
101
handler .EnqueueRequestsFromMapFunc (r .ClusterToTalosConfigs ),
101
102
builder .WithPredicates (
102
103
predicates .All (r .Scheme , ctrl .LoggerFrom (ctx ),
103
- predicates .ClusterPausedTransitionsOrInfrastructureReady (r .Scheme , ctrl .LoggerFrom (ctx )),
104
+ predicates .ClusterPausedTransitionsOrInfrastructureProvisioned (r .Scheme , ctrl .LoggerFrom (ctx )),
104
105
predicates .ResourceHasFilterLabel (r .Scheme , ctrl .LoggerFrom (ctx ), r .WatchFilterValue ),
105
106
),
106
107
),
@@ -144,16 +145,12 @@ func (r *TalosConfigReconciler) Reconcile(ctx context.Context, req ctrl.Request)
144
145
// Always attempt to Patch the TalosConfig object and status after each reconciliation.
145
146
defer func () {
146
147
// 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 ))
152
149
153
150
patchOpts := []patch.Option {
154
151
patch.WithOwnedConditions {
155
- Conditions : []capiv1. ConditionType {
156
- bootstrapv1alpha3 .DataSecretAvailableCondition ,
152
+ Conditions : []string {
153
+ string ( bootstrapv1alpha3 .DataSecretAvailableCondition ) ,
157
154
},
158
155
},
159
156
}
@@ -223,24 +220,41 @@ func (r *TalosConfigReconciler) Reconcile(ctx context.Context, req ctrl.Request)
223
220
// bail super early if it's already ready
224
221
if config .Status .Ready {
225
222
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
+ })
227
227
228
228
// reconcile cluster-wide talosconfig
229
229
err = r .reconcileClientConfig (ctx , log , tcScope )
230
230
231
231
if err == nil {
232
- conditions .MarkTrue (config , bootstrapv1alpha3 .ClientConfigAvailableCondition )
232
+ conditions .Set (config , v1.Condition {
233
+ Type : bootstrapv1alpha3 .ClientConfigAvailableCondition ,
234
+ Status : metav1 .ConditionTrue ,
235
+ })
233
236
} 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
+ })
235
243
}
236
244
237
245
return ctrl.Result {}, err
238
246
}
239
247
240
248
// Wait patiently for the infrastructure to be ready
241
- if ! cluster . Status . InfrastructureReady {
249
+ if ! conditions . IsTrue ( cluster , string ( capiv1 . InfrastructureReadyV1Beta1Condition )) {
242
250
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
+ })
244
258
245
259
return ctrl.Result {}, nil
246
260
}
@@ -250,19 +264,31 @@ func (r *TalosConfigReconciler) Reconcile(ctx context.Context, req ctrl.Request)
250
264
if owner .DataSecretName () != nil && (! config .Status .Ready || config .Status .DataSecretName == nil ) {
251
265
config .Status .Ready = true
252
266
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
+ })
254
272
255
273
return ctrl.Result {}, nil
256
274
}
257
275
258
276
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
+ })
260
283
261
284
return ctrl.Result {}, err
262
285
}
263
286
264
287
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
+ })
266
292
267
293
return ctrl.Result {}, nil
268
294
}
@@ -353,7 +379,7 @@ func (r *TalosConfigReconciler) reconcileGenerate(ctx context.Context, tcScope *
353
379
// Packet acts a fool if you don't prepend #!talos to the userdata
354
380
// so we try to suss out if that's the type of machine/machinePool getting created.
355
381
if tcScope .ConfigOwner .IsMachinePool () {
356
- mp := & expv1 .MachinePool {}
382
+ mp := & capiv1 .MachinePool {}
357
383
if err := runtime .DefaultUnstructuredConverter .FromUnstructured (tcScope .ConfigOwner .Object , mp ); err != nil {
358
384
return err
359
385
}
@@ -461,25 +487,25 @@ func (r *TalosConfigReconciler) genConfigs(ctx context.Context, scope *TalosConf
461
487
// TrimPrefix returns the string unchanged if the prefix isn't present.
462
488
k8sVersion := constants .DefaultKubernetesVersion
463
489
if scope .ConfigOwner .IsMachinePool () {
464
- mp := & expv1 .MachinePool {}
490
+ mp := & capiv1 .MachinePool {}
465
491
if err := runtime .DefaultUnstructuredConverter .FromUnstructured (scope .ConfigOwner .Object , mp ); err != nil {
466
492
return retBundle , err
467
493
}
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" )
470
496
}
471
497
} else {
472
498
machine := & capiv1.Machine {}
473
499
if err := runtime .DefaultUnstructuredConverter .FromUnstructured (scope .ConfigOwner .Object , machine ); err != nil {
474
500
return retBundle , err
475
501
}
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" )
478
504
}
479
505
}
480
506
481
507
clusterDNS := constants .DefaultDNSDomain
482
- if scope .Cluster .Spec .ClusterNetwork != nil && scope . Cluster . Spec . ClusterNetwork .ServiceDomain != "" {
508
+ if scope .Cluster .Spec .ClusterNetwork .ServiceDomain != "" {
483
509
clusterDNS = scope .Cluster .Spec .ClusterNetwork .ServiceDomain
484
510
}
485
511
@@ -538,10 +564,10 @@ func (r *TalosConfigReconciler) genConfigs(ctx context.Context, scope *TalosConf
538
564
return retBundle , err
539
565
}
540
566
541
- if scope .Cluster .Spec .ClusterNetwork != nil && scope . Cluster . Spec . ClusterNetwork . Pods != nil {
567
+ if scope .Cluster .Spec .ClusterNetwork . Pods . CIDRBlocks != nil {
542
568
data .RawV1Alpha1 ().ClusterConfig .ClusterNetwork .PodSubnet = scope .Cluster .Spec .ClusterNetwork .Pods .CIDRBlocks
543
569
}
544
- if scope .Cluster .Spec .ClusterNetwork != nil && scope . Cluster . Spec . ClusterNetwork . Services != nil {
570
+ if scope .Cluster .Spec .ClusterNetwork . Services . CIDRBlocks != nil {
545
571
data .RawV1Alpha1 ().ClusterConfig .ClusterNetwork .ServiceSubnet = scope .Cluster .Spec .ClusterNetwork .Services .CIDRBlocks
546
572
}
547
573
@@ -582,7 +608,7 @@ func (r *TalosConfigReconciler) MachineToBootstrapMapFunc(_ context.Context, o c
582
608
}
583
609
584
610
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 ( ) {
586
612
name := client.ObjectKey {Namespace : m .Namespace , Name : m .Spec .Bootstrap .ConfigRef .Name }
587
613
result = append (result , ctrl.Request {NamespacedName : name })
588
614
}
@@ -592,14 +618,14 @@ func (r *TalosConfigReconciler) MachineToBootstrapMapFunc(_ context.Context, o c
592
618
// MachinePoolToBootstrapMapFunc is a handler.ToRequestsFunc to be used to enqueue
593
619
// request for reconciliation of TalosConfig.
594
620
func (r * TalosConfigReconciler ) MachinePoolToBootstrapMapFunc (_ context.Context , o client.Object ) []ctrl.Request {
595
- m , ok := o .(* expv1 .MachinePool )
621
+ m , ok := o .(* capiv1 .MachinePool )
596
622
if ! ok {
597
623
panic (fmt .Sprintf ("Expected a MachinePool but got a %T" , o ))
598
624
}
599
625
600
626
result := []ctrl.Request {}
601
627
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 () {
603
629
name := client.ObjectKey {Namespace : m .Namespace , Name : configRef .Name }
604
630
result = append (result , ctrl.Request {NamespacedName : name })
605
631
}
@@ -629,22 +655,22 @@ func (r *TalosConfigReconciler) ClusterToTalosConfigs(ctx context.Context, o cli
629
655
}
630
656
631
657
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 () {
634
660
name := client.ObjectKey {Namespace : m .Namespace , Name : m .Spec .Bootstrap .ConfigRef .Name }
635
661
result = append (result , ctrl.Request {NamespacedName : name })
636
662
}
637
663
}
638
664
639
665
if feature .Gates .Enabled (feature .MachinePool ) {
640
- machinePoolList := & expv1 .MachinePoolList {}
666
+ machinePoolList := & capiv1 .MachinePoolList {}
641
667
if err := r .Client .List (ctx , machinePoolList , selectors ... ); err != nil {
642
668
return nil
643
669
}
644
670
645
671
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 () {
648
674
name := client.ObjectKey {Namespace : mp .Namespace , Name : mp .Spec .Template .Spec .Bootstrap .ConfigRef .Name }
649
675
result = append (result , ctrl.Request {NamespacedName : name })
650
676
}
0 commit comments