Skip to content

Commit

Permalink
refactor namespaces (#693)
Browse files Browse the repository at this point in the history
Co-authored-by: Praneeth Bajjuri <pbajjuri@pbajjuri-thinkpadp1gen4i.rmtustx.csb>
  • Loading branch information
pbajjuri20 and Praneeth Bajjuri committed Jun 14, 2024
1 parent 3bdb2d6 commit dcaea88
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 56 deletions.
12 changes: 6 additions & 6 deletions pkg/tests/ossm/initcontainer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,34 +18,34 @@ import (
"testing"

"github.com/maistra/maistra-test-tool/pkg/util/check/assert"
"github.com/maistra/maistra-test-tool/pkg/util/ns"
"github.com/maistra/maistra-test-tool/pkg/util/oc"
"github.com/maistra/maistra-test-tool/pkg/util/pod"
. "github.com/maistra/maistra-test-tool/pkg/util/test"
)

func TestInitContainerNotRemovedDuringInjection(t *testing.T) {
const ns = "bookinfo"
const goldString = "[init worked]"
const podSelector = "app=sleep-init"

NewTest(t).Id("T33").Groups(Full, ARM).Run(func(t TestHelper) {
t.Log("Checking init container not removed during sidecar injection.")

t.Cleanup(func() {
oc.RecreateNamespace(t, ns)
oc.RecreateNamespace(t, ns.Bookinfo)
})

DeployControlPlane(t)

oc.RecreateNamespace(t, ns)
oc.RecreateNamespace(t, ns.Bookinfo)

t.LogStep("Deploying test pod.")
oc.ApplyString(t, ns, testInitContainerYAML)
oc.WaitDeploymentRolloutComplete(t, ns, "sleep-init")
oc.ApplyString(t, ns.Bookinfo, testInitContainerYAML)
oc.WaitDeploymentRolloutComplete(t, ns.Bookinfo, "sleep-init")

t.LogStep("Checking pod logs for init message.")
oc.Logs(t,
pod.MatchingSelector(podSelector, ns),
pod.MatchingSelector(podSelector, ns.Bookinfo),
"init",
assert.OutputContains(goldString,
"Init container executed successfully.",
Expand Down
6 changes: 3 additions & 3 deletions pkg/tests/ossm/ratelimit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/maistra/maistra-test-tool/pkg/app"
"github.com/maistra/maistra-test-tool/pkg/util/check/assert"
"github.com/maistra/maistra-test-tool/pkg/util/curl"
"github.com/maistra/maistra-test-tool/pkg/util/ns"
"github.com/maistra/maistra-test-tool/pkg/util/oc"
"github.com/maistra/maistra-test-tool/pkg/util/retry"
"github.com/maistra/maistra-test-tool/pkg/util/shell"
Expand All @@ -41,15 +42,14 @@ var (

func TestRateLimiting(t *testing.T) {
NewTest(t).Id("T28").Groups(Full, ARM).MaxVersion(version.SMCP_2_2).Run(func(t TestHelper) {
ns := "bookinfo"
nsRedis := "redis"

DeployControlPlane(t)

t.LogStep("Install Bookinfo and Redis")
app.InstallAndWaitReady(t, app.Bookinfo(ns), app.Redis(nsRedis))
app.InstallAndWaitReady(t, app.Bookinfo(ns.Bookinfo), app.Redis(nsRedis))
t.Cleanup(func() {
app.Uninstall(t, app.Bookinfo(ns), app.Redis(nsRedis))
app.Uninstall(t, app.Bookinfo(ns.Bookinfo), app.Redis(nsRedis))
oc.DeleteNamespace(t, nsRedis) // namespace redis is only used in this test, so delete it after test
})

Expand Down
19 changes: 9 additions & 10 deletions pkg/tests/ossm/smcp_annotation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

"gopkg.in/yaml.v2"

"github.com/maistra/maistra-test-tool/pkg/util/ns"
"github.com/maistra/maistra-test-tool/pkg/util/oc"
"github.com/maistra/maistra-test-tool/pkg/util/pod"
"github.com/maistra/maistra-test-tool/pkg/util/retry"
Expand All @@ -34,26 +35,24 @@ func TestSMCPAnnotations(t *testing.T) {

t.NewSubTest("proxyEnvoy").Run(func(t test.TestHelper) {
t.Parallel()
ns := "foo"
t.Cleanup(func() {
oc.DeleteFromTemplate(t, ns, testSSLDeploymentWithAnnotation, nil)
oc.DeleteFromTemplate(t, ns.Foo, testSSLDeploymentWithAnnotation, nil)
})
t.LogStep("Deploy TestSSL pod with annotations sidecar.maistra.io/proxyEnv")
oc.ApplyTemplate(t, ns, testSSLDeploymentWithAnnotation, nil)
oc.WaitDeploymentRolloutComplete(t, ns, "testenv")
oc.ApplyTemplate(t, ns.Foo, testSSLDeploymentWithAnnotation, nil)
oc.WaitDeploymentRolloutComplete(t, ns.Foo, "testenv")

t.LogStep("Get annotations and verify that the pod has the expected: sidecar.maistra.io/proxyEnv : { \"maistra_test_env\": \"env_value\", \"maistra_test_env_2\": \"env_value_2\" }")
annotations := VerifyAndGetPodAnnotation(t, pod.MatchingSelector("app=env", ns))
annotations := VerifyAndGetPodAnnotation(t, pod.MatchingSelector("app=env", ns.Foo))
assertAnnotationIsPresent(t, annotations, "sidecar.maistra.io/proxyEnv", `{ "maistra_test_env": "env_value", "maistra_test_env_2": "env_value_2" }`)
})

// Test that the SMCP automatic injection with quotes works
t.NewSubTest("quote_injection").Run(func(t test.TestHelper) {
t.Parallel()
ns := "bar"
t.Cleanup(func() {
oc.Patch(t, meshNamespace, "smcp", smcpName, "json", `[{"op": "remove", "path": "/spec/proxy"}]`)
oc.DeleteFromTemplate(t, ns, testSSLDeploymentWithAnnotation, nil)
oc.DeleteFromTemplate(t, ns.Bar, testSSLDeploymentWithAnnotation, nil)
})
t.LogStep("Enable annotation auto injection in SMCP")
oc.Patch(t,
Expand All @@ -64,12 +63,12 @@ func TestSMCPAnnotations(t *testing.T) {
oc.WaitSMCPReady(t, meshNamespace, smcpName)

t.LogStep("Deploy TestSSL pod with annotations sidecar.maistra.io/proxyEnv")
oc.ApplyTemplate(t, ns, testSSLDeploymentWithAnnotation, nil)
oc.WaitDeploymentRolloutComplete(t, ns, "testenv")
oc.ApplyTemplate(t, ns.Bar, testSSLDeploymentWithAnnotation, nil)
oc.WaitDeploymentRolloutComplete(t, ns.Bar, "testenv")

t.LogStep("Get annotations and verify that the pod has the expected: test1.annotation-from-smcp : test1, test2.annotation-from-smcp : [\"test2\"], test3.annotation-from-smcp : {test3}")
retry.UntilSuccess(t, func(t test.TestHelper) {
annotations := VerifyAndGetPodAnnotation(t, pod.MatchingSelector("app=env", ns))
annotations := VerifyAndGetPodAnnotation(t, pod.MatchingSelector("app=env", ns.Bar))
assertAnnotationIsPresent(t, annotations, "test1.annotation-from-smcp", "test1")
assertAnnotationIsPresent(t, annotations, "test2.annotation-from-smcp", `["test2"]`)
assertAnnotationIsPresent(t, annotations, "test3.annotation-from-smcp", "{test3}")
Expand Down
6 changes: 3 additions & 3 deletions pkg/tests/ossm/smcp_must_gather_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/maistra/maistra-test-tool/pkg/util/check/assert"
"github.com/maistra/maistra-test-tool/pkg/util/check/common"
"github.com/maistra/maistra-test-tool/pkg/util/env"
"github.com/maistra/maistra-test-tool/pkg/util/ns"
"github.com/maistra/maistra-test-tool/pkg/util/oc"
"github.com/maistra/maistra-test-tool/pkg/util/shell"

Expand All @@ -35,15 +36,14 @@ func TestMustGather(t *testing.T) {
NewTest(t).Id("T30").Groups(Full, ARM).Run(func(t TestHelper) {
t.Log("This test verifies must-gather log collection")

ns := "bookinfo"
t.Cleanup(func() {
oc.RecreateNamespace(t, ns)
oc.RecreateNamespace(t, ns.Bookinfo)
})

DeployControlPlane(t)

t.LogStep("Deploy bookinfo in bookinfo ns")
app.InstallAndWaitReady(t, app.Bookinfo(ns))
app.InstallAndWaitReady(t, app.Bookinfo(ns.Bookinfo))

image := env.GetMustGatherImage()
dir := shell.CreateTempDir(t, "must-gather-")
Expand Down
17 changes: 8 additions & 9 deletions pkg/tests/ossm/smm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ import (
func TestSMMRAutoCreationAndDeletion(t *testing.T) {
NewTest(t).Id("T39").Groups(Full, Disconnected, ARM).Run(func(t TestHelper) {
t.Log("This test verifies what happens to the SMMR when SMM is created and deleted")
foo := "foo"
bar := "bar"

t.Cleanup(func() {
oc.ApplyString(t, meshNamespace, smmr) // revert SMMR to original state
})
Expand All @@ -29,14 +28,14 @@ func TestSMMRAutoCreationAndDeletion(t *testing.T) {
oc.DeleteResource(t, meshNamespace, "smmr", "default")

t.LogStep("Create two namespaces")
oc.CreateNamespace(t, foo, bar)
oc.CreateNamespace(t, ns.Foo, ns.Bar)

t.NewSubTest("create first SMM").Run(func(t TestHelper) {
t.Log("This test checks if the SMMR is created when you create a ServiceMeshMember")

t.LogStep("Create ServiceMeshMembers in namespaces foo and bar")
oc.ApplyString(t, foo, smm)
oc.ApplyString(t, bar, smm)
oc.ApplyString(t, ns.Foo, smm)
oc.ApplyString(t, ns.Bar, smm)

t.LogStep("Wait for SMMR to be ready")
oc.WaitSMMRReady(t, meshNamespace)
Expand All @@ -45,8 +44,8 @@ func TestSMMRAutoCreationAndDeletion(t *testing.T) {
retry.UntilSuccess(t, func(t TestHelper) {
shell.Execute(t,
fmt.Sprintf(`oc get smmr default -n %s -o=jsonpath='{.status.members[*]}{"\n"}'`, meshNamespace),
assert.OutputContains(foo, "SMMR has the member foo", "SMMR does not have the namespaces foo and bar"),
assert.OutputContains(bar, "SMMR has the member bar", "SMMR does not have the namespaces foo and bar"))
assert.OutputContains(ns.Foo, "SMMR has the member foo", "SMMR does not have the namespaces foo and bar"),
assert.OutputContains(ns.Bar, "SMMR has the member bar", "SMMR does not have the namespaces foo and bar"))
})
})

Expand All @@ -56,7 +55,7 @@ func TestSMMRAutoCreationAndDeletion(t *testing.T) {
t.Log("See https://issues.redhat.com/browse/OSSM-3450 (test)")

t.LogStep("Delete one SMM, but keep the other")
oc.DeleteFromString(t, bar, smm)
oc.DeleteFromString(t, ns.Bar, smm)

t.LogStep("Check if SMMR becomes ready (it won't be if it gets deleted)")
retry.UntilSuccess(t, func(t TestHelper) {
Expand All @@ -70,7 +69,7 @@ func TestSMMRAutoCreationAndDeletion(t *testing.T) {
t.Log("See https://issues.redhat.com/browse/OSSM-3450 (test)")

t.LogStep("Delete last SMM")
oc.DeleteFromString(t, foo, smm)
oc.DeleteFromString(t, ns.Foo, smm)

t.LogStep("Check that SMMR is deleted")
retry.UntilSuccess(t, func(t TestHelper) {
Expand Down
14 changes: 7 additions & 7 deletions pkg/tests/ossm/testssl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/maistra/maistra-test-tool/pkg/app"
"github.com/maistra/maistra-test-tool/pkg/util/check/assert"
"github.com/maistra/maistra-test-tool/pkg/util/env"
"github.com/maistra/maistra-test-tool/pkg/util/ns"
"github.com/maistra/maistra-test-tool/pkg/util/oc"
"github.com/maistra/maistra-test-tool/pkg/util/pod"
"github.com/maistra/maistra-test-tool/pkg/util/retry"
Expand All @@ -28,7 +29,6 @@ import (

func TestSSL(t *testing.T) {
NewTest(t).Id("T27").Groups(Full, InterOp, ARM).Run(func(t TestHelper) {
ns := "bookinfo"
t.Cleanup(func() {
oc.Patch(t, meshNamespace, "smcp", smcpName, "json", `[{"op": "remove", "path": "/spec/security/controlPlane/tls"}]`)
oc.Patch(t, meshNamespace, "smcp", smcpName, "merge", `
Expand All @@ -39,8 +39,8 @@ spec:
controlPlane:
mtls: false
`)
app.Uninstall(t, app.BookinfoWithMTLS(ns))
oc.DeleteFromTemplate(t, ns, testSSLDeployment, nil)
app.Uninstall(t, app.BookinfoWithMTLS(ns.Bookinfo))
oc.DeleteFromTemplate(t, ns.Bookinfo, testSSLDeployment, nil)
})

DeployControlPlane(t) // TODO: integrate below patch here
Expand All @@ -65,9 +65,9 @@ spec:
oc.WaitSMCPReady(t, meshNamespace, smcpName)

t.LogStep("Install bookinfo with mTLS and testssl pod")
oc.ApplyTemplate(t, ns, testSSLDeployment, nil)
app.InstallAndWaitReady(t, app.BookinfoWithMTLS(ns))
oc.WaitDeploymentRolloutComplete(t, ns, "testssl")
oc.ApplyTemplate(t, ns.Bookinfo, testSSLDeployment, nil)
app.InstallAndWaitReady(t, app.BookinfoWithMTLS(ns.Bookinfo))
oc.WaitDeploymentRolloutComplete(t, ns.Bookinfo, "testssl")

t.LogStep("Check testssl.sh results")
command := "./testssl/testssl.sh -P -6 productpage:9080 || true"
Expand All @@ -76,7 +76,7 @@ spec:
}
retry.UntilSuccessWithOptions(t, retry.Options().MaxAttempts(10), func(t TestHelper) {
oc.Exec(t,
pod.MatchingSelector("app=testssl", ns),
pod.MatchingSelector("app=testssl", ns.Bookinfo),
"testssl",
command,
assert.OutputContains(
Expand Down
21 changes: 11 additions & 10 deletions pkg/tests/tasks/security/authentication/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/maistra/maistra-test-tool/pkg/util/curl"
"github.com/maistra/maistra-test-tool/pkg/util/env"
"github.com/maistra/maistra-test-tool/pkg/util/istio"
"github.com/maistra/maistra-test-tool/pkg/util/ns"
"github.com/maistra/maistra-test-tool/pkg/util/oc"
"github.com/maistra/maistra-test-tool/pkg/util/request"
"github.com/maistra/maistra-test-tool/pkg/util/retry"
Expand All @@ -41,22 +42,22 @@ func TestAuthPolicy(t *testing.T) {
t.Log("Doc reference: https://istio.io/latest/docs/tasks/security/authentication/authn-policy/")

t.Cleanup(func() {
oc.RecreateNamespace(t, "foo", "bar", "legacy")
oc.RecreateNamespace(t, ns.Foo, ns.Bar, ns.Legacy)
})

ossm.DeployControlPlane(t)

t.LogStep("Install httpbin and sleep in multiple namespaces")
app.InstallAndWaitReady(t,
app.Httpbin("foo"),
app.Httpbin("bar"),
app.HttpbinNoSidecar("legacy"),
app.Sleep("foo"),
app.Sleep("bar"),
app.SleepNoSidecar("legacy"))

fromNamespaces := []string{"foo", "bar", "legacy"}
toNamespaces := []string{"foo", "bar"}
app.Httpbin(ns.Foo),
app.Httpbin(ns.Bar),
app.HttpbinNoSidecar(ns.Legacy),
app.Sleep(ns.Foo),
app.Sleep(ns.Bar),
app.SleepNoSidecar(ns.Legacy))

fromNamespaces := []string{ns.Foo, ns.Bar, ns.Legacy}
toNamespaces := []string{ns.Foo, ns.Bar}

t.LogStep("Check connectivity from namespaces foo, bar, and legacy to namespaces foo and bar")
retry.UntilSuccess(t, func(t TestHelper) {
Expand Down
17 changes: 9 additions & 8 deletions pkg/tests/tasks/security/authentication/mtls_migration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/maistra/maistra-test-tool/pkg/app"
"github.com/maistra/maistra-test-tool/pkg/tests/ossm"
"github.com/maistra/maistra-test-tool/pkg/util/env"
"github.com/maistra/maistra-test-tool/pkg/util/ns"
"github.com/maistra/maistra-test-tool/pkg/util/oc"
"github.com/maistra/maistra-test-tool/pkg/util/retry"
"github.com/maistra/maistra-test-tool/pkg/util/test"
Expand All @@ -31,21 +32,21 @@ func TestMTlsMigration(t *testing.T) {
meshNamespace := env.GetDefaultMeshNamespace()

t.Cleanup(func() {
oc.RecreateNamespace(t, "foo", "bar", "legacy") // TODO: recreate all three namespaces with a single call to RecreateNamespace
oc.RecreateNamespace(t, ns.Foo, ns.Bar, ns.Legacy) // TODO: recreate all three namespaces with a single call to RecreateNamespace
})

ossm.DeployControlPlane(t)

t.LogStep("Install httpbin and sleep in multiple namespaces")
app.InstallAndWaitReady(t,
app.Httpbin("foo"),
app.Httpbin("bar"),
app.Sleep("foo"),
app.Sleep("bar"),
app.SleepNoSidecar("legacy"))
app.Httpbin(ns.Foo),
app.Httpbin(ns.Bar),
app.Sleep(ns.Foo),
app.Sleep(ns.Bar),
app.SleepNoSidecar(ns.Legacy))

fromNamespaces := []string{"foo", "bar", "legacy"}
toNamespaces := []string{"foo", "bar"}
fromNamespaces := []string{ns.Foo, ns.Bar, ns.Legacy}
toNamespaces := []string{ns.Foo, ns.Bar}

t.LogStep("Check connectivity from namespaces foo, bar, and legacy to namespace foo and bar")
retry.UntilSuccess(t, func(t test.TestHelper) {
Expand Down

0 comments on commit dcaea88

Please sign in to comment.