Thanks to visit codestin.com
Credit goes to github.com

Skip to content

kubectl: add env option to deployment creation #93269

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

Closed

Conversation

Xercoy
Copy link

@Xercoy Xercoy commented Jul 20, 2020

What type of PR is this?
/kind feature

What this PR does / why we need it:
Creating a deployment using kubectl with environment variables was done with kubectl run. Since most of the generators have been deprecated, including the one for deployments (#87077), this PR adds functionality to the preferred method of deployment creation, kubectl create deployment.

I think this feature would be useful in providing more flexibility for deployments with kubectl create. Additionally, resources related to deployment creation with environment variables via kubectl run can be updated and remain useful rather than eventually being deprecated.

I did not create an issue/enhancement beforehand but I would be more than happy to do so. Apologies especially in case I had missed any content which deemed that this feature shouldn't be implemented.

Supporting documentation/PRs:

and also attached in the docs section.

Special notes for your reviewer:
In addition to running and providing tests, I built the kubectl binary and tested that the new flag/feature works as expected; the intent is for its behavior to be similar to how the flag was in kubectl run.

Please let me know if any changes or amendments should be made, or if I'm not adhering to any guidelines or processes. Would also be more than happy to refactor any recommendations for changes.

Thank you very much to all reviewers, maintainers, and contributors for the time and effort!

Does this PR introduce a user-facing change?:
Yes, this will add an optional flag --env which expects a key value pair of an environment name and value. This flag can be repeated to provide multiple environment variables.

Added the --env flag to allow environment variables to be provided to deployments made with kubectl create. 
- [#91113](https://github.com/kubernetes/kubernetes/pull/91113)
- [#87077](https://github.com/kubernetes/kubernetes/pull/87077)
- [#68132](https://github.com/kubernetes/kubernetes/pull/68132)

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/feature Categorizes issue or PR as related to a new feature. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Jul 20, 2020
@k8s-ci-robot
Copy link
Contributor

Welcome @Xercoy!

It looks like this is your first PR to kubernetes/kubernetes 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes/kubernetes has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot
Copy link
Contributor

Hi @Xercoy. Thanks for your PR.

I'm waiting for a kubernetes 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.

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Jul 20, 2020
@Xercoy
Copy link
Author

Xercoy commented Jul 20, 2020

/cc @kubernetes/sig-cli-api-reviews @kubernetes/sig-cli-pr-reviews
/sig cli

@k8s-ci-robot k8s-ci-robot added sig/cli Categorizes an issue or PR as relevant to SIG CLI. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API and removed needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Jul 20, 2020
@k8s-ci-robot
Copy link
Contributor

@Xercoy: Reiterating the mentions to trigger a notification:
@kubernetes/sig-cli-api-reviews, @kubernetes/sig-cli-pr-reviews

In response to this:

/cc @kubernetes/sig-cli-api-reviews @kubernetes/sig-cli-pr-reviews
/sig cli

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.

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Xercoy
To complete the pull request process, please assign brendandburns
You can assign the PR to them by writing /assign @brendandburns in a comment when ready.

The full list of commands accepted by this bot can be found 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

@k8s-ci-robot k8s-ci-robot added area/kubectl area/test sig/testing Categorizes an issue or PR as relevant to SIG Testing. labels Jul 20, 2020
@fejta-bot
Copy link

This PR may require API review.

If so, when the changes are ready, complete the pre-review checklist and request an API review.

Status of requested reviews is tracked in the API Review project.

Copy link
Contributor

@zhouya0 zhouya0 left a comment

Choose a reason for hiding this comment

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

Code lgtm but:
The main goal is to make create command simple as possible, other need to create deployment should use kubectl apply instead. Before we add --port, --replicas flag since they are commonly used in deployment . Not sure we really want to continue add more.

@Xercoy
Copy link
Author

Xercoy commented Jul 21, 2020

@zhouya0 , thank you for the quick review! I definitely agree with you in that kubectl create deployment should be as simple as possible.

For whatever purposes that are required when using kubectl to create a deployment, whether it's debugging, testing, learning, or teaching, I agree and say that you're right again in that the previous options that were added affect configurations which are commonly used in deployments:

  • --port: the ability to specify a port for a deployment

  • --replicas: the ability to control the number of replicas

  • the ability to provide a command to a deployment

I also think that the ability to provide a deployment with environment variables can also be considered a core configuration of a deployment. I believe that it is commonly used and that the benefits from this feature would outweigh the simplicity that the changes in this PR removes.

The flags listed above enable users to create a deployment which dictates the command, number of replicas, and port. One of the most important pieces of an application's operations are configuration values; many applications need some kind of configuration values to run smoothly. Adding --env provides the create command with the ability to create deployments with the information they need to run, if such configuration is necessary.

Manipulating deployments with kubectl apply or through Helm charts are definitely the best way to have the most control and customization, but I still think that use cases for kubectl create would largely benefit from having --env. The create command is much more than capable of creating deployments for images other than busybox or nginx. This flag would improve on that capability by providing deployments with data that they may need to run.

From my perspective as a user, someone who shares knowledge about Kubernetes, and one who still tries to use kubectl run for many things, this PR improves how deployments can be created with the create command.

As a contributor with this PR, the changes make use of utility/helper functions that already exist, includes tests, and adds code changes that matches how other flags are handled, such as --replicas and --port. In my opinion, this last detail keeps things simple and ensures that refactoring is just as easy (I hope), or at least not too difficult.

While I do agree with you on both points in that the create command should be as simple as possible, and again when you mentioned that the flags mentioned above are commonly used in deployments, adding --env and regarding it as commonly a used configuration from the points I mentioned should be considered.

Of course, I defer the decision to validate the need for this PR to you and the consensus of the community. Overall, it's been an awesome learning experience and a great chance to collaborate and make contributions to a project that has given so much to me. Thanks again.

@zhouya0
Copy link
Contributor

zhouya0 commented Jul 21, 2020

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jul 21, 2020
@Xercoy
Copy link
Author

Xercoy commented Jul 21, 2020

/retest - for flakiness

@Xercoy
Copy link
Author

Xercoy commented Jul 22, 2020

/retest

@Xercoy
Copy link
Author

Xercoy commented Jul 22, 2020

/retest

@Xercoy
Copy link
Author

Xercoy commented Jul 22, 2020

@zhouya0 while Tide is mentioning that this PR isn't mergeable yet, all tests are passing. Thanks again for the review and enabling tests! For the time being, I'll try to promote visibility but please let me know if there's anything else I can do to help.

"SingleEnvVar",
[]string{
"FOO=bar",
"FIZZ=buzz",
Copy link
Author

Choose a reason for hiding this comment

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

This test case should have only one env var set, will fix.

@Xercoy
Copy link
Author

Xercoy commented Jul 23, 2020

/retest

1 similar comment
@Xercoy
Copy link
Author

Xercoy commented Jul 23, 2020

/retest

@Xercoy
Copy link
Author

Xercoy commented Jul 23, 2020

/priority backlog

@k8s-ci-robot k8s-ci-robot added priority/backlog Higher priority than priority/awaiting-more-evidence. and removed needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Jul 23, 2020
@eddiezane
Copy link
Member

eddiezane commented Aug 12, 2020

Holding this while we explore other options as discussed in SIG-CLI meeting.

/hold

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Aug 12, 2020
@fejta-bot
Copy link

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Nov 10, 2020
@fejta-bot
Copy link

Stale issues rot after 30d of inactivity.
Mark the issue as fresh with /remove-lifecycle rotten.
Rotten issues close after an additional 30d of inactivity.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle rotten

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Dec 10, 2020
@fejta-bot
Copy link

Rotten issues close after 30d of inactivity.
Reopen the issue with /reopen.
Mark the issue as fresh with /remove-lifecycle rotten.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/close

@k8s-ci-robot
Copy link
Contributor

@Xercoy: PR needs rebase.

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.

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 9, 2021
@k8s-ci-robot
Copy link
Contributor

@fejta-bot: Closed this PR.

In response to this:

Rotten issues close after 30d of inactivity.
Reopen the issue with /reopen.
Mark the issue as fresh with /remove-lifecycle rotten.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/close

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/kubectl area/test cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API kind/feature Categorizes issue or PR as related to a new feature. lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. priority/backlog Higher priority than priority/awaiting-more-evidence. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/cli Categorizes an issue or PR as relevant to SIG CLI. sig/testing Categorizes an issue or PR as relevant to SIG Testing. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants