From 4bcd183192c66a2a5e3b00460e16f915211c4ad5 Mon Sep 17 00:00:00 2001 From: Harshdeep Singh <38904804+super-harsh@users.noreply.github.com> Date: Wed, 7 Feb 2024 09:46:30 +1300 Subject: [PATCH 1/4] Add affinity and tolerations --- scripts/v2/generate-helm-manifest.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/scripts/v2/generate-helm-manifest.sh b/scripts/v2/generate-helm-manifest.sh index 1d02816a08c..dfd1556daee 100755 --- a/scripts/v2/generate-helm-manifest.sh +++ b/scripts/v2/generate-helm-manifest.sh @@ -49,6 +49,10 @@ sed -i "s@$LOCAL_REGISTRY_CONTROLLER_DOCKER_IMAGE@{{.Values.image.repository}}@g # Perl multiline replacements - using this because it's tricky to do these sorts of multiline replacements with sed perl -0777 -i -pe 's/(template:\n.*metadata:\n.*annotations:\n(\s*))/$1\{\{- if .Values.podAnnotations \}\}\n$2\{\{ toYaml .Values.podAnnotations \}\}\n$2\{\{- end \}\}\n$2/igs' "$GEN_FILES_DIR"/*_deployment_* # Add pod annotations +# Affinity and Toleration +sed -i '/ spec:/a\ {{- if .Values.affinity }}\n affinity:\n {{ toYaml .Values.affinity}}\n {{- end }}' "$GEN_FILES_DIR"/*_deployment_* +sed -i '/ spec:/a\ {{- if .Values.affinity }}\n tolerations:\n {{ toYaml .Values.tolerations}}\n {{- end }}' "$GEN_FILES_DIR"/*_deployment_* + # Metrics Configuration flow_control "metrics-addr" "metrics-addr" "{{- if .Values.metrics.enable}}" "$GEN_FILES_DIR"/*_deployment_* sed -i "1,/metrics-addr=.*/s/\(metrics-addr=\)\(.*\)/\1{{ tpl .Values.metrics.address . }}/g" "$GEN_FILES_DIR"/*_deployment_* From c89cb93aa5fda61558d63df837ec79880ede7251 Mon Sep 17 00:00:00 2001 From: Harshdeep Singh <38904804+super-harsh@users.noreply.github.com> Date: Thu, 8 Feb 2024 09:43:53 +1300 Subject: [PATCH 2/4] Add Affinity and Tolerations to ASOv2 helm chart --- scripts/v2/generate-helm-manifest.sh | 4 ++-- v2/charts/azure-service-operator/values.yaml | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/scripts/v2/generate-helm-manifest.sh b/scripts/v2/generate-helm-manifest.sh index dfd1556daee..7e604219468 100755 --- a/scripts/v2/generate-helm-manifest.sh +++ b/scripts/v2/generate-helm-manifest.sh @@ -50,8 +50,8 @@ sed -i "s@$LOCAL_REGISTRY_CONTROLLER_DOCKER_IMAGE@{{.Values.image.repository}}@g perl -0777 -i -pe 's/(template:\n.*metadata:\n.*annotations:\n(\s*))/$1\{\{- if .Values.podAnnotations \}\}\n$2\{\{ toYaml .Values.podAnnotations \}\}\n$2\{\{- end \}\}\n$2/igs' "$GEN_FILES_DIR"/*_deployment_* # Add pod annotations # Affinity and Toleration -sed -i '/ spec:/a\ {{- if .Values.affinity }}\n affinity:\n {{ toYaml .Values.affinity}}\n {{- end }}' "$GEN_FILES_DIR"/*_deployment_* -sed -i '/ spec:/a\ {{- if .Values.affinity }}\n tolerations:\n {{ toYaml .Values.tolerations}}\n {{- end }}' "$GEN_FILES_DIR"/*_deployment_* +sed -i '/ spec:/a\ {{- with .Values.affinity }}\n affinity:\n {{- toYaml . | nindent 8 }}\n {{- end }}' "$GEN_FILES_DIR"/*_deployment_* +sed -i '/ spec:/a\ {{- with .Values.tolerations }}\n tolerations:\n {{- toYaml . | nindent 8 }}\n {{- end }}' "$GEN_FILES_DIR"/*_deployment_* # Metrics Configuration flow_control "metrics-addr" "metrics-addr" "{{- if .Values.metrics.enable}}" "$GEN_FILES_DIR"/*_deployment_* diff --git a/v2/charts/azure-service-operator/values.yaml b/v2/charts/azure-service-operator/values.yaml index 28cf2add0ce..e748e2788bd 100644 --- a/v2/charts/azure-service-operator/values.yaml +++ b/v2/charts/azure-service-operator/values.yaml @@ -141,3 +141,15 @@ networkPolicies: mysqlCIDR: 0.0.0.0/0 # Destination CIDR for talking to PostgreSQL servers postgresqlCIDR: 0.0.0.0/0 + +# Tolerations are applied to pods. Tolerations allow the scheduler to schedule pods with matching taints. Tolerations allow scheduling but don't guarantee scheduling +# For more information, see https://kubernetes.io/docs/concepts/scheduling-eviction/taint-and-toleration. +tolerations: [] + +# Affinity and anti-affinity expands the types of constraints you can define. +# The affinity feature consists of two types of affinity: +# Node affinity functions like the nodeSelector field but is more expressive and allows you to specify soft rules. +# Inter-pod affinity/anti-affinity allows you to constrain Pods against labels on other Pods. +# For more information, see https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/#affinity-and-anti-affinity +affinity: {} + From dab349750344bbe9e448c157b48d74c05fa6860a Mon Sep 17 00:00:00 2001 From: Harshdeep Singh <38904804+super-harsh@users.noreply.github.com> Date: Thu, 8 Feb 2024 16:02:35 +1300 Subject: [PATCH 3/4] use perl instead of sed --- scripts/v2/generate-helm-manifest.sh | 5 +++-- v2/charts/azure-service-operator/values.yaml | 1 - 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/v2/generate-helm-manifest.sh b/scripts/v2/generate-helm-manifest.sh index 7e604219468..09237957b4d 100755 --- a/scripts/v2/generate-helm-manifest.sh +++ b/scripts/v2/generate-helm-manifest.sh @@ -50,10 +50,11 @@ sed -i "s@$LOCAL_REGISTRY_CONTROLLER_DOCKER_IMAGE@{{.Values.image.repository}}@g perl -0777 -i -pe 's/(template:\n.*metadata:\n.*annotations:\n(\s*))/$1\{\{- if .Values.podAnnotations \}\}\n$2\{\{ toYaml .Values.podAnnotations \}\}\n$2\{\{- end \}\}\n$2/igs' "$GEN_FILES_DIR"/*_deployment_* # Add pod annotations # Affinity and Toleration -sed -i '/ spec:/a\ {{- with .Values.affinity }}\n affinity:\n {{- toYaml . | nindent 8 }}\n {{- end }}' "$GEN_FILES_DIR"/*_deployment_* -sed -i '/ spec:/a\ {{- with .Values.tolerations }}\n tolerations:\n {{- toYaml . | nindent 8 }}\n {{- end }}' "$GEN_FILES_DIR"/*_deployment_* +perl -0777 -i -pe 's/(spec:\n.*template:\n.*spec:\n(\s*))/$1\{\{- with .Values.affinity \}\}\n$2affinity:\n$2\{\{- toYaml . | nindent 8 \}\}\n$2\{\{- end \}\}\n$2/igs' "$GEN_FILES_DIR"/*_deployment_* # Add pod annotations +perl -0777 -i -pe 's/(spec:\n.*template:\n.*spec:\n(\s*))/$1\{\{- with .Values.tolerations \}\}\n$2tolerations:\n$2\{\{- toYaml . | nindent 8 \}\}\n$2\{\{- end \}\}\n$2/igs' "$GEN_FILES_DIR"/*_deployment_* # Add pod annotations # Metrics Configuration + flow_control "metrics-addr" "metrics-addr" "{{- if .Values.metrics.enable}}" "$GEN_FILES_DIR"/*_deployment_* sed -i "1,/metrics-addr=.*/s/\(metrics-addr=\)\(.*\)/\1{{ tpl .Values.metrics.address . }}/g" "$GEN_FILES_DIR"/*_deployment_* sed -i 's/containerPort: 8080/containerPort: {{ .Values.metrics.port | default 8080 }}/g' "$GEN_FILES_DIR"/*_deployment_* diff --git a/v2/charts/azure-service-operator/values.yaml b/v2/charts/azure-service-operator/values.yaml index e748e2788bd..c09b2ee4ba0 100644 --- a/v2/charts/azure-service-operator/values.yaml +++ b/v2/charts/azure-service-operator/values.yaml @@ -152,4 +152,3 @@ tolerations: [] # Inter-pod affinity/anti-affinity allows you to constrain Pods against labels on other Pods. # For more information, see https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/#affinity-and-anti-affinity affinity: {} - From ad3280119085e1ac60214afc792fe47b015708f2 Mon Sep 17 00:00:00 2001 From: Harshdeep Singh <38904804+super-harsh@users.noreply.github.com> Date: Thu, 8 Feb 2024 16:03:13 +1300 Subject: [PATCH 4/4] Remove extra line --- scripts/v2/generate-helm-manifest.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/v2/generate-helm-manifest.sh b/scripts/v2/generate-helm-manifest.sh index 09237957b4d..32c423944d6 100755 --- a/scripts/v2/generate-helm-manifest.sh +++ b/scripts/v2/generate-helm-manifest.sh @@ -54,7 +54,6 @@ perl -0777 -i -pe 's/(spec:\n.*template:\n.*spec:\n(\s*))/$1\{\{- with .Values.a perl -0777 -i -pe 's/(spec:\n.*template:\n.*spec:\n(\s*))/$1\{\{- with .Values.tolerations \}\}\n$2tolerations:\n$2\{\{- toYaml . | nindent 8 \}\}\n$2\{\{- end \}\}\n$2/igs' "$GEN_FILES_DIR"/*_deployment_* # Add pod annotations # Metrics Configuration - flow_control "metrics-addr" "metrics-addr" "{{- if .Values.metrics.enable}}" "$GEN_FILES_DIR"/*_deployment_* sed -i "1,/metrics-addr=.*/s/\(metrics-addr=\)\(.*\)/\1{{ tpl .Values.metrics.address . }}/g" "$GEN_FILES_DIR"/*_deployment_* sed -i 's/containerPort: 8080/containerPort: {{ .Values.metrics.port | default 8080 }}/g' "$GEN_FILES_DIR"/*_deployment_*