From 4cb7f6a4bd0fd74892126dd7389fc3d42f138ac4 Mon Sep 17 00:00:00 2001 From: Andrew Seigner Date: Tue, 23 Mar 2021 10:59:01 -0700 Subject: [PATCH] Fix handling default kubeconfig path (#12) User reported the `install` and `check` subcommands did not work unless an explicit `--context` flag was provided. Their kubeconfig file was in a non-default location. Fix the k8s client builder to correctly set config loading rules, including a check for the `KUBECONFIG` environment variable. Other changes: - Introduce `darwin-arm64` support in CI and release. - Rename `darwin` config in CI/release to `darwin-amd64`. - Update CI from `golang:1.16.0` to `1.16.2`. Signed-off-by: Andrew Seigner --- .github/workflows/actions.yml | 22 ++++++++++++++-------- pkg/k8s/client.go | 5 ++++- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index dd8e7a5..65d5ff6 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -20,7 +20,7 @@ jobs: name: Go Unit Tests runs-on: ubuntu-20.04 container: - image: golang:1.16.0 + image: golang:1.16.2 steps: - name: Checkout Code uses: actions/checkout@v2 @@ -32,7 +32,7 @@ jobs: name: Go Lint runs-on: ubuntu-20.04 container: - image: golang:1.16.0 + image: golang:1.16.2 steps: - name: Checkout Code uses: actions/checkout@v2 @@ -58,16 +58,20 @@ jobs: goos: linux goarch: arm exe: "" - - platform: darwin + - platform: darwin-amd64 goos: darwin - goarch: "" + goarch: amd64 + exe: "" + - platform: darwin-arm64 + goos: darwin + goarch: arm64 exe: "" - platform: windows goos: windows goarch: "" exe: .exe container: - image: golang:1.16.0 + image: golang:1.16.2 steps: - name: Checkout Code uses: actions/checkout@v2 @@ -94,11 +98,11 @@ jobs: strategy: matrix: include: - # no arm runner available, skip it + # no arm runner available, skip linux-arm64, linux-arm, and darwin-arm64 - platform: linux-amd64 os: ubuntu-20.04 exe: "" - - platform: darwin + - platform: darwin-amd64 os: macos-10.15 exe: "" - platform: windows @@ -160,7 +164,9 @@ jobs: exe: "" - platform: linux-arm exe: "" - - platform: darwin + - platform: darwin-amd64 + exe: "" + - platform: darwin-arm64 exe: "" - platform: windows exe: .exe diff --git a/pkg/k8s/client.go b/pkg/k8s/client.go index b15f2e2..1321d9e 100644 --- a/pkg/k8s/client.go +++ b/pkg/k8s/client.go @@ -52,8 +52,11 @@ type ( // New takes a kubeconfig and kubecontext and returns an initialized Client. func New(kubeconfig, kubecontext, bcloudServer string) (Client, error) { + rules := clientcmd.NewDefaultClientConfigLoadingRules() + rules.ExplicitPath = kubeconfig + clientConfig := clientcmd.NewNonInteractiveDeferredLoadingClientConfig( - &clientcmd.ClientConfigLoadingRules{ExplicitPath: kubeconfig}, + rules, &clientcmd.ConfigOverrides{CurrentContext: kubecontext}) config, err := clientConfig.ClientConfig()