Skip to content

Commit b32476d

Browse files
authored
Merge pull request kubernetes-sigs#10788 from chrischdi/pr-make-upgrade-runtime-sdk-public
🌱 test: export method and types for ClusterUpgradeWithRuntimeSDK
2 parents ef8c34d + 186a0a1 commit b32476d

File tree

2 files changed

+28
-13
lines changed

2 files changed

+28
-13
lines changed

test/e2e/cluster_upgrade_runtimesdk.go

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ func hookResponsesConfigMapName(clusterName string) string {
5454
return fmt.Sprintf("%s-%s", clusterName, hookResponsesConfigMapNameSuffix)
5555
}
5656

57-
// clusterUpgradeWithRuntimeSDKSpecInput is the input for clusterUpgradeWithRuntimeSDKSpec.
58-
type clusterUpgradeWithRuntimeSDKSpecInput struct {
57+
// ClusterUpgradeWithRuntimeSDKSpecInput is the input for clusterUpgradeWithRuntimeSDKSpec.
58+
type ClusterUpgradeWithRuntimeSDKSpecInput struct {
5959
E2EConfig *clusterctl.E2EConfig
6060
ClusterctlConfigPath string
6161
BootstrapClusterProxy framework.ClusterProxy
@@ -89,21 +89,27 @@ type clusterUpgradeWithRuntimeSDKSpecInput struct {
8989
// Allows to inject a function to be run after the cluster is upgraded.
9090
// If not specified, this is a no-op.
9191
PostUpgrade func(managementClusterProxy framework.ClusterProxy, workloadClusterNamespace, workloadClusterName string)
92+
93+
// ExtensionServiceNamespace is the namespace where the service for the Runtime SDK is located
94+
// and is used to configure in the test-namespace scoped ExtensionConfig.
95+
ExtensionServiceNamespace string
96+
// ExtensionServiceName is the name of the service to configure in the test-namespace scoped ExtensionConfig.
97+
ExtensionServiceName string
9298
}
9399

94-
// clusterUpgradeWithRuntimeSDKSpec implements a spec that upgrades a cluster and runs the Kubernetes conformance suite.
100+
// ClusterUpgradeWithRuntimeSDKSpec implements a spec that upgrades a cluster and runs the Kubernetes conformance suite.
95101
// Upgrading a cluster refers to upgrading the control-plane and worker nodes (managed by MD and machine pools).
96102
// NOTE: This test only works with a KubeadmControlPlane.
97103
// NOTE: This test works with Clusters with and without ClusterClass.
98104
// When using ClusterClass the ClusterClass must have the variables "etcdImageTag" and "coreDNSImageTag" of type string.
99105
// Those variables should have corresponding patches which set the etcd and CoreDNS tags in KCP.
100-
func clusterUpgradeWithRuntimeSDKSpec(ctx context.Context, inputGetter func() clusterUpgradeWithRuntimeSDKSpecInput) {
106+
func ClusterUpgradeWithRuntimeSDKSpec(ctx context.Context, inputGetter func() ClusterUpgradeWithRuntimeSDKSpecInput) {
101107
const (
102108
specName = "k8s-upgrade-with-runtimesdk"
103109
)
104110

105111
var (
106-
input clusterUpgradeWithRuntimeSDKSpecInput
112+
input ClusterUpgradeWithRuntimeSDKSpecInput
107113
namespace *corev1.Namespace
108114
cancelWatches context.CancelFunc
109115

@@ -125,6 +131,9 @@ func clusterUpgradeWithRuntimeSDKSpec(ctx context.Context, inputGetter func() cl
125131
Expect(input.E2EConfig.Variables).To(HaveKey(KubernetesVersionUpgradeFrom))
126132
Expect(input.E2EConfig.Variables).To(HaveKey(KubernetesVersionUpgradeTo))
127133

134+
Expect(input.ExtensionServiceNamespace).ToNot(BeEmpty())
135+
Expect(input.ExtensionServiceName).ToNot(BeEmpty())
136+
128137
if input.ControlPlaneMachineCount == nil {
129138
controlPlaneMachineCount = 1
130139
} else {
@@ -153,7 +162,7 @@ func clusterUpgradeWithRuntimeSDKSpec(ctx context.Context, inputGetter func() cl
153162
By("Deploy Test Extension ExtensionConfig")
154163

155164
Expect(input.BootstrapClusterProxy.GetClient().Create(ctx,
156-
extensionConfig(specName, namespace.Name))).
165+
extensionConfig(specName, namespace.Name, input.ExtensionServiceNamespace, input.ExtensionServiceName))).
157166
To(Succeed(), "Failed to create the extension config")
158167

159168
By("Creating a workload cluster; creation waits for BeforeClusterCreateHook to gate the operation")
@@ -291,7 +300,7 @@ func clusterUpgradeWithRuntimeSDKSpec(ctx context.Context, inputGetter func() cl
291300
AfterEach(func() {
292301
// Delete the extensionConfig first to ensure the BeforeDeleteCluster hook doesn't block deletion.
293302
Eventually(func() error {
294-
return input.BootstrapClusterProxy.GetClient().Delete(ctx, extensionConfig(specName, namespace.Name))
303+
return input.BootstrapClusterProxy.GetClient().Delete(ctx, extensionConfig(specName, namespace.Name, input.ExtensionServiceNamespace, input.ExtensionServiceName))
295304
}, 10*time.Second, 1*time.Second).Should(Succeed(), "delete extensionConfig failed")
296305

297306
// Dumps all the resources in the spec Namespace, then cleanups the cluster object and the spec Namespace itself.
@@ -401,23 +410,23 @@ func machineSetPreflightChecksTestHandler(ctx context.Context, c client.Client,
401410
// We make sure this cluster-wide object does not conflict with others by using a random generated
402411
// name and a NamespaceSelector selecting on the namespace of the current test.
403412
// Thus, this object is "namespaced" to the current test even though it's a cluster-wide object.
404-
func extensionConfig(name, namespace string) *runtimev1.ExtensionConfig {
413+
func extensionConfig(name, namespace, extensionServiceNamespace, extensionServiceName string) *runtimev1.ExtensionConfig {
405414
return &runtimev1.ExtensionConfig{
406415
ObjectMeta: metav1.ObjectMeta{
407416
// Note: We have to use a constant name here as we have to be able to reference it in the ClusterClass
408417
// when configuring external patches.
409418
Name: name,
410419
Annotations: map[string]string{
411420
// Note: this assumes the test extension get deployed in the default namespace defined in its own runtime-extensions-components.yaml
412-
runtimev1.InjectCAFromSecretAnnotation: "test-extension-system/test-extension-webhook-service-cert",
421+
runtimev1.InjectCAFromSecretAnnotation: fmt.Sprintf("%s/%s-cert", extensionServiceNamespace, extensionServiceName),
413422
},
414423
},
415424
Spec: runtimev1.ExtensionConfigSpec{
416425
ClientConfig: runtimev1.ClientConfig{
417426
Service: &runtimev1.ServiceReference{
418-
Name: "test-extension-webhook-service",
427+
Name: extensionServiceName,
419428
// Note: this assumes the test extension get deployed in the default namespace defined in its own runtime-extensions-components.yaml
420-
Namespace: "test-extension-system",
429+
Namespace: extensionServiceNamespace,
421430
},
422431
},
423432
NamespaceSelector: &metav1.LabelSelector{

test/e2e/cluster_upgrade_runtimesdk_test.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ import (
3030
)
3131

3232
var _ = Describe("When upgrading a workload cluster using ClusterClass with RuntimeSDK [ClusterClass]", func() {
33-
clusterUpgradeWithRuntimeSDKSpec(ctx, func() clusterUpgradeWithRuntimeSDKSpecInput {
33+
ClusterUpgradeWithRuntimeSDKSpec(ctx, func() ClusterUpgradeWithRuntimeSDKSpecInput {
3434
version, err := semver.ParseTolerant(e2eConfig.GetVariable(KubernetesVersionUpgradeFrom))
3535
Expect(err).ToNot(HaveOccurred(), "Invalid argument, KUBERNETES_VERSION_UPGRADE_FROM is not a valid version")
3636
if version.LT(semver.MustParse("1.24.0")) {
3737
Fail("This test only supports upgrades from Kubernetes >= v1.24.0")
3838
}
3939

40-
return clusterUpgradeWithRuntimeSDKSpecInput{
40+
return ClusterUpgradeWithRuntimeSDKSpecInput{
4141
E2EConfig: e2eConfig,
4242
ClusterctlConfigPath: clusterctlConfigPath,
4343
BootstrapClusterProxy: bootstrapClusterProxy,
@@ -51,6 +51,12 @@ var _ = Describe("When upgrading a workload cluster using ClusterClass with Runt
5151
},
5252
// "upgrades" is the same as the "topology" flavor but with an additional MachinePool.
5353
Flavor: ptr.To("upgrades-runtimesdk"),
54+
// The runtime extension gets deployed to the test-extension-system namespace and is exposed
55+
// by the test-extension-webhook-service.
56+
// The below values are used when creating the cluster-wide ExtensionConfig to refer
57+
// the actual service.
58+
ExtensionServiceNamespace: "test-extension-system",
59+
ExtensionServiceName: "test-extension-webhook-service",
5460
}
5561
})
5662
})

0 commit comments

Comments
 (0)