@@ -33,6 +33,7 @@ import (
33
33
"testing"
34
34
"time"
35
35
36
+ guuid "github.com/google/uuid"
36
37
admissionregistrationv1 "k8s.io/api/admissionregistration/v1"
37
38
admissionregistrationv1beta1 "k8s.io/api/admissionregistration/v1beta1"
38
39
apps "k8s.io/api/apps/v1"
@@ -389,59 +390,66 @@ func TestListOptions(t *testing.T) {
389
390
for _ , watchCacheEnabled := range []bool {true , false } {
390
391
t .Run (fmt .Sprintf ("watchCacheEnabled=%t" , watchCacheEnabled ), func (t * testing.T ) {
391
392
tCtx := ktesting .Init (t )
393
+ prefix := path .Join ("/" , guuid .New ().String (), "registry" )
394
+ etcdConfig := storagebackend.Config {
395
+ Prefix : prefix ,
396
+ Transport : storagebackend.TransportConfig {ServerList : []string {framework .GetEtcdURL ()}},
397
+ }
398
+ rawClient , kvClient , err := integration .GetEtcdClients (etcdConfig .Transport )
399
+ if err != nil {
400
+ t .Fatal (err )
401
+ }
402
+ // kvClient is a wrapper around rawClient and to avoid leaking goroutines we need to
403
+ // close the client (which we can do by closing rawClient).
404
+ defer func () {
405
+ err := rawClient .Close ()
406
+ if err != nil {
407
+ t .Fatal (err )
408
+ }
409
+ }()
392
410
393
- var storageTransport * storagebackend.TransportConfig
394
- clientSet , _ , tearDownFn := framework .StartTestServer (tCtx , t , framework.TestServerSetup {
395
- ModifyServerRunOptions : func (opts * options.ServerRunOptions ) {
396
- opts .Etcd .EnableWatchCache = watchCacheEnabled
397
- storageTransport = & opts .Etcd .StorageConfig .Transport
398
- },
399
- })
400
- defer tearDownFn ()
401
-
402
- ns := framework .CreateNamespaceOrDie (clientSet , "list-options" , t )
403
- defer framework .DeleteNamespaceOrDie (clientSet , ns , t )
404
-
405
- rsClient := clientSet .AppsV1 ().ReplicaSets (ns .Name )
406
-
407
- var compactedRv , oldestUncompactedRv string
411
+ var compactedRv string
412
+ var oldestUncompactedRv int64
408
413
for i := 0 ; i < 15 ; i ++ {
409
- rs := newRS (ns . Name )
414
+ rs := newRS ("default" )
410
415
rs .Name = fmt .Sprintf ("test-%d" , i )
411
- created , err := rsClient .Create (tCtx , rs , metav1.CreateOptions {})
416
+ serializer := protobuf .NewSerializer (nil , nil )
417
+ buf := bytes.Buffer {}
418
+ err := serializer .Encode (rs , & buf )
419
+ if err != nil {
420
+ t .Fatal (err )
421
+ }
422
+ key := prefix + "/replicasets/default/" + rs .Name
423
+
424
+ resp , err := kvClient .Put (tCtx , key , buf .String ())
412
425
if err != nil {
413
426
t .Fatal (err )
414
427
}
415
428
if i == 0 {
416
- compactedRv = created . ResourceVersion // We compact this first resource version below
429
+ compactedRv = strconv . FormatInt ( resp . Header . Revision , 10 ) // We compact this first resource version below
417
430
}
418
431
// delete the first 5, and then compact them
419
432
if i < 5 {
420
- var zero int64
421
- if err := rsClient .Delete (tCtx , rs .Name , metav1.DeleteOptions {GracePeriodSeconds : & zero }); err != nil {
433
+ if _ , err := kvClient .Delete (tCtx , key ); err != nil {
422
434
t .Fatal (err )
423
435
}
424
- oldestUncompactedRv = created . ResourceVersion
436
+ oldestUncompactedRv = resp . Header . Revision
425
437
}
426
438
}
427
-
428
- // compact some of the revision history in etcd so we can test "too old" resource versions
429
- rawClient , kvClient , err := integration .GetEtcdClients (* storageTransport )
439
+ _ , err = kvClient .Compact (tCtx , int64 (oldestUncompactedRv ))
430
440
if err != nil {
431
441
t .Fatal (err )
432
442
}
433
- // kvClient is a wrapper around rawClient and to avoid leaking goroutines we need to
434
- // close the client (which we can do by closing rawClient).
435
- defer rawClient .Close ()
436
443
437
- revision , err := strconv .Atoi (oldestUncompactedRv )
438
- if err != nil {
439
- t .Fatal (err )
440
- }
441
- _ , err = kvClient .Compact (tCtx , int64 (revision ))
442
- if err != nil {
443
- t .Fatal (err )
444
- }
444
+ clientSet , _ , tearDownFn := framework .StartTestServer (tCtx , t , framework.TestServerSetup {
445
+ ModifyServerRunOptions : func (opts * options.ServerRunOptions ) {
446
+ opts .Etcd .EnableWatchCache = watchCacheEnabled
447
+ opts .Etcd .StorageConfig = etcdConfig
448
+ },
449
+ })
450
+ defer tearDownFn ()
451
+
452
+ rsClient := clientSet .AppsV1 ().ReplicaSets ("default" )
445
453
446
454
listObj , err := rsClient .List (tCtx , metav1.ListOptions {
447
455
Limit : 6 ,
0 commit comments