Skip to content

Commit

Permalink
Support charts from GitRepository sources
Browse files Browse the repository at this point in the history
  • Loading branch information
hiddeco committed Sep 1, 2020
1 parent 3413c76 commit a165ff6
Show file tree
Hide file tree
Showing 37 changed files with 444 additions and 219 deletions.
1 change: 1 addition & 0 deletions .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ jobs:
run: |
kubectl -n helm-system apply -f config/testdata/podinfo/
kubectl -n helm-system wait helmreleases/podinfo --for=condition=ready --timeout=4m
kubectl -n helm-system wait helmreleases/podinfo-git --for=condition=ready --timeout=4m
- name: Run dependency tests
run: |
kubectl -n helm-system apply -f config/testdata/dependencies
Expand Down
37 changes: 23 additions & 14 deletions api/v2alpha1/helmrelease_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ const HelmReleaseFinalizer = "finalizers.fluxcd.io"

// HelmReleaseSpec defines the desired state of HelmRelease.
type HelmReleaseSpec struct {
// Chart defines the Helm chart name, version and repository.
// Chart defines the template of the v1alpha1.HelmChart that should be created
// for this HelmRelease.
// +required
Chart HelmChartTemplate `json:"chart"`

Expand Down Expand Up @@ -139,41 +140,49 @@ func (in HelmReleaseSpec) GetUninstall() Uninstall {
return *in.Uninstall
}

// HelmChartTemplate defines the template from which the controller
// will generate a HelmChart object in the same namespace as the HelmRepository.
// HelmChartTemplate defines the template from which the controller will generate a
// v1alpha1.HelmChart object in the same namespace as the referenced v1alpha1.Source.
type HelmChartTemplate struct {
// Name of the Helm chart, as made available by the referenced Helm repository.
// +required
Name string `json:"name"`
Spec HelmChartTemplateSpec `json:"spec"`
}

type HelmChartTemplateSpec struct {
// The name or path the Helm chart is available at in the SourceRef.
// +required
Chart string `json:"chart"`

// Version semver expression, defaults to latest when omitted.
// Version semver expression, ignored for charts from GitRepository sources.
// Defaults to latest when omitted.
// +optional
Version string `json:"version,omitempty"`

// The name and namespace of the source HelmRepository the chart is available at.
// The name and namespace of the v1alpha1.Source the chart is available at.
// +required
SourceRef CrossNamespaceObjectReference `json:"sourceRef"`

// Interval at which to check the Helm repository for chart updates.
// Interval at which to check the v1alpha1.Source for updates.
// Defaults to 'HelmReleaseSpec.Interval'.
// +optional
Interval *metav1.Duration `json:"interval,omitempty"`
}

// GetInterval returns the configured interval for the HelmChart, or the given default.
// GetInterval returns the configured interval for the v1alpha1.HelmChart,
// or the given default.
func (in HelmChartTemplate) GetInterval(defaultInterval metav1.Duration) metav1.Duration {
if in.Interval == nil {
if in.Spec.Interval == nil {
return defaultInterval
}
return *in.Interval
return *in.Spec.Interval
}

// GetNamespace returns the namespace targeted namespace for the HelmChart, or the given default.
// GetNamespace returns the namespace targeted namespace for the v1alpha1.HelmChart,
// or the given default.
func (in HelmChartTemplate) GetNamespace(defaultNamespace string) string {
if in.SourceRef.Namespace == "" {
if in.Spec.SourceRef.Namespace == "" {
return defaultNamespace
}
return in.SourceRef.Namespace
return in.Spec.SourceRef.Namespace
}

// DeploymentAction defines a consistent interface for Install and Upgrade.
Expand Down
2 changes: 1 addition & 1 deletion api/v2alpha1/reference_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type CrossNamespaceObjectReference struct {
APIVersion string `json:"apiVersion,omitempty"`

// Kind of the referent.
// +kubebuilder:validation:Enum=HelmRepository
// +kubebuilder:validation:Enum=HelmRepository;GitRepository
// +required
Kind string `json:"kind,omitempty"`

Expand Down
22 changes: 19 additions & 3 deletions api/v2alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

67 changes: 37 additions & 30 deletions config/crd/bases/helm.toolkit.fluxcd.io_helmreleases.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,44 +49,51 @@ spec:
description: HelmReleaseSpec defines the desired state of HelmRelease.
properties:
chart:
description: Chart defines the Helm chart name, version and repository.
description: Chart defines the template of the v1alpha1.HelmChart
that should be created for this HelmRelease.
properties:
interval:
description: Interval at which to check the Helm repository for
chart updates. Defaults to 'HelmReleaseSpec.Interval'.
type: string
name:
description: Name of the Helm chart, as made available by the
referenced Helm repository.
type: string
sourceRef:
description: The name and namespace of the source HelmRepository
the chart is available at.
spec:
properties:
apiVersion:
description: APIVersion of the referent.
chart:
description: The name or path the Helm chart is available
at in the SourceRef.
type: string
kind:
description: Kind of the referent.
enum:
- HelmRepository
interval:
description: Interval at which to check the v1alpha1.Source
for updates. Defaults to 'HelmReleaseSpec.Interval'.
type: string
name:
description: Name of the referent.
type: string
namespace:
description: Namespace of the referent.
sourceRef:
description: The name and namespace of the v1alpha1.Source
the chart is available at.
properties:
apiVersion:
description: APIVersion of the referent.
type: string
kind:
description: Kind of the referent.
enum:
- HelmRepository
- GitRepository
type: string
name:
description: Name of the referent.
type: string
namespace:
description: Namespace of the referent.
type: string
required:
- name
type: object
version:
description: Version semver expression, ignored for charts
from GitRepository sources. Defaults to latest when omitted.
type: string
required:
- name
- chart
- sourceRef
type: object
version:
description: Version semver expression, defaults to latest when
omitted.
type: string
required:
- name
- sourceRef
- spec
type: object
dependsOn:
description: DependsOn may contain a list of HelmReleases that must
Expand Down
4 changes: 2 additions & 2 deletions config/default/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ resources:
- ../crd
- ../rbac
- ../manager
- github.com/fluxcd/source-controller/config//crd?ref=v0.0.9
- github.com/fluxcd/source-controller/config//manager?ref=v0.0.9
- github.com/fluxcd/source-controller/config//crd?ref=v0.0.13
- github.com/fluxcd/source-controller/config//manager?ref=v0.0.13
- namespace.yaml
17 changes: 0 additions & 17 deletions config/samples/helm_v2alpha1_helmrelease.yaml

This file was deleted.

18 changes: 18 additions & 0 deletions config/samples/helm_v2alpha1_helmrelease_gitrepository.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: helm.toolkit.fluxcd.io/v2alpha1
kind: HelmRelease
metadata:
name: podinfo-gitrepository
spec:
interval: 5m
chart:
spec:
chart: ./charts/podinfo
sourceRef:
kind: GitRepository
name: podinfo
interval: 1m
upgrade:
remediation:
remediateLastFailure: true
test:
enable: true
19 changes: 19 additions & 0 deletions config/samples/helm_v2alpha1_helmrelease_helmrepository.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
apiVersion: helm.toolkit.fluxcd.io/v2alpha1
kind: HelmRelease
metadata:
name: podinfo-helmrepository
spec:
interval: 5m
chart:
spec:
chart: podinfo
version: '>=4.0.0 <5.0.0'
sourceRef:
kind: HelmRepository
name: podinfo
interval: 1m
upgrade:
remediation:
remediateLastFailure: true
test:
enable: true
9 changes: 9 additions & 0 deletions config/samples/source_v1alpha1_gitrepository.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: source.toolkit.fluxcd.io/v1alpha1
kind: GitRepository
metadata:
name: podinfo
spec:
interval: 1m
url: https://github.com/stefanprodan/podinfo
ref:
branch: master
13 changes: 7 additions & 6 deletions config/testdata/dependencies/helmrelease-backend.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ metadata:
spec:
interval: 5m
chart:
name: podinfo
version: '^4.0.0'
sourceRef:
kind: HelmRepository
name: webapp
interval: 1m
spec:
chart: podinfo
version: '>=4.0.0 <5.0.0'
sourceRef:
kind: HelmRepository
name: webapp
interval: 1m
values:
service:
grpcService: backend
Expand Down
13 changes: 7 additions & 6 deletions config/testdata/dependencies/helmrelease-frontend.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ metadata:
spec:
interval: 5m
chart:
name: podinfo
version: '^4.0.0'
sourceRef:
kind: HelmRepository
name: webapp
interval: 1m
spec:
chart: podinfo
version: '>=4.0.0 <5.0.0'
sourceRef:
kind: HelmRepository
name: webapp
interval: 1m
dependsOn:
- backend
values:
Expand Down
13 changes: 7 additions & 6 deletions config/testdata/install-fail-remediate/helmrelease.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ metadata:
spec:
interval: 5m
chart:
name: podinfo
version: '^4.0.0'
sourceRef:
kind: HelmRepository
name: podinfo
interval: 1m
spec:
chart: podinfo
version: '>=4.0.0 <5.0.0'
sourceRef:
kind: HelmRepository
name: podinfo
interval: 1m
install:
remediation:
remediateLastFailure: true
Expand Down
13 changes: 7 additions & 6 deletions config/testdata/install-fail-retry/helmrelease.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ metadata:
spec:
interval: 5m
chart:
name: podinfo
version: '^4.0.0'
sourceRef:
kind: HelmRepository
name: podinfo
interval: 1m
spec:
chart: podinfo
version: '>=4.0.0 <5.0.0'
sourceRef:
kind: HelmRepository
name: podinfo
interval: 1m
install:
remediation:
retries: 1
Expand Down
13 changes: 7 additions & 6 deletions config/testdata/install-fail/helmrelease.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ metadata:
spec:
interval: 5m
chart:
name: podinfo
version: '^4.0.0'
sourceRef:
kind: HelmRepository
name: podinfo
interval: 1m
spec:
chart: podinfo
version: '>=4.0.0 <5.0.0'
sourceRef:
kind: HelmRepository
name: podinfo
interval: 1m
values:
resources:
requests:
Expand Down
Loading

0 comments on commit a165ff6

Please sign in to comment.