Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial support for CRDs (upgrade) policies #250

Merged
merged 4 commits into from
Apr 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
name: e2e

on:
workflow_dispatch:
pull_request:
push:
branches:
- main

- "feature/**"
jobs:
kind:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -511,6 +512,36 @@ jobs:
exit 1
fi
kubectl -n helm-system delete -f config/testdata/post-renderer-kustomize
- name: Boostrap CRDs Upgrade Tests
if: ${{ startsWith(github.ref, 'refs/tags/') || startsWith(github.ref, 'refs/heads/') }}
run: |
REF=${{ github.ref }}
if echo "$REF" | grep 'refs/tags/'; then
TYPE=tag
REF=${REF#refs/tags/}
else
TYPE=branch
if echo "$REF" | grep 'refs/pull/'; then
REF=${REF#refs/pull/}
else
REF=${REF#refs/heads/}
fi
fi
echo "$HEAD_REF,$CURR_REF -> $REF of type $TYPE"
echo "helm install --namespace default --set $TYPE=$REF --set url=https://github.com/${{ github.repository }} this config/testdata/charts/crds/bootstrap"
helm install --namespace default --set $TYPE=$REF --set url=https://github.com/${{ github.repository }} this config/testdata/charts/crds/bootstrap
kubectl -n default apply -f config/testdata/crds-upgrade/init
kubectl -n default wait helmreleases/crds-upgrade-test --for=condition=ready --timeout=2m
- name: CRDs Upgrade Test Create
if: ${{ startsWith(github.ref, 'refs/tags/') || startsWith(github.ref, 'refs/heads/') }}
run: |
kubectl -n default apply -f config/testdata/crds-upgrade/create
kubectl -n default wait helmreleases/crds-upgrade-test --for=condition=ready --timeout=2m
- name: CRDs Upgrade Test CreateReplace
if: ${{ startsWith(github.ref, 'refs/tags/') || startsWith(github.ref, 'refs/heads/') }}
run: |
kubectl -n default apply -f config/testdata/crds-upgrade/create-replace
kubectl -n default wait helmreleases/crds-upgrade-test --for=condition=ready --timeout=2m
- name: Logs
run: |
kubectl -n helm-system logs deploy/source-controller
Expand Down
60 changes: 60 additions & 0 deletions api/v2beta1/helmrelease_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,9 +335,34 @@ type Install struct {

// SkipCRDs tells the Helm install action to not install any CRDs. By default,
// CRDs are installed if not already present.
//
// Deprecated use CRD policy (`crds`) attribute with value `Skip` instead.
//
// +deprecated
// +optional
SkipCRDs bool `json:"skipCRDs,omitempty"`

// CRDs upgrade CRDs from the Helm Chart's crds directory according
// to the CRD upgrade policy provided here. Valid values are `Skip`,
// `Create` or `CreateReplace`. Default is `Create` and if omitted
// CRDs are installed but not updated.
//
// Skip: do neither install nor replace (update) any CRDs.
//
// Create: new CRDs are created, existing CRDs are neither updated nor deleted.
//
// CreateReplace: new CRDs are created, existing CRDs are updated (replaced)
// but not deleted.
//
// By default, CRDs are applied (installed) during Helm install action.
// With this option users can opt-in to CRD replace existing CRDs on Helm
// install actions, which is not (yet) natively supported by Helm.
// https://helm.sh/docs/chart_best_practices/custom_resource_definitions.
//
// +kubebuilder:validation:Enum=Skip;Create;CreateReplace
// +optional
CRDs CRDsPolicy `json:"crds,omitempty"`

// CreateNamespace tells the Helm install action to create the
// HelmReleaseSpec.TargetNamespace if it does not exist yet.
// On uninstall, the namespace will not be garbage collected.
Expand Down Expand Up @@ -431,6 +456,21 @@ func (in InstallRemediation) RetriesExhausted(hr HelmRelease) bool {
return in.Retries >= 0 && in.GetFailureCount(hr) > int64(in.Retries)
}

// CRDsPolicy defines the install/upgrade approach to use for CRDs when
// installing or upgrading a HelmRelease.
type CRDsPolicy string

const (
// Skip CRDs do neither install nor replace (update) any CRDs.
Skip CRDsPolicy = "Skip"
// Create CRDs which do not already exist, do not replace (update) already existing
// CRDs and keep (do not delete) CRDs which no longer exist in the current release.
Create CRDsPolicy = "Create"
// Create CRDs which do not already exist, Replace (update) already existing CRDs
// and keep (do not delete) CRDs which no longer exist in the current release.
CreateReplace CRDsPolicy = "CreateReplace"
)

// Upgrade holds the configuration for Helm upgrade actions for this
// HelmRelease.
type Upgrade struct {
Expand Down Expand Up @@ -473,6 +513,26 @@ type Upgrade struct {
// upgrade action when it fails.
// +optional
CleanupOnFail bool `json:"cleanupOnFail,omitempty"`

// CRDs upgrade CRDs from the Helm Chart's crds directory according
// to the CRD upgrade policy provided here. Valid values are `Skip`,
// `Create` or `CreateReplace`. Default is `Skip` and if omitted
// CRDs are neither installed nor upgraded.
//
// Skip: do neither install nor replace (update) any CRDs.
//
// Create: new CRDs are created, existing CRDs are neither updated nor deleted.
//
// CreateReplace: new CRDs are created, existing CRDs are updated (replaced)
// but not deleted.
//
// By default, CRDs are not applied during Helm upgrade action. With this
// option users can opt-in to CRD upgrade, which is not (yet) natively supported by Helm.
// https://helm.sh/docs/chart_best_practices/custom_resource_definitions.
//
// +kubebuilder:validation:Enum=Skip;Create;CreateReplace
// +optional
CRDs CRDsPolicy `json:"crds,omitempty"`
}

// GetTimeout returns the configured timeout for the Helm upgrade action, or the
Expand Down
39 changes: 38 additions & 1 deletion config/crd/bases/helm.toolkit.fluxcd.io_helmreleases.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,24 @@ spec:
description: Install holds the configuration for Helm install actions
for this HelmRelease.
properties:
crds:
description: "CRDs upgrade CRDs from the Helm Chart's crds directory
according to the CRD upgrade policy provided here. Valid values
are `Skip`, `Create` or `CreateReplace`. Default is `Create`
and if omitted CRDs are installed but not updated. \n Skip:
do neither install nor replace (update) any CRDs. \n Create:
new CRDs are created, existing CRDs are neither updated nor
deleted. \n CreateReplace: new CRDs are created, existing CRDs
are updated (replaced) but not deleted. \n By default, CRDs
are applied (installed) during Helm install action. With this
option users can opt-in to CRD replace existing CRDs on Helm
install actions, which is not (yet) natively supported by Helm.
https://helm.sh/docs/chart_best_practices/custom_resource_definitions."
enum:
- Skip
- Create
- CreateReplace
type: string
createNamespace:
description: CreateNamespace tells the Helm install action to
create the HelmReleaseSpec.TargetNamespace if it does not exist
Expand Down Expand Up @@ -188,8 +206,10 @@ spec:
remains in the history.
type: boolean
skipCRDs:
description: SkipCRDs tells the Helm install action to not install
description: "SkipCRDs tells the Helm install action to not install
any CRDs. By default, CRDs are installed if not already present.
\n Deprecated use CRD policy (`crds`) attribute with value `Skip`
instead."
type: boolean
timeout:
description: Timeout is the time to wait for any individual Kubernetes
Expand Down Expand Up @@ -459,6 +479,23 @@ spec:
description: CleanupOnFail allows deletion of new resources created
during the Helm upgrade action when it fails.
type: boolean
crds:
description: "CRDs upgrade CRDs from the Helm Chart's crds directory
according to the CRD upgrade policy provided here. Valid values
are `Skip`, `Create` or `CreateReplace`. Default is `Skip` and
if omitted CRDs are neither installed nor upgraded. \n Skip:
do neither install nor replace (update) any CRDs. \n Create:
new CRDs are created, existing CRDs are neither updated nor
deleted. \n CreateReplace: new CRDs are created, existing CRDs
are updated (replaced) but not deleted. \n By default, CRDs
are not applied during Helm upgrade action. With this option
users can opt-in to CRD upgrade, which is not (yet) natively
supported by Helm. https://helm.sh/docs/chart_best_practices/custom_resource_definitions."
enum:
- Skip
- Create
- CreateReplace
type: string
disableHooks:
description: DisableHooks prevents hooks from running during the
Helm upgrade action.
Expand Down
7 changes: 7 additions & 0 deletions config/testdata/charts/crds/bootstrap/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
23 changes: 23 additions & 0 deletions config/testdata/charts/crds/bootstrap/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
apiVersion: v2
name: crd-upgrade-bootstrap
description: Helper Chart to bootstrap e2e test GitRepository

# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
type: application

# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 1.0.0

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
appVersion: 1.0.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
apiVersion: source.toolkit.fluxcd.io/v1beta1
kind: GitRepository
metadata:
name: this
namespace: default
spec:
interval: 1m
url: "{{ .Values.url }}"
ref:
{{- if .Values.branch }}
branch: "{{ .Values.branch }}"
{{- end}}
{{- if .Values.branch }}
tag: "{{ .Values.tag }}"
{{- end}}
3 changes: 3 additions & 0 deletions config/testdata/charts/crds/bootstrap/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
url: "https://github.com/fluxcd/helm-controller"
branch: null
tag: null
7 changes: 7 additions & 0 deletions config/testdata/charts/crds/v1/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
23 changes: 23 additions & 0 deletions config/testdata/charts/crds/v1/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
apiVersion: v2
name: crd-upgrade
description: CRDs Upgrade Test Chart v1

# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
type: application

# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 1.0.0

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
appVersion: 1.0.0
38 changes: 38 additions & 0 deletions config/testdata/charts/crds/v1/crds/a.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@

---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: crdupgradetestas.crd-upgrades.helmreleases.helm.toolkit.fluxcd.io
spec:
group: crd-upgrades.helmreleases.helm.toolkit.fluxcd.io
names:
kind: CrdUpgradeTesta
listKind: CrdUpgradeTestaList
plural: crdupgradetestas
singular: crdupgradetesta
scope: Namespaced
versions:
- name: v2beta1
schema:
openAPIV3Schema:
description: Test
properties:
apiVersion:
type: string
kind:
type: string
metadata:
type: object
spec:
properties: {}
type: object
status:
properties: {}
type: object
type: object
served: true
storage: true
subresources:
status: {}

38 changes: 38 additions & 0 deletions config/testdata/charts/crds/v1/crds/b.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@

---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: crdupgradetestbs.crd-upgrades.helmreleases.helm.toolkit.fluxcd.io
spec:
group: crd-upgrades.helmreleases.helm.toolkit.fluxcd.io
names:
kind: CrdUpgradeTestb
listKind: CrdUpgradeTestbList
plural: crdupgradetestbs
singular: crdupgradetestb
scope: Namespaced
versions:
- name: v2beta1
schema:
openAPIV3Schema:
description: Test
properties:
apiVersion:
type: string
kind:
type: string
metadata:
type: object
spec:
properties: {}
type: object
status:
properties: {}
type: object
type: object
served: true
storage: true
subresources:
status: {}

38 changes: 38 additions & 0 deletions config/testdata/charts/crds/v1/crds/d.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@

---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: crdupgradetestds.crd-upgrades.helmreleases.helm.toolkit.fluxcd.io
spec:
group: crd-upgrades.helmreleases.helm.toolkit.fluxcd.io
names:
kind: CrdUpgradeTestd
listKind: CrdUpgradeTestdList
plural: crdupgradetestds
singular: crdupgradetestd
scope: Namespaced
versions:
- name: v2beta1
schema:
openAPIV3Schema:
description: Test
properties:
apiVersion:
type: string
kind:
type: string
metadata:
type: object
spec:
properties: {}
type: object
status:
properties: {}
type: object
type: object
served: true
storage: true
subresources:
status: {}

Loading