Skip to content

Commit

Permalink
Fixes for test extension
Browse files Browse the repository at this point in the history
  • Loading branch information
chrischdi committed Jul 5, 2024
1 parent e9eec9e commit a594559
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 44 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/cluster_upgrade_runtimesdk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
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 @@ -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"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
- op: replace
path: /metadata/name
value: quick-start-runtimesdk
value: ${CLUSTER_CLASS_NAME}-runtimesdk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
- op: replace
path: /metadata/name
value: quick-start-runtimesdk
value: ${CLUSTER_CLASS_NAME}-runtimesdk
Original file line number Diff line number Diff line change
Expand Up @@ -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
74 changes: 41 additions & 33 deletions test/extension/handlers/topologymutation/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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")

Expand Down Expand Up @@ -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.",
},
},
},
},
}...)
}
}

0 comments on commit a594559

Please sign in to comment.