Skip to content

Commit 5409d78

Browse files
authored
chore(controllers): simplify tests around conditions (#2136)
* feat(controllers): add helper for conditions equality * chore(controllers): simplify tests for folder controller * chore(controllers): simplify notification template tests * chore(controllers): simplify contactpoint tests * chore(controllers): simplify alertrulegroup tests * chore(controllers): simplify dashboard tests * chore(controllers): simplify some datasource tests * chore(controllers): simplify datasource tests * chore(controllers): simplify grafana tests * chore(controllers): simplify library panel tests * chore(controllers): simplify mute timing * chore(controllers): simplify notification policy tests * chore(controllers): simplify LoopDetected test * feat(CommonResource): expose Metadata * feat(controllers): add GrafanaCommonReconciler interface * feat(controllers): add reconcileAndValidateCondition helper * chore(controllers): switch to reconcileAndValidateCondition * fix(lint): formatting
1 parent 60b98bb commit 5409d78

22 files changed

+699
-718
lines changed

api/v1beta1/common.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ type CommonResource interface {
5454
client.Object
5555
MatchLabels() *metav1.LabelSelector
5656
MatchNamespace() string
57+
Metadata() metav1.ObjectMeta
5758
AllowCrossNamespace() bool
5859
CommonStatus() *GrafanaCommonStatus
5960
}

api/v1beta1/grafanaalertrulegroup_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,10 @@ func (in *GrafanaAlertRuleGroup) MatchNamespace() string {
202202
return in.Namespace
203203
}
204204

205+
func (in *GrafanaAlertRuleGroup) Metadata() metav1.ObjectMeta {
206+
return in.ObjectMeta
207+
}
208+
205209
func (in *GrafanaAlertRuleGroup) AllowCrossNamespace() bool {
206210
return in.Spec.AllowCrossNamespaceImport
207211
}

api/v1beta1/grafanacontactpoint_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ func (in *GrafanaContactPoint) MatchNamespace() string {
104104
return in.Namespace
105105
}
106106

107+
func (in *GrafanaContactPoint) Metadata() metav1.ObjectMeta {
108+
return in.ObjectMeta
109+
}
110+
107111
func (in *GrafanaContactPoint) AllowCrossNamespace() bool {
108112
return in.Spec.AllowCrossNamespaceImport
109113
}

api/v1beta1/grafanadashboard_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,10 @@ func (in *GrafanaDashboard) MatchNamespace() string {
139139
return in.Namespace
140140
}
141141

142+
func (in *GrafanaDashboard) Metadata() metav1.ObjectMeta {
143+
return in.ObjectMeta
144+
}
145+
142146
func (in *GrafanaDashboard) AllowCrossNamespace() bool {
143147
return in.Spec.AllowCrossNamespaceImport
144148
}

api/v1beta1/grafanadatasource_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,10 @@ func (in *GrafanaDatasource) MatchNamespace() string {
164164
return in.Namespace
165165
}
166166

167+
func (in *GrafanaDatasource) Metadata() metav1.ObjectMeta {
168+
return in.ObjectMeta
169+
}
170+
167171
func (in *GrafanaDatasource) AllowCrossNamespace() bool {
168172
return in.Spec.AllowCrossNamespaceImport
169173
}

api/v1beta1/grafanafolder_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,10 @@ func (in *GrafanaFolder) MatchNamespace() string {
171171
return in.Namespace
172172
}
173173

174+
func (in *GrafanaFolder) Metadata() metav1.ObjectMeta {
175+
return in.ObjectMeta
176+
}
177+
174178
func (in *GrafanaFolder) AllowCrossNamespace() bool {
175179
return in.Spec.AllowCrossNamespaceImport
176180
}

api/v1beta1/grafanalibrarypanel_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ func (in *GrafanaLibraryPanel) MatchNamespace() string {
8989
return in.Namespace
9090
}
9191

92+
func (in *GrafanaLibraryPanel) Metadata() metav1.ObjectMeta {
93+
return in.ObjectMeta
94+
}
95+
9296
func (in *GrafanaLibraryPanel) AllowCrossNamespace() bool {
9397
return in.Spec.AllowCrossNamespaceImport
9498
}

api/v1beta1/grafanamutetiming_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ func (in *GrafanaMuteTiming) MatchNamespace() string {
101101
return in.Namespace
102102
}
103103

104+
func (in *GrafanaMuteTiming) Metadata() metav1.ObjectMeta {
105+
return in.ObjectMeta
106+
}
107+
104108
func (in *GrafanaMuteTiming) AllowCrossNamespace() bool {
105109
return in.Spec.AllowCrossNamespaceImport
106110
}

api/v1beta1/grafananotificationpolicy_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,10 @@ func (in *GrafanaNotificationPolicy) MatchNamespace() string {
216216
return in.Namespace
217217
}
218218

219+
func (in *GrafanaNotificationPolicy) Metadata() metav1.ObjectMeta {
220+
return in.ObjectMeta
221+
}
222+
219223
func (in *GrafanaNotificationPolicy) AllowCrossNamespace() bool {
220224
return in.Spec.AllowCrossNamespaceImport
221225
}

api/v1beta1/grafananotificationtemplate_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ func (in *GrafanaNotificationTemplate) MatchNamespace() string {
6262
return in.Namespace
6363
}
6464

65+
func (in *GrafanaNotificationTemplate) Metadata() metav1.ObjectMeta {
66+
return in.ObjectMeta
67+
}
68+
6569
func (in *GrafanaNotificationTemplate) AllowCrossNamespace() bool {
6670
return in.Spec.AllowCrossNamespaceImport
6771
}

0 commit comments

Comments
 (0)