Skip to content

Commit

Permalink
test: allow modification of apigroup for infrastructure
Browse files Browse the repository at this point in the history
  • Loading branch information
chrischdi committed Aug 23, 2024
1 parent 436544c commit 87ea563
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 2 additions & 0 deletions test/e2e/autoscaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ type AutoscalerSpecInput struct {
InfrastructureMachineTemplateKind string
InfrastructureMachinePoolTemplateKind string
InfrastructureMachinePoolKind string
InfrastructureAPIGroup string
AutoscalerVersion string

// InstallOnManagementCluster steers if the autoscaler should get installed to the management or workload cluster.
Expand Down Expand Up @@ -184,6 +185,7 @@ func AutoscalerSpec(ctx context.Context, inputGetter func() AutoscalerSpecInput)
InfrastructureMachineTemplateKind: input.InfrastructureMachineTemplateKind,
InfrastructureMachinePoolTemplateKind: input.InfrastructureMachinePoolTemplateKind,
InfrastructureMachinePoolKind: input.InfrastructureMachinePoolKind,
InfrastructureAPIGroup: input.InfrastructureAPIGroup,
WorkloadYamlPath: autoscalerWorkloadYAMLPath,
ManagementClusterProxy: input.BootstrapClusterProxy,
WorkloadClusterProxy: workloadClusterProxy,
Expand Down
11 changes: 8 additions & 3 deletions test/framework/autoscaler_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type ApplyAutoscalerToWorkloadClusterInput struct {
InfrastructureMachineTemplateKind string
InfrastructureMachinePoolTemplateKind string
InfrastructureMachinePoolKind string
InfrastructureAPIGroup string
// WorkloadYamlPath should point the yaml that will be applied on the workload cluster.
// The YAML file should:
// - Be creating the autoscaler deployment in the workload cluster
Expand Down Expand Up @@ -90,11 +91,15 @@ func ApplyAutoscalerToWorkloadCluster(ctx context.Context, input ApplyAutoscaler
workloadYamlTemplate, err := os.ReadFile(input.WorkloadYamlPath)
Expect(err).ToNot(HaveOccurred(), "failed to load %s", workloadYamlTemplate)

if input.InfrastructureAPIGroup == "" {
input.InfrastructureAPIGroup = "infrastructure.cluster.x-k8s.io"
}

// Get a server address for the Management Cluster.
// This address should be accessible from the workload cluster.
serverAddr, mgtClusterCA := getServerAddrAndCA(ctx, input.ManagementClusterProxy)
// Generate a token with the required permission that can be used by the autoscaler.
token := getAuthenticationTokenForAutoscaler(ctx, input.ManagementClusterProxy, input.Cluster.Namespace, input.Cluster.Name, input.InfrastructureMachineTemplateKind, input.InfrastructureMachinePoolTemplateKind, input.InfrastructureMachinePoolKind)
token := getAuthenticationTokenForAutoscaler(ctx, input.ManagementClusterProxy, input.Cluster.Namespace, input.Cluster.Name, input.InfrastructureAPIGroup, input.InfrastructureMachineTemplateKind, input.InfrastructureMachinePoolTemplateKind, input.InfrastructureMachinePoolKind)

workloadYaml, err := ProcessYAML(&ProcessYAMLInput{
Template: workloadYamlTemplate,
Expand Down Expand Up @@ -530,7 +535,7 @@ func EnableAutoscalerForMachinePoolTopologyAndWait(ctx context.Context, input En

// getAuthenticationTokenForAutoscaler returns a bearer authenticationToken with minimal RBAC permissions that will be used
// by the autoscaler running on the workload cluster to access the management cluster.
func getAuthenticationTokenForAutoscaler(ctx context.Context, managementClusterProxy ClusterProxy, namespace string, cluster string, infraMachineTemplateKind, infraMachinePoolTemplateKind, infraMachinePoolKind string) string {
func getAuthenticationTokenForAutoscaler(ctx context.Context, managementClusterProxy ClusterProxy, namespace string, cluster string, infraAPIGroup, infraMachineTemplateKind, infraMachinePoolTemplateKind, infraMachinePoolKind string) string {
name := fmt.Sprintf("cluster-%s", cluster)
sa := &corev1.ServiceAccount{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -553,7 +558,7 @@ func getAuthenticationTokenForAutoscaler(ctx context.Context, managementClusterP
},
{
Verbs: []string{"get", "list"},
APIGroups: []string{"infrastructure.cluster.x-k8s.io"},
APIGroups: []string{infraAPIGroup},
Resources: []string{infraMachineTemplateKind, infraMachinePoolTemplateKind, infraMachinePoolKind},
},
},
Expand Down

0 comments on commit 87ea563

Please sign in to comment.