Skip to content

Commit

Permalink
OSSM-1397 Add test to check whether the operator adds back the `maist…
Browse files Browse the repository at this point in the history
…ra.io/member-of` label after it's removed (#639)
  • Loading branch information
luksa authored Nov 27, 2023
1 parent 0fbd864 commit fcedfe8
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 4 deletions.
6 changes: 3 additions & 3 deletions pkg/tests/ossm/deploy_on_infra_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
27 changes: 27 additions & 0 deletions pkg/tests/ossm/smm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions pkg/util/oc/oc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 5 additions & 1 deletion pkg/util/oc/oc_struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit fcedfe8

Please sign in to comment.