Skip to content

Commit

Permalink
fix: install script should use api server of detected kubeconfig
Browse files Browse the repository at this point in the history
  • Loading branch information
tinyzimmer committed Oct 2, 2023
1 parent efa26c4 commit d358e9f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -138,20 +138,20 @@ $(ENVTEST): $(LOCALBIN)
K3D ?= k3d
CLUSTER_NAME ?= webmesh-cni

test-cluster:
test-cluster: ## Create a test cluster with the WebMesh CNI installed.
$(K3D) cluster create $(CLUSTER_NAME) \
--k3s-arg '--flannel-backend=none@server:*' \
--k3s-arg "--disable-network-policy@server:*" \
--volume '$(BUNDLE):/var/lib/rancher/k3s/server/manifests/webmesh.yaml@server:*' \

build-and-load: docker
load: docker ## Load the docker image into the test cluster.
$(K3D) image import $(IMG) --cluster $(CLUSTER_NAME)

test-cluster-calico:
test-cluster-calico: ## Create a test cluster with Calico installed. This is used for testing the storage provider.
$(K3D) cluster create $(CLUSTER_NAME) \
--k3s-arg '--flannel-backend=none@server:*' \
--k3s-arg "--disable-network-policy@server:*" \
--volume '$(CURDIR)/config/ref/calico.yaml:/var/lib/rancher/k3s/server/manifests/calico.yaml@server:*' \

remove-cluster:
remove-cluster: ## Remove the test cluster.
$(K3D) cluster delete $(CLUSTER_NAME)
7 changes: 2 additions & 5 deletions internal/cmd/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ import (
)

const (
// KubernetesAPIEndpointEnvVar is the name of the environment variable that contains the Kubernetes API endpoint.
KubernetesAPIEndpointEnvVar = "KUBERNETES_API_ENDPOINT"
// NetConfEnvVar is the name of the environment variable that contains the CNI configuration.
NetConfEnvVar = "CNI_NETWORK_CONFIG"
// NetConfFileName is the name of the file that contains the CNI configuration.
Expand Down Expand Up @@ -76,7 +74,7 @@ func Main(version string) {
APIVersion: "v1",
Clusters: map[string]*clientcmdapi.Cluster{
"webmesh-cni": {
Server: os.Getenv("KUBERNETES_API_ENDPOINT"),
Server: cfg.Host,
TLSServerName: cfg.ServerName,
InsecureSkipTLSVerify: cfg.Insecure,
CertificateAuthority: cfg.CAFile,
Expand Down Expand Up @@ -108,7 +106,7 @@ func Main(version string) {
conf := os.Getenv(NetConfEnvVar)
conf = strings.Replace(conf, "__KUBERNETES_NODE_NAME__", os.Getenv(NodeNameEnvVar), -1)
conf = strings.Replace(conf, "__K8S_POD_NAMESPACE__", os.Getenv(PodNamespaceEnvVar), -1)
conf = strings.Replace(conf, "__KUBERNETES_API_ENDPOINT__", os.Getenv("KUBERNETES_API_ENDPOINT"), -1)
conf = strings.Replace(conf, "__KUBERNETES_API_ENDPOINT__", cfg.Host, -1)
conf = strings.Replace(conf, "__KUBECONFIG_FILEPATH__", kubeconfigPath, -1)
// Write the CNI configuration to the destination directory.
confPath := filepath.Join(os.Getenv(BinaryDestConfEnvVar), os.Getenv(NetConfFileNameEnvVar))
Expand Down Expand Up @@ -151,7 +149,6 @@ func installPluginBinary(src, dest string) error {
// checkEnv ensures all the required environment variables are set.
func checkEnv() error {
for _, envvar := range []string{
KubernetesAPIEndpointEnvVar,
NetConfEnvVar,
NetConfFileNameEnvVar,
NodeNameEnvVar,
Expand Down

0 comments on commit d358e9f

Please sign in to comment.