@@ -339,10 +339,6 @@ type Cacher struct {
339
339
expiredBookmarkWatchers []* cacheWatcher
340
340
}
341
341
342
- func (c * Cacher ) RequestWatchProgress (ctx context.Context ) error {
343
- return c .storage .RequestWatchProgress (ctx )
344
- }
345
-
346
342
// NewCacherFromConfig creates a new Cacher responsible for servicing WATCH and LIST requests from
347
343
// its internal cache and updating its cache in the background based on the
348
344
// given configuration.
@@ -495,56 +491,13 @@ func (c *Cacher) startCaching(stopChannel <-chan struct{}) {
495
491
}
496
492
}
497
493
498
- // Versioner implements storage.Interface.
499
- func (c * Cacher ) Versioner () storage.Versioner {
500
- return c .storage .Versioner ()
501
- }
502
-
503
- // Create implements storage.Interface.
504
- func (c * Cacher ) Create (ctx context.Context , key string , obj , out runtime.Object , ttl uint64 ) error {
505
- return c .storage .Create (ctx , key , obj , out , ttl )
506
- }
507
-
508
- // Delete implements storage.Interface.
509
- func (c * Cacher ) Delete (
510
- ctx context.Context , key string , out runtime.Object , preconditions * storage.Preconditions ,
511
- validateDeletion storage.ValidateObjectFunc , _ runtime.Object , opts storage.DeleteOptions ) error {
512
- // Ignore the suggestion and try to pass down the current version of the object
513
- // read from cache.
514
- if elem , exists , err := c .watchCache .GetByKey (key ); err != nil {
515
- klog .Errorf ("GetByKey returned error: %v" , err )
516
- } else if exists {
517
- // DeepCopy the object since we modify resource version when serializing the
518
- // current object.
519
- currObj := elem .(* storeElement ).Object .DeepCopyObject ()
520
- return c .storage .Delete (ctx , key , out , preconditions , validateDeletion , currObj , opts )
521
- }
522
- // If we couldn't get the object, fallback to no-suggestion.
523
- return c .storage .Delete (ctx , key , out , preconditions , validateDeletion , nil , opts )
524
- }
525
-
526
494
type namespacedName struct {
527
495
namespace string
528
496
name string
529
497
}
530
498
531
- // Watch implements storage.Interface.
532
499
func (c * Cacher ) Watch (ctx context.Context , key string , opts storage.ListOptions ) (watch.Interface , error ) {
533
500
pred := opts .Predicate
534
- // if the watch-list feature wasn't set and the resourceVersion is unset
535
- // ensure that the rv from which the watch is being served, is the latest
536
- // one. "latest" is ensured by serving the watch from
537
- // the underlying storage.
538
- //
539
- // it should never happen due to our validation but let's just be super-safe here
540
- // and disable sendingInitialEvents when the feature wasn't enabled
541
- if ! utilfeature .DefaultFeatureGate .Enabled (features .WatchList ) && opts .SendInitialEvents != nil {
542
- opts .SendInitialEvents = nil
543
- }
544
- // TODO: we should eventually get rid of this legacy case
545
- if utilfeature .DefaultFeatureGate .Enabled (features .WatchFromStorageWithoutResourceVersion ) && opts .SendInitialEvents == nil && opts .ResourceVersion == "" {
546
- return c .storage .Watch (ctx , key , opts )
547
- }
548
501
requestedWatchRV , err := c .versioner .ParseResourceVersion (opts .ResourceVersion )
549
502
if err != nil {
550
503
return nil , err
@@ -709,58 +662,17 @@ func (c *Cacher) Watch(ctx context.Context, key string, opts storage.ListOptions
709
662
return watcher , nil
710
663
}
711
664
712
- // Get implements storage.Interface.
713
665
func (c * Cacher ) Get (ctx context.Context , key string , opts storage.GetOptions , objPtr runtime.Object ) error {
714
- ctx , span := tracing .Start (ctx , "cacher.Get" ,
715
- attribute .String ("audit-id" , audit .GetAuditIDTruncated (ctx )),
716
- attribute .String ("key" , key ),
717
- attribute .String ("resource-version" , opts .ResourceVersion ))
718
- defer span .End (500 * time .Millisecond )
719
- if opts .ResourceVersion == "" {
720
- // If resourceVersion is not specified, serve it from underlying
721
- // storage (for backward compatibility).
722
- span .AddEvent ("About to Get from underlying storage" )
723
- return c .storage .Get (ctx , key , opts , objPtr )
724
- }
725
-
726
- if utilfeature .DefaultFeatureGate .Enabled (features .ResilientWatchCacheInitialization ) {
727
- if ! c .ready .check () {
728
- // If Cache is not initialized, delegate Get requests to storage
729
- // as described in https://kep.k8s.io/4568
730
- span .AddEvent ("About to Get from underlying storage - cache not initialized" )
731
- return c .storage .Get (ctx , key , opts , objPtr )
732
- }
733
- }
734
-
735
- // If resourceVersion is specified, serve it from cache.
736
- // It's guaranteed that the returned value is at least that
737
- // fresh as the given resourceVersion.
738
666
getRV , err := c .versioner .ParseResourceVersion (opts .ResourceVersion )
739
667
if err != nil {
740
668
return err
741
669
}
742
670
743
- // Do not create a trace - it's not for free and there are tons
744
- // of Get requests. We can add it if it will be really needed.
745
-
746
- if ! utilfeature .DefaultFeatureGate .Enabled (features .ResilientWatchCacheInitialization ) {
747
- if getRV == 0 && ! c .ready .check () {
748
- // If Cacher is not yet initialized and we don't require any specific
749
- // minimal resource version, simply forward the request to storage.
750
- span .AddEvent ("About to Get from underlying storage - cache not initialized and no resourceVersion set" )
751
- return c .storage .Get (ctx , key , opts , objPtr )
752
- }
753
- if err := c .ready .wait (ctx ); err != nil {
754
- return errors .NewServiceUnavailable (err .Error ())
755
- }
756
- }
757
-
758
671
objVal , err := conversion .EnforcePtr (objPtr )
759
672
if err != nil {
760
673
return err
761
674
}
762
675
763
- span .AddEvent ("About to fetch object from cache" )
764
676
obj , exists , readResourceVersion , err := c .watchCache .WaitUntilFreshAndGet (ctx , getRV , key )
765
677
if err != nil {
766
678
return err
@@ -845,32 +757,9 @@ type listResp struct {
845
757
}
846
758
847
759
// GetList implements storage.Interface
848
- func (c * Cacher ) GetList (ctx context.Context , key string , opts storage.ListOptions , listObj runtime.Object ) error {
760
+ func (c * Cacher ) GetList (ctx context.Context , key string , opts storage.ListOptions , listObj runtime.Object , listRV uint64 ) error {
849
761
recursive := opts .Recursive
850
- resourceVersion := opts .ResourceVersion
851
762
pred := opts .Predicate
852
- if shouldDelegateList (opts ) {
853
- return c .storage .GetList (ctx , key , opts , listObj )
854
- }
855
-
856
- listRV , err := c .versioner .ParseResourceVersion (resourceVersion )
857
- if err != nil {
858
- return err
859
- }
860
-
861
- if utilfeature .DefaultFeatureGate .Enabled (features .ResilientWatchCacheInitialization ) {
862
- if ! c .ready .check () && shouldDelegateListOnNotReadyCache (opts ) {
863
- // If Cacher is not initialized, delegate List requests to storage
864
- // as described in https://kep.k8s.io/4568
865
- return c .storage .GetList (ctx , key , opts , listObj )
866
- }
867
- } else {
868
- if listRV == 0 && ! c .ready .check () {
869
- // If Cacher is not yet initialized and we don't require any specific
870
- // minimal resource version, simply forward the request to storage.
871
- return c .storage .GetList (ctx , key , opts , listObj )
872
- }
873
- }
874
763
// For recursive lists, we need to make sure the key ended with "/" so that we only
875
764
// get children "directories". e.g. if we have key "/a", "/a/b", "/ab", getting keys
876
765
// with prefix "/a" will return all three, while with prefix "/a/" will return only
@@ -879,14 +768,6 @@ func (c *Cacher) GetList(ctx context.Context, key string, opts storage.ListOptio
879
768
if opts .Recursive && ! strings .HasSuffix (key , "/" ) {
880
769
preparedKey += "/"
881
770
}
882
- requestWatchProgressSupported := etcdfeature .DefaultFeatureSupportChecker .Supports (storage .RequestWatchProgress )
883
- consistentRead := resourceVersion == "" && utilfeature .DefaultFeatureGate .Enabled (features .ConsistentListFromCache ) && requestWatchProgressSupported
884
- if consistentRead {
885
- listRV , err = storage .GetCurrentResourceVersionFromStorage (ctx , c .storage , c .newListFunc , c .resourcePrefix , c .objectType .String ())
886
- if err != nil {
887
- return err
888
- }
889
- }
890
771
891
772
ctx , span := tracing .Start (ctx , "cacher.GetList" ,
892
773
attribute .String ("audit-id" , audit .GetAuditIDTruncated (ctx )),
@@ -920,24 +801,9 @@ func (c *Cacher) GetList(ctx context.Context, key string, opts storage.ListOptio
920
801
}
921
802
922
803
resp , indexUsed , err := c .listItems (ctx , listRV , preparedKey , pred , recursive )
923
- success := "true"
924
- fallback := "false"
925
804
if err != nil {
926
- if consistentRead {
927
- if storage .IsTooLargeResourceVersion (err ) {
928
- fallback = "true"
929
- err = c .storage .GetList (ctx , key , opts , listObj )
930
- }
931
- if err != nil {
932
- success = "false"
933
- }
934
- metrics .ConsistentReadTotal .WithLabelValues (c .resourcePrefix , success , fallback ).Add (1 )
935
- }
936
805
return err
937
806
}
938
- if consistentRead {
939
- metrics .ConsistentReadTotal .WithLabelValues (c .resourcePrefix , success , fallback ).Add (1 )
940
- }
941
807
span .AddEvent ("Listed items from cache" , attribute .Int ("count" , len (resp .Items )))
942
808
// store pointer of eligible objects,
943
809
// Why not directly put object in the items of listObj?
@@ -987,37 +853,6 @@ func (c *Cacher) GetList(ctx context.Context, key string, opts storage.ListOptio
987
853
return nil
988
854
}
989
855
990
- // GuaranteedUpdate implements storage.Interface.
991
- func (c * Cacher ) GuaranteedUpdate (
992
- ctx context.Context , key string , destination runtime.Object , ignoreNotFound bool ,
993
- preconditions * storage.Preconditions , tryUpdate storage.UpdateFunc , _ runtime.Object ) error {
994
- // Ignore the suggestion and try to pass down the current version of the object
995
- // read from cache.
996
- if elem , exists , err := c .watchCache .GetByKey (key ); err != nil {
997
- klog .Errorf ("GetByKey returned error: %v" , err )
998
- } else if exists {
999
- // DeepCopy the object since we modify resource version when serializing the
1000
- // current object.
1001
- currObj := elem .(* storeElement ).Object .DeepCopyObject ()
1002
- return c .storage .GuaranteedUpdate (ctx , key , destination , ignoreNotFound , preconditions , tryUpdate , currObj )
1003
- }
1004
- // If we couldn't get the object, fallback to no-suggestion.
1005
- return c .storage .GuaranteedUpdate (ctx , key , destination , ignoreNotFound , preconditions , tryUpdate , nil )
1006
- }
1007
-
1008
- // Count implements storage.Interface.
1009
- func (c * Cacher ) Count (pathPrefix string ) (int64 , error ) {
1010
- return c .storage .Count (pathPrefix )
1011
- }
1012
-
1013
- // ReadinessCheck implements storage.Interface.
1014
- func (c * Cacher ) ReadinessCheck () error {
1015
- if ! c .ready .check () {
1016
- return storage .ErrStorageNotReady
1017
- }
1018
- return nil
1019
- }
1020
-
1021
856
// baseObjectThreadUnsafe omits locking for cachingObject.
1022
857
func baseObjectThreadUnsafe (object runtime.Object ) runtime.Object {
1023
858
if co , ok := object .(* cachingObject ); ok {
@@ -1494,6 +1329,10 @@ func (c *Cacher) setInitialEventsEndBookmarkIfRequested(cacheInterval *watchCach
1494
1329
}
1495
1330
}
1496
1331
1332
+ func (c * Cacher ) Ready () bool {
1333
+ return c .ready .check ()
1334
+ }
1335
+
1497
1336
// errWatcher implements watch.Interface to return a single error
1498
1337
type errWatcher struct {
1499
1338
result chan watch.Event
0 commit comments