Skip to content

Commit

Permalink
Merge pull request #93 from canonical/KU-519/wait-apiserver
Browse files Browse the repository at this point in the history
wait for apiserver instead of Ready nodes
  • Loading branch information
neoaggelos authored Mar 13, 2024
2 parents 22f9dc6 + 2628f40 commit 500b80e
Show file tree
Hide file tree
Showing 13 changed files with 37 additions and 15 deletions.
2 changes: 1 addition & 1 deletion controllers/cloudinit/controlplane_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func NewInitControlPlane(input *ControlPlaneInitInput) (*CloudConfig, error) {
fmt.Sprintf("%s %q", scriptPath(installMicroK8sScript), installArgs),
fmt.Sprintf("%s %q %q %q", scriptPath(configureContainerdProxyScript), input.ContainerdHTTPProxy, input.ContainerdHTTPSProxy, input.ContainerdNoProxy),
scriptPath(configureKubeletScript),
"microk8s status --wait-ready",
scriptPath(waitAPIServerScript),
"microk8s refresh-certs /var/tmp",
fmt.Sprintf("%s %v", scriptPath(configureCalicoIPIPScript), input.IPinIP),
fmt.Sprintf("%s %q", scriptPath(configureClusterAgentPortScript), input.ClusterAgentPort),
Expand Down
2 changes: 1 addition & 1 deletion controllers/cloudinit/controlplane_init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func TestControlPlaneInit(t *testing.T) {
`/capi-scripts/00-install-microk8s.sh "--channel 1.25 --classic"`,
`/capi-scripts/10-configure-containerd-proxy.sh "" "" ""`,
`/capi-scripts/10-configure-kubelet.sh`,
`microk8s status --wait-ready`,
`/capi-scripts/50-wait-apiserver.sh`,
`microk8s refresh-certs /var/tmp`,
`/capi-scripts/10-configure-calico-ipip.sh true`,
`/capi-scripts/10-configure-cluster-agent-port.sh "30000"`,
Expand Down
4 changes: 2 additions & 2 deletions controllers/cloudinit/controlplane_join.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,11 @@ func NewJoinControlPlane(input *ControlPlaneJoinInput) (*CloudConfig, error) {
fmt.Sprintf("%s %q", scriptPath(installMicroK8sScript), installArgs),
fmt.Sprintf("%s %q %q %q", scriptPath(configureContainerdProxyScript), input.ContainerdHTTPProxy, input.ContainerdHTTPSProxy, input.ContainerdNoProxy),
scriptPath(configureKubeletScript),
"microk8s status --wait-ready",
scriptPath(waitAPIServerScript),
fmt.Sprintf("%s %v", scriptPath(configureCalicoIPIPScript), input.IPinIP),
fmt.Sprintf("%s %q", scriptPath(configureClusterAgentPortScript), input.ClusterAgentPort),
fmt.Sprintf("%s %q", scriptPath(configureDqlitePortScript), input.DqlitePort),
"microk8s status --wait-ready",
scriptPath(waitAPIServerScript),
fmt.Sprintf("%s %q %q", scriptPath(configureCertLB), endpointType, input.ControlPlaneEndpoint),
fmt.Sprintf("%s no %s", scriptPath(microk8sJoinScript), strings.Join(joinURLs, " ")),
scriptPath(configureAPIServerScript),
Expand Down
4 changes: 2 additions & 2 deletions controllers/cloudinit/controlplane_join_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ func TestControlPlaneJoin(t *testing.T) {
`/capi-scripts/00-install-microk8s.sh "--channel 1.25 --classic"`,
`/capi-scripts/10-configure-containerd-proxy.sh "" "" ""`,
`/capi-scripts/10-configure-kubelet.sh`,
`microk8s status --wait-ready`,
`/capi-scripts/50-wait-apiserver.sh`,
`/capi-scripts/10-configure-calico-ipip.sh true`,
`/capi-scripts/10-configure-cluster-agent-port.sh "30000"`,
`/capi-scripts/10-configure-dqlite-port.sh "2379"`,
`microk8s status --wait-ready`,
`/capi-scripts/50-wait-apiserver.sh`,
`/capi-scripts/10-configure-cert-for-lb.sh "DNS" "k8s.my-domain.com"`,
`/capi-scripts/20-microk8s-join.sh no "10.0.3.39:30000/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" "10.0.3.40:30000/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" "10.0.3.41:30000/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"`,
`/capi-scripts/10-configure-apiserver.sh`,
Expand Down
4 changes: 4 additions & 0 deletions controllers/cloudinit/embed.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ const (

// configureTraefikScript configures the control plane endpoint in the traefik provider configuration.
configureTraefikScript script = "30-configure-traefik.sh"

// waitAPIServerScript waits for the kube-apiserver to be ready.
waitAPIServerScript script = "50-wait-apiserver.sh"
)

var allScripts = []script{
Expand All @@ -92,6 +95,7 @@ var allScripts = []script{
configureKubeletScript,
microk8sEnableScript,
microk8sJoinScript,
waitAPIServerScript,
}

func mustGetScript(scriptName script) string {
Expand Down
2 changes: 1 addition & 1 deletion controllers/cloudinit/scripts/10-configure-apiserver.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ while ! snap restart microk8s.daemon-kubelite; do
done

# delete kubernetes service to make sure port is updated
microk8s status --wait-ready
/capi-scripts/50-wait-apiserver.sh
microk8s kubectl delete svc kubernetes

# redirect port 16443 to 6443
Expand Down
7 changes: 7 additions & 0 deletions controllers/cloudinit/scripts/10-configure-calico-ipip.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ fi

CNI_YAML="/var/snap/microk8s/current/args/cni-network/cni.yaml"

if [ ! -f "${CNI_YAML}" ]; then
echo "Will not configure Calico, missing cni.yaml"
exit 0
fi

/capi-scripts/50-wait-apiserver.sh

# Stop calico-node and delete ippools to ensure no vxlan pools are left around
microk8s kubectl delete daemonset/calico-node -n kube-system || true
microk8s kubectl delete ippools --all || true
Expand Down
3 changes: 2 additions & 1 deletion controllers/cloudinit/scripts/10-configure-cert-for-lb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ sleep 10
while ! snap restart microk8s.daemon-kubelite; do
sleep 5
done
microk8s status --wait-ready

/capi-scripts/50-wait-apiserver.sh
2 changes: 1 addition & 1 deletion controllers/cloudinit/scripts/20-microk8s-enable.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ microk8s enable community || true

while [[ "$@" != "" ]]; do
microk8s enable "$1"
microk8s status --wait-ready
/capi-scripts/50-wait-apiserver.sh
shift
done
5 changes: 1 addition & 4 deletions controllers/cloudinit/scripts/20-microk8s-join.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,5 @@ done
sleep 10

if [ ${1} == "no" ]; then
while ! microk8s status --wait-ready; do
echo "Waiting for the cluster to come up"
sleep 5
done
/capi-scripts/50-wait-apiserver.sh
fi
13 changes: 13 additions & 0 deletions controllers/cloudinit/scripts/50-wait-apiserver.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash -xe

# Usage:
# $0
#
# Assumptions:
# - microk8s is installed
# - microk8s kubelite service is running

while ! microk8s kubectl get --raw /readyz; do
echo Waiting for kube-apiserver
sleep 3
done
2 changes: 1 addition & 1 deletion controllers/cloudinit/worker_join.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func NewJoinWorker(input *WorkerInput) (*CloudConfig, error) {
fmt.Sprintf("%s %q", scriptPath(installMicroK8sScript), installArgs),
fmt.Sprintf("%s %q %q %q", scriptPath(configureContainerdProxyScript), input.ContainerdHTTPProxy, input.ContainerdHTTPSProxy, input.ContainerdNoProxy),
scriptPath(configureKubeletScript),
"microk8s status --wait-ready",
scriptPath(waitAPIServerScript),
fmt.Sprintf("%s %q", scriptPath(configureClusterAgentPortScript), input.ClusterAgentPort),
fmt.Sprintf("%s yes %s", scriptPath(microk8sJoinScript), strings.Join(joinURLs, " ")),
fmt.Sprintf("%s %s 6443 %s", scriptPath(configureTraefikScript), input.ControlPlaneEndpoint, stopApiServerProxyRefreshes),
Expand Down
2 changes: 1 addition & 1 deletion controllers/cloudinit/worker_join_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func TestWorkerJoin(t *testing.T) {
`/capi-scripts/00-install-microk8s.sh "--channel 1.24 --classic"`,
`/capi-scripts/10-configure-containerd-proxy.sh "" "" ""`,
`/capi-scripts/10-configure-kubelet.sh`,
`microk8s status --wait-ready`,
`/capi-scripts/50-wait-apiserver.sh`,
`/capi-scripts/10-configure-cluster-agent-port.sh "30000"`,
`/capi-scripts/20-microk8s-join.sh yes "10.0.3.194:30000/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" "10.0.3.195:30000/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"`,
`/capi-scripts/30-configure-traefik.sh capi-aws-apiserver-1647391446.us-east-1.elb.amazonaws.com 6443 no`,
Expand Down

0 comments on commit 500b80e

Please sign in to comment.