cnoe-io / idpbuilder

Spin up a complete internal developer platform with only Docker required as a dependency.
https://cloud-native.slack.com/archives/C05TN9WFN5S
Apache License 2.0
194 stars 59 forks source link

Feature: add a flag for `--kubeconfig` or support `KUBECONFIG` environment variable #362

Open punkwalker opened 2 months ago

punkwalker commented 2 months ago

Have you searched for this feature request?

Problem Statement

Currently create command uses $HOME/.kube/config for writing kubeconfig of Kind cluster. And get command also uses same default path for interacting with cluster.

This works fine but there are following scenarios where this behavior is not useful. Story 1: I don't want the local cluster kubeconfig in default location.

Story 2: I am using context switching tools like kubeswitch which allows me to create sticky context for each terminal. In this case, If I create multiple builds, the get secrets command keeps fetching secrets from the cluster for which the context is set in the default kubeconfig.

Story 3: I want to have kubectl like experience of using non-default kubeconfig when I am interacting with the cluster.

Possible Solution

As a quick fix, the logic of kubeConfigPath in create and get secret command can be modified to check KUBECONFIG environment variable as follows:

    kubeConfigPath := filepath.Join(homedir.HomeDir(), ".kube", "config")
    kubeConfigPathEnv := os.Getenv("KUBECONFIG")

    if kubeConfigPathEnv != "" {
        kubeConfigPath = kubeConfigPathEnv
    }

Long term, we should add support for --kubeconfig flag and then set the value to opts. Eventually it can be used for #74

Alternatives Considered

Currently. No alternative than using default kubeconfig file