Skip to content

Commit 4f0063e

Browse files
committed
Fix GenCachedObjectName in CachedResource replication reconciler
On-behalf-of: @SAP [email protected] Signed-off-by: Robert Vasek <[email protected]>
1 parent f58cd31 commit 4f0063e

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

pkg/reconciler/cache/cachedresources/replication/replication_reconcile.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func GenCachedObjectName(gvr schema.GroupVersionResource, namespace, name string
5959
buf.WriteString(namespace)
6060
buf.WriteString(name)
6161

62-
hash := sha256.Sum256([]byte(name))
62+
hash := sha256.Sum256(buf.Bytes())
6363
base36hash := strings.ToLower(base36.EncodeBytes(hash[:]))
6464

6565
return base36hash
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
Copyright 2025 The KCP 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 replication
18+
19+
import (
20+
"testing"
21+
22+
"github.com/stretchr/testify/require"
23+
24+
"k8s.io/apimachinery/pkg/runtime/schema"
25+
)
26+
27+
func TestGenCachedObjectName(t *testing.T) {
28+
tests := map[string]struct {
29+
gvr schema.GroupVersionResource
30+
namespace string
31+
name string
32+
want string
33+
}{
34+
"matching": {
35+
gvr: schema.GroupVersionResource{
36+
Group: "group-1",
37+
Version: "v1",
38+
Resource: "resource-1",
39+
},
40+
namespace: "",
41+
name: "a-resource",
42+
want: "6dgup41jy1ta41gc4q4hb1hdnmrdgl4rdn5ux0t8ya9nhk3jo6",
43+
},
44+
}
45+
for tname, tt := range tests {
46+
t.Run(tname, func(t *testing.T) {
47+
objName := GenCachedObjectName(tt.gvr, tt.namespace, tt.name)
48+
require.Equal(t, tt.want, objName, "GenCachedObjectName returned an unexpected object name")
49+
})
50+
}
51+
}

0 commit comments

Comments
 (0)