@@ -308,20 +308,89 @@ func InstallIstioMinimalWithIngress(namespace string) error {
308
308
return cmd .Run ()
309
309
}
310
310
311
- // TODO:
311
+ // InstallIstio installs Istio with default configuration.
312
+ func InstallIstio () error {
313
+ // First ensure istioctl is available
314
+ if ! IsIstioctlInstalled () {
315
+ fmt .Println ("istioctl not found, installing istioctl..." )
316
+ if err := InstallIstioctl (); err != nil {
317
+ return fmt .Errorf ("failed to install istioctl: %w" , err )
318
+ }
319
+
320
+ // Verify installation
321
+ if ! IsIstioctlInstalled () {
322
+ return fmt .Errorf ("istioctl installation failed - binary not available after installation" )
323
+ }
324
+ }
325
+
326
+ // Check if Istio is already installed
327
+ if IsIstioInstalled () {
328
+ fmt .Println ("Istio is already installed" )
329
+ return nil
330
+ }
331
+
332
+ // Install Istio with default configuration
333
+ fmt .Println ("Installing Istio..." )
334
+ cmd := exec .Command ("istioctl" , "install" ,
335
+ "--set" , "values.defaultRevision=default" ,
336
+ "-y" )
337
+ if _ , err := Run (cmd ); err != nil {
338
+ return fmt .Errorf ("failed to install Istio: %w" , err )
339
+ }
340
+
341
+ fmt .Println ("Istio installation completed" )
342
+ return nil
343
+ }
344
+
345
+ // IsIstioctlInstalled checks if istioctl binary is available and working
346
+ func IsIstioctlInstalled () bool {
347
+ // Check if istioctl binary exists in PATH
348
+ if _ , err := exec .LookPath ("istioctl" ); err != nil {
349
+ return false
350
+ }
351
+
352
+ // Verify istioctl can run and show version
353
+ cmd := exec .Command ("istioctl" , "version" , "--short" , "--remote=false" )
354
+ _ , err := Run (cmd )
355
+ return err == nil
356
+ }
357
+
358
+ // IsIstioInstalled checks if Istio is installed in the cluster
312
359
func IsIstioInstalled () bool {
313
- cmd := exec .Command ("istioctl" , "version" )
360
+ // Check if istioctl binary is available first
361
+ if ! IsIstioctlInstalled () {
362
+ return false
363
+ }
364
+
365
+ // Check if istio-system namespace exists
366
+ cmd := exec .Command ("kubectl" , "get" , "namespace" , "istio-system" )
367
+ if _ , err := Run (cmd ); err != nil {
368
+ return false
369
+ }
370
+
371
+ // Check if istiod deployment exists and is available
372
+ cmd = exec .Command ("kubectl" , "get" , "deployment" , "istiod" , "-n" , "istio-system" )
373
+ if _ , err := Run (cmd ); err != nil {
374
+ return false
375
+ }
376
+
377
+ // Verify istioctl can communicate with the cluster
378
+ cmd = exec .Command ("istioctl" , "version" , "--short" )
314
379
_ , err := Run (cmd )
315
380
return err == nil
316
381
}
317
382
318
383
// WaitIstioAvailable waits for Istio to be available and running.
319
384
// Returns nil if Istio is ready, or an error if not ready within timeout.
320
385
func WaitIstioAvailable () error {
321
- // First check if istio-system namespace exists
386
+ // First check if istio-system namespace exists, if not install Istio
322
387
cmd := exec .Command ("kubectl" , "get" , "namespace" , "istio-system" )
323
388
if _ , err := Run (cmd ); err != nil {
324
- return fmt .Errorf ("istio-system namespace not found: %w" , err )
389
+ // Namespace doesn't exist, install Istio
390
+ fmt .Println ("istio-system namespace not found, installing Istio..." )
391
+ if err := InstallIstio (); err != nil {
392
+ return fmt .Errorf ("failed to install Istio: %w" , err )
393
+ }
325
394
}
326
395
327
396
// Wait for Istio control plane (istiod) pods to be ready
@@ -580,51 +649,44 @@ func WaitCertManagerRunning() error {
580
649
"--all-namespaces" ,
581
650
"--timeout" , "2m" ,
582
651
)
583
- _ , err = Run (cmd )
584
- return err
585
-
652
+ if _ , err : = Run (cmd ); err != nil {
653
+ return fmt . Errorf ( "cert-manager endpoints not ready: %w" , err )
654
+ }
586
655
// First check if cert-manager namespace exists, if not install cert-manager
587
- // cmd := exec.Command("kubectl", "get", "namespace", "cert-manager")
588
- // if _, err := Run(cmd); err != nil {
589
- // // Namespace doesn't exist, install cert-manager
590
- // fmt.Println("cert-manager namespace not found, installing cert-manager...")
591
- // if err := InstallCertManager(); err != nil {
592
- // return fmt.Errorf("failed to install cert-manager: %w", err)
593
- // }
594
- // }
595
-
596
- // // Wait for the cert-manager namespace to be ready
597
- // cmd = exec.Command("kubectl", "wait", "--for=condition=Ready", "namespace/cert-manager", "--timeout=300s")
598
- // if _, err := Run(cmd); err != nil {
599
- // return fmt.Errorf("cert-manager namespace not ready: %w", err)
600
- // }
601
-
602
- // // Wait for each CertManager deployment individually by name (most reliable)
603
- // deployments := []string{"cert-manager", "cert-manager-cainjector", "cert-manager-webhook"}
604
-
605
- // for _, deployment := range deployments {
606
- // cmd := exec.Command("kubectl", "wait", "deployment", deployment,
607
- // "-n", "cert-manager",
608
- // "--for", "condition=Available",
609
- // "--timeout", "300s")
610
-
611
- // if _, err := Run(cmd); err != nil {
612
- // return fmt.Errorf("deployment %s not ready: %w", deployment, err)
613
- // }
614
- // }
615
-
616
- // // Wait for the cert-manager webhook to be ready (critical for functionality)
617
- // cmd = exec.Command("kubectl", "wait", "pods",
618
- // "-n", "cert-manager",
619
- // "-l", "app=webhook",
620
- // "--for", "condition=Ready",
621
- // "--timeout", "300s")
622
-
623
- // if _, err := Run(cmd); err != nil {
624
- // return fmt.Errorf("cert-manager webhook pods not ready: %w", err)
625
- // }
626
-
627
- // return nil
656
+ cmd = exec .Command ("kubectl" , "get" , "namespace" , "cert-manager" )
657
+ if _ , err := Run (cmd ); err != nil {
658
+ // Namespace doesn't exist, install cert-manager
659
+ fmt .Println ("cert-manager namespace not found, installing cert-manager..." )
660
+ if err := InstallCertManager (); err != nil {
661
+ return fmt .Errorf ("failed to install cert-manager: %w" , err )
662
+ }
663
+ }
664
+
665
+ // Wait for each CertManager deployment individually by name (most reliable)
666
+ deployments := []string {"cert-manager" , "cert-manager-cainjector" , "cert-manager-webhook" }
667
+
668
+ for _ , deployment := range deployments {
669
+ cmd := exec .Command ("kubectl" , "wait" , "deployment" , deployment ,
670
+ "-n" , "cert-manager" ,
671
+ "--for" , "condition=Available" ,
672
+ "--timeout" , "300s" )
673
+
674
+ if _ , err := Run (cmd ); err != nil {
675
+ return fmt .Errorf ("deployment %s not ready: %w" , deployment , err )
676
+ }
677
+ }
678
+
679
+ // Wait for the cert-manager webhook to be ready (critical for functionality)
680
+ cmd = exec .Command ("kubectl" , "wait" , "pods" ,
681
+ "-n" , "cert-manager" ,
682
+ "-l" , "app=webhook" ,
683
+ "--for" , "condition=Ready" ,
684
+ "--timeout" , "300s" )
685
+
686
+ if _ , err := Run (cmd ); err != nil {
687
+ return fmt .Errorf ("cert-manager webhook pods not ready: %w" , err )
688
+ }
689
+ return err
628
690
}
629
691
630
692
// IsCertManagerCRDsInstalled checks if any Cert Manager CRDs are installed
0 commit comments