Skip to content

Commit

Permalink
Simplify sharding end-to-end tests (rancher#2396)
Browse files Browse the repository at this point in the history
This makes sharding end-to-end tests more lightweight by relying on
`GitRepo`s pointing to an external repository. Relying on test
infrastructure and creating git repositories on-the-fly is not
necessary, because sharding tests don't need to push any commit.

Checks on Fleet controller logs are now more reliable, by consistently
tailing the last 100 log entries.
  • Loading branch information
weyfonk authored May 3, 2024
1 parent b996ca8 commit a2ee46e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 41 deletions.
2 changes: 1 addition & 1 deletion e2e/assets/gitrepo/gitrepo_sharded.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ spec:
pollingInterval: {{.PollingInterval}}
targetNamespace: {{.TargetNamespace}}
paths:
- examples
- simple-chart
57 changes: 17 additions & 40 deletions e2e/single-cluster/sharding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,22 @@ package singlecluster_test
import (
"fmt"
"math/rand"
"os"
"path"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/matchers"
"github.com/rancher/fleet/e2e/testenv"
"github.com/rancher/fleet/e2e/testenv/githelper"
"github.com/rancher/fleet/e2e/testenv/kubectl"
)

var shards = []string{"shard1", "shard2", "shard3"}

var _ = Describe("Filtering events by shard", Label("sharding", "infra-setup"), Ordered, func() {
var _ = Describe("Filtering events by shard", Label("sharding"), Ordered, func() {
var (
tmpDir string
clonedir string
k kubectl.Command
gh *githelper.Git
inClusterRepoURL string
gitrepoName string
r = rand.New(rand.NewSource(GinkgoRandomSeed()))
targetNamespace string
k kubectl.Command
gitrepoName string
r = rand.New(rand.NewSource(GinkgoRandomSeed()))
targetNamespace string
)

BeforeAll(func() {
Expand All @@ -45,22 +38,6 @@ var _ = Describe("Filtering events by shard", Label("sharding", "infra-setup"),
Expect(hasReconciledGitRepos).To(BeFalse())
}

// Build git repo URL reachable _within_ the cluster, for the GitRepo
host, err := githelper.BuildGitHostname(env.Namespace)
Expect(err).ToNot(HaveOccurred())

addr, err := githelper.GetExternalRepoAddr(env, port, repoName)
Expect(err).ToNot(HaveOccurred())
gh = githelper.NewHTTP(addr)

inClusterRepoURL = gh.GetInClusterURL(host, port, repoName)

tmpDir, _ = os.MkdirTemp("", "fleet-")
clonedir = path.Join(tmpDir, repoName)

_, err = gh.Create(clonedir, testenv.AssetPath("gitrepo/sleeper-chart"), "examples")
Expect(err).ToNot(HaveOccurred())

k = env.Kubectl.Namespace(env.Namespace)
})

Expand All @@ -82,8 +59,8 @@ var _ = Describe("Filtering events by shard", Label("sharding", "infra-setup"),
ShardID string
}{
gitrepoName,
inClusterRepoURL,
gh.Branch,
"https://github.com/rancher/fleet-test-data",
"master",
"15s", // default
targetNamespace, // to avoid conflicts with other tests
shard,
Expand All @@ -93,11 +70,11 @@ var _ = Describe("Filtering events by shard", Label("sharding", "infra-setup"),
})

It(fmt.Sprintf("deploys the gitrepo via the controller labeled with shard ID %s", shard), func() {
By("checking the pod exists")
By("checking the configmap exists")
Eventually(func() string {
out, _ := k.Namespace(targetNamespace).Get("pods")
out, _ := k.Namespace(targetNamespace).Get("configmaps")
return out
}).Should(ContainSubstring("sleeper-"))
}).Should(ContainSubstring("test-simple-chart-config"))

for _, s := range shards {
Eventually(func(g Gomega) {
Expand All @@ -106,6 +83,7 @@ var _ = Describe("Filtering events by shard", Label("sharding", "infra-setup"),
"app=fleet-controller",
"-l",
fmt.Sprintf("shard=%s", s),
"--tail=100",
)
g.Expect(err).ToNot(HaveOccurred())
regexMatcher := matchers.MatchRegexpMatcher{
Expand Down Expand Up @@ -136,7 +114,6 @@ var _ = Describe("Filtering events by shard", Label("sharding", "infra-setup"),
})

AfterEach(func() {
_ = os.RemoveAll(tmpDir)
_, _ = k.Delete("gitrepo", gitrepoName)
})
})
Expand All @@ -156,8 +133,8 @@ var _ = Describe("Filtering events by shard", Label("sharding", "infra-setup"),
ShardID string
}{
gitrepoName,
inClusterRepoURL,
gh.Branch,
"https://github.com/rancher/fleet-test-data",
"master",
"15s", // default
targetNamespace, // to avoid conflicts with other tests
"unknown",
Expand All @@ -166,18 +143,19 @@ var _ = Describe("Filtering events by shard", Label("sharding", "infra-setup"),
})

It("does not deploy the gitrepo", func() {
By("checking the pod does not exist")
By("checking the configmap does not exist")
Eventually(func() string {
out, _ := k.Namespace(targetNamespace).Get("pods")
out, _ := k.Namespace(targetNamespace).Get("configmaps")
return out
}).ShouldNot(ContainSubstring("sleeper-"))
}).ShouldNot(ContainSubstring("test-simple-chart-config"))

for _, s := range shards {
logs, err := k.Namespace("cattle-fleet-system").Logs(
"-l",
"app=fleet-controller",
"-l",
fmt.Sprintf("shard=%s", s),
"--tail=100",
)
Expect(err).ToNot(HaveOccurred())
regexMatcher := matchers.MatchRegexpMatcher{
Expand All @@ -199,7 +177,6 @@ var _ = Describe("Filtering events by shard", Label("sharding", "infra-setup"),
})

AfterEach(func() {
_ = os.RemoveAll(tmpDir)
_, _ = k.Delete("gitrepo", gitrepoName)
})
})
Expand Down

0 comments on commit a2ee46e

Please sign in to comment.