Introduce source interface
- add source interface with `GetArtifact` and `GetInterval` funcs - implement source interface for all types - fix HelmChart requeue
This commit is contained in:
parent
95acc78577
commit
1832b2d11d
|
@ -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`
|
||||
|
|
|
@ -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`
|
||||
|
|
|
@ -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`
|
||||
|
|
|
@ -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
|
||||
}
|
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue