Skip to content

Commit d65a432

Browse files
committed
Cleanup clusterOperatorInsights helper function
1 parent 01473c3 commit d65a432

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
@@ -140,7 +140,7 @@ func TestUnreachableHost(t *testing.T) {
140140
checkPodsLogs(t, "exceeded than threshold 5. Marking as degraded.")
141141

142142
// Check the operator is degraded
143-
insightsDegraded := operatorConditionCheck(t, clusterOperatorInsights(), "Degraded")
143+
insightsDegraded := operatorConditionCheck(t, clusterOperator("insights", t), "Degraded")
144144
if !insightsDegraded {
145145
t.Fatal("Insights is not degraded")
146146
}
@@ -151,7 +151,7 @@ func TestUnreachableHost(t *testing.T) {
151151
}
152152
// Check the operator is not degraded anymore
153153
errDegraded := wait.PollImmediate(3*time.Second, 3*time.Minute, func() (bool, error) {
154-
insightsDegraded := operatorConditionCheck(t, clusterOperatorInsights(), "Degraded")
154+
insightsDegraded := operatorConditionCheck(t, clusterOperator("insights", t), "Degraded")
155155
if insightsDegraded {
156156
return false, nil
157157
}

test/integration/main_test.go

+5-11
Original file line numberDiff line numberDiff line change
@@ -75,21 +75,15 @@ func configV1Client() (result *configv1client.ConfigV1Client) {
7575
return client
7676
}
7777

78-
func clusterOperator(clusterName string) *configv1.ClusterOperator {
78+
func clusterOperator(clusterName string, t *testing.T) *configv1.ClusterOperator {
7979
// get info about given cluster operator
8080
operator, err := configClient.ClusterOperators().Get(context.Background(), clusterName, metav1.GetOptions{})
8181
if err != nil {
82-
// TODO -> change to t.Fatal in follow-up PR
83-
panic(err.Error())
82+
t.Fatalf("Failed to get information about the operator: %s", err)
8483
}
8584
return operator
8685
}
8786

88-
func clusterOperatorInsights() *configv1.ClusterOperator {
89-
// TODO -> delete this function in follow-up PR
90-
return clusterOperator("insights")
91-
}
92-
9387
func operatorConditionCheck(t *testing.T, operator *configv1.ClusterOperator, conditionType configv1.ClusterStatusConditionType) bool {
9488
statusConditions := operator.Status.Conditions
9589

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

0 commit comments

Comments
 (0)