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