diff --git a/CHANGELOG.md b/CHANGELOG.md index ca99daf8..71d4ce32 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,9 +3,26 @@ All notable changes to this project will be documented here. -### v2.1.14 +### v2.1.19 - Fix: Reverts [PR-240](https://github.com/stakater/application/pull/240), This can already be configured via `paths` [PR-247](https://github.com/stakater/application/pull/247) +### v2.1.18 +- feat: Add vertical pod autoscaler template [PR-249](https://github.com/stakater/application/pull/249) + +### v2.1.17 +- feat: allow overriding revisionHistoryLimit [PR-257](https://github.com/stakater/application/pull/257) + + > Caution: This PR changes the default value for `revisionHistoryLimit` from 10 to 2. + +### v2.1.16 +- fix: optional service account [PR-213](https://github.com/stakater/application/pull/213) + +### v2.1.15 +- fix: allow setting arbitrary resource constraints [PR-255](https://github.com/stakater/application/pull/255) + +### v2.1.14 +- feat: allow overriding clusterIP [PR-258](https://github.com/stakater/application/pull/258) + ### v2.1.13 - Fix: make deployment.image.tag and job.image.tag optional [PR-234](https://github.com/stakater/application/pull/234) diff --git a/README.md b/README.md index 333aaf39..ba28c0db 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,7 @@ To uninstall the chart: | deployment.env | Environment variables to be passed to the app container | `{}` | | deployment.volumes | Volumes to be added to the pod | `{}` | | deployment.volumeMounts | Mount path for Volumes | `{}` | +| deployment.revisionHistoryLimit | The number of old history to retain to allow rollback | `2` | | deployment.command | Command for primary container of deployment | `[]` | | deployment.args | Arg for primary container of deployment | `[]` | | deployment.tolerations | Taint tolerations for nodes | `[]` | @@ -204,6 +205,7 @@ Periodic probe of container liveness. Container will be restarted if the probe f | service.annotations | Annotations for service | `{}` | | service.ports | Ports for applications service | - port: 8080
  name: http
  protocol: TCP
  targetPort: 8080 | | service.type | Type of service | `ClusterIP` | +| service.clusterIP | Fixed IP for a ClusterIP service. Set to `None` for an headless service. | `null` | @@ -303,6 +305,16 @@ Stakater [Forecastle](https://github.com/stakater/Forecastle) parameters | autoscaling.maxReplicas | Sets maximum replica count when autoscaling is enabled | `10` | | autoscaling.metrics | Configuration for hpa metrics, set when autoscaling is enabled | `{}` | +### VPA - Vertical Pod Autoscaler Parameters + +| Name | Description | Value | +| ------------------------ | -------------------------------------------------------------------------------------------- | --------------- | +| vpa.enabled | Enable vertical pod autoscaler | `false` | +| vpa.additionalLabels | Labels for vertical pod autoscaler | `{}` | +| vpa.annotations | Annotations for vertical pod autoscaler | `{}` | +| vpa.containerPolicies | container policies for individual containers. | `[]` | + + ### EndpointMonitor Paramaters Stakater [IngressMonitorController](https://github.com/stakater/IngressMonitorController) EndpointMonitor parameters diff --git a/Tiltfile b/Tiltfile index d0825e0a..b85ffcd1 100644 --- a/Tiltfile +++ b/Tiltfile @@ -14,6 +14,12 @@ imc_namespace = "stakater-ingress-monitor-controller" namespace_create(imc_namespace) helm_resource('imc', 'oci://ghcr.io/stakater/charts/ingress-monitor-controller', namespace=imc_namespace,flags=['--set','developmentMode=true']) +# Install IMC Config +local_resource( + 'imc-config', + cmd='helm upgrade --install ingress-monitor-controller-config -n {} oci://ghcr.io/stakater/charts/ingress-monitor-controller-config --set developmentMode=true'.format(imc_namespace) + ) + # Install Forecastle forecastle_namespace = "stakater-forecastle" namespace_create(forecastle_namespace) @@ -40,5 +46,21 @@ local_resource( cmd='helm install grafana-operator -n grafana-operator oci://ghcr.io/stakater/charts/grafana-operator --version=0.0.1 --set operator.installPlanApproval=Automatic' ) +# Install openshift-vertical-pod-autoscaler +vpa_namespace = "openshift-vertical-pod-autoscaler" +namespace_create(vpa_namespace) +local_resource( + 'openshift-vertical-pod-autoscaler', + cmd='helm install openshift-vertical-pod-autoscaler -n openshift-vertical-pod-autoscaler oci://ghcr.io/stakater/charts/openshift-vertical-pod-autoscaler' + ) + +# Wait until VPA CRD becomes available +local_resource( + 'wait-for-crds', + cmd='timeout 300s bash -c "until kubectl wait --for condition=Established crd/verticalpodautoscalers.autoscaling.k8s.io; do sleep 10; done"', + resource_deps=[ + 'openshift-vertical-pod-autoscaler' + ]) + # Install cert-manager # it exists already diff --git a/Tiltfile-delete b/Tiltfile-delete index f2e3fd32..e928dcc4 100644 --- a/Tiltfile-delete +++ b/Tiltfile-delete @@ -8,6 +8,10 @@ def delete_external_secrets_operator(): print('Deleting external-secrets operator') local('helm uninstall external-secrets-operator -n external-secrets-operator') +def delete_openshift_vertical_pod_autoscaler(): + print('Uninstalling openshift-vertical-pod-autoscaler') + local('helm uninstall openshift-vertical-pod-autoscaler -n openshift-vertical-pod-autoscaler') + def delete_imc_crds(): print('Deleting imc crds') local('oc get crds -o name | grep \'endpointmonitor\\.stakater\\.com\' | xargs -r -n 1 oc delete') @@ -34,6 +38,7 @@ def delete_grafana_crds(): delete_grafana_operator() delete_external_secrets_operator() +delete_openshift_vertical_pod_autoscaler() delete_imc_crds() delete_forecastle_crds() delete_ss_crds() diff --git a/application/Chart.yaml b/application/Chart.yaml index 6d7d34e0..e2d6c2da 100644 --- a/application/Chart.yaml +++ b/application/Chart.yaml @@ -6,7 +6,7 @@ type: application # Helm chart Version -version: 2.1.13 +version: 2.1.17 keywords: diff --git a/application/templates/deployment.yaml b/application/templates/deployment.yaml index bbe14c63..8e03b7dc 100644 --- a/application/templates/deployment.yaml +++ b/application/templates/deployment.yaml @@ -1,4 +1,4 @@ -{{- if (.Values.deployment).enabled }} +{{- if .Values.deployment.enabled }} apiVersion: apps/v1 kind: Deployment metadata: @@ -28,6 +28,9 @@ spec: {{- if .Values.deployment.strategy }} strategy: {{ toYaml .Values.deployment.strategy | indent 4 }} + {{- end }} + {{- if not (kindIs "invalid" .Values.deployment.revisionHistoryLimit) }} + revisionHistoryLimit: {{ .Values.deployment.revisionHistoryLimit }} {{- end }} template: metadata: @@ -246,13 +249,10 @@ spec: {{- end }} {{- end }} {{- end }} + {{- with .Values.deployment.resources }} resources: - limits: - memory: {{ .Values.deployment.resources.limits.memory }} - cpu: {{ .Values.deployment.resources.limits.cpu }} - requests: - memory: {{ .Values.deployment.resources.requests.memory }} - cpu: {{ .Values.deployment.resources.requests.cpu }} + {{- toYaml . | nindent 10 }} + {{- end }} {{- if .Values.deployment.containerSecurityContext }} securityContext: {{ toYaml .Values.deployment.containerSecurityContext | indent 10 }} @@ -291,9 +291,11 @@ spec: {{- end }} {{- end }} {{- end }} + {{- if .Values.rbac.serviceAccount.enabled }} {{- if .Values.rbac.serviceAccount.name }} serviceAccountName: {{ .Values.rbac.serviceAccount.name }} - {{- else }} - serviceAccountName: {{ template "application.name" . }} + {{- else }} + serviceAccountName: {{ template "application.name" $ }} + {{- end }} {{- end }} {{- end }} diff --git a/application/templates/service.yaml b/application/templates/service.yaml index 9dcd202c..5a7c17d1 100644 --- a/application/templates/service.yaml +++ b/application/templates/service.yaml @@ -16,6 +16,9 @@ metadata: spec: {{- if .Values.service.type }} type: "{{ .Values.service.type }}" +{{- end }} +{{- with .Values.service.clusterIP }} + clusterIP: {{ . }} {{- end }} selector: {{ include "application.selectorLabels" . | indent 4 }} @@ -35,4 +38,4 @@ spec: {{- else }} {{ toYaml .Values.service.ports | indent 4 }} {{- end }} -{{- end }} \ No newline at end of file +{{- end }} diff --git a/application/templates/vpa.yaml b/application/templates/vpa.yaml new file mode 100644 index 00000000..36fc32f4 --- /dev/null +++ b/application/templates/vpa.yaml @@ -0,0 +1,27 @@ +{{- if .Values.vpa.enabled -}} +{{- if not (.Capabilities.APIVersions.Has "autoscaling.k8s.io/v1/VerticalPodAutoscaler") }} + {{- fail "There is no VerticalPodAutoscaler resource definition in the target cluster!" }} +{{- end }} +apiVersion: "autoscaling.k8s.io/v1" +kind: VerticalPodAutoscaler +metadata: + name: {{ template "application.name" . }} + namespace: {{ include "application.namespace" . }} + labels: + {{- include "application.labels" . | nindent 4 }} + {{- with .Values.vpa.additionalLabels }} + {{- toYaml . | nindent 4 }} + {{- end }} + {{- if .Values.vpa.annotations }} + annotations: + {{- toYaml .Values.vpa.annotations | nindent 4 }} + {{- end }} +spec: + targetRef: + apiVersion: apps/v1 + kind: Deployment + name: {{ template "application.name" . }} + resourcePolicy: + containerPolicies: + {{- toYaml .Values.vpa.containerPolicies | nindent 6 }} +{{- end }} diff --git a/application/tests/deployment_test.yaml b/application/tests/deployment_test.yaml index c98cae84..07a22287 100644 --- a/application/tests/deployment_test.yaml +++ b/application/tests/deployment_test.yaml @@ -75,3 +75,29 @@ tests: - equal: path: spec.template.spec.containers[0].image value: example-image:example-tag@sha256:example-digest + + - it: yields empty service account name when disabled + set: + rbac.serviceAccount.enabled: false + asserts: + - notExists: + path: spec.template.spec.serviceAccountName + + - it: uses service account name override when present + set: + rbac.serviceAccount.enabled: true + rbac.serviceAccount.name: example-sa + asserts: + - equal: + path: spec.template.spec.serviceAccountName + value: example-sa + + - it: uses a generated service account name when not given + set: + applicationName: example-app + rbac.serviceAccount.enabled: true + rbac.serviceAccount.name: "" + asserts: + - equal: + path: spec.template.spec.serviceAccountName + value: example-app diff --git a/application/values-test.yaml b/application/values-test.yaml index f38827df..3769cb7e 100644 --- a/application/values-test.yaml +++ b/application/values-test.yaml @@ -398,7 +398,7 @@ rbac: # Service Account to use by pods serviceAccount: enabled: true - name: "" + name: "application" # Additional Labels on service account additionalLabels: @@ -525,6 +525,27 @@ autoscaling: type: Utilization averageUtilization: 60 +# autoscaling is used for vertical pod autoscaling +vpa: +# enabled is a boolean flag for enabling or disabling vpa + enabled: true +# additionalLabels defines additional labels + additionalLabels: + # key: value +# annotations defines annotations in key value pair + annotations: + # key: value +# container policies for individual containers. +# There can be at most one entry for every named container and optionally a single wildcard entry with `containerName = '*'`, which handles all containers that do not have individual policies. + containerPolicies: + - containerName: '*' + minAllowed: + cpu: 0.5 + memory: 1Gi + maxAllowed: + cpu: 1 + memory: 5Gi + # EndpointMonitor for IMC (https://github.com/stakater/IngressMonitorController) endpointMonitor: enabled: true diff --git a/application/values.yaml b/application/values.yaml index 4766af4b..00c40bc0 100644 --- a/application/values.yaml +++ b/application/values.yaml @@ -187,6 +187,9 @@ deployment: # values: # - ssd + # Number of ReplicaSet versions to retain + revisionHistoryLimit: 2 + # Image of the app container image: repository: repository/image-name @@ -334,6 +337,9 @@ service: targetPort: 8080 type: ClusterIP + # Set to 'None' will make this service headless + clusterIP: + ########################################################## # Ingress object for exposing services ########################################################## @@ -610,6 +616,21 @@ autoscaling: type: Utilization averageUtilization: 60 +########################################################## +# VPA - Vertical Pod Autoscaling +########################################################## +vpa: +# enabled is a boolean flag for enabling or disabling vpa + enabled: false +# additionalLabels defines additional labels + additionalLabels: + # key: value +# annotations defines annotations in key value pair + annotations: + # key: value +# container policies for individual containers. + containerPolicies: [] + ########################################################## # EndpointMonitor for IMC # https://github.com/stakater/IngressMonitorController