diff --git a/api/v1alpha1/gitrepository_types.go b/api/v1alpha1/gitrepository_types.go index 4493f0f4..75417902 100644 --- a/api/v1alpha1/gitrepository_types.go +++ b/api/v1alpha1/gitrepository_types.go @@ -126,6 +126,17 @@ func GitRepositoryReadyMessage(repository GitRepository) string { return "" } +// GetArtifact returns the latest artifact from the source +// if present in the status sub-resource. +func (in *GitRepository) GetArtifact() *Artifact { + return in.Status.Artifact +} + +// GetInterval returns the interval at which the source is updated. +func (in *GitRepository) GetInterval() metav1.Duration { + return in.Spec.Interval +} + // +kubebuilder:object:root=true // +kubebuilder:subresource:status // +kubebuilder:printcolumn:name="URL",type=string,JSONPath=`.spec.url` diff --git a/api/v1alpha1/helmchart_types.go b/api/v1alpha1/helmchart_types.go index 48a2cf20..44b3f5d6 100644 --- a/api/v1alpha1/helmchart_types.go +++ b/api/v1alpha1/helmchart_types.go @@ -38,18 +38,8 @@ type HelmChartSpec struct { HelmRepositoryRef corev1.LocalObjectReference `json:"helmRepositoryRef"` // The interval at which to check the Helm repository for updates. - // Defaults to the interval of the Helm repository. - // +optional - Interval *metav1.Duration `json:"interval,omitempty"` -} - -// IntervalOrDefault returns the defined interval on the HelmChartSpec -// or the given default. -func (s HelmChartSpec) IntervalOrDefault(interval metav1.Duration) metav1.Duration { - if s.Interval == nil { - return interval - } - return *s.Interval + // +required + Interval metav1.Duration `json:"interval,omitempty"` } // HelmChartStatus defines the observed state of HelmChart @@ -121,6 +111,17 @@ func HelmChartReadyMessage(chart HelmChart) string { return "" } +// GetArtifact returns the latest artifact from the source +// if present in the status sub-resource. +func (in *HelmChart) GetArtifact() *Artifact { + return in.Status.Artifact +} + +// GetInterval returns the interval at which the source is updated. +func (in *HelmChart) GetInterval() metav1.Duration { + return in.Spec.Interval +} + // +kubebuilder:object:root=true // +kubebuilder:subresource:status // +kubebuilder:printcolumn:name="Name",type=string,JSONPath=`.spec.name` diff --git a/api/v1alpha1/helmrepository_types.go b/api/v1alpha1/helmrepository_types.go index cd1eac32..bd899757 100644 --- a/api/v1alpha1/helmrepository_types.go +++ b/api/v1alpha1/helmrepository_types.go @@ -107,6 +107,17 @@ func HelmRepositoryReadyMessage(repository HelmRepository) string { return "" } +// GetArtifact returns the latest artifact from the source +// if present in the status sub-resource. +func (in *HelmRepository) GetArtifact() *Artifact { + return in.Status.Artifact +} + +// GetInterval returns the interval at which the source is updated. +func (in *HelmRepository) GetInterval() metav1.Duration { + return in.Spec.Interval +} + // +kubebuilder:object:root=true // +kubebuilder:subresource:status // +kubebuilder:printcolumn:name="URL",type=string,JSONPath=`.spec.url` diff --git a/api/v1alpha1/source.go b/api/v1alpha1/source.go new file mode 100644 index 00000000..d98acd26 --- /dev/null +++ b/api/v1alpha1/source.go @@ -0,0 +1,13 @@ +package v1alpha1 + +import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + +// Source interface must be supported by all API types. +// +k8s:deepcopy-gen=false +type Source interface { + // GetArtifact returns the latest artifact from the source + // if present in the status sub-resource. + GetArtifact() *Artifact + // GetInterval returns the interval at which the source is updated. + GetInterval() metav1.Duration +} diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go index 337c634b..57439315 100644 --- a/api/v1alpha1/zz_generated.deepcopy.go +++ b/api/v1alpha1/zz_generated.deepcopy.go @@ -22,7 +22,6 @@ package v1alpha1 import ( "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" ) @@ -174,7 +173,7 @@ func (in *HelmChart) DeepCopyInto(out *HelmChart) { *out = *in out.TypeMeta = in.TypeMeta in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - in.Spec.DeepCopyInto(&out.Spec) + out.Spec = in.Spec in.Status.DeepCopyInto(&out.Status) } @@ -232,11 +231,7 @@ func (in *HelmChartList) DeepCopyObject() runtime.Object { func (in *HelmChartSpec) DeepCopyInto(out *HelmChartSpec) { *out = *in out.HelmRepositoryRef = in.HelmRepositoryRef - if in.Interval != nil { - in, out := &in.Interval, &out.Interval - *out = new(metav1.Duration) - **out = **in - } + out.Interval = in.Interval } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new HelmChartSpec. diff --git a/config/crd/bases/source.fluxcd.io_helmcharts.yaml b/config/crd/bases/source.fluxcd.io_helmcharts.yaml index cdc5910e..95f238d3 100644 --- a/config/crd/bases/source.fluxcd.io_helmcharts.yaml +++ b/config/crd/bases/source.fluxcd.io_helmcharts.yaml @@ -65,7 +65,7 @@ spec: type: object interval: description: The interval at which to check the Helm repository for - updates. Defaults to the interval of the Helm repository. + updates. type: string name: description: The name of the Helm chart, as made available by the referenced diff --git a/controllers/gitrepository_controller.go b/controllers/gitrepository_controller.go index 67d376f5..879cf67f 100644 --- a/controllers/gitrepository_controller.go +++ b/controllers/gitrepository_controller.go @@ -89,7 +89,7 @@ func (r *GitRepositoryReconciler) Reconcile(req ctrl.Request) (ctrl.Result, erro log.Info("Git repository sync succeeded", "msg", sourcev1.GitRepositoryReadyMessage(syncedRepo)) // requeue repository - return ctrl.Result{RequeueAfter: repo.Spec.Interval.Duration}, nil + return ctrl.Result{RequeueAfter: repo.GetInterval().Duration}, nil } func (r *GitRepositoryReconciler) SetupWithManager(mgr ctrl.Manager) error { diff --git a/controllers/helmchart_controller.go b/controllers/helmchart_controller.go index c632cc66..63ea2f75 100644 --- a/controllers/helmchart_controller.go +++ b/controllers/helmchart_controller.go @@ -104,7 +104,7 @@ func (r *HelmChartReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) { log.Info("Helm chart sync succeeded", "msg", sourcev1.HelmChartReadyMessage(pulledChart)) // requeue chart - return ctrl.Result{RequeueAfter: repository.Spec.Interval.Duration}, nil + return ctrl.Result{RequeueAfter: chart.GetInterval().Duration}, nil } func (r *HelmChartReconciler) SetupWithManager(mgr ctrl.Manager) error { diff --git a/controllers/helmrepository_controller.go b/controllers/helmrepository_controller.go index d77445aa..c3999ae0 100644 --- a/controllers/helmrepository_controller.go +++ b/controllers/helmrepository_controller.go @@ -91,7 +91,7 @@ func (r *HelmRepositoryReconciler) Reconcile(req ctrl.Request) (ctrl.Result, err log.Info("Helm repository sync succeeded", "msg", sourcev1.HelmRepositoryReadyMessage(syncedRepo)) // requeue repository - return ctrl.Result{RequeueAfter: repository.Spec.Interval.Duration}, nil + return ctrl.Result{RequeueAfter: repository.GetInterval().Duration}, nil } func (r *HelmRepositoryReconciler) SetupWithManager(mgr ctrl.Manager) error {