blob: be7fc5fdcc99fdadef48c5621cb81d503d8039f4 [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
7# SPDX-License-Identifier: LicenseRef-ONF-Member-Only-1.0
8
9*/ -}}
10
11{{/*
12Renders a set of standardised labels
13*/}}
14{{- define "omec-control-plane.metadata_labels" -}}
15{{- $application := index . 0 -}}
16{{- $context := index . 1 -}}
17release: {{ $context.Release.Name }}
18app: {{ $application }}
19{{- end -}}
20
21{{/*
22Render the given template.
23*/}}
24{{- define "omec-control-plane.template" -}}
25{{- $name := index . 0 -}}
26{{- $context := index . 1 -}}
27{{- $last := base $context.Template.Name }}
28{{- $wtf := $context.Template.Name | replace $last $name -}}
29{{ include $wtf $context }}
30{{- end -}}
31
32{{/*
33Return domain name for Diameter identity, realm, and hostname for a given application.
34*/}}
35{{- define "omec-control-plane.diameter_endpoint" -}}
36{{- $service := index . 0 -}}
37{{- $type := index . 1 -}}
38{{- $context := index . 2 -}}
39{{- if eq $type "identity" -}}
40{{- printf "%s.%s.svc.%s" $service $context.Release.Namespace $context.Values.config.clusterDomain -}}
41{{- else if eq $type "realm" -}}
42{{- printf "%s.svc.%s" $context.Release.Namespace $context.Values.config.clusterDomain -}}
43{{- else if eq $type "host" -}}
44{{- printf "%s" $service -}}
45{{- end -}}
46{{- end -}}
47
48{{/*
49Render ServiceAccount, Role, and RoleBinding required for kubernetes-entrypoint.
50*/}}
51{{- define "omec-control-plane.service_account" -}}
52{{- $context := index . 1 -}}
53{{- $saName := index . 0 -}}
54{{- $saNamespace := $context.Release.Namespace }}
55---
56apiVersion: v1
57kind: ServiceAccount
58metadata:
59 name: {{ $saName }}
60 namespace: {{ $saNamespace }}
61 labels:
62{{ tuple $saName $context | include "omec-control-plane.metadata_labels" | indent 4 }}
63---
64{{- if semverCompare ">=1.16-0" $context.Capabilities.KubeVersion.GitVersion }}
65apiVersion: rbac.authorization.k8s.io/v1
66{{- else }}
67apiVersion: rbac.authorization.k8s.io/v1beta1
68{{- end }}
69kind: RoleBinding
70metadata:
71 name: {{ $saName }}
72 namespace: {{ $saNamespace }}
73 labels:
74{{ tuple $saName $context | include "omec-control-plane.metadata_labels" | indent 4 }}
75roleRef:
76 apiGroup: rbac.authorization.k8s.io
77 kind: Role
78 name: {{ $saName }}
79subjects:
80 - kind: ServiceAccount
81 name: {{ $saName }}
82 namespace: {{ $saNamespace }}
83---
84{{- if semverCompare ">=1.16-0" $context.Capabilities.KubeVersion.GitVersion }}
85apiVersion: rbac.authorization.k8s.io/v1
86{{- else }}
87apiVersion: rbac.authorization.k8s.io/v1beta1
88{{- end }}
89kind: Role
90metadata:
91 name: {{ $saName }}
92 namespace: {{ $saNamespace }}
93 labels:
94{{ tuple $saName $context | include "omec-control-plane.metadata_labels" | indent 4 }}
95rules:
96 - apiGroups:
97 - ""
98 - extensions
99 - batch
100 - apps
101 verbs:
102 - get
103 - list
104 - patch
105 resources:
106 - statefulsets
107 - daemonsets
108 - jobs
109 - pods
110 - services
111 - endpoints
112 - configmaps
113{{- end -}}
114
115{{/*
116Render init container for coredump.
117*/}}
118{{- define "omec-control-plane.coredump_init" -}}
119{{- $pod := index . 0 -}}
120{{- $context := index . 1 -}}
121- name: {{ $pod }}-coredump-init
122 image: {{ $context.Values.images.tags.init | quote }}
123 imagePullPolicy: {{ $context.Values.images.pullPolicy }}
124 securityContext:
125 privileged: true
126 runAsUser: 0
127 command: ["sh", "-xc"]
128 args:
129 - echo '/tmp/coredump/core.%h.%e.%t' > /mnt/host-rootfs/proc/sys/kernel/core_pattern
130 volumeMounts:
131 - name: host-rootfs
132 mountPath: /mnt/host-rootfs
133{{- end -}}