Skip to content

Commit

Permalink
fix label key expression formating
Browse files Browse the repository at this point in the history
  • Loading branch information
dbenque committed Sep 21, 2020
1 parent d92f02b commit 231ab8c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion internal/kubernetes/nodefilters.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func ConvertLabelsToFilterExpr(labels map[string]string) *string {
if k != "" && labels[k] == "" {
res = append(res, fmt.Sprintf(`'%s' in metadata.labels`, k))
} else {
res = append(res, fmt.Sprintf(`metadata.labels.%s == '%s'`, k, labels[k]))
res = append(res, fmt.Sprintf(`metadata.labels['%s'] == '%s'`, k, labels[k]))
}
}
temp := strings.Join(res, " && ")
Expand Down
13 changes: 12 additions & 1 deletion internal/kubernetes/nodefilters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,17 @@ func TestOldNodeLabelFilter(t *testing.T) {
labels: map[string]string{"cool": "very"},
passesFilter: true,
},
{
name: "SingleMatchingLabel.WithDomain",
obj: &core.Node{
ObjectMeta: meta.ObjectMeta{
Name: nodeName,
Labels: map[string]string{"planetlabs.com/cool": "very"},
},
},
labels: map[string]string{"planetlabs.com/cool": "very"},
passesFilter: true,
},
{
name: "ManyMatchingLabels",
obj: &core.Node{
Expand Down Expand Up @@ -431,7 +442,7 @@ func TestConvertLabelsToFilterExpr(t *testing.T) {
"sup": "cool",
}

desired := "metadata.labels.foo == 'bar' && metadata.labels.sup == 'cool'"
desired := "metadata.labels['foo'] == 'bar' && metadata.labels['sup'] == 'cool'"
actual := ConvertLabelsToFilterExpr(input)

assert.Equal(t, desired, *actual)
Expand Down

0 comments on commit 231ab8c

Please sign in to comment.