Skip to content

Commit 0bda8a9

Browse files
feat: upgrade to CAPI v1.11.x
1 parent 5b26ed7 commit 0bda8a9

File tree

13 files changed

+194
-222
lines changed

13 files changed

+194
-222
lines changed

api/v1alpha3/conditions.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@
44

55
package v1alpha3
66

7-
import (
8-
capiv1 "sigs.k8s.io/cluster-api/api/v1beta1"
9-
)
10-
117
// Conditions and condition Reasons for the TalosConfig object
128

139
const (
@@ -16,7 +12,7 @@ const (
1612
// NOTE: When the DataSecret generation starts the process completes immediately and within the
1713
// same reconciliation, so the user will always see a transition from Wait to Generated without having
1814
// evidence that BootstrapSecret generation is started/in progress.
19-
DataSecretAvailableCondition capiv1.ConditionType = "DataSecretAvailable"
15+
DataSecretAvailableCondition string = "DataSecretAvailable"
2016

2117
// WaitingForClusterInfrastructureReason (Severity=Info) document a bootstrap secret generation process
2218
// waiting for the cluster infrastructure to be ready.
@@ -33,7 +29,7 @@ const (
3329

3430
const (
3531
// ClientConfigAvailableCondition documents the status of the client config generation process.
36-
ClientConfigAvailableCondition capiv1.ConditionType = "ClientConfigAvailable"
32+
ClientConfigAvailableCondition string = "ClientConfigAvailable"
3733

3834
// ClientConfigGenerationFailedReason (Severity=Warning) documents a TalosConfig controller detecting
3935
// an error while generating a client config; those kind of errors are usually due to misconfigurations

api/v1alpha3/talosconfig_types.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package v1alpha3
66

77
import (
88
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
9-
capiv1 "sigs.k8s.io/cluster-api/api/v1beta1"
109
)
1110

1211
const (
@@ -76,7 +75,7 @@ type TalosConfigStatus struct {
7675

7776
// Conditions defines current service state of the TalosConfig.
7877
// +optional
79-
Conditions capiv1.Conditions `json:"conditions,omitempty"`
78+
Conditions []metav1.Condition `json:"conditions,omitempty"`
8079
}
8180

8281
// +kubebuilder:object:root=true
@@ -94,12 +93,12 @@ type TalosConfig struct {
9493
}
9594

9695
// GetConditions returns the set of conditions for this object.
97-
func (c *TalosConfig) GetConditions() capiv1.Conditions {
96+
func (c *TalosConfig) GetConditions() []metav1.Condition {
9897
return c.Status.Conditions
9998
}
10099

101100
// SetConditions sets the conditions on this object.
102-
func (c *TalosConfig) SetConditions(conditions capiv1.Conditions) {
101+
func (c *TalosConfig) SetConditions(conditions []metav1.Condition) {
103102
c.Status.Conditions = conditions
104103
}
105104

api/v1alpha3/zz_generated.deepcopy.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

controllers/scheme.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ package controllers
77
import (
88
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
99
"k8s.io/client-go/kubernetes/scheme"
10-
capiv1 "sigs.k8s.io/cluster-api/api/v1beta1"
11-
expv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1"
10+
capiv1 "sigs.k8s.io/cluster-api/api/core/v1beta2"
1211

1312
bootstrapv1alpha2 "github.com/siderolabs/cluster-api-bootstrap-provider-talos/api/v1alpha2"
1413
bootstrapv1alpha3 "github.com/siderolabs/cluster-api-bootstrap-provider-talos/api/v1alpha3"
@@ -18,7 +17,6 @@ import (
1817
// Use shared scheme for all calls.
1918
func init() {
2019
utilruntime.Must(capiv1.AddToScheme(scheme.Scheme))
21-
utilruntime.Must(expv1.AddToScheme(scheme.Scheme))
2220
utilruntime.Must(bootstrapv1alpha2.AddToScheme(scheme.Scheme))
2321
utilruntime.Must(bootstrapv1alpha3.AddToScheme(scheme.Scheme))
2422

controllers/secrets.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
corev1 "k8s.io/api/core/v1"
2020
k8serrors "k8s.io/apimachinery/pkg/api/errors"
2121
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
22-
capiv1 "sigs.k8s.io/cluster-api/api/v1beta1"
22+
capiv1 "sigs.k8s.io/cluster-api/api/core/v1beta2"
2323
"sigs.k8s.io/cluster-api/util/collections"
2424
"sigs.k8s.io/controller-runtime/pkg/client"
2525

controllers/talosconfig_controller.go

Lines changed: 62 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
594620
func (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

Comments
 (0)