@@ -56,6 +56,7 @@ import (
56
56
"sigs.k8s.io/cluster-api/internal/util/taints"
57
57
"sigs.k8s.io/cluster-api/util"
58
58
"sigs.k8s.io/cluster-api/util/conditions"
59
+ v1beta2conditions "sigs.k8s.io/cluster-api/util/conditions/v1beta2"
59
60
clog "sigs.k8s.io/cluster-api/util/log"
60
61
"sigs.k8s.io/cluster-api/util/patch"
61
62
"sigs.k8s.io/cluster-api/util/paused"
@@ -229,8 +230,39 @@ func (r *KubeadmConfigReconciler) Reconcile(ctx context.Context, req ctrl.Reques
229
230
bootstrapv1 .CertificatesAvailableCondition ,
230
231
),
231
232
)
233
+ if err := v1beta2conditions .SetSummaryCondition (config , config , bootstrapv1 .KubeadmConfigReadyV1Beta2Condition ,
234
+ v1beta2conditions.ForConditionTypes {
235
+ bootstrapv1 .KubeadmConfigDataSecretAvailableV1Beta2Condition ,
236
+ bootstrapv1 .KubeadmConfigCertificatesAvailableV1Beta2Condition ,
237
+ },
238
+ // Using a custom merge strategy to override reasons applied during merge and to ignore some
239
+ // info message so the ready condition aggregation in other resources is less noisy.
240
+ v1beta2conditions.CustomMergeStrategy {
241
+ MergeStrategy : v1beta2conditions .DefaultMergeStrategy (
242
+ // Use custom reasons.
243
+ v1beta2conditions .ComputeReasonFunc (v1beta2conditions .GetDefaultComputeMergeReasonFunc (
244
+ bootstrapv1 .KubeadmConfigNotReadyV1Beta2Reason ,
245
+ bootstrapv1 .KubeadmConfigReadyUnknownV1Beta2Reason ,
246
+ bootstrapv1 .KubeadmConfigReadyV1Beta2Reason ,
247
+ )),
248
+ ),
249
+ },
250
+ ); err != nil {
251
+ rerr = kerrors .NewAggregate ([]error {rerr , err })
252
+ }
232
253
// Patch ObservedGeneration only if the reconciliation completed successfully
233
- patchOpts := []patch.Option {}
254
+ patchOpts := []patch.Option {
255
+ patch.WithOwnedConditions {Conditions : []clusterv1.ConditionType {
256
+ clusterv1 .ReadyCondition ,
257
+ bootstrapv1 .DataSecretAvailableCondition ,
258
+ bootstrapv1 .CertificatesAvailableCondition ,
259
+ }},
260
+ patch.WithOwnedV1Beta2Conditions {Conditions : []string {
261
+ bootstrapv1 .KubeadmConfigReadyV1Beta2Condition ,
262
+ bootstrapv1 .KubeadmConfigDataSecretAvailableV1Beta2Condition ,
263
+ bootstrapv1 .KubeadmConfigCertificatesAvailableV1Beta2Condition ,
264
+ }},
265
+ }
234
266
if rerr == nil {
235
267
patchOpts = append (patchOpts , patch.WithStatusObservedGeneration {})
236
268
}
@@ -264,13 +296,24 @@ func (r *KubeadmConfigReconciler) reconcile(ctx context.Context, scope *Scope, c
264
296
case ! cluster .Status .InfrastructureReady :
265
297
log .Info ("Cluster infrastructure is not ready, waiting" )
266
298
conditions .MarkFalse (config , bootstrapv1 .DataSecretAvailableCondition , bootstrapv1 .WaitingForClusterInfrastructureReason , clusterv1 .ConditionSeverityInfo , "" )
299
+ v1beta2conditions .Set (scope .Config , metav1.Condition {
300
+ Type : bootstrapv1 .KubeadmConfigDataSecretAvailableV1Beta2Condition ,
301
+ Status : metav1 .ConditionFalse ,
302
+ Reason : bootstrapv1 .KubeadmConfigDataSecretNotAvailableV1Beta2Reason ,
303
+ Message : "Waiting for Cluster status.infrastructureReady to be true" ,
304
+ })
267
305
return ctrl.Result {}, nil
268
306
// Reconcile status for machines that already have a secret reference, but our status isn't up to date.
269
307
// This case solves the pivoting scenario (or a backup restore) which doesn't preserve the status subresource on objects.
270
308
case configOwner .DataSecretName () != nil && (! config .Status .Ready || config .Status .DataSecretName == nil ):
271
309
config .Status .Ready = true
272
310
config .Status .DataSecretName = configOwner .DataSecretName ()
273
311
conditions .MarkTrue (config , bootstrapv1 .DataSecretAvailableCondition )
312
+ v1beta2conditions .Set (scope .Config , metav1.Condition {
313
+ Type : bootstrapv1 .KubeadmConfigDataSecretAvailableV1Beta2Condition ,
314
+ Status : metav1 .ConditionTrue ,
315
+ Reason : bootstrapv1 .KubeadmConfigDataSecretAvailableV1Beta2Reason ,
316
+ })
274
317
return ctrl.Result {}, nil
275
318
// Status is ready means a config has been generated.
276
319
case config .Status .Ready :
@@ -402,6 +445,12 @@ func (r *KubeadmConfigReconciler) handleClusterNotInitialized(ctx context.Contex
402
445
// using the DataSecretGeneratedFailedReason
403
446
if conditions .GetReason (scope .Config , bootstrapv1 .DataSecretAvailableCondition ) != bootstrapv1 .DataSecretGenerationFailedReason {
404
447
conditions .MarkFalse (scope .Config , bootstrapv1 .DataSecretAvailableCondition , clusterv1 .WaitingForControlPlaneAvailableReason , clusterv1 .ConditionSeverityInfo , "" )
448
+ v1beta2conditions .Set (scope .Config , metav1.Condition {
449
+ Type : bootstrapv1 .KubeadmConfigDataSecretAvailableV1Beta2Condition ,
450
+ Status : metav1 .ConditionFalse ,
451
+ Reason : bootstrapv1 .KubeadmConfigDataSecretNotAvailableV1Beta2Reason ,
452
+ Message : "Waiting for Cluster control plane to be initialized" ,
453
+ })
405
454
}
406
455
407
456
// if it's NOT a control plane machine, requeue
@@ -505,10 +554,21 @@ func (r *KubeadmConfigReconciler) handleClusterNotInitialized(ctx context.Contex
505
554
}
506
555
if err != nil {
507
556
conditions .MarkFalse (scope .Config , bootstrapv1 .CertificatesAvailableCondition , bootstrapv1 .CertificatesGenerationFailedReason , clusterv1 .ConditionSeverityWarning , err .Error ())
557
+ v1beta2conditions .Set (scope .Config , metav1.Condition {
558
+ Type : bootstrapv1 .KubeadmConfigCertificatesAvailableV1Beta2Condition ,
559
+ Status : metav1 .ConditionUnknown ,
560
+ Reason : bootstrapv1 .KubeadmConfigCertificatesAvailableInternalErrorV1Beta2Reason ,
561
+ Message : "Please check controller logs for errors" ,
562
+ })
508
563
return ctrl.Result {}, err
509
564
}
510
565
511
566
conditions .MarkTrue (scope .Config , bootstrapv1 .CertificatesAvailableCondition )
567
+ v1beta2conditions .Set (scope .Config , metav1.Condition {
568
+ Type : bootstrapv1 .KubeadmConfigCertificatesAvailableV1Beta2Condition ,
569
+ Status : metav1 .ConditionTrue ,
570
+ Reason : bootstrapv1 .KubeadmConfigCertificatesAvailableV1Beta2Reason ,
571
+ })
512
572
513
573
verbosityFlag := ""
514
574
if scope .Config .Spec .Verbosity != nil {
@@ -518,12 +578,24 @@ func (r *KubeadmConfigReconciler) handleClusterNotInitialized(ctx context.Contex
518
578
files , err := r .resolveFiles (ctx , scope .Config )
519
579
if err != nil {
520
580
conditions .MarkFalse (scope .Config , bootstrapv1 .DataSecretAvailableCondition , bootstrapv1 .DataSecretGenerationFailedReason , clusterv1 .ConditionSeverityWarning , err .Error ())
581
+ v1beta2conditions .Set (scope .Config , metav1.Condition {
582
+ Type : bootstrapv1 .KubeadmConfigDataSecretAvailableV1Beta2Condition ,
583
+ Status : metav1 .ConditionFalse ,
584
+ Reason : bootstrapv1 .KubeadmConfigDataSecretNotAvailableV1Beta2Reason ,
585
+ Message : "Failed to read content from secrets for spec.files" ,
586
+ })
521
587
return ctrl.Result {}, err
522
588
}
523
589
524
590
users , err := r .resolveUsers (ctx , scope .Config )
525
591
if err != nil {
526
592
conditions .MarkFalse (scope .Config , bootstrapv1 .DataSecretAvailableCondition , bootstrapv1 .DataSecretGenerationFailedReason , clusterv1 .ConditionSeverityWarning , err .Error ())
593
+ v1beta2conditions .Set (scope .Config , metav1.Condition {
594
+ Type : bootstrapv1 .KubeadmConfigDataSecretAvailableV1Beta2Condition ,
595
+ Status : metav1 .ConditionFalse ,
596
+ Reason : bootstrapv1 .KubeadmConfigDataSecretNotAvailableV1Beta2Reason ,
597
+ Message : "Failed to read password from secrets for spec.users" ,
598
+ })
527
599
return ctrl.Result {}, err
528
600
}
529
601
@@ -580,13 +652,30 @@ func (r *KubeadmConfigReconciler) joinWorker(ctx context.Context, scope *Scope)
580
652
)
581
653
if err != nil {
582
654
conditions .MarkFalse (scope .Config , bootstrapv1 .CertificatesAvailableCondition , bootstrapv1 .CertificatesCorruptedReason , clusterv1 .ConditionSeverityError , err .Error ())
655
+ v1beta2conditions .Set (scope .Config , metav1.Condition {
656
+ Type : bootstrapv1 .KubeadmConfigCertificatesAvailableV1Beta2Condition ,
657
+ Status : metav1 .ConditionUnknown ,
658
+ Reason : bootstrapv1 .KubeadmConfigCertificatesAvailableInternalErrorV1Beta2Reason ,
659
+ Message : "Please check controller logs for errors" ,
660
+ })
583
661
return ctrl.Result {}, err
584
662
}
585
663
if err := certificates .EnsureAllExist (); err != nil {
586
664
conditions .MarkFalse (scope .Config , bootstrapv1 .CertificatesAvailableCondition , bootstrapv1 .CertificatesCorruptedReason , clusterv1 .ConditionSeverityError , err .Error ())
665
+ v1beta2conditions .Set (scope .Config , metav1.Condition {
666
+ Type : bootstrapv1 .KubeadmConfigCertificatesAvailableV1Beta2Condition ,
667
+ Status : metav1 .ConditionUnknown ,
668
+ Reason : bootstrapv1 .KubeadmConfigCertificatesAvailableInternalErrorV1Beta2Reason ,
669
+ Message : "Please check controller logs for errors" ,
670
+ })
587
671
return ctrl.Result {}, err
588
672
}
589
673
conditions .MarkTrue (scope .Config , bootstrapv1 .CertificatesAvailableCondition )
674
+ v1beta2conditions .Set (scope .Config , metav1.Condition {
675
+ Type : bootstrapv1 .KubeadmConfigCertificatesAvailableV1Beta2Condition ,
676
+ Status : metav1 .ConditionTrue ,
677
+ Reason : bootstrapv1 .KubeadmConfigCertificatesAvailableV1Beta2Reason ,
678
+ })
590
679
591
680
// Ensure that joinConfiguration.Discovery is properly set for joining node on the current cluster.
592
681
if res , err := r .reconcileDiscovery (ctx , scope .Cluster , scope .Config , certificates ); err != nil {
@@ -630,19 +719,37 @@ func (r *KubeadmConfigReconciler) joinWorker(ctx context.Context, scope *Scope)
630
719
files , err := r .resolveFiles (ctx , scope .Config )
631
720
if err != nil {
632
721
conditions .MarkFalse (scope .Config , bootstrapv1 .DataSecretAvailableCondition , bootstrapv1 .DataSecretGenerationFailedReason , clusterv1 .ConditionSeverityWarning , err .Error ())
722
+ v1beta2conditions .Set (scope .Config , metav1.Condition {
723
+ Type : bootstrapv1 .KubeadmConfigDataSecretAvailableV1Beta2Condition ,
724
+ Status : metav1 .ConditionFalse ,
725
+ Reason : bootstrapv1 .KubeadmConfigDataSecretNotAvailableV1Beta2Reason ,
726
+ Message : "Failed to read content from secrets for spec.files" ,
727
+ })
633
728
return ctrl.Result {}, err
634
729
}
635
730
636
731
users , err := r .resolveUsers (ctx , scope .Config )
637
732
if err != nil {
638
733
conditions .MarkFalse (scope .Config , bootstrapv1 .DataSecretAvailableCondition , bootstrapv1 .DataSecretGenerationFailedReason , clusterv1 .ConditionSeverityWarning , err .Error ())
734
+ v1beta2conditions .Set (scope .Config , metav1.Condition {
735
+ Type : bootstrapv1 .KubeadmConfigDataSecretAvailableV1Beta2Condition ,
736
+ Status : metav1 .ConditionFalse ,
737
+ Reason : bootstrapv1 .KubeadmConfigDataSecretNotAvailableV1Beta2Reason ,
738
+ Message : "Failed to read password from secrets for spec.users" ,
739
+ })
639
740
return ctrl.Result {}, err
640
741
}
641
742
642
743
if discoveryFile := scope .Config .Spec .JoinConfiguration .Discovery .File ; discoveryFile != nil && discoveryFile .KubeConfig != nil {
643
744
kubeconfig , err := r .resolveDiscoveryKubeConfig (discoveryFile )
644
745
if err != nil {
645
746
conditions .MarkFalse (scope .Config , bootstrapv1 .DataSecretAvailableCondition , bootstrapv1 .DataSecretGenerationFailedReason , clusterv1 .ConditionSeverityWarning , err .Error ())
747
+ v1beta2conditions .Set (scope .Config , metav1.Condition {
748
+ Type : bootstrapv1 .KubeadmConfigDataSecretAvailableV1Beta2Condition ,
749
+ Status : metav1 .ConditionFalse ,
750
+ Reason : bootstrapv1 .KubeadmConfigDataSecretNotAvailableV1Beta2Reason ,
751
+ Message : "Failed to create kubeconfig for spec.joinConfiguration.discovery.file" ,
752
+ })
646
753
return ctrl.Result {}, err
647
754
}
648
755
files = append (files , * kubeconfig )
@@ -709,14 +816,31 @@ func (r *KubeadmConfigReconciler) joinControlplane(ctx context.Context, scope *S
709
816
)
710
817
if err != nil {
711
818
conditions .MarkFalse (scope .Config , bootstrapv1 .CertificatesAvailableCondition , bootstrapv1 .CertificatesCorruptedReason , clusterv1 .ConditionSeverityError , err .Error ())
819
+ v1beta2conditions .Set (scope .Config , metav1.Condition {
820
+ Type : bootstrapv1 .KubeadmConfigCertificatesAvailableV1Beta2Condition ,
821
+ Status : metav1 .ConditionUnknown ,
822
+ Reason : bootstrapv1 .KubeadmConfigCertificatesAvailableInternalErrorV1Beta2Reason ,
823
+ Message : "Please check controller logs for errors" ,
824
+ })
712
825
return ctrl.Result {}, err
713
826
}
714
827
if err := certificates .EnsureAllExist (); err != nil {
715
828
conditions .MarkFalse (scope .Config , bootstrapv1 .CertificatesAvailableCondition , bootstrapv1 .CertificatesCorruptedReason , clusterv1 .ConditionSeverityError , err .Error ())
829
+ v1beta2conditions .Set (scope .Config , metav1.Condition {
830
+ Type : bootstrapv1 .KubeadmConfigCertificatesAvailableV1Beta2Condition ,
831
+ Status : metav1 .ConditionUnknown ,
832
+ Reason : bootstrapv1 .KubeadmConfigCertificatesAvailableInternalErrorV1Beta2Reason ,
833
+ Message : "Please check controller logs for errors" ,
834
+ })
716
835
return ctrl.Result {}, err
717
836
}
718
837
719
838
conditions .MarkTrue (scope .Config , bootstrapv1 .CertificatesAvailableCondition )
839
+ v1beta2conditions .Set (scope .Config , metav1.Condition {
840
+ Type : bootstrapv1 .KubeadmConfigCertificatesAvailableV1Beta2Condition ,
841
+ Status : metav1 .ConditionTrue ,
842
+ Reason : bootstrapv1 .KubeadmConfigCertificatesAvailableV1Beta2Reason ,
843
+ })
720
844
721
845
// Ensure that joinConfiguration.Discovery is properly set for joining node on the current cluster.
722
846
if res , err := r .reconcileDiscovery (ctx , scope .Cluster , scope .Config , certificates ); err != nil {
@@ -747,19 +871,37 @@ func (r *KubeadmConfigReconciler) joinControlplane(ctx context.Context, scope *S
747
871
files , err := r .resolveFiles (ctx , scope .Config )
748
872
if err != nil {
749
873
conditions .MarkFalse (scope .Config , bootstrapv1 .DataSecretAvailableCondition , bootstrapv1 .DataSecretGenerationFailedReason , clusterv1 .ConditionSeverityWarning , err .Error ())
874
+ v1beta2conditions .Set (scope .Config , metav1.Condition {
875
+ Type : bootstrapv1 .KubeadmConfigDataSecretAvailableV1Beta2Condition ,
876
+ Status : metav1 .ConditionFalse ,
877
+ Reason : bootstrapv1 .KubeadmConfigDataSecretNotAvailableV1Beta2Reason ,
878
+ Message : "Failed to read content from secrets for spec.files" ,
879
+ })
750
880
return ctrl.Result {}, err
751
881
}
752
882
753
883
users , err := r .resolveUsers (ctx , scope .Config )
754
884
if err != nil {
755
885
conditions .MarkFalse (scope .Config , bootstrapv1 .DataSecretAvailableCondition , bootstrapv1 .DataSecretGenerationFailedReason , clusterv1 .ConditionSeverityWarning , err .Error ())
886
+ v1beta2conditions .Set (scope .Config , metav1.Condition {
887
+ Type : bootstrapv1 .KubeadmConfigDataSecretAvailableV1Beta2Condition ,
888
+ Status : metav1 .ConditionFalse ,
889
+ Reason : bootstrapv1 .KubeadmConfigDataSecretNotAvailableV1Beta2Reason ,
890
+ Message : "Failed to read password from secrets for spec.users" ,
891
+ })
756
892
return ctrl.Result {}, err
757
893
}
758
894
759
895
if discoveryFile := scope .Config .Spec .JoinConfiguration .Discovery .File ; discoveryFile != nil && discoveryFile .KubeConfig != nil {
760
896
kubeconfig , err := r .resolveDiscoveryKubeConfig (discoveryFile )
761
897
if err != nil {
762
898
conditions .MarkFalse (scope .Config , bootstrapv1 .DataSecretAvailableCondition , bootstrapv1 .DataSecretGenerationFailedReason , clusterv1 .ConditionSeverityWarning , err .Error ())
899
+ v1beta2conditions .Set (scope .Config , metav1.Condition {
900
+ Type : bootstrapv1 .KubeadmConfigDataSecretAvailableV1Beta2Condition ,
901
+ Status : metav1 .ConditionFalse ,
902
+ Reason : bootstrapv1 .KubeadmConfigDataSecretNotAvailableV1Beta2Reason ,
903
+ Message : "Failed to create kubeconfig for spec.joinConfiguration.discovery.file" ,
904
+ })
763
905
return ctrl.Result {}, err
764
906
}
765
907
files = append (files , * kubeconfig )
@@ -1235,6 +1377,11 @@ func (r *KubeadmConfigReconciler) storeBootstrapData(ctx context.Context, scope
1235
1377
scope .Config .Status .DataSecretName = ptr .To (secret .Name )
1236
1378
scope .Config .Status .Ready = true
1237
1379
conditions .MarkTrue (scope .Config , bootstrapv1 .DataSecretAvailableCondition )
1380
+ v1beta2conditions .Set (scope .Config , metav1.Condition {
1381
+ Type : bootstrapv1 .KubeadmConfigDataSecretAvailableV1Beta2Condition ,
1382
+ Status : metav1 .ConditionTrue ,
1383
+ Reason : bootstrapv1 .KubeadmConfigDataSecretAvailableV1Beta2Reason ,
1384
+ })
1238
1385
return nil
1239
1386
}
1240
1387
0 commit comments