From d8bd40592a776d62e272f1f82de629d052b313ce Mon Sep 17 00:00:00 2001 From: Christian Schlotter Date: Wed, 17 Jul 2024 07:42:29 +0200 Subject: [PATCH] review fixes --- Makefile | 2 +- test/e2e/config/vsphere.yaml | 2 +- .../config/default/kustomization.yaml | 2 - .../config/default/manager_image_patch.yaml | 2 +- .../handlers/topologymutation/handler.go | 80 ++++++++++--------- test/extension/tilt-provider.yaml | 2 +- 6 files changed, 45 insertions(+), 45 deletions(-) diff --git a/Makefile b/Makefile index 00281f0272..540cd00969 100644 --- a/Makefile +++ b/Makefile @@ -235,7 +235,7 @@ NET_OPERATOR_IMAGE_NAME ?= cluster-api-net-operator NET_OPERATOR_IMG ?= $(STAGING_REGISTRY)/$(NET_OPERATOR_IMAGE_NAME) # test-extension -TEST_EXTENSION_IMAGE_NAME ?= cluster-api-test-extension +TEST_EXTENSION_IMAGE_NAME ?= cluster-api-vsphere-test-extension TEST_EXTENSION_IMG ?= $(STAGING_REGISTRY)/$(TEST_EXTENSION_IMAGE_NAME) # boskosctl diff --git a/test/e2e/config/vsphere.yaml b/test/e2e/config/vsphere.yaml index ab630eaa7c..6f5a982588 100644 --- a/test/e2e/config/vsphere.yaml +++ b/test/e2e/config/vsphere.yaml @@ -16,7 +16,7 @@ images: loadBehavior: mustLoad - name: gcr.io/k8s-staging-capi-vsphere/cluster-api-net-operator-{ARCH}:dev loadBehavior: mustLoad - - name: gcr.io/k8s-staging-capi-vsphere/cluster-api-test-extension-{ARCH}:dev + - name: gcr.io/k8s-staging-capi-vsphere/cluster-api-vsphere-test-extension-{ARCH}:dev loadBehavior: mustLoad - name: gcr.io/k8s-staging-capi-vsphere/extra/vm-operator:v1.8.6-0-gde75746a loadBehavior: tryLoad diff --git a/test/extension/config/default/kustomization.yaml b/test/extension/config/default/kustomization.yaml index 2c33c4391b..6afdad8832 100644 --- a/test/extension/config/default/kustomization.yaml +++ b/test/extension/config/default/kustomization.yaml @@ -3,8 +3,6 @@ namespace: capv-test-extension namePrefix: capv-test-extension- commonLabels: - # capvsim is not a provider, but by adding this label - # we can get this installed by Cluster APIs Tiltfile and by the clusterctl machinery we use in E2E tests. cluster.x-k8s.io/provider: "runtime-extension-capv-test" resources: diff --git a/test/extension/config/default/manager_image_patch.yaml b/test/extension/config/default/manager_image_patch.yaml index cd52fe1759..ba67a7d45a 100644 --- a/test/extension/config/default/manager_image_patch.yaml +++ b/test/extension/config/default/manager_image_patch.yaml @@ -7,5 +7,5 @@ spec: template: spec: containers: - - image: gcr.io/k8s-staging-capi-vsphere/cluster-api-test-extension:dev + - image: gcr.io/k8s-staging-capi-vsphere/cluster-api-vsphere-test-extension:dev name: manager diff --git a/test/extension/handlers/topologymutation/handler.go b/test/extension/handlers/topologymutation/handler.go index b89c22ecab..6f19769fb7 100644 --- a/test/extension/handlers/topologymutation/handler.go +++ b/test/extension/handlers/topologymutation/handler.go @@ -77,50 +77,52 @@ func (h *ExtensionHandlers) GeneratePatches(ctx context.Context, req *runtimehoo // By using WalkTemplates it is possible to implement patches using typed API objects, which makes code // easier to read and less error prone than using unstructured or working with raw json/yaml. // IMPORTANT: by unit testing this func/nested func properly, it is possible to prevent unexpected rollouts when patches are modified. - topologymutation.WalkTemplates(ctx, h.decoder, req, resp, func(ctx context.Context, obj runtime.Object, variables map[string]apiextensionsv1.JSON, holderRef runtimehooksv1.HolderReference) error { - log := ctrl.LoggerFrom(ctx) - - isControlPlane := holderRef.Kind == "KubeadmControlPlane" - - switch obj := obj.(type) { - case *controlplanev1.KubeadmControlPlaneTemplate: - if err := patchKubeadmControlPlaneTemplate(ctx, obj, variables); err != nil { - log.Error(err, "Error patching KubeadmControlPlaneTemplate") - return errors.Wrap(err, "error patching KubeadmControlPlaneTemplate") - } - case *bootstrapv1.KubeadmConfigTemplate: - if err := patchKubeadmConfigTemplate(ctx, obj, variables); err != nil { - log.Error(err, "Error patching KubeadmConfigTemplate") - return errors.Wrap(err, "error patching KubeadmConfigTemplate") - } - case *infrav1.VSphereClusterTemplate: - if err := patchGovmomiClusterTemplate(ctx, obj, variables); err != nil { - log.Error(err, "Error patching VSphereClusterTemplate") - return errors.Wrap(err, "error patching VSphereClusterTemplate") - } - case *infrav1.VSphereMachineTemplate: - if err := patchGovmomiMachineTemplate(ctx, obj, variables, isControlPlane); err != nil { - log.Error(err, "Error patching VSphereMachineTemplate") - return errors.Wrap(err, "error patching VSphereMachineTemplate") + topologymutation.WalkTemplates(ctx, h.decoder, req, resp, + func(ctx context.Context, obj runtime.Object, variables map[string]apiextensionsv1.JSON, holderRef runtimehooksv1.HolderReference) error { + log := ctrl.LoggerFrom(ctx) + + isControlPlane := holderRef.Kind == "KubeadmControlPlane" + + switch obj := obj.(type) { + case *controlplanev1.KubeadmControlPlaneTemplate: + if err := patchKubeadmControlPlaneTemplate(ctx, obj, variables); err != nil { + log.Error(err, "Error patching KubeadmControlPlaneTemplate") + return errors.Wrap(err, "error patching KubeadmControlPlaneTemplate") + } + case *bootstrapv1.KubeadmConfigTemplate: + if err := patchKubeadmConfigTemplate(ctx, obj, variables); err != nil { + log.Error(err, "Error patching KubeadmConfigTemplate") + return errors.Wrap(err, "error patching KubeadmConfigTemplate") + } + case *infrav1.VSphereClusterTemplate: + if err := patchGovmomiClusterTemplate(ctx, obj, variables); err != nil { + log.Error(err, "Error patching VSphereClusterTemplate") + return errors.Wrap(err, "error patching VSphereClusterTemplate") + } + case *infrav1.VSphereMachineTemplate: + if err := patchGovmomiMachineTemplate(ctx, obj, variables, isControlPlane); err != nil { + log.Error(err, "Error patching VSphereMachineTemplate") + return errors.Wrap(err, "error patching VSphereMachineTemplate") + } + case *vmwarev1.VSphereClusterTemplate: + if err := patchSupervisorClusterTemplate(ctx, obj, variables); err != nil { + log.Error(err, "Error patching VSphereClusterTemplate") + return errors.Wrap(err, "error patching VSphereClusterTemplate") + } + case *vmwarev1.VSphereMachineTemplate: + if err := patchSupervisorMachineTemplate(ctx, obj, variables, isControlPlane); err != nil { + log.Error(err, "Error patching VSphereMachineTemplate") + return errors.Wrap(err, "error patching VSphereMachineTemplate") + } } - case *vmwarev1.VSphereClusterTemplate: - if err := patchSupervisorClusterTemplate(ctx, obj, variables); err != nil { - log.Error(err, "Error patching VSphereClusterTemplate") - return errors.Wrap(err, "error patching VSphereClusterTemplate") - } - case *vmwarev1.VSphereMachineTemplate: - if err := patchSupervisorMachineTemplate(ctx, obj, variables, isControlPlane); err != nil { - log.Error(err, "Error patching VSphereMachineTemplate") - return errors.Wrap(err, "error patching VSphereMachineTemplate") - } - } - return nil - }, + return nil + }, // Use a merge-patch instead of a JSON patch because WalkTemplates would create // an incompatible patch for vmwarev1.VSphereClusterTemplate because we provide // an empty template without a set `.spec` and due to omitempty // `.spec.template.spec.controlPlaneEndpoint` does not exist. - topologymutation.PatchFormat{Format: runtimehooksv1.JSONMergePatchType}) + topologymutation.PatchFormat{Format: runtimehooksv1.JSONMergePatchType}, + ) } // patchKubeadmControlPlaneTemplate patches the KubeadmControlPlaneTemplate. diff --git a/test/extension/tilt-provider.yaml b/test/extension/tilt-provider.yaml index 9a8807e975..8723800266 100644 --- a/test/extension/tilt-provider.yaml +++ b/test/extension/tilt-provider.yaml @@ -2,7 +2,7 @@ - name: capv-test-extension config: version: v1.11.99 - image: gcr.io/k8s-staging-capi-vsphere/cluster-api-test-extension + image: gcr.io/k8s-staging-capi-vsphere/cluster-api-vsphere-test-extension live_reload_deps: - main.go - handlers