Skip to content

Commit 2726e56

Browse files
committed
test: allow modification of apigroup for infrastructure
1 parent 6a69144 commit 2726e56

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

test/e2e/autoscaler.go

+2
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ type AutoscalerSpecInput struct {
6262
InfrastructureMachineTemplateKind string
6363
InfrastructureMachinePoolTemplateKind string
6464
InfrastructureMachinePoolKind string
65+
InfrastructureAPIGroup string
6566
AutoscalerVersion string
6667

6768
// InstallOnManagementCluster steers if the autoscaler should get installed to the management or workload cluster.
@@ -183,6 +184,7 @@ func AutoscalerSpec(ctx context.Context, inputGetter func() AutoscalerSpecInput)
183184
InfrastructureMachineTemplateKind: input.InfrastructureMachineTemplateKind,
184185
InfrastructureMachinePoolTemplateKind: input.InfrastructureMachinePoolTemplateKind,
185186
InfrastructureMachinePoolKind: input.InfrastructureMachinePoolKind,
187+
InfrastructureAPIGroup: input.InfrastructureAPIGroup,
186188
WorkloadYamlPath: autoscalerWorkloadYAMLPath,
187189
ManagementClusterProxy: input.BootstrapClusterProxy,
188190
WorkloadClusterProxy: workloadClusterProxy,

test/framework/autoscaler_helpers.go

+8-3
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ type ApplyAutoscalerToWorkloadClusterInput struct {
5252
InfrastructureMachineTemplateKind string
5353
InfrastructureMachinePoolTemplateKind string
5454
InfrastructureMachinePoolKind string
55+
InfrastructureAPIGroup string
5556
// WorkloadYamlPath should point the yaml that will be applied on the workload cluster.
5657
// The YAML file should:
5758
// - Be creating the autoscaler deployment in the workload cluster
@@ -90,11 +91,15 @@ func ApplyAutoscalerToWorkloadCluster(ctx context.Context, input ApplyAutoscaler
9091
workloadYamlTemplate, err := os.ReadFile(input.WorkloadYamlPath)
9192
Expect(err).ToNot(HaveOccurred(), "failed to load %s", workloadYamlTemplate)
9293

94+
if input.InfrastructureAPIGroup == "" {
95+
input.InfrastructureAPIGroup = "infrastructure.cluster.x-k8s.io"
96+
}
97+
9398
// Get a server address for the Management Cluster.
9499
// This address should be accessible from the workload cluster.
95100
serverAddr, mgtClusterCA := getServerAddrAndCA(ctx, input.ManagementClusterProxy)
96101
// Generate a token with the required permission that can be used by the autoscaler.
97-
token := getAuthenticationTokenForAutoscaler(ctx, input.ManagementClusterProxy, input.Cluster.Namespace, input.Cluster.Name, input.InfrastructureMachineTemplateKind, input.InfrastructureMachinePoolTemplateKind, input.InfrastructureMachinePoolKind)
102+
token := getAuthenticationTokenForAutoscaler(ctx, input.ManagementClusterProxy, input.Cluster.Namespace, input.Cluster.Name, input.InfrastructureAPIGroup, input.InfrastructureMachineTemplateKind, input.InfrastructureMachinePoolTemplateKind, input.InfrastructureMachinePoolKind)
98103

99104
workloadYaml, err := ProcessYAML(&ProcessYAMLInput{
100105
Template: workloadYamlTemplate,
@@ -502,7 +507,7 @@ func EnableAutoscalerForMachinePoolTopologyAndWait(ctx context.Context, input En
502507

503508
// getAuthenticationTokenForAutoscaler returns a bearer authenticationToken with minimal RBAC permissions that will be used
504509
// by the autoscaler running on the workload cluster to access the management cluster.
505-
func getAuthenticationTokenForAutoscaler(ctx context.Context, managementClusterProxy ClusterProxy, namespace string, cluster string, infraMachineTemplateKind, infraMachinePoolTemplateKind, infraMachinePoolKind string) string {
510+
func getAuthenticationTokenForAutoscaler(ctx context.Context, managementClusterProxy ClusterProxy, namespace string, cluster string, infraAPIGroup, infraMachineTemplateKind, infraMachinePoolTemplateKind, infraMachinePoolKind string) string {
506511
name := fmt.Sprintf("cluster-%s", cluster)
507512
sa := &corev1.ServiceAccount{
508513
ObjectMeta: metav1.ObjectMeta{
@@ -525,7 +530,7 @@ func getAuthenticationTokenForAutoscaler(ctx context.Context, managementClusterP
525530
},
526531
{
527532
Verbs: []string{"get", "list"},
528-
APIGroups: []string{"infrastructure.cluster.x-k8s.io"},
533+
APIGroups: []string{infraAPIGroup},
529534
Resources: []string{infraMachineTemplateKind, infraMachinePoolTemplateKind, infraMachinePoolKind},
530535
},
531536
},

0 commit comments

Comments
 (0)