diff --git a/Makefile b/Makefile index 749b3f2524..10836ae3bc 100644 --- a/Makefile +++ b/Makefile @@ -408,6 +408,7 @@ generate-e2e-templates-main: $(KUSTOMIZE) ## Generate test templates for the mai "$(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-autoscaler" > "$(E2E_SUPERVISOR_TEMPLATE_DIR)/main/cluster-template-topology-autoscaler-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" "$(KUSTOMIZE)" --load-restrictor LoadRestrictionsNone build "$(E2E_SUPERVISOR_TEMPLATE_DIR)/main/conformance" > "$(E2E_SUPERVISOR_TEMPLATE_DIR)/main/cluster-template-conformance-supervisor.yaml" "$(KUSTOMIZE)" --load-restrictor LoadRestrictionsNone build "$(E2E_SUPERVISOR_TEMPLATE_DIR)/main/fast-rollout" > "$(E2E_SUPERVISOR_TEMPLATE_DIR)/main/cluster-template-fast-rollout-supervisor.yaml" diff --git a/test/e2e/config/vsphere.yaml b/test/e2e/config/vsphere.yaml index b8b88ee97f..5b6b8fc6d1 100644 --- a/test/e2e/config/vsphere.yaml +++ b/test/e2e/config/vsphere.yaml @@ -156,6 +156,7 @@ providers: - sourcePath: "../../../test/e2e/data/infrastructure-vsphere-govmomi/main/clusterclass-quick-start.yaml" - sourcePath: "../../../test/e2e/data/infrastructure-vsphere-govmomi/main/clusterclass-quick-start-runtimesdk.yaml" - sourcePath: "../../../test/e2e/data/infrastructure-vsphere-supervisor/main/cluster-template-topology-supervisor.yaml" + - sourcePath: "../../../test/e2e/data/infrastructure-vsphere-supervisor/main/cluster-template-topology-autoscaler-supervisor.yaml" - 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" diff --git a/test/e2e/data/autoscaler/autoscaler-to-management-workload.yaml b/test/e2e/data/autoscaler/autoscaler-to-management-workload.yaml new file mode 100644 index 0000000000..16f1e09c57 --- /dev/null +++ b/test/e2e/data/autoscaler/autoscaler-to-management-workload.yaml @@ -0,0 +1,89 @@ +# This yaml deploys the autoscaler on a workload cluster and configures it to match +# against the corresponding Cluster API cluster which is defined into the management cluster. +--- +# Specify kubeconfig for management cluster +apiVersion: v1 +kind: Secret +metadata: + name: kubeconfig-management-cluster + namespace: ${CLUSTER_NAMESPACE} +stringData: + kubeconfig: | + apiVersion: v1 + kind: Config + clusters: + - name: management-cluster + cluster: + certificate-authority-data: ${MANAGEMENT_CLUSTER_CA} + server: ${MANAGEMENT_CLUSTER_ADDRESS} + contexts: + - name: management-context + context: + cluster: management-cluster + namespace: ${CLUSTER_NAMESPACE} + user: cluster-autoscaler-sa + current-context: management-context + users: + - name: cluster-autoscaler-sa + user: + token: "${MANAGEMENT_CLUSTER_TOKEN}" +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: cluster-autoscaler + namespace: ${CLUSTER_NAMESPACE} + labels: + app: cluster-autoscaler +spec: + selector: + matchLabels: + app: cluster-autoscaler + replicas: 1 + template: + metadata: + labels: + app: cluster-autoscaler + spec: + containers: + - image: registry.k8s.io/autoscaling/cluster-autoscaler:${AUTOSCALER_VERSION} + name: cluster-autoscaler + command: + - /cluster-autoscaler + args: + - --cloud-provider=clusterapi + # Specify kubeconfig for management cluster + - --cloud-config=/management-cluster/kubeconfig + # Specify kubeconfig for workload cluster + - --kubeconfig=/workload-cluster/value + # Limit cluster autoscaler to only match against resources belonging to a single Cluster API cluster + - --node-group-auto-discovery=clusterapi:namespace=${CLUSTER_NAMESPACE},clusterName=${CLUSTER_NAME} + # Set a short scale down unneeded time, so we don't have to wait too long during e2e testing + - --scale-down-unneeded-time=1m + # Set a short scale down delay after add time, so we don't have to wait too long during e2e testing + - --scale-down-delay-after-add=1m + # Set a short scale down delay after delete time, so we don't have to wait too long during e2e testing + - --scale-down-delay-after-delete=1m + # Set a short scale down delay after failure time, so we don't have to wait too long during e2e testing + - --scale-down-delay-after-failure=1m + # Set a max nodes limit as safeguard so that the test does not scale up unbounded. + # Note: The E2E test should only go up to 4 (assuming it starts with a min node group size of 2). + # Using 6 for additional some buffer and to allow different starting min node group sizes. + - --max-nodes-total=6 + volumeMounts: + - name: kubeconfig-management-cluster + mountPath: /management-cluster + readOnly: true + - name: kubeconfig-workload-cluster + mountPath: /workload-cluster + readOnly: true + terminationGracePeriodSeconds: 10 + volumes: + - name: kubeconfig-management-cluster + secret: + secretName: kubeconfig-management-cluster + optional: false + - name: kubeconfig-workload-cluster + secret: + secretName: ${CLUSTER_NAME}-kubeconfig + optional: false diff --git a/test/e2e/data/infrastructure-vsphere-supervisor/main/topology-autoscaler/cluster-autoscaler.yaml b/test/e2e/data/infrastructure-vsphere-supervisor/main/topology-autoscaler/cluster-autoscaler.yaml new file mode 100644 index 0000000000..30ceeab096 --- /dev/null +++ b/test/e2e/data/infrastructure-vsphere-supervisor/main/topology-autoscaler/cluster-autoscaler.yaml @@ -0,0 +1,12 @@ +- op: replace + path: /spec/topology/workers/machineDeployments/0/metadata + value: + annotations: + cluster.x-k8s.io/cluster-api-autoscaler-node-group-max-size: "5" + cluster.x-k8s.io/cluster-api-autoscaler-node-group-min-size: "2" +- op: remove + path: /spec/topology/workers/machineDeployments/0/replicas + value: + annotations: + cluster.x-k8s.io/cluster-api-autoscaler-node-group-max-size: "5" + cluster.x-k8s.io/cluster-api-autoscaler-node-group-min-size: "2" diff --git a/test/e2e/data/infrastructure-vsphere-supervisor/main/topology-autoscaler/kustomization.yaml b/test/e2e/data/infrastructure-vsphere-supervisor/main/topology-autoscaler/kustomization.yaml new file mode 100644 index 0000000000..8efca71355 --- /dev/null +++ b/test/e2e/data/infrastructure-vsphere-supervisor/main/topology-autoscaler/kustomization.yaml @@ -0,0 +1,8 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: + - ../topology +patches: + - target: + kind: Cluster + path: ./cluster-autoscaler.yaml