Skip to content

Commit

Permalink
review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
chrischdi committed Jul 17, 2024
1 parent 4e5cf03 commit d8bd405
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 45 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/config/vsphere.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions test/extension/config/default/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion test/extension/config/default/manager_image_patch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
80 changes: 41 additions & 39 deletions test/extension/handlers/topologymutation/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion test/extension/tilt-provider.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d8bd405

Please sign in to comment.