Skip to content

Commit f53d2c3

Browse files
committed
Fix some issues in types.ReconcileKey
While trying to determine what key to emit for an element without a namespace, I looked at types.ReconcileKey which would emit "/name" which doesn't appear to agree with the rest of the logic in kubebuilder. This fixes types.ReconcileKey to emit the correct string value if namespace is empty as well as adds a method to construct the object from a string.
1 parent ed1c5d9 commit f53d2c3

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

pkg/controller/types/types.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,17 @@ type ReconcileKey struct {
3737
}
3838

3939
func (r ReconcileKey) String() string {
40+
if r.Namespace == "" {
41+
return r.Name
42+
}
4043
return r.Namespace + "/" + r.Name
4144
}
45+
46+
// ParseReconcileKey returns the ReconcileKey that has been encoded into a string.
47+
func ParseReconcileKey(key string) (ReconcileKey, error) {
48+
namespace, name, err := cache.SplitMetaNamespaceKey(key)
49+
if err != nil {
50+
return ReconcileKey{}, err
51+
}
52+
return ReconcileKey{Name: name, Namespace: namespace}, nil
53+
}

0 commit comments

Comments
 (0)