Skip to content

Commit 800093c

Browse files
committed
feat: capi bump to v1.9.x
Bump CAPI to v1.9.4 and associated packages/ Signed-off-by: Richard Case <[email protected]>
1 parent 2fdb89a commit 800093c

15 files changed

+605
-1012
lines changed

api/v1alpha1/microvmcluster_webhook.go

+8-7
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
ctrl "sigs.k8s.io/controller-runtime"
1313
logf "sigs.k8s.io/controller-runtime/pkg/log"
1414
"sigs.k8s.io/controller-runtime/pkg/webhook"
15+
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
1516
)
1617

1718
var _ = logf.Log.WithName("mvmcluster-resource")
@@ -33,26 +34,26 @@ var (
3334
)
3435

3536
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
36-
func (r *MicrovmCluster) ValidateCreate() error {
37+
func (r *MicrovmCluster) ValidateCreate() (admission.Warnings, error) {
3738
var allErrs field.ErrorList
3839

3940
allErrs = append(allErrs, r.Spec.Placement.Validate()...)
4041

4142
if len(allErrs) == 0 {
42-
return nil
43+
return nil, nil
4344
}
4445

45-
return apierrors.NewInvalid(r.GroupVersionKind().GroupKind(), r.Name, allErrs)
46+
return nil, apierrors.NewInvalid(r.GroupVersionKind().GroupKind(), r.Name, allErrs)
4647
}
4748

4849
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type.
49-
func (r *MicrovmCluster) ValidateDelete() error {
50-
return nil
50+
func (r *MicrovmCluster) ValidateDelete() (admission.Warnings, error) {
51+
return nil, nil
5152
}
5253

5354
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
54-
func (r *MicrovmCluster) ValidateUpdate(old runtime.Object) error {
55-
return nil
55+
func (r *MicrovmCluster) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
56+
return nil, nil
5657
}
5758

5859
// Default satisfies the defaulting webhook interface.

api/v1alpha1/microvmmachine_webhook.go

+7-6
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
ctrl "sigs.k8s.io/controller-runtime"
1313
logf "sigs.k8s.io/controller-runtime/pkg/log"
1414
"sigs.k8s.io/controller-runtime/pkg/webhook"
15+
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
1516
)
1617

1718
var machineLog = logf.Log.WithName("microvmmachine-resource")
@@ -33,17 +34,17 @@ var (
3334
)
3435

3536
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
36-
func (r *MicrovmMachine) ValidateCreate() error {
37-
return nil
37+
func (r *MicrovmMachine) ValidateCreate() (admission.Warnings, error) {
38+
return nil, nil
3839
}
3940

4041
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type.
41-
func (r *MicrovmMachine) ValidateDelete() error {
42-
return nil
42+
func (r *MicrovmMachine) ValidateDelete() (admission.Warnings, error) {
43+
return nil, nil
4344
}
4445

4546
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
46-
func (r *MicrovmMachine) ValidateUpdate(old runtime.Object) error {
47+
func (r *MicrovmMachine) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
4748
machineLog.Info("validate upadate", "name", r.Name)
4849

4950
var allErrs field.ErrorList
@@ -54,7 +55,7 @@ func (r *MicrovmMachine) ValidateUpdate(old runtime.Object) error {
5455
allErrs = append(allErrs, field.Forbidden(field.NewPath("spec"), "microvm machine spec is immutable"))
5556
}
5657

57-
return aggregateObjErrors(r.GroupVersionKind().GroupKind(), r.Name, allErrs)
58+
return nil, aggregateObjErrors(r.GroupVersionKind().GroupKind(), r.Name, allErrs)
5859
}
5960

6061
// Default satisfies the defaulting webhook interface.

api/v1alpha1/microvmmachinetemplate_webhook.go

+7-6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
ctrl "sigs.k8s.io/controller-runtime"
1111
logf "sigs.k8s.io/controller-runtime/pkg/log"
1212
"sigs.k8s.io/controller-runtime/pkg/webhook"
13+
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
1314
)
1415

1516
var _ = logf.Log.WithName("microvmmachinetemplate-resource")
@@ -27,16 +28,16 @@ func (r *MicrovmMachineTemplate) SetupWebhookWithManager(mgr ctrl.Manager) error
2728
var _ webhook.Validator = &MicrovmMachineTemplate{}
2829

2930
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
30-
func (r *MicrovmMachineTemplate) ValidateCreate() error {
31-
return nil
31+
func (r *MicrovmMachineTemplate) ValidateCreate() (admission.Warnings, error) {
32+
return nil, nil
3233
}
3334

3435
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type.
35-
func (r *MicrovmMachineTemplate) ValidateDelete() error {
36-
return nil
36+
func (r *MicrovmMachineTemplate) ValidateDelete() (admission.Warnings, error) {
37+
return nil, nil
3738
}
3839

3940
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
40-
func (r *MicrovmMachineTemplate) ValidateUpdate(old runtime.Object) error {
41-
return nil
41+
func (r *MicrovmMachineTemplate) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
42+
return nil, nil
4243
}

controllers/helpers_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ func createMachine() *clusterv1.Machine {
275275
Name: testMachineName,
276276
Namespace: testClusterNamespace,
277277
Labels: map[string]string{
278-
clusterv1.ClusterLabelName: testClusterName,
278+
clusterv1.ClusterNameLabel: testClusterName,
279279
},
280280
},
281281
Spec: clusterv1.MachineSpec{

controllers/microvmcluster_controller.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525
"sigs.k8s.io/controller-runtime/pkg/handler"
2626
"sigs.k8s.io/controller-runtime/pkg/log"
2727
"sigs.k8s.io/controller-runtime/pkg/reconcile"
28-
"sigs.k8s.io/controller-runtime/pkg/source"
2928

3029
infrav1 "github.com/liquidmetal-dev/cluster-api-provider-microvm/api/v1alpha1"
3130
"github.com/liquidmetal-dev/cluster-api-provider-microvm/internal/defaults"
@@ -240,10 +239,10 @@ func (r *MicrovmClusterReconciler) SetupWithManager(
240239
builder := ctrl.NewControllerManagedBy(mgr).
241240
WithOptions(options).
242241
For(&infrav1.MicrovmCluster{}).
243-
WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(log, r.WatchFilterValue)).
244-
WithEventFilter(predicates.ResourceIsNotExternallyManaged(log)).
242+
WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(mgr.GetScheme(), log, r.WatchFilterValue)).
243+
WithEventFilter(predicates.ResourceIsNotExternallyManaged(mgr.GetScheme(), log)).
245244
Watches(
246-
&source.Kind{Type: &clusterv1.Cluster{}},
245+
&clusterv1.Cluster{},
247246
handler.EnqueueRequestsFromMapFunc(
248247
util.ClusterToInfrastructureMapFunc(ctx,
249248
infrav1.GroupVersion.WithKind("MicrovmCluster"),
@@ -252,7 +251,7 @@ func (r *MicrovmClusterReconciler) SetupWithManager(
252251
),
253252
),
254253
builder.WithPredicates(
255-
predicates.ClusterUnpaused(log),
254+
predicates.ClusterUnpaused(mgr.GetScheme(), log),
256255
),
257256
)
258257

controllers/microvmcluster_controller_test.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,13 @@ func TestClusterReconciliationDelete(t *testing.T) {
250250
g := NewWithT(t)
251251

252252
mvmCluster := createMicrovmCluster()
253-
mvmCluster.ObjectMeta.DeletionTimestamp = &metav1.Time{
254-
Time: time.Now(),
253+
mvmCluster.ObjectMeta = metav1.ObjectMeta{
254+
DeletionTimestamp: &metav1.Time{
255+
Time: time.Now(),
256+
},
257+
Finalizers: []string{
258+
"somefinalizer",
259+
},
255260
}
256261

257262
objects := []runtime.Object{

controllers/microvmmachine_controller.go

+8-12
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import (
3030
"sigs.k8s.io/controller-runtime/pkg/handler"
3131
"sigs.k8s.io/controller-runtime/pkg/log"
3232
"sigs.k8s.io/controller-runtime/pkg/reconcile"
33-
"sigs.k8s.io/controller-runtime/pkg/source"
3433

3534
infrav1 "github.com/liquidmetal-dev/cluster-api-provider-microvm/api/v1alpha1"
3635
"github.com/liquidmetal-dev/cluster-api-provider-microvm/internal/defaults"
@@ -57,9 +56,6 @@ type MicrovmMachineReconciler struct {
5756

5857
// Reconcile is part of the main kubernetes reconciliation loop which aims to
5958
// move the current state of the cluster closer to the desired state.
60-
//
61-
// For more details, check Reconcile and its Result here:
62-
// - https://pkg.go.dev/sigs.k8s.io/[email protected]/pkg/reconcile
6359
func (r *MicrovmMachineReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
6460
log := log.FromContext(ctx)
6561

@@ -390,7 +386,7 @@ func (r *MicrovmMachineReconciler) SetupWithManager(
390386
) error {
391387
log := ctrl.LoggerFrom(ctx)
392388

393-
clusterToObjectFunc, err := util.ClusterToObjectsMapper(
389+
clusterToObjectFunc, err := util.ClusterToTypedObjectsMapper(
394390
r.Client,
395391
&infrav1.MicrovmMachineList{},
396392
mgr.GetScheme(),
@@ -402,22 +398,22 @@ func (r *MicrovmMachineReconciler) SetupWithManager(
402398
builder := ctrl.NewControllerManagedBy(mgr).
403399
WithOptions(options).
404400
For(&infrav1.MicrovmMachine{}).
405-
WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(log, r.WatchFilterValue)).
406-
WithEventFilter(predicates.ResourceIsNotExternallyManaged(log)).
401+
WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(mgr.GetScheme(), log, r.WatchFilterValue)).
402+
WithEventFilter(predicates.ResourceIsNotExternallyManaged(mgr.GetScheme(), log)).
407403
Watches(
408-
&source.Kind{Type: &clusterv1.Machine{}},
404+
&clusterv1.Machine{},
409405
handler.EnqueueRequestsFromMapFunc(
410406
util.MachineToInfrastructureMapFunc(infrav1.GroupVersion.WithKind("MicrovmMachine")),
411407
),
412408
).
413409
Watches(
414-
&source.Kind{Type: &infrav1.MicrovmCluster{}},
410+
&infrav1.MicrovmCluster{},
415411
handler.EnqueueRequestsFromMapFunc(r.MicroVMClusterToMicrovmMachine(ctx, log)),
416412
).
417413
Watches(
418-
&source.Kind{Type: &clusterv1.Cluster{}},
414+
&clusterv1.Cluster{},
419415
handler.EnqueueRequestsFromMapFunc(clusterToObjectFunc),
420-
builder.WithPredicates(predicates.ClusterUnpausedAndInfrastructureReady(log)),
416+
builder.WithPredicates(predicates.ClusterPausedTransitionsOrInfrastructureReady(mgr.GetScheme(), log)),
421417
)
422418

423419
if err := builder.Complete(r); err != nil {
@@ -437,7 +433,7 @@ func (r *MicrovmMachineReconciler) MicroVMClusterToMicrovmMachine(
437433
ctx context.Context,
438434
log logr.Logger,
439435
) handler.MapFunc {
440-
return func(o client.Object) []ctrl.Request {
436+
return func(ctx context.Context, o client.Object) []ctrl.Request {
441437
mvmCluster, ok := o.(*infrav1.MicrovmCluster)
442438
if !ok {
443439
log.Error(errExpectedMicrovmCluster, "failed to get microvmcluster")

0 commit comments

Comments
 (0)