Skip to content

Commit

Permalink
feat: Update cloud-init customization
Browse files Browse the repository at this point in the history
Changes relative to upstream:
* Add explanatory comments
* Do not use stderr output of preKubeadmCommands indicate an error with
  bootstrapping

Changes relative to our fork:
* Do not disable IPv6
* Do not remove cloud-init logs and seed
* Do not disable VMware customization
* Do not disable network configuration
* Do not truncate cloud-init-output.log
  • Loading branch information
dlipovetsky committed Oct 12, 2023
1 parent 55ae3fe commit 0ed4d6d
Showing 1 changed file with 26 additions and 23 deletions.
49 changes: 26 additions & 23 deletions controllers/cluster_scripts/cloud_init.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ users:
- name: root
lock_passwd: false
write_files:
# Due to a known issue with VMware Guest Customization, cloud-init believes every boot
# is the first boot. This ensures that cloud-init does not remove SSH keys on a reboot.
- path: /etc/cloud/cloud.cfg.d/cse.cfg
owner: root
content: |
ssh_deletekeys: false
# The control_plane.sh script runs on the first control plane machine. The node.sh script
# runs on every subsequent control plane machine, and every worker machine.
- path: /root/ {{- if .ControlPlane -}} control_plane {{- else -}} node {{- end -}} .sh
owner: root
content: |
Expand All @@ -11,12 +19,14 @@ write_files:
vmtoolsd --cmd "info-set guestinfo.post_customization_script_execution_status $?"
ERROR_MESSAGE="$(date) $(caller): $BASH_COMMAND"
echo "$ERROR_MESSAGE" &>> /var/log/capvcd/customization/error.log
if [[ -s /root/kubeadm.err ]]
vmtoolsd --cmd "info-set guestinfo.post_customization_script_execution_failure_reason $ERROR_MESSAGE"

CLOUD_INIT_OUTPUT=""
if [[ -f /var/log/cloud-init-output.log ]]
then
KUBEADM_FAILURE=$(cat /root/kubeadm.err)
ERROR_MESSAGE="$ERROR_MESSAGE $KUBEADM_FAILURE"
CLOUD_INIT_OUTPUT=$(</var/log/cloud-init-output.log)
fi
vmtoolsd --cmd "info-set guestinfo.post_customization_script_execution_failure_reason $ERROR_MESSAGE"
vmtoolsd --cmd "info-set guestinfo.post_customization_cloud_init_output $CLOUD_INIT_OUTPUT"
}
mkdir -p /var/log/capvcd/customization
trap 'catch $? $LINENO' ERR EXIT
Expand All @@ -33,21 +43,21 @@ write_files:
CSI_NODE_PATH=/root/csi-node.yaml {{- end }}

vmtoolsd --cmd "info-set guestinfo.postcustomization.networkconfiguration.status in_progress"
hostname "{{ .MachineName }}"
echo "::1 ipv6-localhost ipv6-loopback" >/etc/hosts
echo "127.0.0.1 localhost" >>/etc/hosts
echo "{{ .MachineName }}" >/etc/hostname
echo "127.0.0.1" `hostname` >>/etc/hosts
echo 'net.ipv6.conf.all.disable_ipv6 = 1' >> /etc/sysctl.conf
echo 'net.ipv6.conf.default.disable_ipv6 = 1' >> /etc/sysctl.conf
echo 'net.ipv6.conf.lo.disable_ipv6 = 1' >> /etc/sysctl.conf
sudo sysctl -p
# also remove ipv6 localhost entry from /etc/hosts
sed -i 's/::1/127.0.0.1/g' /etc/hosts || true
vmtoolsd --cmd "info-set guestinfo.postcustomization.networkconfiguration.status successful"

vmtoolsd --cmd "info-set guestinfo.metering.status in_progress"
# Our images do not ship the VCD metering service, but CAPVCD requires a successful status to finish bootstrapping.
vmtoolsd --cmd "info-set guestinfo.metering.status successful"

vmtoolsd --cmd "info-set guestinfo.postcustomization.proxy.setting.status in_progress"
vmtoolsd --cmd "info-set guestinfo.postcustomization.proxy.setting.status successful"

vmtoolsd --cmd "info-set {{ if .ControlPlane -}} guestinfo.postcustomization.kubeinit.status {{- else -}} guestinfo.postcustomization.kubeadm.node.join.status {{- end }} in_progress"
{{ .BootstrapRunCmd }}
{
{{ .BootstrapRunCmd }}
}
if [[ ! -f /run/cluster-api/bootstrap-success.complete ]]
then
echo "file /run/cluster-api/bootstrap-success.complete not found" &>> /var/log/capvcd/customization/error.log
Expand All @@ -58,12 +68,8 @@ write_files:
echo "$(date) post customization script execution completed" &>> /var/log/capvcd/customization/status.log
exit 0
runcmd:
- 'sudo cloud-init clean --seed --logs'
- 'sudo cat /dev/null > /var/log/cloud-init-output.log'
- 'cloud-init clean'
{{ if .ControlPlane }}
- '[ ! -f /run/kubeadm/konvoy-set-kube-proxy-configuration.sh] && sudo reboot'
- '[ ! -f /run/konvoy/containerd-apply-patches.sh] && sudo reboot'
- '[ ! -f /run/konvoy/restart-containerd-and-wait.sh] && sudo reboot'
- '[ ! -f /root/control_plane.sh ] && sudo reboot'
- '[ ! -f /run/kubeadm/kubeadm.yaml ] && sudo reboot'
- bash /root/control_plane.sh
Expand All @@ -74,9 +80,6 @@ runcmd:
{{ end }}
timezone: UTC
disable_root: false
disable_vmware_customization: true
network:
config: disabled
preserve_hostname: false
hostname: "{{ .MachineName }}"
final_message: "The system is ready after $UPTIME seconds"
final_message: "The system is ready after $UPTIME seconds"

0 comments on commit 0ed4d6d

Please sign in to comment.