Skip to content

Commit 5fdb821

Browse files
[improvement] Remove v1beta2 conditions package (#859)
* Remove the "sigs.k8s.io/cluster-api/util/conditions/v1beta2" package * fix(?) LC controller test * lint
1 parent e435634 commit 5fdb821

25 files changed

+406
-391
lines changed

api/v1alpha2/linodecluster_types.go

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const (
2626
// ClusterFinalizer allows ReconcileLinodeCluster to clean up Linode resources associated
2727
// with LinodeCluster before removing it from the apiserver.
2828
ClusterFinalizer = "linodecluster.infrastructure.cluster.x-k8s.io"
29+
ConditionPaused = "Paused"
2930
)
3031

3132
// LinodeClusterSpec defines the desired state of LinodeCluster
@@ -121,26 +122,36 @@ type LinodeCluster struct {
121122
Status LinodeClusterStatus `json:"status,omitempty"`
122123
}
123124

124-
func (lc *LinodeCluster) GetConditions() []metav1.Condition {
125+
func (lc *LinodeCluster) SetCondition(cond metav1.Condition) {
126+
if cond.LastTransitionTime.IsZero() {
127+
cond.LastTransitionTime = metav1.Now()
128+
}
125129
for i := range lc.Status.Conditions {
126-
if lc.Status.Conditions[i].Reason == "" {
127-
lc.Status.Conditions[i].Reason = DefaultConditionReason
130+
if lc.Status.Conditions[i].Type == cond.Type {
131+
lc.Status.Conditions[i] = cond
132+
return
128133
}
129134
}
130-
return lc.Status.Conditions
135+
lc.Status.Conditions = append(lc.Status.Conditions, cond)
131136
}
132137

133-
func (lc *LinodeCluster) SetConditions(conditions []metav1.Condition) {
134-
lc.Status.Conditions = conditions
135-
}
138+
func (lc *LinodeCluster) GetCondition(condType string) *metav1.Condition {
139+
for i := range lc.Status.Conditions {
140+
if lc.Status.Conditions[i].Type == condType {
141+
return &lc.Status.Conditions[i]
142+
}
143+
}
136144

137-
// We need V1Beta2Conditions helpers to be able to use the conditions package from cluster-api
138-
func (lc *LinodeCluster) GetV1Beta2Conditions() []metav1.Condition {
139-
return lc.GetConditions()
145+
return nil
140146
}
141147

142-
func (lc *LinodeCluster) SetV1Beta2Conditions(conditions []metav1.Condition) {
143-
lc.SetConditions(conditions)
148+
func (lc *LinodeCluster) IsPaused() bool {
149+
for i := range lc.Status.Conditions {
150+
if lc.Status.Conditions[i].Type == ConditionPaused {
151+
return lc.Status.Conditions[i].Status == metav1.ConditionTrue
152+
}
153+
}
154+
return false
144155
}
145156

146157
// NetworkSpec encapsulates Linode networking resources.

api/v1alpha2/linodefirewall_types.go

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -151,26 +151,36 @@ type LinodeFirewall struct {
151151
Status LinodeFirewallStatus `json:"status,omitempty"`
152152
}
153153

154-
func (lfw *LinodeFirewall) GetConditions() []metav1.Condition {
154+
func (lfw *LinodeFirewall) SetCondition(cond metav1.Condition) {
155+
if cond.LastTransitionTime.IsZero() {
156+
cond.LastTransitionTime = metav1.Now()
157+
}
155158
for i := range lfw.Status.Conditions {
156-
if lfw.Status.Conditions[i].Reason == "" {
157-
lfw.Status.Conditions[i].Reason = DefaultConditionReason
159+
if lfw.Status.Conditions[i].Type == cond.Type {
160+
lfw.Status.Conditions[i] = cond
161+
return
158162
}
159163
}
160-
return lfw.Status.Conditions
164+
lfw.Status.Conditions = append(lfw.Status.Conditions, cond)
161165
}
162166

163-
func (lfw *LinodeFirewall) SetConditions(conditions []metav1.Condition) {
164-
lfw.Status.Conditions = conditions
165-
}
167+
func (lfw *LinodeFirewall) GetCondition(condType string) *metav1.Condition {
168+
for i := range lfw.Status.Conditions {
169+
if lfw.Status.Conditions[i].Type == condType {
170+
return &lfw.Status.Conditions[i]
171+
}
172+
}
166173

167-
// We need V1Beta2Conditions helpers to be able to use the conditions package from cluster-api
168-
func (lfw *LinodeFirewall) GetV1Beta2Conditions() []metav1.Condition {
169-
return lfw.GetConditions()
174+
return nil
170175
}
171176

172-
func (lfw *LinodeFirewall) SetV1Beta2Conditions(conditions []metav1.Condition) {
173-
lfw.SetConditions(conditions)
177+
func (lfw *LinodeFirewall) IsPaused() bool {
178+
for i := range lfw.Status.Conditions {
179+
if lfw.Status.Conditions[i].Type == ConditionPaused {
180+
return lfw.Status.Conditions[i].Status == metav1.ConditionTrue
181+
}
182+
}
183+
return false
174184
}
175185

176186
// +kubebuilder:object:root=true

api/v1alpha2/linodemachine_types.go

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -576,25 +576,45 @@ type LinodeMachine struct {
576576
Status LinodeMachineStatus `json:"status,omitempty"`
577577
}
578578

579-
func (lm *LinodeMachine) GetConditions() []metav1.Condition {
579+
func (lm *LinodeMachine) SetCondition(cond metav1.Condition) {
580+
if cond.LastTransitionTime.IsZero() {
581+
cond.LastTransitionTime = metav1.Now()
582+
}
580583
for i := range lm.Status.Conditions {
581-
if lm.Status.Conditions[i].Reason == "" {
582-
lm.Status.Conditions[i].Reason = DefaultConditionReason
584+
if lm.Status.Conditions[i].Type == cond.Type {
585+
lm.Status.Conditions[i] = cond
586+
587+
return
583588
}
584589
}
585-
return lm.Status.Conditions
590+
lm.Status.Conditions = append(lm.Status.Conditions, cond)
586591
}
587592

588-
func (lm *LinodeMachine) SetConditions(conditions []metav1.Condition) {
589-
lm.Status.Conditions = conditions
593+
func (lm *LinodeMachine) GetCondition(condType string) *metav1.Condition {
594+
for i := range lm.Status.Conditions {
595+
if lm.Status.Conditions[i].Type == condType {
596+
return &lm.Status.Conditions[i]
597+
}
598+
}
599+
600+
return nil
590601
}
591602

592-
func (lm *LinodeMachine) GetV1Beta2Conditions() []metav1.Condition {
593-
return lm.GetConditions()
603+
func (lm *LinodeMachine) DeleteCondition(condType string) {
604+
for i := range lm.Status.Conditions {
605+
if lm.Status.Conditions[i].Type == condType {
606+
lm.Status.Conditions = append(lm.Status.Conditions[:i], lm.Status.Conditions[i+1:]...)
607+
}
608+
}
594609
}
595610

596-
func (lm *LinodeMachine) SetV1Beta2Conditions(conditions []metav1.Condition) {
597-
lm.SetConditions(conditions)
611+
func (lm *LinodeMachine) IsPaused() bool {
612+
for i := range lm.Status.Conditions {
613+
if lm.Status.Conditions[i].Type == ConditionPaused {
614+
return lm.Status.Conditions[i].Status == metav1.ConditionTrue
615+
}
616+
}
617+
return false
598618
}
599619

600620
// +kubebuilder:object:root=true

api/v1alpha2/linodemachinetemplate_types.go

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -76,25 +76,18 @@ type LinodeMachineTemplate struct {
7676
Status LinodeMachineTemplateStatus `json:"status,omitempty"`
7777
}
7878

79-
func (lmt *LinodeMachineTemplate) GetConditions() []metav1.Condition {
79+
func (lmt *LinodeMachineTemplate) SetCondition(cond metav1.Condition) {
80+
if cond.LastTransitionTime.IsZero() {
81+
cond.LastTransitionTime = metav1.Now()
82+
}
8083
for i := range lmt.Status.Conditions {
81-
if lmt.Status.Conditions[i].Reason == "" {
82-
lmt.Status.Conditions[i].Reason = DefaultConditionReason
84+
if lmt.Status.Conditions[i].Type == cond.Type {
85+
lmt.Status.Conditions[i] = cond
86+
87+
return
8388
}
8489
}
85-
return lmt.Status.Conditions
86-
}
87-
88-
func (lmt *LinodeMachineTemplate) SetConditions(conditions []metav1.Condition) {
89-
lmt.Status.Conditions = conditions
90-
}
91-
92-
func (lmt *LinodeMachineTemplate) GetV1Beta2Conditions() []metav1.Condition {
93-
return lmt.GetConditions()
94-
}
95-
96-
func (lmt *LinodeMachineTemplate) SetV1Beta2Conditions(conditions []metav1.Condition) {
97-
lmt.SetConditions(conditions)
90+
lmt.Status.Conditions = append(lmt.Status.Conditions, cond)
9891
}
9992

10093
// +kubebuilder:object:root=true

api/v1alpha2/linodeobjectstoragebucket_types.go

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -122,25 +122,28 @@ type LinodeObjectStorageBucket struct {
122122
Status LinodeObjectStorageBucketStatus `json:"status,omitempty"`
123123
}
124124

125-
func (losb *LinodeObjectStorageBucket) GetConditions() []metav1.Condition {
126-
for i := range losb.Status.Conditions {
127-
if losb.Status.Conditions[i].Reason == "" {
128-
losb.Status.Conditions[i].Reason = DefaultConditionReason
129-
}
125+
func (lobj *LinodeObjectStorageBucket) SetCondition(cond metav1.Condition) {
126+
if cond.LastTransitionTime.IsZero() {
127+
cond.LastTransitionTime = metav1.Now()
130128
}
131-
return losb.Status.Conditions
132-
}
129+
for i := range lobj.Status.Conditions {
130+
if lobj.Status.Conditions[i].Type == cond.Type {
131+
lobj.Status.Conditions[i] = cond
133132

134-
func (losb *LinodeObjectStorageBucket) SetConditions(conditions []metav1.Condition) {
135-
losb.Status.Conditions = conditions
133+
return
134+
}
135+
}
136+
lobj.Status.Conditions = append(lobj.Status.Conditions, cond)
136137
}
137138

138-
func (losb *LinodeObjectStorageBucket) GetV1Beta2Conditions() []metav1.Condition {
139-
return losb.GetConditions()
140-
}
139+
func (lobj *LinodeObjectStorageBucket) GetCondition(condType string) *metav1.Condition {
140+
for i := range lobj.Status.Conditions {
141+
if lobj.Status.Conditions[i].Type == condType {
142+
return &lobj.Status.Conditions[i]
143+
}
144+
}
141145

142-
func (losb *LinodeObjectStorageBucket) SetV1Beta2Conditions(conditions []metav1.Condition) {
143-
losb.SetConditions(conditions)
146+
return nil
144147
}
145148

146149
// +kubebuilder:object:root=true

api/v1alpha2/linodeobjectstoragekey_types.go

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -158,25 +158,28 @@ type LinodeObjectStorageKey struct {
158158
Status LinodeObjectStorageKeyStatus `json:"status,omitempty"`
159159
}
160160

161-
func (losk *LinodeObjectStorageKey) GetConditions() []metav1.Condition {
162-
for i := range losk.Status.Conditions {
163-
if losk.Status.Conditions[i].Reason == "" {
164-
losk.Status.Conditions[i].Reason = DefaultConditionReason
165-
}
161+
func (key *LinodeObjectStorageKey) SetCondition(cond metav1.Condition) {
162+
if cond.LastTransitionTime.IsZero() {
163+
cond.LastTransitionTime = metav1.Now()
166164
}
167-
return losk.Status.Conditions
168-
}
165+
for i := range key.Status.Conditions {
166+
if key.Status.Conditions[i].Type == cond.Type {
167+
key.Status.Conditions[i] = cond
169168

170-
func (losk *LinodeObjectStorageKey) SetConditions(conditions []metav1.Condition) {
171-
losk.Status.Conditions = conditions
169+
return
170+
}
171+
}
172+
key.Status.Conditions = append(key.Status.Conditions, cond)
172173
}
173174

174-
func (losk *LinodeObjectStorageKey) GetV1Beta2Conditions() []metav1.Condition {
175-
return losk.GetConditions()
176-
}
175+
func (key *LinodeObjectStorageKey) GetCondition(condType string) *metav1.Condition {
176+
for i := range key.Status.Conditions {
177+
if key.Status.Conditions[i].Type == condType {
178+
return &key.Status.Conditions[i]
179+
}
180+
}
177181

178-
func (losk *LinodeObjectStorageKey) SetV1Beta2Conditions(conditions []metav1.Condition) {
179-
losk.SetConditions(conditions)
182+
return nil
180183
}
181184

182185
// LinodeObjectStorageKeyList contains a list of LinodeObjectStorageKey

api/v1alpha2/linodeplacementgroup_types.go

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -134,25 +134,37 @@ type LinodePlacementGroup struct {
134134
Status LinodePlacementGroupStatus `json:"status,omitempty"`
135135
}
136136

137-
func (lpg *LinodePlacementGroup) GetConditions() []metav1.Condition {
137+
func (lpg *LinodePlacementGroup) SetCondition(cond metav1.Condition) {
138+
if cond.LastTransitionTime.IsZero() {
139+
cond.LastTransitionTime = metav1.Now()
140+
}
138141
for i := range lpg.Status.Conditions {
139-
if lpg.Status.Conditions[i].Reason == "" {
140-
lpg.Status.Conditions[i].Reason = DefaultConditionReason
142+
if lpg.Status.Conditions[i].Type == cond.Type {
143+
lpg.Status.Conditions[i] = cond
144+
145+
return
141146
}
142147
}
143-
return lpg.Status.Conditions
148+
lpg.Status.Conditions = append(lpg.Status.Conditions, cond)
144149
}
145150

146-
func (lpg *LinodePlacementGroup) SetConditions(conditions []metav1.Condition) {
147-
lpg.Status.Conditions = conditions
148-
}
151+
func (lpg *LinodePlacementGroup) GetCondition(condType string) *metav1.Condition {
152+
for i := range lpg.Status.Conditions {
153+
if lpg.Status.Conditions[i].Type == condType {
154+
return &lpg.Status.Conditions[i]
155+
}
156+
}
149157

150-
func (lpg *LinodePlacementGroup) GetV1Beta2Conditions() []metav1.Condition {
151-
return lpg.GetConditions()
158+
return nil
152159
}
153160

154-
func (lpg *LinodePlacementGroup) SetV1Beta2Conditions(conditions []metav1.Condition) {
155-
lpg.SetConditions(conditions)
161+
func (lpg *LinodePlacementGroup) IsPaused() bool {
162+
for i := range lpg.Status.Conditions {
163+
if lpg.Status.Conditions[i].Type == ConditionPaused {
164+
return lpg.Status.Conditions[i].Status == metav1.ConditionTrue
165+
}
166+
}
167+
return false
156168
}
157169

158170
// +kubebuilder:object:root=true

api/v1alpha2/linodevpc_types.go

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -209,25 +209,37 @@ type LinodeVPC struct {
209209
Status LinodeVPCStatus `json:"status,omitempty"`
210210
}
211211

212-
func (lv *LinodeVPC) GetConditions() []metav1.Condition {
212+
func (lv *LinodeVPC) SetCondition(cond metav1.Condition) {
213+
if cond.LastTransitionTime.IsZero() {
214+
cond.LastTransitionTime = metav1.Now()
215+
}
213216
for i := range lv.Status.Conditions {
214-
if lv.Status.Conditions[i].Reason == "" {
215-
lv.Status.Conditions[i].Reason = DefaultConditionReason
217+
if lv.Status.Conditions[i].Type == cond.Type {
218+
lv.Status.Conditions[i] = cond
219+
220+
return
216221
}
217222
}
218-
return lv.Status.Conditions
223+
lv.Status.Conditions = append(lv.Status.Conditions, cond)
219224
}
220225

221-
func (lv *LinodeVPC) SetConditions(conditions []metav1.Condition) {
222-
lv.Status.Conditions = conditions
223-
}
226+
func (lv *LinodeVPC) GetCondition(condType string) *metav1.Condition {
227+
for i := range lv.Status.Conditions {
228+
if lv.Status.Conditions[i].Type == condType {
229+
return &lv.Status.Conditions[i]
230+
}
231+
}
224232

225-
func (lv *LinodeVPC) GetV1Beta2Conditions() []metav1.Condition {
226-
return lv.GetConditions()
233+
return nil
227234
}
228235

229-
func (lv *LinodeVPC) SetV1Beta2Conditions(conditions []metav1.Condition) {
230-
lv.SetConditions(conditions)
236+
func (lv *LinodeVPC) IsPaused() bool {
237+
for i := range lv.Status.Conditions {
238+
if lv.Status.Conditions[i].Type == ConditionPaused {
239+
return lv.Status.Conditions[i].Status == metav1.ConditionTrue
240+
}
241+
}
242+
return false
231243
}
232244

233245
// +kubebuilder:object:root=true

0 commit comments

Comments
 (0)