Skip to content

Commit

Permalink
Merge pull request #3254 from weaveworks/fix-waiting-for-pod
Browse files Browse the repository at this point in the history
poll to wait for a pod before starting port forward
  • Loading branch information
Chanwit Kaewkasi authored Jan 10, 2023
2 parents dc7a257 + b841504 commit fab0ca0
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions cmd/gitops/beta/run/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ import (
"github.com/weaveworks/weave-gitops/pkg/s3"
"github.com/weaveworks/weave-gitops/pkg/validate"
"github.com/weaveworks/weave-gitops/pkg/version"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/client-go/discovery"
"k8s.io/client-go/rest"
Expand Down Expand Up @@ -897,12 +899,26 @@ func runCommandWithoutSession(cmd *cobra.Command, args []string) error {
// get pod from specMap
namespacedName := types.NamespacedName{Namespace: specMap.Namespace, Name: specMap.Name}

pod, err := run.GetPodFromResourceDescription(thisCtx, namespacedName, specMap.Kind, kubeClient)
if err != nil {
log.Failuref("Error getting pod from specMap: %v", err)
var (
pod *corev1.Pod
podErr error
)

if pollErr := wait.PollImmediate(2*time.Second, flags.Timeout, func() (bool, error) {
pod, podErr = run.GetPodFromResourceDescription(thisCtx, namespacedName, specMap.Kind, kubeClient)
if pod != nil && podErr == nil {
return true, nil
}

log.Waitingf("Waiting for a pod from specMap: %v", podErr)
return false, nil
}); pollErr != nil {
log.Failuref("Waiting for a pod from specMap: %v", pollErr)
}

if pod != nil {
if pod == nil {
log.Failuref("Error getting pod from specMap")
} else /* pod is available */ {
waitFwd := make(chan struct{}, 1)
readyChannel := make(chan struct{})
cancelPortFwd = func() {
Expand Down

0 comments on commit fab0ca0

Please sign in to comment.