blob: 0e6248976223f4f1ebe4006f01991aa49b5df556 [file] [log] [blame]
Hyunsun Mooned19c092019-07-10 15:24:45 -06001{{- /*
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{{/*
18Return endpoint of the given application.
19*/}}
20{{- define "oaisim.endpoint_lookup" -}}
21{{- $app := index . 0 -}}
22{{- $type := index . 1 -}}
23{{- $context := index . 2 -}}
Hyunsun Moon43eadcc2019-08-20 16:16:08 -060024{{- $appContext := index $context.Values.config $app -}}
Hyunsun Mooned19c092019-07-10 15:24:45 -060025{{- $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{{/*
34Render 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{{/*
45Return 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 Moon10152302019-10-24 20:23:35 -050052
53{{/*
54Renders a set of standardised labels
55*/}}
56{{- define "oaisim.metadata_labels" -}}
57{{- $application := index . 0 -}}
58{{- $context := index . 1 -}}
59release: {{ $context.Release.Name }}
60app: {{ $application }}
61{{- end -}}
62
63{{/*
64Render 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---
71apiVersion: v1
72kind: ServiceAccount
73metadata:
74 name: {{ $saName }}
75 namespace: {{ $saNamespace }}
76 labels:
77{{ tuple $saName $context | include "oaisim.metadata_labels" | indent 4 }}
78---
Matteo Scandolo5628d4b2021-01-11 11:46:12 -080079apiVersion: rbac.authorization.k8s.io/v1
Hyunsun Moon10152302019-10-24 20:23:35 -050080kind: RoleBinding
81metadata:
82 name: {{ $saName }}
83 namespace: {{ $saNamespace }}
84 labels:
85{{ tuple $saName $context | include "oaisim.metadata_labels" | indent 4 }}
86roleRef:
87 apiGroup: rbac.authorization.k8s.io
88 kind: Role
89 name: {{ $saName }}
90subjects:
91 - kind: ServiceAccount
92 name: {{ $saName }}
93 namespace: {{ $saNamespace }}
94---
Matteo Scandolo5628d4b2021-01-11 11:46:12 -080095apiVersion: rbac.authorization.k8s.io/v1
Hyunsun Moon10152302019-10-24 20:23:35 -050096kind: Role
97metadata:
98 name: {{ $saName }}
99 namespace: {{ $saNamespace }}
100 labels:
101{{ tuple $saName $context | include "oaisim.metadata_labels" | indent 4 }}
102rules:
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 -}}