Skip to content

Commit

Permalink
Add resources to policy rule
Browse files Browse the repository at this point in the history
  • Loading branch information
willie-yao committed Mar 23, 2024
1 parent 886778a commit be01bdf
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 23 deletions.
20 changes: 11 additions & 9 deletions test/e2e/autoscaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ type AutoscalerSpecInput struct {
// InfrastructureMachineTemplateKind should be the plural form of the InfraMachineTemplate kind.
// It should be specified in lower case.
// Example: dockermachinetemplates.
InfrastructureMachineTemplateKind string
AutoscalerVersion string
InfrastructureMachineTemplateKind string
InfrastructureMachinePoolTemplateKind string
AutoscalerVersion string

// Allows to inject a function to be run after test namespace is created.
// If not specified, this is a no-op.
Expand Down Expand Up @@ -156,13 +157,14 @@ func AutoscalerSpec(ctx context.Context, inputGetter func() AutoscalerSpecInput)
By("Installing the autoscaler on the workload cluster")
autoscalerWorkloadYAMLPath := input.E2EConfig.GetVariable(AutoscalerWorkloadYAMLPath)
framework.ApplyAutoscalerToWorkloadCluster(ctx, framework.ApplyAutoscalerToWorkloadClusterInput{
ArtifactFolder: input.ArtifactFolder,
InfrastructureMachineTemplateKind: input.InfrastructureMachineTemplateKind,
WorkloadYamlPath: autoscalerWorkloadYAMLPath,
ManagementClusterProxy: input.BootstrapClusterProxy,
WorkloadClusterProxy: workloadClusterProxy,
Cluster: clusterResources.Cluster,
AutoscalerVersion: input.AutoscalerVersion,
ArtifactFolder: input.ArtifactFolder,
InfrastructureMachineTemplateKind: input.InfrastructureMachineTemplateKind,
InfrastructureMachinePoolTemplateKind: input.InfrastructureMachinePoolTemplateKind,
WorkloadYamlPath: autoscalerWorkloadYAMLPath,
ManagementClusterProxy: input.BootstrapClusterProxy,
WorkloadClusterProxy: workloadClusterProxy,
Cluster: clusterResources.Cluster,
AutoscalerVersion: input.AutoscalerVersion,
}, input.E2EConfig.GetIntervals(specName, "wait-controllers")...)

By("Creating workload that forces the system to scale up")
Expand Down
19 changes: 10 additions & 9 deletions test/e2e/autoscaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,16 @@ import (
var _ = Describe("When using the autoscaler with Cluster API using ClusterClass [ClusterClass]", func() {
AutoscalerSpec(ctx, func() AutoscalerSpecInput {
return AutoscalerSpecInput{
E2EConfig: e2eConfig,
ClusterctlConfigPath: clusterctlConfigPath,
BootstrapClusterProxy: bootstrapClusterProxy,
ArtifactFolder: artifactFolder,
SkipCleanup: skipCleanup,
InfrastructureProvider: ptr.To("docker"),
InfrastructureMachineTemplateKind: "dockermachinetemplates",
Flavor: ptr.To("topology-autoscaler"),
AutoscalerVersion: "v1.29.0",
E2EConfig: e2eConfig,
ClusterctlConfigPath: clusterctlConfigPath,
BootstrapClusterProxy: bootstrapClusterProxy,
ArtifactFolder: artifactFolder,
SkipCleanup: skipCleanup,
InfrastructureProvider: ptr.To("docker"),
InfrastructureMachineTemplateKind: "dockermachinetemplates",
InfrastructureMachinePoolTemplateKind: "dockermachinepooltemplates",
Flavor: ptr.To("topology-autoscaler"),
AutoscalerVersion: "v1.29.0",
}
})
})
11 changes: 6 additions & 5 deletions test/framework/autoscaler_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ import (
type ApplyAutoscalerToWorkloadClusterInput struct {
ClusterctlConfigPath string

ArtifactFolder string
InfrastructureMachineTemplateKind string
ArtifactFolder string
InfrastructureMachineTemplateKind string
InfrastructureMachinePoolTemplateKind 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 @@ -89,7 +90,7 @@ func ApplyAutoscalerToWorkloadCluster(ctx context.Context, input ApplyAutoscaler
// 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)
token := getAuthenticationTokenForAutoscaler(ctx, input.ManagementClusterProxy, input.Cluster.Namespace, input.Cluster.Name, input.InfrastructureMachineTemplateKind, input.InfrastructureMachinePoolTemplateKind)

workloadYaml, err := ProcessYAML(&ProcessYAMLInput{
Template: workloadYamlTemplate,
Expand Down Expand Up @@ -403,7 +404,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 string) string {
func getAuthenticationTokenForAutoscaler(ctx context.Context, managementClusterProxy ClusterProxy, namespace string, cluster string, infraMachineTemplateKind string, infraMachinePoolTemplateKind string) string {
name := fmt.Sprintf("cluster-%s", cluster)
sa := &corev1.ServiceAccount{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -427,7 +428,7 @@ func getAuthenticationTokenForAutoscaler(ctx context.Context, managementClusterP
{
Verbs: []string{"get", "list"},
APIGroups: []string{"infrastructure.cluster.x-k8s.io"},
Resources: []string{infraMachineTemplateKind},
Resources: []string{infraMachineTemplateKind, infraMachinePoolTemplateKind, "dockermachinepools"},
},
},
}
Expand Down

0 comments on commit be01bdf

Please sign in to comment.