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

Improve NewPodControllerForExistingPod to set podReady to true #2623

Merged
merged 2 commits into from
Jan 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
viveksinghggits marked this conversation as resolved.
Show resolved Hide resolved
// 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