diff --git a/pkg/crc/cluster/cluster.go b/pkg/crc/cluster/cluster.go index ad2201358a..990ae73c20 100644 --- a/pkg/crc/cluster/cluster.go +++ b/pkg/crc/cluster/cluster.go @@ -510,3 +510,29 @@ func DeleteMCOLeaderLease(ctx context.Context, ocConfig oc.Config) error { _, _, err := ocConfig.RunOcCommand("delete", "-A", "lease", "--all") return err } + +func CheckCorePodsRunning(ctx context.Context, ocConfig oc.Config) error { + coreNameSpace := []string{"kube-system", "openshift-dns", "openshift-ingress", "openshift-ovn-kubernetes", "openshift-service-ca"} + waitForPods := func() error { + for _, namespace := range coreNameSpace { + if !podRunningForNamespace(ocConfig, namespace) { + logging.Debugf("Pods in %s namespace are not running", namespace) + return &errors.RetriableError{Err: fmt.Errorf("pods in %s namespace are not running", namespace)} + } + } + return nil + } + return errors.Retry(ctx, 2*time.Minute, waitForPods, 2*time.Second) +} + +func podRunningForNamespace(ocConfig oc.Config, namespace string) bool { + stdin, stderr, err := ocConfig.WithFailFast().RunOcCommand("get", "pods", "-n", namespace, "--field-selector=status.phase!=Running") + if err != nil { + logging.Debugf("Failed to get pods in %s namespace, stderr: %s", namespace, stderr) + return false + } + if len(stdin) != 0 { + return false + } + return true +} diff --git a/pkg/crc/machine/start.go b/pkg/crc/machine/start.go index 967f0b2512..d349e9ed6f 100644 --- a/pkg/crc/machine/start.go +++ b/pkg/crc/machine/start.go @@ -1064,7 +1064,10 @@ func startMicroshift(ctx context.Context, sshRunner *crcssh.Runner, ocConfig oc. return err } - return cluster.WaitForAPIServer(ctx, ocConfig) + if err := cluster.WaitForAPIServer(ctx, ocConfig); err != nil { + return err + } + return cluster.CheckCorePodsRunning(ctx, ocConfig) } func ensurePullSecretPresentInVM(sshRunner *crcssh.Runner, pullSec cluster.PullSecretLoader) error {