Skip to content

Instantly share code, notes, and snippets.

@joshrosso
Created February 6, 2017 14:50
Show Gist options
  • Save joshrosso/e3f745022b80ce4fa600aca21fb7ee90 to your computer and use it in GitHub Desktop.
Save joshrosso/e3f745022b80ce4fa600aca21fb7ee90 to your computer and use it in GitHub Desktop.
#!/bin/bash
jq -r .Resources.LaunchConfigurationWorker.Properties.UserData assets/cloud-formation.json | base64 -d > launchConfigAssets.txt
jq -r .Resources.InstanceController.Properties.UserData assets/cloud-formation.json | base64 -d > controllerAssets.txt
jq -r '.systemd.units[] | select(.name=="kubelet.service") | .contents' launchConfigAssets.txt > workerKubelet.txt
jq -r '.systemd.units[] | select(.name=="kubelet.service") | .contents' controllerAssets.txt > controllerKubelet.txt
workerExecPreNum=$(grep -m 1 -n 'ExecStartPre' workerKubelet.txt | cut -f1 -d:)
workerMountNum=$(grep -m 1 -n '\-\-volume' workerKubelet.txt | cut -f1 -d:)
sed -i "${workerExecPreNum}iExecStartPre=/bin/mkdir -p /opt/cni/bin" workerKubelet.txt
sed -i "${workerMountNum}i\ --mount volume=cni-bin-dir,target=/opt/cni/bin \\\\" workerKubelet.txt
sed -i "${workerMountNum}i\ --volume=cni-bin-dir,kind=host,source=/opt/cni/bin \\\\" workerKubelet.txt
export kubeletWorkerUpdate=$(cat workerKubelet.txt)
jq -r '.systemd.units[] | select(.name=="kubelet.service") | .contents=env.kubeletWorkerUpdate' launchConfigAssets.txt | awk 'BEGIN{RS="";getline<"-";print>ARGV[1]}' updatedLaunchConfigKubelet.json
controllerExecPreNum=$(grep -m 1 -n 'ExecStartPre' controllerKubelet.txt | cut -f1 -d:)
controllerMountNum=$(grep -m 1 -n '\-\-volume' controllerKubelet.txt | cut -f1 -d:)
sed -i "${controllerExecPreNum}iExecStartPre=/bin/mkdir -p /opt/cni/bin" controllerKubelet.txt
sed -i "${controllerMountNum}i\ --mount volume=cni-bin-dir,target=/opt/cni/bin \\\\" controllerKubelet.txt
sed -i "${controllerMountNum}i\ --volume=cni-bin-dir,kind=host,source=/opt/cni/bin \\\\" controllerKubelet.txt
export kubeletControllerUpdate=$(cat controllerKubelet.txt)
jq -r '.systemd.units[] | select(.name=="kubelet.service") | .contents=env.kubeletControllerUpdate' controllerAssets.txt | awk 'BEGIN{RS="";getline<"-";print>ARGV[1]}' updatedControllerKubelet.json
jq . launchConfigAssets.txt > launchConfigAssets.json
jq . controllerAssets.txt > controllerAssets.json
rm launchConfigAssets.txt controllerAssets.txt workerKubelet.txt controllerKubelet.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment