@@ -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
@@ -853,32 +765,9 @@ type listResp struct {
853
765
}
854
766
855
767
// GetList implements storage.Interface
856
- func (c * Cacher ) GetList (ctx context.Context , key string , opts storage.ListOptions , listObj runtime.Object ) error {
768
+ func (c * Cacher ) GetList (ctx context.Context , key string , opts storage.ListOptions , listObj runtime.Object , listRV uint64 ) error {
857
769
recursive := opts .Recursive
858
- resourceVersion := opts .ResourceVersion
859
770
pred := opts .Predicate
860
- if shouldDelegateList (opts ) {
861
- return c .storage .GetList (ctx , key , opts , listObj )
862
- }
863
-
864
- listRV , err := c .versioner .ParseResourceVersion (resourceVersion )
865
- if err != nil {
866
- return err
867
- }
868
-
869
- if utilfeature .DefaultFeatureGate .Enabled (features .ResilientWatchCacheInitialization ) {
870
- if ! c .ready .check () && shouldDelegateListOnNotReadyCache (opts ) {
871
- // If Cacher is not initialized, delegate List requests to storage
872
- // as described in https://kep.k8s.io/4568
873
- return c .storage .GetList (ctx , key , opts , listObj )
874
- }
875
- } else {
876
- if listRV == 0 && ! c .ready .check () {
877
- // If Cacher is not yet initialized and we don't require any specific
878
- // minimal resource version, simply forward the request to storage.
879
- return c .storage .GetList (ctx , key , opts , listObj )
880
- }
881
- }
882
771
// For recursive lists, we need to make sure the key ended with "/" so that we only
883
772
// get children "directories". e.g. if we have key "/a", "/a/b", "/ab", getting keys
884
773
// with prefix "/a" will return all three, while with prefix "/a/" will return only
@@ -887,14 +776,6 @@ func (c *Cacher) GetList(ctx context.Context, key string, opts storage.ListOptio
887
776
if opts .Recursive && ! strings .HasSuffix (key , "/" ) {
888
777
preparedKey += "/"
889
778
}
890
- requestWatchProgressSupported := etcdfeature .DefaultFeatureSupportChecker .Supports (storage .RequestWatchProgress )
891
- consistentRead := resourceVersion == "" && utilfeature .DefaultFeatureGate .Enabled (features .ConsistentListFromCache ) && requestWatchProgressSupported
892
- if consistentRead {
893
- listRV , err = storage .GetCurrentResourceVersionFromStorage (ctx , c .storage , c .newListFunc , c .resourcePrefix , c .objectType .String ())
894
- if err != nil {
895
- return err
896
- }
897
- }
898
779
899
780
ctx , span := tracing .Start (ctx , "cacher.GetList" ,
900
781
attribute .String ("audit-id" , audit .GetAuditIDTruncated (ctx )),
@@ -928,24 +809,9 @@ func (c *Cacher) GetList(ctx context.Context, key string, opts storage.ListOptio
928
809
}
929
810
930
811
resp , indexUsed , err := c .listItems (ctx , listRV , preparedKey , pred , recursive )
931
- success := "true"
932
- fallback := "false"
933
812
if err != nil {
934
- if consistentRead {
935
- if storage .IsTooLargeResourceVersion (err ) {
936
- fallback = "true"
937
- err = c .storage .GetList (ctx , key , opts , listObj )
938
- }
939
- if err != nil {
940
- success = "false"
941
- }
942
- metrics .ConsistentReadTotal .WithLabelValues (c .resourcePrefix , success , fallback ).Add (1 )
943
- }
944
813
return err
945
814
}
946
- if consistentRead {
947
- metrics .ConsistentReadTotal .WithLabelValues (c .resourcePrefix , success , fallback ).Add (1 )
948
- }
949
815
span .AddEvent ("Listed items from cache" , attribute .Int ("count" , len (resp .Items )))
950
816
// store pointer of eligible objects,
951
817
// Why not directly put object in the items of listObj?
@@ -995,37 +861,6 @@ func (c *Cacher) GetList(ctx context.Context, key string, opts storage.ListOptio
995
861
return nil
996
862
}
997
863
998
- // GuaranteedUpdate implements storage.Interface.
999
- func (c * Cacher ) GuaranteedUpdate (
1000
- ctx context.Context , key string , destination runtime.Object , ignoreNotFound bool ,
1001
- preconditions * storage.Preconditions , tryUpdate storage.UpdateFunc , _ runtime.Object ) error {
1002
- // Ignore the suggestion and try to pass down the current version of the object
1003
- // read from cache.
1004
- if elem , exists , err := c .watchCache .GetByKey (key ); err != nil {
1005
- klog .Errorf ("GetByKey returned error: %v" , err )
1006
- } else if exists {
1007
- // DeepCopy the object since we modify resource version when serializing the
1008
- // current object.
1009
- currObj := elem .(* storeElement ).Object .DeepCopyObject ()
1010
- return c .storage .GuaranteedUpdate (ctx , key , destination , ignoreNotFound , preconditions , tryUpdate , currObj )
1011
- }
1012
- // If we couldn't get the object, fallback to no-suggestion.
1013
- return c .storage .GuaranteedUpdate (ctx , key , destination , ignoreNotFound , preconditions , tryUpdate , nil )
1014
- }
1015
-
1016
- // Count implements storage.Interface.
1017
- func (c * Cacher ) Count (pathPrefix string ) (int64 , error ) {
1018
- return c .storage .Count (pathPrefix )
1019
- }
1020
-
1021
- // ReadinessCheck implements storage.Interface.
1022
- func (c * Cacher ) ReadinessCheck () error {
1023
- if ! c .ready .check () {
1024
- return storage .ErrStorageNotReady
1025
- }
1026
- return nil
1027
- }
1028
-
1029
864
// baseObjectThreadUnsafe omits locking for cachingObject.
1030
865
func baseObjectThreadUnsafe (object runtime.Object ) runtime.Object {
1031
866
if co , ok := object .(* cachingObject ); ok {
@@ -1502,6 +1337,10 @@ func (c *Cacher) setInitialEventsEndBookmarkIfRequested(cacheInterval *watchCach
1502
1337
}
1503
1338
}
1504
1339
1340
+ func (c * Cacher ) Ready () bool {
1341
+ return c .ready .check ()
1342
+ }
1343
+
1505
1344
// errWatcher implements watch.Interface to return a single error
1506
1345
type errWatcher struct {
1507
1346
result chan watch.Event
0 commit comments