Skip to content

Commit c4d9756

Browse files
authored
Merge pull request #117 from fluxcd/helm/charts-from-git
Support Helm charts from GitRepository sources
2 parents 05867db + 24f47ac commit c4d9756

14 files changed

+631
-185
lines changed

api/v1alpha1/helmchart_types.go

Lines changed: 68 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,41 @@ const HelmChartKind = "HelmChart"
2525

2626
// HelmChartSpec defines the desired state of a Helm chart.
2727
type HelmChartSpec struct {
28-
// The name of the Helm chart, as made available by the referenced
29-
// Helm repository.
28+
// The name or path the Helm chart is available at in the SourceRef.
3029
// +required
31-
Name string `json:"name"`
30+
Chart string `json:"chart"`
3231

33-
// The chart version semver expression, defaults to latest when
34-
// omitted.
32+
// The chart version semver expression, ignored for charts from GitRepository
33+
// sources. Defaults to latest when omitted.
3534
// +optional
3635
Version string `json:"version,omitempty"`
3736

38-
// The name of the HelmRepository the chart is available at.
37+
// The reference to the Source the chart is available at.
3938
// +required
40-
HelmRepositoryRef corev1.LocalObjectReference `json:"helmRepositoryRef"`
39+
SourceRef LocalHelmChartSourceReference `json:"sourceRef"`
4140

42-
// The interval at which to check the Helm repository for updates.
41+
// The interval at which to check the Source for updates.
4342
// +required
4443
Interval metav1.Duration `json:"interval"`
4544
}
4645

46+
// LocalHelmChartSourceReference contains enough information to let you locate the
47+
// typed referenced object at namespace level.
48+
type LocalHelmChartSourceReference struct {
49+
// APIVersion of the referent.
50+
// +optional
51+
APIVersion string `json:"apiVersion,omitempty"`
52+
53+
// Kind of the referent, valid values are ('HelmRepository', 'GitRepository').
54+
// +kubebuilder:validation:Enum=HelmRepository;GitRepository
55+
// +required
56+
Kind string `json:"kind"`
57+
58+
// Name of the referent.
59+
// +required
60+
Name string `json:"name"`
61+
}
62+
4763
// HelmChartStatus defines the observed state of the HelmChart.
4864
type HelmChartStatus struct {
4965
// +optional
@@ -63,72 +79,62 @@ const (
6379
// Helm chart failed.
6480
ChartPullFailedReason string = "ChartPullFailed"
6581

66-
// ChartPulLSucceededReason represents the fact that the pull of
82+
// ChartPullSucceededReason represents the fact that the pull of
6783
// the Helm chart succeeded.
6884
ChartPullSucceededReason string = "ChartPullSucceeded"
69-
)
7085

71-
// HelmChartReady sets the given artifact and url on the HelmChart
72-
// and resets the conditions to SourceCondition of type Ready with
73-
// status true and the given reason and message. It returns the
74-
// modified HelmChart.
75-
func HelmChartReady(chart HelmChart, artifact Artifact, url, reason, message string) HelmChart {
76-
chart.Status.Conditions = []SourceCondition{
77-
{
78-
Type: ReadyCondition,
79-
Status: corev1.ConditionTrue,
80-
LastTransitionTime: metav1.Now(),
81-
Reason: reason,
82-
Message: message,
83-
},
84-
}
85-
chart.Status.URL = url
86+
// ChartPackageFailedReason represent the fact that the package of
87+
// the Helm chart failed.
88+
ChartPackageFailedReason string = "ChartPackageFailed"
8689

87-
if chart.Status.Artifact != nil {
88-
if chart.Status.Artifact.Path != artifact.Path {
89-
chart.Status.Artifact = &artifact
90-
}
91-
} else {
92-
chart.Status.Artifact = &artifact
93-
}
90+
// ChartPackageSucceededReason represents the fact that the package of
91+
// the Helm chart succeeded.
92+
ChartPackageSucceededReason string = "ChartPackageSucceeded"
93+
)
9494

95+
// HelmReleaseProgressing resets any failures and registers progress toward reconciling the given HelmRelease
96+
// by setting the ReadyCondition to ConditionUnknown for ProgressingReason.
97+
func HelmChartProgressing(chart HelmChart) HelmChart {
98+
chart.Status.URL = ""
99+
chart.Status.Artifact = nil
100+
chart.Status.Conditions = []SourceCondition{}
101+
SetHelmChartCondition(&chart, ReadyCondition, corev1.ConditionUnknown, ProgressingReason, "reconciliation in progress")
95102
return chart
96103
}
97104

98-
// HelmChartProgressing resets the conditions of the HelmChart
99-
// to SourceCondition of type Ready with status unknown and
100-
// progressing reason and message. It returns the modified HelmChart.
101-
func HelmChartProgressing(chart HelmChart) HelmChart {
102-
chart.Status.Conditions = []SourceCondition{
103-
{
104-
Type: ReadyCondition,
105-
Status: corev1.ConditionUnknown,
106-
LastTransitionTime: metav1.Now(),
107-
Reason: ProgressingReason,
108-
Message: "reconciliation in progress",
109-
},
110-
}
105+
// SetHelmChartCondition sets the given condition with the given status, reason and message
106+
// on the HelmChart.
107+
func SetHelmChartCondition(chart *HelmChart, condition string, status corev1.ConditionStatus, reason, message string) {
108+
chart.Status.Conditions = filterOutSourceCondition(chart.Status.Conditions, condition)
109+
chart.Status.Conditions = append(chart.Status.Conditions, SourceCondition{
110+
Type: condition,
111+
Status: status,
112+
LastTransitionTime: metav1.Now(),
113+
Reason: reason,
114+
Message: message,
115+
})
116+
}
117+
118+
// HelmChartReady sets the given artifact and url on the HelmChart
119+
// and sets the ReadyCondition to True, with the given reason and
120+
// message. It returns the modified HelmChart.
121+
func HelmChartReady(chart HelmChart, artifact Artifact, url, reason, message string) HelmChart {
122+
chart.Status.Artifact = &artifact
123+
chart.Status.URL = url
124+
SetHelmChartCondition(&chart, ReadyCondition, corev1.ConditionTrue, reason, message)
111125
return chart
112126
}
113127

114-
// HelmChartNotReady resets the conditions of the HelmChart to
115-
// SourceCondition of type Ready with status false and the given
116-
// reason and message. It returns the modified HelmChart.
128+
// HelmChartNotReady sets the ReadyCondition on the given HelmChart
129+
// to False, with the given reason and message. It returns the modified
130+
// HelmChart.
117131
func HelmChartNotReady(chart HelmChart, reason, message string) HelmChart {
118-
chart.Status.Conditions = []SourceCondition{
119-
{
120-
Type: ReadyCondition,
121-
Status: corev1.ConditionFalse,
122-
LastTransitionTime: metav1.Now(),
123-
Reason: reason,
124-
Message: message,
125-
},
126-
}
132+
SetHelmChartCondition(&chart, ReadyCondition, corev1.ConditionFalse, reason, message)
127133
return chart
128134
}
129135

130-
// HelmChartReadyMessage returns the message of the SourceCondition
131-
// of type Ready with status true if present, or an empty string.
136+
// HelmChartReadyMessage returns the message of the ReadyCondition
137+
// with status True, or an empty string.
132138
func HelmChartReadyMessage(chart HelmChart) string {
133139
for _, condition := range chart.Status.Conditions {
134140
if condition.Type == ReadyCondition && condition.Status == corev1.ConditionTrue {
@@ -153,9 +159,10 @@ func (in *HelmChart) GetInterval() metav1.Duration {
153159
// +genclient:Namespaced
154160
// +kubebuilder:object:root=true
155161
// +kubebuilder:subresource:status
156-
// +kubebuilder:printcolumn:name="Name",type=string,JSONPath=`.spec.name`
162+
// +kubebuilder:printcolumn:name="Chart",type=string,JSONPath=`.spec.chart`
157163
// +kubebuilder:printcolumn:name="Version",type=string,JSONPath=`.spec.version`
158-
// +kubebuilder:printcolumn:name="Repository",type=string,JSONPath=`.spec.helmRepositoryRef.name`
164+
// +kubebuilder:printcolumn:name="Source Kind",type=string,JSONPath=`.spec.sourceRef.kind`
165+
// +kubebuilder:printcolumn:name="Source Name",type=string,JSONPath=`.spec.sourceRef.name`
159166
// +kubebuilder:printcolumn:name="Ready",type="string",JSONPath=".status.conditions[?(@.type==\"Ready\")].status",description=""
160167
// +kubebuilder:printcolumn:name="Status",type="string",JSONPath=".status.conditions[?(@.type==\"Ready\")].message",description=""
161168
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp",description=""

api/v1alpha1/source.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,16 @@ const (
1717
// reconciliation outside of the defined schedule.
1818
ReconcileAtAnnotation string = "fluxcd.io/reconcileAt"
1919
)
20+
21+
// filterOutSourceCondition returns a new SourceCondition slice without the
22+
// SourceCondition of the given type.
23+
func filterOutSourceCondition(conditions []SourceCondition, condition string) []SourceCondition {
24+
var newConditions []SourceCondition
25+
for _, c := range conditions {
26+
if c.Type == condition {
27+
continue
28+
}
29+
newConditions = append(newConditions, c)
30+
}
31+
return newConditions
32+
}

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 16 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/source.toolkit.fluxcd.io_helmcharts.yaml

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,17 @@ spec:
1717
scope: Namespaced
1818
versions:
1919
- additionalPrinterColumns:
20-
- jsonPath: .spec.name
21-
name: Name
20+
- jsonPath: .spec.chart
21+
name: Chart
2222
type: string
2323
- jsonPath: .spec.version
2424
name: Version
2525
type: string
26-
- jsonPath: .spec.helmRepositoryRef.name
27-
name: Repository
26+
- jsonPath: .spec.sourceRef.kind
27+
name: Source Kind
28+
type: string
29+
- jsonPath: .spec.sourceRef.name
30+
name: Source Name
2831
type: string
2932
- jsonPath: .status.conditions[?(@.type=="Ready")].status
3033
name: Ready
@@ -55,31 +58,41 @@ spec:
5558
spec:
5659
description: HelmChartSpec defines the desired state of a Helm chart.
5760
properties:
58-
helmRepositoryRef:
59-
description: The name of the HelmRepository the chart is available
60-
at.
61+
chart:
62+
description: The name or path the Helm chart is available at in the
63+
SourceRef.
64+
type: string
65+
interval:
66+
description: The interval at which to check the Source for updates.
67+
type: string
68+
sourceRef:
69+
description: The reference to the Source the chart is available at.
6170
properties:
71+
apiVersion:
72+
description: APIVersion of the referent.
73+
type: string
74+
kind:
75+
description: Kind of the referent, valid values are ('HelmRepository',
76+
'GitRepository').
77+
enum:
78+
- HelmRepository
79+
- GitRepository
80+
type: string
6281
name:
63-
description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
64-
TODO: Add other useful fields. apiVersion, kind, uid?'
82+
description: Name of the referent.
6583
type: string
84+
required:
85+
- kind
86+
- name
6687
type: object
67-
interval:
68-
description: The interval at which to check the Helm repository for
69-
updates.
70-
type: string
71-
name:
72-
description: The name of the Helm chart, as made available by the
73-
referenced Helm repository.
74-
type: string
7588
version:
76-
description: The chart version semver expression, defaults to latest
77-
when omitted.
89+
description: The chart version semver expression, ignored for charts
90+
from GitRepository sources. Defaults to latest when omitted.
7891
type: string
7992
required:
80-
- helmRepositoryRef
93+
- chart
8194
- interval
82-
- name
95+
- sourceRef
8396
type: object
8497
status:
8598
description: HelmChartStatus defines the observed state of the HelmChart.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
apiVersion: source.toolkit.fluxcd.io/v1alpha1
2+
kind: HelmChart
3+
metadata:
4+
name: helmchart-git-sample
5+
spec:
6+
chart: charts/podinfo
7+
version: '^2.0.0'
8+
sourceRef:
9+
kind: GitRepository
10+
name: gitrepository-sample
11+
interval: 1m

config/samples/source_v1alpha1_helmchart.yaml renamed to config/samples/source_v1alpha1_helmchart_helmrepository.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ kind: HelmChart
33
metadata:
44
name: helmchart-sample
55
spec:
6-
name: podinfo
6+
chart: podinfo
77
version: '>=2.0.0 <3.0.0'
8-
helmRepositoryRef:
8+
sourceRef:
9+
kind: HelmRepository
910
name: helmrepository-sample
1011
interval: 1m

0 commit comments

Comments
 (0)