Skip to content

Commit 28d93d0

Browse files
committed
WIP: Refactor HelmChartReconciler
Signed-off-by: Hidde Beydals <hello@hidde.co>
1 parent 77f314c commit 28d93d0

13 files changed

+874
-738
lines changed

api/v1beta1/condition_types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ const (
2424
SourceVerifiedCondition string = "SourceVerified"
2525

2626
ArtifactAvailableCondition string = "ArtifactAvailable"
27+
28+
SourceRefReadyCondition string = "SourceRefReady"
2729
)
2830

2931
const (

api/v1beta1/helmchart_types.go

Lines changed: 15 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,19 @@ package v1beta1
1818

1919
import (
2020
"github.com/fluxcd/pkg/apis/meta"
21-
apimeta "k8s.io/apimachinery/pkg/api/meta"
2221
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2322
)
2423

2524
// HelmChartKind is the string representation of a HelmChart.
2625
const HelmChartKind = "HelmChart"
2726

27+
const (
28+
DependenciesBuildCondition string = "DependenciesBuild"
29+
ValuesFilesMergedCondition string = "ValuesFilesMerged"
30+
ChartPackagedCondition string = "ChartPackaged"
31+
ChartReconciled string = "ChartReconciled"
32+
)
33+
2834
// HelmChartSpec defines the desired state of a Helm chart.
2935
type HelmChartSpec struct {
3036
// The name or path the Helm chart is available at in the SourceRef.
@@ -122,52 +128,20 @@ const (
122128
ChartPackageSucceededReason string = "ChartPackageSucceeded"
123129
)
124130

125-
// HelmChartProgressing resets the conditions of the HelmChart to meta.Condition
126-
// of type meta.ReadyCondition with status 'Unknown' and meta.ProgressingReason
127-
// reason and message. It returns the modified HelmChart.
128-
func HelmChartProgressing(chart HelmChart) HelmChart {
129-
chart.Status.ObservedGeneration = chart.Generation
130-
chart.Status.URL = ""
131-
chart.Status.Conditions = []metav1.Condition{}
132-
meta.SetResourceCondition(&chart, meta.ReadyCondition, metav1.ConditionUnknown, meta.ProgressingReason, "reconciliation in progress")
133-
return chart
134-
}
135-
136-
// HelmChartReady sets the given Artifact and URL on the HelmChart and sets the
137-
// meta.ReadyCondition to 'True', with the given reason and message. It returns
138-
// the modified HelmChart.
139-
func HelmChartReady(chart HelmChart, artifact Artifact, url, reason, message string) HelmChart {
140-
chart.Status.Artifact = &artifact
141-
chart.Status.URL = url
142-
meta.SetResourceCondition(&chart, meta.ReadyCondition, metav1.ConditionTrue, reason, message)
143-
return chart
144-
}
145-
146-
// HelmChartNotReady sets the meta.ReadyCondition on the given HelmChart to
147-
// 'False', with the given reason and message. It returns the modified
148-
// HelmChart.
149-
func HelmChartNotReady(chart HelmChart, reason, message string) HelmChart {
150-
meta.SetResourceCondition(&chart, meta.ReadyCondition, metav1.ConditionFalse, reason, message)
151-
return chart
152-
}
153-
154-
// HelmChartReadyMessage returns the message of the meta.ReadyCondition with
155-
// status 'True', or an empty string.
156-
func HelmChartReadyMessage(chart HelmChart) string {
157-
if c := apimeta.FindStatusCondition(chart.Status.Conditions, meta.ReadyCondition); c != nil {
158-
if c.Status == metav1.ConditionTrue {
159-
return c.Message
160-
}
161-
}
162-
return ""
163-
}
164-
165131
// GetArtifact returns the latest artifact from the source if present in the
166132
// status sub-resource.
167133
func (in *HelmChart) GetArtifact() *Artifact {
168134
return in.Status.Artifact
169135
}
170136

137+
func (in HelmChart) GetConditions() []metav1.Condition {
138+
return in.Status.Conditions
139+
}
140+
141+
func (in *HelmChart) SetConditions(conditions []metav1.Condition) {
142+
in.Status.Conditions = conditions
143+
}
144+
171145
// GetStatusConditions returns a pointer to the Status.Conditions slice
172146
func (in *HelmChart) GetStatusConditions() *[]metav1.Condition {
173147
return &in.Status.Conditions

api/v1beta1/source.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package v1beta1
1818

1919
import (
2020
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21+
"k8s.io/apimachinery/pkg/runtime"
2122
)
2223

2324
const (
@@ -29,9 +30,15 @@ const (
2930
// Source interface must be supported by all API types.
3031
// +k8s:deepcopy-gen=false
3132
type Source interface {
33+
metav1.Object
34+
runtime.Object
35+
3236
// GetArtifact returns the latest artifact from the source if present in the
3337
// status sub-resource.
3438
GetArtifact() *Artifact
39+
// GetConditions returns the conditions of the source if present in the
40+
// status sub-resource.
41+
GetConditions() []metav1.Condition
3542
// GetInterval returns the interval at which the source is updated.
3643
GetInterval() metav1.Duration
3744
}

api/v1beta1/zz_generated.deepcopy.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

controllers/bucket_controller_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ import (
4141

4242
const (
4343
bucketInterval = 1 * time.Second
44-
bucketTimeout = 30 * time.Second
44+
bucketTimeout = 30 * time.Second
4545
)
4646

4747
func TestBucketReconciler_Reconcile(t *testing.T) {

0 commit comments

Comments
 (0)