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