Skip to content

Commit 00bb853

Browse files
committed
Refactor to adopt k8s standardized Condition type
Updates to use metav1.Condition type and removes references for deprecated corev1.Condition* constants and uses the new k8s api/meta helpers in place of the old pkg/apis/meta types. Signed-off-by: Aurel Canciu <[email protected]>
1 parent 35c6fd7 commit 00bb853

21 files changed

+319
-152
lines changed

api/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/fluxcd/source-controller/api
33
go 1.15
44

55
require (
6-
github.com/fluxcd/pkg/apis/meta v0.2.0
6+
github.com/fluxcd/pkg/apis/meta v0.3.0
77
k8s.io/api v0.19.3
88
k8s.io/apimachinery v0.19.3
99
sigs.k8s.io/controller-runtime v0.6.3

api/go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ github.com/evanphx/json-patch v4.9.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLi
6363
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
6464
github.com/fluxcd/pkg/apis/meta v0.2.0 h1:bxoFQtZM6OLLj0+n3h6ga7IEWUtGEDJPc65OWiXSMvY=
6565
github.com/fluxcd/pkg/apis/meta v0.2.0/go.mod h1:50RLLSfqM4LlQrh/+5LiJVf7Hjdthee8WDdXBvpjBdA=
66+
github.com/fluxcd/pkg/apis/meta v0.3.0 h1:o2YkfGgf0j8sKeZs8cBmmmMKLA7kEoS1qYViOial1Ds=
67+
github.com/fluxcd/pkg/apis/meta v0.3.0/go.mod h1:wOzQQx8CdtUQCGaLzqGu4QgnNxYkI6/wvdvlovxWhF0=
6668
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
6769
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
6870
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=

api/v1beta1/bucket_types.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package v1beta1
1919
import (
2020
"github.com/fluxcd/pkg/apis/meta"
2121
corev1 "k8s.io/api/core/v1"
22+
apimeta "k8s.io/apimachinery/pkg/api/meta"
2223
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2324
)
2425

@@ -85,7 +86,7 @@ type BucketStatus struct {
8586

8687
// Conditions holds the conditions for the Bucket.
8788
// +optional
88-
Conditions []meta.Condition `json:"conditions,omitempty"`
89+
Conditions []metav1.Condition `json:"conditions,omitempty"`
8990

9091
// URL is the download link for the artifact output of the last Bucket sync.
9192
// +optional
@@ -106,22 +107,22 @@ const (
106107
BucketOperationFailedReason string = "BucketOperationFailed"
107108
)
108109

109-
// BucketProgressing resets the conditions of the Bucket to meta.Condition of
110+
// BucketProgressing resets the conditions of the Bucket to metav1.Condition of
110111
// type meta.ReadyCondition with status 'Unknown' and meta.ProgressingReason
111112
// reason and message. It returns the modified Bucket.
112113
func BucketProgressing(bucket Bucket) Bucket {
113114
bucket.Status.ObservedGeneration = bucket.Generation
114115
bucket.Status.URL = ""
115-
bucket.Status.Conditions = []meta.Condition{}
116-
SetBucketCondition(&bucket, meta.ReadyCondition, corev1.ConditionUnknown, meta.ProgressingReason, "reconciliation in progress")
116+
bucket.Status.Conditions = []metav1.Condition{}
117+
SetBucketCondition(&bucket, meta.ReadyCondition, metav1.ConditionUnknown, meta.ProgressingReason, "reconciliation in progress")
117118
return bucket
118119
}
119120

120121
// SetBucketCondition sets the given condition with the given status, reason and
121122
// message on the Bucket.
122-
func SetBucketCondition(bucket *Bucket, conditionType string, status corev1.ConditionStatus, reason, message string) {
123+
func SetBucketCondition(bucket *Bucket, conditionType string, status metav1.ConditionStatus, reason, message string) {
123124
bucket.Status.Conditions = meta.FilterOutCondition(bucket.Status.Conditions, conditionType)
124-
bucket.Status.Conditions = append(bucket.Status.Conditions, meta.Condition{
125+
bucket.Status.Conditions = append(bucket.Status.Conditions, metav1.Condition{
125126
Type: conditionType,
126127
Status: status,
127128
LastTransitionTime: metav1.Now(),
@@ -136,22 +137,22 @@ func SetBucketCondition(bucket *Bucket, conditionType string, status corev1.Cond
136137
func BucketReady(bucket Bucket, artifact Artifact, url, reason, message string) Bucket {
137138
bucket.Status.Artifact = &artifact
138139
bucket.Status.URL = url
139-
SetBucketCondition(&bucket, meta.ReadyCondition, corev1.ConditionTrue, reason, message)
140+
SetBucketCondition(&bucket, meta.ReadyCondition, metav1.ConditionTrue, reason, message)
140141
return bucket
141142
}
142143

143144
// BucketNotReady sets the meta.ReadyCondition on the Bucket to 'False', with
144145
// the given reason and message. It returns the modified Bucket.
145146
func BucketNotReady(bucket Bucket, reason, message string) Bucket {
146-
SetBucketCondition(&bucket, meta.ReadyCondition, corev1.ConditionFalse, reason, message)
147+
SetBucketCondition(&bucket, meta.ReadyCondition, metav1.ConditionFalse, reason, message)
147148
return bucket
148149
}
149150

150-
// BucketReadyMessage returns the message of the meta.Condition of type
151+
// BucketReadyMessage returns the message of the metav1.Condition of type
151152
// meta.ReadyCondition with status 'True' if present, or an empty string.
152153
func BucketReadyMessage(bucket Bucket) string {
153-
if c := meta.GetCondition(bucket.Status.Conditions, meta.ReadyCondition); c != nil {
154-
if c.Status == corev1.ConditionTrue {
154+
if c := apimeta.FindStatusCondition(bucket.Status.Conditions, meta.ReadyCondition); c != nil {
155+
if c.Status == metav1.ConditionTrue {
155156
return c.Message
156157
}
157158
}

api/v1beta1/gitrepository_types.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package v1beta1
1919
import (
2020
"github.com/fluxcd/pkg/apis/meta"
2121
corev1 "k8s.io/api/core/v1"
22+
apimeta "k8s.io/apimachinery/pkg/api/meta"
2223
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2324
)
2425

@@ -105,7 +106,7 @@ type GitRepositoryStatus struct {
105106

106107
// Conditions holds the conditions for the GitRepository.
107108
// +optional
108-
Conditions []meta.Condition `json:"conditions,omitempty"`
109+
Conditions []metav1.Condition `json:"conditions,omitempty"`
109110

110111
// URL is the download link for the artifact output of the last repository
111112
// sync.
@@ -128,22 +129,22 @@ const (
128129
)
129130

130131
// GitRepositoryProgressing resets the conditions of the GitRepository to
131-
// meta.Condition of type meta.ReadyCondition with status 'Unknown' and
132+
// metav1.Condition of type meta.ReadyCondition with status 'Unknown' and
132133
// meta.ProgressingReason reason and message. It returns the modified
133134
// GitRepository.
134135
func GitRepositoryProgressing(repository GitRepository) GitRepository {
135136
repository.Status.ObservedGeneration = repository.Generation
136137
repository.Status.URL = ""
137-
repository.Status.Conditions = []meta.Condition{}
138-
SetGitRepositoryCondition(&repository, meta.ReadyCondition, corev1.ConditionUnknown, meta.ProgressingReason, "reconciliation in progress")
138+
repository.Status.Conditions = []metav1.Condition{}
139+
SetGitRepositoryCondition(&repository, meta.ReadyCondition, metav1.ConditionUnknown, meta.ProgressingReason, "reconciliation in progress")
139140
return repository
140141
}
141142

142143
// SetGitRepositoryCondition sets the given condition with the given status,
143144
// reason and message on the GitRepository.
144-
func SetGitRepositoryCondition(repository *GitRepository, condition string, status corev1.ConditionStatus, reason, message string) {
145+
func SetGitRepositoryCondition(repository *GitRepository, condition string, status metav1.ConditionStatus, reason, message string) {
145146
repository.Status.Conditions = meta.FilterOutCondition(repository.Status.Conditions, condition)
146-
repository.Status.Conditions = append(repository.Status.Conditions, meta.Condition{
147+
repository.Status.Conditions = append(repository.Status.Conditions, metav1.Condition{
147148
Type: condition,
148149
Status: status,
149150
LastTransitionTime: metav1.Now(),
@@ -158,23 +159,23 @@ func SetGitRepositoryCondition(repository *GitRepository, condition string, stat
158159
func GitRepositoryReady(repository GitRepository, artifact Artifact, url, reason, message string) GitRepository {
159160
repository.Status.Artifact = &artifact
160161
repository.Status.URL = url
161-
SetGitRepositoryCondition(&repository, meta.ReadyCondition, corev1.ConditionTrue, reason, message)
162+
SetGitRepositoryCondition(&repository, meta.ReadyCondition, metav1.ConditionTrue, reason, message)
162163
return repository
163164
}
164165

165166
// GitRepositoryNotReady sets the meta.ReadyCondition on the given GitRepository
166167
// to 'False', with the given reason and message. It returns the modified
167168
// GitRepository.
168169
func GitRepositoryNotReady(repository GitRepository, reason, message string) GitRepository {
169-
SetGitRepositoryCondition(&repository, meta.ReadyCondition, corev1.ConditionFalse, reason, message)
170+
SetGitRepositoryCondition(&repository, meta.ReadyCondition, metav1.ConditionFalse, reason, message)
170171
return repository
171172
}
172173

173-
// GitRepositoryReadyMessage returns the message of the meta.Condition of type
174+
// GitRepositoryReadyMessage returns the message of the metav1.Condition of type
174175
// meta.ReadyCondition with status 'True' if present, or an empty string.
175176
func GitRepositoryReadyMessage(repository GitRepository) string {
176-
if c := meta.GetCondition(repository.Status.Conditions, meta.ReadyCondition); c != nil {
177-
if c.Status == corev1.ConditionTrue {
177+
if c := apimeta.FindStatusCondition(repository.Status.Conditions, meta.ReadyCondition); c != nil {
178+
if c.Status == metav1.ConditionTrue {
178179
return c.Message
179180
}
180181
}

api/v1beta1/helmchart_types.go

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

1919
import (
2020
"github.com/fluxcd/pkg/apis/meta"
21-
corev1 "k8s.io/api/core/v1"
21+
apimeta "k8s.io/apimachinery/pkg/api/meta"
2222
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2323
)
2424

@@ -77,7 +77,7 @@ type HelmChartStatus struct {
7777

7878
// Conditions holds the conditions for the HelmChart.
7979
// +optional
80-
Conditions []meta.Condition `json:"conditions,omitempty"`
80+
Conditions []metav1.Condition `json:"conditions,omitempty"`
8181

8282
// URL is the download link for the last chart pulled.
8383
// +optional
@@ -112,16 +112,16 @@ const (
112112
func HelmChartProgressing(chart HelmChart) HelmChart {
113113
chart.Status.ObservedGeneration = chart.Generation
114114
chart.Status.URL = ""
115-
chart.Status.Conditions = []meta.Condition{}
116-
SetHelmChartCondition(&chart, meta.ReadyCondition, corev1.ConditionUnknown, meta.ProgressingReason, "reconciliation in progress")
115+
chart.Status.Conditions = []metav1.Condition{}
116+
SetHelmChartCondition(&chart, meta.ReadyCondition, metav1.ConditionUnknown, meta.ProgressingReason, "reconciliation in progress")
117117
return chart
118118
}
119119

120120
// SetHelmChartCondition sets the given condition with the given status, reason
121121
// and message on the HelmChart.
122-
func SetHelmChartCondition(chart *HelmChart, condition string, status corev1.ConditionStatus, reason, message string) {
122+
func SetHelmChartCondition(chart *HelmChart, condition string, status metav1.ConditionStatus, reason, message string) {
123123
chart.Status.Conditions = meta.FilterOutCondition(chart.Status.Conditions, condition)
124-
chart.Status.Conditions = append(chart.Status.Conditions, meta.Condition{
124+
chart.Status.Conditions = append(chart.Status.Conditions, metav1.Condition{
125125
Type: condition,
126126
Status: status,
127127
LastTransitionTime: metav1.Now(),
@@ -136,23 +136,23 @@ func SetHelmChartCondition(chart *HelmChart, condition string, status corev1.Con
136136
func HelmChartReady(chart HelmChart, artifact Artifact, url, reason, message string) HelmChart {
137137
chart.Status.Artifact = &artifact
138138
chart.Status.URL = url
139-
SetHelmChartCondition(&chart, meta.ReadyCondition, corev1.ConditionTrue, reason, message)
139+
SetHelmChartCondition(&chart, meta.ReadyCondition, metav1.ConditionTrue, reason, message)
140140
return chart
141141
}
142142

143143
// HelmChartNotReady sets the meta.ReadyCondition on the given HelmChart to
144144
// 'False', with the given reason and message. It returns the modified
145145
// HelmChart.
146146
func HelmChartNotReady(chart HelmChart, reason, message string) HelmChart {
147-
SetHelmChartCondition(&chart, meta.ReadyCondition, corev1.ConditionFalse, reason, message)
147+
SetHelmChartCondition(&chart, meta.ReadyCondition, metav1.ConditionFalse, reason, message)
148148
return chart
149149
}
150150

151151
// HelmChartReadyMessage returns the message of the meta.ReadyCondition with
152152
// status 'True', or an empty string.
153153
func HelmChartReadyMessage(chart HelmChart) string {
154-
if c := meta.GetCondition(chart.Status.Conditions, meta.ReadyCondition); c != nil {
155-
if c.Status == corev1.ConditionTrue {
154+
if c := apimeta.FindStatusCondition(chart.Status.Conditions, meta.ReadyCondition); c != nil {
155+
if c.Status == metav1.ConditionTrue {
156156
return c.Message
157157
}
158158
}

api/v1beta1/helmrepository_types.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package v1beta1
1919
import (
2020
"github.com/fluxcd/pkg/apis/meta"
2121
corev1 "k8s.io/api/core/v1"
22+
apimeta "k8s.io/apimachinery/pkg/api/meta"
2223
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2324
)
2425

@@ -63,7 +64,7 @@ type HelmRepositoryStatus struct {
6364

6465
// Conditions holds the conditions for the HelmRepository.
6566
// +optional
66-
Conditions []meta.Condition `json:"conditions,omitempty"`
67+
Conditions []metav1.Condition `json:"conditions,omitempty"`
6768

6869
// URL is the download link for the last index fetched.
6970
// +optional
@@ -85,22 +86,22 @@ const (
8586
)
8687

8788
// HelmRepositoryProgressing resets the conditions of the HelmRepository to
88-
// meta.Condition of type meta.ReadyCondition with status 'Unknown' and
89+
// metav1.Condition of type meta.ReadyCondition with status 'Unknown' and
8990
// meta.ProgressingReason reason and message. It returns the modified
9091
// HelmRepository.
9192
func HelmRepositoryProgressing(repository HelmRepository) HelmRepository {
9293
repository.Status.ObservedGeneration = repository.Generation
9394
repository.Status.URL = ""
94-
repository.Status.Conditions = []meta.Condition{}
95-
SetHelmRepositoryCondition(&repository, meta.ReadyCondition, corev1.ConditionUnknown, meta.ProgressingReason, "reconciliation in progress")
95+
repository.Status.Conditions = []metav1.Condition{}
96+
SetHelmRepositoryCondition(&repository, meta.ReadyCondition, metav1.ConditionUnknown, meta.ProgressingReason, "reconciliation in progress")
9697
return repository
9798
}
9899

99100
// SetHelmRepositoryCondition sets the given condition with the given status,
100101
// reason and message on the HelmRepository.
101-
func SetHelmRepositoryCondition(repository *HelmRepository, condition string, status corev1.ConditionStatus, reason, message string) {
102+
func SetHelmRepositoryCondition(repository *HelmRepository, condition string, status metav1.ConditionStatus, reason, message string) {
102103
repository.Status.Conditions = meta.FilterOutCondition(repository.Status.Conditions, condition)
103-
repository.Status.Conditions = append(repository.Status.Conditions, meta.Condition{
104+
repository.Status.Conditions = append(repository.Status.Conditions, metav1.Condition{
104105
Type: condition,
105106
Status: status,
106107
LastTransitionTime: metav1.Now(),
@@ -115,23 +116,23 @@ func SetHelmRepositoryCondition(repository *HelmRepository, condition string, st
115116
func HelmRepositoryReady(repository HelmRepository, artifact Artifact, url, reason, message string) HelmRepository {
116117
repository.Status.Artifact = &artifact
117118
repository.Status.URL = url
118-
SetHelmRepositoryCondition(&repository, meta.ReadyCondition, corev1.ConditionTrue, reason, message)
119+
SetHelmRepositoryCondition(&repository, meta.ReadyCondition, metav1.ConditionTrue, reason, message)
119120
return repository
120121
}
121122

122123
// HelmRepositoryNotReady sets the meta.ReadyCondition on the given
123124
// HelmRepository to 'False', with the given reason and message. It returns the
124125
// modified HelmRepository.
125126
func HelmRepositoryNotReady(repository HelmRepository, reason, message string) HelmRepository {
126-
SetHelmRepositoryCondition(&repository, meta.ReadyCondition, corev1.ConditionFalse, reason, message)
127+
SetHelmRepositoryCondition(&repository, meta.ReadyCondition, metav1.ConditionFalse, reason, message)
127128
return repository
128129
}
129130

130-
// HelmRepositoryReadyMessage returns the message of the meta.Condition of type
131+
// HelmRepositoryReadyMessage returns the message of the metav1.Condition of type
131132
// meta.ReadyCondition with status 'True' if present, or an empty string.
132133
func HelmRepositoryReadyMessage(repository HelmRepository) string {
133-
if c := meta.GetCondition(repository.Status.Conditions, meta.ReadyCondition); c != nil {
134-
if c.Status == corev1.ConditionTrue {
134+
if c := apimeta.FindStatusCondition(repository.Status.Conditions, meta.ReadyCondition); c != nil {
135+
if c.Status == metav1.ConditionTrue {
135136
return c.Message
136137
}
137138
}

api/v1beta1/zz_generated.deepcopy.go

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

0 commit comments

Comments
 (0)