Skip to content

Commit 21c35fa

Browse files
committed
wip
1 parent 9b2e03a commit 21c35fa

File tree

4 files changed

+32
-54
lines changed

4 files changed

+32
-54
lines changed

GNUmakefile

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,16 @@ OS_ARCH := $(shell go env GOOS)_$(shell go env GOARCH)
99
TF_PROV_DOCS := $(PWD)/kubernetes/test-infra/tfproviderdocs
1010
EXT_PROV_DIR := $(PWD)/kubernetes/test-infra/external-providers
1111
EXT_PROV_BIN := /tmp/.terraform.d/localhost/test/kubernetes/9.9.9/$(OS_ARCH)/terraform-provider-kubernetes_9.9.9_$(OS_ARCH)
12-
KUBECONFIG1 = $(shell echo $(KUBECONFIG) | cut -d\: -f1)
12+
13+
ifdef KUBE_CONFIG_PATHS
14+
KUBECONFIG1 := $(shell echo $(KUBE_CONFIG_PATHS) | cut -d\: -f1)
15+
else
16+
KUBECONFIG1 := $(shell echo $(KUBECONFIG) | cut -d\: -f1)
17+
endif
18+
19+
ifndef KUBECONFIG1
20+
$(error "Please set KUBE_CONFIG_PATHS or KUBECONFIG environment variable")
21+
endif
1322

1423
ifneq ($(PWD),$(PROVIDER_DIR))
1524
$(error "Makefile must be run from the provider directory")
@@ -58,7 +67,8 @@ test: fmtcheck
5867
xargs -t -n4 go test $(TESTARGS) -timeout=30s -parallel=4
5968

6069
testacc: fmtcheck vet
61-
rm -f kubernetes/testdata/kubeconfig
70+
rm -rf kubernetes/testdata || true
71+
mkdir kubernetes/testdata
6272
cp $(KUBECONFIG1) kubernetes/testdata/kubeconfig
6373
rm -rf $(EXT_PROV_DIR)/.terraform $(EXT_PROV_DIR)/.terraform.lock.hcl || true
6474
mkdir $(EXT_PROV_DIR)/.terraform

kubernetes/provider.go

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,7 @@ import (
44
"bytes"
55
"context"
66
"fmt"
7-
"log"
8-
"net/http"
9-
"os"
10-
"path/filepath"
11-
127
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
13-
148
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/logging"
159
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1610
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
@@ -20,6 +14,10 @@ import (
2014
"k8s.io/client-go/kubernetes"
2115
_ "k8s.io/client-go/plugin/pkg/client/auth"
2216
restclient "k8s.io/client-go/rest"
17+
"log"
18+
"net/http"
19+
"os"
20+
"path/filepath"
2321

2422
"k8s.io/client-go/tools/clientcmd"
2523
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
@@ -90,6 +88,7 @@ func Provider() *schema.Provider {
9088
"config_paths": {
9189
Type: schema.TypeList,
9290
Elem: &schema.Schema{Type: schema.TypeString},
91+
DefaultFunc: configPathsEnv,
9392
Optional: true,
9493
Description: "A list of paths to kube config files. Can be set with KUBE_CONFIG_PATHS environment variable.",
9594
// This should conflict with every attribute except for "insecure", since all of these options will be read from the kubeconfig.
@@ -221,6 +220,21 @@ func Provider() *schema.Provider {
221220
return p
222221
}
223222

223+
// configPathsEnv fetches the value of the environment variable KUBE_CONFIG_PATHS, if defined.
224+
func configPathsEnv() (interface{}, error) {
225+
value, exists := os.LookupEnv("KUBE_CONFIG_PATHS")
226+
if exists {
227+
log.Print("[DEBUG] using environment variable KUBE_CONFIG_PATHS to define config_paths")
228+
log.Printf("[DEBUG] value of KUBE_CONFIG_PATHS: %v", value)
229+
}
230+
pathList := filepath.SplitList(value)
231+
configPaths := new([]interface{})
232+
for _, p := range pathList {
233+
*configPaths = append(*configPaths, p)
234+
}
235+
return *configPaths, nil
236+
}
237+
224238
type KubeClientsets interface {
225239
MainClientset() (*kubernetes.Clientset, error)
226240
AggregatorClientset() (*aggregator.Clientset, error)

kubernetes/testdata/client.crt

Lines changed: 0 additions & 19 deletions
This file was deleted.

kubernetes/testdata/client.key

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)