Skip to content

Commit

Permalink
Fix some issues in types.ReconcileKey
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
briantkennedy committed Apr 4, 2018
1 parent ed1c5d9 commit f53d2c3
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pkg/controller/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit f53d2c3

Please sign in to comment.