Skip to content

Commit

Permalink
fix: time.ParseDuration() doesn't actually support 'd' suffix, warn o…
Browse files Browse the repository at this point in the history
…n negative Duration
  • Loading branch information
ylmrx committed Dec 13, 2024
1 parent f1d6356 commit 53a663b
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion api/kuik/v1alpha1/repository_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type RepositorySpec struct {
PullSecretNames []string `json:"pullSecretNames,omitempty"`
// PullSecretsNamespace is the namespace where pull secrets can be found for CachedImages of this Repository
PullSecretsNamespace string `json:"pullSecretsNamespace,omitempty"`
// UpdateInterval is the interval in human readable format (1m, 1h, 1d...) at which matched CachedImages from this Repository are updated (see spec.UpdateFilters)
// UpdateInterval is the interval in human readable format (1m, 1h...) at which matched CachedImages from this Repository are updated (see spec.UpdateFilters)
UpdateInterval *metav1.Duration `json:"updateInterval,omitempty"`
// UpdateFilters is a list of regexps that need to match (at least one of them) the .spec.SourceImage of a CachedImage from this Repository to update it at regular interval
UpdateFilters []string `json:"updateFilters,omitempty"`
Expand Down
4 changes: 2 additions & 2 deletions config/crd/bases/kuik.enix.io_repositories.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ spec:
type: array
updateInterval:
description: UpdateInterval is the interval in human readable format
(1m, 1h, 1d...) at which matched CachedImages from this Repository
are updated (see spec.UpdateFilters)
(1m, 1h...) at which matched CachedImages from this Repository are
updated (see spec.UpdateFilters)
type: string
required:
- name
Expand Down
4 changes: 2 additions & 2 deletions helm/kube-image-keeper/crds/repository-crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ spec:
type: array
updateInterval:
description: UpdateInterval is the interval in human readable format
(1m, 1h, 1d...) at which matched CachedImages from this Repository
are updated (see spec.UpdateFilters)
(1m, 1h...) at which matched CachedImages from this Repository are
updated (see spec.UpdateFilters)
type: string
required:
- name
Expand Down
5 changes: 5 additions & 0 deletions internal/controller/kuik/repository_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package kuik

import (
"context"
"errors"
"fmt"
"regexp"
"time"

Expand Down Expand Up @@ -149,6 +151,9 @@ func (r *RepositoryReconciler) Reconcile(ctx context.Context, req ctrl.Request)
}

if repository.Spec.UpdateInterval != nil {
if repository.Spec.UpdateInterval.Duration <= 0 {
return ctrl.Result{}, errors.New(fmt.Sprintf("invalid UpdateInterval: %s", repository.Spec.UpdateInterval.String()))
}
nextUpdate := repository.Status.LastUpdate.Add(repository.Spec.UpdateInterval.Duration)
if time.Now().After(nextUpdate) {
log.Info("updating repository")
Expand Down

0 comments on commit 53a663b

Please sign in to comment.