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 <darkowlzz@protonmail.com>
This commit is contained in:
Sunny 2023-10-17 21:04:07 +00:00
parent b518499857
commit 3dacb3140e
6 changed files with 33 additions and 17 deletions

View File

@ -89,13 +89,13 @@ type HelmRepositorySpec struct {
// efficient use of resources. // efficient use of resources.
// +kubebuilder:validation:Type=string // +kubebuilder:validation:Type=string
// +kubebuilder:validation:Pattern="^([0-9]+(\\.[0-9]+)?(ms|s|m|h))+$" // +kubebuilder:validation:Pattern="^([0-9]+(\\.[0-9]+)?(ms|s|m|h))+$"
// +required // +optional
Interval metav1.Duration `json:"interval"` Interval metav1.Duration `json:"interval,omitempty"`
// Timeout is used for the index fetch operation for an HTTPS helm repository, // Timeout is used for the index fetch operation for an HTTPS helm repository,
// and for remote OCI Repository operations like pulling for an OCI helm repository. // and for remote OCI Repository operations like pulling for an OCI helm
// chart by the associated HelmChart.
// Its default value is 60s. // Its default value is 60s.
// +kubebuilder:default:="60s"
// +kubebuilder:validation:Type=string // +kubebuilder:validation:Type=string
// +kubebuilder:validation:Pattern="^([0-9]+(\\.[0-9]+)?(ms|s|m))+$" // +kubebuilder:validation:Pattern="^([0-9]+(\\.[0-9]+)?(ms|s|m))+$"
// +optional // +optional
@ -170,8 +170,20 @@ func (in *HelmRepository) SetConditions(conditions []metav1.Condition) {
// GetRequeueAfter returns the duration after which the source must be // GetRequeueAfter returns the duration after which the source must be
// reconciled again. // reconciled again.
func (in HelmRepository) GetRequeueAfter() time.Duration { func (in HelmRepository) GetRequeueAfter() time.Duration {
if in.Spec.Interval.Duration != 0 {
return in.Spec.Interval.Duration return in.Spec.Interval.Duration
} }
return time.Minute
}
// GetTimeout returns the timeout duration used for various operations related
// to this HelmRepository.
func (in HelmRepository) GetTimeout() time.Duration {
if in.Spec.Timeout != nil {
return in.Spec.Timeout.Duration
}
return time.Minute
}
// GetArtifact returns the latest artifact from the source if present in the // GetArtifact returns the latest artifact from the source if present in the
// status sub-resource. // status sub-resource.

View File

@ -357,10 +357,10 @@ spec:
of this HelmRepository. of this HelmRepository.
type: boolean type: boolean
timeout: timeout:
default: 60s
description: Timeout is used for the index fetch operation for an description: Timeout is used for the index fetch operation for an
HTTPS helm repository, and for remote OCI Repository operations HTTPS helm repository, and for remote OCI Repository operations
like pulling for an OCI helm repository. Its default value is 60s. like pulling for an OCI helm chart by the associated HelmChart.
Its default value is 60s.
pattern: ^([0-9]+(\.[0-9]+)?(ms|s|m))+$ pattern: ^([0-9]+(\.[0-9]+)?(ms|s|m))+$
type: string type: string
type: type:
@ -376,7 +376,6 @@ spec:
pattern: ^(http|https|oci)://.*$ pattern: ^(http|https|oci)://.*$
type: string type: string
required: required:
- interval
- url - url
type: object type: object
status: status:

View File

@ -866,6 +866,7 @@ Kubernetes meta/v1.Duration
</em> </em>
</td> </td>
<td> <td>
<em>(Optional)</em>
<p>Interval at which the HelmRepository URL is checked for updates. <p>Interval at which the HelmRepository URL is checked for updates.
This interval is approximate and may be subject to jitter to ensure This interval is approximate and may be subject to jitter to ensure
efficient use of resources.</p> efficient use of resources.</p>
@ -883,7 +884,8 @@ Kubernetes meta/v1.Duration
<td> <td>
<em>(Optional)</em> <em>(Optional)</em>
<p>Timeout is used for the index fetch operation for an HTTPS helm repository, <p>Timeout is used for the index fetch operation for an HTTPS helm repository,
and for remote OCI Repository operations like pulling for an OCI helm repository. and for remote OCI Repository operations like pulling for an OCI helm
chart by the associated HelmChart.
Its default value is 60s.</p> Its default value is 60s.</p>
</td> </td>
</tr> </tr>
@ -2583,6 +2585,7 @@ Kubernetes meta/v1.Duration
</em> </em>
</td> </td>
<td> <td>
<em>(Optional)</em>
<p>Interval at which the HelmRepository URL is checked for updates. <p>Interval at which the HelmRepository URL is checked for updates.
This interval is approximate and may be subject to jitter to ensure This interval is approximate and may be subject to jitter to ensure
efficient use of resources.</p> efficient use of resources.</p>
@ -2600,7 +2603,8 @@ Kubernetes meta/v1.Duration
<td> <td>
<em>(Optional)</em> <em>(Optional)</em>
<p>Timeout is used for the index fetch operation for an HTTPS helm repository, <p>Timeout is used for the index fetch operation for an HTTPS helm repository,
and for remote OCI Repository operations like pulling for an OCI helm repository. and for remote OCI Repository operations like pulling for an OCI helm
chart by the associated HelmChart.
Its default value is 60s.</p> Its default value is 60s.</p>
</td> </td>
</tr> </tr>

View File

@ -352,8 +352,9 @@ for more information about setting up GKE Workload Identity.
**Note:** This field is ineffectual for [OCI Helm **Note:** This field is ineffectual for [OCI Helm
Repositories](#helm-oci-repository). Repositories](#helm-oci-repository).
`.spec.interval` is a required field that specifies the interval which the `.spec.interval` is a an optional field that specifies the interval which the
Helm repository index must be consulted at. Helm repository index must be consulted at. When not set, the default value is
`1m`.
After successfully reconciling a HelmRepository object, the source-controller After successfully reconciling a HelmRepository object, the source-controller
requeues the object for inspection after the specified interval. The value requeues the object for inspection after the specified interval. The value
@ -385,8 +386,8 @@ Repositories](#helm-oci-repository).
`.spec.timeout` is an optional field to specify a timeout for the fetch `.spec.timeout` is an optional field to specify a timeout for the fetch
operation. The value must be in a operation. The value must be in a
[Go recognized duration string format](https://pkg.go.dev/time#ParseDuration), [Go recognized duration string format](https://pkg.go.dev/time#ParseDuration),
e.g. `1m30s` for a timeout of one minute and thirty seconds. The default value e.g. `1m30s` for a timeout of one minute and thirty seconds. When not set, the
is `60s`. default value is `1m`.
### Secret reference ### Secret reference

View File

@ -514,7 +514,7 @@ func (r *HelmChartReconciler) reconcileSource(ctx context.Context, sp *patch.Ser
func (r *HelmChartReconciler) buildFromHelmRepository(ctx context.Context, obj *helmv1.HelmChart, func (r *HelmChartReconciler) buildFromHelmRepository(ctx context.Context, obj *helmv1.HelmChart,
repo *helmv1.HelmRepository, b *chart.Build) (sreconcile.Result, error) { repo *helmv1.HelmRepository, b *chart.Build) (sreconcile.Result, error) {
// Used to login with the repository declared provider // Used to login with the repository declared provider
ctxTimeout, cancel := context.WithTimeout(ctx, repo.Spec.Timeout.Duration) ctxTimeout, cancel := context.WithTimeout(ctx, repo.GetTimeout())
defer cancel() defer cancel()
normalizedURL, err := repository.NormalizeURL(repo.Spec.URL) normalizedURL, err := repository.NormalizeURL(repo.Spec.URL)
@ -999,7 +999,7 @@ func (r *HelmChartReconciler) namespacedChartRepositoryCallback(ctx context.Cont
} }
// Used to login with the repository declared provider // Used to login with the repository declared provider
ctxTimeout, cancel := context.WithTimeout(ctx, obj.Spec.Timeout.Duration) ctxTimeout, cancel := context.WithTimeout(ctx, obj.GetTimeout())
defer cancel() defer cancel()
clientOpts, certsTmpDir, err := getter.GetClientOpts(ctxTimeout, r.Client, obj, normalizedURL) clientOpts, certsTmpDir, err := getter.GetClientOpts(ctxTimeout, r.Client, obj, normalizedURL)

View File

@ -72,7 +72,7 @@ func GetClientOpts(ctx context.Context, c client.Client, obj *helmv1.HelmReposit
hrOpts := &ClientOpts{ hrOpts := &ClientOpts{
GetterOpts: []helmgetter.Option{ GetterOpts: []helmgetter.Option{
helmgetter.WithURL(url), helmgetter.WithURL(url),
helmgetter.WithTimeout(obj.Spec.Timeout.Duration), helmgetter.WithTimeout(obj.GetTimeout()),
helmgetter.WithPassCredentialsAll(obj.Spec.PassCredentials), helmgetter.WithPassCredentialsAll(obj.Spec.PassCredentials),
}, },
} }