From a2cf33b7ae53fbd2db4afcb14aa05e0b4c8ce8de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20BILQU=C3=89?= Date: Tue, 28 May 2024 15:30:20 +0000 Subject: [PATCH 1/3] Allow to scale up the operator pods by using the Helm Chart --- .helm/starter/README.md | 5 +++++ Makefile | 5 ++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/.helm/starter/README.md b/.helm/starter/README.md index 8fca8b498..31e48bd7c 100644 --- a/.helm/starter/README.md +++ b/.helm/starter/README.md @@ -235,6 +235,11 @@ AWX: |---|---|---| | `extraDeploy` | array of additional resources to be deployed (supports YAML or literal "\|") | - | +### Operator +| Value | Description | Default | +|---|---|---| +| `Operator.replicas` | Number of controller-manager instance replicas | `1` | + ### customSecrets | Value | Description | Default | |---|---|---| diff --git a/Makefile b/Makefile index c2ee3b5ba..bedc82aea 100644 --- a/Makefile +++ b/Makefile @@ -375,9 +375,12 @@ helm-chart-generate: kustomize helm kubectl-slice yq charts for file in $${cluster_scoped_files}; do\ $(YQ) -i '.metadata.name += "-{{ .Release.Name }}"' $${file};\ done - # Correct the reference for the clusterrolebinding $(YQ) -i '.roleRef.name += "-{{ .Release.Name }}"' 'charts/$(CHART_NAME)/raw-files/clusterrolebinding-awx-operator-proxy-rolebinding.yaml' + # Correct .spec.replicas for the controller-manager deployment + for file in charts/$(CHART_NAME)/raw-files/deployment-*-controller-manager.yaml; do\ + $(YQ) -i '.spec.replicas = "{{ (.Values.Operator).replicas | default 1 }}"' $${file};\ + done # move all custom resource definitions to crds folder mkdir charts/$(CHART_NAME)/crds mv charts/$(CHART_NAME)/raw-files/customresourcedefinition*.yaml charts/$(CHART_NAME)/crds/. From c35ff39ef42e26f4d63a62ed7ce99397eca459cc Mon Sep 17 00:00:00 2001 From: David Hageman Date: Mon, 3 Jun 2024 14:59:48 -0500 Subject: [PATCH 2/3] Add support for horizontal pod autoscaling (#1676) --- config/crd/bases/awx.ansible.com_awxs.yaml | 8 ++++++ .../horizontal-pod-autoscaler.md | 27 +++++++++++++++++++ ...ing-the-web-and-task-pods-independently.md | 11 +++++--- .../templates/deployments/task.yaml.j2 | 4 +-- .../templates/deployments/web.yaml.j2 | 4 +-- 5 files changed, 47 insertions(+), 7 deletions(-) create mode 100644 docs/user-guide/advanced-configuration/horizontal-pod-autoscaler.md diff --git a/config/crd/bases/awx.ansible.com_awxs.yaml b/config/crd/bases/awx.ansible.com_awxs.yaml index 5b0a5c0f5..b69d164e2 100644 --- a/config/crd/bases/awx.ansible.com_awxs.yaml +++ b/config/crd/bases/awx.ansible.com_awxs.yaml @@ -1574,10 +1574,18 @@ spec: description: Number of web instance replicas type: integer format: int32 + web_manage_replicas: + description: Enables operator control of replicas count for the web deployment when set to 'true' + type: boolean + default: true task_replicas: description: Number of task instance replicas type: integer format: int32 + task_manage_replicas: + description: Enables operator control of replicas count for the task deployment when set to 'true' + type: boolean + default: true web_liveness_initial_delay: description: Initial delay before starting liveness checks on web pod type: integer diff --git a/docs/user-guide/advanced-configuration/horizontal-pod-autoscaler.md b/docs/user-guide/advanced-configuration/horizontal-pod-autoscaler.md new file mode 100644 index 000000000..e44527e8b --- /dev/null +++ b/docs/user-guide/advanced-configuration/horizontal-pod-autoscaler.md @@ -0,0 +1,27 @@ +### Horizontal Pod Autoscaler (HPA) + +Horizontal Pod Autoscaler allows Kubernetes to scale the number of replicas of +deployments in response to configured metrics. + +This feature conflicts with the operators ability to manage the number of static +replicas to create for each deployment. + +The use of the settings below will tell the operator to not manage the replicas +field on the identified deployments even if a replicas count has been set for those +properties in the operator resource. + +| Name | Description | Default | +| -----------------------| ----------------------------------------- | ------- | +| web_manage_replicas | Indicates operator should control the | true | +| | replicas count for the web deployment. | | +| | | | +| task_manage_replicas | Indicates operator should control the | true | +| | replicas count for the task deployment. | | + +#### Recommended Settings for HPA + +Please see the Kubernetes documentation on how to configure the horizontal pod +autoscaler. + +The values for optimal HPA are cluster and need specific so general guidelines +are not available at this time. diff --git a/docs/user-guide/advanced-configuration/scaling-the-web-and-task-pods-independently.md b/docs/user-guide/advanced-configuration/scaling-the-web-and-task-pods-independently.md index 1dc9c3440..9f1ed01d9 100644 --- a/docs/user-guide/advanced-configuration/scaling-the-web-and-task-pods-independently.md +++ b/docs/user-guide/advanced-configuration/scaling-the-web-and-task-pods-independently.md @@ -1,8 +1,13 @@ -#### Scaling the Web and Task Pods independently +#### Scaling the Web and Task Pods independently You can scale replicas up or down for each deployment by using the `web_replicas` or `task_replicas` respectively. You can scale all pods across both deployments by using `replicas` as well. The logic behind these CRD keys acts as such: -- If you specify the `replicas` field, the key passed will scale both the `web` and `task` replicas to the same number. +- If you specify the `replicas` field, the key passed will scale both the `web` and `task` replicas to the same number. - If `web_replicas` or `task_replicas` is ever passed, it will override the existing `replicas` field on the specific deployment with the new key value. -These new replicas can be constrained in a similar manner to previous single deployments by appending the particular deployment name in front of the constraint used. More about those new constraints can be found in the [Assigning AWX pods to specific nodes](./assigning-awx-pods-to-specific-nodes.md) page. +These new replicas can be constrained in a similar manner to previous single deployments by appending the particular deployment name in front of the constraint used. More about those new constraints can be found in the [Assigning AWX pods to specific nodes](./assigning-awx-pods-to-specific-nodes.md) page. + +##### Horizontal Pod Autoscaling + +The operator is capable of working with Kubernete's HPA capabilities. See [Horizontal Pod Autoscaler](./horizontal-pod-autoscaler.md) +documentation for more information. diff --git a/roles/installer/templates/deployments/task.yaml.j2 b/roles/installer/templates/deployments/task.yaml.j2 index db022b5f0..8903405dd 100644 --- a/roles/installer/templates/deployments/task.yaml.j2 +++ b/roles/installer/templates/deployments/task.yaml.j2 @@ -8,9 +8,9 @@ metadata: {{ lookup("template", "../common/templates/labels/common.yaml.j2") | indent(width=4) | trim }} {{ lookup("template", "../common/templates/labels/version.yaml.j2") | indent(width=4) | trim }} spec: -{% if task_replicas != '' %} +{% if task_replicas != '' and task_manage_replicas is true %} replicas: {{ task_replicas }} -{% elif replicas != '' %} +{% elif replicas != '' and task_manage_replicas is true %} replicas: {{ replicas }} {% endif %} selector: diff --git a/roles/installer/templates/deployments/web.yaml.j2 b/roles/installer/templates/deployments/web.yaml.j2 index 115bbcbd6..202c7b7dd 100644 --- a/roles/installer/templates/deployments/web.yaml.j2 +++ b/roles/installer/templates/deployments/web.yaml.j2 @@ -9,9 +9,9 @@ metadata: {{ lookup("template", "../common/templates/labels/common.yaml.j2") | indent(width=4) | trim }} {{ lookup("template", "../common/templates/labels/version.yaml.j2") | indent(width=4) | trim }} spec: -{% if web_replicas != '' %} +{% if web_replicas != '' and web_manage_replicas is true %} replicas: {{ web_replicas }} -{% elif replicas != '' %} +{% elif replicas != '' and web_manage_replicas is true %} replicas: {{ replicas }} {% endif %} selector: From 389eafe17923d0c021f54dde5d83a0e8bd4b8b9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20BILQU=C3=89?= Date: Tue, 4 Jun 2024 16:26:18 +0000 Subject: [PATCH 3/3] fix: spec.replicas --- Makefile | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index bedc82aea..a055b7fce 100644 --- a/Makefile +++ b/Makefile @@ -370,6 +370,10 @@ helm-chart-generate: kustomize helm kubectl-slice yq charts for file in charts/$(CHART_NAME)/raw-files/*rolebinding*; do\ $(YQ) -i '.subjects[0].namespace = "{{ .Release.Namespace }}"' $${file};\ done + # Add .spec.replicas for the controller-manager deployment + for file in charts/$(CHART_NAME)/raw-files/deployment-*-controller-manager.yaml; do\ + $(YQ) -i '.spec.replicas = "{{ (.Values.Operator).replicas | default 1 }}"' $${file};\ + done # Correct .metadata.name for cluster scoped resources cluster_scoped_files="charts/$(CHART_NAME)/raw-files/clusterrolebinding-awx-operator-proxy-rolebinding.yaml charts/$(CHART_NAME)/raw-files/clusterrole-awx-operator-metrics-reader.yaml charts/$(CHART_NAME)/raw-files/clusterrole-awx-operator-proxy-role.yaml";\ for file in $${cluster_scoped_files}; do\ @@ -377,9 +381,9 @@ helm-chart-generate: kustomize helm kubectl-slice yq charts done # Correct the reference for the clusterrolebinding $(YQ) -i '.roleRef.name += "-{{ .Release.Name }}"' 'charts/$(CHART_NAME)/raw-files/clusterrolebinding-awx-operator-proxy-rolebinding.yaml' - # Correct .spec.replicas for the controller-manager deployment + # Correct .spec.replicas type for the controller-manager deployment for file in charts/$(CHART_NAME)/raw-files/deployment-*-controller-manager.yaml; do\ - $(YQ) -i '.spec.replicas = "{{ (.Values.Operator).replicas | default 1 }}"' $${file};\ + $(SED_I) "s/'{{ (.Values.Operator).replicas | default 1 }}'/{{ (.Values.Operator).replicas | default 1 }}/g" $${file};\ done # move all custom resource definitions to crds folder mkdir charts/$(CHART_NAME)/crds