4 SCRIPTDIR="$(readlink -f $(dirname ${BASH_SOURCE[0]}))"
5 LIBDIR="$(dirname $(dirname ${SCRIPTDIR}))/env/lib"
7 source $LIBDIR/logging.sh
8 source $LIBDIR/common.sh
10 FLANNEL_VERSION="v0.15.0"
12 # This may be used to update the in-place addon YAML files from the
14 function build_source {
15 mkdir -p ${SCRIPTDIR}/addons
18 curl -sL https://raw.githubusercontent.com/coreos/flannel/${FLANNEL_VERSION}/Documentation/kube-flannel.yml -o ${SCRIPTDIR}/addons/flannel.yaml
19 cat <<EOF >${SCRIPTDIR}/templates/flannel-addon.yaml
20 {{- if eq .Values.cni "flannel" }}
22 $(kubectl create configmap flannel-addon --from-file=${SCRIPTDIR}/addons/flannel.yaml -o yaml --dry-run=client)
25 sed -i -e 's/ name: flannel-addon/ name: {{ .Values.clusterName }}-flannel-addon/' ${SCRIPTDIR}/templates/flannel-addon.yaml
26 sed -i -e 's/10.244.0.0\/16/{{ .Values.podCidr }}/' ${SCRIPTDIR}/templates/flannel-addon.yaml
29 flux install --export >${SCRIPTDIR}/addons/flux-system.yaml
30 # The name "sync" must be sorted after "flux-system" to ensure
31 # Flux CRDs are instantiated first
32 cat <<'EOF' >${SCRIPTDIR}/addons/sync.yaml
34 apiVersion: source.toolkit.fluxcd.io/v1beta1
37 name: {{ .Values.flux.repositoryName }}
38 namespace: flux-system
40 gitImplementation: go-git
43 branch: {{ .Values.flux.branch }}
45 url: {{ .Values.flux.url }}
47 apiVersion: kustomize.toolkit.fluxcd.io/v1beta2
50 name: {{ .Values.clusterName }}-flux-sync
51 namespace: flux-system
54 path: {{ .Values.flux.path }}
58 name: {{ .Values.flux.repositoryName }}
60 cat <<EOF >${SCRIPTDIR}/templates/flux-addon.yaml
61 {{- if .Values.flux }}
63 $(kubectl create configmap flux-addon --from-file=${SCRIPTDIR}/addons/flux-system.yaml,${SCRIPTDIR}/addons/sync.yaml -o yaml --dry-run=client)
66 sed -i -e 's/ name: flux-addon/ name: {{ .Values.clusterName }}-flux-addon/' ${SCRIPTDIR}/templates/flux-addon.yaml
68 # PodSecurityPolicy is being replaced in future versions of K8s.
69 # The recommended practice is described by K8s at
70 # - https://kubernetes.io/docs/concepts/policy/pod-security-policy/#recommended-practice
71 # - https://kubernetes.io/docs/concepts/security/pod-security-standards/
72 # and provides three levels: privileged, baseline, and restricted.
74 # The question to answer here is how to reconcile the K8s levels
75 # against the Akraino security requirements.
77 # For the time being, the below populates the cluster with the K8s
78 # recommended levels and provides an additional policy (icn) bound
79 # to the system:authenticated group to meet the Akraino
81 cat <<EOF >${SCRIPTDIR}/addons/podsecurity.yaml
83 $(curl -sL https://raw.githubusercontent.com/kubernetes/website/main/content/en/examples/policy/privileged-psp.yaml)
85 $(curl -sL https://raw.githubusercontent.com/kubernetes/website/main/content/en/examples/policy/baseline-psp.yaml)
87 $(curl -sL https://raw.githubusercontent.com/kubernetes/website/main/content/en/examples/policy/restricted-psp.yaml)
89 $(curl -sL https://raw.githubusercontent.com/kubernetes/website/main/content/en/examples/policy/privileged-psp.yaml |
90 sed -e 's/ name: privileged/ name: icn/' |
91 sed -e '/^ allowedCapabilities:/,/^ [!-]/d')
97 requiredDropCapabilities:
100 apiVersion: rbac.authorization.k8s.io/v1
105 addonmanager.kubernetes.io/mode: Reconcile
112 - podsecuritypolicies
116 apiVersion: rbac.authorization.k8s.io/v1
121 addonmanager.kubernetes.io/mode: Reconcile
128 - podsecuritypolicies
132 apiVersion: rbac.authorization.k8s.io/v1
137 addonmanager.kubernetes.io/mode: Reconcile
144 - podsecuritypolicies
148 apiVersion: rbac.authorization.k8s.io/v1
153 addonmanager.kubernetes.io/mode: Reconcile
160 - podsecuritypolicies
164 apiVersion: rbac.authorization.k8s.io/v1
167 name: psp:privileged:nodes
168 namespace: kube-system
170 addonmanager.kubernetes.io/mode: Reconcile
172 apiGroup: rbac.authorization.k8s.io
178 apiGroup: rbac.authorization.k8s.io
180 apiVersion: rbac.authorization.k8s.io/v1
183 name: psp:privileged:kube-system
184 namespace: kube-system
186 apiGroup: rbac.authorization.k8s.io
191 name: system:serviceaccounts:kube-system
192 apiGroup: rbac.authorization.k8s.io
194 apiVersion: rbac.authorization.k8s.io/v1
195 kind: ClusterRoleBinding
201 apiGroup: rbac.authorization.k8s.io
204 name: system:authenticated
205 apiGroup: rbac.authorization.k8s.io
207 cat <<EOF >${SCRIPTDIR}/templates/podsecurity-addon.yaml
209 $(kubectl create configmap podsecurity-addon --from-file=${SCRIPTDIR}/addons/podsecurity.yaml -o yaml --dry-run=client)
211 sed -i -e 's/ name: podsecurity-addon/ name: {{ .Values.clusterName }}-podsecurity-addon/' ${SCRIPTDIR}/templates/podsecurity-addon.yaml
216 "build-source") build_source ;;
218 Usage: $(basename $0) COMMAND
221 build-source - Rebuild the in-tree addon YAML files