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