blob: 0833603a83caaf2db2a2f111b3ba416546c51ef0 [file] [log] [blame]
Jeremy Ronquillo223db002020-06-05 10:28:22 -07001{{- /*
Jeremy Ronquilloec2d3e42020-06-05 11:33:39 -07002
Jeremy Ronquillo223db002020-06-05 10:28:22 -07003# Copyright 2018 Intel Corporation
Jeremy Ronquilloec2d3e42020-06-05 11:33:39 -07004# Copyright 2018-present Open Networking Foundation
Jeremy Ronquillo223db002020-06-05 10:28:22 -07005#
Jeremy Ronquilloec2d3e42020-06-05 11:33:39 -07006# SPDX-License-Identifier: Apache-2.0
Jeremy Ronquillo6046ce32020-06-18 11:06:29 -07007# SPDX-License-Identifier: LicenseRef-ONF-Member-Only-1.0
Jeremy Ronquilloec2d3e42020-06-05 11:33:39 -07008
Jeremy Ronquillo223db002020-06-05 10:28:22 -07009*/ -}}
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---
64apiVersion: rbac.authorization.k8s.io/v1beta1
65kind: RoleBinding
66metadata:
67 name: {{ $saName }}
68 namespace: {{ $saNamespace }}
69 labels:
70{{ tuple $saName $context | include "omec-control-plane.metadata_labels" | indent 4 }}
71roleRef:
72 apiGroup: rbac.authorization.k8s.io
73 kind: Role
74 name: {{ $saName }}
75subjects:
76 - kind: ServiceAccount
77 name: {{ $saName }}
78 namespace: {{ $saNamespace }}
79---
80apiVersion: rbac.authorization.k8s.io/v1beta1
81kind: Role
82metadata:
83 name: {{ $saName }}
84 namespace: {{ $saNamespace }}
85 labels:
86{{ tuple $saName $context | include "omec-control-plane.metadata_labels" | indent 4 }}
87rules:
88 - apiGroups:
89 - ""
90 - extensions
91 - batch
92 - apps
93 verbs:
94 - get
95 - list
96 - patch
97 resources:
98 - statefulsets
99 - daemonsets
100 - jobs
101 - pods
102 - services
103 - endpoints
104 - configmaps
105{{- end -}}
106
107{{/*
108Render init container for coredump.
109*/}}
110{{- define "omec-control-plane.coredump_init" -}}
111{{- $pod := index . 0 -}}
112{{- $context := index . 1 -}}
113- name: {{ $pod }}-coredump-init
114 image: {{ $context.Values.images.tags.init | quote }}
115 imagePullPolicy: {{ $context.Values.images.pullPolicy }}
116 securityContext:
117 privileged: true
118 runAsUser: 0
119 command: ["bash", "-xc"]
120 args:
121 - echo '/tmp/coredump/core.%h.%e.%t' > /mnt/host-rootfs/proc/sys/kernel/core_pattern
122 volumeMounts:
123 - name: host-rootfs
124 mountPath: /mnt/host-rootfs
125{{- end -}}