blob: f259272367bce8b55a3813e2c8fbf4b22aac7493 [file] [log] [blame]
badhri854c028b32021-11-03 18:24:05 -05001{{- /*
2
3# Copyright 2018 Intel Corporation
4# Copyright 2018-present Open Networking Foundation
5#
6# SPDX-License-Identifier: Apache-2.0
badhri854c028b32021-11-03 18:24:05 -05007
8*/ -}}
9
10{{/*
11Renders a set of standardised labels
12*/}}
13{{- define "omec-control-plane.metadata_labels" -}}
14{{- $application := index . 0 -}}
15{{- $context := index . 1 -}}
16release: {{ $context.Release.Name }}
17app: {{ $application }}
18{{- end -}}
19
20{{/*
21Render the given template.
22*/}}
23{{- define "omec-control-plane.template" -}}
24{{- $name := index . 0 -}}
25{{- $context := index . 1 -}}
26{{- $last := base $context.Template.Name }}
27{{- $wtf := $context.Template.Name | replace $last $name -}}
28{{ include $wtf $context }}
29{{- end -}}
30
31{{/*
32Return domain name for Diameter identity, realm, and hostname for a given application.
33*/}}
34{{- define "omec-control-plane.diameter_endpoint" -}}
35{{- $service := index . 0 -}}
36{{- $type := index . 1 -}}
37{{- $context := index . 2 -}}
38{{- if eq $type "identity" -}}
39{{- printf "%s.%s.svc.%s" $service $context.Release.Namespace $context.Values.config.clusterDomain -}}
40{{- else if eq $type "realm" -}}
41{{- printf "%s.svc.%s" $context.Release.Namespace $context.Values.config.clusterDomain -}}
42{{- else if eq $type "host" -}}
43{{- printf "%s" $service -}}
44{{- end -}}
45{{- end -}}
46
47{{/*
48Render ServiceAccount, Role, and RoleBinding required for kubernetes-entrypoint.
49*/}}
50{{- define "omec-control-plane.service_account" -}}
51{{- $context := index . 1 -}}
52{{- $saName := index . 0 -}}
53{{- $saNamespace := $context.Release.Namespace }}
54---
55apiVersion: v1
56kind: ServiceAccount
57metadata:
58 name: {{ $saName }}
59 namespace: {{ $saNamespace }}
60 labels:
61{{ tuple $saName $context | include "omec-control-plane.metadata_labels" | indent 4 }}
62---
63{{- if semverCompare ">=1.16-0" $context.Capabilities.KubeVersion.GitVersion }}
64apiVersion: rbac.authorization.k8s.io/v1
65{{- else }}
66apiVersion: rbac.authorization.k8s.io/v1beta1
67{{- end }}
68kind: RoleBinding
69metadata:
70 name: {{ $saName }}
71 namespace: {{ $saNamespace }}
72 labels:
73{{ tuple $saName $context | include "omec-control-plane.metadata_labels" | indent 4 }}
74roleRef:
75 apiGroup: rbac.authorization.k8s.io
76 kind: Role
77 name: {{ $saName }}
78subjects:
79 - kind: ServiceAccount
80 name: {{ $saName }}
81 namespace: {{ $saNamespace }}
82---
83{{- if semverCompare ">=1.16-0" $context.Capabilities.KubeVersion.GitVersion }}
84apiVersion: rbac.authorization.k8s.io/v1
85{{- else }}
86apiVersion: rbac.authorization.k8s.io/v1beta1
87{{- end }}
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: ["sh", "-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 -}}