Skip to content

Commit 3dacb31

Browse files
committed
optional interval and default timeout for helmrepo
With static HelmRepository OCI, the interval become optional. Make interval optional in the API. Introduce getters for interval, in the form of GetRequeueAfter(), and timeout with internal default values. HelmRepository will not have interval and timeout fields unless it's explicitly set. Signed-off-by: Sunny <[email protected]>
1 parent b518499 commit 3dacb31

File tree

6 files changed

+33
-17
lines changed

6 files changed

+33
-17
lines changed

api/v1beta2/helmrepository_types.go

+17-5
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,13 @@ type HelmRepositorySpec struct {
8989
// efficient use of resources.
9090
// +kubebuilder:validation:Type=string
9191
// +kubebuilder:validation:Pattern="^([0-9]+(\\.[0-9]+)?(ms|s|m|h))+$"
92-
// +required
93-
Interval metav1.Duration `json:"interval"`
92+
// +optional
93+
Interval metav1.Duration `json:"interval,omitempty"`
9494

9595
// Timeout is used for the index fetch operation for an HTTPS helm repository,
96-
// and for remote OCI Repository operations like pulling for an OCI helm repository.
96+
// and for remote OCI Repository operations like pulling for an OCI helm
97+
// chart by the associated HelmChart.
9798
// Its default value is 60s.
98-
// +kubebuilder:default:="60s"
9999
// +kubebuilder:validation:Type=string
100100
// +kubebuilder:validation:Pattern="^([0-9]+(\\.[0-9]+)?(ms|s|m))+$"
101101
// +optional
@@ -170,7 +170,19 @@ func (in *HelmRepository) SetConditions(conditions []metav1.Condition) {
170170
// GetRequeueAfter returns the duration after which the source must be
171171
// reconciled again.
172172
func (in HelmRepository) GetRequeueAfter() time.Duration {
173-
return in.Spec.Interval.Duration
173+
if in.Spec.Interval.Duration != 0 {
174+
return in.Spec.Interval.Duration
175+
}
176+
return time.Minute
177+
}
178+
179+
// GetTimeout returns the timeout duration used for various operations related
180+
// to this HelmRepository.
181+
func (in HelmRepository) GetTimeout() time.Duration {
182+
if in.Spec.Timeout != nil {
183+
return in.Spec.Timeout.Duration
184+
}
185+
return time.Minute
174186
}
175187

176188
// GetArtifact returns the latest artifact from the source if present in the

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

+2-3
Original file line numberDiff line numberDiff line change
@@ -357,10 +357,10 @@ spec:
357357
of this HelmRepository.
358358
type: boolean
359359
timeout:
360-
default: 60s
361360
description: Timeout is used for the index fetch operation for an
362361
HTTPS helm repository, and for remote OCI Repository operations
363-
like pulling for an OCI helm repository. Its default value is 60s.
362+
like pulling for an OCI helm chart by the associated HelmChart.
363+
Its default value is 60s.
364364
pattern: ^([0-9]+(\.[0-9]+)?(ms|s|m))+$
365365
type: string
366366
type:
@@ -376,7 +376,6 @@ spec:
376376
pattern: ^(http|https|oci)://.*$
377377
type: string
378378
required:
379-
- interval
380379
- url
381380
type: object
382381
status:

docs/api/v1beta2/source.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -866,6 +866,7 @@ Kubernetes meta/v1.Duration
866866
</em>
867867
</td>
868868
<td>
869+
<em>(Optional)</em>
869870
<p>Interval at which the HelmRepository URL is checked for updates.
870871
This interval is approximate and may be subject to jitter to ensure
871872
efficient use of resources.</p>
@@ -883,7 +884,8 @@ Kubernetes meta/v1.Duration
883884
<td>
884885
<em>(Optional)</em>
885886
<p>Timeout is used for the index fetch operation for an HTTPS helm repository,
886-
and for remote OCI Repository operations like pulling for an OCI helm repository.
887+
and for remote OCI Repository operations like pulling for an OCI helm
888+
chart by the associated HelmChart.
887889
Its default value is 60s.</p>
888890
</td>
889891
</tr>
@@ -2583,6 +2585,7 @@ Kubernetes meta/v1.Duration
25832585
</em>
25842586
</td>
25852587
<td>
2588+
<em>(Optional)</em>
25862589
<p>Interval at which the HelmRepository URL is checked for updates.
25872590
This interval is approximate and may be subject to jitter to ensure
25882591
efficient use of resources.</p>
@@ -2600,7 +2603,8 @@ Kubernetes meta/v1.Duration
26002603
<td>
26012604
<em>(Optional)</em>
26022605
<p>Timeout is used for the index fetch operation for an HTTPS helm repository,
2603-
and for remote OCI Repository operations like pulling for an OCI helm repository.
2606+
and for remote OCI Repository operations like pulling for an OCI helm
2607+
chart by the associated HelmChart.
26042608
Its default value is 60s.</p>
26052609
</td>
26062610
</tr>

docs/spec/v1beta2/helmrepositories.md

+5-4
Original file line numberDiff line numberDiff line change
@@ -352,8 +352,9 @@ for more information about setting up GKE Workload Identity.
352352
**Note:** This field is ineffectual for [OCI Helm
353353
Repositories](#helm-oci-repository).
354354

355-
`.spec.interval` is a required field that specifies the interval which the
356-
Helm repository index must be consulted at.
355+
`.spec.interval` is a an optional field that specifies the interval which the
356+
Helm repository index must be consulted at. When not set, the default value is
357+
`1m`.
357358

358359
After successfully reconciling a HelmRepository object, the source-controller
359360
requeues the object for inspection after the specified interval. The value
@@ -385,8 +386,8 @@ Repositories](#helm-oci-repository).
385386
`.spec.timeout` is an optional field to specify a timeout for the fetch
386387
operation. The value must be in a
387388
[Go recognized duration string format](https://pkg.go.dev/time#ParseDuration),
388-
e.g. `1m30s` for a timeout of one minute and thirty seconds. The default value
389-
is `60s`.
389+
e.g. `1m30s` for a timeout of one minute and thirty seconds. When not set, the
390+
default value is `1m`.
390391

391392
### Secret reference
392393

internal/controller/helmchart_controller.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ func (r *HelmChartReconciler) reconcileSource(ctx context.Context, sp *patch.Ser
514514
func (r *HelmChartReconciler) buildFromHelmRepository(ctx context.Context, obj *helmv1.HelmChart,
515515
repo *helmv1.HelmRepository, b *chart.Build) (sreconcile.Result, error) {
516516
// Used to login with the repository declared provider
517-
ctxTimeout, cancel := context.WithTimeout(ctx, repo.Spec.Timeout.Duration)
517+
ctxTimeout, cancel := context.WithTimeout(ctx, repo.GetTimeout())
518518
defer cancel()
519519

520520
normalizedURL, err := repository.NormalizeURL(repo.Spec.URL)
@@ -999,7 +999,7 @@ func (r *HelmChartReconciler) namespacedChartRepositoryCallback(ctx context.Cont
999999
}
10001000

10011001
// Used to login with the repository declared provider
1002-
ctxTimeout, cancel := context.WithTimeout(ctx, obj.Spec.Timeout.Duration)
1002+
ctxTimeout, cancel := context.WithTimeout(ctx, obj.GetTimeout())
10031003
defer cancel()
10041004

10051005
clientOpts, certsTmpDir, err := getter.GetClientOpts(ctxTimeout, r.Client, obj, normalizedURL)

internal/helm/getter/client_opts.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func GetClientOpts(ctx context.Context, c client.Client, obj *helmv1.HelmReposit
7272
hrOpts := &ClientOpts{
7373
GetterOpts: []helmgetter.Option{
7474
helmgetter.WithURL(url),
75-
helmgetter.WithTimeout(obj.Spec.Timeout.Duration),
75+
helmgetter.WithTimeout(obj.GetTimeout()),
7676
helmgetter.WithPassCredentialsAll(obj.Spec.PassCredentials),
7777
},
7878
}

0 commit comments

Comments
 (0)