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

feat(cli): override kubectl path with env-var #221

Merged
merged 6 commits into from
Feb 29, 2020

Conversation

mplzik
Copy link
Contributor

@mplzik mplzik commented Feb 20, 2020

Up to now, Tanka was using hard-coded string as a kubectl path, making
it hard to do any other tool without playing tricks with $PATH. This
commit allows to use TANKA_KUBECTL_PATH env variable to override the
path to kubectl used in Tanka's code.

See also #220 .

Copy link
Member

@sh0rez sh0rez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea is cool!

I wonder if it would be cleaner to have a function that returns a kubectl cmd with the correct binary set, instead of calling kubectlPath in multiple places:

func kubectl(args ...string) *exec.Cmd {
  binary := "kubectl"
  if env :=  os.Getenv("TANKA_KUBECTL_PATH"); env != "" {
    binary = env
  }

  return exec.Command(binary, args...)
}

@sh0rez
Copy link
Member

sh0rez commented Feb 20, 2020

Furthermore, env vars are not obvious from the CLI, we should document them at https://tanka.dev/env-vars

@mplzik
Copy link
Contributor Author

mplzik commented Feb 20, 2020

@sh0rez definitely agree, this PR was a my first shot (after trying to do a (not-so) nice) dependency injection approach. Your approach is even nicer, let me re-work the PR and update the docs.

@mplzik
Copy link
Contributor Author

mplzik commented Feb 20, 2020

Also, my original plan was to use CLI arguments for the override; this however proved quite clumsy given various places where kubectl is called. If there's any nice way of doing that, I'll be happy to go for it instead of introducing an env var.

docs/docs/env-vars.md Outdated Show resolved Hide resolved
Copy link
Member

@sh0rez sh0rez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting nits, I'll fix myself. LGTM 🚀

docs/docs/env-vars.md Outdated Show resolved Hide resolved
docs/docs/env-vars.md Outdated Show resolved Hide resolved
docs/docs/env-vars.md Outdated Show resolved Hide resolved
mplzik and others added 5 commits February 29, 2020 21:46
Up to now, Tanka was using hard-coded string as a `kubectl` path, making
it hard to do any other tool without playing tricks with $PATH. This
commit allows to use TANKA_KUBECTL_PATH env variable to override the
path to `kubectl` used in Tanka's code.

See also #220 .

Signed-off-by: Milan Plzik <milan.plzik@grafana.com>
As suggested in PR review, let's turn the `KubectlPath` into an actual
function that returns exec.Command object.

Signed-off-by: Milan Plzik <milan.plzik@grafana.com>
Signed-off-by: Milan Plzik <milan.plzik@grafana.com>
* `kubectlCmd` is only used within `client` package, no need for it to be
  public.
* Nicer formatting of the environment variable documentation.

Signed-off-by: Milan Plzik <milan.plzik@grafana.com>
@sh0rez sh0rez force-pushed the mplzik/kubectl-dependency-injection branch from 49f0e18 to e27e7b4 Compare February 29, 2020 20:50
Copy link
Member

@sh0rez sh0rez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@sh0rez sh0rez changed the title Allow overriding kubectl path using env var. feat(cli): override kubectl path with env-var Feb 29, 2020
@sh0rez sh0rez merged commit 6546515 into master Feb 29, 2020
@sh0rez sh0rez deleted the mplzik/kubectl-dependency-injection branch February 29, 2020 20:52
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.

None yet

2 participants