Skip to content

Fixed large resourceversion and limit for storages #132374

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 25, 2025

Conversation

PatrickLaabs
Copy link
Contributor

What type of PR is this?

/kind bug

What this PR does / why we need it:

Currently, when you do try to query the StorageClassList with a very high resourceVersion and a high limit value, you'll get a response, like this:
NOTE: Youll not only get a error message from etcdserver, you will also get a 500 error code.

curl -v -X GET "https://localhost:6443/apis/storage.k8s.io/v1/storageclasses?resourceVersion=276&timeoutSeconds=1&gracePeriodSeconds=103" -H "Authorization: Bearer $TOKEN" --insecure

{
  "kind": "Status",
  "apiVersion": "v1",
  "metadata": {},
  "status": "Failure",
  "message": "etcdserver: mvcc: required revision is a future revision",
  "code": 500

The issues #132358 suggested, that we might want to return a more graceful error message and a error code of 504, like this:

    "causes": [
      {
        "reason": "ResourceVersionTooLarge",
        "message": "Too large resource version"
      }
    ],
    "retryAfterSeconds": 1
  },
  "code": 504

After making some slight adjustments on the error handling, we are able to query the StorageClassList with a very high resourceVersion and a high limit value, and we will receive the desired message:

curl -v -X GET "https://localhost:6443/apis/storage.k8s.io/v1/storageclasses?resourceVersion=44232320&limit=38&timeoutSeconds=1&gracePeriodSeconds=103" -H "Authorization: Bearer $TOKEN" --insecure

{
  "kind": "Status",
  "apiVersion": "v1",
  "metadata": {},
  "status": "Failure",
  "message": "Timeout: Too large resource version: 2902323232, current: 300",
  "reason": "Timeout",
  "details": {
    "causes": [
      {
        "reason": "ResourceVersionTooLarge",
        "message": "Too large resource version"
      }
    ],
    "retryAfterSeconds": 1
  },
  "code": 504

Which issue(s) this PR is related to:

Fixes #132358

Special notes for your reviewer:

I am quite not sure, if the current change is what we really want.
This was a challenge for me 😄

We will check for the error message from etcd:
if err == etcdrpc.ErrFutureRev, which is infact this

ErrGRPCFutureRev               = status.Error(codes.OutOfRange, "etcdserver: mvcc: required revision is a future revision")

As I am not sure, if this is a good practice, I looked at the interpretListError function, which will be called within the GetList function.

And yes, we already doing it this way:

func interpretListError(err error, paging bool, continueKey, keyPrefix string) error {
	switch {
	case err == etcdrpc.ErrCompacted:
		if paging {
			return handleCompactedErrorForPaging(continueKey, keyPrefix)
		}
		return errors.NewResourceExpired(expired)
	}
	return err
}

But I'd be more than happy for some suggestions, if this is not the right approach 👍

Does this PR introduce a user-facing change?

Fixed API response for StorageClassList queries and returns a graceful error message, if the provided ResourceVersion is too large.

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:

NONE

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. kind/bug Categorizes issue or PR as related to a bug. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Jun 18, 2025
@k8s-ci-robot
Copy link
Contributor

This issue is currently awaiting triage.

If a SIG or subproject determines this is a relevant issue, they will accept it by applying the triage/accepted label and provide further guidance.

The triage/accepted label can be added by org members by writing /triage accepted in a comment.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Jun 18, 2025
@k8s-ci-robot
Copy link
Contributor

Hi @PatrickLaabs. Thanks for your PR.

I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added the needs-priority Indicates a PR lacks a `priority/foo` label and requires one. label Jun 18, 2025
@k8s-ci-robot k8s-ci-robot added area/apiserver sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. sig/etcd Categorizes an issue or PR as relevant to SIG Etcd. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Jun 18, 2025
@likakuli
Copy link
Member

likakuli commented Jun 19, 2025

Could you please add a unit test for it?

@PatrickLaabs
Copy link
Contributor Author

Thanks for the response and of course. I was waiting for a response on this, before I invest more time.

@serathius
Copy link
Contributor

serathius commented Jun 19, 2025

etcdserver: mvcc: required revision is a future revision is error from etcd, Too large resource version is error from cache.

Reason why you get different errors is due to &limit=38 argument, it changes LIST semantic from NotOlderThan served from cache, to legacy Exact served from etcd.

I'm not against unifying the semantic, I think it's even benefitial, but we definitely need a test for that. Suggest adding a scenario to RunTestList.

// If we can't get the current RV, use 0 as a fallback.
currentRV = 0
}
return storage.NewTooLargeResourceVersionError(requestedRV, currentRV, 1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I remember correctly the 1 in NewTooLargeResourceVersionError stands for 1 second in Retry-After. Seems like a incorrect suggestion for clients.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, thats correct. Setting it to value of 0 is a better approach, right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you check other places we use NewTooLargeResourceVersionError and see what we do there.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

func (s *store) validateMinimumResourceVersion(minimumResourceVersion string, actualRevision uint64) error {
if minimumResourceVersion == "" {
return nil
}
minimumRV, err := s.versioner.ParseResourceVersion(minimumResourceVersion)
if err != nil {
return apierrors.NewBadRequest(fmt.Sprintf("invalid resource version: %v", err))
}
// Enforce the storage.Interface guarantee that the resource version of the returned data
// "will be at least 'resourceVersion'".
if minimumRV > actualRevision {
return storage.NewTooLargeResourceVersionError(minimumRV, actualRevision, 0)
}
return nil
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found 3 cases:

Looks like there is no established value. For now I would set it to 0 to be consistent with etcd3 store. Long term it would be better to have one common strategy.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thats exactly what i thought. I'll set a reminder, to open up a follow-up issue for this one 👍

@PatrickLaabs
Copy link
Contributor Author

After reviewing the unit test, I have found something:

if tt.expectRVTooLarge {
	// TODO: Clasify etcd future revision error as TooLargeResourceVersion
	if err == nil || !(storage.IsTooLargeResourceVersion(err) || strings.Contains(err.Error(), "etcdserver: mvcc: required revision is a future revision")) {
		t.Fatalf("expecting resource version too high error, but get: %q", err)
	}
	return
}

If I am not completely wrong here.. thats exact the point we are looking for in our unit tests, right?

With my update Code, I had commented in the reviews, I made these adjustments for the unit test:

			if tt.expectRVTooLarge {
				if !storage.IsTooLargeResourceVersion(err) {
					t.Fatalf("expecting resource version too high error, but get: %v", err)
				}
				return
			}

What do you thing? Or shall we extend the testings?

@serathius
Copy link
Contributor

If I am not completely wrong here.. thats exact the point we are looking for in our unit tests, right?

yes

@serathius
Copy link
Contributor

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jun 20, 2025
@serathius
Copy link
Contributor

/lgtm

PTAL @wojtek-t

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 23, 2025
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: 5a109d1122209e58f31535536f127fa2c8ca0d60

@@ -744,6 +746,14 @@ func (s *store) GetList(ctx context.Context, key string, opts storage.ListOption
})
metrics.RecordEtcdRequest(metricsOp, s.groupResource, err, startTime)
if err != nil {
if errors.Is(err, etcdrpc.ErrFutureRev) {
currentRV, getRVErr := s.GetCurrentResourceVersion(ctx)
if getRVErr != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to surface this error somewhere, or just log it maybe?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is already on error handling path, we only call GetCurrentResourceVersion to provide more information to error. I don't think there is a need to surface the error, but maybe returning NewTooLargeResourceVersionError with rev 0 might not be correct. Maybe we should change error.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am currently a little busy at work. I'll get back to this in Friday 😊

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can improved that as a follow-up - let's merge that as this is already unifying the error types.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wojtek-t Sounds good. Shall I create the issue, or do you want to create and assign it to me?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please go ahead and create it

@wojtek-t
Copy link
Member

/lgtm
/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: PatrickLaabs, wojtek-t

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 25, 2025
@PatrickLaabs
Copy link
Contributor Author

Follow-Up issue to improve returned error message:

#132526

@k8s-ci-robot k8s-ci-robot merged commit 49bff13 into kubernetes:master Jun 25, 2025
13 checks passed
@k8s-ci-robot k8s-ci-robot added this to the v1.34 milestone Jun 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/apiserver cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. sig/etcd Categorizes an issue or PR as relevant to SIG Etcd. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Large resourceVersion parameter returns 500 error
6 participants