Skip to content

Commit

Permalink
Convert kind.sh to use j2 to generate kind.yaml
Browse files Browse the repository at this point in the history
Convert kind.sh to use j2 to generate kind.yaml from kind.yaml.j2. This
also collapses kind.yaml and kind-ha.yaml into one file.

Signed-off-by: Billy McFall <22157057+Billy99@users.noreply.github.com>
  • Loading branch information
Billy99 committed May 13, 2020
1 parent d306b78 commit aeb15cc
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 66 deletions.
2 changes: 2 additions & 0 deletions contrib/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
kind.yaml

31 changes: 18 additions & 13 deletions contrib/kind.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#!/usr/bin/env bash


# ensure j2 renderer installed
pip freeze | grep j2cli || pip install j2cli[yaml] --user
export PATH=~/.local/bin:$PATH

run_kubectl() {
local retries=0
local attempts=10
Expand Down Expand Up @@ -70,18 +75,12 @@ print_params()

parse_args $*

MASTER_COUNT=1
# Set default values
KIND_CLUSTER_NAME=${KIND_CLUSTER_NAME:-ovn}
K8S_VERSION=${K8S_VERSION:-v1.17.2}
KIND_INSTALL_INGRESS=${KIND_INSTALL_INGRESS:-false}
KIND_HA=${KIND_HA:-false}
if [ "$KIND_HA" == true ]; then
DEFAULT_KIND_CONFIG=./kind-ha.yaml
MASTER_COUNT=`grep -c "^\s-\srole\s*:\s*control-plane" kind-ha.yaml`
else
DEFAULT_KIND_CONFIG=./kind.yaml
MASTER_COUNT=`grep -c "^\s-\srole\s*:\s*control-plane" kind.yaml`
fi
KIND_CONFIG=${KIND_CONFIG:-$DEFAULT_KIND_CONFIG}
KIND_CONFIG=${KIND_CONFIG:-./kind.yaml.j2}
KIND_REMOVE_TAINT=${KIND_REMOVE_TAINT:-true}

print_params
Expand All @@ -95,11 +94,17 @@ if [ -z "$API_IP" ]; then
exit 1
fi

sed -i "s/apiServerAddress.*/apiServerAddress: ${API_IP}/" ${KIND_CONFIG}
# Output of the j2 command
KIND_CONFIG_LCL=./kind.yaml

# Create KIND cluster
KIND_CLUSTER_NAME=${KIND_CLUSTER_NAME:-ovn}
kind create cluster --name ${KIND_CLUSTER_NAME} --kubeconfig ${HOME}/admin.conf --image kindest/node:${K8S_VERSION} --config=${KIND_CONFIG}
ovn_apiServerAddress=${API_IP} \
ovn_ha=${KIND_HA} \
j2 ${KIND_CONFIG} -o ${KIND_CONFIG_LCL}

MASTER_COUNT=`grep -c "^\s-\srole\s*:\s*control-plane" ${KIND_CONFIG_LCL}`

# Create KIND cluster. For additional debug, add '--verbosity <int>': 0 None .. 3 Debug
kind create cluster --name ${KIND_CLUSTER_NAME} --kubeconfig ${HOME}/admin.conf --image kindest/node:${K8S_VERSION} --config=${KIND_CONFIG_LCL}
export KUBECONFIG=${HOME}/admin.conf
cat ${KUBECONFIG}
mkdir -p /tmp/kind
Expand Down
44 changes: 0 additions & 44 deletions contrib/kind.yaml

This file was deleted.

21 changes: 12 additions & 9 deletions contrib/kind-ha.yaml → contrib/kind.yaml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: kind.x-k8s.io/v1alpha4
networking:
# the default CNI will not be installed
disableDefaultCNI: true
apiServerAddress: 11.12.13.1
apiServerAddress: {{ ovn_apiServerAddress | default('11.12.13.1') }}
apiServerPort: 11337
kubeadmConfigPatches:
- |
Expand All @@ -25,6 +25,7 @@ nodes:
kubeletExtraArgs:
node-labels: "ingress-ready=true"
authorization-mode: "AlwaysAllow"
{%- if ovn_ha is equalto "true" %}
- role: control-plane
extraMounts:
- hostPath: /tmp/kind
Expand All @@ -33,12 +34,14 @@ nodes:
extraMounts:
- hostPath: /tmp/kind
containerPath: /var/run/secrets/kubernetes.io/serviceaccount/
# - role: worker
# extraMounts:
# - hostPath: /tmp/kind
# containerPath: /var/run/secrets/kubernetes.io/serviceaccount/
# - role: worker
# extraMounts:
# - hostPath: /tmp/kind
# containerPath: /var/run/secrets/kubernetes.io/serviceaccount/
{%- else %}
- role: worker
extraMounts:
- hostPath: /tmp/kind
containerPath: /var/run/secrets/kubernetes.io/serviceaccount/
- role: worker
extraMounts:
- hostPath: /tmp/kind
containerPath: /var/run/secrets/kubernetes.io/serviceaccount/
{%- endif %}

0 comments on commit aeb15cc

Please sign in to comment.