Skip to content

Commit

Permalink
Improve NewPodControllerForExistingPod to set podReady to true (#…
Browse files Browse the repository at this point in the history
…2623)

* Improve `NewPodControllerForExistingPod` to set `podReady` to true

`NewPodControllerForExistingPod` function was supposed to return the
podController for an existing pod. If this function is caleld, it would mean
that the pod is already runnign and we are creating `podController` for that
pod.
But this function didn't set `podReady` field of podController to true that
was beign checked in some other methods to make sure that the pod is running.
And because of that those methods would see the pod to be not running and
complain.
This commit fixes that by making sure that the pod is running and sets
`podReady` to true.

* Improve comment to function
  • Loading branch information
viveksinghggits committed Jan 24, 2024
1 parent 6946482 commit 0cebc07
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions pkg/kube/pod_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,20 @@ func NewPodController(cli kubernetes.Interface, options *PodOptions, opts ...Pod
return r
}

// NewPodControllerForExistingPod returns a new PodController given Kubernetes
// Client and existing pod details.
// Invocation of StartPod of returned PodController instance will fail, since the pod is already known.
func NewPodControllerForExistingPod(cli kubernetes.Interface, pod *corev1.Pod) PodController {
r := &podController{
// NewPodControllerForExistingPod returns a new PodController for the given
// running pod.
// Invocation of StartPod of returned PodController instance will fail, since
// the pod is expected to be running already.
// Note:
// If the pod is not in the ready state, it will wait for up to
// KANISTER_POD_READY_WAIT_TIMEOUT (15 minutes by default) until the pod becomes ready.
func NewPodControllerForExistingPod(cli kubernetes.Interface, pod *corev1.Pod) (PodController, error) {
err := WaitForPodReady(context.Background(), cli, pod.Namespace, pod.Name)
if err != nil {
return nil, err
}

pc := &podController{
cli: cli,
pcp: &podControllerProcessor{
cli: cli,
Expand All @@ -117,9 +126,10 @@ func NewPodControllerForExistingPod(cli kubernetes.Interface, pod *corev1.Pod) P
Namespace: pod.Namespace,
ContainerName: pod.Spec.Containers[0].Name,
}
r.podOptions = options
pc.podOptions = options
pc.podReady = true

return r
return pc, nil
}

func (p *podController) PodName() string {
Expand Down

0 comments on commit 0cebc07

Please sign in to comment.