diff --git a/.github/workflows/helm-publish.yml b/.github/workflows/helm-publish.yml new file mode 100644 index 0000000..734b1bd --- /dev/null +++ b/.github/workflows/helm-publish.yml @@ -0,0 +1,45 @@ +name: Publish Helm chart + +on: + push: + branches: + - main + paths: + - "charts/**" + - "config/crd/bases/**" + - "config/rbac/**" + - "Makefile" + - ".github/workflows/helm-publish.yml" + workflow_dispatch: {} + +permissions: {} + +jobs: + publish: + permissions: + contents: read + packages: write + name: Package and push to GHCR + runs-on: ubuntu-latest + steps: + - name: Clone the code + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + with: + persist-credentials: false + + - name: Setup Helm + uses: azure/setup-helm@b9e51907a09c216f16ebe8536097933489208112 # v4.3.0 + + - name: Prepare chart (copy CRD, derive RBAC template) + run: make helm-chart + + - name: Log in to GHCR + run: echo "${{ secrets.GITHUB_TOKEN }}" | helm registry login ghcr.io -u "${{ github.actor }}" --password-stdin + + - name: Package chart + run: helm package charts/runtime-conditions-crd -d dist + + - name: Push chart as an OCI artifact + run: | + chart_file="$(ls dist/runtime-conditions-crd-*.tgz)" + helm push "$chart_file" oci://ghcr.io/runtimeconditions/charts diff --git a/.gitignore b/.gitignore index 9f0f3a1..fa5acb5 100644 --- a/.gitignore +++ b/.gitignore @@ -28,3 +28,8 @@ go.work # Kubeconfig might contain secrets *.kubeconfig + +# Copied/derived into the Helm chart by `make helm-chart` - config/crd/bases +# and config/rbac are the source of truth, not these. +/charts/runtime-conditions-crd/crds/*.yaml +/charts/runtime-conditions-crd/templates/rbac.yaml diff --git a/AGENTS.md b/AGENTS.md index 2d6d4e1..792df04 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -13,6 +13,7 @@ manager binary in this repo. | `config/crd/bases/*.yaml` | Generated CRD manifest. DO NOT EDIT by hand - run `make manifests`. | | `config/samples/*.yaml` | Example CR. Edit these if the schema changes. | | `config/rbac/runtimeconditionsprofile_{admin,editor,viewer}_role.yaml` | Convenience ClusterRoles for people/service accounts using the CRD. Not tied to any controller. | +| `charts/runtime-conditions-crd/` | Helm chart wrapping the CRD (+ the same RBAC convenience roles, toggled by `rbac.create`). Published as an OCI artifact to GHCR on push to main. `crds/*.yaml` and `templates/rbac.yaml` are derived from `config/crd/bases/` and `config/rbac/` by `make helm-chart` - not committed, don't hand-edit them. Run `make helm-chart` before `helm lint`/`helm package` locally. | After editing `api/v1alpha1/*_types.go`, always run: diff --git a/Makefile b/Makefile index 2090998..c6ef91e 100644 --- a/Makefile +++ b/Makefile @@ -36,6 +36,21 @@ help: ## Display this help. manifests: controller-gen ## Generate the CustomResourceDefinition. "$(CONTROLLER_GEN)" crd paths="./..." output:crd:artifacts:config=config/crd/bases +.PHONY: helm-chart +helm-chart: ## Copy the CRD and derive the RBAC template into charts/runtime-conditions-crd. Not committed - run before helm package/lint. + @mkdir -p charts/runtime-conditions-crd/crds charts/runtime-conditions-crd/templates + @cp config/crd/bases/runtimeconditions.io_runtimeconditionsprofiles.yaml \ + charts/runtime-conditions-crd/crds/runtimeconditions.io_runtimeconditionsprofiles.yaml + @{ \ + echo '{{- if .Values.rbac.create }}'; \ + sed 's/managed-by: kustomize/managed-by: {{ .Release.Service }}/' config/rbac/runtimeconditionsprofile_admin_role.yaml; \ + echo '---'; \ + sed 's/managed-by: kustomize/managed-by: {{ .Release.Service }}/' config/rbac/runtimeconditionsprofile_editor_role.yaml; \ + echo '---'; \ + sed 's/managed-by: kustomize/managed-by: {{ .Release.Service }}/' config/rbac/runtimeconditionsprofile_viewer_role.yaml; \ + echo '{{- end }}'; \ + } > charts/runtime-conditions-crd/templates/rbac.yaml + .PHONY: generate generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations. "$(CONTROLLER_GEN)" object paths="./..." @@ -95,8 +110,8 @@ GOLANGCI_LINT = $(LOCALBIN)/golangci-lint ## Tool Versions KUSTOMIZE_VERSION ?= v5.8.1 -CONTROLLER_TOOLS_VERSION ?= v0.21.0 -GOLANGCI_LINT_VERSION ?= v2.13.2 +CONTROLLER_TOOLS_VERSION ?= v0.20.1 +GOLANGCI_LINT_VERSION ?= v2.12.2 .PHONY: kustomize kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary. $(KUSTOMIZE): $(LOCALBIN) diff --git a/charts/runtime-conditions-crd/Chart.yaml b/charts/runtime-conditions-crd/Chart.yaml new file mode 100644 index 0000000..3d250b3 --- /dev/null +++ b/charts/runtime-conditions-crd/Chart.yaml @@ -0,0 +1,9 @@ +apiVersion: v2 +name: runtime-conditions-crd +description: The RuntimeConditionsProfile CustomResourceDefinition (runtimeconditions.io/v1alpha1) +type: application +version: 0.1.0 +appVersion: v1alpha1 +home: https://runtimeconditions.io +sources: + - https://github.com/runtimeconditions/runtime-conditions-crd diff --git a/charts/runtime-conditions-crd/values.yaml b/charts/runtime-conditions-crd/values.yaml new file mode 100644 index 0000000..718e6d5 --- /dev/null +++ b/charts/runtime-conditions-crd/values.yaml @@ -0,0 +1,4 @@ +rbac: + # Install the convenience admin/editor/viewer ClusterRoles for the + # RuntimeConditionsProfile CRD. Not tied to any controller. + create: true diff --git a/config/crd/bases/runtimeconditions.io_runtimeconditionsprofiles.yaml b/config/crd/bases/runtimeconditions.io_runtimeconditionsprofiles.yaml index 0f60423..112f96b 100644 --- a/config/crd/bases/runtimeconditions.io_runtimeconditionsprofiles.yaml +++ b/config/crd/bases/runtimeconditions.io_runtimeconditionsprofiles.yaml @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - controller-gen.kubebuilder.io/version: v0.21.0 + controller-gen.kubebuilder.io/version: v0.20.1 name: runtimeconditionsprofiles.runtimeconditions.io spec: group: runtimeconditions.io