88 "testing"
99 "time"
1010
11- "github.com/openshift/cluster-etcd-operator/pkg/etcdcli"
12- "go.etcd.io/etcd/api/v3/etcdserverpb"
13-
1411 testing2 "k8s.io/utils/clock/testing"
1512
1613 "github.com/openshift/library-go/pkg/controller/factory"
@@ -96,14 +93,6 @@ func TestSyncLoopWithDefaultBackupCR(t *testing.T) {
9693 & operatorv1.StaticPodOperatorSpec {OperatorSpec : operatorv1.OperatorSpec {ManagementState : operatorv1 .Managed }},
9794 & operatorv1.StaticPodOperatorStatus {}, nil , nil )
9895
99- defaultEtcdMembers := []* etcdserverpb.Member {
100- u .FakeEtcdMemberWithoutServer (0 ),
101- u .FakeEtcdMemberWithoutServer (1 ),
102- u .FakeEtcdMemberWithoutServer (2 ),
103- }
104- fakeEtcdClient , err := etcdcli .NewFakeEtcdClient (defaultEtcdMembers , etcdcli .WithFakeClusterHealth (& etcdcli.FakeMemberHealth {Healthy : 3 , Unhealthy : 0 }))
105- require .NoError (t , err )
106-
10796 controller := PeriodicBackupController {
10897 operatorClient : fakeOperatorClient ,
10998 podLister : fakeKubeInformerForNamespace .InformersFor (operatorclient .TargetNamespace ).Core ().V1 ().Pods ().Lister (),
@@ -112,7 +101,6 @@ func TestSyncLoopWithDefaultBackupCR(t *testing.T) {
112101 operatorImagePullSpec : "pullspec-image" ,
113102 backupVarGetter : backuphelpers .NewDisabledBackupConfig (),
114103 featureGateAccessor : backupFeatureGateAccessor ,
115- etcdClient : fakeEtcdClient ,
116104 kubeInformers : fakeKubeInformerForNamespace ,
117105 }
118106
@@ -129,7 +117,7 @@ func TestSyncLoopWithDefaultBackupCR(t *testing.T) {
129117 fakeKubeInformerForNamespace .Start (stopChan )
130118
131119 expDisabledBackupVar := " args:\n - --enabled=false"
132- err = controller .sync (context .TODO (), syncCtx )
120+ err : = controller .sync (context .TODO (), syncCtx )
133121 require .NoError (t , err )
134122 require .Equal (t , expDisabledBackupVar , controller .backupVarGetter .ArgString ())
135123
@@ -193,14 +181,6 @@ func TestSyncLoopWithDefaultBackupCRWithoutRetentionSpec(t *testing.T) {
193181 & operatorv1.StaticPodOperatorSpec {OperatorSpec : operatorv1.OperatorSpec {ManagementState : operatorv1 .Managed }},
194182 & operatorv1.StaticPodOperatorStatus {}, nil , nil )
195183
196- defaultEtcdMembers := []* etcdserverpb.Member {
197- u .FakeEtcdMemberWithoutServer (0 ),
198- u .FakeEtcdMemberWithoutServer (1 ),
199- u .FakeEtcdMemberWithoutServer (2 ),
200- }
201- fakeEtcdClient , err := etcdcli .NewFakeEtcdClient (defaultEtcdMembers , etcdcli .WithFakeClusterHealth (& etcdcli.FakeMemberHealth {Healthy : 3 , Unhealthy : 0 }))
202- require .NoError (t , err )
203-
204184 controller := PeriodicBackupController {
205185 operatorClient : fakeOperatorClient ,
206186 podLister : fakeKubeInformerForNamespace .InformersFor (operatorclient .TargetNamespace ).Core ().V1 ().Pods ().Lister (),
@@ -209,7 +189,6 @@ func TestSyncLoopWithDefaultBackupCRWithoutRetentionSpec(t *testing.T) {
209189 operatorImagePullSpec : "pullspec-image" ,
210190 backupVarGetter : backuphelpers .NewDisabledBackupConfig (),
211191 featureGateAccessor : backupFeatureGateAccessor ,
212- etcdClient : fakeEtcdClient ,
213192 kubeInformers : fakeKubeInformerForNamespace ,
214193 }
215194
@@ -226,7 +205,7 @@ func TestSyncLoopWithDefaultBackupCRWithoutRetentionSpec(t *testing.T) {
226205 fakeKubeInformerForNamespace .Start (stopChan )
227206
228207 expDisabledBackupVar := " args:\n - --enabled=false"
229- err = controller .sync (context .TODO (), syncCtx )
208+ err : = controller .sync (context .TODO (), syncCtx )
230209 require .NoError (t , err )
231210 require .Equal (t , expDisabledBackupVar , controller .backupVarGetter .ArgString ())
232211
@@ -290,14 +269,6 @@ func TestSyncLoopWithDefaultBackupCRWithoutScheduleSpec(t *testing.T) {
290269 & operatorv1.StaticPodOperatorSpec {OperatorSpec : operatorv1.OperatorSpec {ManagementState : operatorv1 .Managed }},
291270 & operatorv1.StaticPodOperatorStatus {}, nil , nil )
292271
293- defaultEtcdMembers := []* etcdserverpb.Member {
294- u .FakeEtcdMemberWithoutServer (0 ),
295- u .FakeEtcdMemberWithoutServer (1 ),
296- u .FakeEtcdMemberWithoutServer (2 ),
297- }
298- fakeEtcdClient , err := etcdcli .NewFakeEtcdClient (defaultEtcdMembers , etcdcli .WithFakeClusterHealth (& etcdcli.FakeMemberHealth {Healthy : 3 , Unhealthy : 0 }))
299- require .NoError (t , err )
300-
301272 controller := PeriodicBackupController {
302273 operatorClient : fakeOperatorClient ,
303274 podLister : fakeKubeInformerForNamespace .InformersFor (operatorclient .TargetNamespace ).Core ().V1 ().Pods ().Lister (),
@@ -306,7 +277,6 @@ func TestSyncLoopWithDefaultBackupCRWithoutScheduleSpec(t *testing.T) {
306277 operatorImagePullSpec : "pullspec-image" ,
307278 backupVarGetter : backuphelpers .NewDisabledBackupConfig (),
308279 featureGateAccessor : backupFeatureGateAccessor ,
309- etcdClient : fakeEtcdClient ,
310280 kubeInformers : fakeKubeInformerForNamespace ,
311281 }
312282
@@ -323,7 +293,7 @@ func TestSyncLoopWithDefaultBackupCRWithoutScheduleSpec(t *testing.T) {
323293 fakeKubeInformerForNamespace .Start (stopChan )
324294
325295 expDisabledBackupVar := " args:\n - --enabled=false"
326- err = controller .sync (context .TODO (), syncCtx )
296+ err : = controller .sync (context .TODO (), syncCtx )
327297 require .NoError (t , err )
328298 require .Equal (t , expDisabledBackupVar , controller .backupVarGetter .ArgString ())
329299
@@ -388,14 +358,6 @@ func TestSyncLoopWithDefaultBackupCREditSpec(t *testing.T) {
388358 & operatorv1.StaticPodOperatorSpec {OperatorSpec : operatorv1.OperatorSpec {ManagementState : operatorv1 .Managed }},
389359 & operatorv1.StaticPodOperatorStatus {}, nil , nil )
390360
391- defaultEtcdMembers := []* etcdserverpb.Member {
392- u .FakeEtcdMemberWithoutServer (0 ),
393- u .FakeEtcdMemberWithoutServer (1 ),
394- u .FakeEtcdMemberWithoutServer (2 ),
395- }
396- fakeEtcdClient , err := etcdcli .NewFakeEtcdClient (defaultEtcdMembers , etcdcli .WithFakeClusterHealth (& etcdcli.FakeMemberHealth {Healthy : 3 , Unhealthy : 0 }))
397- require .NoError (t , err )
398-
399361 controller := PeriodicBackupController {
400362 operatorClient : fakeOperatorClient ,
401363 podLister : fakeKubeInformerForNamespace .InformersFor (operatorclient .TargetNamespace ).Core ().V1 ().Pods ().Lister (),
@@ -404,7 +366,6 @@ func TestSyncLoopWithDefaultBackupCREditSpec(t *testing.T) {
404366 operatorImagePullSpec : "pullspec-image" ,
405367 backupVarGetter : backuphelpers .NewDisabledBackupConfig (),
406368 featureGateAccessor : backupFeatureGateAccessor ,
407- etcdClient : fakeEtcdClient ,
408369 kubeInformers : fakeKubeInformerForNamespace ,
409370 }
410371
@@ -421,7 +382,7 @@ func TestSyncLoopWithDefaultBackupCREditSpec(t *testing.T) {
421382 fakeKubeInformerForNamespace .Start (stopChan )
422383
423384 expDisabledBackupVar := " args:\n - --enabled=false"
424- err = controller .sync (context .TODO (), syncCtx )
385+ err : = controller .sync (context .TODO (), syncCtx )
425386 require .NoError (t , err )
426387 require .Equal (t , expDisabledBackupVar , controller .backupVarGetter .ArgString ())
427388
@@ -512,14 +473,6 @@ func TestSyncLoopFailsDegradesOperatorWithDefaultBackupCR(t *testing.T) {
512473 backups .Items = append (backups .Items , backup )
513474 operatorFake := fake .NewClientset ([]runtime.Object {& backups }... )
514475
515- defaultEtcdMembers := []* etcdserverpb.Member {
516- u .FakeEtcdMemberWithoutServer (0 ),
517- u .FakeEtcdMemberWithoutServer (1 ),
518- u .FakeEtcdMemberWithoutServer (2 ),
519- }
520- fakeEtcdClient , err := etcdcli .NewFakeEtcdClient (defaultEtcdMembers , etcdcli .WithFakeClusterHealth (& etcdcli.FakeMemberHealth {Healthy : 3 , Unhealthy : 0 }))
521- require .NoError (t , err )
522-
523476 controller := PeriodicBackupController {
524477 operatorClient : fakeOperatorClient ,
525478 podLister : fakeKubeInformerForNamespace .InformersFor (operatorclient .TargetNamespace ).Core ().V1 ().Pods ().Lister (),
@@ -528,7 +481,6 @@ func TestSyncLoopFailsDegradesOperatorWithDefaultBackupCR(t *testing.T) {
528481 operatorImagePullSpec : "pullspec-image" ,
529482 backupVarGetter : backuphelpers .NewDisabledBackupConfig (),
530483 featureGateAccessor : backupFeatureGateAccessor ,
531- etcdClient : fakeEtcdClient ,
532484 kubeInformers : fakeKubeInformerForNamespace ,
533485 }
534486
@@ -545,7 +497,7 @@ func TestSyncLoopFailsDegradesOperatorWithDefaultBackupCR(t *testing.T) {
545497 fakeKubeInformerForNamespace .Start (stopChan )
546498
547499 expDisabledBackupVar := " args:\n - --enabled=false"
548- err = controller .sync (context .TODO (), syncCtx )
500+ err : = controller .sync (context .TODO (), syncCtx )
549501 require .NoError (t , err )
550502 require .Equal (t , expDisabledBackupVar , controller .backupVarGetter .ArgString ())
551503 requireOperatorStatus (t , fakeOperatorClient , false )
@@ -852,23 +804,24 @@ func extractEtcdBackupServerArgVal(t testing.TB, argName string, args []string)
852804
853805func TestEnsureVotingNodesLabeled (t * testing.T ) {
854806 // arrange
855- defaultEtcdMembers := []* etcdserverpb.Member {
856- u .FakeEtcdMemberWithoutServer (0 ),
857- u .FakeEtcdMemberWithoutServer (1 ),
858- u .FakeEtcdMemberWithoutServer (2 ),
859- }
860- fakeEtcdClient , err := etcdcli .NewFakeEtcdClient (defaultEtcdMembers , etcdcli .WithFakeClusterHealth (& etcdcli.FakeMemberHealth {Healthy : 3 , Unhealthy : 0 }))
861- require .NoError (t , err )
862-
863807 allClusterNodes := defaultClusterNodes ()
864808 var objects []runtime.Object
865809 for _ , n := range allClusterNodes {
866810 objects = append (objects , n )
867811 }
812+
813+ endpointCM := u .EndpointsConfigMap (
814+ u .WithEndpoint (1 , "10.0.0.1" + etcdClientPort ),
815+ u .WithEndpoint (2 , "10.0.0.2" + etcdClientPort ),
816+ u .WithEndpoint (3 , "10.0.0.3" + etcdClientPort ),
817+ )
818+ objects = append (objects , endpointCM )
868819 client := k8sfakeclient .NewClientset (objects ... )
869820
870821 // act
871- err = ensureVotingNodesLabeled (context .TODO (), client , fakeEtcdClient )
822+ endpoints , err := getEtcdEndpoints (context .TODO (), client )
823+ require .NoError (t , err )
824+ err = ensureVotingNodesLabeled (context .TODO (), client , endpoints )
872825 require .NoError (t , err )
873826
874827 // assert
0 commit comments