Skip to content

Commit 961f159

Browse files
test(e2e): wait for CRDs (#11665)
Signed-off-by: Jakub Dyszkiewicz <[email protected]> Signed-off-by: Charly Molter <[email protected]>
1 parent 078fe8a commit 961f159

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

test/framework/k8s_cluster.go

+34
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,9 @@ func (c *K8sCluster) GetPodLogs(pod v1.Pod, podLogOpts v1.PodLogOptions) (string
283283
// deployKumaViaKubectl uses kubectl to install kuma
284284
// using the resources from the `kumactl install control-plane` command
285285
func (c *K8sCluster) deployKumaViaKubectl(mode string) error {
286+
if err := c.installCRDs(); err != nil {
287+
return err
288+
}
286289
yaml, err := c.yamlForKumaViaKubectl(mode)
287290
if err != nil {
288291
return err
@@ -293,6 +296,37 @@ func (c *K8sCluster) deployKumaViaKubectl(mode string) error {
293296
yaml)
294297
}
295298

299+
// installCRDs installs Kuma CRDs and waits until it's ready
300+
// Usually it's immediately, but when we were installing CRDs and Kuma CP at the same time, sometimes we hit
301+
// a problem when CP could not recognize CRDs in Kubernetes and CP was restarted.
302+
func (c *K8sCluster) installCRDs() error {
303+
crds, err := c.GetKumactlOptions().RunKumactlAndGetOutputV(false, "install", "crds")
304+
if err != nil {
305+
return err
306+
}
307+
if err := k8s.KubectlApplyFromStringE(c.t, c.GetKubectlOptions(), crds); err != nil {
308+
return err
309+
}
310+
311+
regexPattern := `(?m)^\s*name:\s*([^\s]+\.kuma\.io)\b`
312+
re := regexp.MustCompile(regexPattern)
313+
matches := re.FindAllStringSubmatch(crds, -1)
314+
if matches == nil {
315+
return fmt.Errorf("no matches found")
316+
}
317+
318+
for _, match := range matches {
319+
if len(match) > 1 {
320+
crdName := match[1]
321+
err := k8s.RunKubectlE(c.t, c.GetKubectlOptions(), "wait", "--for", "condition=established", "--timeout=60s", "crd/"+crdName)
322+
if err != nil {
323+
return err
324+
}
325+
}
326+
}
327+
return nil
328+
}
329+
296330
func (c *K8sCluster) yamlForKumaViaKubectl(mode string) (string, error) {
297331
argsMap := map[string]string{
298332
"--mode": mode,

0 commit comments

Comments
 (0)