Woojoong Kim | d3c132c | 2020-08-26 14:46:47 -0700 | [diff] [blame] | 1 | {{- /* |
| 2 | |
| 3 | # Copyright 2020-present Open Networking Foundation |
| 4 | # |
| 5 | # SPDX-License-Identifier: Apache-2.0 |
| 6 | # SPDX-License-Identifier: LicenseRef-ONF-Member-Only-1.0 |
| 7 | |
| 8 | */ -}} |
| 9 | |
| 10 | {{/* |
| 11 | Renders a set of standardised labels |
| 12 | */}} |
| 13 | {{- define "thingsboard-iot-platform.metadata_labels" -}} |
| 14 | {{- $application := index . 0 -}} |
| 15 | {{- $context := index . 1 -}} |
| 16 | release: {{ $context.Release.Name }} |
| 17 | app: {{ $application }} |
| 18 | {{- end -}} |
| 19 | |
| 20 | {{/* |
| 21 | Render the given template. |
| 22 | */}} |
| 23 | {{- define "thingsboard-iot-platform.template" -}} |
| 24 | {{- $name := index . 0 -}} |
| 25 | {{- $context := index . 1 -}} |
| 26 | {{- $last := base $context.Template.Name }} |
| 27 | {{- $wtf := $context.Template.Name | replace $last $name -}} |
| 28 | {{ include $wtf $context }} |
| 29 | {{- end -}} |
| 30 | |
| 31 | {{/* |
| 32 | Render ServiceAccount, Role, and RoleBinding required for kubernetes-entrypoint. |
| 33 | */}} |
| 34 | {{- define "thingsboard-iot-platform.service_account" -}} |
| 35 | {{- $context := index . 1 -}} |
| 36 | {{- $saName := index . 0 -}} |
| 37 | {{- $saNamespace := $context.Release.Namespace }} |
| 38 | --- |
| 39 | apiVersion: v1 |
| 40 | kind: ServiceAccount |
| 41 | metadata: |
| 42 | name: {{ $saName }} |
| 43 | namespace: {{ $saNamespace }} |
| 44 | labels: |
| 45 | {{ tuple $saName $context | include "thingsboard-iot-platform.metadata_labels" | indent 4 }} |
| 46 | --- |
| 47 | apiVersion: rbac.authorization.k8s.io/v1beta1 |
| 48 | kind: RoleBinding |
| 49 | metadata: |
| 50 | name: {{ $saName }} |
| 51 | namespace: {{ $saNamespace }} |
| 52 | labels: |
| 53 | {{ tuple $saName $context | include "thingsboard-iot-platform.metadata_labels" | indent 4 }} |
| 54 | roleRef: |
| 55 | apiGroup: rbac.authorization.k8s.io |
| 56 | kind: Role |
| 57 | name: {{ $saName }} |
| 58 | subjects: |
| 59 | - kind: ServiceAccount |
| 60 | name: {{ $saName }} |
| 61 | namespace: {{ $saNamespace }} |
| 62 | --- |
| 63 | apiVersion: rbac.authorization.k8s.io/v1beta1 |
| 64 | kind: Role |
| 65 | metadata: |
| 66 | name: {{ $saName }} |
| 67 | namespace: {{ $saNamespace }} |
| 68 | labels: |
| 69 | {{ tuple $saName $context | include "thingsboard-iot-platform.metadata_labels" | indent 4 }} |
| 70 | rules: |
| 71 | - apiGroups: |
| 72 | - "" |
| 73 | - extensions |
| 74 | - batch |
| 75 | - apps |
| 76 | verbs: |
| 77 | - get |
| 78 | - list |
| 79 | - patch |
| 80 | resources: |
| 81 | - statefulsets |
| 82 | - daemonsets |
| 83 | - jobs |
| 84 | - pods |
| 85 | - services |
| 86 | - endpoints |
| 87 | - configmaps |
| 88 | {{- end -}} |