Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Duration doesn't actually support 'd' suffix, warn on negative Duration #454

Merged
merged 1 commit into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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 Expand Up @@ -60,5 +60,5 @@
}

func init() {
SchemeBuilder.Register(&Repository{}, &RepositoryList{})

Check failure on line 63 in api/kuik/v1alpha1/repository_types.go

View workflow job for this annotation

GitHub Actions / Static Analysis

cannot use &Repository{} (value of type *Repository) as "k8s.io/apimachinery/pkg/runtime".Object value in argument to SchemeBuilder.Register: *Repository does not implement "k8s.io/apimachinery/pkg/runtime".Object (missing method DeepCopyObject)

Check failure on line 63 in api/kuik/v1alpha1/repository_types.go

View workflow job for this annotation

GitHub Actions / Static Analysis

cannot use &RepositoryList{} (value of type *RepositoryList) as "k8s.io/apimachinery/pkg/runtime".Object value in argument to SchemeBuilder.Register: *RepositoryList does not implement "k8s.io/apimachinery/pkg/runtime".Object (missing method DeepCopyObject)) (typecheck)
}
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
Loading