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

describer: improve job and pod template output #122618

Merged
merged 1 commit into from
Jan 23, 2024

Conversation

ivanvc
Copy link
Member

@ivanvc ivanvc commented Jan 6, 2024

What type of PR is this?

/kind feature

What this PR does / why we need it:

  • Add Node-Selectors and Tolerations to pod template's describe output.
  • Add Suspend to job's describe output.

Which issue(s) this PR fixes:

Fixes #122613

Special notes for your reviewer:

Does this PR introduce a user-facing change?

`kubectl describe`: added Suspend to job, and Node-Selectors and Tolerations to pod template output

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:


@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/S Denotes a PR that changes 10-29 lines, ignoring generated files. kind/feature Categorizes issue or PR as related to a new feature. labels Jan 6, 2024
Copy link

linux-foundation-easycla bot commented Jan 6, 2024

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: ivanvc / name: Iván Valdés Castillo (6d65c06)

@k8s-ci-robot k8s-ci-robot added do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Jan 6, 2024
@k8s-ci-robot
Copy link
Contributor

Welcome @ivanvc!

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 k8s-ci-robot added needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jan 6, 2024
@k8s-ci-robot
Copy link
Contributor

Hi @ivanvc. 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 needs-priority Indicates a PR lacks a `priority/foo` label and requires one. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Jan 6, 2024
@k8s-ci-robot k8s-ci-robot added area/kubectl sig/cli Categorizes an issue or PR as relevant to SIG CLI. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Jan 6, 2024
@HirazawaUi
Copy link
Contributor

/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 Jan 6, 2024
@ivanvc ivanvc force-pushed the improve-describe-job-output branch from 2106366 to 243b6fc Compare January 11, 2024 18:51
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jan 11, 2024
@ivanvc ivanvc force-pushed the improve-describe-job-output branch from 243b6fc to c8fa972 Compare January 11, 2024 19:44
@ivanvc ivanvc requested a review from kaisoz January 11, 2024 22:45
@ivanvc ivanvc force-pushed the improve-describe-job-output branch from c8fa972 to ff888ee Compare January 17, 2024 21:03
@ivanvc ivanvc requested a review from kaisoz January 17, 2024 21:03
@kaisoz
Copy link
Contributor

kaisoz commented Jan 17, 2024

/lgtm

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

LGTM label has been added.

Git tree hash: dda7e67465193879ad1d0d5caeefaf7c53ddb025

Copy link
Contributor

@mimowo mimowo left a comment

Choose a reason for hiding this comment

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

Thanks. LGTM overall, suggesting to print out other missing, important GA fields: BackoffLimit and TTLSecondsAfterFinished.

We also have a bunch of Beta-level fields in Job (such as PodFailurePolicy, BackoffLimitPerIndex, or PodReplacementPolicy), but I think it is ok to put them in a follow-up PR/Issue to make the distinction (or just wait for GA-level and print as they graduate).

@@ -2516,8 +2519,8 @@ func TestDescribeDeployment(t *testing.T) {
expects: []string{
"Replicas: 2 desired | 1 updated | 3 total | 2 available | 1 unavailable",
"Image: mytest-image:v2.0",
"OldReplicaSets: bar-001 (2/2 replicas created)",
"NewReplicaSet: bar-002 (1/1 replicas created)",
"OldReplicaSets: bar-001 (2/2 replicas created)",
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: revert unrelated formatting changes

Copy link
Contributor

Choose a reason for hiding this comment

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

When updating the above, please make sure to also address this one.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hey @mimowo, the tests fail if I don't add the extra spaces here. I think it's due to the alignment of tabs with Node-Selectors. See:

--- FAIL: TestDescribeDeployment (0.00s)                                                                                                      
    --- FAIL: TestDescribeDeployment/deployment_during_the_process_of_rolling_out (0.00s) 
        describe_test.go:2839: expected to find "OldReplicaSets:  bar-001 (2/2 replicas created)" in:                
             Name:               bar                                                                                                          
            Namespace:          foo                                                                                                           
            CreationTimestamp:  Fri, 01 Jan 2021 00:00:00 +0000                                                                               
            Labels:             k8s-app=bar                                                                                                   
            Annotations:        <none>
            Selector:           k8s-app=bar
            Replicas:           2 desired | 1 updated | 3 total | 2 available | 1 unavailable
            StrategyType:                  
            MinReadySeconds:    0     
            Pod Template:                  
              Labels:  k8s-app=bar                                                                                                            
              Containers:       
               :                 
                Image:        mytest-image:v2.0
                Port:         <none>
                Host Port:    <none>
                Environment:  <none>
                Mounts:                        
                  /tmp/vol-bar from vol-bar (rw)
                  /tmp/vol-foo from vol-foo (rw)
              Volumes:              
               vol-foo:
                Type:       EmptyDir (a temporary directory that shares a pod's lifetime)
                Medium:                         
                SizeLimit:  <unset>
               vol-bar:
                Type:          EmptyDir (a temporary directory that shares a pod's lifetime)
                Medium:        
                SizeLimit:     <unset>
              Node-Selectors:  <none>
              Tolerations:     <none>                                                                                                         
            OldReplicaSets:    bar-001 (2/2 replicas created)
            NewReplicaSet:     bar-002 (1/1 replicas created)
            Events:                  
              Type    Reason             Age                From                   Message
              ----    ------             ----               ----                   -------
              Normal  ScalingReplicaSet  12m (x3 over 20m)  deployment-controller  Scaled up replica set bar-002 to 1
              Normal  ScalingReplicaSet  10m                deployment-controller  Scaled up replica set bar-001 to 2
              Normal  ScalingReplicaSet  2m                 deployment-controller  Scaled up replica set bar-002 to 1
              Normal  ScalingReplicaSet  60s                deployment-controller  Scaled down replica set bar-002 to 1

Copy link
Contributor

Choose a reason for hiding this comment

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

I see, indeed the values for Node-Selectors Tolerations and OldReplicaSets are aligned in the full output.

Out of curiosity, I'm wondering where is the code / mechanism which determines the shift of OldReplicaSets to align it. Can you find it out? So that we better understand the intent, because some values are out of alignment, for example Volumes.vol-foo.Type.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is the code for the empty dir volume: https://github.com/kubernetes/kubernetes/blob/d2b16b2/staging/src/k8s.io/kubectl/pkg/describe/describe.go#L1028-L1039
From reading the code, the value should be aligned, as it seems just a tab. This is the code for OldReplicaSets: https://github.com/kubernetes/kubernetes/blob/d2b16b2/staging/src/k8s.io/kubectl/pkg/describe/describe.go#L4372-L4375

@@ -2313,6 +2315,9 @@ func describeJob(job *batchv1.Job, events *corev1.EventList) (string, error) {
if job.Spec.Parallelism != nil {
w.Write(LEVEL_0, "Parallelism:\t%d\n", *job.Spec.Parallelism)
}
if job.Spec.Suspend != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we also print: BackoffLimit and TTLSecondsAfterFinished? These are other important GA-level fields. There is also ManualSelector, but I'm not sure it is relevant enough.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd advice against manualSelector, this should be used very cautiously and rarely. The other two are ok addition.

Copy link
Contributor

Choose a reason for hiding this comment

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

My biggest concern is you're adding this between two important parameters, parallelism and completions, which I frequently look at together. I'd suggest to move suspend printing below completion mode or before parallelism, iow:
your current output looks like:

Annotations:              <none>
Parallelism:              1
Suspend:                  false
Completions:              1
Completion Mode:          NonIndexed
Start Time:               Mon, 11 Dec 2023 15:18:09 +0100

but I'd suggest to have (suspend before parallelism):

Annotations:              <none>
Suspend:                  false
Parallelism:              1
Completions:              1
Completion Mode:          NonIndexed
Start Time:               Mon, 11 Dec 2023 15:18:09 +0100

or (suspend after completion mode)

Annotations:              <none>
Parallelism:              1
Completions:              1
Completion Mode:          NonIndexed
Suspend:                  false
Start Time:               Mon, 11 Dec 2023 15:18:09 +0100

Copy link
Member Author

Choose a reason for hiding this comment

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

@soltysh, any suggestion on where to place BackoffLimit and TTLSecondsAfterFinished? I'm assuming, going with your last suggestion, after Suspend and before Start Time. But I just wanted to check if you have an opinion here.

Copy link
Contributor

@mimowo mimowo Jan 19, 2024

Choose a reason for hiding this comment

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

For me pretty much every configuration works, just don't split the Parallelism, completions and completionMode, as pointed out.

If I were to suggest something then maybe:

Annotations:      batch.kubernetes.io/cronjob-scheduled-timestamp: 2024-01-19T08:48:00Z
Controlled By:    CronJob/hello
Parallelism:      1
Completions:      1
Completion Mode:  NonIndexed
**Backoff Limit:**          6 
**TTL Seconds After Finished**: 21  # seems reasonable to be close to `Completed At`
Start Time:       Fri, 19 Jan 2024 09:48:00 +0100
Completed At:     Fri, 19 Jan 2024 09:48:13 +0100
Duration:         13s

Copy link
Member Author

@ivanvc ivanvc Jan 19, 2024

Choose a reason for hiding this comment

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

Done, it now looks like the following:

            Name:                        bar
            Namespace:                   foo
            Selector:                    
            Labels:                      <none>
            Annotations:                 <none>
            Completions:                 <unset>
            Suspend:                     true
            Backoff Limit:               1
            TTL Seconds After Finished:  123
            Pods Statuses:               0 Active / 0 Succeeded / 0 Failed
            Pod Template:
              Labels:  <none>
              Containers: <none>
              Volumes:         <none>
              Node-Selectors:  <none>
              Tolerations:     <none>
            Events:            <none>

If these values are not specified, it omits them:

            Name:           bar
            Namespace:      foo
            Selector:       
            Labels:         <none>
            Annotations:    <none>
            Completions:    <unset>
            Pods Statuses:  0 Active / 0 Succeeded / 0 Failed
            Pod Template:
              Labels:  <none>
              Containers: <none>
              Volumes:         <none>
              Node-Selectors:  <none>
              Tolerations:     <none>
            Events:            <none>

@soltysh
Copy link
Contributor

soltysh commented Jan 18, 2024

/triage accepted
/priority important-longterm

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. and removed 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. labels Jan 18, 2024
Copy link
Contributor

@soltysh soltysh left a comment

Choose a reason for hiding this comment

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

@ivanvc once you address the comments pls ping me on slack

@@ -2313,6 +2315,9 @@ func describeJob(job *batchv1.Job, events *corev1.EventList) (string, error) {
if job.Spec.Parallelism != nil {
w.Write(LEVEL_0, "Parallelism:\t%d\n", *job.Spec.Parallelism)
}
if job.Spec.Suspend != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd advice against manualSelector, this should be used very cautiously and rarely. The other two are ok addition.

@@ -2313,6 +2315,9 @@ func describeJob(job *batchv1.Job, events *corev1.EventList) (string, error) {
if job.Spec.Parallelism != nil {
w.Write(LEVEL_0, "Parallelism:\t%d\n", *job.Spec.Parallelism)
}
if job.Spec.Suspend != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

My biggest concern is you're adding this between two important parameters, parallelism and completions, which I frequently look at together. I'd suggest to move suspend printing below completion mode or before parallelism, iow:
your current output looks like:

Annotations:              <none>
Parallelism:              1
Suspend:                  false
Completions:              1
Completion Mode:          NonIndexed
Start Time:               Mon, 11 Dec 2023 15:18:09 +0100

but I'd suggest to have (suspend before parallelism):

Annotations:              <none>
Suspend:                  false
Parallelism:              1
Completions:              1
Completion Mode:          NonIndexed
Start Time:               Mon, 11 Dec 2023 15:18:09 +0100

or (suspend after completion mode)

Annotations:              <none>
Parallelism:              1
Completions:              1
Completion Mode:          NonIndexed
Suspend:                  false
Start Time:               Mon, 11 Dec 2023 15:18:09 +0100

@@ -2516,8 +2519,8 @@ func TestDescribeDeployment(t *testing.T) {
expects: []string{
"Replicas: 2 desired | 1 updated | 3 total | 2 available | 1 unavailable",
"Image: mytest-image:v2.0",
"OldReplicaSets: bar-001 (2/2 replicas created)",
"NewReplicaSet: bar-002 (1/1 replicas created)",
"OldReplicaSets: bar-001 (2/2 replicas created)",
Copy link
Contributor

Choose a reason for hiding this comment

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

When updating the above, please make sure to also address this one.

* Add Node-Selectors and Tolerations to pod template's describe output.
* Add Suspend, BackoffLimit and TTLSecondsAfterFinished to job's describe
  output.
@ivanvc ivanvc force-pushed the improve-describe-job-output branch from ff888ee to 6d65c06 Compare January 19, 2024 18:18
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jan 19, 2024
@ivanvc ivanvc requested a review from soltysh January 19, 2024 20:02
Copy link
Contributor

@soltysh soltysh left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

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

LGTM label has been added.

Git tree hash: 1373f785369cdb636b42ae78fe448f7f99f66b99

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ivanvc, soltysh

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 added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jan 23, 2024
@k8s-triage-robot
Copy link

The Kubernetes project has merge-blocking tests that are currently too flaky to consistently pass.

This bot retests PRs for certain kubernetes repos according to the following rules:

  • The PR does have any do-not-merge/* labels
  • The PR does not have the needs-ok-to-test label
  • The PR is mergeable (does not have a needs-rebase label)
  • The PR is approved (has cncf-cla: yes, lgtm, approved labels)
  • The PR is failing tests required for merge

You can:

/retest

@k8s-ci-robot k8s-ci-robot merged commit cf2003f into kubernetes:master Jan 23, 2024
14 checks passed
@k8s-ci-robot k8s-ci-robot added this to the v1.30 milestone Jan 23, 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/kubectl 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. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. 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. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

kubectl describe job should print key fields for scheduling (suspend, tolerations, nodeSelector)
7 participants