Skip to content

Commit 590faf6

Browse files
authored
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
1 parent 658cd39 commit 590faf6

File tree

4 files changed

+48
-8
lines changed

4 files changed

+48
-8
lines changed

.github/workflows/go.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,13 @@ jobs:
9191
!*.log
9292
key: k0sctl-cache
9393

94+
- name: Kubectl cache
95+
uses: actions/cache@v2
96+
with:
97+
path: |
98+
smoke-test/kubectl
99+
key: kubectl-1.21.3
100+
94101
- name: Docker Layer Caching For Footloose
95102
uses: satackey/[email protected]
96103
continue-on-error: true

phase/get_kubeconfig.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,20 @@ func (p *GetKubeconfig) Run() error {
2323
if err != nil {
2424
return err
2525
}
26+
2627
// the controller admin.conf is aways pointing to localhost, thus we need to change the address
2728
// something usable from outside
28-
a := p.Config.Spec.K0s.Config.DigString("spec", "api", "externalAddress")
29-
if a == "" {
30-
a = h.SSH.Address
29+
address := h.Address()
30+
if a, ok := p.Config.Spec.K0s.Config.Dig("spec", "api", "externalAddress").(string); ok {
31+
address = a
3132
}
3233

33-
port := p.Config.Spec.K0s.Config.Dig("spec", "api", "port").(int)
34-
if port == 0 {
35-
port = 6443
34+
port := 6443
35+
if p, ok := p.Config.Spec.K0s.Config.Dig("spec", "api", "port").(int); ok {
36+
port = p
3637
}
3738

38-
cfgString, err := kubeConfig(output, p.Config.Metadata.Name, a, port)
39+
cfgString, err := kubeConfig(output, p.Config.Metadata.Name, address, port)
3940
if err != nil {
4041
return err
4142
}

smoke-test/smoke-basic.sh

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,30 @@ envsubst < "${K0SCTL_TEMPLATE}" > k0sctl.yaml
1212

1313
deleteCluster
1414
createCluster
15+
16+
echo "* Starting apply"
1517
../k0sctl apply --config k0sctl.yaml --debug
16-
# Check that the hooks got actually ran properly
18+
echo "* Apply OK"
19+
20+
echo "* Verify hooks were executed on the host"
1721
footloose ssh root@manager0 -- grep -q hello apply.hook
1822

23+
echo "* Verify 'k0sctl kubeconfig' output includes 'data' block"
1924
../k0sctl kubeconfig --config k0sctl.yaml | grep -v -- "-data"
25+
26+
echo "* Run kubectl on controller"
27+
footloose ssh root@manager0 -- k0s kubectl get nodes
28+
29+
echo "* Downloading kubectl for local test"
30+
downloadKubectl
31+
32+
echo "* Using k0sctl kubecofig locally"
33+
../k0sctl kubeconfig --config k0sctl.yaml > kubeconfig
34+
35+
echo "* Output:"
36+
cat kubeconfig | grep -v -- "-data"
37+
38+
echo "* Running kubectl"
39+
./kubectl --kubeconfig kubeconfig get nodes
40+
echo "* Done"
41+

smoke-test/smoke.common.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,14 @@ function cleanup() {
2323
if [ -z "${PRESERVE_CLUSTER}" ]; then
2424
deleteCluster
2525
fi
26+
}
27+
28+
function downloadKubectl() {
29+
OS=$(uname | tr '[:upper:]' '[:lower:]')
30+
ARCH="amd64"
31+
case $(uname -m) in
32+
arm,arm64) ARCH="arm64" ;;
33+
esac
34+
[ -f kubectl ] || (curl -L https://storage.googleapis.com/kubernetes-release/release/v1.21.3/bin/${OS}/${ARCH}/kubectl > ./kubectl && chmod +x ./kubectl)
35+
./kubectl version --client
2636
}

0 commit comments

Comments
 (0)