Skip to content

Commit 8d4fce1

Browse files
darkowlzzhiddeco
authored andcommitted
Add more details in helmchart spec doc
Details about the source reference, reconcile strategy and artifact revision value based on the reconcile strategy. Signed-off-by: Sunny <[email protected]>
1 parent 9e73bfa commit 8d4fce1

File tree

2 files changed

+156
-31
lines changed

2 files changed

+156
-31
lines changed

controllers/helmchart_controller.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -475,8 +475,9 @@ func (r *HelmChartReconciler) buildFromHelmRepository(ctx context.Context, obj *
475475
return sreconcile.ResultSuccess, nil
476476
}
477477

478-
// buildFromHelmRepository attempts to pull and/or package a Helm chart with
479-
// the specified data v1beta2.HelmChart object and the given v1beta2.Artifact.
478+
// buildFromTarballArtifact attempts to pull and/or package a Helm chart with
479+
// the specified data from the v1beta2.HelmChart object and the given
480+
// v1beta2.Artifact.
480481
// In case of a failure it records v1beta2.FetchFailedCondition on the chart
481482
// object, and returns early.
482483
func (r *HelmChartReconciler) buildFromTarballArtifact(ctx context.Context, obj *sourcev1.HelmChart, source sourcev1.Artifact, b *chart.Build) (sreconcile.Result, error) {

docs/spec/v1beta2/helmcharts.md

Lines changed: 153 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -97,56 +97,132 @@ As with all other Kubernetes config, a HelmChart needs `apiVersion`, `kind`, and
9797
A HelmChart also needs a
9898
[`.spec` section](https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#spec-and-status).
9999

100-
### Interval
100+
### Source reference
101101

102-
`.spec.interval` is a required field that specifies the interval at which the
103-
Helm Chart source must be checked for updates.
102+
`.spec.sourceRef` is a required field that specifies a reference to the Source
103+
the chart is available at.
104104

105-
After successfully reconciling a HelmChart object, the source-controller
106-
requeues the object for inspection after the specified interval. The value must
107-
be in a [Go recognized duration string format](https://pkg.go.dev/time#ParseDuration),
108-
e.g. `10m0s` to look at the source for updates every 10 minutes.
105+
Supported references are:
106+
- [`HelmRepository`](helmrepositories.md)
107+
- [`GitRepository`](gitrepositories.md)
108+
- [`Bucket`](buckets.md)
109109

110-
If the `.metadata.generation` of a resource changes (due to e.g. applying a
111-
change to the spec), this is handled instantly outside the interval window.
110+
Although there are three kinds of source references, there are only two
111+
underlying implementations. The artifact building process for `GitRepository`
112+
and `Bucket` are the same as they are already built source artifacts. In case
113+
of `HelmRepository`, a chart is fetched and/or packaged based on the
114+
configuration of the Helm chart.
112115

113-
### Source reference
116+
For a `HelmChart` to be reconciled, the associated artifact in the source
117+
reference must be ready. If the source artifact is not ready, the `HelmChart`
118+
reconciliation is retried.
114119

115-
`.spec.sourceRef` is a required field that specifies a reference to the Source
116-
the chart is available at. `.spec.sourceRef.kind` must be one of
117-
`HelmRepository`, `GitRepository` or `Bucket`. `.spec.sourceRef.name` is the
118-
name of the referred kind.
120+
When the `metadata.generation` of the `HelmChart` don't match with the
121+
`status.observedGeneration`, the chart is fetched from source and/or packaged.
122+
If there's no `.spec.valuesFiles` specified, the chart is only fetched from the
123+
source, and not packaged. If `.spec.valuesFiles` are specified, the chart is
124+
fetched and packaged with the values files. When the `metadata.generation`
125+
matches the `status.observedGeneration`, the chart is only fetched from source
126+
or from the cache if available, and not packaged.
127+
128+
When using a `HelmRepository` source reference, the secret reference defined in
129+
the Helm repository is used to fetch the chart.
130+
131+
The HelmChart reconciliation behavior varies depending on the source reference
132+
kind, see [reconcile strategy](#reconcile-strategy).
133+
134+
The attributes of the generated artifact also varies depending on the source
135+
reference kind, see [artifact](#artifact).
119136

120137
### Chart
121138

122139
`.spec.chart` is a required field that specifies the name or path the Helm chart
123-
is available at in the [Source reference](#source-reference). For HelmRepository
124-
Source reference, it'll be just the name of the chart. For GitRepository and
125-
Bucket Source reference, it'll be the path to the Helm chart directory.
140+
is available at in the [Source reference](#source-reference).
141+
142+
For `HelmRepository` Source reference, it'll be just the name of the chart.
143+
144+
```yaml
145+
spec:
146+
chart: podinfo
147+
sourceRef:
148+
name: podinfo
149+
kind: HelmRepository
150+
```
151+
152+
For `GitRepository` and `Bucket` Source reference, it'll be the path to the
153+
Helm chart directory.
154+
155+
```yaml
156+
spec:
157+
chart: ./charts/podinfo
158+
sourceRef:
159+
name: podinfo
160+
kind: <GitRepository|Bucket>
161+
```
126162

127163
### Version
128164

129165
`.spec.version` is an optional field to specify the version of the chart in
130-
semver. It is applicable only when the Source reference is a HelmRepository. It
131-
is ignored for GitRepository and Bucket Source reference. It defaults to the
132-
latest version of the chart with value `*`.
166+
semver. It is applicable only when the Source reference is a `HelmRepository`.
167+
It is ignored for `GitRepository` and `Bucket` Source reference. It defaults to
168+
the latest version of the chart with value `*`.
169+
170+
Version can be a fixed semver, minor or patch semver range of a specific
171+
version (i.e. `4.0.x`) or any semver range (i.e. `>=4.0.0 <5.0.0`).
133172

134173
### Values files
135174

136175
`.spec.valuesFiles` is an optional field to specify an alternative list of
137176
values files to use as the chart values (values.yaml). The file paths are
138177
expected to be relative to the Source reference. Values files are merged in the
139178
order of the list with the last file overriding the first. It is ignored when
140-
omitted.
179+
omitted. When values files are specified, the chart is fetched and packaged
180+
with the provided values.
181+
182+
```yaml
183+
spec:
184+
chart:
185+
spec:
186+
chart: podinfo
187+
...
188+
valuesFiles:
189+
- values.yaml
190+
- values-production.yaml
191+
```
192+
193+
Values files also affect the generated artifact revision, see
194+
[artifact](#artifact).
141195

142196
### Reconcile strategy
143197

144198
`.spec.reconcileStrategy` is an optional field to specify what enables the
145199
creation of a new Artifact. Valid values are `ChartVersion` and `Revision`.
146200
`ChartVersion` is used for creating a new artifact when the chart version
147-
changes in the HelmRepository. `Revision` is used for creating a new artifact
148-
when the source revision changes in GitRepository or Bucket Source references.
149-
It defaults to `ChartVersion`.
201+
changes in a `HelmRepository`. `Revision` is used for creating a new artifact
202+
when the source revision changes in a `GitRepository` or a `Bucket` Source. It
203+
defaults to `ChartVersion`.
204+
205+
**NOTE:** If the reconcile strategy is `ChartVersion` and the source reference
206+
is a `GitRepository` or a `Bucket`, no new chart artifact is produced on updates
207+
to the source unless the `version` in `Chart.yaml` is incremented. To produce
208+
new chart artifact on change in source revision, set the reconcile strategy to
209+
`Revision`.
210+
211+
Reconcile strategy also affects the artifact version, see [artifact](#artifact)
212+
for more details.
213+
214+
### Interval
215+
216+
`.spec.interval` is a required field that specifies the interval at which the
217+
Helm Chart source must be checked for updates.
218+
219+
After successfully reconciling a HelmChart object, the source-controller
220+
requeues the object for inspection after the specified interval. The value must
221+
be in a [Go recognized duration string format](https://pkg.go.dev/time#ParseDuration),
222+
e.g. `10m0s` to look at the source for updates every 10 minutes.
223+
224+
If the `.metadata.generation` of a resource changes (due to e.g. applying a
225+
change to the spec), this is handled instantly outside the interval window.
150226

151227
### Suspend
152228

@@ -317,7 +393,7 @@ The HelmChart reports the last built chart as an Artifact object in the
317393
The Artifact file is a gzip compressed TAR archive (`<chart-name>-<chart-version>.tgz`),
318394
and can be retrieved in-cluster from the `.status.artifact.url` HTTP address.
319395

320-
### Artifact example
396+
#### Artifact example
321397

322398
```yaml
323399
---
@@ -334,6 +410,51 @@ status:
334410
url: http://source-controller.flux-system.svc.cluster.local./helmchart/<source-namespace>/<chart-name>/<chart-name>-<chart-version>.tgz
335411
```
336412

413+
When using a `HelmRepository` as the source reference and values files are
414+
provided, the value of `status.artifact.revision` is the chart version combined
415+
with the `HelmChart` object generation. For example, if the chart version is
416+
`6.0.3` and the `HelmChart` object generation is `1`, the
417+
`status.artifact.revision` value will be `6.0.3+1`.
418+
419+
```yaml
420+
---
421+
apiVersion: source.toolkit.fluxcd.io/v1beta2
422+
kind: HelmChart
423+
metadata:
424+
name: <chart-name>
425+
status:
426+
artifact:
427+
checksum: ee68224ded207ebb18a8e9730cf3313fa6bc1f31e6d8d3943ab541113559bb52
428+
lastUpdateTime: "2022-02-28T08:07:12Z"
429+
path: helmchart/<source-namespace>/<chart-name>/<chart-name>-6.0.3+1.tgz
430+
revision: 6.0.3+1
431+
url: http://source-controller.flux-system.svc.cluster.local./helmchart/<source-namespace>/<chart-name>/<chart-name>-6.0.3+1.tgz
432+
observedGeneration: 1
433+
...
434+
```
435+
436+
When using a `GitRepository` or a `Bucket` as the source reference and
437+
`Revision` as the reconcile strategy, the value of `status.artifact.revision` is
438+
the chart version combined with the first 12 characters of the revision of the
439+
`GitRepository` or `Bucket`. For example if the chart version is `6.0.3` and the
440+
revision of the `Bucket` is `4e5cbb7b97d00a8039b8810b90b922f4256fd3bd8f78b934b4892dae13f7ca87`,
441+
the `status.artifact.revision` value will be `6.0.3+4e5cbb7b97d0`.
442+
443+
```yaml
444+
---
445+
apiVersion: source.toolkit.fluxcd.io/v1beta2
446+
kind: HelmChart
447+
metadata:
448+
name: <chart-name>
449+
status:
450+
artifact:
451+
checksum: 8d1f0ac3f4b0e8759a32180086f17ac87ca04e5d46c356e67f97e97616ef4718
452+
lastUpdateTime: "2022-02-28T08:07:12Z"
453+
path: helmchart/<source-namespace>/<chart-name>/<chart-name>-6.0.3+4e5cbb7b97d0.tgz
454+
revision: 6.0.3+4e5cbb7b97d0
455+
url: http://source-controller.flux-system.svc.cluster.local./helmchart/<source-namespace>/<chart-name>/<chart-name>-6.0.3+4e5cbb7b97d0.tgz
456+
```
457+
337458
### Conditions
338459

339460
A HelmChart enters various states during its lifecycle, reflected as [Kubernetes
@@ -451,15 +572,18 @@ the spec is made.
451572

452573
### Observed Source Artifact Revision
453574

454-
The source-controller reports the revision of the
575+
The source-controller reports the revision of the last
455576
[Source reference's](#source-reference) Artifact the current chart was fetched
456-
from in the HelmChart's `.status.observedSourceArtifactRevision`.
577+
from in the HelmChart's `.status.observedSourceArtifactRevision`. It is used to
578+
keep track of the source artifact revision and detect when a new source
579+
artifact is available.
457580

458581
### Observed Chart Name
459582

460-
The source-controller reports the resolved chart name of the current Artifact
583+
The source-controller reports the last resolved chart name of the Artifact
461584
for the [`.spec.chart` field](#chart) in the HelmChart's
462-
`.status.observedChartName`.
585+
`.status.observedChartName`. It is used to keep track of the chart and detect
586+
when a new chart is found.
463587

464588
### Observed Generation
465589

0 commit comments

Comments
 (0)