Skip to content

Commit 1832b2d

Browse files
committed
Introduce source interface
- add source interface with `GetArtifact` and `GetInterval` funcs - implement source interface for all types - fix HelmChart requeue
1 parent 95acc78 commit 1832b2d

File tree

9 files changed

+54
-23
lines changed

9 files changed

+54
-23
lines changed

api/v1alpha1/gitrepository_types.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,17 @@ func GitRepositoryReadyMessage(repository GitRepository) string {
126126
return ""
127127
}
128128

129+
// GetArtifact returns the latest artifact from the source
130+
// if present in the status sub-resource.
131+
func (in *GitRepository) GetArtifact() *Artifact {
132+
return in.Status.Artifact
133+
}
134+
135+
// GetInterval returns the interval at which the source is updated.
136+
func (in *GitRepository) GetInterval() metav1.Duration {
137+
return in.Spec.Interval
138+
}
139+
129140
// +kubebuilder:object:root=true
130141
// +kubebuilder:subresource:status
131142
// +kubebuilder:printcolumn:name="URL",type=string,JSONPath=`.spec.url`

api/v1alpha1/helmchart_types.go

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,8 @@ type HelmChartSpec struct {
3838
HelmRepositoryRef corev1.LocalObjectReference `json:"helmRepositoryRef"`
3939

4040
// The interval at which to check the Helm repository for updates.
41-
// Defaults to the interval of the Helm repository.
42-
// +optional
43-
Interval *metav1.Duration `json:"interval,omitempty"`
44-
}
45-
46-
// IntervalOrDefault returns the defined interval on the HelmChartSpec
47-
// or the given default.
48-
func (s HelmChartSpec) IntervalOrDefault(interval metav1.Duration) metav1.Duration {
49-
if s.Interval == nil {
50-
return interval
51-
}
52-
return *s.Interval
41+
// +required
42+
Interval metav1.Duration `json:"interval,omitempty"`
5343
}
5444

5545
// HelmChartStatus defines the observed state of HelmChart
@@ -121,6 +111,17 @@ func HelmChartReadyMessage(chart HelmChart) string {
121111
return ""
122112
}
123113

114+
// GetArtifact returns the latest artifact from the source
115+
// if present in the status sub-resource.
116+
func (in *HelmChart) GetArtifact() *Artifact {
117+
return in.Status.Artifact
118+
}
119+
120+
// GetInterval returns the interval at which the source is updated.
121+
func (in *HelmChart) GetInterval() metav1.Duration {
122+
return in.Spec.Interval
123+
}
124+
124125
// +kubebuilder:object:root=true
125126
// +kubebuilder:subresource:status
126127
// +kubebuilder:printcolumn:name="Name",type=string,JSONPath=`.spec.name`

api/v1alpha1/helmrepository_types.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,17 @@ func HelmRepositoryReadyMessage(repository HelmRepository) string {
107107
return ""
108108
}
109109

110+
// GetArtifact returns the latest artifact from the source
111+
// if present in the status sub-resource.
112+
func (in *HelmRepository) GetArtifact() *Artifact {
113+
return in.Status.Artifact
114+
}
115+
116+
// GetInterval returns the interval at which the source is updated.
117+
func (in *HelmRepository) GetInterval() metav1.Duration {
118+
return in.Spec.Interval
119+
}
120+
110121
// +kubebuilder:object:root=true
111122
// +kubebuilder:subresource:status
112123
// +kubebuilder:printcolumn:name="URL",type=string,JSONPath=`.spec.url`

api/v1alpha1/source.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package v1alpha1
2+
3+
import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
4+
5+
// Source interface must be supported by all API types.
6+
// +k8s:deepcopy-gen=false
7+
type Source interface {
8+
// GetArtifact returns the latest artifact from the source
9+
// if present in the status sub-resource.
10+
GetArtifact() *Artifact
11+
// GetInterval returns the interval at which the source is updated.
12+
GetInterval() metav1.Duration
13+
}

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 2 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/source.fluxcd.io_helmcharts.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ spec:
6565
type: object
6666
interval:
6767
description: The interval at which to check the Helm repository for
68-
updates. Defaults to the interval of the Helm repository.
68+
updates.
6969
type: string
7070
name:
7171
description: The name of the Helm chart, as made available by the referenced

controllers/gitrepository_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func (r *GitRepositoryReconciler) Reconcile(req ctrl.Request) (ctrl.Result, erro
8989
log.Info("Git repository sync succeeded", "msg", sourcev1.GitRepositoryReadyMessage(syncedRepo))
9090

9191
// requeue repository
92-
return ctrl.Result{RequeueAfter: repo.Spec.Interval.Duration}, nil
92+
return ctrl.Result{RequeueAfter: repo.GetInterval().Duration}, nil
9393
}
9494

9595
func (r *GitRepositoryReconciler) SetupWithManager(mgr ctrl.Manager) error {

controllers/helmchart_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func (r *HelmChartReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
104104
log.Info("Helm chart sync succeeded", "msg", sourcev1.HelmChartReadyMessage(pulledChart))
105105

106106
// requeue chart
107-
return ctrl.Result{RequeueAfter: repository.Spec.Interval.Duration}, nil
107+
return ctrl.Result{RequeueAfter: chart.GetInterval().Duration}, nil
108108
}
109109

110110
func (r *HelmChartReconciler) SetupWithManager(mgr ctrl.Manager) error {

controllers/helmrepository_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func (r *HelmRepositoryReconciler) Reconcile(req ctrl.Request) (ctrl.Result, err
9191
log.Info("Helm repository sync succeeded", "msg", sourcev1.HelmRepositoryReadyMessage(syncedRepo))
9292

9393
// requeue repository
94-
return ctrl.Result{RequeueAfter: repository.Spec.Interval.Duration}, nil
94+
return ctrl.Result{RequeueAfter: repository.GetInterval().Duration}, nil
9595
}
9696

9797
func (r *HelmRepositoryReconciler) SetupWithManager(mgr ctrl.Manager) error {

0 commit comments

Comments
 (0)