test: implement Istio installation utilities for e2e testing

- Add InstallIstioctl() function to download and install istioctl binary
- Add InstallIstioMinimalWithIngress() to set up Istio with minimal profile
- Add IsIstioInstalled() and WaitIstioctlAvailable() helper functions
- Use positional formatting in URL template for istioctl downloads
- Support configurable Istio namespace for installation
- Add error handling and proper command output redirection

This enables e2e tests to automatically set up Istio service mesh
components required for workspace HTTP proxy functionality.

Signed-off-by: Yash Pal <yashpal2104@gmail.com>
This commit is contained in:
Yash Pal 2025-09-05 17:15:19 +05:30
parent 0fbbe7a0ee
commit 95f18da965
2 changed files with 90 additions and 0 deletions

View File

@ -40,6 +40,9 @@ var (
// isPrometheusOperatorAlreadyInstalled will be set true when prometheus CRDs be found on the cluster
// isPrometheusOperatorAlreadyInstalled = false
isIstioctlAlreadyInstalled = false
skipIstioctlInstall = os.Getenv("ISTIO_INSTALL_SKIP") == "true"
)
// TestE2E runs the end-to-end (e2e) test suite for the project. These tests execute in an isolated,
@ -88,6 +91,21 @@ var _ = BeforeSuite(func() {
}
By("checking that cert manager is running")
Expect(utils.WaitCertManagerRunning()).To(Succeed(), "CertManager is not running")
if !skipIstioctlInstall {
By("checking if istioctl is installed already")
isIstioctlAlreadyInstalled = utils.IsIstioInstalled()
if !isIstioctlAlreadyInstalled {
_, _ = fmt.Fprintf(GinkgoWriter, "Installing istioctl...\n")
Expect(utils.InstallIstioctl()).To(Succeed(), "Failed to install istioctl")
} else {
_, _ = fmt.Fprintf(GinkgoWriter, "WARNING: istioctl is already installed. Skipping installation...\n")
}
}
By("checking that istioctl is available")
Expect(utils.WaitIstioctlAvailable()).To(Succeed(), "istioctl is not available")
})
var _ = AfterSuite(func() {

View File

@ -17,6 +17,7 @@ limitations under the License.
package utils
import (
"errors"
"fmt"
"os"
"os/exec"
@ -27,6 +28,10 @@ import (
const (
// use LTS version of istioctl
istioctlVersion = "1.27.0"
istioctlURL = ""
// use LTS version of prometheus-operator
prometheusOperatorVersion = "v0.72.0"
prometheusOperatorURL = "https://github.com/prometheus-operator/prometheus-operator/" +
@ -61,6 +66,73 @@ func Run(cmd *exec.Cmd) (string, error) {
return string(output), nil
}
// UninstallPrometheusOperator uninstalls the prometheus
func UninstallIstioctl() {
url := fmt.Sprintf(prometheusOperatorURL, prometheusOperatorVersion)
cmd := exec.Command("kubectl", "delete", "-f", url)
if _, err := Run(cmd); err != nil {
warnError(err)
}
}
// InstallIstioctl installs the istioctl to be used to manage istio resources.
func InstallIstioctl() error{
url := fmt.Sprintf("https://github.com/istio/istio/releases/download/%[1]s/istioctl-%[1]s-linux-amd64.tar.gz", istioctlVersion)
downloadCmd := exec.Command("curl", "-L", url, "-o", "istioctl.tar.gz")
extractCmd := exec.Command("tar", "-xzf", "istioctl.tar.gz")
chmodCmd := exec.Command("chmod", "+x", "istioctl")
moveCmd := exec.Command("sudo", "mv", "istioctl", "~/usr/local/bin/istioctl")
downloadCmd.Stdout, downloadCmd.Stderr = os.Stdout, os.Stderr
extractCmd.Stdout, extractCmd.Stderr = os.Stdout, os.Stderr
chmodCmd.Stdout, chmodCmd.Stderr = os.Stdout, os.Stderr
moveCmd.Stdout, moveCmd.Stderr = os.Stdout, os.Stderr
if err := downloadCmd.Run(); err != nil {
return fmt.Errorf("failed to download istioctl: %w", err)
}
if err := extractCmd.Run(); err != nil {
return fmt.Errorf("failed to extract istioctl: %w", err)
}
if err := chmodCmd.Run(); err != nil {
return fmt.Errorf("failed to make istioctl executable: %w", err)
}
if err := moveCmd.Run(); err != nil {
return fmt.Errorf("failed to move istioctl to /usr/local/bin: %w", err)
}
return nil
}
// InstallIstioMinimalWithIngress installs Istio with minimal profile and ingressgateway enabled.
func InstallIstioMinimalWithIngress(namespace string) error {
cmd := exec.Command("istioctl",
"install",
"--set", "profile=minimal",
"--set", "values.gateways.istio-ingressgateway.enabled=true",
"--set", fmt.Sprintf("values.global.istioNamespace=%s", namespace),
"-y",
)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return cmd.Run()
}
// TODO:
func IsIstioInstalled() bool {
cmd := exec.Command("istioctl", "version")
_, err := Run(cmd)
return err == nil
}
// WaitIstioctlAvailable checks if 'istioctl' is available in PATH.
// Returns nil if found, or an error if not found.
func WaitIstioctlAvailable() error {
if _, err := exec.LookPath("istioctl"); err != nil {
return errors.New("istioctl binary not found in PATH")
}
return nil
}
// UninstallPrometheusOperator uninstalls the prometheus
func UninstallPrometheusOperator() {
url := fmt.Sprintf(prometheusOperatorURL, prometheusOperatorVersion)