Skip to content

Commit

Permalink
chore: bump CAPI to v1.5.0-rc1
Browse files Browse the repository at this point in the history
Signed-off-by: Richard Case <richard.case@outlook.com>
  • Loading branch information
richardcase committed Jul 20, 2023
1 parent 82fbf78 commit 94d9c05
Show file tree
Hide file tree
Showing 24 changed files with 232 additions and 255 deletions.
15 changes: 9 additions & 6 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
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
check-latest: true
go-version: 1.20
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.3
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 public.ecr.aws/docker/library/golang:1.20.6 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-rc.1/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-rc.1",
"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())
})
}
}
6 changes: 3 additions & 3 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
14 changes: 7 additions & 7 deletions controllers/gcpmachine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,26 +62,26 @@ func (r *GCPMachineReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Ma
For(&infrav1.GCPMachine{}).
WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue)).
Watches(
&source.Kind{Type: &clusterv1.Machine{}},
&clusterv1.Machine{},
handler.EnqueueRequestsFromMapFunc(util.MachineToInfrastructureMapFunc(infrav1.GroupVersion.WithKind("GCPMachine"))),
).
Watches(
&source.Kind{Type: &infrav1.GCPCluster{}},
&infrav1.GCPCluster{},
handler.EnqueueRequestsFromMapFunc(r.GCPClusterToGCPMachines(ctx)),
).
Build(r)
if err != nil {
return errors.Wrap(err, "error creating controller")
}

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

// 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(log),
); err != nil {
Expand All @@ -95,7 +95,7 @@ func (r *GCPMachineReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Ma
// of GCPMachines.
func (r *GCPMachineReconciler) GCPClusterToGCPMachines(ctx context.Context) handler.MapFunc {
log := ctrl.LoggerFrom(ctx)
return func(o client.Object) []ctrl.Request {
return func(mapCtx context.Context, o client.Object) []ctrl.Request {
result := []ctrl.Request{}

c, ok := o.(*infrav1.GCPCluster)
Expand All @@ -104,7 +104,7 @@ func (r *GCPMachineReconciler) GCPClusterToGCPMachines(ctx context.Context) hand
return nil
}

cluster, err := util.GetOwnerCluster(ctx, r.Client, c.ObjectMeta)
cluster, err := util.GetOwnerCluster(mapCtx, r.Client, c.ObjectMeta)
switch {
case apierrors.IsNotFound(err) || cluster == nil:
return result
Expand All @@ -115,7 +115,7 @@ func (r *GCPMachineReconciler) GCPClusterToGCPMachines(ctx context.Context) hand

labels := map[string]string{clusterv1.ClusterNameLabel: cluster.Name}
machineList := &clusterv1.MachineList{}
if err := r.List(ctx, machineList, client.InNamespace(c.Namespace), client.MatchingLabels(labels)); err != nil {
if err := r.List(mapCtx, machineList, client.InNamespace(c.Namespace), client.MatchingLabels(labels)); err != nil {
log.Error(err, "failed to list Machines")
return nil
}
Expand Down
Loading

0 comments on commit 94d9c05

Please sign in to comment.