Skip to content

Commit

Permalink
Restore initial configmap contents after install tests
Browse files Browse the repository at this point in the history
This implements cleanup, enabling agent TLS mode tests to be run
multiple times and not necessarily after all other tests.
  • Loading branch information
weyfonk committed Jun 14, 2024
1 parent 3531871 commit ce0e72e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
2 changes: 0 additions & 2 deletions e2e/multi-cluster/installation/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@ import (
var (
agentMode string
kd kubectl.Command
ku kubectl.Command
)

var _ = Describe("Fleet installation with TLS agent modes", func() {
BeforeEach(func() {
kd = env.Kubectl.Context(env.Downstream)
ku = env.Kubectl.Context(env.Upstream)
})

JustBeforeEach(func() {
Expand Down
35 changes: 34 additions & 1 deletion e2e/multi-cluster/installation/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
package installation_test

import (
"fmt"
"strings"
"testing"

"github.com/rancher/fleet/e2e/testenv"
"github.com/rancher/fleet/e2e/testenv/kubectl"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
Expand All @@ -17,12 +20,42 @@ func TestE2E(t *testing.T) {
}

var (
env *testenv.Env
env *testenv.Env
ku kubectl.Command
config string
)

var _ = BeforeSuite(func() {
SetDefaultEventuallyTimeout(testenv.Timeout)
testenv.SetRoot("../..")

env = testenv.New()
ku = env.Kubectl.Context(env.Upstream)

// Save initial state of `fleet-controller` config map
cfg, err := ku.Get(
"configmap",
"fleet-controller",
"-n",
"cattle-fleet-system",
"-o",
"jsonpath={.data.config}")
Expect(err).ToNot(HaveOccurred(), cfg)

cfg = strings.ReplaceAll(cfg, `"`, `\"`)
config = strings.ReplaceAll(cfg, "\n", "")
})

var _ = AfterSuite(func() {
// Restore initial state of config map
out, err := ku.Patch(
"configmap",
"fleet-controller",
"-n",
"cattle-fleet-system",
"--type=merge",
"-p",
fmt.Sprintf(`{"data":{"config":"%s"}}`, config),
)
Expect(err).ToNot(HaveOccurred(), string(out))
})

0 comments on commit ce0e72e

Please sign in to comment.