From 590faf64f3fa81b5c6e37d37b9ee1c5a31c0066c Mon Sep 17 00:00:00 2001 From: Kimmo Lehto Date: Mon, 30 Aug 2021 14:06:47 +0300 Subject: [PATCH] Fix panic in kubeconfig sub-command when no spec.api.port set (#182) * Test kubeconfig validity in smoke-tests * What -a * Cache fix * See if changing to kubernetes-admin changes anything * Change it back. * Echo out the user * Echo out the whole config * Dont censor * Add type check * Increase basic smoke test verbosity * More consistent type check for externalAddress --- .github/workflows/go.yml | 7 +++++++ phase/get_kubeconfig.go | 15 ++++++++------- smoke-test/smoke-basic.sh | 24 +++++++++++++++++++++++- smoke-test/smoke.common.sh | 10 ++++++++++ 4 files changed, 48 insertions(+), 8 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 261b5a89..c5c04318 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -91,6 +91,13 @@ jobs: !*.log key: k0sctl-cache + - name: Kubectl cache + uses: actions/cache@v2 + with: + path: | + smoke-test/kubectl + key: kubectl-1.21.3 + - name: Docker Layer Caching For Footloose uses: satackey/action-docker-layer-caching@v0.0.11 continue-on-error: true diff --git a/phase/get_kubeconfig.go b/phase/get_kubeconfig.go index 5b43641d..e901114f 100644 --- a/phase/get_kubeconfig.go +++ b/phase/get_kubeconfig.go @@ -23,19 +23,20 @@ func (p *GetKubeconfig) Run() error { if err != nil { return err } + // the controller admin.conf is aways pointing to localhost, thus we need to change the address // something usable from outside - a := p.Config.Spec.K0s.Config.DigString("spec", "api", "externalAddress") - if a == "" { - a = h.SSH.Address + address := h.Address() + if a, ok := p.Config.Spec.K0s.Config.Dig("spec", "api", "externalAddress").(string); ok { + address = a } - port := p.Config.Spec.K0s.Config.Dig("spec", "api", "port").(int) - if port == 0 { - port = 6443 + port := 6443 + if p, ok := p.Config.Spec.K0s.Config.Dig("spec", "api", "port").(int); ok { + port = p } - cfgString, err := kubeConfig(output, p.Config.Metadata.Name, a, port) + cfgString, err := kubeConfig(output, p.Config.Metadata.Name, address, port) if err != nil { return err } diff --git a/smoke-test/smoke-basic.sh b/smoke-test/smoke-basic.sh index c8567480..3a83de84 100755 --- a/smoke-test/smoke-basic.sh +++ b/smoke-test/smoke-basic.sh @@ -12,8 +12,30 @@ envsubst < "${K0SCTL_TEMPLATE}" > k0sctl.yaml deleteCluster createCluster + +echo "* Starting apply" ../k0sctl apply --config k0sctl.yaml --debug -# Check that the hooks got actually ran properly +echo "* Apply OK" + +echo "* Verify hooks were executed on the host" footloose ssh root@manager0 -- grep -q hello apply.hook +echo "* Verify 'k0sctl kubeconfig' output includes 'data' block" ../k0sctl kubeconfig --config k0sctl.yaml | grep -v -- "-data" + +echo "* Run kubectl on controller" +footloose ssh root@manager0 -- k0s kubectl get nodes + +echo "* Downloading kubectl for local test" +downloadKubectl + +echo "* Using k0sctl kubecofig locally" +../k0sctl kubeconfig --config k0sctl.yaml > kubeconfig + +echo "* Output:" +cat kubeconfig | grep -v -- "-data" + +echo "* Running kubectl" +./kubectl --kubeconfig kubeconfig get nodes +echo "* Done" + diff --git a/smoke-test/smoke.common.sh b/smoke-test/smoke.common.sh index 320ca2de..01bc2b7d 100644 --- a/smoke-test/smoke.common.sh +++ b/smoke-test/smoke.common.sh @@ -23,4 +23,14 @@ function cleanup() { if [ -z "${PRESERVE_CLUSTER}" ]; then deleteCluster fi +} + +function downloadKubectl() { + OS=$(uname | tr '[:upper:]' '[:lower:]') + ARCH="amd64" + case $(uname -m) in + arm,arm64) ARCH="arm64" ;; + esac + [ -f kubectl ] || (curl -L https://storage.googleapis.com/kubernetes-release/release/v1.21.3/bin/${OS}/${ARCH}/kubectl > ./kubectl && chmod +x ./kubectl) + ./kubectl version --client } \ No newline at end of file