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

UPSTREAM: 53606: use deployment pod template if 0 replicas #16379

Conversation

juanvallejo
Copy link
Contributor

@juanvallejo juanvallejo commented Sep 15, 2017

Fixes #14286
Fixes #14915

Prevent oc debug from hanging indefinitely when dealing
with a deployment that has been scaled down to 0.

cc @openshift/cli-review @smarterclayton

@openshift-ci-robot openshift-ci-robot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Sep 15, 2017
template, err := f.ApproximatePodTemplateForObject(infos[0].Object)
if err != nil && template == nil {
return fmt.Errorf("cannot debug %s: %v", infos[0].Name, err)
var template *kapi.PodTemplateSpec
Copy link
Contributor

Choose a reason for hiding this comment

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

Why wouldn't we always use ApproximatePodTemplateForObject for debug?

Copy link
Contributor

Choose a reason for hiding this comment

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

ApproximatePodTemplateForObject shouldn't wait for pods under DC

Copy link
Contributor Author

@juanvallejo juanvallejo Sep 15, 2017

Choose a reason for hiding this comment

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

With a deployment object, the default case was being hit here, as its type resolved to *extensions.Deployment. It then got stuck in the call to f.AttachablePodForObject. I could add a new case to the switch for *extensions.Deployment with the same logic as the *deployapi.DeploymentConfig case. wdyt?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

There should be an "approximatepodtemplateforobject" for RCs and RSs and Deployments and StatefulSets and Daemonsets upstream that doesn't depend on pods existing. So I would expect to always be using approximate pod template and for it to never block.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Without adding the case for *extensions.Deployment, current behavior hits the default case in https://github.com/openshift/origin/blob/master/pkg/cmd/util/clientcmd/factory.go#L209. Then AttachablePodForObject method is called on factory_object_mapping upstream with a timeout of 1 min.

Here is where the blocking seems to be happening.

Another possible solution could be to skip the call to AttachablePodForObject altogether if there are 0 replicas, and add a new type switch case for *extensions.Deployment here that just returns t.Spec.Template

Copy link
Contributor

Choose a reason for hiding this comment

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

Don't call AttachablePodForObject ever. ApproximatePodTemplateforObject should always be used for debug all the way down, and nothing in APTFO should ever wait for a container to start (it doesn't have to). attach requires a running pod, debug does not.

@juanvallejo juanvallejo force-pushed the jvallejo/fix-debug-on-deployment-w-0-replicas branch 2 times, most recently from edb4c59 to a26a37e Compare September 15, 2017 18:15
@0xmichalis
Copy link
Contributor

/retest

1 similar comment
@0xmichalis
Copy link
Contributor

/retest

@openshift-ci-robot openshift-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Sep 18, 2017
@juanvallejo
Copy link
Contributor Author

@smarterclayton

There should be an "approximatepodtemplateforobject" for RCs and RSs and Deployments and StatefulSets and Daemonsets upstream that doesn't depend on pods existing. So I would expect to always be using approximate pod template and for it to never block.

Thanks, added ApproximatePodTemplateForObject to upstream factory to handle upstream types. Also removed use of AttachablePodForObject from this method downstream.

@juanvallejo
Copy link
Contributor Author

/retest

@juanvallejo juanvallejo force-pushed the jvallejo/fix-debug-on-deployment-w-0-replicas branch 2 times, most recently from cfcfe3d to 19c54c2 Compare September 18, 2017 17:41
@juanvallejo
Copy link
Contributor Author

/retest

@juanvallejo juanvallejo force-pushed the jvallejo/fix-debug-on-deployment-w-0-replicas branch 2 times, most recently from a63cf37 to dca2dc3 Compare September 20, 2017 14:51
@juanvallejo
Copy link
Contributor Author

/retest

@juanvallejo
Copy link
Contributor Author

ping @smarterclayton

@fabianofranz
Copy link
Member

/unassign
/assign @smarterclayton

@smarterclayton
Copy link
Contributor

Test case for test-cmd that uses an RC scaled to zero and a DC scaled to zero to prove it works.

@juanvallejo juanvallejo force-pushed the jvallejo/fix-debug-on-deployment-w-0-replicas branch from 7588e37 to c547f05 Compare September 25, 2017 19:08
@juanvallejo
Copy link
Contributor Author

@smarterclayton

Test case for test-cmd that uses an RC scaled to zero and a DC scaled to zero to prove it works.

Thanks, done

@juanvallejo juanvallejo force-pushed the jvallejo/fix-debug-on-deployment-w-0-replicas branch from eb8ee57 to 094634d Compare September 25, 2017 20:44
@openshift-merge-robot openshift-merge-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 29, 2017

for i := range pods.Items {
pod := &pods.Items[i]
if fallback == nil || pod.CreationTimestamp.Before(fallback.CreationTimestamp) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why wouldn't you return the first pod no matter what, instead of the fallback?

Copy link
Contributor

Choose a reason for hiding this comment

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

Are you looking for pods newer than the most recent deployment?

Copy link
Contributor Author

@juanvallejo juanvallejo Oct 2, 2017

Choose a reason for hiding this comment

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

@smarterclayton Yeah, this is existing code that I moved from the clientcmd/factory to clientcmd/factory_object_mapping. Can update the logic to just return the first pod if any exists instead, if that is a better approach

Copy link
Contributor

Choose a reason for hiding this comment

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

Hrm, it's probably fine. I just wasn't sure why it is here. Add a comment to this section that describes the algorithm.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, done! Will go ahead and open PR for upstream changes
if everything else looks okay

@juanvallejo juanvallejo force-pushed the jvallejo/fix-debug-on-deployment-w-0-replicas branch from 094634d to c8f4eb6 Compare October 9, 2017 17:44
@openshift-merge-robot openshift-merge-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 9, 2017
@juanvallejo
Copy link
Contributor Author

@smarterclayton friendly ping on #16379 (comment)

@juanvallejo juanvallejo force-pushed the jvallejo/fix-debug-on-deployment-w-0-replicas branch from e9cf687 to 2463610 Compare October 10, 2017 14:10
@juanvallejo
Copy link
Contributor Author

Thanks, done!

@juanvallejo
Copy link
Contributor Author

/retest

k8s-github-robot pushed a commit to kubernetes/kubernetes that referenced this pull request Oct 12, 2017
…mplate-factory-method

Automatic merge from submit-queue (batch tested with PRs 53606, 49361). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

add ApproximatePodTemplateForObject factory method

Makes it possible to get at a pod spec template even if an object is scaled to zero, for use with commands that care about pod templates.

**Release note**:

```release-note
NONE
```

Related downstream patch and use-case: openshift/origin#16379

cc @smarterclayton
@juanvallejo
Copy link
Contributor Author

juanvallejo commented Oct 12, 2017

@smarterclayton upstream dep has merged, ptal

@openshift-merge-robot openshift-merge-robot added vendor-update Touching vendor dir or related files needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Oct 14, 2017
@juanvallejo juanvallejo force-pushed the jvallejo/fix-debug-on-deployment-w-0-replicas branch from 2463610 to b0e827d Compare October 18, 2017 16:08
@openshift-merge-robot openshift-merge-robot added needs-upstream and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Oct 18, 2017
@juanvallejo
Copy link
Contributor Author

/test extended_conformance_gce

@juanvallejo
Copy link
Contributor Author

/test extended_conformance_gce
/test extended_conformance_install_update

@juanvallejo
Copy link
Contributor Author

/retest

1 similar comment
@juanvallejo
Copy link
Contributor Author

/retest

@juanvallejo
Copy link
Contributor Author

/test extended_conformance_gce

@juanvallejo juanvallejo force-pushed the jvallejo/fix-debug-on-deployment-w-0-replicas branch from b0e827d to 0598c2d Compare October 20, 2017 20:13
@juanvallejo
Copy link
Contributor Author

/test extended_conformance_gce

@juanvallejo
Copy link
Contributor Author

@smarterclayton friendly ping - wondering if you could tag this for merging

@juanvallejo
Copy link
Contributor Author

/kind bug

@openshift-ci-robot openshift-ci-robot added the kind/bug Categorizes issue or PR as related to a bug. label Oct 25, 2017
@smarterclayton
Copy link
Contributor

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Oct 25, 2017
@openshift-merge-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: juanvallejo, smarterclayton

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

Needs approval from an approver in each of these OWNERS Files:

You can indicate your approval by writing /approve in a comment
You can cancel your approval by writing /approve cancel in a comment

@openshift-merge-robot openshift-merge-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 25, 2017
@openshift-merge-robot
Copy link
Contributor

Automatic merge from submit-queue.

@openshift-merge-robot openshift-merge-robot merged commit 598a4ac into openshift:master Oct 25, 2017
@juanvallejo juanvallejo deleted the jvallejo/fix-debug-on-deployment-w-0-replicas branch October 26, 2017 15:08
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. kind/bug Categorizes issue or PR as related to a bug. lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. vendor-update Touching vendor dir or related files
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants