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 {{- range \$clusterName, \$cluster := .Values.clusters }}
21 {{- if eq \$cluster.cni "flannel" }}
23 $(kubectl create configmap flannel-addon --from-file=${SCRIPTDIR}/addons/flannel.yaml -o yaml --dry-run=client)
27 sed -i -e 's/ name: flannel-addon/ name: {{ $clusterName }}-flannel-addon/' ${SCRIPTDIR}/templates/flannel-addon.yaml
28 sed -i -e 's/10.244.0.0\/16/{{ $cluster.podCidr }}/' ${SCRIPTDIR}/templates/flannel-addon.yaml
31 flux install --export >${SCRIPTDIR}/addons/flux-system.yaml
32 # The name "sync" must be sorted after "flux-system" to ensure
33 # Flux CRDs are instantiated first
34 cat <<'EOF' >${SCRIPTDIR}/addons/sync.yaml
36 apiVersion: source.toolkit.fluxcd.io/v1beta1
39 name: {{ $cluster.flux.repositoryName }}
40 namespace: flux-system
42 gitImplementation: go-git
45 branch: {{ $cluster.flux.branch }}
47 url: {{ $cluster.flux.url }}
49 apiVersion: kustomize.toolkit.fluxcd.io/v1beta2
52 name: {{ $clusterName }}-flux-sync
53 namespace: flux-system
56 path: {{ $cluster.flux.path }}
60 name: {{ $cluster.flux.repositoryName }}
62 cat <<EOF >${SCRIPTDIR}/templates/flux-addon.yaml
63 {{- range \$clusterName, \$cluster := .Values.clusters }}
64 {{- if \$cluster.flux }}
66 $(kubectl create configmap flux-addon --from-file=${SCRIPTDIR}/addons/flux-system.yaml,${SCRIPTDIR}/addons/sync.yaml -o yaml --dry-run=client)
70 sed -i -e 's/ name: flux-addon/ name: {{ $clusterName }}-flux-addon/' ${SCRIPTDIR}/templates/flux-addon.yaml
74 "build-source") build_source ;;
76 Usage: $(basename $0) COMMAND
79 build-source - Rebuild the in-tree addon YAML files