diff --git a/library/common-test/tests/pod/automount_sa_token_test.yaml b/library/common-test/tests/pod/automount_sa_token_test.yaml new file mode 100644 index 0000000000..f4faf383ef --- /dev/null +++ b/library/common-test/tests/pod/automount_sa_token_test.yaml @@ -0,0 +1,75 @@ +suite: pod auto mount sa token test +templates: + - common.yaml +tests: + - it: should pass with automountServiceAccountToken disabled from "global" + set: + podOptions: + automountServiceAccountToken: false + controllers: + controller-name1: + enabled: true + primary: true + type: Deployment + podSpec: {} + asserts: + - documentIndex: &deploymentDoc 0 + isKind: + of: Deployment + - documentIndex: *deploymentDoc + equal: + path: spec.template.spec.automountServiceAccountToken + value: false + + - it: should pass with automountServiceAccountToken enabled from "global" + set: + podOptions: + automountServiceAccountToken: true + controllers: + controller-name1: + enabled: true + primary: true + type: Deployment + podSpec: {} + asserts: + - documentIndex: *deploymentDoc + isKind: + of: Deployment + - documentIndex: *deploymentDoc + equal: + path: spec.template.spec.automountServiceAccountToken + value: true + + - it: should pass with disabled automountServiceAccountToken from pod + set: + podOptions: + automountServiceAccountToken: true + controllers: + controller-name1: + enabled: true + primary: true + type: Deployment + podSpec: + automountServiceAccountToken: false + asserts: + - documentIndex: *deploymentDoc + equal: + path: spec.template.spec.automountServiceAccountToken + value: false + + - it: should pass with enabled automountServiceAccountToken from pod + set: + podOptions: + automountServiceAccountToken: false + controllers: + controller-name1: + enabled: true + primary: true + type: Deployment + podSpec: + automountServiceAccountToken: true + asserts: + - documentIndex: *deploymentDoc + equal: + path: spec.template.spec.automountServiceAccountToken + value: true diff --git a/library/common-test/tests/pod/image_pull_secret_test.yaml b/library/common-test/tests/pod/image_pull_secret_test.yaml index 46a91b41fa..541514abdf 100644 --- a/library/common-test/tests/pod/image_pull_secret_test.yaml +++ b/library/common-test/tests/pod/image_pull_secret_test.yaml @@ -43,8 +43,8 @@ tests: equal: path: spec.jobTemplate.spec.template.spec.imagePullSecrets value: - - release-name-common-test-pull-secret1 - - release-name-common-test-pull-secret2 + - name: release-name-common-test-pull-secret1 + - name: release-name-common-test-pull-secret2 - documentIndex: &otherDeploymentDoc 3 isKind: of: Deployment @@ -90,8 +90,8 @@ tests: equal: path: spec.template.spec.imagePullSecrets value: - - release-name-common-test-pull-secret1 - - release-name-common-test-pull-secret2 + - name: release-name-common-test-pull-secret1 + - name: release-name-common-test-pull-secret2 - documentIndex: &otherDeploymentDoc 3 isKind: of: Deployment @@ -99,8 +99,8 @@ tests: equal: path: spec.template.spec.imagePullSecrets value: - - release-name-common-test-pull-secret1 - - release-name-common-test-pull-secret2 + - name: release-name-common-test-pull-secret1 + - name: release-name-common-test-pull-secret2 - it: should assign imagePullSecrets to selected pods set: @@ -143,8 +143,8 @@ tests: equal: path: spec.template.spec.imagePullSecrets value: - - release-name-common-test-pull-secret1 - - release-name-common-test-pull-secret2 + - name: release-name-common-test-pull-secret1 + - name: release-name-common-test-pull-secret2 - documentIndex: &otherDeploymentDoc 3 isKind: of: Deployment @@ -152,4 +152,4 @@ tests: equal: path: spec.template.spec.imagePullSecrets value: - - release-name-common-test-pull-secret1 + - name: release-name-common-test-pull-secret1 diff --git a/library/common-test/tests/pod/service_account_name_test.yaml b/library/common-test/tests/pod/service_account_name_test.yaml new file mode 100644 index 0000000000..2673ce040f --- /dev/null +++ b/library/common-test/tests/pod/service_account_name_test.yaml @@ -0,0 +1,130 @@ +suite: pod service account name test +templates: + - common.yaml +tests: + - it: should assign serviceAccount to primary pod + set: + controllers: + controller-name1: + enabled: true + primary: true + type: CronJob + schedule: "* * * * *" + podSpec: {} + controller-name2: + enabled: true + primary: false + type: Deployment + podSpec: {} + serviceAccounts: + sa-name1: + enabled: true + asserts: + - documentIndex: &cronJobDoc 1 + isKind: + of: CronJob + - documentIndex: *cronJobDoc + equal: + path: metadata.name + value: release-name-common-test + - documentIndex: *cronJobDoc + equal: + path: spec.jobTemplate.spec.template.spec.serviceAccountName + value: release-name-common-test-sa-name1 + - documentIndex: &otherDeploymentDoc 2 + isKind: + of: Deployment + - documentIndex: *otherDeploymentDoc + equal: + path: spec.template.spec.serviceAccountName + value: default + + - it: should assign serviceAccount to all pods + set: + controllers: + controller-name1: + enabled: true + primary: true + type: Deployment + podSpec: {} + controller-name2: + enabled: true + primary: false + type: Deployment + podSpec: {} + serviceAccounts: + sa-name1: + enabled: true + targetSelectAll: true + asserts: + - documentIndex: &deploymentDoc 1 + isKind: + of: Deployment + - documentIndex: *deploymentDoc + equal: + path: spec.template.spec.serviceAccountName + value: release-name-common-test-sa-name1 + - documentIndex: &otherDeploymentDoc 2 + isKind: + of: Deployment + - documentIndex: *otherDeploymentDoc + equal: + path: spec.template.spec.serviceAccountName + value: release-name-common-test-sa-name1 + + - it: should assign serviceAccount to selected pods + set: + controllers: + controller-name1: + enabled: true + primary: true + type: DaemonSet + podSpec: {} + controller-name2: + enabled: true + primary: false + type: Deployment + podSpec: {} + serviceAccounts: + sa-name1: + enabled: true + targetSelector: + - controller-name1 + - controller-name2 + asserts: + - documentIndex: &daemonSetDoc 1 + isKind: + of: DaemonSet + - documentIndex: *daemonSetDoc + equal: + path: spec.template.spec.serviceAccountName + value: release-name-common-test-sa-name1 + - documentIndex: &otherDeploymentDoc 2 + isKind: + of: Deployment + - documentIndex: *otherDeploymentDoc + equal: + path: spec.template.spec.serviceAccountName + value: release-name-common-test-sa-name1 + + # Failures + - it: should fail with more than 1 SA assigned to a pod + set: + controllers: + controller-name1: + enabled: true + primary: true + type: Deployment + podSpec: {} + serviceAccounts: + sa-name1: + enabled: true + targetSelector: + - controller-name1 + sa-name2: + enabled: true + targetSelector: + - controller-name1 + asserts: + - failedTemplate: + errorMessage: Expected at most 1 ServiceAccount to be assigned on a pod [controller-name1]. But [2] were assigned diff --git a/library/common/1.0.0/docs/controllers.md b/library/common/1.0.0/docs/controllers.md index ee95117b2c..d9128e3dd7 100644 --- a/library/common/1.0.0/docs/controllers.md +++ b/library/common/1.0.0/docs/controllers.md @@ -1,46 +1,47 @@ # Controllers -| Key | Type | Required | Helm Template | Default | Description | -| :---------------------------------------------------------------------- | :-------: | :------: | :-----------: | :------------------------------------------------------------: | :----------------------------------------------------------------------------------- | -| controllers | `dict` | ❌ | ❌ | `{}` | Define the controllers as dicts | -| controllers.[controller-name] | `dict` | ✅ | ❌ | `{}` | Holds controller definition | -| controllers.[controller-name].enabled | `boolean` | ✅ | ❌ | `false` | Enables or Disables the controller | -| controllers.[controller-name].primary | `boolean` | ✅ | ❌ | `false` | Sets the controller as primary | -| controllers.[controller-name].labels | `dict` | ❌ | ❌ | `{}` | Additional labels for controller | -| controllers.[controller-name].labels.[key-name] | `string` | ❌ | ❌ | | [Key] of the additional label | -| controllers.[controller-name].labels.[key-name].[value] | `string` | ❌ | ✅ | | [Value] for [key] of the additional label | -| controllers.[controller-name].annotations | `dict` | ❌ | ❌ | `{}` | Additional annotations for controller | -| controllers.[controller-name].annotations.[key-name] | `string` | ❌ | ❌ | | [Key] of the additional annotation | -| controllers.[controller-name].annotations.[key-name].[value] | `string` | ❌ | ✅ | | [Value] for [key] of the additional annotation | -| controllers.[controller-name].type | `string` | ✅ | ❌ | `""` | Define the kind of the controller (Deployment, DaemonSet, StatefulSet, CronJob, Job) | -| controllers.[controller-name].podSpec | `dict` | ✅ | ❌ | `{}` | Holds the pod definition | -| controllers.[controller-name].podSpec.labels | `dict` | ❌ | ❌ | `{}` | Additional Pod Labels | -| controllers.[controller-name].podSpec.labels.[key-name] | `string` | ❌ | ❌ | | [Key] of the additional label | -| controllers.[controller-name].podSpec.labels.[key-name].[value] | `string` | ❌ | ✅ | | [Value] for [key] of the additional label | -| controllers.[controller-name].podSpec.annotations | `dict` | ❌ | ✅ | `{}` | Pod Annotations | -| controllers.[controller-name].podSpec.annotations.[key-name] | `string` | ❌ | ❌ | | [Key] of the additional annotation | -| controllers.[controller-name].podSpec.annotations.[key-name].[value] | `string` | ❌ | ✅ | | [Value] of [key] of the additional annotation | -| controllers.[controller-name].podSpec.hostNetwork | `boolean` | ❌ | ❌ | `{{ .Values.podOptions.hostNetwork }}` (false) | Pod's hostNetwork | -| controllers.[controller-name].podSpec.enableServiceLinks | `boolean` | ❌ | ❌ | `{{ .Values.podOptions.enableServiceLinks }}` (false) | Pod's enableServiceLinks | -| controllers.[controller-name].podSpec.restartPolicy | `string` | ❌ | ✅ | `{{ .Values.podOptions.restartPolicy }}` (Always) | Pod's restartPolicy. (Always, Never, OnFailure) | -| controllers.[controller-name].podSpec.schedulerName | `string` | ❌ | ✅ | `{{ .Values.podOptions.schedulerName }}` ("") | Pod's schedulerName | -| controllers.[controller-name].podSpec.priorityClassName | `string` | ❌ | ✅ | `{{ .Values.podOptions.priorityClassName }}` ("") | Pod's priorityClassName | -| controllers.[controller-name].podSpec.hostname | `string` | ❌ | ✅ | `""` | Pod's hostname | -| controllers.[controller-name].podSpec.terminationGracePeriodSeconds | `int` | ❌ | ✅ | `{{ .Values.podOptions.terminationGracePeriodSeconds }}` (120) | Pod's terminationGracePeriodSeconds | -| controllers.[controller-name].podSpec.nodeSelector | `dict` | ❌ | ❌ | `{{ .Values.podOptions.nodeSelector }}` ({}) | Pod's nodeSelector | -| controllers.[controller-name].podSpec.nodeSelector.[key-name] | `string` | ❌ | ❌ | | [Key] for nodeSelector | -| controllers.[controller-name].podSpec.nodeSelector.[key-name].[value] | `string` | ❌ | ✅ | | [Value] for [key] for nodeSelector | -| controllers.[controller-name].podSpec.hostAliases | `list` | ❌ | ❌ | | Pod's host aliases | -| controllers.[controller-name].podSpec.hostAliases.ip | `string` | ❌ | ✅ | | Value for `ip` in hosts aliases | -| controllers.[controller-name].podSpec.hostAliases.hostnames | `list` | ❌ | ❌ | | Hostnames for the `ip` in hosts aliases | -| controllers.[controller-name].podSpec.hostAliases.hostnames.[host-name] | `string` | ❌ | ✅ | | [Value] for `hostnames` for the `ip` in hosts aliases | -| controllers.[controller-name].podSpec.dnsPolicy | `string` | ❌ | ✅ | `{{ .Values.podOptions.dnsPolicy }}` (ClusterFirst) | Pod's DNS Policy (ClusterFirst, ClusterFirstWithHostNet, Default, None). | -| controllers.[controller-name].podSpec.tolerations | `list` | ❌ | ❌ | `{{ .Values.podOptions.tolerations }}` ([]) | Pod's Tolerations | -| controllers.[controller-name].podSpec.tolerations.operator | `string` | ✅ | ✅ | | Toleration's `operator` (Equal, Exists) | -| controllers.[controller-name].podSpec.tolerations.key | `string` | ❌/✅ | ✅ | | Toleration's `key`. Required only when `operator` = `Equal` | -| controllers.[controller-name].podSpec.tolerations.value | `string` | ❌/✅ | ✅ | | Toleration's `value`. Required only when `operator` = `Equal` | -| controllers.[controller-name].podSpec.tolerations.effect | `string` | ❌ | ✅ | | Toleration's `effect`.(NoExecute, NoSchedule, PreferNoSchedule) | -| controllers.[controller-name].podSpec.tolerations.tolerationSeconds | `int` | ❌ | ❌ | | Toleration's `tolerationSeconds`. | +| Key | Type | Required | Helm Template | Default | Description | +| :---------------------------------------------------------------------- | :-------: | :------: | :-----------: | :-------------------------------------------------------------: | :----------------------------------------------------------------------------------- | +| controllers | `dict` | ❌ | ❌ | `{}` | Define the controllers as dicts | +| controllers.[controller-name] | `dict` | ✅ | ❌ | `{}` | Holds controller definition | +| controllers.[controller-name].enabled | `boolean` | ✅ | ❌ | `false` | Enables or Disables the controller | +| controllers.[controller-name].primary | `boolean` | ✅ | ❌ | `false` | Sets the controller as primary | +| controllers.[controller-name].labels | `dict` | ❌ | ❌ | `{}` | Additional labels for controller | +| controllers.[controller-name].labels.[key-name] | `string` | ❌ | ❌ | | [Key] of the additional label | +| controllers.[controller-name].labels.[key-name].[value] | `string` | ❌ | ✅ | | [Value] for [key] of the additional label | +| controllers.[controller-name].annotations | `dict` | ❌ | ❌ | `{}` | Additional annotations for controller | +| controllers.[controller-name].annotations.[key-name] | `string` | ❌ | ❌ | | [Key] of the additional annotation | +| controllers.[controller-name].annotations.[key-name].[value] | `string` | ❌ | ✅ | | [Value] for [key] of the additional annotation | +| controllers.[controller-name].type | `string` | ✅ | ❌ | `""` | Define the kind of the controller (Deployment, DaemonSet, StatefulSet, CronJob, Job) | +| controllers.[controller-name].podSpec | `dict` | ✅ | ❌ | `{}` | Holds the pod definition | +| controllers.[controller-name].podSpec.labels | `dict` | ❌ | ❌ | `{}` | Additional Pod Labels | +| controllers.[controller-name].podSpec.labels.[key-name] | `string` | ❌ | ❌ | | [Key] of the additional label | +| controllers.[controller-name].podSpec.labels.[key-name].[value] | `string` | ❌ | ✅ | | [Value] for [key] of the additional label | +| controllers.[controller-name].podSpec.annotations | `dict` | ❌ | ✅ | `{}` | Pod Annotations | +| controllers.[controller-name].podSpec.annotations.[key-name] | `string` | ❌ | ❌ | | [Key] of the additional annotation | +| controllers.[controller-name].podSpec.annotations.[key-name].[value] | `string` | ❌ | ✅ | | [Value] of [key] of the additional annotation | +| controllers.[controller-name].podSpec.automountServiceAccountToken | `boolean` | ❌ | ❌ | `{{ .Values.podOptions.automountServiceAccoutnToken }}` (false) | Pod's automountServiceAccountToken | +| controllers.[controller-name].podSpec.hostNetwork | `boolean` | ❌ | ❌ | `{{ .Values.podOptions.hostNetwork }}` (false) | Pod's hostNetwork | +| controllers.[controller-name].podSpec.enableServiceLinks | `boolean` | ❌ | ❌ | `{{ .Values.podOptions.enableServiceLinks }}` (false) | Pod's enableServiceLinks | +| controllers.[controller-name].podSpec.restartPolicy | `string` | ❌ | ✅ | `{{ .Values.podOptions.restartPolicy }}` (Always) | Pod's restartPolicy. (Always, Never, OnFailure) | +| controllers.[controller-name].podSpec.schedulerName | `string` | ❌ | ✅ | `{{ .Values.podOptions.schedulerName }}` ("") | Pod's schedulerName | +| controllers.[controller-name].podSpec.priorityClassName | `string` | ❌ | ✅ | `{{ .Values.podOptions.priorityClassName }}` ("") | Pod's priorityClassName | +| controllers.[controller-name].podSpec.hostname | `string` | ❌ | ✅ | `""` | Pod's hostname | +| controllers.[controller-name].podSpec.terminationGracePeriodSeconds | `int` | ❌ | ✅ | `{{ .Values.podOptions.terminationGracePeriodSeconds }}` (120) | Pod's terminationGracePeriodSeconds | +| controllers.[controller-name].podSpec.nodeSelector | `dict` | ❌ | ❌ | `{{ .Values.podOptions.nodeSelector }}` ({}) | Pod's nodeSelector | +| controllers.[controller-name].podSpec.nodeSelector.[key-name] | `string` | ❌ | ❌ | | [Key] for nodeSelector | +| controllers.[controller-name].podSpec.nodeSelector.[key-name].[value] | `string` | ❌ | ✅ | | [Value] for [key] for nodeSelector | +| controllers.[controller-name].podSpec.hostAliases | `list` | ❌ | ❌ | | Pod's host aliases | +| controllers.[controller-name].podSpec.hostAliases.ip | `string` | ❌ | ✅ | | Value for `ip` in hosts aliases | +| controllers.[controller-name].podSpec.hostAliases.hostnames | `list` | ❌ | ❌ | | Hostnames for the `ip` in hosts aliases | +| controllers.[controller-name].podSpec.hostAliases.hostnames.[host-name] | `string` | ❌ | ✅ | | [Value] for `hostnames` for the `ip` in hosts aliases | +| controllers.[controller-name].podSpec.dnsPolicy | `string` | ❌ | ✅ | `{{ .Values.podOptions.dnsPolicy }}` (ClusterFirst) | Pod's DNS Policy (ClusterFirst, ClusterFirstWithHostNet, Default, None). | +| controllers.[controller-name].podSpec.tolerations | `list` | ❌ | ❌ | `{{ .Values.podOptions.tolerations }}` ([]) | Pod's Tolerations | +| controllers.[controller-name].podSpec.tolerations.operator | `string` | ✅ | ✅ | | Toleration's `operator` (Equal, Exists) | +| controllers.[controller-name].podSpec.tolerations.key | `string` | ❌/✅ | ✅ | | Toleration's `key`. Required only when `operator` = `Equal` | +| controllers.[controller-name].podSpec.tolerations.value | `string` | ❌/✅ | ✅ | | Toleration's `value`. Required only when `operator` = `Equal` | +| controllers.[controller-name].podSpec.tolerations.effect | `string` | ❌ | ✅ | | Toleration's `effect`.(NoExecute, NoSchedule, PreferNoSchedule) | +| controllers.[controller-name].podSpec.tolerations.tolerationSeconds | `int` | ❌ | ❌ | | Toleration's `tolerationSeconds`. | --- @@ -90,6 +91,7 @@ controllers: key: value annotations: key: value + automountServiceAccountToken: true hostNetwork: false enableServiceLinks: false schedulerName: some-scheduler diff --git a/library/common/1.0.0/docs/imagePullSecrets.md b/library/common/1.0.0/docs/imagePullSecrets.md index b260551acb..c751253141 100644 --- a/library/common/1.0.0/docs/imagePullSecrets.md +++ b/library/common/1.0.0/docs/imagePullSecrets.md @@ -13,10 +13,10 @@ | imagePullSecrets.[pull-secret-name].data.password | `string` | ✅ | ✅ | `""` | Define the password of the image pull secret | | imagePullSecrets.[pull-secret-name].data.email | `string` | ✅ | ✅ | `""` | Define the email of the image pull secret | | imagePullSecrets.[pull-secret-name].targetSelectAll | `boolean` | ❌ | ❌ | | Whether to assign the secret to all pods or not | -| imagePullSecrets.[pull-secret-name].targetSelector | `list` | ❌ | ❌ | `""` | Define the pod(s) to assign the secret | +| imagePullSecrets.[pull-secret-name].targetSelector | `list` | ❌ | ❌ | `[]` | Define the pod(s) to assign the secret | > When `targetSelectAll` is `true`, it will assign the secret to all pods (`targetSelector` is ignored in this case) -> When `targetSelector` is a list, it's entry is a string, referencing the pod(s) name that will be assigned. +> When `targetSelector` is a list, each entry is a string, referencing the pod(s) name that will be assigned. > When `targetSelector` is a empty, it will assign the secret to the primary pod --- diff --git a/library/common/1.0.0/docs/secrets.md b/library/common/1.0.0/docs/secrets.md index 911da0118c..1e3fdc3126 100644 --- a/library/common/1.0.0/docs/secrets.md +++ b/library/common/1.0.0/docs/secrets.md @@ -31,9 +31,9 @@ secrets: secret-name: enabled: true + type: CustomSecretType labels: key: value - type: CustomSecretType keytpl: "{{ .Values.some.value }}" annotations: key: value diff --git a/library/common/1.0.0/docs/serviceAccounts.md b/library/common/1.0.0/docs/serviceAccounts.md new file mode 100644 index 0000000000..88d3d1a658 --- /dev/null +++ b/library/common/1.0.0/docs/serviceAccounts.md @@ -0,0 +1,50 @@ +# Service Account + +| Key | Type | Required | Helm Template | Default | Description | +| :---------------------------------------- | :-------: | :------: | :-----------: | :-----: | :------------------------------------------------------ | +| serviceAccounts | `dict` | ❌ | ❌ | `{}` | Define the serviceAccounts as dicts | +| serviceAccounts.[sa-name] | `dict` | ✅ | ❌ | `{}` | Holds secret definition | +| serviceAccounts.[sa-name].enabled | `boolean` | ✅ | ❌ | `false` | Enables or Disables the secret | +| serviceAccounts.[sa-name].labels | `dict` | ❌ | ✅ | `{}` | Additional labels for secret | +| serviceAccounts.[sa-name].annotations | `dict` | ❌ | ✅ | `{}` | Additional annotations for secret | +| serviceAccounts.[sa-name].targetSelectAll | `boolean` | ❌ | ❌ | | Whether to assign the serviceAccount to all pods or not | +| serviceAccounts.[sa-name].targetSelector | `list` | ❌ | ❌ | `[]` | Define the pod(s) to assign the serviceAccount | + +> When `targetSelectAll` is `true`, it will assign the serviceAccount to all pods (`targetSelector` is ignored in this case) +> When `targetSelector` is a list, each entry is a string, referencing the pod(s) name that will be assigned. +> When `targetSelector` is a empty, it will assign the serviceAccount to the primary pod + +--- + +Appears in: + +- `.Values.serviceAccounts` + +--- + +Naming scheme: + +- `$FullName-$ServiceAccountName` (release-name-chart-name-ServiceAccountName) + +--- + +Examples: + +```yaml +serviceAccounts: + sa-name: + enabled: true + labels: + key: value + keytpl: "{{ .Values.some.value }}" + annotations: + key: value + keytpl: "{{ .Values.some.value }}" + targetSelectAll: true + + other-sa-name: + enabled: true + targetSelector: + - pod-name + - other-pod-name +``` diff --git a/library/common/1.0.0/templates/classes/_configmap.tpl b/library/common/1.0.0/templates/classes/_configmap.tpl index eac7680146..7799c8fae9 100644 --- a/library/common/1.0.0/templates/classes/_configmap.tpl +++ b/library/common/1.0.0/templates/classes/_configmap.tpl @@ -1,6 +1,6 @@ {{/* Configmap Class */}} {{/* Call this template: -{{ include "ix.v1.common.class.configmap" (dict "objectData" $objectData "rootCtx" $) }} +{{ include "ix.v1.common.class.configmap" (dict "rootCtx" $ "objectData" $objectData) }} rootCtx: The root context of the template. It is used to access the global context. objectData: diff --git a/library/common/1.0.0/templates/classes/_cronjob.tpl b/library/common/1.0.0/templates/classes/_cronjob.tpl index 585b953993..7caf769246 100644 --- a/library/common/1.0.0/templates/classes/_cronjob.tpl +++ b/library/common/1.0.0/templates/classes/_cronjob.tpl @@ -1,6 +1,6 @@ {{/* CronJob Class */}} {{/* Call this template: -{{ include "ix.v1.common.class.cronjob" (dict "objectData" $objectData "rootCtx" $) }} +{{ include "ix.v1.common.class.cronjob" (dict "rootCtx" $ "objectData" $objectData) }} rootCtx: The root context of the template. It is used to access the global context. objectData: The object data to be used to render the CronJob. diff --git a/library/common/1.0.0/templates/classes/_daemonset.tpl b/library/common/1.0.0/templates/classes/_daemonset.tpl index 74367439b5..80bbdbf5fe 100644 --- a/library/common/1.0.0/templates/classes/_daemonset.tpl +++ b/library/common/1.0.0/templates/classes/_daemonset.tpl @@ -1,6 +1,6 @@ {{/* DaemonSet Class */}} {{/* Call this template: -{{ include "ix.v1.common.class.deployment" (dict "objectData" $objectData "rootCtx" $) }} +{{ include "ix.v1.common.class.deployment" (dict "rootCtx" $ "objectData" $objectData) }} rootCtx: The root context of the template. It is used to access the global context. objectData: The object data to be used to render the DaemonSet. diff --git a/library/common/1.0.0/templates/classes/_deployment.tpl b/library/common/1.0.0/templates/classes/_deployment.tpl index 358fc25bd4..e5afc1b1c1 100644 --- a/library/common/1.0.0/templates/classes/_deployment.tpl +++ b/library/common/1.0.0/templates/classes/_deployment.tpl @@ -1,6 +1,6 @@ {{/* Deployment Class */}} {{/* Call this template: -{{ include "ix.v1.common.class.deployment" (dict "objectData" $objectData "rootCtx" $) }} +{{ include "ix.v1.common.class.deployment" (dict "rootCtx" $ "objectData" $objectData) }} rootCtx: The root context of the template. It is used to access the global context. objectData: The object data to be used to render the Deployment. diff --git a/library/common/1.0.0/templates/classes/_job.tpl b/library/common/1.0.0/templates/classes/_job.tpl index 0f566f4779..bbd037da61 100644 --- a/library/common/1.0.0/templates/classes/_job.tpl +++ b/library/common/1.0.0/templates/classes/_job.tpl @@ -1,6 +1,6 @@ {{/* Job Class */}} {{/* Call this template: -{{ include "ix.v1.common.class.job" (dict "objectData" $objectData "rootCtx" $) }} +{{ include "ix.v1.common.class.job" (dict "rootCtx" $ "objectData" $objectData) }} rootCtx: The root context of the template. It is used to access the global context. objectData: The object data to be used to render the Job. diff --git a/library/common/1.0.0/templates/classes/_secret.tpl b/library/common/1.0.0/templates/classes/_secret.tpl index 3f2fc3000c..9f7e1f3920 100644 --- a/library/common/1.0.0/templates/classes/_secret.tpl +++ b/library/common/1.0.0/templates/classes/_secret.tpl @@ -1,6 +1,6 @@ {{/* Secret Class */}} {{/* Call this template: -{{ include "ix.v1.common.class.secret" (dict "objectData" $objectData "rootCtx" $) }} +{{ include "ix.v1.common.class.secret" (dict "rootCtx" $ "objectData" $objectData) }} rootCtx: The root context of the template. It is used to access the global context. objectData: diff --git a/library/common/1.0.0/templates/classes/_serviceAccount.tpl b/library/common/1.0.0/templates/classes/_serviceAccount.tpl new file mode 100644 index 0000000000..1672d3bea5 --- /dev/null +++ b/library/common/1.0.0/templates/classes/_serviceAccount.tpl @@ -0,0 +1,32 @@ +{{/* Service Account Class */}} +{{/* Call this template: +{{ include "ix.v1.common.class.serviceAccount" (dict "rootCtx" $ "objectData" $objectData) }} + +rootCtx: The root context of the template. It is used to access the global context. +objectData: + name: The name of the serviceAccount. + labels: The labels of the serviceAccount. + annotations: The annotations of the serviceAccount. + autoMountToken: Whether to mount the ServiceAccount token or not. +*/}} + +{{- define "ix.v1.common.class.serviceAccount" -}} + + {{- $rootCtx := .rootCtx -}} + {{- $objectData := .objectData }} +--- +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ $objectData.name }} + {{- $labels := (mustMerge ($objectData.labels | default dict) (include "ix.v1.common.lib.metadata.allLabels" $rootCtx | fromYaml)) -}} + {{- with (include "ix.v1.common.lib.metadata.render" (dict "rootCtx" $rootCtx "labels" $labels) | trim) }} + labels: + {{- . | nindent 4 }} + {{- end -}} + {{- $annotations := (mustMerge ($objectData.annotations | default dict) (include "ix.v1.common.lib.metadata.allAnnotations" $rootCtx | fromYaml)) -}} + {{- with (include "ix.v1.common.lib.metadata.render" (dict "rootCtx" $rootCtx "annotations" $annotations) | trim) }} + annotations: + {{- . | nindent 4 }} + {{- end -}} +{{- end -}} diff --git a/library/common/1.0.0/templates/classes/_statefulset.tpl b/library/common/1.0.0/templates/classes/_statefulset.tpl index ffd1127805..792fd44f61 100644 --- a/library/common/1.0.0/templates/classes/_statefulset.tpl +++ b/library/common/1.0.0/templates/classes/_statefulset.tpl @@ -1,6 +1,6 @@ {{/* StatefulSet Class */}} {{/* Call this template: -{{ include "ix.v1.common.class.deployment" (dict "objectData" $objectData "rootCtx" $) }} +{{ include "ix.v1.common.class.deployment" (dict "rootCtx" $ "objectData" $objectData) }} rootCtx: The root context of the template. It is used to access the global context. objectData: The object data to be used to render the StatefulSet. diff --git a/library/common/1.0.0/templates/lib/controller/_pod.tpl b/library/common/1.0.0/templates/lib/controller/_pod.tpl index 7f1545cffb..398093e467 100644 --- a/library/common/1.0.0/templates/lib/controller/_pod.tpl +++ b/library/common/1.0.0/templates/lib/controller/_pod.tpl @@ -7,7 +7,8 @@ objectData: The object data to be used to render the Pod. {{- define "ix.v1.common.lib.controller.pod" -}} {{- $rootCtx := .rootCtx -}} {{- $objectData := .objectData -}} -#TODO:serviceAccountName: +serviceAccountName: {{ include "ix.v1.common.lib.pod.serviceAccountName" (dict "rootCtx" $rootCtx "objectData" $objectData) }} +automountServiceAccountToken: {{ include "ix.v1.common.lib.pod.automountServiceAccountToken" (dict "rootCtx" $rootCtx "objectData" $objectData) }} {{- with (include "ix.v1.common.lib.pod.imagePullSecrets" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim) }} imagePullSecrets: {{- . | nindent 2 }} diff --git a/library/common/1.0.0/templates/lib/pod/_autoMountServiceAccountToken.tpl b/library/common/1.0.0/templates/lib/pod/_autoMountServiceAccountToken.tpl new file mode 100644 index 0000000000..46428bff02 --- /dev/null +++ b/library/common/1.0.0/templates/lib/pod/_autoMountServiceAccountToken.tpl @@ -0,0 +1,24 @@ +{{/* Returns automountServiceAccountToken */}} +{{/* Call this template: +{{ include "ix.v1.common.lib.pod.automountServiceAccountToken" (dict "rootCtx" $ "objectData" $objectData) }} +rootCtx: The root context of the template. It is used to access the global context. +objectData: The object data to be used to render the Pod. +*/}} +{{- define "ix.v1.common.lib.pod.automountServiceAccountToken" -}} + {{- $rootCtx := .rootCtx -}} + {{- $objectData := .objectData -}} + + {{- $automount := false -}} + + {{/* Initialize from the "global" option */}} + {{- if (kindIs "bool" $rootCtx.Values.podOptions.automountServiceAccountToken) -}} + {{- $automount = $rootCtx.Values.podOptions.automountServiceAccountToken -}} + {{- end -}} + + {{/* Override with pod's option */}} + {{- if (kindIs "bool" $objectData.podSpec.automountServiceAccountToken) -}} + {{- $automount = $objectData.podSpec.automountServiceAccountToken -}} + {{- end -}} + + {{- $automount -}} +{{- end -}} diff --git a/library/common/1.0.0/templates/lib/pod/_imagePullSecrets.tpl b/library/common/1.0.0/templates/lib/pod/_imagePullSecrets.tpl index 151f5c9ddc..7d01f94731 100644 --- a/library/common/1.0.0/templates/lib/pod/_imagePullSecrets.tpl +++ b/library/common/1.0.0/templates/lib/pod/_imagePullSecrets.tpl @@ -9,7 +9,6 @@ objectData: The object data to be used to render the Pod. {{- $objectData := .objectData -}} {{- $imgPullSecrets := list -}} - {{- $podSelected := true -}} {{- range $name, $imgPull := $rootCtx.Values.imagePullSecrets -}} {{- $pullName := (printf "%s-%s" (include "ix.v1.common.lib.chart.names.fullname" $rootCtx) $name) -}} @@ -34,6 +33,6 @@ objectData: The object data to be used to render the Pod. {{- end -}} {{- range $imgPullSecrets }} -- {{ . }} +- name: {{ . }} {{- end -}} {{- end -}} diff --git a/library/common/1.0.0/templates/lib/pod/_serviceAccountName.tpl b/library/common/1.0.0/templates/lib/pod/_serviceAccountName.tpl new file mode 100644 index 0000000000..0dae50b251 --- /dev/null +++ b/library/common/1.0.0/templates/lib/pod/_serviceAccountName.tpl @@ -0,0 +1,44 @@ +{{/* Returns Service Account Name */}} +{{/* Call this template: +{{ include "ix.v1.common.lib.pod.serviceAccountName" (dict "rootCtx" $ "objectData" $objectData) }} +rootCtx: The root context of the template. It is used to access the global context. +objectData: The object data to be used to render the Pod. +*/}} +{{- define "ix.v1.common.lib.pod.serviceAccountName" -}} + {{- $rootCtx := .rootCtx -}} + {{- $objectData := .objectData -}} + + {{- $saName := "default" -}} + {{- $saNameCount := 0 -}} + + {{- range $name, $serviceAccount := $rootCtx.Values.serviceAccounts -}} + {{- $name = (printf "%s-%s" (include "ix.v1.common.lib.chart.names.fullname" $rootCtx) $name) -}} + + {{- if $serviceAccount.enabled -}} + {{/* If targetSelectAll is true */}} + {{- if $serviceAccount.targetSelectAll -}} + {{- $saName = $name -}} + {{- $saNameCount = add1 $saNameCount -}} + + {{/* Else if targetSelector is a list */}} + {{- else if (kindIs "slice" $serviceAccount.targetSelector) -}} + {{- if (mustHas $objectData.shortName $serviceAccount.targetSelector) -}} + {{- $saName = $name -}} + {{- $saNameCount = add1 $saNameCount -}} + {{- end -}} + + {{/* If not targetSelectAll or targetSelector, but is the primary pod */}} + {{- else if $objectData.primary -}} + {{- $saName = $name -}} + {{- $saNameCount = add1 $saNameCount -}} + {{- end -}} + + {{- end -}} + {{- end -}} + + {{- if gt $saNameCount 1 -}} + {{- fail (printf "Expected at most 1 ServiceAccount to be assigned on a pod [%s]. But [%v] were assigned" $objectData.shortName $saNameCount) -}} + {{- end -}} + + {{- $saName -}} +{{- end -}} diff --git a/library/common/1.0.0/templates/loader/_apply.tpl b/library/common/1.0.0/templates/loader/_apply.tpl index 26260bf37c..933ae95be8 100644 --- a/library/common/1.0.0/templates/loader/_apply.tpl +++ b/library/common/1.0.0/templates/loader/_apply.tpl @@ -10,6 +10,9 @@ {{/* Render Image Pull Secrets(s) */}} {{- include "ix.v1.common.spawner.imagePullSecrets" . | nindent 0 -}} + {{/* Render Service Accounts(s) */}} + {{- include "ix.v1.common.spawner.serviceAccounts" . | nindent 0 -}} + {{/* Render Controller(s) */}} {{- include "ix.v1.common.spawner.controllers" . | nindent 0 -}} diff --git a/library/common/1.0.0/templates/spawner/_configmap.tpl b/library/common/1.0.0/templates/spawner/_configmap.tpl index bf79e6e25d..bb4693e4e9 100644 --- a/library/common/1.0.0/templates/spawner/_configmap.tpl +++ b/library/common/1.0.0/templates/spawner/_configmap.tpl @@ -20,7 +20,7 @@ {{/* Set the name of the configmap */}} {{- $_ := set $objectData "name" $objectName -}} {{/* Call class to create the object */}} - {{- include "ix.v1.common.class.configmap" (dict "objectData" $objectData "rootCtx" $) -}} + {{- include "ix.v1.common.class.configmap" (dict "rootCtx" $ "objectData" $objectData) -}} {{- end -}} diff --git a/library/common/1.0.0/templates/spawner/_controller.tpl b/library/common/1.0.0/templates/spawner/_controller.tpl index 36e9c8b359..772b36efa0 100644 --- a/library/common/1.0.0/templates/spawner/_controller.tpl +++ b/library/common/1.0.0/templates/spawner/_controller.tpl @@ -33,15 +33,15 @@ {{/* Call class to create the object */}} {{- if eq $objectData.type "Deployment" -}} - {{- include "ix.v1.common.class.deployment" (dict "objectData" $objectData "rootCtx" $) -}} + {{- include "ix.v1.common.class.deployment" (dict "rootCtx" $ "objectData" $objectData) -}} {{- else if eq $objectData.type "StatefulSet" -}} - {{- include "ix.v1.common.class.statefulset" (dict "objectData" $objectData "rootCtx" $) -}} + {{- include "ix.v1.common.class.statefulset" (dict "rootCtx" $ "objectData" $objectData) -}} {{- else if eq $objectData.type "DaemonSet" -}} - {{- include "ix.v1.common.class.daemonset" (dict "objectData" $objectData "rootCtx" $) -}} + {{- include "ix.v1.common.class.daemonset" (dict "rootCtx" $ "objectData" $objectData) -}} {{- else if eq $objectData.type "Job" -}} - {{- include "ix.v1.common.class.job" (dict "objectData" $objectData "rootCtx" $) -}} + {{- include "ix.v1.common.class.job" (dict "rootCtx" $ "objectData" $objectData) -}} {{- else if eq $objectData.type "CronJob" -}} - {{- include "ix.v1.common.class.cronjob" (dict "objectData" $objectData "rootCtx" $) -}} + {{- include "ix.v1.common.class.cronjob" (dict "rootCtx" $ "objectData" $objectData) -}} {{- end -}} {{- end -}} diff --git a/library/common/1.0.0/templates/spawner/_imagePullSecret.tpl b/library/common/1.0.0/templates/spawner/_imagePullSecret.tpl index aeafb4e70a..97fb830355 100644 --- a/library/common/1.0.0/templates/spawner/_imagePullSecret.tpl +++ b/library/common/1.0.0/templates/spawner/_imagePullSecret.tpl @@ -1,4 +1,4 @@ -{{/* Configmap Spawwner */}} +{{/* Image Pull Secrets Spawner */}} {{/* Call this template: {{ include "ix.v1.common.spawner.imagePullSecrets" $ -}} */}} @@ -13,11 +13,11 @@ {{- $objectData := (mustDeepCopy $imgPullSecret) -}} {{- $objectName := (printf "%s-%s" (include "ix.v1.common.lib.chart.names.fullname" $) $name) -}} + {{/* Perform validations */}} {{- include "ix.v1.common.lib.chart.names.validation" (dict "name" $objectName) -}} {{- include "ix.v1.common.lib.imagePullSecret.validation" (dict "objectData" $objectData) -}} - {{- $data := include "ix.v1.common.lib.imagePullSecret.createData" (dict "objectData" $objectData "rootCtx" $) -}} - + {{- $data := include "ix.v1.common.lib.imagePullSecret.createData" (dict "rootCtx" $ "objectData" $objectData) -}} {{/* Update the data */}} {{- $_ := set $objectData "data" $data -}} @@ -29,7 +29,7 @@ {{- $_ := set $objectData "name" $objectName -}} {{/* Call class to create the object */}} - {{- include "ix.v1.common.class.secret" (dict "objectData" $objectData "rootCtx" $) -}} + {{- include "ix.v1.common.class.secret" (dict "rootCtx" $ "objectData" $objectData) -}} {{- end -}} diff --git a/library/common/1.0.0/templates/spawner/_secret.tpl b/library/common/1.0.0/templates/spawner/_secret.tpl index 888f41414d..01691b4765 100644 --- a/library/common/1.0.0/templates/spawner/_secret.tpl +++ b/library/common/1.0.0/templates/spawner/_secret.tpl @@ -20,7 +20,7 @@ {{/* Set the name of the secret */}} {{- $_ := set $objectData "name" $objectName -}} {{/* Call class to create the object */}} - {{- include "ix.v1.common.class.secret" (dict "objectData" $objectData "rootCtx" $) -}} + {{- include "ix.v1.common.class.secret" (dict "rootCtx" $ "objectData" $objectData) -}} {{- end -}} diff --git a/library/common/1.0.0/templates/spawner/_serviceAccount.tpl b/library/common/1.0.0/templates/spawner/_serviceAccount.tpl new file mode 100644 index 0000000000..2a2f90f902 --- /dev/null +++ b/library/common/1.0.0/templates/spawner/_serviceAccount.tpl @@ -0,0 +1,30 @@ +{{/* Service Account Spawner */}} +{{/* Call this template: +{{ include "ix.v1.common.spawner.serviceAccounts" $ -}} +*/}} + +{{- define "ix.v1.common.spawner.serviceAccounts" -}} + + {{- range $name, $serviceAccount := .Values.serviceAccounts -}} + + {{- if $serviceAccount.enabled -}} + + {{/* Create a copy of the configmap */}} + {{- $objectData := (mustDeepCopy $serviceAccount) -}} + + {{- $objectName := (printf "%s-%s" (include "ix.v1.common.lib.chart.names.fullname" $) $name) -}} + + {{/* Perform validations */}} + {{- include "ix.v1.common.lib.chart.names.validation" (dict "name" $objectName) -}} + + {{/* Set the name of the service account */}} + {{- $_ := set $objectData "name" $objectName -}} + + {{/* Call class to create the object */}} + {{- include "ix.v1.common.class.serviceAccount" (dict "rootCtx" $ "objectData" $objectData) -}} + + {{- end -}} + + {{- end -}} + +{{- end -}} diff --git a/library/common/1.0.0/values.yaml b/library/common/1.0.0/values.yaml index b1cba6ab35..274a15fe01 100644 --- a/library/common/1.0.0/values.yaml +++ b/library/common/1.0.0/values.yaml @@ -5,7 +5,7 @@ global: # -- Set additional global annotations annotations: {} # -- Scale Storage Class - scaleZFSStorageClass: '{{ printf "ix-storage-class-%v" .Release.Name}}' + scaleZFSStorageClass: '{{ printf "ix-storage-class-%v" .Release.Name }}' # TODO: fallbackDefaults: @@ -36,7 +36,7 @@ image: pullPolicy: IfNotPresent # -- Service Account: -serviceAccount: +serviceAccounts: sa-name: # -- Enables the service account enabled: false @@ -44,8 +44,7 @@ serviceAccount: labels: {} # -- Service account annotations annotations: {} - autoMountSAToken: true - # targetSelector: all + targetSelectAll: false targetSelector: - pod-name @@ -122,6 +121,7 @@ podOptions: tolerations: [] schedulerName: "" priorityClassName: "" + automountServiceAccountToken: false terminationGracePeriodSeconds: 120 # TODO: Add affinity # TODO: Add topologySpreadConstraints