@@ -4,43 +4,30 @@ import (
4
4
"context"
5
5
"strings"
6
6
"testing"
7
+ "time"
7
8
8
9
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
9
10
"k8s.io/client-go/util/retry"
10
11
11
- imageregistryv1 "github.com/openshift/api/imageregistry/v1"
12
- operatorapi "github.com/openshift/api/operator/v1"
13
-
14
- "github.com/openshift/cluster-image-registry-operator/pkg/defaults"
15
12
"github.com/openshift/cluster-image-registry-operator/test/framework"
16
13
)
17
14
18
15
func TestLeaderElection (t * testing.T ) {
19
- te := framework .SetupAvailableImageRegistry (t , & imageregistryv1.ImageRegistrySpec {
20
- ManagementState : operatorapi .Managed ,
21
- Storage : imageregistryv1.ImageRegistryConfigStorage {
22
- EmptyDir : & imageregistryv1.ImageRegistryConfigStorageEmptyDir {},
23
- },
24
- Replicas : 1 ,
25
- })
16
+ te := framework .Setup (t )
26
17
defer framework .TeardownImageRegistry (te )
27
18
28
- if _ , err := framework .WaitForRegistryDeployment (te .Client ()); err != nil {
29
- t .Fatalf ("error awaiting for registry deployment: %v" , err )
30
- }
31
-
32
19
var numberOfReplicas = int32 (3 )
33
20
if err := retry .RetryOnConflict (retry .DefaultBackoff , func () error {
34
- deploy , err := te .Client ().Deployments (defaults . ImageRegistryOperatorNamespace ).Get (
35
- context .Background (), "cluster-image-registry-operator" , metav1.GetOptions {},
21
+ deploy , err := te .Client ().Deployments (framework . OperatorDeploymentNamespace ).Get (
22
+ context .Background (), framework . OperatorDeploymentName , metav1.GetOptions {},
36
23
)
37
24
if err != nil {
38
25
return err
39
26
}
40
27
41
28
deploy .Spec .Replicas = & numberOfReplicas
42
29
43
- _ , err = te .Client ().Deployments (defaults . ImageRegistryOperatorNamespace ).Update (
30
+ _ , err = te .Client ().Deployments (framework . OperatorDeploymentNamespace ).Update (
44
31
context .Background (), deploy , metav1.UpdateOptions {},
45
32
)
46
33
return err
@@ -49,9 +36,15 @@ func TestLeaderElection(t *testing.T) {
49
36
}
50
37
51
38
framework .WaitUntilDeploymentIsRolledOut (
52
- te , defaults .ImageRegistryOperatorNamespace , "cluster-image-registry-operator" ,
39
+ te ,
40
+ framework .OperatorDeploymentNamespace ,
41
+ framework .OperatorDeploymentName ,
53
42
)
54
43
44
+ // With the convention of leader election we need to wait a couple of seconds
45
+ // for the pods to write the logs, so we don't get false positives
46
+ time .Sleep (time .Second * 2 )
47
+
55
48
allLogs , err := framework .GetOperatorLogs (te .Client ())
56
49
if err != nil {
57
50
t .Fatalf ("error reading operator logs: %v" , err )
0 commit comments