From af0e3b27cbfd7795d9c76d74dee71aede88a4330 Mon Sep 17 00:00:00 2001
From: Michal Rostecki <mrostecki@opensuse.org>
Date: Mon, 24 Feb 2020 19:57:31 +0100
Subject: [PATCH 04/10] helm: Allow variables for compatibility with openSUSE
 images

tl;dr: Few minor variables, which have no impact for users of Cilium
using images from Dockerhub, but are necessary for (open)SUSE to consume
the upstream helm charts without maintaining forks or crazy sed magic.

This change introduces several new values in helm charts which make it
possible to use them with images from registry.opensuse.org:

- cniInstallScript - path or command of the script which installs CNI
  plugin (default: /cni-install.sh; openSUSE: cilium-cni-install)
- cniUninstallScript - path or command of the script which uninstalls
  CNI plugin (default: /cni-uninstall.sh; openSUSE:
  cilium-cni-uninstall)
- initScript - path or command of the init container script
  (default: /init-container.sh; openSUSE: cilium-init)

Reason behind those changes is that openSUSE images use only RPM
packages as the source of any files. rpmlint has strict rules where
files can be installed. It's against rpmlintrc rules and openSUSE
policies to install scripts in the / directory, they have to be
installed in /usr/bin. Having ".sh" extensions in names of installed
scripts is discouraged.

After this commit, generating YAML manifest using openSUSE images can be
done with:

  helm template cilium \
      --namespace=kube-system \
      --set global.containerRuntime.integration=crio \
      --set global.registry=registry.opensuse.org/devel/kubic/containers/container/kubic \
      --set global.tag=1.6.5 \
      --set agent.cniInstallScript=cilium-cni-install \
      --set agent.cniUninstallScript=cilium-cni-uninstall \
      --set agent.initScript=cilium-init \
      --set operator.image=cilium-operator > opensuse.yaml

For the upstream Cilium images, default values do not bring any changes.

Signed-off-by: Michal Rostecki <mrostecki@opensuse.org>
---
 .../charts/agent/templates/daemonset.yaml      | 18 +++++++++---------
 .../kubernetes/cilium/charts/agent/values.yaml |  3 +++
 2 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/install/kubernetes/cilium/charts/agent/templates/daemonset.yaml b/install/kubernetes/cilium/charts/agent/templates/daemonset.yaml
index 975f9d5c3..03444ea46 100644
--- a/install/kubernetes/cilium/charts/agent/templates/daemonset.yaml
+++ b/install/kubernetes/cilium/charts/agent/templates/daemonset.yaml
@@ -136,12 +136,12 @@ spec:
           postStart:
             exec:
               command:
-              - "/cni-install.sh"
+              - {{ .Values.cniInstallScript }}
               -{{- if .Values.global.debug.enabled }} "--enable-debug=true"{{- else }} "--enable-debug=false"{{- end }}
           preStop:
             exec:
               command:
-              - /cni-uninstall.sh
+              - {{ .Values.cniUninstallScript }}
 {{- end }}
         name: cilium-agent
 {{- if .Values.global.prometheus.enabled }}
@@ -233,10 +233,10 @@ spec:
 {{- if and .Values.global.nodeinit.enabled (not (eq .Values.global.nodeinit.bootstrapFile "")) }}
       - name: wait-for-node-init
         command: ['sh', '-c', 'until stat {{ .Values.global.nodeinit.bootstrapFile }} > /dev/null 2>&1; do echo "Waiting on node-init to run..."; sleep 1; done']
-{{- if contains "/" .Values.image }}
-        image: "{{ .Values.image }}"
+{{- if contains "/" .Values.initImage }}
+        image: "{{ .Values.initImage }}"
 {{- else }}
-        image: "{{ .Values.global.registry }}/{{ .Values.image }}:{{ .Values.global.tag }}"
+        image: "{{ .Values.global.registry }}/{{ .Values.initImage }}:{{ .Values.global.tag }}"
 {{- end }}
         imagePullPolicy: {{ .Values.global.pullPolicy }}
         volumeMounts:
@@ -244,7 +244,7 @@ spec:
           name: cilium-bootstrap-file
 {{- end }}
       - command:
-        - /init-container.sh
+        - {{ .Values.initScript }}
         env:
         - name: CILIUM_ALL_STATE
           valueFrom:
@@ -264,10 +264,10 @@ spec:
               key: wait-bpf-mount
               name: cilium-config
               optional: true
-{{- if contains "/" .Values.image }}
-        image: "{{ .Values.image }}"
+{{- if contains "/" .Values.initImage }}
+        image: "{{ .Values.initImage }}"
 {{- else }}
-        image: "{{ .Values.global.registry }}/{{ .Values.image }}:{{ .Values.global.tag }}"
+        image: "{{ .Values.global.registry }}/{{ .Values.initImage }}:{{ .Values.global.tag }}"
 {{- end }}
         imagePullPolicy: {{ .Values.global.pullPolicy }}
         name: clean-cilium-state
diff --git a/install/kubernetes/cilium/charts/agent/values.yaml b/install/kubernetes/cilium/charts/agent/values.yaml
index 233d3e068..788bde816 100644
--- a/install/kubernetes/cilium/charts/agent/values.yaml
+++ b/install/kubernetes/cilium/charts/agent/values.yaml
@@ -1,4 +1,7 @@
+cniInstallScript: /cni-install.sh
+cniUninstallScript: /cni-uninstall.sh
 image: cilium
+initScript: /init-container.sh
 
 # Specifies the maximum number of Pods that can be unavailable during the
 # update process.
-- 
2.27.0

