-
Notifications
You must be signed in to change notification settings - Fork 30
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
Add usage of list trees to include cluster files in deletion pr #1210
Conversation
c69772e
to
10185c8
Compare
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.
This is really clean 💯 , looking great!
The only thing is making sure we support gitlab too. It would be nice to keep go-git-providers as the interface abstraction layer over both github/gitlab (instead of e.g. branching here based on provider type, and doing ListTree for github and GetFiles(recursive=true) for gitlab.
Would it be tricky to implement ListTrees in ggp for gitlab?
currFile := fakeGitProvider.originalFiles[i].Path | ||
nextFile := fakeGitProvider.originalFiles[j].Path | ||
return currFile < nextFile | ||
}) |
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.
Nice bit of logic here ✨ !
Buttt, maybe we use the similar pattern in TestCreatePullRequest
and provide the expected list of commitedFiles in each test case above.
Just so we can all test it doesn't try and delete all the files in tree.
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.
@foot isn't this the same as using the originalFiles passed to the provider? The comparison is done between that (expected) and the actual committed files
filteredTreeEntries := make(map[string]bool) | ||
for _, f := range p.originalFiles { | ||
if _, ok := filteredTreeEntries[f.Path]; !ok { | ||
filteredTreeEntries[f.Path] = true |
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.
Is this in case we provide duplicates in p.originalFiles? I'm not sure if we need it?
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.
it is because the add files to commit already adds the files in the management cluster belonging to the specified cluster, which are also in the original files , so if they are found they should be ignored (for the test's case)
@foot updated with adding path parameter as well as removing filtering unless no cluster path is found, and simply retrieving all the cluster paths from the tree listing instead of adding the manifest file and then checking not to add it again |
0f6c52c
to
5f16e2b
Compare
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.
💯 Looking great
filesList = append(filesList, gitprovider.CommitFile{ | ||
Path: &path, | ||
Content: nil, | ||
}) |
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.
Also still want to delete the getClusterManifestPath
here 👍
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.
it is replaced with getClusterDirPath
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.
Right!
There are actually 2 "places" we want to delete files from when cleaning up.
getClusterManifestPath
which is usually ./clusters/management/clusters/my-cluster.yaml, It holds the cluster definition (how many nodes it has, what version of k8s it runs), this file is loaded into the management cluster. The existing deletion behaviour only tried to delete this file.- ✨ New ✨
getClusterDirPath
, which is something like./clusters/default/my-cluster/**
, all the files that should run on the new cluster, could be kustomizations, helmrelease etc. We write is into a different location so that it doesn't get loaded into the management cluster. It should only run onmy-cluster
.
E.g. here is PR creating a cluster https://github.com/wkp-example-org/capd-demo-reloaded/pull/203/files
So we still wanna delete both 👍
Update NewFakeGitProvider calls with missing arguments
Update adding files paths to be deleted to all be from the tree listing instead of manually adding the manifest file seperately Signed-off-by: Rana Tarek Hassan <[email protected]>
fix cluster file path in test Co-authored-by: Simon <[email protected]>
Cleanup delete cluster pull request test in clusters_test Remove filtering retrieved tree files in delete cluster pull request Signed-off-by: Rana Tarek Hassan <[email protected]>
c81619e
to
d1e6721
Compare
Update delete cluster pr test with updated manifest and cluster paths Signed-off-by: Rana Tarek Hassan <[email protected]>
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.
name: "create delete pull request with namespaced cluster names including multiple files in tree", | ||
provider: NewFakeGitProvider("https://github.com/org/repo/pull/1", nil, nil, []string{ | ||
"clusters/ns-foo/foo/kustomization.yaml", | ||
"clusters/management/clusters/ns-foo/foo.yaml", |
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.
I guess everything coming back from getTrees should be deleted actually? I was thinking we should add some other files here which shouldn't be deleted.. but as ggp is handling all the filtering this is basically just the set of files that should be removed.
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.
yes these are the files that are added by fake gpp so adding other files in the list of the test will actually add them in the commit to be deleted
go.mod
Outdated
@@ -288,6 +288,7 @@ replace ( | |||
// to fix a vulnerability affecting the github.com/gorilla/handlers dependency. For more info visit | |||
// https://security.snyk.io/vuln/SNYK-GOLANG-GITHUBCOMGORILLAHANDLERS-540773. Newer versions _should_ also work. | |||
github.com/docker/distribution => github.com/docker/distribution v0.0.0-20201106182221-03aaf6ab5111 | |||
github.com/fluxcd/go-git-providers => github.com/ranatrk/go-git-providers v0.0.0-20220809210816-77b521f7fbb7 |
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.
Lets update this to a commit on main
when the ggp PR is merged!
Fixes #747
Add usage of list trees from go-git-provider to list all files of the cluster when creating a delete pull request for cluster deletion
Depends on fluxcd/go-git-providers#153