Skip to content

Commit

Permalink
Merge pull request #62 from Skarlso/add-gitlab-source
Browse files Browse the repository at this point in the history
feat: add gitlab as a source type
  • Loading branch information
Skarlso authored Feb 29, 2024
2 parents 33cb862 + d9ca8a6 commit ba8403e
Show file tree
Hide file tree
Showing 10 changed files with 435 additions and 71 deletions.
41 changes: 35 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Let's look at each of them.

There are two ways to fetch CRDs from a URL.

First, by defining a Digest. If a digest is defined together with a URL the operator will _only_ apply the content that
First, by defining a Digest. If a `digest` is defined together with a URL the operator will _only_ apply the content that
corresponds to the digest.

For example:
Expand Down Expand Up @@ -88,29 +88,58 @@ And done. What this does, we'll get to under [But what does it do?](#but-what-do
## GitHub
GitHub is largely the same, but
GitHub is mostly the same, but...
## But what does it do?
### Constant Version Reconciliation
The semver that we defined is a constraint. A semver constraint. It could be something like `>=v1`. And anything that
satisfies this constraint gets installed. It only rolls forward, to prevent accidental or intentional upstream version
satisfies this constraint gets installed. It only rolls forward to prevent accidental or intentional upstream version
rollbacks if a later version is removed.

Given the `interval` it checks every time if there is a newer version satisfying the constraint. The CRD keeps track of
the last applied version in its status. Once there is a new one, it applies it to the cluster and saves that version.

It also saves attempted versions. If a version is failed to apply, it will still record it as attempted version in its
It also saves attempted versions. If a version fails to apply, it will still record it as the attempted version in its
status.

## GitLab

GitLab has a slightly different approach to manifests and such. The reconciliation process is the same as for GitHub.

The difference is that the manifest needs to be in the release as an `Other` link asset.

Described [Release Assets](https://docs.gitlab.com/ee/user/project/releases/index.html#release-assets).

For an example release, check out [this](https://gitlab.com/Skarlso/gitlab-test-1/-/releases/v0.0.2) release.

Once this manifest exists, the yaml should look something like this:

```yaml
apiVersion: delivery.crd-bootstrap/v1alpha1
kind: Bootstrap
metadata:
name: bootstrap-sample
namespace: crd-bootstrap-system
spec:
interval: 10s
source:
gitlab:
owner: Skarlso
repo: gitlab-test-1
manifest: manifest.yaml # defined as an Other type link asset
version:
semver: v0.0.2
```

## Helm Charts

Helm Charts can have CRDs in them according to the [specification](https://helm.sh/docs/chart_best_practices/custom_resource_definitions/).

`crd-bootstrap` is able to extract those CRDs and install them as is.
`crd-bootstrap` can extract those CRDs and install them as is.

After that, the bootstrapper will keep them in sync similar to the other sources.
After that, the bootstrapper will keep them in sync, similar to the other sources.

There are two sources. With regular HTTP:

Expand Down
28 changes: 27 additions & 1 deletion api/v1alpha1/bootstrap_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,29 @@ type GitHub struct {
Manifest string `json:"manifest"`
}

// GitLab defines a GitLab type source where the CRD is coming from `release` section of a GitLab repository.
// https://docs.gitlab.com/ee/api/releases/index.html
type GitLab struct {
// BaseAPIURL is used for the GitLab API url. Defaults to api.github.com if not defined.
// +optional
BaseAPIURL string `json:"baseAPIURL,omitempty"`

// Owner defines the owner of the repository. Otherwise, known as Namespace.
// +required
Owner string `json:"owner"`

// Repo defines the name of the repository.
// +required
Repo string `json:"repo"`

// SecretRef contains a pointed to a Token in case the repository is private.
// +optional
SecretRef *v1.LocalObjectReference `json:"secretRef,omitempty"`
// Manifest defines the name of the manifest that contains the CRD definitions on the GitLab release page.
// +required
Manifest string `json:"manifest"`
}

// Helm defines a Helm type source where the CRD is coming from a helm release with a version.
type Helm struct {
// ChartReference is the location of the helm chart.
Expand Down Expand Up @@ -93,7 +116,10 @@ type URL struct {
type Source struct {
// GitHub type source.
// +optional
GitHub *GitHub `json:"gitHub,omitempty"`
GitHub *GitHub `json:"github,omitempty"`
// GitLab type source.
// +optional
GitLab *GitLab `json:"gitlab,omitempty"`
// Helm type source.
// +optional
Helm *Helm `json:"helm,omitempty"`
Expand Down
25 changes: 25 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"github.com/Skarlso/crd-bootstrap/internal/controller"
"github.com/Skarlso/crd-bootstrap/pkg/source/configmap"
"github.com/Skarlso/crd-bootstrap/pkg/source/github"
"github.com/Skarlso/crd-bootstrap/pkg/source/gitlab"
"github.com/Skarlso/crd-bootstrap/pkg/source/helm"
"github.com/Skarlso/crd-bootstrap/pkg/source/url"
)
Expand Down Expand Up @@ -90,7 +91,8 @@ func main() {
c := http.DefaultClient
urlProvider := url.NewSource(c, mgr.GetClient(), nil)
githubProvider := github.NewSource(c, mgr.GetClient(), urlProvider)
configMapProvider := configmap.NewSource(mgr.GetClient(), githubProvider)
gitlabProvider := gitlab.NewSource(c, mgr.GetClient(), githubProvider)
configMapProvider := configmap.NewSource(mgr.GetClient(), gitlabProvider)
helmProvider := helm.NewSource(c, mgr.GetClient(), configMapProvider)
if err = (&controller.BootstrapReconciler{
Client: mgr.GetClient(),
Expand Down
35 changes: 34 additions & 1 deletion config/crd/bases/delivery.crd-bootstrap_bootstraps.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ spec:
- name
- namespace
type: object
gitHub:
github:
description: GitHub type source.
properties:
baseAPIURL:
Expand Down Expand Up @@ -100,6 +100,39 @@ spec:
- owner
- repo
type: object
gitlab:
description: GitLab type source.
properties:
baseAPIURL:
description: BaseAPIURL is used for the GitLab API url. Defaults
to api.github.com if not defined.
type: string
manifest:
description: Manifest defines the name of the manifest that
contains the CRD definitions on the GitLab release page.
type: string
owner:
description: Owner defines the owner of the repository. Otherwise,
known as Namespace.
type: string
repo:
description: Repo defines the name of the repository.
type: string
secretRef:
description: SecretRef contains a pointed to a Token in case
the repository is private.
properties:
name:
description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
TODO: Add other useful fields. apiVersion, kind, uid?'
type: string
type: object
x-kubernetes-map-type: atomic
required:
- manifest
- owner
- repo
type: object
helm:
description: Helm type source.
properties:
Expand Down
14 changes: 14 additions & 0 deletions config/samples/delivery_v1alpha1_bootstrap_gitlab.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: delivery.crd-bootstrap/v1alpha1
kind: Bootstrap
metadata:
name: bootstrap-sample
namespace: crd-bootstrap-system
spec:
interval: 10s
source:
gitlab:
owner: Skarlso
repo: gitlab-test-1
manifest: manifest.yaml # defined as an Other type link asset
version:
semver: v0.0.2
9 changes: 9 additions & 0 deletions docs/release_notes/v0.6.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Release v0.6.0

| :boom: WARNING |
|------------------------------------------------------------------------------------------------------------------------------------------------------|
| This release is not backwards compatible! It broke how `GitHub` sources are defined. Instead of `gitHub` it is now `github`. Note the uppercase `h`. |

This release adds `GitLab` as a possible source.

For more information, check out pr [#62](https://github.com/Skarlso/crd-bootstrap/pull/62).
Loading

0 comments on commit ba8403e

Please sign in to comment.