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

kubectl wait: Introduce --wait-for-creation flag #122994

Merged

Conversation

ardaguclu
Copy link
Member

@ardaguclu ardaguclu commented Jan 26, 2024

What type of PR is this?

/kind feature

What this PR does / why we need it:

This PR introduces new --wait-for-creation flag to also wait for the creation of resources with
preserving the default behavior.

Which issue(s) this PR fixes:

Fixes kubernetes/kubectl#1516, kubernetes/kubectl#1487

Does this PR introduce a user-facing change?

NONE

(release note cleared since this was rolled back in #125630, original release note below)

`kubectl wait` will now wait for resources to be created by default. Please use the new `--wait-for-creation=false` flag for the previous behavior of immediately failing if the specified resource does not yet exist.

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. kind/feature Categorizes issue or PR as related to a new feature. labels Jan 26, 2024
@ardaguclu ardaguclu marked this pull request as draft January 26, 2024 12:58
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Jan 26, 2024
@k8s-ci-robot k8s-ci-robot added area/kubectl area/test sig/cli Categorizes an issue or PR as relevant to SIG CLI. sig/testing Categorizes an issue or PR as relevant to SIG Testing. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Jan 26, 2024
@ardaguclu ardaguclu force-pushed the wait-non-existed-resources branch from 0594661 to e9a9207 Compare February 16, 2024 08:49
@ardaguclu ardaguclu changed the title Add new --wait-non-existence flag in kubectl wait command kubectl wait: Introduce --wait-for-creation flag Feb 16, 2024
@ardaguclu ardaguclu marked this pull request as ready for review February 16, 2024 08:51
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Feb 16, 2024
@ardaguclu
Copy link
Member Author

/triage accepted
/priority important-long-term

@k8s-ci-robot k8s-ci-robot added the triage/accepted Indicates an issue or PR is ready to be actively worked on. label Feb 16, 2024
@k8s-ci-robot
Copy link
Contributor

@ardaguclu: The label(s) priority/important-long-term cannot be applied, because the repository doesn't have them.

In response to this:

/triage accepted
/priority important-long-term

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 removed the needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. label Feb 16, 2024
@ardaguclu ardaguclu force-pushed the wait-non-existed-resources branch from e9a9207 to d1408d1 Compare February 16, 2024 08:53
@ardaguclu
Copy link
Member Author

/priority important-longterm

@k8s-ci-robot k8s-ci-robot added the priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. label Feb 16, 2024
@ardaguclu ardaguclu force-pushed the wait-non-existed-resources branch from b474a40 to 17cd4de Compare June 3, 2024 10:28
@k8s-ci-robot k8s-ci-robot added area/code-generation sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. sig/auth Categorizes an issue or PR as relevant to SIG Auth. and removed approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Jun 3, 2024
@ardaguclu ardaguclu force-pushed the wait-non-existed-resources branch from 17cd4de to 7a8faf9 Compare June 3, 2024 10:30
@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 3, 2024
kubectl wait command errors out when the waited resource does not exist.
But we need to provide a way to the users about intentionally also waiting for
the creation of resources.

This PR introduces a new flag to cover waiting for the creation of resources
with preserving the default behavior.
@ardaguclu ardaguclu force-pushed the wait-non-existed-resources branch from 7a8faf9 to e24b9a0 Compare June 3, 2024 10:31
@ardaguclu
Copy link
Member Author

unrelated
/lgtm

@k8s-ci-robot
Copy link
Contributor

@ardaguclu: you cannot LGTM your own PR.

In response to this:

unrelated
/lgtm

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-sigs/prow repository.

@ardaguclu
Copy link
Member Author

not lgtm :)
/retest

@sftim
Copy link
Contributor

sftim commented Jun 12, 2024

It's all green! Thanks @ardaguclu

@eddiezane
Copy link
Member

/release-note-edit

`kubectl wait` will now wait for resources to be created by default. Please use the new `--wait-for-creation=false` flag for the previous behavior. 

@eddiezane
Copy link
Member

/release-note-edit

`kubectl wait` will now wait for resources to be created by default. Please use the new `--wait-for-creation=false` flag for the previous behavior of immediately failing if the specified resource does not yet exist. 

Copy link
Member

@eddiezane eddiezane left a comment

Choose a reason for hiding this comment

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

Nice work!

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 20, 2024
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: 8fa76aa7cbf4937ba3ada79a9b65f40bdf7d43c1

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ardaguclu, eddiezane

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

@k8s-ci-robot k8s-ci-robot merged commit b95fce1 into kubernetes:master Jun 20, 2024
15 checks passed
@k8s-ci-robot k8s-ci-robot added this to the v1.31 milestone Jun 20, 2024
@ardaguclu ardaguclu deleted the wait-non-existed-resources branch June 21, 2024 04:32
@@ -320,6 +328,40 @@ func (o *WaitOptions) RunWait() error {
ctx, cancel := watchtools.ContextWithOptionalTimeout(context.Background(), o.Timeout)
defer cancel()

isForDelete := strings.ToLower(o.ForCondition) == "delete"
if o.WaitForCreation && o.Timeout == 0 {
return fmt.Errorf("--wait-for-creation requires a timeout value greater than 0")
Copy link
Member

@liggitt liggitt Jun 21, 2024

Choose a reason for hiding this comment

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

This is a regressing change for folks using --timeout=0 as documented:

The length of time to wait before giving up. Zero means check once and don't wait.

Previously, this would check a condition once:

kubectl wait --for=condition=Available deployments --all --timeout=0

Now, it fails with:

error: --wait-for-creation requires a timeout value greater than 0

I'm not sure defaulting WaitForCreation to true is compatible here. Rollback in #125630 with a test added to exercise the --timeout=0 case so this can be brought back in more compatibly.

Copy link
Member Author

Choose a reason for hiding this comment

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

Does that mean if the timeout=0, we should ignore the waitforcreation step and mention this in the flag description?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because when timeout=0, ConditionFn will be executed once and returns

Copy link
Member Author

@ardaguclu ardaguclu Jun 21, 2024

Choose a reason for hiding this comment

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

yeah, it (L:336) should be something like this;

if o.WaitForCreation && !isForDelete && o.Timeout != 0 {

Copy link
Member

@liggitt liggitt Jun 21, 2024

Choose a reason for hiding this comment

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

Please use the new --wait-for-creation=false flag for the previous behavior of immediately failing if the specified resource does not yet exist.

That sounds like this is changing existing behavior, which doesn't really match the description of This PR introduces new --wait-for-creation flag to also wait for the creation of resources with preserving the default behavior.

Would it be simpler and more compatible to default WaitForCreation to false? Then that would be reasonable to forbid WaitForCreation and Timeout of 0, or WaitForCreation and isForDelete.

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree with you. Besides, we can change the default separately in the future after carefully considering what we should do for such cases.

Copy link
Member Author

Choose a reason for hiding this comment

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

@eddiezane what do you think about bringing same PR back just the default value is false?

@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. and removed release-note Denotes a PR that will be considered when it comes time to generate release notes. labels Jun 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/code-generation area/kubectl area/test cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/feature Categorizes issue or PR as related to a new feature. lgtm "Looks good to me", indicates that a PR is ready to be merged. priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. release-note-none Denotes a PR that doesn't merit a release note. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. sig/auth Categorizes an issue or PR as relevant to SIG Auth. 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. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
Archived in project
Archived in project
Development

Successfully merging this pull request may close these issues.

kubectl wait for un-existed resource.
7 participants