diff --git a/pkg/tests/ossm/deploy_on_infra_test.go b/pkg/tests/ossm/deploy_on_infra_test.go index aa48b13d..28786bb4 100644 --- a/pkg/tests/ossm/deploy_on_infra_test.go +++ b/pkg/tests/ossm/deploy_on_infra_test.go @@ -52,9 +52,9 @@ func TestDeployOnInfraNodes(t *testing.T) { oc.TaintNode(t, "-l node-role.kubernetes.io/infra", "node-role.kubernetes.io/infra=reserved:NoSchedule-", "node-role.kubernetes.io/infra=reserved:NoExecute-") - oc.Label(t, "", "node", workername, "node-role.kubernetes.io/infra-") - oc.Label(t, "", "node", workername, "node-role.kubernetes.io-") - //TODO: to improve this after merge this PR: https://github.com/maistra/maistra-test-tool/pull/597 we need to reuse waitOperatorSucceded and make that func available to all the code + oc.RemoveLabel(t, "", "node", workername, "node-role.kubernetes.io/infra") + oc.RemoveLabel(t, "", "node", workername, "node-role.kubernetes.io") + // TODO: to improve this after merge this PR: https://github.com/maistra/maistra-test-tool/pull/597 we need to reuse waitOperatorSucceded and make that func available to all the code // Use waitOperatorSucceded will avoid flaky in this test case locator := pod.MatchingSelector("name=istio-operator", "openshift-operators") oc.WaitPodReady(t, locator) diff --git a/pkg/tests/ossm/smm_test.go b/pkg/tests/ossm/smm_test.go index 8b7f3b83..9cbdd143 100644 --- a/pkg/tests/ossm/smm_test.go +++ b/pkg/tests/ossm/smm_test.go @@ -5,6 +5,7 @@ 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/retry" "github.com/maistra/maistra-test-tool/pkg/util/shell" @@ -83,6 +84,32 @@ func TestSMMRAutoCreationAndDeletion(t *testing.T) { }) } +func TestSMMReconciliation(t *testing.T) { + NewTest(t).Groups(Full, Disconnected).Run(func(t TestHelper) { + t.Log("This test verifies whether the member-of label is added back to the namespace") + t.Log("See https://issues.redhat.com/browse/OSSM-1397") + + t.Cleanup(func() { + oc.RecreateNamespace(t, meshNamespace) + }) + + DeployControlPlane(t) + + t.Log("Remove maistra.io/member-of label from bookinfo namespace") + oc.RemoveLabel(t, "", "Namespace", ns.Bookinfo, "maistra.io/member-of") + + t.LogStep("Check if label was added back by the operator") + retry.UntilSuccess(t, func(t test.TestHelper) { + oc.GetYaml(t, + "", "namespace", ns.Bookinfo, + assert.OutputContains( + "maistra.io/member-of", + "The maistra.io/member-of label was added back", + "The maistra.io/member-of label was not added back")) + }) + }) +} + var ( smm = ` apiVersion: maistra.io/v1 diff --git a/pkg/util/oc/oc.go b/pkg/util/oc/oc.go index 740bb3d1..c74f4cb5 100644 --- a/pkg/util/oc/oc.go +++ b/pkg/util/oc/oc.go @@ -236,6 +236,11 @@ func TouchSMCP(t test.TestHelper, ns string, name string) { DefaultOC.TouchSMCP(t, ns, name) } +func RemoveLabel(t test.TestHelper, ns string, kind string, name string, label string) { + t.T().Helper() + DefaultOC.RemoveLabel(t, ns, kind, name, label) +} + func Label(t test.TestHelper, ns string, kind string, name string, labels string) { t.T().Helper() DefaultOC.Label(t, ns, kind, name, labels) diff --git a/pkg/util/oc/oc_struct.go b/pkg/util/oc/oc_struct.go index 9fa66057..4e04fb07 100644 --- a/pkg/util/oc/oc_struct.go +++ b/pkg/util/oc/oc_struct.go @@ -392,11 +392,15 @@ func (o OC) TaintNode(t test.TestHelper, name string, taints ...string) { }) } +func (o OC) RemoveLabel(t test.TestHelper, ns string, kind string, name string, label string) { + o.Label(t, ns, kind, name, label+"-") +} + func (o OC) Label(t test.TestHelper, ns string, kind string, name string, labels string) { t.T().Helper() nsFlag := "" if ns != "" { - nsFlag = "-n " + ns + nsFlag = fmt.Sprintf("-n %s ", ns) } o.withKubeconfig(t, func() { t.T().Helper()