Skip to content

Commit

Permalink
Merge pull request kubernetes#50223 from tcharding/kubectl-run-dup
Browse files Browse the repository at this point in the history
Automatic merge from submit-queue. 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>.

Remove duplicate code fixing empty name error

**What this PR does / why we need it**:

Removes two helper functions which have duplicate code; code can be safely added to the calling function. This does add an extra parameter to calls. Since the helpers are file local functions with only two call sites it is trivial to see that this PR maintains current logic.

**Special notes for your reviewer**:

The diff is a bit convoluted since this PR [re]moves lines in consecutive functions.

**Release note**:
```release-note
NONE
```

/sig cli
/kind cleanup
  • Loading branch information
Kubernetes Submit Queue authored Oct 11, 2017
2 parents 494be59 + acae1d5 commit 82869c5
Showing 1 changed file with 5 additions and 21 deletions.
26 changes: 5 additions & 21 deletions pkg/kubectl/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ func RunRun(f cmdutil.Factory, cmdIn io.Reader, cmdOut, cmdErr io.Writer, cmd *c
leaveStdinOpen := cmdutil.GetFlagBool(cmd, "leave-stdin-open")
waitForExitCode := !leaveStdinOpen && restartPolicy == api.RestartPolicyNever
if waitForExitCode {
pod, err = waitForPodTerminated(clientset.Core(), attachablePod.Namespace, attachablePod.Name)
pod, err = waitForPod(clientset.Core(), attachablePod.Namespace, attachablePod.Name, conditions.PodCompleted)
if err != nil {
return err
}
Expand Down Expand Up @@ -416,33 +416,17 @@ func waitForPod(podClient coreclient.PodsGetter, ns, name string, exitCondition
}
return err
})
return result, err
}

func waitForPodRunning(podClient coreclient.PodsGetter, ns, name string) (*api.Pod, error) {
pod, err := waitForPod(podClient, ns, name, conditions.PodRunningAndReady)

// fix generic not found error with empty name in PodRunningAndReady
if err != nil && errors.IsNotFound(err) {
return nil, errors.NewNotFound(api.Resource("pods"), name)
}

return pod, err
}

func waitForPodTerminated(podClient coreclient.PodsGetter, ns, name string) (*api.Pod, error) {
pod, err := waitForPod(podClient, ns, name, conditions.PodCompleted)

// fix generic not found error with empty name in PodCompleted
// Fix generic not found error.
if err != nil && errors.IsNotFound(err) {
return nil, errors.NewNotFound(api.Resource("pods"), name)
err = errors.NewNotFound(api.Resource("pods"), name)
}

return pod, err
return result, err
}

func handleAttachPod(f cmdutil.Factory, podClient coreclient.PodsGetter, ns, name string, opts *AttachOptions) error {
pod, err := waitForPodRunning(podClient, ns, name)
pod, err := waitForPod(podClient, ns, name, conditions.PodRunningAndReady)
if err != nil && err != conditions.ErrPodCompleted {
return err
}
Expand Down

0 comments on commit 82869c5

Please sign in to comment.