Skip to content
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

Automated cherry pick of #42506 #42622

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 17 additions & 0 deletions pkg/storage/etcd/etcd_helper_test.go
Expand Up @@ -567,3 +567,20 @@ func TestDeleteWithRetry(t *testing.T) {
t.Errorf("Expect an NotFound error, got %v", err)
}
}

func TestPrefix(t *testing.T) {
server := etcdtesting.NewEtcdTestClientServer(t)
defer server.Terminate(t)

testcases := map[string]string{
"custom/prefix": "/custom/prefix",
"/custom//prefix//": "/custom/prefix",
"/registry": "/registry",
}
for configuredPrefix, effectivePrefix := range testcases {
helper := newEtcdHelper(server.Client, testapi.Default.Codec(), configuredPrefix)
if helper.pathPrefix != effectivePrefix {
t.Errorf("configured prefix of %s, expected effective prefix of %s, got %s", configuredPrefix, effectivePrefix, helper.pathPrefix)
}
}
}
11 changes: 7 additions & 4 deletions pkg/storage/etcd3/store.go
Expand Up @@ -76,10 +76,13 @@ func NewWithNoQuorumRead(c *clientv3.Client, codec runtime.Codec, prefix string)
func newStore(c *clientv3.Client, quorumRead bool, codec runtime.Codec, prefix string) *store {
versioner := etcd.APIObjectVersioner{}
result := &store{
client: c,
versioner: versioner,
codec: codec,
pathPrefix: prefix,
client: c,
versioner: versioner,
codec: codec,
// for compatibility with etcd2 impl.
// no-op for default prefix of '/registry'.
// keeps compatibility with etcd2 impl for custom prefixes that don't start with '/'
pathPrefix: path.Join("/", prefix),
watcher: newWatcher(c, codec, versioner),
}
if !quorumRead {
Expand Down
15 changes: 15 additions & 0 deletions pkg/storage/etcd3/store_test.go
Expand Up @@ -555,3 +555,18 @@ func testPropogateStore(ctx context.Context, t *testing.T, store *store, obj *ap
}
return key, setOutput
}

func TestPrefix(t *testing.T) {
cluster := integration.NewClusterV3(t, &integration.ClusterConfig{Size: 1})
testcases := map[string]string{
"custom/prefix": "/custom/prefix",
"/custom//prefix//": "/custom/prefix",
"/registry": "/registry",
}
for configuredPrefix, effectivePrefix := range testcases {
store := newStore(cluster.RandClient(), false, testapi.Default.Codec(), configuredPrefix)
if store.pathPrefix != effectivePrefix {
t.Errorf("configured prefix of %s, expected effective prefix of %s, got %s", configuredPrefix, effectivePrefix, store.pathPrefix)
}
}
}