mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-05 18:24:07 +00:00
k8s.io/apiserver/storage/etcd: refactor etcd GetList.
Reorder some code. Signed-off-by: Siyuan Zhang <sizhang@google.com>
This commit is contained in:
parent
84ec5e2ecc
commit
a968f51fa2
@ -634,15 +634,6 @@ func (s *store) GetList(ctx context.Context, key string, opts storage.ListOption
|
|||||||
|
|
||||||
newItemFunc := getNewItemFunc(listObj, v)
|
newItemFunc := getNewItemFunc(listObj, v)
|
||||||
|
|
||||||
var fromRV *uint64
|
|
||||||
if len(opts.ResourceVersion) > 0 {
|
|
||||||
parsedRV, err := s.versioner.ParseResourceVersion(opts.ResourceVersion)
|
|
||||||
if err != nil {
|
|
||||||
return apierrors.NewBadRequest(fmt.Sprintf("invalid resource version: %v", err))
|
|
||||||
}
|
|
||||||
fromRV = &parsedRV
|
|
||||||
}
|
|
||||||
|
|
||||||
var continueRV, withRev int64
|
var continueRV, withRev int64
|
||||||
var continueKey string
|
var continueKey string
|
||||||
switch {
|
switch {
|
||||||
@ -662,21 +653,23 @@ func (s *store) GetList(ctx context.Context, key string, opts storage.ListOption
|
|||||||
if continueRV > 0 {
|
if continueRV > 0 {
|
||||||
withRev = continueRV
|
withRev = continueRV
|
||||||
}
|
}
|
||||||
default:
|
case len(opts.ResourceVersion) > 0:
|
||||||
if fromRV != nil {
|
parsedRV, err := s.versioner.ParseResourceVersion(opts.ResourceVersion)
|
||||||
switch opts.ResourceVersionMatch {
|
if err != nil {
|
||||||
case metav1.ResourceVersionMatchNotOlderThan:
|
return apierrors.NewBadRequest(fmt.Sprintf("invalid resource version: %v", err))
|
||||||
// The not older than constraint is checked after we get a response from etcd,
|
}
|
||||||
// and returnedRV is then set to the revision we get from the etcd response.
|
switch opts.ResourceVersionMatch {
|
||||||
case metav1.ResourceVersionMatchExact:
|
case metav1.ResourceVersionMatchNotOlderThan:
|
||||||
withRev = int64(*fromRV)
|
// The not older than constraint is checked after we get a response from etcd,
|
||||||
case "": // legacy case
|
// and returnedRV is then set to the revision we get from the etcd response.
|
||||||
if opts.Recursive && opts.Predicate.Limit > 0 && *fromRV > 0 {
|
case metav1.ResourceVersionMatchExact:
|
||||||
withRev = int64(*fromRV)
|
withRev = int64(parsedRV)
|
||||||
}
|
case "": // legacy case
|
||||||
default:
|
if opts.Recursive && opts.Predicate.Limit > 0 && parsedRV > 0 {
|
||||||
return fmt.Errorf("unknown ResourceVersionMatch value: %v", opts.ResourceVersionMatch)
|
withRev = int64(parsedRV)
|
||||||
}
|
}
|
||||||
|
default:
|
||||||
|
return fmt.Errorf("unknown ResourceVersionMatch value: %v", opts.ResourceVersionMatch)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -527,12 +527,6 @@ func testListOptionsCase(t *testing.T, rsClient appsv1.ReplicaSetInterface, watc
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if opts.ResourceVersion == invalidResourceVersion {
|
|
||||||
if err == nil || !strings.Contains(err.Error(), "Invalid value") {
|
|
||||||
t.Fatalf("expecting invalid value error, but got: %v", err)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if opts.Continue == invalidContinueToken {
|
if opts.Continue == invalidContinueToken {
|
||||||
if err == nil || !strings.Contains(err.Error(), "continue key is not valid") {
|
if err == nil || !strings.Contains(err.Error(), "continue key is not valid") {
|
||||||
t.Fatalf("expected continue key not valid error, but got: %v", err)
|
t.Fatalf("expected continue key not valid error, but got: %v", err)
|
||||||
@ -546,6 +540,12 @@ func testListOptionsCase(t *testing.T, rsClient appsv1.ReplicaSetInterface, watc
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if opts.ResourceVersion == invalidResourceVersion {
|
||||||
|
if err == nil || !strings.Contains(err.Error(), "Invalid value") {
|
||||||
|
t.Fatalf("expecting invalid value error, but got: %v", err)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Check for too old errors
|
// Check for too old errors
|
||||||
isExact := opts.ResourceVersionMatch == metav1.ResourceVersionMatchExact
|
isExact := opts.ResourceVersionMatch == metav1.ResourceVersionMatchExact
|
||||||
|
Loading…
Reference in New Issue
Block a user