@@ -9,13 +9,14 @@ import (
99 "regexp"
1010 "strings"
1111
12+ "github.com/pulumi/pulumi/sdk/v3/go/pulumi"
13+
1214 "github.com/DataDog/datadog-agent/test/e2e-framework/common/config"
1315 "github.com/DataDog/datadog-agent/test/e2e-framework/common/utils"
1416 "github.com/DataDog/datadog-agent/test/e2e-framework/components"
1517 "github.com/DataDog/datadog-agent/test/e2e-framework/components/command"
1618 oscomp "github.com/DataDog/datadog-agent/test/e2e-framework/components/os"
1719 "github.com/DataDog/datadog-agent/test/e2e-framework/components/remote"
18- "github.com/pulumi/pulumi/sdk/v3/go/pulumi"
1920)
2021
2122func NewLocalOpenShiftCluster (env config.Env , name string , pullSecretPath string , opts ... pulumi.ResourceOption ) (* Cluster , error ) {
@@ -136,9 +137,61 @@ func NewOpenShiftCluster(env config.Env, vm *remote.Host, name string, pullSecre
136137 return err
137138 }
138139
139- clusterComp .KubeConfig = pulumi .All (kubeConfig .StdoutOutput (), vm .Address ).ApplyT (func (args []interface {}) string {
140+ // Wait for the control plane to be fully ready before proceeding
141+ waitControlPlane , err := runner .Command (commonEnvironment .CommonNamer ().ResourceName ("wait-control-plane-ready" ), & command.Args {
142+ Create : pulumi .String (`
143+ # Wait for API server to be responsive
144+ for i in {1..30}; do
145+ if curl -sk https://127.0.0.1:6443/healthz 2>/dev/null | grep -q ok; then
146+ echo "API server responsive"
147+ break
148+ fi
149+ echo "Waiting for API server (attempt $i/30)..."
150+ sleep 10
151+ done
152+
153+ export KUBECONFIG=~/.crc/machines/crc/kubeconfig
154+
155+ # Wait for nodes to be ready
156+ echo "Waiting for nodes to be Ready..."
157+ for i in {1..60}; do
158+ ready_nodes=$(kubectl get nodes --no-headers 2>/dev/null | grep -c ' Ready ')
159+ if [ "$ready_nodes" -gt 0 ]; then
160+ echo "Found $ready_nodes Ready nodes"
161+ break
162+ fi
163+ echo "Waiting for nodes (attempt $i/60)..."
164+ sleep 5
165+ done
166+
167+ # Wait for some system pods to be running
168+ echo "Waiting for system pods to be running..."
169+ for namespace in openshift-kube-apiserver openshift-kube-controller-manager; do
170+ for i in {1..60}; do
171+ running_pods=$(kubectl get pods -n "$namespace" --field-selector=status.phase=Running --no-headers 2>/dev/null | wc -l)
172+ if [ "$running_pods" -gt 0 ]; then
173+ echo "Namespace $namespace has $running_pods running pod(s)"
174+ break
175+ fi
176+ if [ $i -lt 60 ]; then
177+ echo "Waiting for $namespace pods (attempt $i/60)..."
178+ sleep 5
179+ fi
180+ done
181+ done
182+
183+ echo "Control plane is ready"
184+ exit 0
185+ ` ),
186+ }, utils .MergeOptions (opts , utils .PulumiDependsOn (kubeConfig ))... )
187+ if err != nil {
188+ return err
189+ }
190+
191+ clusterComp .KubeConfig = pulumi .All (kubeConfig .StdoutOutput (), vm .Address , waitControlPlane .StdoutOutput ()).ApplyT (func (args []interface {}) string {
140192 kubeconfigRaw := args [0 ].(string )
141193 vmIP := args [1 ].(string )
194+ // args[2] is the output from waitControlPlane, ensuring it completes first
142195 allowInsecure := regexp .MustCompile ("certificate-authority-data:.+" ).ReplaceAllString (kubeconfigRaw , "insecure-skip-tls-verify: true" )
143196 updated := strings .ReplaceAll (allowInsecure , "api.crc.testing:6443" , vmIP + ":8443" )
144197 return updated
0 commit comments