Wei-Yu Chen | 0f12b9c | 2019-04-18 11:12:59 -0700 | [diff] [blame] | 1 | {{- /* |
| 2 | # Copyright 2018-present Open Networking Foundation |
| 3 | # Copyright 2018 Intel Corporation |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | */ -}} |
| 17 | |
Wei-Yu Chen | 0f12b9c | 2019-04-18 11:12:59 -0700 | [diff] [blame] | 18 | {{/* |
Hyunsun Moon | 7a007bb | 2019-08-19 16:41:36 -0600 | [diff] [blame] | 19 | Renders a set of standardised labels |
Wei-Yu Chen | 0f12b9c | 2019-04-18 11:12:59 -0700 | [diff] [blame] | 20 | */}} |
Hyunsun Moon | 7a007bb | 2019-08-19 16:41:36 -0600 | [diff] [blame] | 21 | {{- define "omec-control-plane.metadata_labels" -}} |
Hyunsun Moon | 06f9855 | 2019-08-15 13:44:47 -0600 | [diff] [blame] | 22 | {{- $application := index . 0 -}} |
| 23 | {{- $context := index . 1 -}} |
| 24 | release: {{ $context.Release.Name }} |
| 25 | app: {{ $application }} |
Wei-Yu Chen | 0f12b9c | 2019-04-18 11:12:59 -0700 | [diff] [blame] | 26 | {{- end -}} |
Hyunsun Moon | a24d3f9 | 2019-06-19 03:04:58 -0500 | [diff] [blame] | 27 | |
| 28 | {{/* |
| 29 | Render the given template. |
| 30 | */}} |
Hyunsun Moon | 7a007bb | 2019-08-19 16:41:36 -0600 | [diff] [blame] | 31 | {{- define "omec-control-plane.template" -}} |
Hyunsun Moon | a24d3f9 | 2019-06-19 03:04:58 -0500 | [diff] [blame] | 32 | {{- $name := index . 0 -}} |
| 33 | {{- $context := index . 1 -}} |
| 34 | {{- $last := base $context.Template.Name }} |
| 35 | {{- $wtf := $context.Template.Name | replace $last $name -}} |
| 36 | {{ include $wtf $context }} |
| 37 | {{- end -}} |
Hyunsun Moon | 636e17d | 2019-07-03 12:52:15 -0500 | [diff] [blame] | 38 | |
| 39 | {{/* |
| 40 | Return identity, realm, and hostname of the first pod of the given statefulset. |
| 41 | */}} |
Hyunsun Moon | 7a007bb | 2019-08-19 16:41:36 -0600 | [diff] [blame] | 42 | {{- define "omec-control-plane.endpoint_lookup" -}} |
Hyunsun Moon | 636e17d | 2019-07-03 12:52:15 -0500 | [diff] [blame] | 43 | {{- $service := index . 0 -}} |
| 44 | {{- $type := index . 1 -}} |
| 45 | {{- $context := index . 2 -}} |
Hyunsun Moon | 636e17d | 2019-07-03 12:52:15 -0500 | [diff] [blame] | 46 | {{- if eq $type "identity" -}} |
Hyunsun Moon | 06f9855 | 2019-08-15 13:44:47 -0600 | [diff] [blame] | 47 | {{- printf "%s-0.%s.%s.svc.%s" $service $service $context.Release.Namespace "cluster.local" -}} |
Hyunsun Moon | 636e17d | 2019-07-03 12:52:15 -0500 | [diff] [blame] | 48 | {{- else if eq $type "realm" -}} |
Hyunsun Moon | 06f9855 | 2019-08-15 13:44:47 -0600 | [diff] [blame] | 49 | {{- printf "%s.%s.svc.%s" $service $context.Release.Namespace "cluster.local" -}} |
Hyunsun Moon | 636e17d | 2019-07-03 12:52:15 -0500 | [diff] [blame] | 50 | {{- else if eq $type "host" -}} |
Hyunsun Moon | 06f9855 | 2019-08-15 13:44:47 -0600 | [diff] [blame] | 51 | {{- printf "%s-0" $service -}} |
Hyunsun Moon | 636e17d | 2019-07-03 12:52:15 -0500 | [diff] [blame] | 52 | {{- end -}} |
| 53 | {{- end -}} |
Hyunsun Moon | 16d7092 | 2019-08-25 04:57:25 -0500 | [diff] [blame] | 54 | |
| 55 | {{/* |
| 56 | Render ServiceAccount, Role, and RoleBinding required for kubernetes-entrypoint. |
| 57 | */}} |
| 58 | {{- define "omec-control-plane.service_account" -}} |
| 59 | {{- $context := index . 1 -}} |
| 60 | {{- $saName := index . 0 -}} |
| 61 | {{- $saNamespace := $context.Release.Namespace }} |
| 62 | --- |
| 63 | apiVersion: v1 |
| 64 | kind: ServiceAccount |
| 65 | metadata: |
| 66 | name: {{ $saName }} |
| 67 | namespace: {{ $saNamespace }} |
| 68 | labels: |
| 69 | {{ tuple $saName $context | include "omec-control-plane.metadata_labels" | indent 4 }} |
| 70 | --- |
| 71 | apiVersion: rbac.authorization.k8s.io/v1beta1 |
| 72 | kind: RoleBinding |
| 73 | metadata: |
| 74 | name: {{ $saName }} |
| 75 | namespace: {{ $saNamespace }} |
| 76 | labels: |
| 77 | {{ tuple $saName $context | include "omec-control-plane.metadata_labels" | indent 4 }} |
| 78 | roleRef: |
| 79 | apiGroup: rbac.authorization.k8s.io |
| 80 | kind: Role |
| 81 | name: {{ $saName }} |
| 82 | subjects: |
| 83 | - kind: ServiceAccount |
| 84 | name: {{ $saName }} |
| 85 | namespace: {{ $saNamespace }} |
| 86 | --- |
| 87 | apiVersion: rbac.authorization.k8s.io/v1beta1 |
| 88 | kind: Role |
| 89 | metadata: |
| 90 | name: {{ $saName }} |
| 91 | namespace: {{ $saNamespace }} |
| 92 | labels: |
| 93 | {{ tuple $saName $context | include "omec-control-plane.metadata_labels" | indent 4 }} |
| 94 | rules: |
| 95 | - apiGroups: |
| 96 | - "" |
| 97 | - extensions |
| 98 | - batch |
| 99 | - apps |
| 100 | verbs: |
| 101 | - get |
| 102 | - list |
| 103 | - patch |
| 104 | resources: |
| 105 | - statefulsets |
| 106 | - daemonsets |
| 107 | - jobs |
| 108 | - pods |
| 109 | - services |
| 110 | - endpoints |
| 111 | - configmaps |
| 112 | {{- end -}} |