Skip to content

Commit

Permalink
Update dependencies and CAPI to 1.5 (#527)
Browse files Browse the repository at this point in the history
* run go mod tidy

* go mod tidy

* update capi to v1.5.2

* update k8s to v0.27.6

* update controller runtime

* fix controller runtime lint issues

* bump infrastructureprovider v1.5.99

* Update Go version to 1.21

* Run go mod tidy

* Revert "Update Go version to 1.21"

This reverts commit 21c63a7.

* Stay on 1.20.10 go version in Dockerfile
  • Loading branch information
llDrLove authored Oct 30, 2023
1 parent fdf3a00 commit fc6b6c3
Show file tree
Hide file tree
Showing 15 changed files with 112 additions and 98 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ create-management-cluster: $(KUSTOMIZE) $(ENVSUBST)
./hack/install-cert-manager.sh

# Deploy CAPI
curl --retry $(CURL_RETRIES) -sSL https://github.com/kubernetes-sigs/cluster-api/releases/download/v1.4.5/cluster-api-components.yaml | $(ENVSUBST) | kubectl apply -f -
curl --retry $(CURL_RETRIES) -sSL https://github.com/kubernetes-sigs/cluster-api/releases/download/v1.5.2/cluster-api-components.yaml | $(ENVSUBST) | kubectl apply -f -

# Deploy CAPDO
kind load docker-image $(CONTROLLER_IMG)-$(ARCH):$(TAG) --name=capdo
Expand Down
2 changes: 1 addition & 1 deletion Tiltfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ settings = {
"deploy_cert_manager": True,
"preload_images_for_kind": True,
"kind_cluster_name": "capdo",
"capi_version": "v1.4.5",
"capi_version": "v1.5.2",
"cert_manager_version": "v1.10.1",
"kubernetes_version": "v1.25.5",
}
Expand Down
17 changes: 9 additions & 8 deletions api/v1beta1/docluster_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
ctrl "sigs.k8s.io/controller-runtime"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/webhook"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
)

// log is for logging in this package.
Expand All @@ -49,31 +50,31 @@ func (r *DOCluster) SetupWebhookWithManager(mgr ctrl.Manager) error {
func (r *DOCluster) Default() {}

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
func (r *DOCluster) ValidateCreate() error {
return nil
func (r *DOCluster) ValidateCreate() (admission.Warnings, error) {
return nil, nil
}

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
func (r *DOCluster) ValidateUpdate(old runtime.Object) error {
func (r *DOCluster) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
var allErrs field.ErrorList

oldDOCluster, ok := old.(*DOCluster)
if !ok {
return apierrors.NewBadRequest(fmt.Sprintf("expected an DOCluster but got a %T", old))
return nil, apierrors.NewBadRequest(fmt.Sprintf("expected an DOCluster but got a %T", old))
}

if r.Spec.Region != oldDOCluster.Spec.Region {
allErrs = append(allErrs, field.Invalid(field.NewPath("spec", "region"), r.Spec.Region, "field is immutable"))
}

if len(allErrs) == 0 {
return nil
return nil, nil
}

return apierrors.NewInvalid(r.GroupVersionKind().GroupKind(), r.Name, allErrs)
return nil, apierrors.NewInvalid(r.GroupVersionKind().GroupKind(), r.Name, allErrs)
}

// ValidateDelete implements webhook.Validator so a webhook will be registered for the type.
func (r *DOCluster) ValidateDelete() error {
return nil
func (r *DOCluster) ValidateDelete() (admission.Warnings, error) {
return nil, nil
}
17 changes: 9 additions & 8 deletions api/v1beta1/doclustertemplate_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
ctrl "sigs.k8s.io/controller-runtime"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/webhook"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
)

// log is for logging in this package.
Expand All @@ -49,27 +50,27 @@ func (r *DOClusterTemplate) Default() {
var _ webhook.Validator = &DOClusterTemplate{}

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
func (r *DOClusterTemplate) ValidateCreate() error {
func (r *DOClusterTemplate) ValidateCreate() (admission.Warnings, error) {
doclustertemplatelog.Info("validate create", "name", r.Name)

return nil
return nil, nil
}

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
func (r *DOClusterTemplate) ValidateUpdate(oldRaw runtime.Object) error {
func (r *DOClusterTemplate) ValidateUpdate(oldRaw runtime.Object) (admission.Warnings, error) {
old, ok := oldRaw.(*DOClusterTemplate)
if !ok {
return apierrors.NewBadRequest(fmt.Sprintf("expected an DOClusterTemplate but got a %T", oldRaw))
return nil, apierrors.NewBadRequest(fmt.Sprintf("expected an DOClusterTemplate but got a %T", oldRaw))
}

if !reflect.DeepEqual(r.Spec, old.Spec) {
return apierrors.NewBadRequest("DOClusterTemplate.Spec is immutable")
return nil, apierrors.NewBadRequest("DOClusterTemplate.Spec is immutable")
}
return nil
return nil, nil
}

// ValidateDelete implements webhook.Validator so a webhook will be registered for the type.
func (r *DOClusterTemplate) ValidateDelete() error {
func (r *DOClusterTemplate) ValidateDelete() (admission.Warnings, error) {
doclustertemplatelog.Info("validate delete", "name", r.Name)
return nil
return nil, nil
}
19 changes: 10 additions & 9 deletions api/v1beta1/domachine_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
ctrl "sigs.k8s.io/controller-runtime"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/webhook"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
)

// log is for logging in this package.
Expand All @@ -51,22 +52,22 @@ func (r *DOMachine) SetupWebhookWithManager(mgr ctrl.Manager) error {
func (r *DOMachine) Default() {}

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
func (r *DOMachine) ValidateCreate() error {
return nil
func (r *DOMachine) ValidateCreate() (admission.Warnings, error) {
return nil, nil
}

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
func (r *DOMachine) ValidateUpdate(old runtime.Object) error {
func (r *DOMachine) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
var allErrs field.ErrorList

newDOMachine, err := runtime.DefaultUnstructuredConverter.ToUnstructured(r)
if err != nil {
return apierrors.NewInternalError(errors.Wrap(err, "failed to convert new DOMachine to unstructured object"))
return nil, apierrors.NewInternalError(errors.Wrap(err, "failed to convert new DOMachine to unstructured object"))
}

oldDOMachine, err := runtime.DefaultUnstructuredConverter.ToUnstructured(old)
if err != nil {
return apierrors.NewInternalError(errors.Wrap(err, "failed to convert old DOMachine to unstructured object"))
return nil, apierrors.NewInternalError(errors.Wrap(err, "failed to convert old DOMachine to unstructured object"))
}

newDOMachineSpec := newDOMachine["spec"].(map[string]interface{})
Expand All @@ -85,13 +86,13 @@ func (r *DOMachine) ValidateUpdate(old runtime.Object) error {
}

if len(allErrs) == 0 {
return nil
return nil, nil
}

return apierrors.NewInvalid(r.GroupVersionKind().GroupKind(), r.Name, allErrs)
return nil, apierrors.NewInvalid(r.GroupVersionKind().GroupKind(), r.Name, allErrs)
}

// ValidateDelete implements webhook.Validator so a webhook will be registered for the type.
func (r *DOMachine) ValidateDelete() error {
return nil
func (r *DOMachine) ValidateDelete() (admission.Warnings, error) {
return nil, nil
}
17 changes: 9 additions & 8 deletions api/v1beta1/domachinetemplate_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
ctrl "sigs.k8s.io/controller-runtime"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/webhook"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
)

// +kubebuilder:webhook:verbs=create;update,path=/validate-infrastructure-cluster-x-k8s-io-v1beta1-domachinetemplate,mutating=false,failurePolicy=fail,matchPolicy=Equivalent,groups=infrastructure.cluster.x-k8s.io,resources=domachinetemplates,versions=v1beta1,name=validation.domachinetemplate.infrastructure.cluster.x-k8s.io,sideEffects=None,admissionReviewVersions=v1beta1
Expand All @@ -42,22 +43,22 @@ func (r *DOMachineTemplate) SetupWebhookWithManager(mgr ctrl.Manager) error {
var _ webhook.Validator = &DOMachineTemplate{}

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
func (r *DOMachineTemplate) ValidateCreate() error {
func (r *DOMachineTemplate) ValidateCreate() (admission.Warnings, error) {
var allErrs field.ErrorList

if r.Spec.Template.Spec.ProviderID != nil {
allErrs = append(allErrs, field.Forbidden(field.NewPath("spec", "template", "spec", "providerID"), "cannot be set in templates"))
}

if len(allErrs) == 0 {
return nil
return nil, nil
}

return apierrors.NewInvalid(r.GroupVersionKind().GroupKind(), r.Name, allErrs)
return nil, apierrors.NewInvalid(r.GroupVersionKind().GroupKind(), r.Name, allErrs)
}

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
func (r *DOMachineTemplate) ValidateUpdate(old runtime.Object) error {
func (r *DOMachineTemplate) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
var allErrs field.ErrorList

oldDOMachineTemplate := old.(*DOMachineTemplate)
Expand All @@ -66,15 +67,15 @@ func (r *DOMachineTemplate) ValidateUpdate(old runtime.Object) error {
}

if len(allErrs) == 0 {
return nil
return nil, nil
}

return apierrors.NewInvalid(r.GroupVersionKind().GroupKind(), r.Name, allErrs)
return nil, apierrors.NewInvalid(r.GroupVersionKind().GroupKind(), r.Name, allErrs)
}

// ValidateDelete implements webhook.Validator so a webhook will be registered for the type.
func (r *DOMachineTemplate) ValidateDelete() error {
return nil
func (r *DOMachineTemplate) ValidateDelete() (admission.Warnings, error) {
return nil, nil
}

// Default implements webhookutil.defaulter so a webhook will be registered for the type.
Expand Down
2 changes: 1 addition & 1 deletion controllers/docluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (r *DOClusterReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Man

// Add a watch on clusterv1.Cluster object for unpause notifications.
if err = c.Watch(
&source.Kind{Type: &clusterv1.Cluster{}},
source.Kind(mgr.GetCache(), &clusterv1.Cluster{}),
handler.EnqueueRequestsFromMapFunc(util.ClusterToInfrastructureMapFunc(ctx, infrav1.GroupVersion.WithKind("DOCluster"), mgr.GetClient(), &infrav1.DOCluster{})),
predicates.ClusterUnpaused(ctrl.LoggerFrom(ctx)),
); err != nil {
Expand Down
10 changes: 5 additions & 5 deletions controllers/domachine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,26 +60,26 @@ func (r *DOMachineReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Man
For(&infrav1.DOMachine{}).
WithEventFilter(predicates.ResourceNotPaused(ctrl.LoggerFrom(ctx))). // don't queue reconcile if resource is paused
Watches(
&source.Kind{Type: &clusterv1.Machine{}},
&clusterv1.Machine{},
handler.EnqueueRequestsFromMapFunc(util.MachineToInfrastructureMapFunc(infrav1.GroupVersion.WithKind("DOMachine"))),
).
Watches(
&source.Kind{Type: &infrav1.DOCluster{}},
&infrav1.DOCluster{},
handler.EnqueueRequestsFromMapFunc(r.DOClusterToDOMachines(ctx)),
).
Build(r)
if err != nil {
return errors.Wrapf(err, "error creating controller")
}

clusterToObjectFunc, err := util.ClusterToObjectsMapper(r.Client, &infrav1.DOMachineList{}, mgr.GetScheme())
clusterToObjectFunc, err := util.ClusterToTypedObjectsMapper(r.Client, &infrav1.DOMachineList{}, mgr.GetScheme())
if err != nil {
return errors.Wrapf(err, "failed to create mapper for Cluster to DOMachines")
}

// Add a watch on clusterv1.Cluster object for unpause & ready notifications.
if err := c.Watch(
&source.Kind{Type: &clusterv1.Cluster{}},
source.Kind(mgr.GetCache(), &clusterv1.Cluster{}),
handler.EnqueueRequestsFromMapFunc(clusterToObjectFunc),
predicates.ClusterUnpausedAndInfrastructureReady(ctrl.LoggerFrom(ctx)),
); err != nil {
Expand All @@ -92,7 +92,7 @@ func (r *DOMachineReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Man
// DOClusterToDOMachines convert the cluster to machines spec.
func (r *DOMachineReconciler) DOClusterToDOMachines(ctx context.Context) handler.MapFunc {
log := ctrl.LoggerFrom(ctx)
return func(o client.Object) []ctrl.Request {
return func(ctx context.Context, o client.Object) []ctrl.Request {
result := []ctrl.Request{}

c, ok := o.(*infrav1.DOCluster)
Expand Down
3 changes: 2 additions & 1 deletion controllers/domachine_controller_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package controllers

import (
"context"
"testing"

. "github.com/onsi/gomega"
Expand Down Expand Up @@ -154,7 +155,7 @@ func TestDOMachineReconciler_DOClusterToDOMachines(t *testing.T) {
}

fn := r.DOClusterToDOMachines(ctrl.SetupSignalHandler())
out := fn(tt.request)
out := fn(context.Background(), tt.request)
g.Expect(out).To(Equal(tt.expected))
})
}
Expand Down
27 changes: 14 additions & 13 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ require (
github.com/pkg/errors v0.9.1
github.com/spf13/pflag v1.0.5
golang.org/x/oauth2 v0.13.0
k8s.io/api v0.26.7
k8s.io/apimachinery v0.26.7
k8s.io/client-go v0.26.7
k8s.io/api v0.27.6
k8s.io/apimachinery v0.27.6
k8s.io/client-go v0.27.6
k8s.io/klog/v2 v2.90.1
k8s.io/utils v0.0.0-20230209194617-a36077c30491
sigs.k8s.io/cluster-api v1.4.5
sigs.k8s.io/cluster-api/test v1.4.5
sigs.k8s.io/controller-runtime v0.14.5
sigs.k8s.io/cluster-api v1.5.2
sigs.k8s.io/cluster-api/test v1.5.2
sigs.k8s.io/controller-runtime v0.15.2
)

require (
Expand All @@ -29,6 +29,7 @@ require (
github.com/Masterminds/semver/v3 v3.2.0 // indirect
github.com/Masterminds/sprig/v3 v3.2.3 // indirect
github.com/Microsoft/go-winio v0.5.0 // indirect
github.com/adrg/xdg v0.4.0 // indirect
github.com/alessio/shellescape v1.4.1 // indirect
github.com/antlr/antlr4/runtime/Go/antlr v1.4.10 // indirect
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a // indirect
Expand All @@ -37,7 +38,7 @@ require (
github.com/blang/semver/v4 v4.0.0 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/coredns/caddy v1.1.0 // indirect
github.com/coredns/corefile-migration v1.0.20 // indirect
github.com/coredns/corefile-migration v1.0.21 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/docker/distribution v2.8.2+incompatible // indirect
github.com/docker/docker v24.0.5+incompatible // indirect
Expand Down Expand Up @@ -108,7 +109,7 @@ require (
golang.org/x/text v0.13.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.13.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.2.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.3.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect
google.golang.org/protobuf v1.31.0 // indirect
Expand All @@ -117,15 +118,15 @@ require (
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gotest.tools/v3 v3.5.0 // indirect
k8s.io/apiextensions-apiserver v0.26.7 // indirect
k8s.io/apiserver v0.26.7 // indirect
k8s.io/cluster-bootstrap v0.26.7 // indirect
k8s.io/component-base v0.26.7 // indirect
k8s.io/apiextensions-apiserver v0.27.2 // indirect
k8s.io/apiserver v0.27.2 // indirect
k8s.io/cluster-bootstrap v0.27.2 // indirect
k8s.io/component-base v0.27.2 // indirect
k8s.io/kube-openapi v0.0.0-20230501164219-8b0f38b5fd1f // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/kind v0.20.0 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)

replace sigs.k8s.io/cluster-api => sigs.k8s.io/cluster-api v1.4.5
replace sigs.k8s.io/cluster-api => sigs.k8s.io/cluster-api v1.5.2
Loading

0 comments on commit fc6b6c3

Please sign in to comment.