Skip to content

Commit

Permalink
Provide configuration via .env file for mesh namespace and smcp name
Browse files Browse the repository at this point in the history
  • Loading branch information
Marton Rozman authored and Marton Rozman committed Dec 3, 2021
1 parent 16fac9c commit 9779a0b
Show file tree
Hide file tree
Showing 38 changed files with 454 additions and 211 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ The test cases include several changes for an OpenShift environment. Currently,
## Testing Prerequisite

1. User can access a running OpenShift cluster from command line.
2. Service Mesh Control Plane (SMCP) has been installed on an OpenShift cluster. The SMCP is in namespace `istio-system` and the SMCP name is `basic`
2. Service Mesh Control Plane (SMCP) has been installed on an OpenShift cluster. The `tests/.env` file is configured for the namespace where SMCP is located like `istio-system` and for the SMCP name, like `basic`. Then in all cases `source .env` has to be executed.
3. An `oc` client has been installed. User has completed CLI login an OCP cluster as an admin user. Run `oc login -u [user] -p [token] --server=[OCP API server]`

## Testing
Expand All @@ -51,7 +51,7 @@ The test cases include several changes for an OpenShift environment. Currently,
$ export SAMPLEARCH=z
```

- To run all the test cases: `cd tests; go test -timeout 3h -v`. It is required to use the `-timeout` flag. Otherwise, the go test will fall into panic after 10 minutes.
- To run all the test cases: `cd tests; source .env; go test -timeout 3h -v`. It is required to use the `-timeout` flag. Otherwise, the go test will fall into panic after 10 minutes.
```
$ cd tests
$ go test -timeout 3h -v 2>&1 | tee >(${GOPATH}/bin/go-junit-report > results.xml) test.log
Expand Down
23 changes: 13 additions & 10 deletions pkg/ossm/ratelimit.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ import (
)

const (
rateLimitFilterYaml = "../testdata/resources/yaml/ratelimit-envoyfilter.yaml"
rateLimitFilterYaml_template = "../testdata/resources/yaml/ratelimit-envoyfilter_template.yaml"
rateLimitFilterYaml = "../testdata/resources/yaml/ratelimit-envoyfilter.yaml"
)

func cleanupRateLimiting(redisDeploy examples.Redis, bookinfoDeploy examples.Bookinfo) {
util.Shell(`kubectl -n istio-system patch smcp/basic --type=json -p='[{"op": "remove", "path": "/spec/techPreview"}]'`)
util.KubeDelete("istio-system", rateLimitFilterYaml)
util.Shell(`kubectl -n %s patch smcp/%s --type=json -p='[{"op": "remove", "path": "/spec/techPreview/rateLimiting"}]'`, meshNamespace, smcpName)
util.KubeDelete(meshNamespace, rateLimitSMCPPatch)
redisDeploy.Uninstall()
bookinfoDeploy.Uninstall()
}
Expand All @@ -44,26 +45,28 @@ func TestRateLimiting(t *testing.T) {
if err := redisDeploy.Install(); err != nil {
t.Fatal(err)
}

if _, err := util.Shell(`kubectl -n istio-system patch smcp/basic --type=merge --patch="%s"`, rateLimitSMCPPatch); err != nil {
if _, err := util.Shell(`kubectl -n %s patch smcp/%s --type=merge --patch="%s"`, meshNamespace, smcpName, rateLimitSMCPPatch); err != nil {
t.Fatal(err)
}

if _, err := util.Shell(`oc -n istio-system wait --for condition=Ready smcp/basic --timeout 180s`); err != nil {
if _, err := util.Shell(`oc -n %s wait --for condition=Ready smcp/%s --timeout 180s`, meshNamespace, smcpName); err != nil {
t.Fatal(err)
}

if err := util.CheckPodRunning("istio-system", "app=rls"); err != nil {
if err := util.CheckPodRunning(meshNamespace, "app=rls"); err != nil {
t.Fatalf("rls deployment not ready: %v", err)
}

if err := util.KubeApply("istio-system", rateLimitFilterYaml); err != nil {
util.Shell(`envsubst < %s > %s`, rateLimitFilterYaml_template, rateLimitFilterYaml)
if err := util.KubeApply(meshNamespace, rateLimitFilterYaml); err != nil {
t.Fatalf("error applying envoy filter: %v", err)
}
util.Shell(`kubectl -n %s get envoyfilter -o yaml > rrr.yaml`, meshNamespace)
//util.Log.Info(msg)

// Give some time to envoy filters apply
time.Sleep(time.Second * 5)

host, err := util.Shell("oc -n istio-system get route istio-ingressgateway -o jsonpath='{.spec.host}'")
host, err := util.Shell("oc -n %s get route istio-ingressgateway -o jsonpath='{.spec.host}'", meshNamespace)
if err != nil {
t.Fatalf("error getting route hostname: %v", err)
}
Expand Down
101 changes: 55 additions & 46 deletions pkg/ossm/smcp_install.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,121 +23,130 @@ import (
)

func installDefaultSMCP21() {
util.Log.Info("Create SMCP v2.1 in istio-system")
util.ShellMuteOutputError(`oc new-project istio-system`)
util.KubeApply("istio-system", smcpV21)
util.KubeApply("istio-system", smmr)
util.Log.Info("Create SMCP v2.1 in ", meshNamespace)
util.ShellMuteOutputError(`oc new-project %s`, meshNamespace)
util.Shell(`envsubst < %s > %s`, smcpV21_template, smcpV21)
util.KubeApply(meshNamespace, smcpV21)
util.KubeApply(meshNamespace, smmr)
util.Log.Info("Waiting for mesh installation to complete")
util.Shell(`oc wait --for condition=Ready -n %s smmr/default --timeout 300s`, "istio-system")
util.Shell(`oc wait --for condition=Ready -n %s smmr/default --timeout 300s`, meshNamespace)
}

func TestSMCPInstall(t *testing.T) {
defer installDefaultSMCP21()

t.Run("smcp_test_install_2.1", func(t *testing.T) {
defer util.RecoverPanic(t)
util.Log.Info("Create SMCP v2.1 in istio-system")
util.ShellMuteOutputError(`oc new-project istio-system`)
util.KubeApply("istio-system", smcpV21)
util.KubeApply("istio-system", smmr)
util.Log.Info("Create SMCP v2.1 in ", meshNamespace)
util.ShellMuteOutputError(`oc new-project %s`, meshNamespace)
util.Shell(`envsubst < %s > %s`, smcpV21_template, smcpV21)
util.KubeApply(meshNamespace, smcpV21)
util.KubeApply(meshNamespace, smmr)
util.Log.Info("Waiting for mesh installation to complete")
util.Shell(`oc wait --for condition=Ready -n %s smmr/default --timeout 300s`, "istio-system")
util.Shell(`oc wait --for condition=Ready -n %s smmr/default --timeout 300s`, meshNamespace)

util.Log.Info("Verify SMCP status and pods")
msg, _ := util.Shell(`oc get -n %s smcp/%s -o wide`, "istio-system", "basic")
msg, _ := util.Shell(`oc get -n %s smcp/%s -o wide`, meshNamespace, smcpName)
if !strings.Contains(msg, "ComponentsReady") {
util.Log.Error("SMCP not Ready")
t.Error("SMCP not Ready")
}
util.Shell(`oc get -n %s pods`, "istio-system")
util.Shell(`oc get -n %s pods`, meshNamespace)
})

t.Run("smcp_test_uninstall_2.1", func(t *testing.T) {
defer util.RecoverPanic(t)
util.Log.Info("Delete SMCP v2.1 in istio-system")
util.KubeDelete("istio-system", smmr)
util.KubeDelete("istio-system", smcpV21)
util.Log.Info("Delete SMCP v2.1 in ", meshNamespace)
util.KubeDelete(meshNamespace, smmr)
util.Shell(`envsubst < %s > %s`, smcpV21_template, smcpV21)
util.KubeDelete(meshNamespace, smcpV21)
time.Sleep(time.Duration(40) * time.Second)
})

t.Run("smcp_test_install_2.0", func(t *testing.T) {
defer util.RecoverPanic(t)
util.Log.Info("Create SMCP v2.0 in namespace istio-system")
util.ShellMuteOutputError(`oc new-project istio-system`)
util.KubeApply("istio-system", smcpV20)
util.KubeApply("istio-system", smmr)
util.Log.Info("Create SMCP v2.0 in namespace ", meshNamespace)
util.ShellMuteOutputError(`oc new-project %s`, meshNamespace)
util.Shell(`envsubst < %s > %s`, smcpV20_template, smcpV20)
util.KubeApply(meshNamespace, smcpV20)
util.KubeApply(meshNamespace, smmr)
util.Log.Info("Waiting for mesh installation to complete")
util.Shell(`oc wait --for condition=Ready -n %s smmr/default --timeout 300s`, "istio-system")
util.Shell(`oc wait --for condition=Ready -n %s smmr/default --timeout 300s`, meshNamespace)

util.Log.Info("Verify SMCP status and pods")
msg, _ := util.Shell(`oc get -n %s smcp/%s -o wide`, "istio-system", "basic")
msg, _ := util.Shell(`oc get -n %s smcp/%s -o wide`, meshNamespace, smcpName)
if !strings.Contains(msg, "ComponentsReady") {
util.Log.Error("SMCP not Ready")
t.Error("SMCP not Ready")
}
util.Shell(`oc get -n %s pods`, "istio-system")
util.Shell(`oc get -n %s pods`, meshNamespace)
})

t.Run("smcp_test_uninstall_2.0", func(t *testing.T) {
defer util.RecoverPanic(t)
util.Log.Info("Delete SMCP v2.0 in istio-system")
util.KubeDelete("istio-system", smmr)
util.KubeDelete("istio-system", smcpV20)
util.Log.Info("Delete SMCP v2.0 in ", meshNamespace)
util.KubeDelete(meshNamespace, smmr)
util.Shell(`envsubst < %s > %s`, smcpV20_template, smcpV20)
util.KubeDelete(meshNamespace, smcpV20)
time.Sleep(time.Duration(40) * time.Second)
})

t.Run("smcp_test_install_1.1", func(t *testing.T) {
defer util.RecoverPanic(t)
util.Log.Info("Create SMCP v1.1 in namespace istio-system")
util.ShellMuteOutputError(`oc new-project istio-system`)
util.KubeApply("istio-system", smcpV11)
util.KubeApply("istio-system", smmr)
util.Log.Info("Create SMCP v1.1 in namespace ", meshNamespace)
util.ShellMuteOutputError(`oc new-project %s`, meshNamespace)
util.Shell(`envsubst < %s > %s`, smcpV11_template, smcpV11)
util.KubeApply(meshNamespace, smcpV11)
util.KubeApply(meshNamespace, smmr)
util.Log.Info("Waiting for mesh installation to complete")
util.Shell(`oc wait --for condition=Ready -n %s smmr/default --timeout 300s`, "istio-system")
util.Shell(`oc wait --for condition=Ready -n %s smmr/default --timeout 300s`, meshNamespace)

util.Log.Info("Verify SMCP status and pods")
msg, _ := util.Shell(`oc get -n %s smcp/%s -o wide`, "istio-system", "basic")
msg, _ := util.Shell(`oc get -n %s smcp/%s -o wide`, meshNamespace, smcpName)
if !strings.Contains(msg, "ComponentsReady") {
util.Log.Error("SMCP not Ready")
t.Error("SMCP not Ready")
}
util.Shell(`oc get -n %s pods`, "istio-system")
util.Shell(`oc get -n %s pods`, meshNamespace)
})

t.Run("smcp_test_uninstall_1.1", func(t *testing.T) {
defer util.RecoverPanic(t)
util.Log.Info("Delete SMCP v1,1 in istio-system")
util.KubeDelete("istio-system", smmr)
util.KubeDelete("istio-system", smcpV11)
util.Log.Info("Delete SMCP v1,1 in ", meshNamespace)
util.KubeDelete(meshNamespace, smmr)
util.Shell(`envsubst < %s > %s`, smcpV11_template, smcpV11)
util.KubeDelete(meshNamespace, smcpV11)
time.Sleep(time.Duration(40) * time.Second)
})

t.Run("smcp_test_upgrade_2.0_to_2.1", func(t *testing.T) {
defer util.RecoverPanic(t)

util.Log.Info("Create SMCP v2.0 in namespace istio-system")
util.ShellMuteOutputError(`oc new-project istio-system`)
util.KubeApply("istio-system", smcpV20)
util.KubeApply("istio-system", smmr)
util.Log.Info("Create SMCP v2.0 in namespace ", meshNamespace)
util.ShellMuteOutputError(`oc new-project %s`, meshNamespace)
util.Shell(`envsubst < %s > %s`, smcpV20_template, smcpV20)
util.KubeApply(meshNamespace, smcpV20)
util.KubeApply(meshNamespace, smmr)
util.Log.Info("Waiting for mesh installation to complete")
util.Shell(`oc wait --for condition=Ready -n %s smmr/default --timeout 300s`, "istio-system")
util.Shell(`oc wait --for condition=Ready -n %s smmr/default --timeout 300s`, meshNamespace)

util.Log.Info("Verify SMCP status and pods")
util.Shell(`oc get -n %s smcp/%s -o wide`, "istio-system", "basic")
util.Shell(`oc get -n %s pods`, "istio-system")
util.Shell(`oc get -n %s smcp/%s -o wide`, meshNamespace, smcpName)
util.Shell(`oc get -n %s pods`, meshNamespace)

util.Log.Info("Upgrade SMCP to v2.1 in istio-system")
util.KubeApply("istio-system", smcpV21)
util.Shell(`envsubst < %s > %s`, smcpV21_template, smcpV21)
util.KubeApply(meshNamespace, smcpV21)
util.Log.Info("Waiting for mesh installation to complete")
time.Sleep(time.Duration(10) * time.Second)
util.Shell(`oc wait --for condition=Ready -n %s smmr/default --timeout 360s`, "istio-system")
util.Shell(`oc wait --for condition=Ready -n %s smmr/default --timeout 360s`, meshNamespace)

util.Log.Info("Verify SMCP status and pods")
msg, _ := util.Shell(`oc get -n %s smcp/%s -o wide`, "istio-system", "basic")
msg, _ := util.Shell(`oc get -n %s smcp/%s -o wide`, meshNamespace, smcpName)
if !strings.Contains(msg, "ComponentsReady") {
util.Log.Error("SMCP not Ready")
t.Error("SMCP not Ready")
}
util.Shell(`oc get -n %s pods`, "istio-system")
util.Shell(`oc get -n %s pods`, meshNamespace)
})
}
41 changes: 16 additions & 25 deletions pkg/ossm/smcp_tls_ssl.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package ossm

import (
"os"
"strings"
"testing"

Expand All @@ -25,8 +24,8 @@ import (

func cleanupTestTLSVersionSMCP() {
util.Log.Info("Cleanup ...")
util.Shell(`kubectl patch -n %s smcp/basic --type=json -p='[{"op": "remove", "path": "/spec/security/controlPlane/tls"}]'`, "istio-system")
util.Shell(`oc wait --for condition=Ready -n %s smmr/default --timeout 180s`, "istio-system")
util.Shell(`kubectl patch -n %s smcp/%s --type=json -p='[{"op": "remove", "path": "/spec/security/controlPlane/tls"}]'`, meshNamespace, smcpName)
util.Shell(`oc wait --for condition=Ready -n %s smmr/default --timeout 180s`, meshNamespace)
}

func cleanupTestSSL() {
Expand All @@ -35,17 +34,9 @@ func cleanupTestSSL() {
util.KubeDeleteContents("bookinfo", testSSLDeployment)
bookinfo.Uninstall()

util.Shell(`kubectl patch -n %s smcp/basic --type=json -p='[{"op": "remove", "path": "/spec/security/controlPlane/tls"}]'`, "istio-system")
util.Shell(`kubectl patch -n %s smcp/basic --type merge -p '{"spec":{"security":{"dataPlane":{"mtls":false},"controlPlane":{"mtls":false}}}}'`, "istio-system")
util.Shell(`oc wait --for condition=Ready -n %s smmr/default --timeout 180s`, "istio-system")
}

func getenv(key, fallback string) string {
value := os.Getenv(key)
if len(value) == 0 {
return fallback
}
return value
util.Shell(`kubectl patch -n %s smcp/%s --type=json -p='[{"op": "remove", "path": "/spec/security/controlPlane/tls"}]'`, meshNamespace, smcpName)
util.Shell(`kubectl patch -n %s smcp/%s --type merge -p '{"spec":{"security":{"dataPlane":{"mtls":false},"controlPlane":{"mtls":false}}}}'`, meshNamespace, smcpName)
util.Shell(`oc wait --for condition=Ready -n %s smmr/default --timeout 180s`, meshNamespace)
}

func TestTLSVersionSMCP(t *testing.T) {
Expand All @@ -55,8 +46,8 @@ func TestTLSVersionSMCP(t *testing.T) {
defer util.RecoverPanic(t)

util.Log.Info("Update SMCP spec.security.controlPlane.tls.minProtocolVersion: TLSv1_0")
_, err := util.Shell(`kubectl patch -n %s smcp/basic --type merge -p '{"spec":{"security":{"controlPlane":{"tls":{"minProtocolVersion":"TLSv1_0"}}}}}'`, "istio-system")
util.Shell(`oc wait --for condition=Ready -n %s smmr/default --timeout 180s`, "istio-system")
_, err := util.Shell(`kubectl patch -n %s smcp/%s --type merge -p '{"spec":{"security":{"controlPlane":{"tls":{"minProtocolVersion":"TLSv1_0"}}}}}'`, meshNamespace, smcpName)
util.Shell(`oc wait --for condition=Ready -n %s smmr/default --timeout 180s`, meshNamespace)
if err != nil {
t.Errorf("Failed to update SMCP with tls.maxProtocolVersion: TLSv1_0")
}
Expand All @@ -66,8 +57,8 @@ func TestTLSVersionSMCP(t *testing.T) {
defer util.RecoverPanic(t)

util.Log.Info("Update SMCP spec.security.controlPlane.tls.minProtocolVersion: TLSv1_1")
_, err := util.Shell(`kubectl patch -n %s smcp/basic --type merge -p '{"spec":{"security":{"controlPlane":{"tls":{"minProtocolVersion":"TLSv1_1"}}}}}'`, "istio-system")
util.Shell(`oc wait --for condition=Ready -n %s smmr/default --timeout 180s`, "istio-system")
_, err := util.Shell(`kubectl patch -n %s smcp/%s --type merge -p '{"spec":{"security":{"controlPlane":{"tls":{"minProtocolVersion":"TLSv1_1"}}}}}'`, meshNamespace, smcpName)
util.Shell(`oc wait --for condition=Ready -n %s smmr/default --timeout 180s`, meshNamespace)
if err != nil {
t.Errorf("Failed to update SMCP with tls.maxProtocolVersion: TLSv1_1")
}
Expand All @@ -77,8 +68,8 @@ func TestTLSVersionSMCP(t *testing.T) {
defer util.RecoverPanic(t)

util.Log.Info("Update SMCP spec.security.controlPlane.tls.minProtocolVersion: TLSv1_3")
_, err := util.Shell(`kubectl patch -n %s smcp/basic --type merge -p '{"spec":{"security":{"controlPlane":{"tls":{"maxProtocolVersion":"TLSv1_3"}}}}}'`, "istio-system")
util.Shell(`oc wait --for condition=Ready -n %s smmr/default --timeout 180s`, "istio-system")
_, err := util.Shell(`kubectl patch -n %s smcp/%s --type merge -p '{"spec":{"security":{"controlPlane":{"tls":{"maxProtocolVersion":"TLSv1_3"}}}}}'`, meshNamespace, smcpName)
util.Shell(`oc wait --for condition=Ready -n %s smmr/default --timeout 180s`, meshNamespace)
if err != nil {
t.Errorf("Failed to update SMCP with tls.maxProtocolVersion: TLSv1_3")
}
Expand All @@ -93,20 +84,20 @@ func TestSSL(t *testing.T) {

// update mtls to true
util.Log.Info("Update SMCP mtls to true")
util.Shell(`kubectl patch -n %s smcp/basic --type merge -p '{"spec":{"security":{"dataPlane":{"mtls":true},"controlPlane":{"mtls":true}}}}'`, "istio-system")
util.Shell(`oc wait --for condition=Ready -n %s smmr/default --timeout 180s`, "istio-system")
util.Shell(`kubectl patch -n %s smcp/%s --type merge -p '{"spec":{"security":{"dataPlane":{"mtls":true},"controlPlane":{"mtls":true}}}}'`, meshNamespace, smcpName)
util.Shell(`oc wait --for condition=Ready -n %s smmr/default --timeout 180s`, meshNamespace)

util.Log.Info("Update SMCP spec.security.controlPlane.tls")

util.Shell(`kubectl patch -n %s smcp/basic --type merge -p '{%s:{%s,%s,%s,%s}}}}}'`,
"istio-system",
util.Shell(`kubectl patch -n %s smcp/%s --type merge -p '{%s:{%s,%s,%s,%s}}}}}'`,
meshNamespace, smcpName,
`"spec":{"security":{"controlPlane":{"tls"`,
`"minProtocolVersion":"TLSv1_2"`,
`"maxProtocolVersion":"TLSv1_2"`,
`"cipherSuites":["TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256"]`,
`"ecdhCurves":["CurveP256", "CurveP384"]`)

util.Shell(`oc wait --for condition=Ready -n %s smmr/default --timeout 180s`, "istio-system")
util.Shell(`oc wait --for condition=Ready -n %s smmr/default --timeout 180s`, meshNamespace)

util.Log.Info("Deploy bookinfo")
bookinfo := examples.Bookinfo{"bookinfo"}
Expand Down
2 changes: 1 addition & 1 deletion pkg/ossm/sme_install.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func TestExtensionInstall(t *testing.T) {

t.Run("Operator_test_sme_install", func(t *testing.T) {
defer util.RecoverPanic(t)
util.CheckPodRunning("istio-system", "app=wasm-cacher")
util.CheckPodRunning(meshNamespace, "app=wasm-cacher")

util.Log.Info("Creating ServiceMeshExtension")
util.KubeApplyContents("bookinfo", httpbinServiceMeshExtension)
Expand Down
23 changes: 19 additions & 4 deletions pkg/ossm/yaml_vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,24 @@

package ossm

import "os"

var (
smcpV21 = "../templates/smcp-templates/v2.1/cr_2.1_default.yaml"
smcpV20 = "../templates/smcp-templates/v2.0/cr_2.0_default.yaml"
smcpV11 = "../templates/smcp-templates/v1.1/cr_1.1_default.yaml"
smmr = "../templates/smmr-templates/smmr_default.yaml"
meshNamespace string = getenv("MESHNAMESPACE", "istio-system")
smcpName string = getenv("SMCPNAME", "basic")
smcpV21_template = "../templates/smcp-templates/v2.1/cr_2.1_default_template.yaml"
smcpV20_template = "../templates/smcp-templates/v2.0/cr_2.0_default_template.yaml"
smcpV11_template = "../templates/smcp-templates/v1.1/cr_1.1_default_template.yaml"
smcpV21 = "../templates/smcp-templates/v2.1/cr_2.1_default.yaml"
smcpV20 = "../templates/smcp-templates/v2.0/cr_2.0_default.yaml"
smcpV11 = "../templates/smcp-templates/v1.1/cr_1.1_default.yaml"
smmr = "../templates/smmr-templates/smmr_default.yaml"
)

func getenv(key, fallback string) string {
value := os.Getenv(key)
if len(value) == 0 {
return fallback
}
return value
}

0 comments on commit 9779a0b

Please sign in to comment.