Skip to content

Commit fab0ca0

Browse files
author
Chanwit Kaewkasi
authored
Merge pull request #3254 from weaveworks/fix-waiting-for-pod
poll to wait for a pod before starting port forward
2 parents dc7a257 + b841504 commit fab0ca0

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

cmd/gitops/beta/run/cmd.go

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@ import (
3434
"github.com/weaveworks/weave-gitops/pkg/s3"
3535
"github.com/weaveworks/weave-gitops/pkg/validate"
3636
"github.com/weaveworks/weave-gitops/pkg/version"
37+
corev1 "k8s.io/api/core/v1"
3738
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3839
"k8s.io/apimachinery/pkg/types"
40+
"k8s.io/apimachinery/pkg/util/wait"
3941
"k8s.io/cli-runtime/pkg/genericclioptions"
4042
"k8s.io/client-go/discovery"
4143
"k8s.io/client-go/rest"
@@ -897,12 +899,26 @@ func runCommandWithoutSession(cmd *cobra.Command, args []string) error {
897899
// get pod from specMap
898900
namespacedName := types.NamespacedName{Namespace: specMap.Namespace, Name: specMap.Name}
899901

900-
pod, err := run.GetPodFromResourceDescription(thisCtx, namespacedName, specMap.Kind, kubeClient)
901-
if err != nil {
902-
log.Failuref("Error getting pod from specMap: %v", err)
902+
var (
903+
pod *corev1.Pod
904+
podErr error
905+
)
906+
907+
if pollErr := wait.PollImmediate(2*time.Second, flags.Timeout, func() (bool, error) {
908+
pod, podErr = run.GetPodFromResourceDescription(thisCtx, namespacedName, specMap.Kind, kubeClient)
909+
if pod != nil && podErr == nil {
910+
return true, nil
911+
}
912+
913+
log.Waitingf("Waiting for a pod from specMap: %v", podErr)
914+
return false, nil
915+
}); pollErr != nil {
916+
log.Failuref("Waiting for a pod from specMap: %v", pollErr)
903917
}
904918

905-
if pod != nil {
919+
if pod == nil {
920+
log.Failuref("Error getting pod from specMap")
921+
} else /* pod is available */ {
906922
waitFwd := make(chan struct{}, 1)
907923
readyChannel := make(chan struct{})
908924
cancelPortFwd = func() {

0 commit comments

Comments
 (0)