Skip to content
This repository has been archived by the owner on Feb 6, 2024. It is now read-only.

rules_k8s: Support passing in a kubeconfig file #287

Merged
merged 1 commit into from
Mar 14, 2019
Merged

rules_k8s: Support passing in a kubeconfig file #287

merged 1 commit into from
Mar 14, 2019

Conversation

rohansingh
Copy link
Contributor

Add support for passing in a generated kubeconfig file to rules_k8s
objects. This can be used to pass in a configuration that's generated by
Bazel.

@k8s-ci-robot
Copy link

Hi @rohansingh. Thanks for your PR.

I'm waiting for a bazelbuild member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@rohansingh
Copy link
Contributor Author

This doesn't include any updates to relevant documentation. If this approach is acceptable, I'll make those updates as well.

@smukherj1
Copy link
Contributor

/ok-to-test

Copy link
Contributor

@smukherj1 smukherj1 left a comment

Choose a reason for hiding this comment

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

Hi Rohan,

Thanks for your PR. Could you please add a test for this as well in addition to the docs?

For the test, recommend extending one of the k8s_object rules here https://github.com/bazelbuild/rules_k8s/blob/master/examples/hellogrpc/BUILD#L24. Either make the k8s_service or the k8s_deploy target use a kubeconfig and move some of the config to the kubeconfig.

Thanks!

@@ -26,4 +26,5 @@ function exe() { echo "\$ ${@/eval/}" ; "$@" ; }
RUNFILES="${PYTHON_RUNFILES:-$(guess_runfiles)}"

PYTHON_RUNFILES=${RUNFILES} %{resolve_script} | \
exe %{kubectl_tool} --cluster="%{cluster}" --context="%{context}" --user="%{user}" %{namespace_arg} apply $@ -f -
exe %{kubectl_tool} --kubeconfig="%{kubeconfig}" --cluster="%{cluster}" \
Copy link
Contributor

Choose a reason for hiding this comment

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

What does kubectl do when --kubeconfig is given a blank string? Would it be preferable to only specify --kubeconfig when there's something to specify? The if condition would move to the k8s_object rule.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When --kubeconfig='', the behavior is the same as not specifying --kubeconfig at all. It's the same as --cluster='' and --context='' in that regard.

I agree that it would be cleaner and preferable to not output flags if the value is empty, since we're just getting lucky that the default value of all the current flags is an empty string. However, I think that should be a separate PR that would do this for all of the flags, rather than having different behavior for just this one flag.

@@ -28,4 +28,5 @@ RUNFILES="${PYTHON_RUNFILES:-$(guess_runfiles)}"
# TODO(mattmoor): Should we create namespaces that do not exist?

PYTHON_RUNFILES=${RUNFILES} %{resolve_script} | \
exe %{kubectl_tool} --cluster="%{cluster}" --context="%{context}" --user="%{user}" %{namespace_arg} create $@ -f -
exe %{kubectl_tool} --kubeconfig="%{kubeconfig}" --cluster="%{cluster}" \
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment here as apply

@rohansingh
Copy link
Contributor Author

@smukherj1 Thanks for the prompt review! I'll add tests and docs (and fix the buildifier failure).

@rohansingh
Copy link
Contributor Author

Updated documentation and tests, and rebased. Note that I don't have an environment setup for running the e2e tests locally, so kind of shooting in the dark here.

Add support for passing in a generated kubeconfig file to `rules_k8s`
objects. This can be used to pass in a configuration that's generated by
Bazel.
@k8s-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: rohansingh, smukherj1

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@smukherj1 smukherj1 merged commit 8bcee3c into bazelbuild:master Mar 14, 2019
@rohansingh rohansingh deleted the kubeconfig branch March 14, 2019 17:17
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants