Skip to content

Commit a291ed7

Browse files
ChrisJBurnsjhrozek
andauthored
enable CRD upgrades via Helm with feature flags (#2809)
* enables crd upgrades via Helm with feature flags - allow for feature flagging crd installs - moves from crds/ to templates/ to allow for upgraded - added wrapper go tool for feature flag and helm keep conditionals Signed-off-by: Chris Burns <[email protected]> * bumps chart Signed-off-by: Chris Burns <[email protected]> * Update cmd/thv-operator/Taskfile.yml Co-authored-by: Jakub Hrozek <[email protected]> * adds docs and fixes error paths in wrapper tool - we want to safeguard against larger files - we want error if there is a CRD that isn't in the feature flag map - adds some docs to the main readme about why we put crds in template Signed-off-by: Chris Burns <[email protected]> * updates crds Signed-off-by: Chris Burns <[email protected]> * updates crds Signed-off-by: Chris Burns <[email protected]> * bumps chart Signed-off-by: Chris Burns <[email protected]> --------- Signed-off-by: Chris Burns <[email protected]> Co-authored-by: Jakub Hrozek <[email protected]>
1 parent c914d42 commit a291ed7

34 files changed

+4161
-13
lines changed

.github/workflows/operator-ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ jobs:
9595
- name: Check for changes
9696
id: git-check
9797
run: |
98-
git diff --exit-code deploy/charts/operator-crds/crds || echo "crd-changes=true" >> $GITHUB_OUTPUT
98+
git diff --exit-code deploy/charts/operator-crds/templates || echo "crd-changes=true" >> $GITHUB_OUTPUT
9999
git diff --exit-code deploy/charts/operator/templates || echo "operator-changes=true" >> $GITHUB_OUTPUT
100100
101101
- name: Fail if CRDs are not up to date

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,5 @@ cmd/thv-operator/.task/checksum/crdref-gen
4141

4242
# Test coverage
4343
coverage*
44+
45+
crd-helm-wrapper

cmd/thv-operator/Taskfile.yml

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,15 +182,28 @@ tasks:
182182

183183
operator-manifests:
184184
desc: Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects
185+
vars:
186+
PROJECT_ROOT:
187+
sh: git rev-parse --show-toplevel || pwd
188+
CONTROLLER_GEN_PATHS:
189+
sh: |
190+
if [[ "$PWD" == *"/cmd/thv-operator"* ]]; then
191+
echo "./..."
192+
else
193+
echo "./cmd/thv-operator/..."
194+
fi
185195
cmds:
186-
- cmd: mkdir -p bin
196+
- cmd: mkdir -p {{.PROJECT_ROOT}}/cmd/thv-operator/bin
187197
platforms: [linux, darwin]
188-
- cmd: cmd.exe /c mkdir bin
198+
- cmd: cmd.exe /c mkdir {{.PROJECT_ROOT}}/cmd/thv-operator/bin
189199
platforms: [windows]
190200
ignore_error: true # Windows has no mkdir -p, so just ignore error if it exists
191201
- go install sigs.k8s.io/controller-tools/cmd/[email protected]
192-
- $(go env GOPATH)/bin/controller-gen crd webhook paths="./cmd/thv-operator/..." output:crd:artifacts:config=deploy/charts/operator-crds/crds
193-
- $(go env GOPATH)/bin/controller-gen rbac:roleName=toolhive-operator-manager-role paths="./cmd/thv-operator/..." output:rbac:artifacts:config=deploy/charts/operator/templates/clusterrole
202+
- $(go env GOPATH)/bin/controller-gen rbac:roleName=toolhive-operator-manager-role paths="{{.CONTROLLER_GEN_PATHS}}" output:rbac:artifacts:config={{.PROJECT_ROOT}}/deploy/charts/operator/templates/clusterrole
203+
- $(go env GOPATH)/bin/controller-gen crd webhook paths="{{.CONTROLLER_GEN_PATHS}}" output:crd:artifacts:config={{.PROJECT_ROOT}}/deploy/charts/operator-crds/files/crds
204+
# Wrap CRDs with Helm templates for conditional installation
205+
- go run {{.PROJECT_ROOT}}/deploy/charts/operator-crds/crd-helm-wrapper/main.go -source {{.PROJECT_ROOT}}/deploy/charts/operator-crds/files/crds -target {{.PROJECT_ROOT}}/deploy/charts/operator-crds/templates
206+
# - "{{.PROJECT_ROOT}}/deploy/charts/operator-crds/scripts/wrap-crds.sh"
194207

195208
operator-test:
196209
desc: Run tests for the operator

cmd/thv-operator/test-integration/mcp-external-auth/suite_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ var _ = BeforeSuite(func() {
5757

5858
By("bootstrapping test environment")
5959
testEnv = &envtest.Environment{
60-
CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "..", "deploy", "charts", "operator-crds", "crds")},
60+
CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "..", "deploy", "charts", "operator-crds", "files", "crds")},
6161
ErrorIfCRDPathMissing: true,
6262
}
6363

cmd/thv-operator/test-integration/mcp-group/suite_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ var _ = BeforeSuite(func() {
5858

5959
By("bootstrapping test environment")
6060
testEnv = &envtest.Environment{
61-
CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "..", "deploy", "charts", "operator-crds", "crds")},
61+
CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "..", "deploy", "charts", "operator-crds", "files", "crds")},
6262
ErrorIfCRDPathMissing: true,
6363
}
6464

cmd/thv-operator/test-integration/mcp-registry/suite_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ var _ = BeforeSuite(func() {
6868
testEnv = &envtest.Environment{
6969
UseExistingCluster: &useExistingCluster,
7070
CRDDirectoryPaths: []string{
71-
filepath.Join("..", "..", "..", "..", "deploy", "charts", "operator-crds", "crds"),
71+
filepath.Join("..", "..", "..", "..", "deploy", "charts", "operator-crds", "files", "crds"),
7272
},
7373
ErrorIfCRDPathMissing: true,
7474
BinaryAssetsDirectory: kubebuilderAssets,

cmd/thv-operator/test-integration/mcp-server/suite_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ var _ = BeforeSuite(func() {
6161

6262
By("bootstrapping test environment")
6363
testEnv = &envtest.Environment{
64-
CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "..", "deploy", "charts", "operator-crds", "crds")},
64+
CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "..", "deploy", "charts", "operator-crds", "files", "crds")},
6565
ErrorIfCRDPathMissing: true,
6666
}
6767

cmd/thv-operator/test-integration/virtualmcp/suite_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ var _ = BeforeSuite(func() {
6161

6262
By("bootstrapping test environment")
6363
testEnv = &envtest.Environment{
64-
CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "..", "deploy", "charts", "operator-crds", "crds")},
64+
CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "..", "deploy", "charts", "operator-crds", "files", "crds")},
6565
ErrorIfCRDPathMissing: true,
6666
}
6767

deploy/charts/operator-crds/.helmignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,9 @@
2121
.idea/
2222
*.tmproj
2323
.vscode/
24+
# Source CRD files and wrapper tool (only wrapped templates are needed)
25+
files/
26+
crd-helm-wrapper/
27+
# Documentation
28+
CLAUDE.md
29+
CONTRIBUTING.md

deploy/charts/operator-crds/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ apiVersion: v2
22
name: toolhive-operator-crds
33
description: A Helm chart for installing the ToolHive Operator CRDs into Kubernetes.
44
type: application
5-
version: 0.0.79
5+
version: 0.0.80
66
appVersion: "0.0.1"

0 commit comments

Comments
 (0)