@@ -283,6 +283,9 @@ func (c *K8sCluster) GetPodLogs(pod v1.Pod, podLogOpts v1.PodLogOptions) (string
283
283
// deployKumaViaKubectl uses kubectl to install kuma
284
284
// using the resources from the `kumactl install control-plane` command
285
285
func (c * K8sCluster ) deployKumaViaKubectl (mode string ) error {
286
+ if err := c .installCRDs (); err != nil {
287
+ return err
288
+ }
286
289
yaml , err := c .yamlForKumaViaKubectl (mode )
287
290
if err != nil {
288
291
return err
@@ -293,6 +296,37 @@ func (c *K8sCluster) deployKumaViaKubectl(mode string) error {
293
296
yaml )
294
297
}
295
298
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
+
296
330
func (c * K8sCluster ) yamlForKumaViaKubectl (mode string ) (string , error ) {
297
331
argsMap := map [string ]string {
298
332
"--mode" : mode ,
0 commit comments