diff --git a/.ci/mkdocs/mkdocs.yml b/.ci/mkdocs/mkdocs.yml index 5a630798..fbdd8af7 100644 --- a/.ci/mkdocs/mkdocs.yml +++ b/.ci/mkdocs/mkdocs.yml @@ -75,6 +75,9 @@ nav: - NFS share: common-library/storage/types/nfs-share.md - persistentVolumeClaim: common-library/storage/types/persistentVolumeClaim.md - Secret: common-library/storage/types/secret.md + - How To...: + - common-library/howto/index.md + - Default container options: common-library/howto/default-container-options.md - App Template: - app-template/index.md - How To...: diff --git a/.github/workflows/charts-release-oci.yaml b/.github/workflows/charts-release-oci.yaml index 56d4d52a..5fb8479c 100644 --- a/.github/workflows/charts-release-oci.yaml +++ b/.github/workflows/charts-release-oci.yaml @@ -21,6 +21,7 @@ jobs: name: Release charts runs-on: ubuntu-22.04 permissions: + contents: read packages: write # needed for ghcr access actions: read # for detecting the Github Actions environment. id-token: write # for creating OIDC tokens for signing. @@ -61,8 +62,8 @@ jobs: helm package "${{ env.CHARTS_SRC_DIR }}/${CHART_TYPE}/${CHART_NAME}" --dependency-update --destination "${{ env.CHARTS_SRC_DIR }}/${CHART_TYPE}" --version "${CHART_VERSION}" helm push "${{ env.CHARTS_SRC_DIR }}/${CHART_TYPE}/${CHART_NAME}-${CHART_VERSION}.tgz" oci://${{ env.TARGET_REGISTRY }}/${{ github.actor }}/helm &> push-metadata.txt CHART_DIGEST=$(awk '/Digest: /{print $2}' push-metadata.txt) - cosign sign -y "${{ env.TARGET_REGISTRY }}/${{ github.actor }}/helm/${CHART_NAME}:${CHART_VERSION}@${CHART_DIGEST}" + cosign sign --yes "${{ env.TARGET_REGISTRY }}/${{ github.actor }}/helm/${CHART_NAME}:${CHART_VERSION}@${CHART_DIGEST}" cosign verify "${{ env.TARGET_REGISTRY }}/${{ github.actor }}/helm/${CHART_NAME}:${CHART_VERSION}@${CHART_DIGEST}" \ --certificate-oidc-issuer "https://token.actions.githubusercontent.com" \ - --certificate-identity "https://github.com/${GITHUB_WORKFLOW_REF}" + --certificate-identity "https://github.com/bjw-s/helm-charts/.github/workflows/charts-release-oci.yaml@refs/heads/main" done diff --git a/.github/workflows/pr-validate.yaml b/.github/workflows/pr-validate.yaml index 70ed342b..217f2009 100644 --- a/.github/workflows/pr-validate.yaml +++ b/.github/workflows/pr-validate.yaml @@ -4,7 +4,6 @@ on: pull_request: types: - opened - - edited - reopened - ready_for_review - synchronize diff --git a/charts/apps/k8s-ycl/Chart.yaml b/charts/apps/k8s-ycl/Chart.yaml index 6bf5aa1f..2c04ac6f 100644 --- a/charts/apps/k8s-ycl/Chart.yaml +++ b/charts/apps/k8s-ycl/Chart.yaml @@ -2,7 +2,7 @@ apiVersion: v2 description: Kubernetes admission controller to remove CPU limits from Pods. name: k8s-ycl -version: 1.3.2 +version: 1.3.3 appVersion: v0.2.0 kubeVersion: ">=1.22.0-0" sources: @@ -19,12 +19,12 @@ maintainers: dependencies: - name: common repository: https://bjw-s.github.io/helm-charts - version: 3.3.2 + version: 3.4.0 annotations: artifacthub.io/changes: |- - kind: changed description: | - Update common library to 3.3.2 + Update common library to 3.4.0 artifacthub.io/links: | - name: "source" url: "https://github.com/bjw-s/k8s-ycl" diff --git a/charts/apps/k8s-ycl/README.md b/charts/apps/k8s-ycl/README.md index fd247598..4d88f024 100644 --- a/charts/apps/k8s-ycl/README.md +++ b/charts/apps/k8s-ycl/README.md @@ -20,7 +20,7 @@ Kubernetes: `>=1.22.0-0` | Repository | Name | Version | |------------|------|---------| -| https://bjw-s.github.io/helm-charts | common | 3.3.2 | +| https://bjw-s.github.io/helm-charts | common | 3.4.0 | ## Values diff --git a/charts/apps/k8s-ycl/values.schema.json b/charts/apps/k8s-ycl/values.schema.json index aae83aff..00c07f32 100644 --- a/charts/apps/k8s-ycl/values.schema.json +++ b/charts/apps/k8s-ycl/values.schema.json @@ -1,3 +1,3 @@ { - "$ref": "https://raw.githubusercontent.com/bjw-s/helm-charts/common-3.3.2/charts/library/common/values.schema.json" + "$ref": "https://raw.githubusercontent.com/bjw-s/helm-charts/common-3.4.0/charts/library/common/values.schema.json" } diff --git a/charts/library/common-test/ci/configMapsFolder/test_1/test_1.sh b/charts/library/common-test/ci/configMapsFolder/test_1/test_1.sh new file mode 100644 index 00000000..75b89d12 --- /dev/null +++ b/charts/library/common-test/ci/configMapsFolder/test_1/test_1.sh @@ -0,0 +1,2 @@ +#! /bin/bash +echo "Hello!" diff --git a/charts/library/common-test/ci/configMapsFolder/test_1/test_1.yaml b/charts/library/common-test/ci/configMapsFolder/test_1/test_1.yaml new file mode 100644 index 00000000..af089953 --- /dev/null +++ b/charts/library/common-test/ci/configMapsFolder/test_1/test_1.yaml @@ -0,0 +1,2 @@ +test: + test: "{{ .Values.configMapsFromFolderBasePath }}" diff --git a/charts/library/common-test/ci/configMapsFolder/test_2/test_2.escape.yaml b/charts/library/common-test/ci/configMapsFolder/test_2/test_2.escape.yaml new file mode 100644 index 00000000..af089953 --- /dev/null +++ b/charts/library/common-test/ci/configMapsFolder/test_2/test_2.escape.yaml @@ -0,0 +1,2 @@ +test: + test: "{{ .Values.configMapsFromFolderBasePath }}" diff --git a/charts/library/common-test/tests/_values/controllers_main_default_container.yaml b/charts/library/common-test/tests/_values/controllers_main_default_container.yaml index b3e702fa..74f3fdf2 100644 --- a/charts/library/common-test/tests/_values/controllers_main_default_container.yaml +++ b/charts/library/common-test/tests/_values/controllers_main_default_container.yaml @@ -6,4 +6,3 @@ controllers: image: repository: ghcr.io/mendhak/http-https-echo tag: 31 - pullPolicy: IfNotPresent diff --git a/charts/library/common-test/tests/configmap/metadata_test.yaml b/charts/library/common-test/tests/configmap/metadata_test.yaml index d15d0b41..f31510e3 100644 --- a/charts/library/common-test/tests/configmap/metadata_test.yaml +++ b/charts/library/common-test/tests/configmap/metadata_test.yaml @@ -98,3 +98,56 @@ tests: global_label: test helm.sh/chart: common-test-1.0.0 test_label: test + + - it: default metadata from folder should pass + set: + configMaps: + config: + data: + test: test + configMapsFromFolderBasePath: ci/configMapsFolder + asserts: + - hasDocuments: + count: 4 + - documentIndex: &FirstConfigmapDocument 1 + isKind: + of: ConfigMap + - documentIndex: *FirstConfigmapDocument + notExists: + path: metadata.annotations + - documentIndex: *FirstConfigmapDocument + equal: + path: metadata.labels + value: + app.kubernetes.io/instance: RELEASE-NAME + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/name: RELEASE-NAME + helm.sh/chart: common-test-1.0.0 + - documentIndex: &SecondConfigmapDocument 2 + isKind: + of: ConfigMap + - documentIndex: *SecondConfigmapDocument + notExists: + path: metadata.annotations + - documentIndex: *SecondConfigmapDocument + equal: + path: metadata.labels + value: + app.kubernetes.io/instance: RELEASE-NAME + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/name: RELEASE-NAME + helm.sh/chart: common-test-1.0.0 + - documentIndex: &ThirdConfigmapDocument 3 + isKind: + of: ConfigMap + - documentIndex: *ThirdConfigmapDocument + notExists: + path: metadata.annotations + - documentIndex: *ThirdConfigmapDocument + equal: + path: metadata.labels + value: + app.kubernetes.io/instance: RELEASE-NAME + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/name: RELEASE-NAME + helm.sh/chart: common-test-1.0.0 diff --git a/charts/library/common-test/tests/configmap/names_test.yaml b/charts/library/common-test/tests/configmap/names_test.yaml index 028cc892..6613a95c 100644 --- a/charts/library/common-test/tests/configmap/names_test.yaml +++ b/charts/library/common-test/tests/configmap/names_test.yaml @@ -107,3 +107,36 @@ tests: equal: path: metadata.name value: RELEASE-NAME + + - it: with templated nameOverride and from folder should pass + set: + configMaps: + config: + data: + test: test + nameOverride: "{{ .Release.Name }}" + configMapsFromFolderBasePath: ci/configMapsFolder + asserts: + - hasDocuments: + count: 4 + - documentIndex: &FirstConfigmapDocument 1 + isKind: + of: ConfigMap + - documentIndex: *FirstConfigmapDocument + equal: + path: metadata.name + value: RELEASE-NAME + - documentIndex: &SecondConfigmapDocument 2 + isKind: + of: ConfigMap + - documentIndex: *SecondConfigmapDocument + equal: + path: metadata.name + value: RELEASE-NAME-test_1 + - documentIndex: &ThirdConfigmapDocument 3 + isKind: + of: ConfigMap + - documentIndex: *ThirdConfigmapDocument + equal: + path: metadata.name + value: RELEASE-NAME-test_2 diff --git a/charts/library/common-test/tests/container/args_test.yaml b/charts/library/common-test/tests/container/field_args_test.yaml similarity index 68% rename from charts/library/common-test/tests/container/args_test.yaml rename to charts/library/common-test/tests/container/field_args_test.yaml index a6760fed..76aa324a 100644 --- a/charts/library/common-test/tests/container/args_test.yaml +++ b/charts/library/common-test/tests/container/field_args_test.yaml @@ -75,3 +75,35 @@ tests: - sleep - infinity - test + + - it: args from defaultContainerOptions should pass + set: + controllers.main.defaultContainerOptions: + args: value_of_args + asserts: + - documentIndex: &DeploymentDoc 0 + isKind: + of: Deployment + - documentIndex: *DeploymentDoc + equal: + path: spec.template.spec.containers[0].args + value: + - value_of_args + + - it: args from defaultContainerOptions with container override should pass + set: + controllers.main.defaultContainerOptions: + args: value_of_args + controllers.main.containers.main.args: + - value 1 + - value 2 + asserts: + - documentIndex: &DeploymentDoc 0 + isKind: + of: Deployment + - documentIndex: *DeploymentDoc + equal: + path: spec.template.spec.containers[0].args + value: + - value 1 + - value 2 diff --git a/charts/library/common-test/tests/container/command_test.yaml b/charts/library/common-test/tests/container/field_command_test.yaml similarity index 66% rename from charts/library/common-test/tests/container/command_test.yaml rename to charts/library/common-test/tests/container/field_command_test.yaml index 96e03353..d41871bc 100644 --- a/charts/library/common-test/tests/container/command_test.yaml +++ b/charts/library/common-test/tests/container/field_command_test.yaml @@ -73,3 +73,35 @@ tests: value: - /bin/sh - -c + + - it: command from defaultContainerOptions should pass + set: + controllers.main.defaultContainerOptions: + command: value_of_command + asserts: + - documentIndex: &DeploymentDoc 0 + isKind: + of: Deployment + - documentIndex: *DeploymentDoc + equal: + path: spec.template.spec.containers[0].command + value: + - value_of_command + + - it: command from defaultContainerOptions with container override should pass + set: + controllers.main.defaultContainerOptions: + command: value_of_command + controllers.main.containers.main.command: + - value 1 + - value 2 + asserts: + - documentIndex: &DeploymentDoc 0 + isKind: + of: Deployment + - documentIndex: *DeploymentDoc + equal: + path: spec.template.spec.containers[0].command + value: + - value 1 + - value 2 diff --git a/charts/library/common-test/tests/container/env_test.yaml b/charts/library/common-test/tests/container/field_env_test.yaml similarity index 87% rename from charts/library/common-test/tests/container/env_test.yaml rename to charts/library/common-test/tests/container/field_env_test.yaml index 0b5130b0..e2813943 100644 --- a/charts/library/common-test/tests/container/env_test.yaml +++ b/charts/library/common-test/tests/container/field_env_test.yaml @@ -237,3 +237,37 @@ tests: value: name: DEPENDENT_ENV value: moo_two + + - it: env from defaultContainerOptions should pass + set: + controllers.main.defaultContainerOptions: + env: + string: value_of_env + asserts: + - documentIndex: &DeploymentDoc 0 + isKind: + of: Deployment + - documentIndex: *DeploymentDoc + equal: + path: spec.template.spec.containers[0].env[0] + value: + name: string + value: value_of_env + + - it: env from defaultContainerOptions with container override should pass + set: + controllers.main.defaultContainerOptions: + env: + string: value_of_env + controllers.main.containers.main.env: + someThingElse: value_of_env + asserts: + - documentIndex: &DeploymentDoc 0 + isKind: + of: Deployment + - documentIndex: *DeploymentDoc + equal: + path: spec.template.spec.containers[0].env[0] + value: + name: someThingElse + value: value_of_env diff --git a/charts/library/common-test/tests/container/envfrom_test.yaml b/charts/library/common-test/tests/container/field_envfrom_test.yaml similarity index 71% rename from charts/library/common-test/tests/container/envfrom_test.yaml rename to charts/library/common-test/tests/container/field_envfrom_test.yaml index cb4bdadb..08b3c5a7 100644 --- a/charts/library/common-test/tests/container/envfrom_test.yaml +++ b/charts/library/common-test/tests/container/field_envfrom_test.yaml @@ -41,6 +41,61 @@ tests: configMapRef: name: myCustomConfig + - it: envFrom from defaultContainerOptions should pass + set: + controllers.main.defaultContainerOptions: + envFrom: + - secretRef: + name: myCustomSecret + prefix: test + - configMapRef: + name: myCustomConfig + asserts: + - documentIndex: &DeploymentDoc 0 + isKind: + of: Deployment + - documentIndex: *DeploymentDoc + equal: + path: spec.template.spec.containers[0].envFrom[0] + value: + secretRef: + name: myCustomSecret + prefix: test + - documentIndex: *DeploymentDoc + equal: + path: spec.template.spec.containers[0].envFrom[1] + value: + configMapRef: + name: myCustomConfig + + - it: envFrom from defaultContainerOptions with container override should pass + set: + controllers.main.defaultContainerOptions: + envFrom: + - secretRef: + name: myCustomSecret + prefix: test + - configMapRef: + name: myCustomConfig + controllers.main.containers.main.envFrom: + - secretRef: + name: myCustomSecretOverride + prefix: test + asserts: + - documentIndex: &DeploymentDoc 0 + isKind: + of: Deployment + - documentIndex: *DeploymentDoc + equal: + path: spec.template.spec.containers[0].envFrom[0] + value: + secretRef: + name: myCustomSecretOverride + prefix: test + - documentIndex: *DeploymentDoc + notExists: + path: spec.template.spec.containers[0].envFrom[1] + - it: envFrom configmap identifier reference should pass set: controllers.main.containers.main.envFrom: diff --git a/charts/library/common-test/tests/container/image_test.yaml b/charts/library/common-test/tests/container/field_image_test.yaml similarity index 50% rename from charts/library/common-test/tests/container/image_test.yaml rename to charts/library/common-test/tests/container/field_image_test.yaml index e407626c..bb64d835 100644 --- a/charts/library/common-test/tests/container/image_test.yaml +++ b/charts/library/common-test/tests/container/field_image_test.yaml @@ -3,10 +3,10 @@ suite: container image tag templates: - common.yaml -values: - - ../_values/controllers_main_default_container.yaml tests: - it: string tag should pass + values: + - ../_values/controllers_main_default_container.yaml set: controllers.main.containers.main.image: repository: ghcr.io/mendhak/http-https-echo @@ -21,6 +21,8 @@ tests: value: ghcr.io/mendhak/http-https-echo:latest - it: integer tag should pass + values: + - ../_values/controllers_main_default_container.yaml set: controllers.main.containers.main.image: repository: ghcr.io/mendhak/http-https-echo @@ -35,6 +37,8 @@ tests: value: ghcr.io/mendhak/http-https-echo:1.23 - it: template tag should pass + values: + - ../_values/controllers_main_default_container.yaml set: controllers.main.containers.main.image: repository: ghcr.io/mendhak/http-https-echo @@ -47,3 +51,38 @@ tests: equal: path: spec.template.spec.containers[0].image value: ghcr.io/mendhak/http-https-echo:1.0.0 + + - it: tag from defaultContainerOptions should pass + set: + controllers.main: + defaultContainerOptions: + image: + repository: ghcr.io/mendhak/http-https-echo + tag: 32 + containers: + main: {} # needed to have at least a container enabled + asserts: + - documentIndex: &DeploymentDoc 0 + isKind: + of: Deployment + - documentIndex: *DeploymentDoc + equal: + path: spec.template.spec.containers[0].image + value: ghcr.io/mendhak/http-https-echo:32 + + - it: tag from defaultContainerOptions with container override should pass + set: + controllers.main.defaultContainerOptions.image: + repository: ghcr.io/mendhak/http-https-echo + tag: 32 + controllers.main.containers.main.image: + repository: ghcr.io/mendhak/http-https-echo-override + tag: 33 + asserts: + - documentIndex: &DeploymentDoc 0 + isKind: + of: Deployment + - documentIndex: *DeploymentDoc + equal: + path: spec.template.spec.containers[0].image + value: ghcr.io/mendhak/http-https-echo-override:33 diff --git a/charts/library/common-test/tests/container/field_resources_test.yaml b/charts/library/common-test/tests/container/field_resources_test.yaml new file mode 100644 index 00000000..16d1a196 --- /dev/null +++ b/charts/library/common-test/tests/container/field_resources_test.yaml @@ -0,0 +1,142 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: container resources +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml +tests: + - it: default should pass + asserts: + - documentIndex: 0 + isKind: + of: Deployment + - documentIndex: 0 + notExists: + path: spec.template.spec.containers[0].resources + + - it: defaultContainerOption should pass + set: + controllers: + main: + defaultContainerOptions: + resources: + requests: + memory: 1Gi + initContainers: + test: + image: + repository: ghcr.io/mendhak/http-https-echo + tag: 31 + asserts: + - documentIndex: 0 + isKind: + of: Deployment + - documentIndex: 0 + equal: + path: spec.template.spec.containers[0].resources + value: + requests: + memory: 1Gi + - documentIndex: 0 + equal: + path: spec.template.spec.initContainers[0].resources + value: + requests: + memory: 1Gi + + - it: defaultContainerOption with container override should pass + set: + controllers: + main: + defaultContainerOptions: + resources: + requests: + memory: 1Gi + containers: + main: + resources: + requests: + memory: 2Gi + initContainers: + test: + image: + repository: ghcr.io/mendhak/http-https-echo + tag: 31 + asserts: + - documentIndex: 0 + isKind: + of: Deployment + - documentIndex: 0 + equal: + path: spec.template.spec.containers[0].resources + value: + requests: + memory: 2Gi + - documentIndex: 0 + equal: + path: spec.template.spec.initContainers[0].resources + value: + requests: + memory: 1Gi + + - it: defaultContainerOption with initContainer override should pass + set: + controllers: + main: + defaultContainerOptions: + resources: + requests: + memory: 1Gi + initContainers: + test: + image: + repository: ghcr.io/mendhak/http-https-echo + tag: 31 + resources: + requests: + memory: 2Gi + asserts: + - documentIndex: 0 + isKind: + of: Deployment + - documentIndex: 0 + equal: + path: spec.template.spec.containers[0].resources + value: + requests: + memory: 1Gi + - documentIndex: 0 + equal: + path: spec.template.spec.initContainers[0].resources + value: + requests: + memory: 2Gi + + - it: defaultContainerOption disabled for initContainer should pass + set: + controllers: + main: + applyDefaultContainerOptionsToInitContainers: false + defaultContainerOptions: + resources: + requests: + memory: 1Gi + initContainers: + test: + image: + repository: ghcr.io/mendhak/http-https-echo + tag: 31 + asserts: + - documentIndex: 0 + isKind: + of: Deployment + - documentIndex: 0 + equal: + path: spec.template.spec.containers[0].resources + value: + requests: + memory: 1Gi + - documentIndex: 0 + notExists: + path: spec.template.spec.initContainers[0].resources diff --git a/charts/library/common-test/tests/container/field_securityContext_test.yaml b/charts/library/common-test/tests/container/field_securityContext_test.yaml new file mode 100644 index 00000000..2f8afce4 --- /dev/null +++ b/charts/library/common-test/tests/container/field_securityContext_test.yaml @@ -0,0 +1,59 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: container securityContext +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml +tests: + - it: default should pass + asserts: + - documentIndex: 0 + isKind: + of: Deployment + - documentIndex: 0 + notExists: + path: spec.template.spec.containers[0].securityContext + + - it: defaultContainerOption should pass + set: + controllers: + main: + defaultContainerOptions: + securityContext: + runAsUser: 1000 + runAsGroup: 1000 + asserts: + - documentIndex: 0 + isKind: + of: Deployment + - documentIndex: 0 + equal: + path: spec.template.spec.containers[0].securityContext + value: + runAsUser: 1000 + runAsGroup: 1000 + + - it: defaultContainerOption with container override should pass + set: + controllers: + main: + defaultContainerOptions: + securityContext: + runAsUser: 1000 + runAsGroup: 1000 + containers: + main: + securityContext: + runAsUser: 568 + runAsGroup: 568 + asserts: + - documentIndex: 0 + isKind: + of: Deployment + - documentIndex: 0 + equal: + path: spec.template.spec.containers[0].securityContext + value: + runAsUser: 568 + runAsGroup: 568 diff --git a/charts/library/common-test/tests/controller/default_container_options_test.yaml b/charts/library/common-test/tests/controller/default_container_options_test.yaml new file mode 100644 index 00000000..e9e91b3b --- /dev/null +++ b/charts/library/common-test/tests/controller/default_container_options_test.yaml @@ -0,0 +1,136 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: controller defaultContainerOptions +templates: + - common.yaml +values: + - ../_values/controllers_main_default_container.yaml +tests: + - it: default should pass + asserts: + - documentIndex: 0 + isKind: + of: Deployment + - documentIndex: 0 + notExists: + path: spec.template.spec.containers[0].resources + + - it: defaultContainerOption with implicit strategy should pass + set: + controllers.main.defaultContainerOptions: + resources: + requests: + memory: 1Gi + cpu: 150m + controllers.main.containers.main.resources: + requests: + memory: 2Gi + asserts: + - documentIndex: 0 + isKind: + of: Deployment + - documentIndex: 0 + equal: + path: spec.template.spec.containers[0].resources + value: + requests: + memory: 2Gi + + - it: defaultContainerOption with overwrite strategy should pass + set: + controllers.main.defaultContainerOptionsStrategy: overwrite + controllers.main.defaultContainerOptions: + resources: + requests: + memory: 1Gi + cpu: 150m + controllers.main.containers.main.resources: + requests: + memory: 2Gi + asserts: + - documentIndex: 0 + isKind: + of: Deployment + - documentIndex: 0 + equal: + path: spec.template.spec.containers[0].resources + value: + requests: + memory: 2Gi + + - it: defaultContainerOption with merge strategy should pass + set: + controllers.main.defaultContainerOptionsStrategy: merge + controllers.main.defaultContainerOptions: + resources: + requests: + memory: 1Gi + cpu: 150m + controllers.main.containers.main.resources: + requests: + memory: 2Gi + asserts: + - documentIndex: 0 + isKind: + of: Deployment + - documentIndex: 0 + equal: + path: spec.template.spec.containers[0].resources + value: + requests: + memory: 2Gi + cpu: 150m + + - it: Default applyDefaultContainerOptionsToInitContainers (true) should pass + set: + controllers.main.defaultContainerOptions: + resources: + requests: + memory: 1Gi + controllers.main.initContainers: + test: + image: + repository: ghcr.io/mendhak/http-https-echo + tag: 31 + asserts: + - documentIndex: 0 + isKind: + of: Deployment + - documentIndex: 0 + equal: + path: spec.template.spec.containers[0].resources + value: + requests: + memory: 1Gi + - documentIndex: 0 + equal: + path: spec.template.spec.initContainers[0].resources + value: + requests: + memory: 1Gi + + - it: applyDefaultContainerOptionsToInitContainers false should pass + set: + controllers.main.applyDefaultContainerOptionsToInitContainers: false + controllers.main.defaultContainerOptions: + resources: + requests: + memory: 1Gi + controllers.main.initContainers: + test: + image: + repository: ghcr.io/mendhak/http-https-echo + tag: 31 + asserts: + - documentIndex: 0 + isKind: + of: Deployment + - documentIndex: 0 + equal: + path: spec.template.spec.containers[0].resources + value: + requests: + memory: 1Gi + - documentIndex: 0 + notExists: + path: spec.template.spec.initContainers[0].resources diff --git a/charts/library/common/Chart.yaml b/charts/library/common/Chart.yaml index e58c30b6..5b573058 100644 --- a/charts/library/common/Chart.yaml +++ b/charts/library/common/Chart.yaml @@ -3,7 +3,7 @@ apiVersion: v2 name: common description: Function library for Helm charts type: library -version: 3.3.2 +version: 3.4.0 kubeVersion: ">=1.22.0-0" keywords: - common @@ -16,16 +16,16 @@ annotations: artifacthub.io/changes: |- - kind: added description: |- - Added support for specifying unsupported raw resources. + Add configMapsFromFolderBasePath to create ConfigMaps from a folder - kind: added description: |- - Added `stdin` and `tty` fields to container spec. (fixed in v3.3.2) + Added support for setting `defaultContainerOptions`. + links: + - name: Documentation + url: https://bjw-s.github.io/helm-charts/docs/common-library/howto/default-container-options - kind: added description: |- - Added `persistentVolumeClaimRetentionPolicy` field to statefulset spec. + Added support for `loadBalancerClass`. - kind: fixed description: |- - Added `externalName` field to service schema. (fixed in v3.3.1) - - kind: fixed - description: |- - Always allow specifying `nodePort` field on service ports. + Fixed volume name reference when persistence key matches release name. diff --git a/charts/library/common/README.md b/charts/library/common/README.md index 5f946917..88c4f026 100644 --- a/charts/library/common/README.md +++ b/charts/library/common/README.md @@ -1,6 +1,6 @@ # common -![Version: 3.3.2](https://img.shields.io/badge/Version-3.3.2-informational?style=flat-square) ![Type: library](https://img.shields.io/badge/Type-library-informational?style=flat-square) +![Version: 3.4.0](https://img.shields.io/badge/Version-3.4.0-informational?style=flat-square) ![Type: library](https://img.shields.io/badge/Type-library-informational?style=flat-square) Function library for Helm charts @@ -27,7 +27,7 @@ Include this chart as a dependency in your `Chart.yaml` e.g. # Chart.yaml dependencies: - name: common - version: 3.3.2 + version: 3.4.0 repository: https://bjw-s.github.io/helm-charts/ ``` @@ -50,4 +50,4 @@ These values will be validated by a JSON schema which can be found [here](https: - Join the home-operations [Discord](https://discord.gg/home-operations) community ---------------------------------------------- -Autogenerated from chart metadata using [helm-docs v1.13.1](https://github.com/norwoodj/helm-docs/releases/v1.13.1) +Autogenerated from chart metadata using [helm-docs v1.14.2](https://github.com/norwoodj/helm-docs/releases/v1.14.2) diff --git a/charts/library/common/schemas/containers.json b/charts/library/common/schemas/containers.json index f3806618..f99ebbe8 100644 --- a/charts/library/common/schemas/containers.json +++ b/charts/library/common/schemas/containers.json @@ -9,22 +9,10 @@ "default": true }, "args": { - "oneOf": [ - { - "type": "array", - "items": {"type": "string"} - }, - {"type": "string"} - ] + "$ref": "#/args" }, "command": { - "oneOf": [ - { - "type": "array", - "items": {"type": "string"} - }, - {"type": "string"} - ] + "$ref": "#/command" }, "dependsOn": { "oneOf": [ @@ -36,82 +24,13 @@ ] }, "env": { - "oneOf": [ - { - "type": "array", - "items": { - "anyOf": [ - {"$ref": "envVars.json#/envVarListItem"}, - {"$ref": "envVars.json#/valueFromListItem"} - ] - } - }, - { - "type": "object", - "additionalProperties": { - "anyOf": [ - {"$ref": "envVars.json#/envVarValue"}, - {"$ref": "envVars.json#/envVarItem"}, - {"$ref": "envVars.json#/valueFromItem"} - ] - } - } - ] + "$ref": "#/env" }, "envFrom": { - "type": "array", - "items": { - "type": "object", - "additionalProperties": false, - "properties": { - "configMap": { - "type": "string" - }, - "configMapRef": { - "type": "object", - "additionalProperties": false, - "properties": { - "name": {"type": "string"}, - "identifier": {"type": "string"}, - "optional": {"type": "boolean"} - }, - "oneOf": [{"required": ["name"]}, {"required": ["identifier"]}] - }, - "prefix": { - "type": ["string", "null"] - }, - "secret": { - "type": "string" - }, - "secretRef": { - "type": "object", - "additionalProperties": false, - "properties": { - "name": {"type": "string"}, - "identifier": {"type": "string"}, - "optional": {"type": "boolean"} - }, - "oneOf": [{"required": ["name"]}, {"required": ["identifier"]}] - } - } - } + "$ref": "#/envFrom" }, "image": { - "type": "object", - "additionalProperties": false, - "properties": { - "pullPolicy": { - "type": "string", - "enum": ["Always", "IfNotPresent"] - }, - "repository": { - "type": "string" - }, - "tag": { - "type": ["string", "number"] - } - }, - "required": ["repository", "tag"] + "$ref": "#/image" }, "lifecycle": { "$ref": "k8s-api.json#/core.v1.Lifecycle" @@ -170,6 +89,106 @@ } }, + "args": { + "oneOf": [ + { + "type": "array", + "items": {"type": "string"} + }, + {"type": "string"} + ] + }, + + "command": { + "oneOf": [ + { + "type": "array", + "items": {"type": "string"} + }, + {"type": "string"} + ] + }, + + "env": { + "oneOf": [ + { + "type": "array", + "items": { + "anyOf": [ + {"$ref": "envVars.json#/envVarListItem"}, + {"$ref": "envVars.json#/valueFromListItem"} + ] + } + }, + { + "type": "object", + "additionalProperties": { + "anyOf": [ + {"$ref": "envVars.json#/envVarValue"}, + {"$ref": "envVars.json#/envVarItem"}, + {"$ref": "envVars.json#/valueFromItem"} + ] + } + } + ] + }, + + "envFrom": { + "type": "array", + "items": { + "type": "object", + "additionalProperties": false, + "properties": { + "configMap": { + "type": "string" + }, + "configMapRef": { + "type": "object", + "additionalProperties": false, + "properties": { + "name": {"type": "string"}, + "identifier": {"type": "string"}, + "optional": {"type": "boolean"} + }, + "oneOf": [{"required": ["name"]}, {"required": ["identifier"]}] + }, + "prefix": { + "type": ["string", "null"] + }, + "secret": { + "type": "string" + }, + "secretRef": { + "type": "object", + "additionalProperties": false, + "properties": { + "name": {"type": "string"}, + "identifier": {"type": "string"}, + "optional": {"type": "boolean"} + }, + "oneOf": [{"required": ["name"]}, {"required": ["identifier"]}] + } + } + } + }, + + "image": { + "type": "object", + "additionalProperties": false, + "properties": { + "pullPolicy": { + "type": "string", + "enum": ["Always", "IfNotPresent"] + }, + "repository": { + "type": "string" + }, + "tag": { + "type": ["string", "number"] + } + } + }, + "probe": { "additionalProperties": false, "properties": { diff --git a/charts/library/common/schemas/controllers.json b/charts/library/common/schemas/controllers.json index 73c67899..a3c1f2af 100644 --- a/charts/library/common/schemas/controllers.json +++ b/charts/library/common/schemas/controllers.json @@ -47,6 +47,42 @@ "statefulset": { "$ref": "#/statefulset" }, + "applyDefaultContainerOptionsToInitContainers": { + "type": "boolean", + "default": true + }, + "defaultContainerOptionsStrategy": { + "type": "string", + "default": "overwrite", + "enum": ["overwrite", "merge"] + }, + "defaultContainerOptions": { + "type": "object", + "additionalProperties": false, + "properties": { + "args": { + "$ref": "containers.json#/args" + }, + "command": { + "$ref": "containers.json#/command" + }, + "env": { + "$ref": "containers.json#/env" + }, + "envFrom": { + "$ref": "containers.json#/envFrom" + }, + "image": { + "$ref": "containers.json#/image" + }, + "resources": { + "$ref": "k8s-api.json#/core.v1.ResourceRequirements" + }, + "securityContext": { + "$ref": "k8s-api.json#/core.v1.ContainerSecurityContext" + } + } + }, "initContainers": { "type": "object", "additionalProperties": { diff --git a/charts/library/common/schemas/service.json b/charts/library/common/schemas/service.json index 785fce39..ee597177 100644 --- a/charts/library/common/schemas/service.json +++ b/charts/library/common/schemas/service.json @@ -32,6 +32,9 @@ "type": "array", "items": {"type": "string"} }, + "loadBalancerClass": { + "type": "string" + }, "externalTrafficPolicy": { "type": "string", "enum": ["Cluster", "Local"] diff --git a/charts/library/common/templates/classes/_service.tpl b/charts/library/common/templates/classes/_service.tpl index 3517506d..2b991d7f 100644 --- a/charts/library/common/templates/classes/_service.tpl +++ b/charts/library/common/templates/classes/_service.tpl @@ -49,6 +49,9 @@ spec: loadBalancerSourceRanges: {{ toYaml $serviceObject.loadBalancerSourceRanges | nindent 4 }} {{- end -}} + {{- if $serviceObject.loadBalancerClass }} + loadBalancerClass: {{ $serviceObject.loadBalancerClass }} + {{- end -}} {{- else if eq $svcType "ExternalName" }} type: {{ $svcType }} {{- if $serviceObject.externalName }} diff --git a/charts/library/common/templates/lib/container/_valuesToObject.tpl b/charts/library/common/templates/lib/container/_valuesToObject.tpl index 50b9e2f5..285ef973 100644 --- a/charts/library/common/templates/lib/container/_valuesToObject.tpl +++ b/charts/library/common/templates/lib/container/_valuesToObject.tpl @@ -3,11 +3,39 @@ Convert container values to an object */}} {{- define "bjw-s.common.lib.container.valuesToObject" -}} {{- $rootContext := .rootContext -}} + {{- $controllerObject := mustDeepCopy .controllerObject -}} + {{- $containerType := .containerType -}} {{- $identifier := .id -}} - {{- $objectValues := .values -}} + {{- $objectValues := mustDeepCopy .values -}} + {{- $defaultContainerOptionsStrategy := dig "defaultContainerOptionsStrategy" "overwrite" $controllerObject -}} + {{- $mergeDefaultContainerOptions := true -}} {{- $_ := set $objectValues "identifier" $identifier -}} + {{- /* Allow disabling default options for initContainers */ -}} + {{- if (eq "init" $containerType) -}} + {{- $applyDefaultContainerOptionsToInitContainers := dig "applyDefaultContainerOptionsToInitContainers" true $controllerObject -}} + {{- if (not (eq $applyDefaultContainerOptionsToInitContainers true)) -}} + {{- $mergeDefaultContainerOptions = false -}} + {{- end -}} + {{- end -}} + + {{- /* Merge default container options if required */ -}} + {{- if (eq true $mergeDefaultContainerOptions) -}} + {{- if eq "overwrite" $defaultContainerOptionsStrategy -}} + {{- range $key, $defaultValue := (dig "defaultContainerOptions" dict $controllerObject) }} + {{- $specificValue := dig $key nil $objectValues -}} + {{- if not (empty $specificValue) -}} + {{- $_ := set $objectValues $key $specificValue -}} + {{- else -}} + {{- $_ := set $objectValues $key $defaultValue -}} + {{- end -}} + {{- end -}} + {{- else if eq "merge" $defaultContainerOptionsStrategy -}} + {{- $objectValues = merge $objectValues (dig "defaultContainerOptions" dict $controllerObject) -}} + {{- end -}} + {{- end -}} + {{- /* Process image tags */ -}} {{- if kindIs "map" $objectValues.image -}} {{- $imageTag := dig "image" "tag" "" $objectValues -}} diff --git a/charts/library/common/templates/lib/container/fields/_args.tpl b/charts/library/common/templates/lib/container/fields/_args.tpl index 172e444e..2aaa8485 100644 --- a/charts/library/common/templates/lib/container/fields/_args.tpl +++ b/charts/library/common/templates/lib/container/fields/_args.tpl @@ -4,19 +4,17 @@ Args used by the container. {{- define "bjw-s.common.lib.container.field.args" -}} {{- $ctx := .ctx -}} {{- $containerObject := $ctx.containerObject -}} + {{- $argValues := get $containerObject "args" -}} {{- /* Default to empty list */ -}} {{- $args := list -}} {{- /* See if an override is desired */ -}} - {{- if not (empty (get $containerObject "args")) -}} - {{- $option := get $containerObject "args" -}} - {{- if not (empty $option) -}} - {{- if kindIs "string" $option -}} - {{- $args = append $args $option -}} - {{- else -}} - {{- $args = $option -}} - {{- end -}} + {{- if not (empty $argValues) -}} + {{- if kindIs "string" $argValues -}} + {{- $args = append $args $argValues -}} + {{- else -}} + {{- $args = $argValues -}} {{- end -}} {{- end -}} diff --git a/charts/library/common/templates/lib/container/fields/_command.tpl b/charts/library/common/templates/lib/container/fields/_command.tpl index 67e3b65b..18122bab 100644 --- a/charts/library/common/templates/lib/container/fields/_command.tpl +++ b/charts/library/common/templates/lib/container/fields/_command.tpl @@ -4,19 +4,17 @@ Command used by the container. {{- define "bjw-s.common.lib.container.field.command" -}} {{- $ctx := .ctx -}} {{- $containerObject := $ctx.containerObject -}} + {{- $commandValues := get $containerObject "command" -}} {{- /* Default to empty list */ -}} {{- $command := list -}} {{- /* See if an override is desired */ -}} - {{- if not (empty (get $containerObject "command")) -}} - {{- $option := get $containerObject "command" -}} - {{- if not (empty $option) -}} - {{- if kindIs "string" $option -}} - {{- $command = append $command $option -}} - {{- else -}} - {{- $command = $option -}} - {{- end -}} + {{- if not (empty $commandValues) -}} + {{- if kindIs "string" $commandValues -}} + {{- $command = append $command $commandValues -}} + {{- else -}} + {{- $command = $commandValues -}} {{- end -}} {{- end -}} diff --git a/charts/library/common/templates/lib/container/fields/_env.tpl b/charts/library/common/templates/lib/container/fields/_env.tpl index 72973fb2..c8e7d62a 100644 --- a/charts/library/common/templates/lib/container/fields/_env.tpl +++ b/charts/library/common/templates/lib/container/fields/_env.tpl @@ -5,25 +5,26 @@ Env field used by the container. {{- $ctx := .ctx -}} {{- $rootContext := $ctx.rootContext -}} {{- $containerObject := $ctx.containerObject -}} + {{- $envValues := get $containerObject "env" -}} {{- /* Default to empty list */ -}} {{- $envList := list -}} {{- /* See if an override is desired */ -}} - {{- if not (empty (get $containerObject "env")) -}} - {{- if kindIs "slice" $containerObject.env -}} + {{- if not (empty $envValues) -}} + {{- if kindIs "slice" $envValues -}} {{- /* Env is a list so we assume the order is already as desired */ -}} - {{- range $name, $var := $containerObject.env -}} + {{- range $name, $var := $envValues -}} {{- if kindIs "int" $name -}} {{- $name = required "environment variables as a list of maps require a name field" $var.name -}} {{- end -}} {{- end -}} - {{- $envList = $containerObject.env -}} + {{- $envList = $envValues -}} {{- else -}} {{- /* Env is a map so we must check if ordering is desired */ -}} {{- $graph := dict -}} - {{- range $name, $var := $containerObject.env -}} + {{- range $name, $var := $envValues -}} {{- if kindIs "map" $var -}} {{- /* Value is a map so ordering can be specified */ -}} {{- if empty (dig "dependsOn" nil $var) -}} @@ -44,7 +45,7 @@ Env field used by the container. {{- range $name := $args.out -}} {{- $envItem := dict "name" $name -}} - {{- $envValue := get $containerObject.env $name -}} + {{- $envValue := get $envValues $name -}} {{- if kindIs "map" $envValue -}} {{- $envItem := merge $envItem (omit $envValue "dependsOn") -}} diff --git a/charts/library/common/templates/lib/container/fields/_envFrom.tpl b/charts/library/common/templates/lib/container/fields/_envFrom.tpl index 84e73129..31fe2001 100644 --- a/charts/library/common/templates/lib/container/fields/_envFrom.tpl +++ b/charts/library/common/templates/lib/container/fields/_envFrom.tpl @@ -1,14 +1,15 @@ {{/* -Env field used by the container. +envFrom field used by the container. */}} {{- define "bjw-s.common.lib.container.field.envFrom" -}} {{- $ctx := .ctx -}} {{- $rootContext := $ctx.rootContext -}} {{- $containerObject := $ctx.containerObject -}} + {{- $envFromValues := get $containerObject "envFrom" -}} - {{- if not (empty (get $containerObject "envFrom")) -}} + {{- if not (empty $envFromValues) -}} {{- $envFrom := list -}} - {{- range $containerObject.envFrom -}} + {{- range $envFromValues -}} {{- $item := dict -}} {{- if hasKey . "configMap" -}} diff --git a/charts/library/common/templates/lib/pod/fields/_containers.tpl b/charts/library/common/templates/lib/pod/fields/_containers.tpl index 6c9f8ded..0549ab4e 100644 --- a/charts/library/common/templates/lib/pod/fields/_containers.tpl +++ b/charts/library/common/templates/lib/pod/fields/_containers.tpl @@ -15,7 +15,7 @@ Returns the value for containers {{- range $key, $containerValues := $enabledContainers -}} {{- /* Create object from the container values */ -}} - {{- $containerObject := (include "bjw-s.common.lib.container.valuesToObject" (dict "rootContext" $rootContext "id" $key "values" $containerValues)) | fromYaml -}} + {{- $containerObject := (include "bjw-s.common.lib.container.valuesToObject" (dict "rootContext" $rootContext "controllerObject" $controllerObject "containerType" "default" "id" $key "values" $containerValues)) | fromYaml -}} {{- /* Perform validations on the Container before rendering */ -}} {{- include "bjw-s.common.lib.container.validate" (dict "rootContext" $ "controllerObject" $controllerObject "containerObject" $containerObject) -}} diff --git a/charts/library/common/templates/lib/pod/fields/_initContainers.tpl b/charts/library/common/templates/lib/pod/fields/_initContainers.tpl index f5bc750a..3ad8fbd4 100644 --- a/charts/library/common/templates/lib/pod/fields/_initContainers.tpl +++ b/charts/library/common/templates/lib/pod/fields/_initContainers.tpl @@ -21,7 +21,7 @@ Returns the value for initContainers {{- if $containerEnabled -}} {{- /* Create object from the container values */ -}} - {{- $containerObject := (include "bjw-s.common.lib.container.valuesToObject" (dict "rootContext" $rootContext "id" $key "values" $containerValues)) | fromYaml -}} + {{- $containerObject := (include "bjw-s.common.lib.container.valuesToObject" (dict "rootContext" $rootContext "controllerObject" $controllerObject "containerType" "init" "id" $key "values" $containerValues)) | fromYaml -}} {{- /* Perform validations on the Container before rendering */ -}} {{- include "bjw-s.common.lib.container.validate" (dict "rootContext" $ "controllerObject" $controllerObject "containerObject" $containerObject) -}} diff --git a/charts/library/common/templates/lib/pod/fields/_volumes.tpl b/charts/library/common/templates/lib/pod/fields/_volumes.tpl index 2918d504..8bb09593 100644 --- a/charts/library/common/templates/lib/pod/fields/_volumes.tpl +++ b/charts/library/common/templates/lib/pod/fields/_volumes.tpl @@ -51,7 +51,9 @@ Returns the value for volumes {{- $pvcName = (printf "%s-%s" (include "bjw-s.common.lib.chart.names.fullname" $rootContext) $persistenceValues.nameOverride) -}} {{- end -}} {{- else -}} - {{- $pvcName = (printf "%s-%s" (include "bjw-s.common.lib.chart.names.fullname" $rootContext) $identifier) -}} + {{- if not (eq $pvcName $identifier) -}} + {{- $pvcName = (printf "%s-%s" (include "bjw-s.common.lib.chart.names.fullname" $rootContext) $identifier) -}} + {{- end -}} {{- end -}} {{- end -}} {{- $_ := set $volume "persistentVolumeClaim" (dict "claimName" $pvcName) -}} diff --git a/charts/library/common/templates/loader/_generate.tpl b/charts/library/common/templates/loader/_generate.tpl index 62657304..3dc1af44 100644 --- a/charts/library/common/templates/loader/_generate.tpl +++ b/charts/library/common/templates/loader/_generate.tpl @@ -13,6 +13,7 @@ Secondary entrypoint and primary loader for the common chart {{- include "bjw-s.common.render.ingresses" . | nindent 0 -}} {{- include "bjw-s.common.render.serviceMonitors" . | nindent 0 -}} {{- include "bjw-s.common.render.routes" . | nindent 0 -}} + {{- include "bjw-s.common.render.configMaps.fromFiles" . | nindent 0 -}} {{- include "bjw-s.common.render.configMaps" . | nindent 0 -}} {{- include "bjw-s.common.render.secrets" . | nindent 0 -}} {{- include "bjw-s.common.render.networkpolicies" . | nindent 0 -}} diff --git a/charts/library/common/templates/render/_configmaps.tpl b/charts/library/common/templates/render/_configmaps.tpl index 7d69205d..484a3d5e 100644 --- a/charts/library/common/templates/render/_configmaps.tpl +++ b/charts/library/common/templates/render/_configmaps.tpl @@ -24,3 +24,36 @@ Renders the configMap objects required by the chart. {{- end -}} {{- end -}} {{- end -}} + +{{/* +Renders configMap objects required by the chart from a folder in the repo's path. +*/}} +{{- define "bjw-s.common.render.configMaps.fromFiles" -}} +{{- $rootValues := .Values -}} + +{{/* Generate a list of unique top level folders */}} +{{ $topLevelFolders := dict}} +{{- range $path, $_ := .Files.Glob (printf "%s/*/*" .Values.configMapsFromFolderBasePath) -}} + {{- $_ := set $topLevelFolders (dir $path) "" -}} +{{- end -}} +{{- $top_level_folder_list := keys $topLevelFolders | sortAlpha -}} + + {{/* Iterate over the top level folders */}} + {{ range $path := $top_level_folder_list }} + {{- $filesContentNoFormat := ($.Files.Glob (printf "%s/*" $path)) -}} + {{- $filesContent := dict -}} + {{- range $file_name, $content := $filesContentNoFormat -}} + {{- $key := base $file_name -}} + {{- if contains ".escape" $key -}} + {{- $key := $key | replace ".escape" "" -}} + {{- $filesContent = merge $filesContent (dict $key (($.Files.Get $file_name) | replace "{{" "{{ `{{` }}")) -}} + {{- else -}} + {{- $filesContent = merge $filesContent (dict $key ($.Files.Get $file_name)) -}} + {{- end -}} + {{- end -}} + {{- $configMapValues := dict "enabled" true "labels" dict "annotations" dict "data" $filesContent -}} + {{- $existingConfigMaps := (get $rootValues "configMaps"| default dict) -}} + {{- $mergedConfigMaps := deepCopy $existingConfigMaps | merge (dict (base $path) $configMapValues) -}} + {{- $rootValues := merge $rootValues (dict "configMaps" $mergedConfigMaps) -}} + {{ end }} +{{ end }} diff --git a/charts/library/common/values.schema.json b/charts/library/common/values.schema.json index c608433a..0865edc1 100644 --- a/charts/library/common/values.schema.json +++ b/charts/library/common/values.schema.json @@ -1,6 +1,6 @@ { "$schema": "http://json-schema.org/draft-07/schema", - "$id": "https://raw.githubusercontent.com/bjw-s/helm-charts/common-3.3.2/charts/library/common/values.schema.json", + "$id": "https://raw.githubusercontent.com/bjw-s/helm-charts/common-3.4.0/charts/library/common/values.schema.json", "type": "object", "properties": { diff --git a/charts/library/common/values.yaml b/charts/library/common/values.yaml index 915d2eb7..82207be3 100644 --- a/charts/library/common/values.yaml +++ b/charts/library/common/values.yaml @@ -194,6 +194,36 @@ controllers: {} # # Controller-specific overrides for `defaultPodOptions` keys # pod: {} +# # -- Whether to apply defaultContainerOptions to initContainers +# applyDefaultContainerOptionsToInitContainers: true +# # -- Set the strategy for the default container options. Defaults to +# # overwrite: If container-level options are set, use those instead of the defaults. +# # merge: If container-level options are set, merge them with the defaults +# # @default -- overwrite +# defaultContainerOptionsStrategy: overwrite +# # -- Set default options for all (init)Containers here +# # Each of these options can be overridden on a container level +# defaultContainerOptions: +# image: +# # -- Override the image repository for the containers +# repository: +# # -- Override the image tag for the containers +# tag: +# # -- Override the image pull policy for the containers +# pullPolicy: +# # -- Override the command(s) for the containers +# command: +# # -- Override the args for the containers +# args: +# # -- Environment variables. +# env: +# # -- Secrets and/or ConfigMaps that will be loaded as environment variables. +# envFrom: {} +# # -- Set the resource requests / limits for the container. +# resources: +# # -- Configure the Security Context for the container +# securityContext: {} + # containers: # main: # # -- Override the container name @@ -211,11 +241,11 @@ controllers: {} # # -- image pull policy # pullPolicy: -# # -- Override the command(s) for the default container +# # -- Override the command(s) for the container # command: [] -# # -- Override the args for the default container +# # -- Override the args for the container # args: [] -# # -- Override the working directory for the default container +# # -- Override the working directory for the container # workingDir: # # -- Environment variables. Template enabled. @@ -410,6 +440,18 @@ configMaps: # data: # foo: bar +# -- A path in your parent's chart filesystem where you can add files to be converted into individual ConfigMaps. +# Your files will need to be two levels deep from the base path. +# For example, if you set this to `files/`, and you have this file tree +# files: +# └── configmap1 +# ├── file1 +# └── file2 +# This will generate a ConfigMap named `configmap1` with keys `file1` and `file2`, values being the respective contents of those files. +# If your file contains `gotpl` syntax that you don't want templated by Helm, prefix the file extension with `.escape` and it will be treated as a regular string. +# For example, `file1.escape.yaml` will be converted to `file1.yaml` in the ConfigMap with the contents of the file not templated. +configMapsFromFolderBasePath: null + # -- Configure the services for the chart here. # Additional services can be added by adding a dictionary key similar to the 'main' service. # @default -- See below diff --git a/charts/other/app-template/Chart.yaml b/charts/other/app-template/Chart.yaml index f210e61d..25c8cfae 100644 --- a/charts/other/app-template/Chart.yaml +++ b/charts/other/app-template/Chart.yaml @@ -2,7 +2,7 @@ apiVersion: v2 description: A common powered chart template. This can be useful for small projects that don't have their own chart. name: app-template -version: 3.3.2 +version: 3.4.0 kubeVersion: ">=1.22.0-0" maintainers: - name: bjw-s @@ -10,12 +10,12 @@ maintainers: dependencies: - name: common repository: https://bjw-s.github.io/helm-charts - version: 3.3.2 + version: 3.4.0 annotations: artifacthub.io/changes: |- - kind: changed description: | - Updated library version to 3.3.2. + Updated library version to 3.4.0. links: - name: Upgrade instructions from v2.x url: https://bjw-s.github.io/helm-charts/docs/app-template/#from-2xx-to-30x diff --git a/charts/other/app-template/README.md b/charts/other/app-template/README.md index 6bc4cb85..02f29d25 100644 --- a/charts/other/app-template/README.md +++ b/charts/other/app-template/README.md @@ -1,6 +1,6 @@ # app-template -![Version: 3.3.2](https://img.shields.io/badge/Version-3.3.2-informational?style=flat-square) +![Version: 3.4.0](https://img.shields.io/badge/Version-3.4.0-informational?style=flat-square) A common powered chart template. This can be useful for small projects that don't have their own chart. @@ -12,7 +12,7 @@ Kubernetes: `>=1.22.0-0` | Repository | Name | Version | |------------|------|---------| -| https://bjw-s.github.io/helm-charts | common | 3.3.2 | +| https://bjw-s.github.io/helm-charts | common | 3.4.0 | ## Installing the Chart diff --git a/charts/other/app-template/schemas/helmrelease-helm-v2.schema.json b/charts/other/app-template/schemas/helmrelease-helm-v2.schema.json index 839d842d..0cb8241e 100644 --- a/charts/other/app-template/schemas/helmrelease-helm-v2.schema.json +++ b/charts/other/app-template/schemas/helmrelease-helm-v2.schema.json @@ -726,7 +726,7 @@ "values": { "description": "Values holds the values for this Helm release.", "x-kubernetes-preserve-unknown-fields": true, - "$ref": "https://raw.githubusercontent.com/bjw-s/helm-charts/common-3.3.2/charts/library/common/values.schema.json" + "$ref": "https://raw.githubusercontent.com/bjw-s/helm-charts/common-3.4.0/charts/library/common/values.schema.json" }, "valuesFrom": { "description": "ValuesFrom holds references to resources containing Helm values for this HelmRelease,\nand information about how they should be merged.", diff --git a/charts/other/app-template/schemas/helmrelease-helm-v2beta2.schema.json b/charts/other/app-template/schemas/helmrelease-helm-v2beta2.schema.json index 83fb026e..b7762db1 100644 --- a/charts/other/app-template/schemas/helmrelease-helm-v2beta2.schema.json +++ b/charts/other/app-template/schemas/helmrelease-helm-v2beta2.schema.json @@ -727,7 +727,7 @@ "values": { "description": "Values holds the values for this Helm release.", "x-kubernetes-preserve-unknown-fields": true, - "$ref": "https://raw.githubusercontent.com/bjw-s/helm-charts/common-3.3.2/charts/library/common/values.schema.json" + "$ref": "https://raw.githubusercontent.com/bjw-s/helm-charts/common-3.4.0/charts/library/common/values.schema.json" }, "valuesFrom": { "description": "ValuesFrom holds references to resources containing Helm values for this HelmRelease, and information about how they should be merged.", diff --git a/charts/other/app-template/values.schema.json b/charts/other/app-template/values.schema.json index aae83aff..00c07f32 100644 --- a/charts/other/app-template/values.schema.json +++ b/charts/other/app-template/values.schema.json @@ -1,3 +1,3 @@ { - "$ref": "https://raw.githubusercontent.com/bjw-s/helm-charts/common-3.3.2/charts/library/common/values.schema.json" + "$ref": "https://raw.githubusercontent.com/bjw-s/helm-charts/common-3.4.0/charts/library/common/values.schema.json" } diff --git a/docs/common-library/howto/default-container-options.md b/docs/common-library/howto/default-container-options.md new file mode 100644 index 00000000..0c5c139d --- /dev/null +++ b/docs/common-library/howto/default-container-options.md @@ -0,0 +1,83 @@ +--- +hide: + - toc +--- + +# Setting default container options + +It is possible to configure default container options under the `controllers.*.defaultContainerOptions` key. These options will be applied to all containers within the controller. + +## Only applying to regular containers + +By default the `defaultContainerOptions` will be applied to both `initContainers` and regular `containers`. +If you wish to only apply the default options to regular containers, set `controllers.*.applyDefaultContainerOptionsToInitContainers` to `false`. + +## Default value strategies + +### Overwrite + +The default strategy for configuring default container options is `overwrite`. This means that if a container has an entry for a default container option it will be overwritten entirely by the container-specific configuration. + +This behavior can be set explicitly by setting `controllers.*.defaultContainerOptionsStrategy` to `overwrite`. + +An (abbreviated) example of the `overwrite` strategy: + +```yaml +controllers: + main: + defaultContainerOptions: + resources: + requests: + memory: 1Gi + cpu: 150m + + containers: + main: + ... + resources: + requests: + cpu: 100m +``` + +The expected `resources` field on the `main` container is expected to look like this: + +```yaml +resources: + requests: + cpu: 150m +``` + +### Merge + +An alternative strategy for configuring default container options is `merge`. This means that if a container has an entry for a default container option it will be merged with the container-specific configuration. + +This behavior can be set explicitly by setting `defaultContainerOptionsStrategy` to `merge`. + +An (abbreviated) example of the `merge` strategy: + +```yaml +controllers: + main: + defaultContainerOptionsStrategy: merge + defaultContainerOptions: + resources: + requests: + memory: 1Gi + cpu: 150m + + containers: + main: + ... + resources: + requests: + cpu: 100m +``` + +The expected `resources` field on the `main` container is expected to look like this: + +```yaml +resources: + requests: + memory: 1Gi + cpu: 150m +``` diff --git a/docs/common-library/howto/index.md b/docs/common-library/howto/index.md new file mode 100644 index 00000000..82f77372 --- /dev/null +++ b/docs/common-library/howto/index.md @@ -0,0 +1,3 @@ +# How to... + +Here you can find information on how to accomplish specific scenario's.