Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use KUBECONFIG environment variable for kubeconfig path with fallback to default #62

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mattmattox
Copy link

Description:

This PR introduces a feature that allows the krs CLI to use the KUBECONFIG environment variable to determine the path to the kubeconfig file. If the KUBECONFIG variable is not set or is empty, the CLI will default to using ~/.kube/config.

Key Changes:

  • KUBECONFIG Environment Variable:

    • The CLI now checks for the KUBECONFIG environment variable to determine the kubeconfig file path.
    • If the environment variable is not set or is empty, the default path ~/.kube/config is used.
  • get_kubeconfig Function:

    • A new helper function get_kubeconfig() is introduced to handle the retrieval of the kubeconfig path based on the environment variable.
  • init Command Update:

    • The init command now uses the get_kubeconfig() function to determine the kubeconfig file path, offering more flexibility for users.

Why This Change?

  • Flexibility: This update allows users to easily specify different kubeconfig files without needing to modify command options or the script itself.
  • Consistency: By adhering to the common convention of using the KUBECONFIG environment variable, the CLI becomes more intuitive and consistent with other Kubernetes tools.

How to Test:

  1. Set the KUBECONFIG environment variable to a custom kubeconfig file path:
    export KUBECONFIG=/path/to/your/kubeconfig
  2. Run the init command to ensure that the specified kubeconfig file is used:
    krs init
  3. Unset the KUBECONFIG environment variable and rerun the init command to verify it defaults to ~/.kube/config:
    unset KUBECONFIG
    krs init

…llback to default

- Updated the CLI to use the `KUBECONFIG` environment variable to determine the path to the kubeconfig file.
- If `KUBECONFIG` is not set or is empty, the script defaults to using `~/.kube/config`.
- Introduced `get_kubeconfig()` function to handle the kubeconfig path retrieval.
- Updated the `init` command to utilize the `get_kubeconfig()` function for flexibility in kubeconfig path resolution.
- Improved the user experience by allowing easier configuration of kubeconfig file location through environment variables.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant