blob: bb9854788bd27bce5e736e630eb0748a376e73c3 [file] [log] [blame]
Jeremy Ronquillo223db002020-06-05 10:28:22 -07001{{- /*
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
18{{/*
19Renders a set of standardised labels
20*/}}
21{{- define "omec-control-plane.metadata_labels" -}}
22{{- $application := index . 0 -}}
23{{- $context := index . 1 -}}
24release: {{ $context.Release.Name }}
25app: {{ $application }}
26{{- end -}}
27
28{{/*
29Render the given template.
30*/}}
31{{- define "omec-control-plane.template" -}}
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 -}}
38
39{{/*
40Return domain name for Diameter identity, realm, and hostname for a given application.
41*/}}
42{{- define "omec-control-plane.diameter_endpoint" -}}
43{{- $service := index . 0 -}}
44{{- $type := index . 1 -}}
45{{- $context := index . 2 -}}
46{{- if eq $type "identity" -}}
47{{- printf "%s.%s.svc.%s" $service $context.Release.Namespace $context.Values.config.clusterDomain -}}
48{{- else if eq $type "realm" -}}
49{{- printf "%s.svc.%s" $context.Release.Namespace $context.Values.config.clusterDomain -}}
50{{- else if eq $type "host" -}}
51{{- printf "%s" $service -}}
52{{- end -}}
53{{- end -}}
54
55{{/*
56Render 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---
63apiVersion: v1
64kind: ServiceAccount
65metadata:
66 name: {{ $saName }}
67 namespace: {{ $saNamespace }}
68 labels:
69{{ tuple $saName $context | include "omec-control-plane.metadata_labels" | indent 4 }}
70---
71apiVersion: rbac.authorization.k8s.io/v1beta1
72kind: RoleBinding
73metadata:
74 name: {{ $saName }}
75 namespace: {{ $saNamespace }}
76 labels:
77{{ tuple $saName $context | include "omec-control-plane.metadata_labels" | indent 4 }}
78roleRef:
79 apiGroup: rbac.authorization.k8s.io
80 kind: Role
81 name: {{ $saName }}
82subjects:
83 - kind: ServiceAccount
84 name: {{ $saName }}
85 namespace: {{ $saNamespace }}
86---
87apiVersion: rbac.authorization.k8s.io/v1beta1
88kind: Role
89metadata:
90 name: {{ $saName }}
91 namespace: {{ $saNamespace }}
92 labels:
93{{ tuple $saName $context | include "omec-control-plane.metadata_labels" | indent 4 }}
94rules:
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 -}}
113
114{{/*
115Render init container for coredump.
116*/}}
117{{- define "omec-control-plane.coredump_init" -}}
118{{- $pod := index . 0 -}}
119{{- $context := index . 1 -}}
120- name: {{ $pod }}-coredump-init
121 image: {{ $context.Values.images.tags.init | quote }}
122 imagePullPolicy: {{ $context.Values.images.pullPolicy }}
123 securityContext:
124 privileged: true
125 runAsUser: 0
126 command: ["bash", "-xc"]
127 args:
128 - echo '/tmp/coredump/core.%h.%e.%t' > /mnt/host-rootfs/proc/sys/kernel/core_pattern
129 volumeMounts:
130 - name: host-rootfs
131 mountPath: /mnt/host-rootfs
132{{- end -}}