Skip to content

Commit 633c52a

Browse files
committed
fix: Auto-install Istio in e2e tests when missing
- Add InstallIstio() function with auto-detection - Modify WaitIstioAvailable() to install if istio-system namespace missing - Improve Istio/istioctl installation checks - Fix cert-manager "Stdout already set" error Resolves "istio-system namespace not found" test failures. Signed-off-by: Yash Pal <yashpal2104@gmail.com>
1 parent 1caea0f commit 633c52a

File tree

3 files changed

+112
-65
lines changed

3 files changed

+112
-65
lines changed

workspaces/controller/Makefile

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -78,22 +78,7 @@ test-e2e: manifests generate fmt vet ## Run the e2e tests. Expected an isolated
7878
echo "No Kind cluster is running. Please start a Kind cluster before running the e2e tests."; \
7979
exit 1; \
8080
}
81-
@echo "Installing CertManager..."
82-
@if [ "$(CERT_MANAGER_INSTALL_SKIP)" != "true" ]; then \
83-
kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.18.2/cert-manager.yaml; \
84-
echo "Waiting for CertManager deployments to be ready..."; \
85-
kubectl wait --for=condition=Available --timeout=300s deployment/cert-manager -n cert-manager; \
86-
kubectl wait --for=condition=Available --timeout=300s deployment/cert-manager-cainjector -n cert-manager; \
87-
kubectl wait --for=condition=Available --timeout=300s deployment/cert-manager-webhook -n cert-manager; \
88-
echo "CertManager is ready!"; \
89-
fi
90-
@echo "Installing Istio..."
91-
@if [ "$(ISTIO_INSTALL_SKIP)" != "true" ]; then \
92-
echo "Istio installation will be handled by the test suite"; \
93-
fi
94-
@if [ "$(PROMETHEUS_INSTALL_SKIP)" != "true" ]; then \
95-
echo "Installing Prometheus (if needed)..."; \
96-
fi
81+
9782
go test ./test/e2e/ -v -ginkgo.v
9883

9984
.PHONY: lint

workspaces/controller/test/e2e/e2e_suite_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ var _ = BeforeSuite(func() {
9494

9595
if !skipIstioctlInstall {
9696
By("checking if istioctl is installed already")
97-
isIstioctlAlreadyInstalled = utils.IsIstioInstalled()
97+
isIstioctlAlreadyInstalled = utils.IsIstioctlInstalled()
9898
if !isIstioctlAlreadyInstalled {
9999
_, _ = fmt.Fprintf(GinkgoWriter, "Installing istioctl...\n")
100100
Expect(utils.InstallIstioctl()).To(Succeed(), "Failed to install istioctl")

workspaces/controller/test/utils/utils.go

Lines changed: 110 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -308,20 +308,89 @@ func InstallIstioMinimalWithIngress(namespace string) error {
308308
return cmd.Run()
309309
}
310310

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
312359
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")
314379
_, err := Run(cmd)
315380
return err == nil
316381
}
317382

318383
// WaitIstioAvailable waits for Istio to be available and running.
319384
// Returns nil if Istio is ready, or an error if not ready within timeout.
320385
func WaitIstioAvailable() error {
321-
// First check if istio-system namespace exists
386+
// First check if istio-system namespace exists, if not install Istio
322387
cmd := exec.Command("kubectl", "get", "namespace", "istio-system")
323388
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+
}
325394
}
326395

327396
// Wait for Istio control plane (istiod) pods to be ready
@@ -580,51 +649,44 @@ func WaitCertManagerRunning() error {
580649
"--all-namespaces",
581650
"--timeout", "2m",
582651
)
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+
}
586655
// 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
628690
}
629691

630692
// IsCertManagerCRDsInstalled checks if any Cert Manager CRDs are installed

0 commit comments

Comments
 (0)