Skip to content

Commit

Permalink
Merge pull request #38 from Skarlso/crds-from-helm-charts
Browse files Browse the repository at this point in the history
feat: add helm as a crd source
  • Loading branch information
Skarlso authored Jan 25, 2024
2 parents 03a9ec9 + 1e875b3 commit 741342b
Show file tree
Hide file tree
Showing 15 changed files with 787 additions and 21 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/check-manifest-generation-diff.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Check for diff after manifest and generated targets

on:
pull_request: {}

jobs:
diff-check-manifests:
name: Check for diff
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Make manifests && generate
run: |
make manifests && make generate
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version-file: '${{ github.workspace }}/go.mod'
- name: Restore Go cache
uses: actions/cache@v3
with:
path: /home/runner/work/_temp/_github_home/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: go mod tidy
run: |
go mod tidy
- name: Check for diff
run: |
git diff --exit-code --shortstat
41 changes: 41 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: test and lint

on:
pull_request:
paths-ignore:
- 'CODE_OF_CONDUCT.md'
- 'README.md'
- 'Contributing.md'
workflow_call:

push:
branches:
- main

permissions:
contents: read # for actions/checkout to fetch code

jobs:
run-test-suite:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version-file: '${{ github.workspace }}/go.mod'
- uses: acifani/setup-tinygo@v2
with:
tinygo-version: '0.29.0'
- name: Restore Go cache
uses: actions/cache@v3
with:
path: /home/runner/work/_temp/_github_home/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Run lint
run: make lint
- name: Run tests
run: make test
1 change: 1 addition & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ linters:
- scopelint
- structcheck
- varcheck
- gci

linters-settings:
gci:
Expand Down
11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ vet: ## Run go vet against code.
test: manifests generate fmt vet envtest ## Run tests.
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./... -coverprofile cover.out

.PHONY: lint
lint: golangci-lint ## Run golangci-lint.
$(GOLANGCI_LINT) run

##@ Build

.PHONY: build
Expand Down Expand Up @@ -139,10 +143,12 @@ $(LOCALBIN):
KUSTOMIZE ?= $(LOCALBIN)/kustomize
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
ENVTEST ?= $(LOCALBIN)/setup-envtest
GOLANGCI_LINT ?= $(LOCALBIN)/golangci-lint

## Tool Versions
KUSTOMIZE_VERSION ?= v5.0.0
CONTROLLER_TOOLS_VERSION ?= v0.11.3
GOLANGCI_LINT_VERSION ?= v1.55.2

KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
.PHONY: kustomize
Expand All @@ -164,3 +170,8 @@ $(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

.PHONY: golangci-lint
golangci-lint: $(GOLANGCI_LINT)
$(GOLANGCI_LINT): $(LOCALBIN)
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s $(GOLANGCI_LINT_VERSION)
19 changes: 19 additions & 0 deletions api/v1alpha1/bootstrap_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,22 @@ type GitHub struct {
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.
// The scheme must be either HTTP or OCI.
// [chart URL | repo/chartname]
// +required
ChartReference string `json:"chartReference"`
// ChartName defines the name of the chart to fetch from the reference URL.
// +required
ChartName string `json:"chartName"`
// Insecure defines
// SecretRef contains a pointer to a secret that contains any needed credentials to access the helm repository.
// +optional
SecretRef *v1.LocalObjectReference `json:"secretRef,omitempty"`
}

// ConfigMap defines a reference to a configmap which hold the CRD information. Version is taken from a version field.
type ConfigMap struct {
// Name of the config map.
Expand All @@ -78,6 +94,9 @@ type Source struct {
// GitHub type source.
// +optional
GitHub *GitHub `json:"gitHub,omitempty"`
// Helm type source.
// +optional
Helm *Helm `json:"helm,omitempty"`
// ConfigMap type source.
// +optional
ConfigMap *ConfigMap `json:"configMap,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.

12 changes: 7 additions & 5 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package main

import (
"flag"
"net/http"
"os"

v1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
Expand All @@ -31,12 +32,11 @@ import (
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
"sigs.k8s.io/controller-runtime/pkg/webhook"

//+kubebuilder:scaffold:imports

deliveryv1alpha1 "github.com/Skarlso/crd-bootstrap/api/v1alpha1"
"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/helm"
"github.com/Skarlso/crd-bootstrap/pkg/source/url"
)

Expand Down Expand Up @@ -87,13 +87,15 @@ func main() {
os.Exit(1)
}

urlProvider := url.NewSource(mgr.GetClient(), nil)
githubProvider := github.NewSource(mgr.GetClient(), urlProvider)
c := http.DefaultClient
urlProvider := url.NewSource(c, mgr.GetClient(), nil)
githubProvider := github.NewSource(c, mgr.GetClient(), urlProvider)
configMapProvider := configmap.NewSource(mgr.GetClient(), githubProvider)
helmProvider := helm.NewSource(c, mgr.GetClient(), configMapProvider)
if err = (&controller.BootstrapReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
SourceProvider: configMapProvider,
SourceProvider: helmProvider,
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "Bootstrap")
os.Exit(1)
Expand Down
26 changes: 26 additions & 0 deletions config/crd/bases/delivery.crd-bootstrap_bootstraps.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,32 @@ spec:
- owner
- repo
type: object
helm:
description: Helm type source.
properties:
chartName:
description: ChartName defines the name of the chart to fetch
from the reference URL.
type: string
chartReference:
description: ChartReference is the location of the helm chart.
The scheme must be either HTTP or OCI. [chart URL | repo/chartname]
type: string
secretRef:
description: Insecure defines SecretRef contains a pointer
to a secret that contains any needed credentials to access
the helm repository.
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:
- chartName
- chartReference
type: object
url:
description: URL type source.
properties:
Expand Down
13 changes: 13 additions & 0 deletions config/samples/delivery_v1alpha1_bootstrap_helm.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: delivery.crd-bootstrap/v1alpha1
kind: Bootstrap
metadata:
name: bootstrap-sample-helm
namespace: crd-bootstrap-system
spec:
interval: 10s
source:
helm:
chartReference: oci://ghcr.io/skarlso/helm/crd-bootstrap
chartName: crd-bootstrap
version:
semver: v0.4.2
13 changes: 13 additions & 0 deletions config/samples/delivery_v1alpha1_bootstrap_helm_url.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: delivery.crd-bootstrap/v1alpha1
kind: Bootstrap
metadata:
name: bootstrap-sample-helm
namespace: crd-bootstrap-system
spec:
interval: 10s
source:
helm:
chartReference: https://ibm.github.io/helm101/
chartName: guestbook
version:
semver: 0.2.1
Loading

0 comments on commit 741342b

Please sign in to comment.