From a5945594f85bcf453e164cbec35f5977d964a648 Mon Sep 17 00:00:00 2001 From: Christian Schlotter Date: Fri, 5 Jul 2024 10:34:58 +0200 Subject: [PATCH] Fixes for test extension --- Makefile | 2 +- test/e2e/cluster_upgrade_runtimesdk_test.go | 2 +- test/e2e/config/vsphere.yaml | 2 +- .../main/clusterclass-runtimesdk/name.yaml | 2 +- .../patch-test-extension.yaml | 8 +- .../main/clusterclass-runtimesdk/name.yaml | 2 +- .../patch-test-extension.yaml | 8 +- .../handlers/topologymutation/handler.go | 74 ++++++++++--------- 8 files changed, 56 insertions(+), 44 deletions(-) diff --git a/Makefile b/Makefile index 20cf4c8cbf..00281f0272 100644 --- a/Makefile +++ b/Makefile @@ -405,7 +405,7 @@ generate-e2e-templates-main: $(KUSTOMIZE) ## Generate test templates for the mai "$(KUSTOMIZE)" --load-restrictor LoadRestrictionsNone build "$(E2E_SUPERVISOR_TEMPLATE_DIR)/main/base" > "$(E2E_SUPERVISOR_TEMPLATE_DIR)/main/cluster-template-supervisor.yaml" cp "$(RELEASE_DIR)/main/clusterclass-template-supervisor.yaml" "$(E2E_SUPERVISOR_TEMPLATE_DIR)/main/clusterclass/clusterclass-quick-start-supervisor.yaml" "$(KUSTOMIZE)" --load-restrictor LoadRestrictionsNone build "$(E2E_SUPERVISOR_TEMPLATE_DIR)/main/clusterclass" > "$(E2E_SUPERVISOR_TEMPLATE_DIR)/main/clusterclass-quick-start-supervisor.yaml" - "$(KUSTOMIZE)" --load-restrictor LoadRestrictionsNone build "$(E2E_SUPERVISOR_TEMPLATE_DIR)/main/clusterclass-runtimesdk" > "$(E2E_SUPERVISOR_TEMPLATE_DIR)/main/clusterclass-quick-start-runtimesdk-supervisor.yaml" + "$(KUSTOMIZE)" --load-restrictor LoadRestrictionsNone build "$(E2E_SUPERVISOR_TEMPLATE_DIR)/main/clusterclass-runtimesdk" > "$(E2E_SUPERVISOR_TEMPLATE_DIR)/main/clusterclass-quick-start-supervisor-runtimesdk.yaml" cp "$(RELEASE_DIR)/main/cluster-template-topology-supervisor.yaml" "$(E2E_SUPERVISOR_TEMPLATE_DIR)/main/topology/cluster-template-topology-supervisor.yaml" "$(KUSTOMIZE)" --load-restrictor LoadRestrictionsNone build "$(E2E_SUPERVISOR_TEMPLATE_DIR)/main/topology" > "$(E2E_SUPERVISOR_TEMPLATE_DIR)/main/cluster-template-topology-supervisor.yaml" "$(KUSTOMIZE)" --load-restrictor LoadRestrictionsNone build "$(E2E_SUPERVISOR_TEMPLATE_DIR)/main/topology-runtimesdk" > "$(E2E_SUPERVISOR_TEMPLATE_DIR)/main/cluster-template-topology-runtimesdk-supervisor.yaml" diff --git a/test/e2e/cluster_upgrade_runtimesdk_test.go b/test/e2e/cluster_upgrade_runtimesdk_test.go index be4fce1701..b597eaf608 100644 --- a/test/e2e/cluster_upgrade_runtimesdk_test.go +++ b/test/e2e/cluster_upgrade_runtimesdk_test.go @@ -25,7 +25,7 @@ import ( "sigs.k8s.io/cluster-api/test/framework" ) -var _ = Describe("When upgrading a workload cluster using ClusterClass with RuntimeSDK [supervisor] [ClusterClass]", func() { +var _ = Describe("When upgrading a workload cluster using ClusterClass with RuntimeSDK [vcsim] [supervisor] [ClusterClass]", func() { const specName = "k8s-upgrade-with-runtimesdk" // aligned to CAPI Setup(specName, func(testSpecificSettingsGetter func() testSettings) { capi_e2e.ClusterUpgradeWithRuntimeSDKSpec(ctx, func() capi_e2e.ClusterUpgradeWithRuntimeSDKSpecInput { diff --git a/test/e2e/config/vsphere.yaml b/test/e2e/config/vsphere.yaml index 58d135cabb..42d812c197 100644 --- a/test/e2e/config/vsphere.yaml +++ b/test/e2e/config/vsphere.yaml @@ -159,7 +159,7 @@ providers: - sourcePath: "../../../test/e2e/data/infrastructure-vsphere-supervisor/main/cluster-template-topology-runtimesdk-supervisor.yaml" - sourcePath: "../../../test/e2e/data/infrastructure-vsphere-supervisor/main/cluster-template-supervisor.yaml" - sourcePath: "../../../test/e2e/data/infrastructure-vsphere-supervisor/main/clusterclass-quick-start-supervisor.yaml" - - sourcePath: "../../../test/e2e/data/infrastructure-vsphere-supervisor/main/clusterclass-quick-start-runtimesdk-supervisor.yaml" + - sourcePath: "../../../test/e2e/data/infrastructure-vsphere-supervisor/main/clusterclass-quick-start-supervisor-runtimesdk.yaml" - sourcePath: "../../../test/e2e/data/infrastructure-vsphere-supervisor/main/cluster-template-install-on-bootstrap-supervisor.yaml" - sourcePath: "../../../test/e2e/data/infrastructure-vsphere-supervisor/main/cluster-template-conformance-supervisor.yaml" - sourcePath: "../../../test/e2e/data/infrastructure-vsphere-supervisor/main/cluster-template-ownerrefs-finalizers-supervisor.yaml" diff --git a/test/e2e/data/infrastructure-vsphere-govmomi/main/clusterclass-runtimesdk/name.yaml b/test/e2e/data/infrastructure-vsphere-govmomi/main/clusterclass-runtimesdk/name.yaml index 53324626ff..c65d3025c0 100644 --- a/test/e2e/data/infrastructure-vsphere-govmomi/main/clusterclass-runtimesdk/name.yaml +++ b/test/e2e/data/infrastructure-vsphere-govmomi/main/clusterclass-runtimesdk/name.yaml @@ -1,3 +1,3 @@ - op: replace path: /metadata/name - value: quick-start-runtimesdk \ No newline at end of file + value: ${CLUSTER_CLASS_NAME}-runtimesdk \ No newline at end of file diff --git a/test/e2e/data/infrastructure-vsphere-govmomi/main/clusterclass-runtimesdk/patch-test-extension.yaml b/test/e2e/data/infrastructure-vsphere-govmomi/main/clusterclass-runtimesdk/patch-test-extension.yaml index a4a5379ef1..6ac7dfab75 100644 --- a/test/e2e/data/infrastructure-vsphere-govmomi/main/clusterclass-runtimesdk/patch-test-extension.yaml +++ b/test/e2e/data/infrastructure-vsphere-govmomi/main/clusterclass-runtimesdk/patch-test-extension.yaml @@ -3,8 +3,10 @@ value: - name: test-patch external: - generateExtension: generate-patches.capv-test-extension - validateExtension: validate-topology.capv-test-extension - discoverVariablesExtension: discover-variables.capv-test-extension + generateExtension: generate-patches.k8s-upgrade-with-runtimesdk + validateExtension: validate-topology.k8s-upgrade-with-runtimesdk + discoverVariablesExtension: discover-variables.k8s-upgrade-with-runtimesdk + settings: + testMode: govmomi - op: remove path: /spec/variables diff --git a/test/e2e/data/infrastructure-vsphere-supervisor/main/clusterclass-runtimesdk/name.yaml b/test/e2e/data/infrastructure-vsphere-supervisor/main/clusterclass-runtimesdk/name.yaml index 53324626ff..6e69902e0b 100644 --- a/test/e2e/data/infrastructure-vsphere-supervisor/main/clusterclass-runtimesdk/name.yaml +++ b/test/e2e/data/infrastructure-vsphere-supervisor/main/clusterclass-runtimesdk/name.yaml @@ -1,3 +1,3 @@ - op: replace path: /metadata/name - value: quick-start-runtimesdk \ No newline at end of file + value: ${CLUSTER_CLASS_NAME}-runtimesdk diff --git a/test/e2e/data/infrastructure-vsphere-supervisor/main/clusterclass-runtimesdk/patch-test-extension.yaml b/test/e2e/data/infrastructure-vsphere-supervisor/main/clusterclass-runtimesdk/patch-test-extension.yaml index a4a5379ef1..9f879e5b58 100644 --- a/test/e2e/data/infrastructure-vsphere-supervisor/main/clusterclass-runtimesdk/patch-test-extension.yaml +++ b/test/e2e/data/infrastructure-vsphere-supervisor/main/clusterclass-runtimesdk/patch-test-extension.yaml @@ -3,8 +3,10 @@ value: - name: test-patch external: - generateExtension: generate-patches.capv-test-extension - validateExtension: validate-topology.capv-test-extension - discoverVariablesExtension: discover-variables.capv-test-extension + generateExtension: generate-patches.k8s-upgrade-with-runtimesdk + validateExtension: validate-topology.k8s-upgrade-with-runtimesdk + discoverVariablesExtension: discover-variables.k8s-upgrade-with-runtimesdk + settings: + testMode: supervisor - op: remove path: /spec/variables diff --git a/test/extension/handlers/topologymutation/handler.go b/test/extension/handlers/topologymutation/handler.go index 806ba6337f..80888a8e3b 100644 --- a/test/extension/handlers/topologymutation/handler.go +++ b/test/extension/handlers/topologymutation/handler.go @@ -182,23 +182,26 @@ func patchKubeadmConfigTemplate(_ context.Context, tpl *bootstrapv1.KubeadmConfi // patch preKubeadmScript preKubeadmScript, err := topologymutation.GetStringVariable(templateVariables, "preKubeadmScript") - if err != nil { - return err - } - version, err := topologymutation.GetStringVariable(templateVariables, "builtin.machineDeployment.version") - if err != nil { + preKubeadmScriptNotFound := topologymutation.IsNotFoundError(err) + if err != nil && !preKubeadmScriptNotFound { return err } + if !preKubeadmScriptNotFound { + version, err := topologymutation.GetStringVariable(templateVariables, "builtin.machineDeployment.version") + if err != nil { + return err + } - versionRegex := regexp.MustCompile("(KUBERNETES_VERSION=.*)") - tpl.Spec.Template.Spec.Files = append(tpl.Spec.Template.Spec.Files, - bootstrapv1.File{ - Owner: "root:root", - Path: "/etc/pre-kubeadm-commands/10-prekubeadmscript.sh", - Permissions: "0755", - Content: versionRegex.ReplaceAllString(preKubeadmScript, fmt.Sprintf("KUBERNETES_VERSION=%s", version)), - }, - ) + versionRegex := regexp.MustCompile("(KUBERNETES_VERSION=.*)") + tpl.Spec.Template.Spec.Files = append(tpl.Spec.Template.Spec.Files, + bootstrapv1.File{ + Owner: "root:root", + Path: "/etc/pre-kubeadm-commands/10-prekubeadmscript.sh", + Permissions: "0755", + Content: versionRegex.ReplaceAllString(preKubeadmScript, fmt.Sprintf("KUBERNETES_VERSION=%s", version)), + }, + ) + } return nil } @@ -337,7 +340,7 @@ func (h *ExtensionHandlers) ValidateTopology(ctx context.Context, _ *runtimehook } // DiscoverVariables implements the HandlerFunc for the DiscoverVariables hook. -func (h *ExtensionHandlers) DiscoverVariables(ctx context.Context, _ *runtimehooksv1.DiscoverVariablesRequest, resp *runtimehooksv1.DiscoverVariablesResponse) { +func (h *ExtensionHandlers) DiscoverVariables(ctx context.Context, req *runtimehooksv1.DiscoverVariablesRequest, resp *runtimehooksv1.DiscoverVariablesResponse) { log := ctrl.LoggerFrom(ctx) log.Info("DiscoverVariables called") @@ -385,28 +388,33 @@ func (h *ExtensionHandlers) DiscoverVariables(ctx context.Context, _ *runtimehoo }, }, }, - { - Name: "infraServer", - Required: true, - Schema: clusterv1.VariableSchema{ - OpenAPIV3Schema: clusterv1.JSONSchemaProps{ - Type: "object", - Properties: map[string]clusterv1.JSONSchemaProps{ - "url": {Type: "string"}, - "thumbprint": {Type: "string"}, + } + + if req.Settings["testMode"] == "govmomi" { + resp.Variables = append(resp.Variables, []clusterv1.ClusterClassVariable{ + { + Name: "infraServer", + Required: true, + Schema: clusterv1.VariableSchema{ + OpenAPIV3Schema: clusterv1.JSONSchemaProps{ + Type: "object", + Properties: map[string]clusterv1.JSONSchemaProps{ + "url": {Type: "string"}, + "thumbprint": {Type: "string"}, + }, }, }, }, - }, - { - Name: "credsSecretName", - Required: true, - Schema: clusterv1.VariableSchema{ - OpenAPIV3Schema: clusterv1.JSONSchemaProps{ - Type: "string", - Description: "Secret containing the credentials for the infra cluster.", + { + Name: "credsSecretName", + Required: true, + Schema: clusterv1.VariableSchema{ + OpenAPIV3Schema: clusterv1.JSONSchemaProps{ + Type: "string", + Description: "Secret containing the credentials for the infra cluster.", + }, }, }, - }, + }...) } }