-
Notifications
You must be signed in to change notification settings - Fork 226
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
Rollouts gitlab support #3853
Rollouts gitlab support #3853
Conversation
@ChristopherFry @natasha41575 Would be great if you both of you can take a look at it. |
@ChristopherFry @natasha41575 The tests are not ideal in current form But they are helpful if one is hacking on |
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.
Minor comments, but I have a bigger question.
Porch also has some code to discover packages from Github. Is there any overlap here? I'm wondering if we will eventually want to combine them into a git-package-discovery library.
type GitLabSource struct { | ||
// SecretReference is the reference to a kubernetes secret | ||
// that contains GitLab access token | ||
SecretRef SecretReference `json:"secretRef,omitempty"` |
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.
The GithubSource
has the SecretRef
in the Selector
. Is there a reason that you decided to do it differently for GitLabSource
?
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.
Good question. The reasoning for separating SecretRef
from Selector
is that SecretRef
is relevant to How to connect to the Package Source
and Selector
is relevant to How to select packages from a source
. So mixing the two felt odd so decided to do it the right way for GitLab
.
I intend to do the same for GitHub
as well but in a separate PR.
SourceType: gitopsv1alpha1.GitHub, | ||
GitHub: gitopsv1alpha1.GitHubSource{ | ||
Selector: gitopsv1alpha1.GitHubSelector{ | ||
Org: "droot", |
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.
Should we create these test packages under https://github.com/GoogleContainerTools/kpt/tree/main/package-examples
(or some other place under GoogleContainerTools)? I think using your username is ok short-term, but long term it would probably be best to have it somewhere more official and not tied to someone's individual account
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.
So two things:
- Absolutely agree on keeping it in an official place. Mine is just a stop gap because of lack of a place.
- We can't use
...kpt/tree/main/package-examples
for this because it complicates adding/deleting tests. One has to make changes in the test packages and commit it, then update the tests because tests will use whatever is available onmain
.kpt-samples
could be another place but that is used for reference packages and using it for tests can make it really noisy.
But need to find a solution.
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.
Perhaps a kpt-test
repo?
if isSelectorField(selector.Directory) { | ||
tree, _, err := gitHubClient.Git.GetTree(ctx, selector.Org, repoName, selector.Revision, true) | ||
tree, _, err := gitHubClient.Git.GetTree(ctx, selector.Org, *repo.Name, repo.GetDefaultBranch(), 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.
Why are we using repo.GetDefaultBranch
here instead of branch
?
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.
Good catch, fixed it.
// initialize a gitlab client | ||
secretName := gitlabSource.SecretRef.Name | ||
if secretName == "" { | ||
return nil, fmt.Errorf("GitLab secret reference is missing from the config") |
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.
super nit: in this error message, we are camel-casing GitLab
, but in later error messages, we leave it all lowercase (gitlab
). I think we should pick one for consistency
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.
Good catch, using lower-case
everywhere for now.
} | ||
|
||
accessToken := string(repositorySecret.Data["token"]) | ||
// TODO(droot): BaseURL should also be configurable through the API |
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.
question: what other baseURLs are possible with gitlab?
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.
Two use-cases that I have in my mind:
- Enterprises can self-host gitlab instances and in that case, capability to point to self-hosted gitlab will be needed
- Eventually, we will use
gitlab
docker instance for our e2e tests where being able to point to our instance will be needed.
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.
Thanks for the review @natasha41575
type GitLabSource struct { | ||
// SecretReference is the reference to a kubernetes secret | ||
// that contains GitLab access token | ||
SecretRef SecretReference `json:"secretRef,omitempty"` |
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.
Good question. The reasoning for separating SecretRef
from Selector
is that SecretRef
is relevant to How to connect to the Package Source
and Selector
is relevant to How to select packages from a source
. So mixing the two felt odd so decided to do it the right way for GitLab
.
I intend to do the same for GitHub
as well but in a separate PR.
SourceType: gitopsv1alpha1.GitHub, | ||
GitHub: gitopsv1alpha1.GitHubSource{ | ||
Selector: gitopsv1alpha1.GitHubSelector{ | ||
Org: "droot", |
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.
So two things:
- Absolutely agree on keeping it in an official place. Mine is just a stop gap because of lack of a place.
- We can't use
...kpt/tree/main/package-examples
for this because it complicates adding/deleting tests. One has to make changes in the test packages and commit it, then update the tests because tests will use whatever is available onmain
.kpt-samples
could be another place but that is used for reference packages and using it for tests can make it really noisy.
But need to find a solution.
10799ca
to
d173d1c
Compare
Eventually, yes once we understand the usage better. |
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.
Looks good!
Not needed now, but In a future change I would definitely suggest splitting the GitHub and GitLab logic into separate files. The Package Discovery file is getting long.
@@ -174,3 +174,14 @@ $(CONTROLLER_GEN): $(LOCALBIN) | |||
envtest: $(ENVTEST) ## Download envtest-setup locally if necessary. | |||
$(ENVTEST): $(LOCALBIN) | |||
test -s $(LOCALBIN)/setup-envtest || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest | |||
|
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: there's an extra newline here
@@ -453,8 +458,9 @@ func (r *RolloutReconciler) computeTargets(ctx context.Context, | |||
|
|||
func pkgNeedsUpdate(rollout *gitopsv1alpha1.Rollout, rrs gitopsv1alpha1.RemoteRootSync, pkg *packagediscovery.DiscoveredPackage) (*gitopsv1alpha1.RemoteRootSync, bool) { | |||
// TODO: We need to check other things here besides git.Revision and metadata | |||
metadata := getSpecMetadata(rollout) |
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 would consider creating a pull request with just this change since this change is technically unrelated to the rest of the changes in the pull request.
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.
Thanks for pointing it out. This will go away once @natasha41575 PR (that has the fix) is merged.
@ChristopherFry Went ahead and did it in the last commit. At some point, I want to introduce an interface for package selection and this sets up well for that change in the future :) |
@@ -463,6 +469,25 @@ func pkgNeedsUpdate(rollout *gitopsv1alpha1.Rollout, rrs gitopsv1alpha1.RemoteRo | |||
return nil, false | |||
} | |||
|
|||
func getSpecMetadata(rollout *gitopsv1alpha1.Rollout) *gitopsv1alpha1.Metadata { |
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 think this PR needs a rebase on main. My PR with this fix merged, but I believe I moved this function to the end of the file in my PR and we should try to avoid something funny happening when this PR is merged.
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 removed my changes to facilitate clean merge. I had to make small change to make the code aware of syncTemplate
being nil.
2c932a9
to
cf781e8
Compare
This PR adds support for
GitLab
as package source.Note: Testing individual components is turning out to be tricky. I have added tests for package discovery for
gitlab
andgithub
that avoids running controller but the test setup is not ideal. I would like to usegitlab
community edition for spinning up git repository with some test data, but I want to tackle that as separate task.