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

Adding capability to pass in args parameter to kubectl #198

Closed
wants to merge 4 commits into from

Conversation

chrislovecnm
Copy link
Contributor

@chrislovecnm chrislovecnm commented Oct 19, 2018

This PR adds a parameter to pass in arguments to kubectl. For instance
a user can pass in "-v=10 --dry-run=true" to kubectl. This work is
based off of @omadawn's work.

Once we have the design stabilized I will update the documentation.

@chrislovecnm chrislovecnm changed the title Adding capability to pass in args parameter to kubectl [WIP] Adding capability to pass in args parameter to kubectl Oct 19, 2018
@chrislovecnm chrislovecnm force-pushed the kubectl-commands branch 2 times, most recently from 075db0f to 3d96226 Compare October 19, 2018 22:02
Copy link
Contributor Author

@chrislovecnm chrislovecnm left a comment

Choose a reason for hiding this comment

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

Various comments

Copy link
Contributor Author

@chrislovecnm chrislovecnm left a comment

Choose a reason for hiding this comment

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

More comments.

@chrislovecnm chrislovecnm changed the title [WIP] Adding capability to pass in args parameter to kubectl Adding capability to pass in args parameter to kubectl Oct 19, 2018
Copy link
Contributor Author

@chrislovecnm chrislovecnm left a comment

Choose a reason for hiding this comment

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

more questions

Copy link
Contributor

@nlopezgi nlopezgi left a comment

Choose a reason for hiding this comment

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

sorry for the delay getting back with comments.

@chrislovecnm
Copy link
Contributor Author

chrislovecnm commented Oct 23, 2018

I will update with the make variables call, but also put in an issue to replace them as that call is deprecated.

@k8s-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: chrislovecnm
To fully approve this pull request, please assign additional approvers.
We suggest the following additional approver: nlopezgi

If they are not already assigned, you can assign the PR to them by writing /assign @nlopezgi in a comment when ready.

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

@chrislovecnm
Copy link
Contributor Author

/test pull-rules-k8s-e2e

@chrislovecnm
Copy link
Contributor Author

/retest

@chrislovecnm
Copy link
Contributor Author

/retest

@chrislovecnm chrislovecnm force-pushed the kubectl-commands branch 3 times, most recently from b466386 to c618df5 Compare November 9, 2018 00:50
@chrislovecnm
Copy link
Contributor Author

@nlopezgi PTAL

@chrislovecnm chrislovecnm force-pushed the kubectl-commands branch 2 times, most recently from eba56a8 to d627ab0 Compare November 9, 2018 01:00
@chrislovecnm
Copy link
Contributor Author

/retest

chrislovecnm added 4 commits November 9, 2018 11:00
Added kubectl_args to apply, delete, describe, create and replace
kubectl commands.

This PR adds a parameter to pass in arguments to kubectl.  For intance
a user can pass in "-v=10 --dry-run=true" to kubectl.  This work is
based off of @omadawn's work.
Allows for the passing in of arguments to kubectl via a cli run command

Adding the capability of using $@ ie. args with kubectl commands.
- modified the java hellohttp example BUILD file to include --v=2 kubectl_args
- added test for --v=2 in BUILD file
- added test for passing in an argument via the cli
@@ -394,6 +394,16 @@ Users can "describe" their environment by running:
bazel run :dev.describe
```

### kubectl Arguments Via the Command Line

The apply, create, delete, and describe commands will accept kubectl arguments passed in
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: wrap line at 80 chars

# also tests that --help can be passed in as a cli argument
check_kubectl_args() {

# checking that --v=2 is passed in via kubect_arguments in
Copy link
Contributor

Choose a reason for hiding this comment

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

s/kubect_arguments/kubectl_args

# the java BUILD file
FILE="./bazel-bin/examples/hellohttp/java/staging.apply"
echo Checking kubectl args in file: "$FILE"
bazel build examples/hellohttp/java:staging.apply
Copy link
Contributor

Choose a reason for hiding this comment

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

what a painful way to test, thanks for setting it up, but we do need some infrastructure to make this easier

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it works 😆

Copy link
Contributor

Choose a reason for hiding this comment

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

Found in the rules_docker e2e tests that we have some sort of crude infrastructure to do some basic checks, for example, that a file contains a string:
https://github.com/bazelbuild/rules_docker/blob/master/testing/e2e.sh#L45
This checks that the output of bazel run has some flags:
https://github.com/bazelbuild/rules_docker/blob/master/testing/e2e.sh#L281
should be simpler than what you have here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

what I have works ... why change it? 🤷‍♂️
I think we really need to FIX it 😆

@@ -172,13 +172,22 @@ def _common_impl(ctx):

kubectl_tool_info = ctx.toolchains["@io_bazel_rules_k8s//toolchains/kubectl:toolchain_type"].kubectlinfo

kubectl_args = " ".join(ctx.attr.kubectl_args or [])
Copy link
Contributor

@nlopezgi nlopezgi Nov 9, 2018

Choose a reason for hiding this comment

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

Ok, so lets make this simple then, lets start w/o supporting make variable expansion and just avoid needing all this code (we can add it later if we need to).
Based off that assumption, all you need here is this line:
kubectl_args = " ".join(ctx.attr.kubectl_args)

(no need to have the or if default is set below in line 238)
and everything between lines 176-180 can go away.
and then just do
"%{kubectl_args}": kubectl_args,
in line 190 below

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we can add it later if we need to

Is there a reason we don't add it now? I will update the code as you recommended, just want to learn more :)

@@ -226,6 +235,7 @@ _common_attrs = {
executable = True,
allow_files = True,
),
"kubectl_args": attr.string_list(),
Copy link
Contributor

Choose a reason for hiding this comment

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

set this with default:
"kubectl_args": attr.string_list(default = []),

@chrislovecnm
Copy link
Contributor Author

Closing cause we have #224

Coming in

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants