Skip to content

Commit a6cc150

Browse files
committed
Initial support for HelmRelease for upgrading CRDs
Signed-off-by: Alexander Berger <alex-berger@gmx.ch>
1 parent 449a469 commit a6cc150

File tree

27 files changed

+803
-3
lines changed

27 files changed

+803
-3
lines changed

.github/workflows/e2e.yaml

+28
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
name: e2e
22

33
on:
4+
workflow_dispatch:
45
pull_request:
56
push:
67
branches:
@@ -511,6 +512,33 @@ jobs:
511512
exit 1
512513
fi
513514
kubectl -n helm-system delete -f config/testdata/post-renderer-kustomize
515+
- name: Boostrap CRDs Upgrade Tests
516+
run: |
517+
REF=${{ github.ref }}
518+
if echo "$REF" | grep 'refs/tags/'; then
519+
TYPE=tag
520+
REF=${REF#refs/tags/}
521+
else
522+
TYPE=branch
523+
if echo "$REF" | grep 'refs/pull/'; then
524+
REF=${REF#refs/pull/}
525+
else
526+
REF=${REF#refs/heads/}
527+
fi
528+
fi
529+
echo "$HEAD_REF,$CURR_REF -> $REF of type $TYPE"
530+
echo "helm install --namespace default --set $TYPE=$REF --set url=https://github.com/${{ github.repository }} this config/testdata/charts/crds/bootstrap"
531+
helm install --namespace default --set $TYPE=$REF --set url=https://github.com/${{ github.repository }} this config/testdata/charts/crds/bootstrap
532+
kubectl -n default apply -f config/testdata/crds-upgrade/init
533+
kubectl -n default wait helmreleases/crds-upgrade-test --for=condition=ready --timeout=2m
534+
- name: CRDs Upgrade Test Create
535+
run: |
536+
kubectl -n default apply -f config/testdata/crds-upgrade/create
537+
kubectl -n default wait helmreleases/crds-upgrade-test --for=condition=ready --timeout=2m
538+
- name: CRDs Upgrade Test CreateReplace
539+
run: |
540+
kubectl -n default apply -f config/testdata/crds-upgrade/create-replace
541+
kubectl -n default wait helmreleases/crds-upgrade-test --for=condition=ready --timeout=2m
514542
- name: Logs
515543
run: |
516544
kubectl -n helm-system logs deploy/source-controller

api/v2beta1/helmrelease_types.go

+31
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,19 @@ func (in InstallRemediation) RetriesExhausted(hr HelmRelease) bool {
431431
return in.Retries >= 0 && in.GetFailureCount(hr) > int64(in.Retries)
432432
}
433433

434+
// CRDsUpgradePolicy defines the upgrade approach to use for CRDs when upgrading
435+
// a HelmRelease.
436+
type CRDsChangePolicy string
437+
438+
const (
439+
// Create CRDs which do not already exist, do not replace already existing CRDs
440+
// and keep (do not delete) CRDs which no longer exist in the current release.
441+
Create CRDsChangePolicy = "Create"
442+
// Create CRDs which do not already exist, Replace already existing CRDs
443+
// and keep (do not delete) CRDs which no longer exist in the current release.
444+
CreateReplace CRDsChangePolicy = "CreateReplace"
445+
)
446+
434447
// Upgrade holds the configuration for Helm upgrade actions for this
435448
// HelmRelease.
436449
type Upgrade struct {
@@ -473,6 +486,24 @@ type Upgrade struct {
473486
// upgrade action when it fails.
474487
// +optional
475488
CleanupOnFail bool `json:"cleanupOnFail,omitempty"`
489+
490+
// UpgradeCRDs upgrade CRDs from the Helm Chart's crds directory according
491+
// to the CRD upgrade policy provided here. Valid values are `Create` or
492+
// `CreateReplace`. If omitted (the default) CRDs
493+
// are not upgraded.
494+
//
495+
// Create: new CRDs are created, existing CRDs are neither updated nor deleted.
496+
//
497+
// CreateReplace: new CRDs are created, existing CRDs are updated (replaced)
498+
// but not deleted.
499+
//
500+
// By default, CRDs are not applied during Helm upgrade action. With this
501+
// option users can opt-in to CRD upgrade, which is not (yet) natively supported by Helm.
502+
// https://helm.sh/docs/chart_best_practices/custom_resource_definitions.
503+
//
504+
// +kubebuilder:validation:Enum=Create;CreateReplace
505+
// +optional
506+
UpgradeCRDs CRDsChangePolicy `json:"upgradeCRDs,omitempty"`
476507
}
477508

478509
// GetTimeout returns the configured timeout for the Helm upgrade action, or the

config/crd/bases/helm.toolkit.fluxcd.io_helmreleases.yaml

+14
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,20 @@ spec:
515515
operation (like Jobs for hooks) during the performance of a
516516
Helm upgrade action. Defaults to 'HelmReleaseSpec.Timeout'.
517517
type: string
518+
upgradeCRDs:
519+
description: "UpgradeCRDs upgrade CRDs from the Helm Chart's crds
520+
directory according to the CRD upgrade policy provided here.
521+
Valid values are `Create` or `CreateReplace`. If omitted (the
522+
default) CRDs are not upgraded. \n Create: new CRDs are created,
523+
existing CRDs are neither updated nor deleted. \n CreateReplace:
524+
new CRDs are created, existing CRDs are updated (replaced) but
525+
not deleted. \n By default, CRDs are not applied during Helm
526+
upgrade action. With this option users can opt-in to CRD upgrade,
527+
which is not (yet) natively supported by Helm. https://helm.sh/docs/chart_best_practices/custom_resource_definitions."
528+
enum:
529+
- Create
530+
- CreateReplace
531+
type: string
518532
type: object
519533
values:
520534
description: Values holds the values for this Helm release.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Patterns to ignore when building packages.
2+
# This supports shell glob matching, relative path matching, and
3+
# negation (prefixed with !). Only one pattern per line.
4+
.DS_Store
5+
# Common VCS dirs
6+
.git/
7+
.gitignore
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
apiVersion: v2
2+
name: crd-upgrade-bootstrap
3+
description: Helper Chart to bootstrap e2e test GitRepository
4+
5+
# A chart can be either an 'application' or a 'library' chart.
6+
#
7+
# Application charts are a collection of templates that can be packaged into versioned archives
8+
# to be deployed.
9+
#
10+
# Library charts provide useful utilities or functions for the chart developer. They're included as
11+
# a dependency of application charts to inject those utilities and functions into the rendering
12+
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
13+
type: application
14+
15+
# This is the chart version. This version number should be incremented each time you make changes
16+
# to the chart and its templates, including the app version.
17+
# Versions are expected to follow Semantic Versioning (https://semver.org/)
18+
version: 1.0.0
19+
20+
# This is the version number of the application being deployed. This version number should be
21+
# incremented each time you make changes to the application. Versions are not expected to
22+
# follow Semantic Versioning. They should reflect the version the application is using.
23+
appVersion: 1.0.0
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
apiVersion: source.toolkit.fluxcd.io/v1beta1
3+
kind: GitRepository
4+
metadata:
5+
name: this
6+
namespace: default
7+
spec:
8+
interval: 1m
9+
url: "{{ .Values.url }}"
10+
ref:
11+
{{- if .Values.branch }}
12+
branch: "{{ .Values.branch }}"
13+
{{- end}}
14+
{{- if .Values.branch }}
15+
tag: "{{ .Values.tag }}"
16+
{{- end}}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
url: "https://github.com/fluxcd/helm-controller"
2+
branch: null
3+
tag: null
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Patterns to ignore when building packages.
2+
# This supports shell glob matching, relative path matching, and
3+
# negation (prefixed with !). Only one pattern per line.
4+
.DS_Store
5+
# Common VCS dirs
6+
.git/
7+
.gitignore
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
apiVersion: v2
2+
name: crd-upgrade
3+
description: CRDs Upgrade Test Chart v1
4+
5+
# A chart can be either an 'application' or a 'library' chart.
6+
#
7+
# Application charts are a collection of templates that can be packaged into versioned archives
8+
# to be deployed.
9+
#
10+
# Library charts provide useful utilities or functions for the chart developer. They're included as
11+
# a dependency of application charts to inject those utilities and functions into the rendering
12+
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
13+
type: application
14+
15+
# This is the chart version. This version number should be incremented each time you make changes
16+
# to the chart and its templates, including the app version.
17+
# Versions are expected to follow Semantic Versioning (https://semver.org/)
18+
version: 1.0.0
19+
20+
# This is the version number of the application being deployed. This version number should be
21+
# incremented each time you make changes to the application. Versions are not expected to
22+
# follow Semantic Versioning. They should reflect the version the application is using.
23+
appVersion: 1.0.0
+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
2+
---
3+
apiVersion: apiextensions.k8s.io/v1
4+
kind: CustomResourceDefinition
5+
metadata:
6+
name: crdupgradetestas.crd-upgrades.helmreleases.helm.toolkit.fluxcd.io
7+
spec:
8+
group: crd-upgrades.helmreleases.helm.toolkit.fluxcd.io
9+
names:
10+
kind: CrdUpgradeTesta
11+
listKind: CrdUpgradeTestaList
12+
plural: crdupgradetestas
13+
singular: crdupgradetesta
14+
scope: Namespaced
15+
versions:
16+
- name: v2beta1
17+
schema:
18+
openAPIV3Schema:
19+
description: Test
20+
properties:
21+
apiVersion:
22+
type: string
23+
kind:
24+
type: string
25+
metadata:
26+
type: object
27+
spec:
28+
properties: {}
29+
type: object
30+
status:
31+
properties: {}
32+
type: object
33+
type: object
34+
served: true
35+
storage: true
36+
subresources:
37+
status: {}
38+
+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
2+
---
3+
apiVersion: apiextensions.k8s.io/v1
4+
kind: CustomResourceDefinition
5+
metadata:
6+
name: crdupgradetestbs.crd-upgrades.helmreleases.helm.toolkit.fluxcd.io
7+
spec:
8+
group: crd-upgrades.helmreleases.helm.toolkit.fluxcd.io
9+
names:
10+
kind: CrdUpgradeTestb
11+
listKind: CrdUpgradeTestbList
12+
plural: crdupgradetestbs
13+
singular: crdupgradetestb
14+
scope: Namespaced
15+
versions:
16+
- name: v2beta1
17+
schema:
18+
openAPIV3Schema:
19+
description: Test
20+
properties:
21+
apiVersion:
22+
type: string
23+
kind:
24+
type: string
25+
metadata:
26+
type: object
27+
spec:
28+
properties: {}
29+
type: object
30+
status:
31+
properties: {}
32+
type: object
33+
type: object
34+
served: true
35+
storage: true
36+
subresources:
37+
status: {}
38+
+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
2+
---
3+
apiVersion: apiextensions.k8s.io/v1
4+
kind: CustomResourceDefinition
5+
metadata:
6+
name: crdupgradetestds.crd-upgrades.helmreleases.helm.toolkit.fluxcd.io
7+
spec:
8+
group: crd-upgrades.helmreleases.helm.toolkit.fluxcd.io
9+
names:
10+
kind: CrdUpgradeTestd
11+
listKind: CrdUpgradeTestdList
12+
plural: crdupgradetestds
13+
singular: crdupgradetestd
14+
scope: Namespaced
15+
versions:
16+
- name: v2beta1
17+
schema:
18+
openAPIV3Schema:
19+
description: Test
20+
properties:
21+
apiVersion:
22+
type: string
23+
kind:
24+
type: string
25+
metadata:
26+
type: object
27+
spec:
28+
properties: {}
29+
type: object
30+
status:
31+
properties: {}
32+
type: object
33+
type: object
34+
served: true
35+
storage: true
36+
subresources:
37+
status: {}
38+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
kind: CrdUpgradeTesta
3+
apiVersion: crd-upgrades.helmreleases.helm.toolkit.fluxcd.io/v2beta1
4+
metadata:
5+
name: a
6+
spec: {}

config/testdata/charts/crds/v1/values.yaml

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Patterns to ignore when building packages.
2+
# This supports shell glob matching, relative path matching, and
3+
# negation (prefixed with !). Only one pattern per line.
4+
.DS_Store
5+
# Common VCS dirs
6+
.git/
7+
.gitignore
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
apiVersion: v2
2+
name: crd-upgrade
3+
description: CRDs Upgrade Test Chart v1
4+
5+
# A chart can be either an 'application' or a 'library' chart.
6+
#
7+
# Application charts are a collection of templates that can be packaged into versioned archives
8+
# to be deployed.
9+
#
10+
# Library charts provide useful utilities or functions for the chart developer. They're included as
11+
# a dependency of application charts to inject those utilities and functions into the rendering
12+
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
13+
type: application
14+
15+
# This is the chart version. This version number should be incremented each time you make changes
16+
# to the chart and its templates, including the app version.
17+
# Versions are expected to follow Semantic Versioning (https://semver.org/)
18+
version: 1.0.0
19+
20+
# This is the version number of the application being deployed. This version number should be
21+
# incremented each time you make changes to the application. Versions are not expected to
22+
# follow Semantic Versioning. They should reflect the version the application is using.
23+
appVersion: 1.0.0
+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
2+
---
3+
apiVersion: apiextensions.k8s.io/v1
4+
kind: CustomResourceDefinition
5+
metadata:
6+
name: crdupgradetestas.crd-upgrades.helmreleases.helm.toolkit.fluxcd.io
7+
spec:
8+
group: crd-upgrades.helmreleases.helm.toolkit.fluxcd.io
9+
names:
10+
kind: CrdUpgradeTesta
11+
listKind: CrdUpgradeTestaList
12+
plural: crdupgradetestas
13+
singular: crdupgradetesta
14+
scope: Namespaced
15+
versions:
16+
- name: v2beta1
17+
schema:
18+
openAPIV3Schema:
19+
description: Test
20+
properties:
21+
apiVersion:
22+
type: string
23+
kind:
24+
type: string
25+
metadata:
26+
type: object
27+
spec:
28+
properties: {}
29+
type: object
30+
status:
31+
properties: {}
32+
type: object
33+
type: object
34+
served: true
35+
storage: true
36+
subresources:
37+
status: {}
38+

0 commit comments

Comments
 (0)