Skip to content

Commit

Permalink
Fix panic in kubeconfig sub-command when no spec.api.port set (#182)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
kke authored Aug 30, 2021
1 parent 658cd39 commit 590faf6
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 8 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]
continue-on-error: true
Expand Down
15 changes: 8 additions & 7 deletions phase/get_kubeconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
24 changes: 23 additions & 1 deletion smoke-test/smoke-basic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"

10 changes: 10 additions & 0 deletions smoke-test/smoke.common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 590faf6

Please sign in to comment.