-
Notifications
You must be signed in to change notification settings - Fork 125
/
cluster_operator.go
46 lines (41 loc) · 1.93 KB
/
cluster_operator.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package library
import (
"context"
"testing"
"time"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait"
configv1 "github.com/openshift/api/config/v1"
configclient "github.com/openshift/client-go/config/clientset/versioned/typed/config/v1"
clusteroperatorhelpers "github.com/openshift/library-go/pkg/config/clusteroperator/v1helpers"
)
var (
WaitPollInterval = time.Second
WaitPollTimeout = 10 * time.Minute
)
// WaitForKubeControllerManagerClusterOperator waits for ClusterOperator/kube-controller-manager to report
// status as available, progressing, and failing as passed through arguments.
func WaitForKubeControllerManagerClusterOperator(t *testing.T, ctx context.Context, client configclient.ConfigV1Interface, available, progressing, degraded configv1.ConditionStatus) {
err := wait.Poll(WaitPollInterval, WaitPollTimeout, func() (bool, error) {
clusterOperator, err := client.ClusterOperators().Get(ctx, "kube-controller-manager", metav1.GetOptions{})
if errors.IsNotFound(err) {
t.Log("ClusterOperator/kube-controller-manager does not yet exist.")
return false, nil
}
if err != nil {
t.Log("Unable to retrieve ClusterOperator/kube-controller-manager:", err)
return false, err
}
conditions := clusterOperator.Status.Conditions
availableOK := clusteroperatorhelpers.IsStatusConditionPresentAndEqual(conditions, configv1.OperatorAvailable, available)
progressingOK := clusteroperatorhelpers.IsStatusConditionPresentAndEqual(conditions, configv1.OperatorProgressing, progressing)
degradedOK := clusteroperatorhelpers.IsStatusConditionPresentAndEqual(conditions, configv1.OperatorDegraded, degraded)
done := availableOK && progressingOK && degradedOK
t.Logf("ClusterOperator/kube-controller-manager: AvailableOK: %v ProgressingOK: %v DegradedOK: %v", availableOK, progressingOK, degradedOK)
return done, nil
})
if err != nil {
t.Fatal(err)
}
}