Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow customizing the Istio version to use in the e2e tests #243

Merged
merged 1 commit into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions e2e/istio/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
include ../suite-certs.mk
include ../suite-k8s.mk

# Version of Istio to install. If empty, the latest version will be installed.
E2E_ISTIO_VERSION ?=

.PHONY: gen-certs
gen-certs: clean-certs ca/ca.authservice.internal certificate/http-echo.authservice.internal
@chmod -R a+r $(CERTS_DIR)
Expand Down
49 changes: 35 additions & 14 deletions e2e/istio/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package istio
import (
"context"
"fmt"
"os"
"os/exec"
"strings"
"testing"
Expand All @@ -30,6 +31,7 @@ import (
)

const (
istioHelmRepo = "https://istio-release.storage.googleapis.com/charts"
istiodConfig = "cluster/istiod-config.yaml"
istioGwConfig = "cluster/istiogw-config.yaml"
manifestsDir = "cluster/manifests"
Expand All @@ -46,23 +48,21 @@ var testManifests = []string{
"telemetry.yaml",
}

// istioInstall contains the commands to install Istio using Helm, so we don't require
// downloading `istioctl` or other tooling that would just make the e2e tests take more time.
var istioInstall = []string{
"helm repo add istio https://istio-release.storage.googleapis.com/charts --force-update",
"helm repo update istio",
fmt.Sprintf("helm --kubeconfig %s install istio-base istio/base -n istio-system --create-namespace", e2e.KubeConfig),
fmt.Sprintf("helm --kubeconfig %s install istiod istio/istiod -n istio-system -f %s --wait", e2e.KubeConfig, istiodConfig),
fmt.Sprintf("helm --kubeconfig %s install istio-ingress istio/gateway -n istio-system -f %s --wait", e2e.KubeConfig, istioGwConfig),
}

// IstioSuite is a suite that installs Istio in the Kubernetes cluster and runs tests against it.
type IstioSuite struct {
e2e.K8sSuite
IstioVersion string
IstioConfigValues string
IstioGatewayValues string
}

func TestIstio(t *testing.T) {
suite.Run(t, &IstioSuite{})
suite.Run(t, &IstioSuite{
// If the IstioVersion is empty, the latest version will be installed
IstioVersion: os.Getenv("E2E_ISTIO_VERSION"),
IstioConfigValues: istiodConfig,
IstioGatewayValues: istioGwConfig,
})
}

// SetupSuite initializes the Kubernetes clients, installs Istio in the cluster and waits until the
Expand All @@ -77,7 +77,7 @@ func (i *IstioSuite) SetupSuite() {
// and make e2e tests easier to run multiple times without tearing down the entire
// environment
if !i.istioInstalled(client) {
i.installistio()
i.installIstio()
}

i.T().Log("deploying the test services...")
Expand All @@ -90,8 +90,20 @@ func (i *IstioSuite) SetupSuite() {
i.WaitForPods(client, "http-echo", "", corev1.PodRunning, e2e.PodReady)
}

func (i *IstioSuite) installistio() {
i.T().Log("installing Istio...")
func (i *IstioSuite) installIstio() {
if i.IstioVersion == "" {
i.T().Log("installing Istio (latest)...")
} else {
i.T().Logf("installing Istio %s...", i.IstioVersion)
}

var istioInstall = []string{
fmt.Sprintf("helm repo add istio %s --force-update", istioHelmRepo),
"helm repo update istio",
i.helmInstall("istio-base", "istio/base", ""),
i.helmInstall("istiod", "istio/istiod", istiodConfig),
i.helmInstall("istio-ingress", "istio/gateway", istioGwConfig),
}

for _, cmd := range istioInstall {
parts := strings.Split(cmd, " ")
Expand All @@ -104,3 +116,12 @@ func (i *IstioSuite) istioInstalled(client kubernetes.Interface) bool {
_, err := client.CoreV1().Services("istio-system").Get(context.Background(), "istiod", metav1.GetOptions{})
return err == nil
}

func (i *IstioSuite) helmInstall(name, chart, values string) string {
cmd := fmt.Sprintf("helm --kubeconfig %s install %s %s --version %s -n istio-system --create-namespace --wait",
e2e.KubeConfig, name, chart, i.IstioVersion)
if values != "" {
cmd += fmt.Sprintf(" -f %s", values)
}
return cmd
}