diff --git a/template/CHART_NAME/templates/daemonset.yaml b/template/CHART_NAME/templates/daemonset.yaml index 9d6cf53d47..d05f54519a 100644 --- a/template/CHART_NAME/templates/daemonset.yaml +++ b/template/CHART_NAME/templates/daemonset.yaml @@ -119,8 +119,13 @@ spec: name: {{ include "common.tplvalues.render" (dict "value" .Values.%%MAIN_OBJECT_BLOCK%%.extraEnvVarsSecret "context" $) }} {{- end }} ports: - - containerPort: foo - protocol: bar + - name: http + containerPort: {{ .Values.%%MAIN_OBJECT_BLOCK%%.containerPorts.http }} + - name: https + containerPort: {{ .Values.%%MAIN_OBJECT_BLOCK%%.containerPorts.https }} + {{- if .Values.%%MAIN_OBJECT_BLOCK%%.extraContainerPorts }} + {{- include "common.tplvalues.render" (dict "value" .Values.%%MAIN_OBJECT_BLOCK%%.extraContainerPorts "context" $) | nindent 12 }} + {{- end }} {{- if .Values.%%MAIN_OBJECT_BLOCK%%.resources }} resources: {{- toYaml .Values.%%MAIN_OBJECT_BLOCK%%.resources | nindent 12 }} {{- else if ne .Values.%%MAIN_OBJECT_BLOCK%%.resourcesPreset "none" }} diff --git a/template/CHART_NAME/templates/deployment.yaml b/template/CHART_NAME/templates/deployment.yaml index 939a4ea1e4..9fb6400ad1 100644 --- a/template/CHART_NAME/templates/deployment.yaml +++ b/template/CHART_NAME/templates/deployment.yaml @@ -15,7 +15,7 @@ metadata: annotations: {{- include "common.tplvalues.render" ( dict "value" $annotations "context" $ ) | nindent 4 }} {{- end }} spec: - {{- if not .Values.%%MAIN_OBJECT_BLOCK%%.autoscaling.enabled }} + {{- if not .Values.%%MAIN_OBJECT_BLOCK%%.autoscaling.hpa.enabled }} replicas: {{ .Values.%%MAIN_OBJECT_BLOCK%%.replicaCount }} {{- end }} {{- if .Values.%%MAIN_OBJECT_BLOCK%%.updateStrategy }} @@ -136,6 +136,9 @@ spec: containerPort: {{ .Values.%%MAIN_OBJECT_BLOCK%%.containerPorts.http }} - name: https containerPort: {{ .Values.%%MAIN_OBJECT_BLOCK%%.containerPorts.https }} + {{- if .Values.%%MAIN_OBJECT_BLOCK%%.extraContainerPorts }} + {{- include "common.tplvalues.render" (dict "value" .Values.%%MAIN_OBJECT_BLOCK%%.extraContainerPorts "context" $) | nindent 12 }} + {{- end }} {{- if not .Values.diagnosticMode.enabled }} {{- if .Values.%%MAIN_OBJECT_BLOCK%%.customLivenessProbe }} livenessProbe: {{- include "common.tplvalues.render" (dict "value" .Values.%%MAIN_OBJECT_BLOCK%%.customLivenessProbe "context" $) | nindent 12 }} diff --git a/template/CHART_NAME/templates/hpa.yaml b/template/CHART_NAME/templates/hpa.yaml index 19ece7c33a..9b50f0033a 100644 --- a/template/CHART_NAME/templates/hpa.yaml +++ b/template/CHART_NAME/templates/hpa.yaml @@ -3,7 +3,7 @@ Copyright Broadcom, Inc. All Rights Reserved. SPDX-License-Identifier: APACHE-2.0 */}} -{{- if .Values.%%MAIN_OBJECT_BLOCK%%.autoscaling.enabled }} +{{- if .Values.%%MAIN_OBJECT_BLOCK%%.autoscaling.hpa.enabled }} apiVersion: {{ include "common.capabilities.hpa.apiVersion" . }} kind: HorizontalPodAutoscaler metadata: @@ -19,31 +19,31 @@ spec: apiVersion: {{ include "common.capabilities.deployment.apiVersion" . }} kind: Deployment name: {{ include "common.names.fullname" . }} - minReplicas: {{ .Values.%%MAIN_OBJECT_BLOCK%%.autoscaling.minReplicas }} - maxReplicas: {{ .Values.%%MAIN_OBJECT_BLOCK%%.autoscaling.maxReplicas }} + minReplicas: {{ .Values.%%MAIN_OBJECT_BLOCK%%.autoscaling.hpa.minReplicas }} + maxReplicas: {{ .Values.%%MAIN_OBJECT_BLOCK%%.autoscaling.hpa.maxReplicas }} metrics: - {{- if .Values.%%MAIN_OBJECT_BLOCK%%.autoscaling.targetMemory }} + {{- if .Values.%%MAIN_OBJECT_BLOCK%%.autoscaling.hpa.targetMemory }} - type: Resource resource: name: memory {{- if semverCompare "<1.23-0" (include "common.capabilities.kubeVersion" .) }} - targetAverageUtilization: {{ .Values.%%MAIN_OBJECT_BLOCK%%.autoscaling.targetMemory }} + targetAverageUtilization: {{ .Values.%%MAIN_OBJECT_BLOCK%%.autoscaling.hpa.targetMemory }} {{- else }} target: type: Utilization - averageUtilization: {{ .Values.worker.autoscaling.targetMemory }} + averageUtilization: {{ .Values.worker.autoscaling.hpa.targetMemory }} {{- end }} {{- end }} - {{- if .Values.%%MAIN_OBJECT_BLOCK%%.autoscaling.targetCPU }} + {{- if .Values.%%MAIN_OBJECT_BLOCK%%.autoscaling.hpa.targetCPU }} - type: Resource resource: name: cpu {{- if semverCompare "<1.23-0" (include "common.capabilities.kubeVersion" .) }} - targetAverageUtilization: {{ .Values.%%MAIN_OBJECT_BLOCK%%.autoscaling.targetCPU }} + targetAverageUtilization: {{ .Values.%%MAIN_OBJECT_BLOCK%%.autoscaling.hpa.targetCPU }} {{- else }} target: type: Utilization - averageUtilization: {{ .Values.worker.autoscaling.targetCPU }} + averageUtilization: {{ .Values.worker.autoscaling.hpa.targetCPU }} {{- end }} {{- end }} {{- end }} diff --git a/template/CHART_NAME/templates/networkpolicy.yaml b/template/CHART_NAME/templates/networkpolicy.yaml index 09ef6f314e..95398f7abf 100644 --- a/template/CHART_NAME/templates/networkpolicy.yaml +++ b/template/CHART_NAME/templates/networkpolicy.yaml @@ -40,6 +40,9 @@ spec: - ports: - port: {{ .Values.%%MAIN_OBJECT_BLOCK%%.containerPorts.http }} - port: {{ .Values.%%MAIN_OBJECT_BLOCK%%.containerPorts.https }} + {{- range .Values.%%MAIN_OBJECT_BLOCK%%.extraContainerPorts }} + - port: {{ .containerPort }} + {{- end }} {{- if not .Values.networkPolicy.allowExternal }} from: - podSelector: diff --git a/template/CHART_NAME/templates/statefulset.yaml b/template/CHART_NAME/templates/statefulset.yaml index 9a825a742d..f9837458de 100644 --- a/template/CHART_NAME/templates/statefulset.yaml +++ b/template/CHART_NAME/templates/statefulset.yaml @@ -15,8 +15,8 @@ metadata: annotations: {{- include "common.tplvalues.render" ( dict "value" $annotations "context" $ ) | nindent 4 }} {{- end }} spec: - {{- if not .Values.autoscaling.enabled }} - replicas: {{ .Values.replicaCount }} + {{- if not .Values.%%MAIN_OBJECT_BLOCK%%.autoscaling.hpa.enabled }} + replicas: {{ .Values.%%MAIN_OBJECT_BLOCK%%.replicaCount }} {{- end }} podManagementPolicy: {{ .Values.podManagementPolicy | quote }} {{- $podLabels := include "common.tplvalues.merge" (dict "values" (list .Values.%%MAIN_OBJECT_BLOCK%%.podLabels .Values.commonLabels) "context" .) }} @@ -139,6 +139,9 @@ spec: containerPort: {{ .Values.%%MAIN_OBJECT_BLOCK%%.containerPorts.http }} - name: https containerPort: {{ .Values.%%MAIN_OBJECT_BLOCK%%.containerPorts.https }} + {{- if .Values.%%MAIN_OBJECT_BLOCK%%.extraContainerPorts }} + {{- include "common.tplvalues.render" (dict "value" .Values.%%MAIN_OBJECT_BLOCK%%.extraContainerPorts "context" $) | nindent 12 }} + {{- end }} {{- if not .Values.diagnosticMode.enabled }} {{- if .Values.%%MAIN_OBJECT_BLOCK%%.customLivenessProbe }} livenessProbe: {{- include "common.tplvalues.render" (dict "value" .Values.%%MAIN_OBJECT_BLOCK%%.customLivenessProbe "context" $) | nindent 12 }} diff --git a/template/CHART_NAME/templates/vpa.yaml b/template/CHART_NAME/templates/vpa.yaml new file mode 100644 index 0000000000..cd9371a8d8 --- /dev/null +++ b/template/CHART_NAME/templates/vpa.yaml @@ -0,0 +1,44 @@ +{{- /* +Copyright Broadcom, Inc. All Rights Reserved. +SPDX-License-Identifier: APACHE-2.0 +*/}} + +{{- if and (.Capabilities.APIVersions.Has "autoscaling.k8s.io/v1/VerticalPodAutoscaler") .Values.%%MAIN_OBJECT_BLOCK%%.autoscaling.vpa.enabled }} +apiVersion: autoscaling.k8s.io/v1 +kind: VerticalPodAutoscaler +metadata: + name: {{ include "common.names.fullname" . }} + namespace: {{ include "common.names.namespace" . | quote }} + labels: {{- include "common.labels.standard" ( dict "customLabels" .Values.commonLabels "context" $ ) | nindent 4 }} + app.kubernetes.io/component: %%COMPONENT_NAME%% + {{- if or .Values.%%MAIN_OBJECT_BLOCK%%.autoscaling.vpa.annotations .Values.commonAnnotations }} + {{- $annotations := include "common.tplvalues.merge" ( dict "values" ( list .Values.%%MAIN_OBJECT_BLOCK%%.autoscaling.vpa.annotations .Values.commonAnnotations ) "context" . ) }} + annotations: {{- include "common.tplvalues.render" ( dict "value" $annotations "context" $) | nindent 4 }} + {{- end }} +spec: + resourcePolicy: + containerPolicies: + - containerName: %%MAIN_OBJECT_BLOCK%% + {{- with .Values.%%MAIN_OBJECT_BLOCK%%.autoscaling.vpa.controlledResources }} + controlledResources: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.%%MAIN_OBJECT_BLOCK%%.autoscaling.vpa.maxAllowed }} + maxAllowed: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.%%MAIN_OBJECT_BLOCK%%.autoscaling.vpa.minAllowed }} + minAllowed: + {{- toYaml . | nindent 8 }} + {{- end }} + targetRef: + apiVersion: {{ include "common.capabilities.deployment.apiVersion" . }} + kind: Deployment + name: {{ include "common.names.fullname" . }} + {{- if .Values.%%MAIN_OBJECT_BLOCK%%.autoscaling.vpa.updatePolicy }} + updatePolicy: + {{- with .Values.%%MAIN_OBJECT_BLOCK%%.autoscaling.vpa.updatePolicy.updateMode }} + updateMode: {{ . }} + {{- end }} + {{- end }} +{{- end }} diff --git a/template/CHART_NAME/values.yaml b/template/CHART_NAME/values.yaml index de1cc06299..58e543964a 100644 --- a/template/CHART_NAME/values.yaml +++ b/template/CHART_NAME/values.yaml @@ -112,6 +112,13 @@ diagnosticMode: containerPorts: http: 80 https: 443 + ## @param %%MAIN_OBJECT_BLOCK%%.extraContainerPorts Optionally specify extra list of additional ports for %%MAIN_CONTAINER_NAME%% containers + ## e.g: + ## extraContainerPorts: + ## - name: myservice + ## containerPort: 9090 + ## + extraContainerPorts: [] ## Configure extra options for %%MAIN_CONTAINER_NAME%% containers' liveness and readiness probes ## ref: https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-probes/#configure-probes ## @param %%MAIN_OBJECT_BLOCK%%.livenessProbe.enabled Enable livenessProbe on %%MAIN_CONTAINER_NAME%% containers @@ -386,19 +393,39 @@ diagnosticMode: minAvailable: "" maxUnavailable: "" ## Autoscaling configuration - ## ref: https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/ - ## @param %%MAIN_OBJECT_BLOCK%%.autoscaling.enabled Enable autoscaling for %%MAIN_OBJECT_BLOCK%% - ## @param %%MAIN_OBJECT_BLOCK%%.autoscaling.minReplicas Minimum number of %%MAIN_OBJECT_BLOCK%% replicas - ## @param %%MAIN_OBJECT_BLOCK%%.autoscaling.maxReplicas Maximum number of %%MAIN_OBJECT_BLOCK%% replicas - ## @param %%MAIN_OBJECT_BLOCK%%.autoscaling.targetCPU Target CPU utilization percentage - ## @param %%MAIN_OBJECT_BLOCK%%.autoscaling.targetMemory Target Memory utilization percentage + ## ref: https://kubernetes.io/docs/concepts/workloads/autoscaling/ ## autoscaling: - enabled: false - minReplicas: "" - maxReplicas: "" - targetCPU: "" - targetMemory: "" + ## @param %%MAIN_OBJECT_BLOCK%%.autoscaling.vpa.enabled Enable VPA for %%MAIN_CONTAINER_NAME%% pods + ## @param %%MAIN_OBJECT_BLOCK%%.autoscaling.vpa.annotations Annotations for VPA resource + ## @param %%MAIN_OBJECT_BLOCK%%.autoscaling.vpa.controlledResources VPA List of resources that the vertical pod autoscaler can control. Defaults to cpu and memory + ## @param %%MAIN_OBJECT_BLOCK%%.autoscaling.vpa.maxAllowed VPA Max allowed resources for the pod + ## @param %%MAIN_OBJECT_BLOCK%%.autoscaling.vpa.minAllowed VPA Min allowed resources for the pod + ## + vpa: + enabled: false + annotations: {} + controlledResources: [] + maxAllowed: {} + minAllowed: {} + ## @param %%MAIN_OBJECT_BLOCK%%.autoscaling.vpa.updatePolicy.updateMode Autoscaling update policy + ## Specifies whether recommended updates are applied when a Pod is started and whether recommended updates are applied during the life of a Pod + ## Possible values are "Off", "Initial", "Recreate", and "Auto". + ## + updatePolicy: + updateMode: Auto + ## @param %%MAIN_OBJECT_BLOCK%%.autoscaling.hpa.enabled Enable HPA for %%MAIN_CONTAINER_NAME%% pods + ## @param %%MAIN_OBJECT_BLOCK%%.autoscaling.hpa.minReplicas Minimum number of replicas + ## @param %%MAIN_OBJECT_BLOCK%%.autoscaling.hpa.maxReplicas Maximum number of replicas + ## @param %%MAIN_OBJECT_BLOCK%%.autoscaling.hpa.targetCPU Target CPU utilization percentage + ## @param %%MAIN_OBJECT_BLOCK%%.autoscaling.hpa.targetMemory Target Memory utilization percentage + ## + hpa: + enabled: false + minReplicas: "" + maxReplicas: "" + targetCPU: "" + targetMemory: "" ## %%SECONDARY_CONTAINER/POD_DESCRIPTION%% ##