Skip to content

Commit

Permalink
Merge pull request #985 from richardcase/bump_capi_150rc
Browse files Browse the repository at this point in the history
chore: bump CAPI to v1.5.0
  • Loading branch information
k8s-ci-robot authored Aug 16, 2023
2 parents 9ef6222 + f524e1a commit 5608868
Show file tree
Hide file tree
Showing 27 changed files with 308 additions and 321 deletions.
14 changes: 9 additions & 5 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
name: Lint
on: [ pull_request ]
on: [pull_request]

permissions:
contents: read

jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
- uses: actions/setup-go@v4
with:
go-version: 1.19
go-version: "1.20"
check-latest: true
cache: false
- name: golangci-lint
uses: golangci/golangci-lint-action@v3.2.0
uses: golangci/golangci-lint-action@v3
with:
version: v1.50.1
version: "v1.53"
7 changes: 7 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ linters-settings:
go: "1.18"
stylecheck:
go: "1.18"
depguard:
rules:
main:
deny:
- pkg: "io/ioutil"
desc: "ioutil is deprecated starting with Go 1.16"


issues:
max-same-issues: 0
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.

# Build the manager binary
FROM golang:1.19.10@sha256:83f9f840072d05ad4d90ce4ac7cb2427632d6b89d5ffc558f18f9577ec8188c0 as builder
FROM golang:1.20.6@sha256:b6c53162b13ec2ac1c725078671dbff289d9e723c045c27d73eacf0a50893598 as builder
WORKDIR /workspace

# Run this with docker build --build_arg $(go env GOPROXY) to override the goproxy
Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ ENVSUBST_VER := v1.4.2
ENVSUBST_BIN := envsubst
ENVSUBST := $(TOOLS_BIN_DIR)/$(ENVSUBST_BIN)

GOLANGCI_LINT_VER := v1.52.1
GOLANGCI_LINT_VER := v1.53.3
GOLANGCI_LINT_BIN := golangci-lint
GOLANGCI_LINT := $(TOOLS_BIN_DIR)/$(GOLANGCI_LINT_BIN)-$(GOLANGCI_LINT_VER)

Expand Down Expand Up @@ -140,7 +140,7 @@ endif
# Build time versioning details.
LDFLAGS := $(shell hack/version.sh)

GOLANG_VERSION := 1.19.10
GOLANG_VERSION := 1.20.6

# CI
CAPG_WORKER_CLUSTER_KUBECONFIG ?= "/tmp/kubeconfig"
Expand Down Expand Up @@ -473,7 +473,7 @@ create-management-cluster: $(KUSTOMIZE) $(ENVSUBST) $(KIND) $(KUBECTL)
./hack/install-cert-manager.sh

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

# Deploy CAPG
$(KIND) load docker-image $(CONTROLLER_IMG)-$(ARCH):$(TAG) --name=clusterapi
Expand Down
2 changes: 1 addition & 1 deletion Tiltfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ settings = {
"deploy_cert_manager": True,
"preload_images_for_kind": True,
"kind_cluster_name": "capg",
"capi_version": "v1.4.4",
"capi_version": "v1.5.0",
"cert_manager_version": "v1.11.0",
"kubernetes_version": "v1.26.1",
}
Expand Down
15 changes: 8 additions & 7 deletions api/v1beta1/gcpcluster_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"
)

// clusterlog is for logging in this package.
Expand All @@ -49,14 +50,14 @@ func (c *GCPCluster) Default() {
}

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

return nil
return nil, nil
}

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
func (c *GCPCluster) ValidateUpdate(oldRaw runtime.Object) error {
func (c *GCPCluster) ValidateUpdate(oldRaw runtime.Object) (admission.Warnings, error) {
clusterlog.Info("validate update", "name", c.Name)
var allErrs field.ErrorList
old := oldRaw.(*GCPCluster)
Expand All @@ -83,15 +84,15 @@ func (c *GCPCluster) ValidateUpdate(oldRaw runtime.Object) error {
}

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

return apierrors.NewInvalid(GroupVersion.WithKind("GCPCluster").GroupKind(), c.Name, allErrs)
return nil, apierrors.NewInvalid(GroupVersion.WithKind("GCPCluster").GroupKind(), c.Name, allErrs)
}

// ValidateDelete implements webhook.Validator so a webhook will be registered for the type.
func (c *GCPCluster) ValidateDelete() error {
func (c *GCPCluster) ValidateDelete() (admission.Warnings, error) {
clusterlog.Info("validate delete", "name", c.Name)

return nil
return nil, nil
}
17 changes: 9 additions & 8 deletions api/v1beta1/gcpclustertemplate_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 *GCPClusterTemplate) Default() {
var _ webhook.Validator = &GCPClusterTemplate{}

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
func (r *GCPClusterTemplate) ValidateCreate() error {
func (r *GCPClusterTemplate) ValidateCreate() (admission.Warnings, error) {
gcpclustertemplatelog.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 *GCPClusterTemplate) ValidateUpdate(oldRaw runtime.Object) error {
func (r *GCPClusterTemplate) ValidateUpdate(oldRaw runtime.Object) (admission.Warnings, error) {
old, ok := oldRaw.(*GCPClusterTemplate)
if !ok {
return apierrors.NewBadRequest(fmt.Sprintf("expected an GCPClusterTemplate but got a %T", oldRaw))
return nil, apierrors.NewBadRequest(fmt.Sprintf("expected an GCPClusterTemplate but got a %T", oldRaw))
}

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

// ValidateDelete implements webhook.Validator so a webhook will be registered for the type.
func (r *GCPClusterTemplate) ValidateDelete() error {
func (r *GCPClusterTemplate) ValidateDelete() (admission.Warnings, error) {
gcpclustertemplatelog.Info("validate delete", "name", r.Name)
return nil
return nil, nil
}
3 changes: 2 additions & 1 deletion api/v1beta1/gcpclustertemplate_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,13 @@ func TestGCPClusterTemplate_ValidateUpdate(t *testing.T) {
test := test
t.Run(test.name, func(t *testing.T) {
t.Parallel()
err := test.newTemplate.ValidateUpdate(test.oldTemplate)
warn, err := test.newTemplate.ValidateUpdate(test.oldTemplate)
if test.wantErr {
g.Expect(err).To(HaveOccurred())
} else {
g.Expect(err).NotTo(HaveOccurred())
}
g.Expect(warn).To(BeNil())
})
}
}
19 changes: 10 additions & 9 deletions api/v1beta1/gcpmachine_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,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 @@ -47,22 +48,22 @@ func (m *GCPMachine) SetupWebhookWithManager(mgr ctrl.Manager) error {
var _ webhook.Validator = &GCPMachine{}

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
func (m *GCPMachine) ValidateCreate() error {
func (m *GCPMachine) ValidateCreate() (admission.Warnings, error) {
clusterlog.Info("validate create", "name", m.Name)
return validateConfidentialCompute(m.Spec)
return nil, validateConfidentialCompute(m.Spec)
}

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
func (m *GCPMachine) ValidateUpdate(old runtime.Object) error {
func (m *GCPMachine) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
newGCPMachine, err := runtime.DefaultUnstructuredConverter.ToUnstructured(m)
if err != nil {
return apierrors.NewInvalid(GroupVersion.WithKind("GCPMachine").GroupKind(), m.Name, field.ErrorList{
return nil, apierrors.NewInvalid(GroupVersion.WithKind("GCPMachine").GroupKind(), m.Name, field.ErrorList{
field.InternalError(nil, errors.Wrap(err, "failed to convert new GCPMachine to unstructured object")),
})
}
oldGCPMachine, err := runtime.DefaultUnstructuredConverter.ToUnstructured(old)
if err != nil {
return apierrors.NewInvalid(GroupVersion.WithKind("GCPMachine").GroupKind(), m.Name, field.ErrorList{
return nil, apierrors.NewInvalid(GroupVersion.WithKind("GCPMachine").GroupKind(), m.Name, field.ErrorList{
field.InternalError(nil, errors.Wrap(err, "failed to convert old GCPMachine to unstructured object")),
})
}
Expand All @@ -83,19 +84,19 @@ func (m *GCPMachine) ValidateUpdate(old runtime.Object) error {
delete(newGCPMachineSpec, "additionalNetworkTags")

if !reflect.DeepEqual(oldGCPMachineSpec, newGCPMachineSpec) {
return apierrors.NewInvalid(GroupVersion.WithKind("GCPMachine").GroupKind(), m.Name, field.ErrorList{
return nil, apierrors.NewInvalid(GroupVersion.WithKind("GCPMachine").GroupKind(), m.Name, field.ErrorList{
field.Forbidden(field.NewPath("spec"), "cannot be modified"),
})
}

return nil
return nil, nil
}

// ValidateDelete implements webhook.Validator so a webhook will be registered for the type.
func (m *GCPMachine) ValidateDelete() error {
func (m *GCPMachine) ValidateDelete() (admission.Warnings, error) {
clusterlog.Info("validate delete", "name", m.Name)

return nil
return nil, nil
}

// Default implements webhookutil.defaulter so a webhook will be registered for the type.
Expand Down
3 changes: 2 additions & 1 deletion api/v1beta1/gcpmachine_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,13 @@ func TestGCPMachine_ValidateCreate(t *testing.T) {
test := test
t.Run(test.name, func(t *testing.T) {
t.Parallel()
err := test.GCPMachine.ValidateCreate()
warn, err := test.GCPMachine.ValidateCreate()
if test.wantErr {
g.Expect(err).To(HaveOccurred())
} else {
g.Expect(err).NotTo(HaveOccurred())
}
g.Expect(warn).To(BeNil())
})
}
}
19 changes: 10 additions & 9 deletions api/v1beta1/gcpmachinetemplate_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"
)

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

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

return validateConfidentialCompute(r.Spec.Template.Spec)
return nil, validateConfidentialCompute(r.Spec.Template.Spec)
}

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
func (r *GCPMachineTemplate) ValidateUpdate(old runtime.Object) error {
func (r *GCPMachineTemplate) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
newGCPMachineTemplate, err := runtime.DefaultUnstructuredConverter.ToUnstructured(r)
if err != nil {
return apierrors.NewInvalid(GroupVersion.WithKind("GCPMachineTemplate").GroupKind(), r.Name, field.ErrorList{
return nil, apierrors.NewInvalid(GroupVersion.WithKind("GCPMachineTemplate").GroupKind(), r.Name, field.ErrorList{
field.InternalError(nil, errors.Wrap(err, "failed to convert new GCPMachineTemplate to unstructured object")),
})
}
oldGCPMachineTemplate, err := runtime.DefaultUnstructuredConverter.ToUnstructured(old)
if err != nil {
return apierrors.NewInvalid(GroupVersion.WithKind("GCPMachineTemplate").GroupKind(), r.Name, field.ErrorList{
return nil, apierrors.NewInvalid(GroupVersion.WithKind("GCPMachineTemplate").GroupKind(), r.Name, field.ErrorList{
field.InternalError(nil, errors.Wrap(err, "failed to convert old GCPMachineTemplate to unstructured object")),
})
}
Expand All @@ -80,19 +81,19 @@ func (r *GCPMachineTemplate) ValidateUpdate(old runtime.Object) error {
delete(newGCPMachineTemplateSpec, "additionalNetworkTags")

if !reflect.DeepEqual(oldGCPMachineTemplateSpec, newGCPMachineTemplateSpec) {
return apierrors.NewInvalid(GroupVersion.WithKind("GCPMachineTemplate").GroupKind(), r.Name, field.ErrorList{
return nil, apierrors.NewInvalid(GroupVersion.WithKind("GCPMachineTemplate").GroupKind(), r.Name, field.ErrorList{
field.Forbidden(field.NewPath("spec"), "cannot be modified"),
})
}

return nil
return nil, nil
}

// ValidateDelete implements webhook.Validator so a webhook will be registered for the type.
func (r *GCPMachineTemplate) ValidateDelete() error {
func (r *GCPMachineTemplate) ValidateDelete() (admission.Warnings, error) {
clusterlog.Info("validate delete", "name", r.Name)

return nil
return nil, nil
}

// Default implements webhookutil.defaulter so a webhook will be registered for the type.
Expand Down
3 changes: 2 additions & 1 deletion api/v1beta1/gcpmachinetemplate_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,13 @@ func TestGCPMachineTemplate_ValidateCreate(t *testing.T) {
test := test
t.Run(test.name, func(t *testing.T) {
t.Parallel()
err := test.template.ValidateCreate()
warn, err := test.template.ValidateCreate()
if test.wantErr {
g.Expect(err).To(HaveOccurred())
} else {
g.Expect(err).NotTo(HaveOccurred())
}
g.Expect(warn).To(BeNil())
})
}
}
14 changes: 7 additions & 7 deletions controllers/gcpcluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ func (r *GCPClusterReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Ma

clusterToInfraFn := util.ClusterToInfrastructureMapFunc(ctx, infrav1.GroupVersion.WithKind("GCPCluster"), mgr.GetClient(), &infrav1.GCPCluster{})
if err = c.Watch(
&source.Kind{Type: &clusterv1.Cluster{}},
handler.EnqueueRequestsFromMapFunc(func(o client.Object) []reconcile.Request {
requests := clusterToInfraFn(o)
source.Kind(mgr.GetCache(), &clusterv1.Cluster{}),
handler.EnqueueRequestsFromMapFunc(func(mapCtx context.Context, o client.Object) []reconcile.Request {
requests := clusterToInfraFn(mapCtx, o)
if requests == nil {
return nil
}
Expand Down Expand Up @@ -152,7 +152,7 @@ func (r *GCPClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request)

// Handle deleted clusters
if !gcpCluster.DeletionTimestamp.IsZero() {
return r.reconcileDelete(ctx, clusterScope)
return ctrl.Result{}, r.reconcileDelete(ctx, clusterScope)
}

// Handle non-deleted clusters
Expand Down Expand Up @@ -225,7 +225,7 @@ func (r *GCPClusterReconciler) reconcile(ctx context.Context, clusterScope *scop
return ctrl.Result{}, nil
}

func (r *GCPClusterReconciler) reconcileDelete(ctx context.Context, clusterScope *scope.ClusterScope) (ctrl.Result, error) {
func (r *GCPClusterReconciler) reconcileDelete(ctx context.Context, clusterScope *scope.ClusterScope) error {
log := log.FromContext(ctx)
log.Info("Reconciling Delete GCPCluster")

Expand All @@ -240,11 +240,11 @@ func (r *GCPClusterReconciler) reconcileDelete(ctx context.Context, clusterScope
if err := r.Delete(ctx); err != nil {
log.Error(err, "Reconcile error")
record.Warnf(clusterScope.GCPCluster, "GCPClusterReconcile", "Reconcile error - %v", err)
return ctrl.Result{}, err
return err
}
}

controllerutil.RemoveFinalizer(clusterScope.GCPCluster, infrav1.ClusterFinalizer)
record.Event(clusterScope.GCPCluster, "GCPClusterReconcile", "Reconciled")
return ctrl.Result{}, nil
return nil
}
Loading

0 comments on commit 5608868

Please sign in to comment.