Skip to content

Commit

Permalink
Switch kmeta/labels to use metav1.ObjectMetaAccessor (knative#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattmoor authored and knative-prow-robot committed Sep 13, 2018
1 parent 5f353e5 commit d14ed38
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
14 changes: 7 additions & 7 deletions kmeta/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,27 +42,27 @@ import (
// MakeVersionLabels constructs a set of labels to apply to subresources
// instantiated at this version of the parent resource, so that we can
// efficiently select them.
func MakeVersionLabels(om metav1.ObjectMeta) labels.Set {
func MakeVersionLabels(om metav1.ObjectMetaAccessor) labels.Set {
return map[string]string{
"controller": string(om.UID),
"version": om.ResourceVersion,
"controller": string(om.GetObjectMeta().GetUID()),
"version": om.GetObjectMeta().GetResourceVersion(),
}
}

// MakeVersionLabelSelector constructs a selector for subresources
// instantiated at this version of the parent resource. This keys
// off of the labels populated by MakeVersionLabels.
func MakeVersionLabelSelector(om metav1.ObjectMeta) labels.Selector {
func MakeVersionLabelSelector(om metav1.ObjectMetaAccessor) labels.Selector {
return labels.SelectorFromSet(MakeVersionLabels(om))
}

// MakeOldVersionLabelSelector constructs a selector for subresources
// instantiated at an older version of the parent resource. This keys
// off of the labels populated by MakeVersionLabels.
func MakeOldVersionLabelSelector(om metav1.ObjectMeta) labels.Selector {
func MakeOldVersionLabelSelector(om metav1.ObjectMetaAccessor) labels.Selector {
return labels.NewSelector().Add(
mustNewRequirement("controller", selection.Equals, []string{string(om.UID)}),
mustNewRequirement("version", selection.NotEquals, []string{om.ResourceVersion}),
mustNewRequirement("controller", selection.Equals, []string{string(om.GetObjectMeta().GetUID())}),
mustNewRequirement("version", selection.NotEquals, []string{om.GetObjectMeta().GetResourceVersion()}),
)
}

Expand Down
6 changes: 3 additions & 3 deletions kmeta/labels_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func TestMakeVersionLabels(t *testing.T) {

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
ls := MakeVersionLabels(test.om)
ls := MakeVersionLabels(&test.om)
if want, got := test.s, ls.String(); got != want {
t.Errorf("MakeVersionLabels() = %v, wanted %v", got, want)
}
Expand Down Expand Up @@ -76,7 +76,7 @@ func TestMakeVersionLabelSelector(t *testing.T) {

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
ls := MakeVersionLabelSelector(test.om)
ls := MakeVersionLabelSelector(&test.om)
if want, got := test.s, ls.String(); got != want {
t.Errorf("MakeVersionLabelSelector() = %v, wanted %v", got, want)
}
Expand Down Expand Up @@ -107,7 +107,7 @@ func TestMakeOldVersionLabelSelector(t *testing.T) {

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
ls := MakeOldVersionLabelSelector(test.om)
ls := MakeOldVersionLabelSelector(&test.om)
if want, got := test.s, ls.String(); got != want {
t.Errorf("MakeOldVersionLabelSelector() = %v, wanted %v", got, want)
}
Expand Down

0 comments on commit d14ed38

Please sign in to comment.