Skip to content

Commit a455c43

Browse files
committed
add unsafe k8s uuid functions
1 parent e960177 commit a455c43

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

pkg/controller/hash.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,16 @@ func validateIDs(names []string) error {
6161
return ErrInvalidNames
6262
}
6363

64+
// K8sNameUUIDUnsafe works like K8sNameUUID, but panics instead of returning an error.
65+
// This should only be used in places where the input is guaranteed to be valid.
66+
func K8sNameUUIDUnsafe(names ...string) string {
67+
uuid, err := K8sNameUUID(names...)
68+
if err != nil {
69+
panic(err)
70+
}
71+
return uuid
72+
}
73+
6474
// K8sObjectUUID takes a client object and computes a hash out of the namespace and name, which is then formatted as a version 8 UUID.
6575
// An empty namespace will be replaced by "default".
6676
func K8sObjectUUID(obj client.Object) (string, error) {
@@ -70,3 +80,13 @@ func K8sObjectUUID(obj client.Object) (string, error) {
7080
}
7181
return K8sNameUUID(namespace, name)
7282
}
83+
84+
// K8sObjectUUIDUnsafe works like K8sObjectUUID, but panics instead of returning an error.
85+
// This should only be used in places where the input is guaranteed to be valid.
86+
func K8sObjectUUIDUnsafe(obj client.Object) string {
87+
uuid, err := K8sObjectUUID(obj)
88+
if err != nil {
89+
panic(err)
90+
}
91+
return uuid
92+
}

0 commit comments

Comments
 (0)