Skip to content

Commit c4eeca9

Browse files
Merge pull request #267 from valaparthvi/cleanup
Cleanup clusterOperatorInsights helper function
2 parents 911a012 + d65a432 commit c4eeca9

File tree

3 files changed

+10
-16
lines changed

3 files changed

+10
-16
lines changed

test/integration/basic_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func TestArchiveUploadedAndResultReceived(t *testing.T) {
6363
func TestOptOutOptIn(t *testing.T) {
6464
// initially IO should be running
6565
errDisabled := wait.PollImmediate(1*time.Second, 30*time.Second, func() (bool, error) {
66-
insightsNotDisabled := !operatorStatus(t, clusterOperatorInsights(), status.OperatorDisabled, configv1.ConditionTrue)
66+
insightsNotDisabled := !operatorStatus(t, clusterOperator("insights", t), status.OperatorDisabled, configv1.ConditionTrue)
6767
if insightsNotDisabled {
6868
return true, nil
6969
}
@@ -146,7 +146,7 @@ func TestOptOutOptIn(t *testing.T) {
146146

147147
// Wait for operator to become disabled because of removed pull-secret
148148
errDisabled = wait.PollImmediate(1*time.Second, 30*time.Second, func() (bool, error) {
149-
insightsDisabled := operatorConditionCheck(t, clusterOperatorInsights(), "Disabled")
149+
insightsDisabled := operatorConditionCheck(t, clusterOperator("insights", t), "Disabled")
150150
if insightsDisabled {
151151
return true, nil
152152
}
@@ -164,7 +164,7 @@ func TestOptOutOptIn(t *testing.T) {
164164
// Check if reports are uploaded - Logs show that insights-operator is enabled and reports are uploaded
165165
restartInsightsOperator(t)
166166
errDisabled = wait.PollImmediate(1*time.Second, 3*time.Minute, func() (bool, error) {
167-
insightsNotDisabled := !operatorStatus(t, clusterOperatorInsights(), status.OperatorDisabled, configv1.ConditionTrue)
167+
insightsNotDisabled := !operatorStatus(t, clusterOperator("insights", t), status.OperatorDisabled, configv1.ConditionTrue)
168168
if insightsNotDisabled {
169169
return true, nil
170170
}

test/integration/bugs_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ func TestUnreachableHost(t *testing.T) {
142142
checkPodsLogs(t, "exceeded than threshold 5. Marking as degraded.")
143143

144144
// Check the operator is degraded
145-
insightsDegraded := operatorConditionCheck(t, clusterOperatorInsights(), "Degraded")
145+
insightsDegraded := operatorConditionCheck(t, clusterOperator("insights", t), "Degraded")
146146
if !insightsDegraded {
147147
t.Fatal("Insights is not degraded")
148148
}
@@ -153,7 +153,7 @@ func TestUnreachableHost(t *testing.T) {
153153
}
154154
// Check the operator is not degraded anymore
155155
errDegraded := wait.PollImmediate(3*time.Second, 3*time.Minute, func() (bool, error) {
156-
insightsDegraded := operatorConditionCheck(t, clusterOperatorInsights(), "Degraded")
156+
insightsDegraded := operatorConditionCheck(t, clusterOperator("insights", t), "Degraded")
157157
if insightsDegraded {
158158
return false, nil
159159
}

test/integration/main_test.go

+5-11
Original file line numberDiff line numberDiff line change
@@ -78,21 +78,15 @@ func configV1Client() (result *configv1client.ConfigV1Client) {
7878
return client
7979
}
8080

81-
func clusterOperator(clusterName string) *configv1.ClusterOperator {
81+
func clusterOperator(clusterName string, t *testing.T) *configv1.ClusterOperator {
8282
// get info about given cluster operator
8383
operator, err := configClient.ClusterOperators().Get(context.Background(), clusterName, metav1.GetOptions{})
8484
if err != nil {
85-
// TODO -> change to t.Fatal in follow-up PR
86-
panic(err.Error())
85+
t.Fatalf("Failed to get information about the operator: %s", err)
8786
}
8887
return operator
8988
}
9089

91-
func clusterOperatorInsights() *configv1.ClusterOperator {
92-
// TODO -> delete this function in follow-up PR
93-
return clusterOperator("insights")
94-
}
95-
9690
func operatorConditionCheck(t *testing.T, operator *configv1.ClusterOperator, conditionType configv1.ClusterStatusConditionType) bool {
9791
statusConditions := operator.Status.Conditions
9892

@@ -294,7 +288,7 @@ func degradeOperatorMonitoring(t *testing.T) func() {
294288
// delete just in case it was already there, so we don't care about error
295289
pod := findPod(t, clientset, "openshift-monitoring", "cluster-monitoring-operator")
296290
clientset.CoreV1().ConfigMaps(pod.Namespace).Delete(context.Background(), "cluster-monitoring-config", metav1.DeleteOptions{})
297-
operatorConditionCheck(t, clusterOperator("monitoring"), "Degraded")
291+
operatorConditionCheck(t, clusterOperator("monitoring", t), "Degraded")
298292
_, err := clientset.CoreV1().ConfigMaps(pod.Namespace).Create(context.Background(),
299293
&corev1.ConfigMap{ObjectMeta: metav1.ObjectMeta{Name: "cluster-monitoring-config"}, Data: map[string]string{"config.yaml": "telemeterClient: enabled: NOT_BOOELAN"}},
300294
metav1.CreateOptions{},
@@ -303,12 +297,12 @@ func degradeOperatorMonitoring(t *testing.T) func() {
303297
err = clientset.CoreV1().Pods(pod.Namespace).Delete(context.Background(), pod.Name, metav1.DeleteOptions{})
304298
e(t, err, "Failed to delete Pod")
305299
wait.PollImmediate(1*time.Second, 5*time.Minute, func() (bool, error) {
306-
return operatorConditionCheck(t, clusterOperator("monitoring"), "Degraded"), nil
300+
return operatorConditionCheck(t, clusterOperator("monitoring", t), "Degraded"), nil
307301
})
308302
return func() {
309303
clientset.CoreV1().ConfigMaps(pod.Namespace).Delete(context.Background(), "cluster-monitoring-config", metav1.DeleteOptions{})
310304
wait.PollImmediate(3*time.Second, 3*time.Minute, func() (bool, error) {
311-
insightsDegraded := operatorConditionCheck(t, clusterOperator("monitoring"), "Degraded")
305+
insightsDegraded := operatorConditionCheck(t, clusterOperator("monitoring", t), "Degraded")
312306
return !insightsDegraded, nil
313307
})
314308
}

0 commit comments

Comments
 (0)