-
Notifications
You must be signed in to change notification settings - Fork 239
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GitRepo Initial Checkout when DisablePolling is True #2469
Merged
Merged
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
e4bd1c5
first implementation
d40be01
changes
3736985
changes
f6a0b04
changes
5bf2190
changes
b0dfe21
changes
4caed92
integration test in the gitjob controller test suit
c912345
re added a test case
c45f0c9
fix
b2342bb
reformating and some useless lines removed
77ad5c4
typo
Tommy12789 743b7a7
Commit updated when force updating
Tommy12789 fbf05e8
conflict
Tommy12789 c1399a1
fixed some conflicts log error messages
Tommy12789 4631d7f
fix comments
Tommy12789 e30d640
Merge branch 'main' into 2432
Tommy12789 6faec86
fix rebase
Tommy12789 b987734
e2e test initial checkout and forceUpdate
Tommy12789 b11d4e1
little fixes
Tommy12789 f7f4762
label fix
Tommy12789 16c03e1
fix
Tommy12789 01ed58b
fix
Tommy12789 fa97aaa
added commit verification after forceUpdate
Tommy12789 286dbd7
fix
Tommy12789 abdb090
fix
Tommy12789 8d29f68
Merge branch 'main' into 2432
Tommy12789 08eeb72
fixed GitRepo to gitrepo
Tommy12789 1f2fb40
goimported
Tommy12789 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
apiVersion: fleet.cattle.io/v1alpha1 | ||
kind: GitRepo | ||
metadata: | ||
name: {{ .Name }} | ||
spec: | ||
repo: {{ .Repo }} | ||
branch: {{ .Branch }} | ||
paths: | ||
- disable_polling | ||
targetNamespace: {{ .TargetNamespace }} | ||
disablePolling: true | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
package singlecluster_test | ||
|
||
import ( | ||
"math/rand" | ||
"os" | ||
"path" | ||
|
||
"github.com/go-git/go-git/v5" | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
|
||
"github.com/rancher/fleet/e2e/testenv" | ||
"github.com/rancher/fleet/e2e/testenv/githelper" | ||
"github.com/rancher/fleet/e2e/testenv/kubectl" | ||
) | ||
|
||
var _ = Describe("GitRepoPollingDisabled", Label("infra-setup"), func() { | ||
var ( | ||
tmpDir string | ||
clonedir string | ||
k kubectl.Command | ||
gh *githelper.Git | ||
clone *git.Repository | ||
repoName string | ||
inClusterRepoURL string | ||
gitrepoName string | ||
r = rand.New(rand.NewSource(GinkgoRandomSeed())) | ||
targetNamespace string | ||
) | ||
|
||
BeforeEach(func() { | ||
k = env.Kubectl.Namespace(env.Namespace) | ||
}) | ||
|
||
JustBeforeEach(func() { | ||
// 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) | ||
|
||
gitrepoName = testenv.RandomFilename("gitjob-test", r) | ||
}) | ||
|
||
AfterEach(func() { | ||
_ = os.RemoveAll(tmpDir) | ||
|
||
_, err := k.Delete("gitrepo", gitrepoName) | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
Eventually(func() string { | ||
out, _ := k.Get("bundledeployments", "-A") | ||
return out | ||
}).ShouldNot(ContainSubstring(gitrepoName)) | ||
|
||
out, err := k.Namespace("cattle-fleet-system").Logs( | ||
"-l", | ||
"app=fleet-controller", | ||
"-c", | ||
"fleet-controller", | ||
) | ||
Expect(err).ToNot(HaveOccurred()) | ||
Expect(out).ToNot(ContainSubstring("ERROR")) | ||
}) | ||
|
||
When("applying a gitrepo with disable polling", func() { | ||
BeforeEach(func() { | ||
repoName = "repo" | ||
targetNamespace = testenv.NewNamespaceName("disable-polling", r) | ||
}) | ||
|
||
JustBeforeEach(func() { | ||
err := testenv.ApplyTemplate(k, testenv.AssetPath("gitrepo/gitrepo-polling-disabled.yaml"), struct { | ||
Name string | ||
Repo string | ||
Branch string | ||
TargetNamespace string | ||
}{ | ||
gitrepoName, | ||
inClusterRepoURL, | ||
gh.Branch, | ||
targetNamespace, | ||
}) | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
clone, err = gh.Create(clonedir, testenv.AssetPath("gitrepo/sleeper-chart"), "disable_polling") | ||
Expect(err).ToNot(HaveOccurred()) | ||
}) | ||
|
||
It("deploys the resources initially and updates them while force updating", func() { | ||
By("checking the pod exists") | ||
Eventually(func() string { | ||
out, _ := k.Namespace(targetNamespace).Get("pods") | ||
return out | ||
}).Should(ContainSubstring("sleeper-")) | ||
|
||
By("Updating the git repository") | ||
replace(path.Join(clonedir, "disable_polling", "templates", "deployment.yaml"), "name: sleeper", "name: newsleep") | ||
|
||
commit, err := gh.Update(clone) | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
By("Verifying the pods aren't updated") | ||
Eventually(func() string { | ||
out, _ := k.Namespace(targetNamespace).Get("pods") | ||
return out | ||
}).ShouldNot(ContainSubstring("newsleep")) | ||
|
||
By("Force updating the GitRepo") | ||
patch := `{"spec": {"forceSyncGeneration": 1}}` | ||
out, err := k.Run("patch", "gitrepo", gitrepoName, "--type=merge", "--patch", patch) | ||
Expect(err).ToNot(HaveOccurred(), out) | ||
|
||
By("Verifying the pods are updated") | ||
Eventually(func() string { | ||
out, _ := k.Namespace(targetNamespace).Get("pods") | ||
return out | ||
}).Should(ContainSubstring("newsleep")) | ||
|
||
By("Verifying the commit hash is updated") | ||
Eventually(func() string { | ||
out, _ := k.Get("gitrepo", gitrepoName, "-o", "jsonpath={.status.commit}") | ||
return out | ||
}).Should(Equal(commit)) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: This could be flagged as a failure if any previous test failed.