From f53d2c34f5785832f0c84d77f0ac8e61b890e8c6 Mon Sep 17 00:00:00 2001 From: Brian Thomas Kennedy Date: Mon, 2 Apr 2018 17:05:43 -0700 Subject: [PATCH] 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. --- pkg/controller/types/types.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pkg/controller/types/types.go b/pkg/controller/types/types.go index 29abaf2e48..10411e41e1 100644 --- a/pkg/controller/types/types.go +++ b/pkg/controller/types/types.go @@ -37,5 +37,17 @@ type ReconcileKey struct { } func (r ReconcileKey) String() string { + if r.Namespace == "" { + return r.Name + } return r.Namespace + "/" + r.Name } + +// ParseReconcileKey returns the ReconcileKey that has been encoded into a string. +func ParseReconcileKey(key string) (ReconcileKey, error) { + namespace, name, err := cache.SplitMetaNamespaceKey(key) + if err != nil { + return ReconcileKey{}, err + } + return ReconcileKey{Name: name, Namespace: namespace}, nil +}