Skip to content

Commit

Permalink
test(e2e): wait for CRDs (#11665)
Browse files Browse the repository at this point in the history
Signed-off-by: Jakub Dyszkiewicz <[email protected]>
Signed-off-by: Charly Molter <[email protected]>
  • Loading branch information
jakubdyszkiewicz authored Oct 4, 2024
1 parent 078fe8a commit 961f159
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions test/framework/k8s_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,9 @@ func (c *K8sCluster) GetPodLogs(pod v1.Pod, podLogOpts v1.PodLogOptions) (string
// deployKumaViaKubectl uses kubectl to install kuma
// using the resources from the `kumactl install control-plane` command
func (c *K8sCluster) deployKumaViaKubectl(mode string) error {
if err := c.installCRDs(); err != nil {
return err
}
yaml, err := c.yamlForKumaViaKubectl(mode)
if err != nil {
return err
Expand All @@ -293,6 +296,37 @@ func (c *K8sCluster) deployKumaViaKubectl(mode string) error {
yaml)
}

// installCRDs installs Kuma CRDs and waits until it's ready
// Usually it's immediately, but when we were installing CRDs and Kuma CP at the same time, sometimes we hit
// a problem when CP could not recognize CRDs in Kubernetes and CP was restarted.
func (c *K8sCluster) installCRDs() error {
crds, err := c.GetKumactlOptions().RunKumactlAndGetOutputV(false, "install", "crds")
if err != nil {
return err
}
if err := k8s.KubectlApplyFromStringE(c.t, c.GetKubectlOptions(), crds); err != nil {
return err
}

regexPattern := `(?m)^\s*name:\s*([^\s]+\.kuma\.io)\b`
re := regexp.MustCompile(regexPattern)
matches := re.FindAllStringSubmatch(crds, -1)
if matches == nil {
return fmt.Errorf("no matches found")
}

for _, match := range matches {
if len(match) > 1 {
crdName := match[1]
err := k8s.RunKubectlE(c.t, c.GetKubectlOptions(), "wait", "--for", "condition=established", "--timeout=60s", "crd/"+crdName)
if err != nil {
return err
}
}
}
return nil
}

func (c *K8sCluster) yamlForKumaViaKubectl(mode string) (string, error) {
argsMap := map[string]string{
"--mode": mode,
Expand Down

0 comments on commit 961f159

Please sign in to comment.