Skip to content

Commit 09a3e27

Browse files
committed
Update
1 parent 2347d3f commit 09a3e27

File tree

4 files changed

+117
-2
lines changed

4 files changed

+117
-2
lines changed

manifests/03-clusterrole.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ rules:
6262
- apiGroups:
6363
- "operator.openshift.io"
6464
resources:
65-
- insightsoperators
65+
- insightsoperators/status
6666
verbs:
6767
- get
6868
- update

pkg/controller/periodic/periodic.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ func createGathererStatus(gfr *gather.GathererFunctionReport) v1.GathererStatus
249249

250250
if len(gfr.Errors) > 0 {
251251
con.Reason = GatherWithErrorReason
252-
con.Message = fmt.Sprintf("%s Error is: %s", con.Message, strings.Join(gfr.Errors, ","))
252+
con.Message = fmt.Sprintf("%s Error: %s", con.Message, strings.Join(gfr.Errors, ","))
253253
}
254254

255255
gs.Conditions = append(gs.Conditions, con)

pkg/controller/periodic/periodic_test.go

+114
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ import (
77
"time"
88

99
"github.com/stretchr/testify/assert"
10+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1011

12+
v1 "github.com/openshift/api/operator/v1"
1113
fakeOperatorCli "github.com/openshift/client-go/operator/clientset/versioned/fake"
1214
"github.com/openshift/insights-operator/pkg/config"
1315
"github.com/openshift/insights-operator/pkg/gather"
@@ -177,3 +179,115 @@ func getMocksForPeriodicTest(listGatherers []gatherers.Interface, interval time.
177179
return New(&mockConfigurator, &mockRecorder, listGatherers, nil, fakeInsightsOperatorCli), &mockRecorder
178180
}
179181

182+
func Test_createGathererStatus(t *testing.T) { //nolint: funlen
183+
tests := []struct {
184+
name string
185+
gfr gather.GathererFunctionReport
186+
expectedGs v1.GathererStatus
187+
}{
188+
{
189+
name: "Data gathered OK",
190+
gfr: gather.GathererFunctionReport{
191+
FuncName: "gatherer1/foo",
192+
Duration: 115000,
193+
RecordsCount: 5,
194+
},
195+
expectedGs: v1.GathererStatus{
196+
Name: "gatherer1/foo",
197+
LastGatherDuration: metav1.Duration{
198+
Duration: 115000000000,
199+
},
200+
Conditions: []metav1.Condition{
201+
{
202+
Type: DataGatheredCondition,
203+
Status: metav1.ConditionTrue,
204+
Reason: GatherOKReason,
205+
Message: "Created 5 records in the archive.",
206+
},
207+
},
208+
},
209+
},
210+
{
211+
name: "No Data",
212+
gfr: gather.GathererFunctionReport{
213+
FuncName: "gatherer2/baz",
214+
Duration: 0,
215+
RecordsCount: 0,
216+
},
217+
expectedGs: v1.GathererStatus{
218+
Name: "gatherer2/baz",
219+
LastGatherDuration: metav1.Duration{
220+
Duration: 0,
221+
},
222+
Conditions: []metav1.Condition{
223+
{
224+
Type: DataGatheredCondition,
225+
Status: metav1.ConditionFalse,
226+
Reason: NoDataGatheredReason,
227+
},
228+
},
229+
},
230+
},
231+
{
232+
name: "Gatherer Error",
233+
gfr: gather.GathererFunctionReport{
234+
FuncName: "gatherer3/bar",
235+
Duration: 0,
236+
RecordsCount: 0,
237+
Errors: []string{"unable to read the data"},
238+
},
239+
expectedGs: v1.GathererStatus{
240+
Name: "gatherer3/bar",
241+
LastGatherDuration: metav1.Duration{
242+
Duration: 0,
243+
},
244+
Conditions: []metav1.Condition{
245+
{
246+
Type: DataGatheredCondition,
247+
Status: metav1.ConditionFalse,
248+
Reason: GatherErrorReason,
249+
Message: "unable to read the data",
250+
},
251+
},
252+
},
253+
},
254+
{
255+
name: "Data gathered with an error",
256+
gfr: gather.GathererFunctionReport{
257+
FuncName: "gatherer4/quz",
258+
Duration: 9000,
259+
RecordsCount: 2,
260+
Errors: []string{"didn't find xyz configmap"},
261+
},
262+
expectedGs: v1.GathererStatus{
263+
Name: "gatherer4/quz",
264+
LastGatherDuration: metav1.Duration{
265+
Duration: 9000000000,
266+
},
267+
Conditions: []metav1.Condition{
268+
{
269+
Type: DataGatheredCondition,
270+
Status: metav1.ConditionTrue,
271+
Reason: GatherWithErrorReason,
272+
Message: "Created 2 records in the archive. Error: didn't find xyz configmap",
273+
},
274+
},
275+
},
276+
},
277+
}
278+
279+
for _, tt := range tests {
280+
t.Run(tt.name, func(t *testing.T) {
281+
gathererStatus := createGathererStatus(&tt.gfr)
282+
assert.Equal(t, tt.expectedGs.Name, gathererStatus.Name)
283+
assert.Equal(t, tt.expectedGs.LastGatherDuration, gathererStatus.LastGatherDuration)
284+
285+
// more asserts since we can use simple equal because of the last transition time of the condition
286+
assert.Len(t, gathererStatus.Conditions, 1)
287+
assert.Equal(t, tt.expectedGs.Conditions[0].Type, gathererStatus.Conditions[0].Type)
288+
assert.Equal(t, tt.expectedGs.Conditions[0].Reason, gathererStatus.Conditions[0].Reason)
289+
assert.Equal(t, tt.expectedGs.Conditions[0].Status, gathererStatus.Conditions[0].Status)
290+
assert.Equal(t, tt.expectedGs.Conditions[0].Message, gathererStatus.Conditions[0].Message)
291+
})
292+
}
293+
}

pkg/controller/status/controller.go

+1
Original file line numberDiff line numberDiff line change
@@ -474,5 +474,6 @@ func relatedObjects(namespace string) []configv1.ObjectReference {
474474
{Resource: "serviceaccounts", Namespace: namespace, Name: "operator"},
475475
{Resource: "services", Namespace: namespace, Name: "metrics"},
476476
{Resource: "configmaps", Namespace: namespace, Name: "service-ca-bundle"},
477+
{Group: "operator.openshift.io", Resource: "insightsoperators", Name: "cluster"},
477478
}
478479
}

0 commit comments

Comments
 (0)