Skip to content

Commit 0a49233

Browse files
robinliebcrenshaw-devzachaller
authored
feat: add gitlab support (#205)
* feat: add gitlab support Signed-off-by: Robin Lieb <[email protected]> * fix: implement initial code review remarks Signed-off-by: Robin Lieb <[email protected]> * test: fix tests Signed-off-by: Robin Lieb <[email protected]> * fix: code review remarks Signed-off-by: Robin Lieb <[email protected]> * Apply suggestions from code review Co-authored-by: Michael Crenshaw <[email protected]> Signed-off-by: Robin Lieb <[email protected]> * feat: log gitlab rate limits only when available Signed-off-by: Robin Lieb <[email protected]> --------- Signed-off-by: Robin Lieb <[email protected]> Co-authored-by: Michael Crenshaw <[email protected]> Co-authored-by: Zach Aller <[email protected]>
1 parent c6a2c1b commit 0a49233

28 files changed

+826
-88
lines changed

api/v1alpha1/common_types.go

+31
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ type GitHub struct {
44
Domain string `json:"domain,omitempty"`
55
}
66

7+
type GitLab struct {
8+
Domain string `json:"domain,omitempty"`
9+
}
10+
711
type Fake struct {
812
Domain string `json:"domain,omitempty"`
913
}
@@ -12,3 +16,30 @@ type ObjectReference struct {
1216
// +kubebuilder:validation:Required
1317
Name string `json:"name"`
1418
}
19+
20+
type GitHubRepo struct {
21+
// +kubebuilder:validation:Required
22+
Owner string `json:"owner"`
23+
// +kubebuilder:validation:Required
24+
Name string `json:"name"`
25+
}
26+
27+
type GitLabRepo struct {
28+
// User, group or group with subgroup (e.g. group/subgroup).
29+
// +kubebuilder:validation:Required
30+
// +kubebuilder:validation:Pattern=^[a-zA-Z0-9_\-\/.]+$
31+
Namespace string `json:"namespace"`
32+
// Project slug of the repository.
33+
// +kubebuilder:validation:Required
34+
// +kubebuilder:validation:Pattern=^[a-zA-Z0-9_\-\/.]+$
35+
Name string `json:"name"`
36+
// +kubebuilder:validation:Required
37+
ProjectID int `json:"projectId"`
38+
}
39+
40+
type FakeRepo struct {
41+
// +kubebuilder:validation:Required
42+
Owner string `json:"owner"`
43+
// +kubebuilder:validation:Required
44+
Name string `json:"name"`
45+
}

api/v1alpha1/gitrepository_types.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,9 @@ import (
2525

2626
// GitRepositorySpec defines the desired state of GitRepository
2727
type GitRepositorySpec struct {
28-
// +kubebuilder:validation:Required
29-
Owner string `json:"owner"`
30-
// +kubebuilder:validation:Required
31-
Name string `json:"name"`
28+
GitHub *GitHubRepo `json:"github,omitempty"`
29+
GitLab *GitLabRepo `json:"gitlab,omitempty"`
30+
Fake *FakeRepo `json:"fake,omitempty"`
3231
// +kubebuilder:validation:Required
3332
ScmProviderRef ObjectReference `json:"scmProviderRef"`
3433
}

api/v1alpha1/scmprovider_types.go

+3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ type ScmProviderSpec struct {
3535
// GitHub required configuration for GitHub as the SCM provider
3636
GitHub *GitHub `json:"github,omitempty"`
3737

38+
// GitLab required configuration for GitLab as the SCM provider
39+
GitLab *GitLab `json:"gitlab,omitempty"`
40+
3841
// Fake required configuration for Fake as the SCM provider
3942
Fake *Fake `json:"fake,omitempty"`
4043
}

api/v1alpha1/zz_generated.deepcopy.go

+81-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/promoter.argoproj.io_gitrepositories.yaml

+37-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/promoter.argoproj.io_scmproviders.yaml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/install.yaml

+43-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/getting-started.md

+44-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Getting Started
22

33
This guide will help you get started installing and setting up the GitOps Promoter. We currently only support
4-
GitHub and GitHub Enterprise as the SCM providers. We would welcome any contributions to add support for other
4+
GitHub, GitHub Enterprise and GitLab as the SCM providers. We would welcome any contributions to add support for other
55
providers.
66

77
## Requirements
@@ -86,8 +86,9 @@ kind: GitRepository
8686
metadata:
8787
name: <git-repository-ref-name>
8888
spec:
89-
name: <repo-name>
90-
owner: <github-org-username>
89+
github:
90+
name: <repo-name>
91+
owner: <github-org-username>
9192
scmProviderRef:
9293
name: <your-scmprovider-name> # The secret that contains the GitHub App configuration
9394
```
@@ -97,6 +98,46 @@ spec:
9798
The GitRepository and ScmProvider also need to be installed to the same namespace that you plan on creating PromotionStrategy
9899
resources in, and it also needs to be in the same namespace of the secret it references.
99100
101+
## GitLab Configuration
102+
103+
To configure the GitOps Promoter with GitLab, you will need to create a GitLab Access Token under the "Developer" role with `api` and `write_repository` scopes and configure the necessary resources to allow the promoter to interact with your repository. This Access Token should be used in a secret as follows:
104+
105+
```yaml
106+
apiVersion: v1
107+
kind: Secret
108+
metadata:
109+
name: <your-secret-name>
110+
type: Opaque
111+
stringData:
112+
token: <your-access-token>
113+
```
114+
115+
We also need a GitRepository and ScmProvider, which is are custom resources that represents a git repository and a provider.
116+
Here is an example of both resources:
117+
118+
```yaml
119+
apiVersion: promoter.argoproj.io/v1alpha1
120+
kind: ScmProvider
121+
metadata:
122+
name: <your-scmprovider-name>
123+
spec:
124+
secretRef:
125+
name: <your-secret-name>
126+
gitlab: {}
127+
---
128+
apiVersion: promoter.argoproj.io/v1alpha1
129+
kind: GitRepository
130+
metadata:
131+
name: <git-repository-ref-name>
132+
spec:
133+
gitlab:
134+
name: <repo-name>
135+
namespace: <user-or-group-with-subgroups>
136+
projectId: <project-id>
137+
scmProviderRef:
138+
name: <your-scmprovider-name> # The secret that contains the GitLab Access Token
139+
```
140+
100141
## Promotion Strategy
101142

102143
The PromotionStrategy resource is the main resource that you will use to configure the promotion of your application to different environments.

0 commit comments

Comments
 (0)