Allow more characters in label selectors (#2064)
Label selectors also allows ".", "/" and "+" now Fixes #970
This commit is contained in:
parent
1d4d67fd56
commit
0105ed4df3
|
|
@ -54,8 +54,8 @@ func ParseLabels(l string) (LabelFilter, error) {
|
||||||
lf.negativeLabels = [][]string{}
|
lf.negativeLabels = [][]string{}
|
||||||
var err error
|
var err error
|
||||||
labels := strings.Split(l, ",")
|
labels := strings.Split(l, ",")
|
||||||
reMissmatch := regexp.MustCompile("^[a-zA-Z0-9_-]+!=[a-zA-Z0-9_-]+$")
|
reMissmatch := regexp.MustCompile(`^[a-zA-Z0-9_\.\/\+-]+!=[a-zA-Z0-9_\.\/\+-]+$`)
|
||||||
reMatch := regexp.MustCompile("^[a-zA-Z0-9_-]+=[a-zA-Z0-9_-]+$")
|
reMatch := regexp.MustCompile(`^[a-zA-Z0-9_\.\/\+-]+=[a-zA-Z0-9_\.\/\+-]+$`)
|
||||||
for _, label := range labels {
|
for _, label := range labels {
|
||||||
if match := reMissmatch.MatchString(label); match { // k!=v case
|
if match := reMissmatch.MatchString(label); match { // k!=v case
|
||||||
kv := strings.Split(label, "!=")
|
kv := strings.Split(label, "!=")
|
||||||
|
|
|
||||||
|
|
@ -22,22 +22,22 @@ func TestSelectReleasesWithOverrides(t *testing.T) {
|
||||||
{
|
{
|
||||||
subject: "multiple OR selectors (non-nillable label first)",
|
subject: "multiple OR selectors (non-nillable label first)",
|
||||||
selector: []string{"name=foo", "type!=bar"},
|
selector: []string{"name=foo", "type!=bar"},
|
||||||
want: []string{"nolabel1", "nolabel2", "foo"},
|
want: []string{"nolabel1", "nolabel2", "foo", "bar", "foobar"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
subject: "multiple AND conditions (nillable label first)",
|
subject: "multiple AND conditions (nillable label first)",
|
||||||
selector: []string{"type!=bar,name!=nolabel2"},
|
selector: []string{"type!=bar,name!=nolabel2"},
|
||||||
want: []string{"nolabel1"},
|
want: []string{"nolabel1", "bar", "foobar"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
subject: "multiple AND conditions (non-nillable label first)",
|
subject: "multiple AND conditions (non-nillable label first)",
|
||||||
selector: []string{"name!=nolabel2,type!=bar"},
|
selector: []string{"name!=nolabel2,type!=bar"},
|
||||||
want: []string{"nolabel1"},
|
want: []string{"nolabel1", "bar", "foobar"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
subject: "inequality on nillable label",
|
subject: "inequality on nillable label",
|
||||||
selector: []string{"type!=bar"},
|
selector: []string{"type!=bar"},
|
||||||
want: []string{"nolabel1", "nolabel2"},
|
want: []string{"nolabel1", "nolabel2", "bar", "foobar"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
subject: "equality on nillable label",
|
subject: "equality on nillable label",
|
||||||
|
|
@ -47,13 +47,33 @@ func TestSelectReleasesWithOverrides(t *testing.T) {
|
||||||
{
|
{
|
||||||
subject: "inequality on non-nillable label",
|
subject: "inequality on non-nillable label",
|
||||||
selector: []string{"name!=nolabel1"},
|
selector: []string{"name!=nolabel1"},
|
||||||
want: []string{"nolabel2", "foo"},
|
want: []string{"nolabel2", "foo", "bar", "foobar"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
subject: "equality on non-nillable label",
|
subject: "equality on non-nillable label",
|
||||||
selector: []string{"name=nolabel1"},
|
selector: []string{"name=nolabel1"},
|
||||||
want: []string{"nolabel1"},
|
want: []string{"nolabel1"},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
subject: "equality on non-alphabetic character label",
|
||||||
|
selector: []string{"version=1.2/3"},
|
||||||
|
want: []string{"bar"},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
subject: "equality on non-alphabetic character label",
|
||||||
|
selector: []string{"version=1.2.3+123"},
|
||||||
|
want: []string{"foobar"},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
subject: "inequality on non-alphatetic character label",
|
||||||
|
selector: []string{"version!=1.2/3"},
|
||||||
|
want: []string{"nolabel1", "nolabel2", "foo", "foobar"},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
subject: "inequality on non-alphatetic character label",
|
||||||
|
selector: []string{"version!=1.2.3+123"},
|
||||||
|
want: []string{"nolabel1", "nolabel2", "foo", "bar"},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
example := []byte(`releases:
|
example := []byte(`releases:
|
||||||
|
|
@ -68,6 +88,16 @@ func TestSelectReleasesWithOverrides(t *testing.T) {
|
||||||
chart: stable/foo
|
chart: stable/foo
|
||||||
labels:
|
labels:
|
||||||
type: bar
|
type: bar
|
||||||
|
- name: bar
|
||||||
|
namespace: kube-system
|
||||||
|
chart: stable/bar
|
||||||
|
labels:
|
||||||
|
version: 1.2/3
|
||||||
|
- name: foobar
|
||||||
|
namespace: kube-system
|
||||||
|
chart: stable/bar
|
||||||
|
labels:
|
||||||
|
version: 1.2.3+123
|
||||||
`)
|
`)
|
||||||
|
|
||||||
state := stateTestEnv{
|
state := stateTestEnv{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue