Skip to content

Commit 9d26a97

Browse files
committed
Don't include API version in hash key
1 parent cc573a4 commit 9d26a97

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

pkg/sharding/key/key.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"fmt"
2121

2222
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
23+
"k8s.io/apimachinery/pkg/runtime/schema"
2324
"k8s.io/apimachinery/pkg/util/sets"
2425
"sigs.k8s.io/controller-runtime/pkg/client"
2526

@@ -90,7 +91,7 @@ func ForObject(obj client.Object) (string, error) {
9091

9192
// Namespace can be empty for cluster-scoped resources. Only check the name field as an optimistic check for
9293
// preventing wrong usage of the function.
93-
return forMetadata(gvk.GroupVersion().String(), gvk.Kind, obj.GetNamespace(), obj.GetName()), nil
94+
return forMetadata(gvk.Group, gvk.Kind, obj.GetNamespace(), obj.GetName()), nil
9495
}
9596

9697
// ForController returns a ring key for the controller of the given object.
@@ -111,11 +112,16 @@ func ForController(obj client.Object) (string, error) {
111112
return "", fmt.Errorf("name of controller reference must not be empty")
112113
}
113114

115+
gv, err := schema.ParseGroupVersion(ref.APIVersion)
116+
if err != nil {
117+
return "", fmt.Errorf("invalid apiVersion of controller reference: %w", err)
118+
}
119+
114120
// Namespace can be empty for cluster-scoped resources. Only check the other fields as an optimistic check for
115121
// preventing wrong usage of the function.
116-
return forMetadata(ref.APIVersion, ref.Kind, obj.GetNamespace(), ref.Name), nil
122+
return forMetadata(gv.Group, ref.Kind, obj.GetNamespace(), ref.Name), nil
117123
}
118124

119-
func forMetadata(apiVersion, kind, namespace, name string) string {
120-
return apiVersion + "/" + kind + "/" + namespace + "/" + name
125+
func forMetadata(group, kind, namespace, name string) string {
126+
return group + "/" + kind + "/" + namespace + "/" + name
121127
}

0 commit comments

Comments
 (0)