Skip to content

Commit 21cba9d

Browse files
committed
Double-check while locking in DynamicRESTMapper
This ensures that the DynamicRESTMapper will double-check after acquiring a lock that it still needs to refresh. This avoids the situation where two requests come in at the same time, both require the same missing resource, and both end up issuing (potentially expensive) discovery requests, even though simply issuing one would have sufficed. This also adds tests to ensure proper behavior, and limits discovery re-requests to 10 per second.
1 parent 8c858b3 commit 21cba9d

File tree

3 files changed

+404
-125
lines changed

3 files changed

+404
-125
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
Copyright 2018 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package apiutil_test
18+
19+
import (
20+
"testing"
21+
22+
. "github.com/onsi/ginkgo"
23+
. "github.com/onsi/gomega"
24+
"k8s.io/client-go/rest"
25+
"sigs.k8s.io/controller-runtime/pkg/envtest"
26+
27+
logf "sigs.k8s.io/controller-runtime/pkg/log"
28+
"sigs.k8s.io/controller-runtime/pkg/log/zap"
29+
)
30+
31+
func TestSource(t *testing.T) {
32+
RegisterFailHandler(Fail)
33+
RunSpecsWithDefaultAndCustomReporters(t, "API Utilities Test Suite", []Reporter{envtest.NewlineReporter{}})
34+
}
35+
36+
var cfg *rest.Config
37+
38+
var _ = BeforeSuite(func(done Done) {
39+
logf.SetLogger(zap.LoggerTo(GinkgoWriter, true))
40+
41+
// for things that technically need a rest.Config for defaulting, but don't actually use them
42+
cfg = &rest.Config{}
43+
44+
close(done)
45+
}, 60)

0 commit comments

Comments
 (0)