Skip to content

Commit

Permalink
Do not display "Waiting for component to start" twice
Browse files Browse the repository at this point in the history
  • Loading branch information
feloy committed Jul 16, 2021
1 parent 9237d8d commit 7ab7f3c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
17 changes: 17 additions & 0 deletions pkg/devfile/adapters/kubernetes/component/adapter.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package component

import (
"context"
"fmt"
"io"
"os"
Expand Down Expand Up @@ -56,6 +57,22 @@ func (a *Adapter) getPod(refresh bool) (*corev1.Pod, error) {
if refresh || a.pod == nil {
podSelector := fmt.Sprintf("component=%s", a.ComponentName)

// First check if the pod is already in desired state
c := a.Client.GetKubeClient()
podList, err := c.KubeClient.CoreV1().Pods(c.Namespace).List(context.TODO(), metav1.ListOptions{
LabelSelector: podSelector,
})
if err != nil {
return nil, fmt.Errorf("unable go list pods: %w", err)
}
if len(podList.Items) == 1 {
pod := podList.Items[0]
if pod.Status.Phase == corev1.PodRunning {
a.pod = &pod
return a.pod, nil
}
}

// Wait for Pod to be in running state otherwise we can't sync data to it.
pod, err := a.Client.GetKubeClient().WaitAndGetPodWithEvents(podSelector, corev1.PodRunning, "Waiting for component to start")
if err != nil {
Expand Down
1 change: 0 additions & 1 deletion pkg/kclient/pods.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (

// WaitAndGetPod block and waits until pod matching selector is in in Running state
// desiredPhase cannot be PodFailed or PodUnknown
// hideSpinner hides the spinner
func (c *Client) WaitAndGetPodWithEvents(selector string, desiredPhase corev1.PodPhase, waitMessage string) (*corev1.Pod, error) {

// Try to grab the preference in order to set a timeout.. but if not, we'll use the default.
Expand Down

0 comments on commit 7ab7f3c

Please sign in to comment.