Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

node-expr fails on valid labels #120

Open
jabbrwcky opened this issue Oct 4, 2021 · 0 comments
Open

node-expr fails on valid labels #120

jabbrwcky opened this issue Oct 4, 2021 · 0 comments

Comments

@jabbrwcky
Copy link

jabbrwcky commented Oct 4, 2021

the nexpression parser used for node-expr fails - or even worse panics - on several classes of valid node labels, e.g.

draino-enabled=true, kubernetes.io/os=linux ordraino="true". (Examples below)

So either a different expression parser would be nice or at least adding a caveat to the documentation.

Some snippts to try in nodefilter_test.go:

{
	name: "ParseBoolean",
	obj: &core.Node{
		ObjectMeta: meta.ObjectMeta{
			Name:   nodeName,
			Labels: map[string]string{"metadata.labels.draino-enabled": "true"},
		},
	},
	expression:   "metadata.labels.draino-enabled == 'true'",
	passesFilter: true,
},

blows up completely

Running tool: /opt/homebrew/bin/go test -timeout 30s -run ^TestNodeLabelFilter$ github.com/planetlabs/draino/internal/kubernetes

2021-10-04T18:08:40.204+0200	ERROR	kubernetes/nodefilters.go:62	Could not parse expression: invalid operation: string - <nil> (1:23)
 | metadata.labels.draino-enabled == 'true'
 | ......................^
github.com/planetlabs/draino/internal/kubernetes.NewNodeLabelFilter.func1
	/Users/jenshausherr/src/draino/internal/kubernetes/nodefilters.go:62
github.com/planetlabs/draino/internal/kubernetes.TestNodeLabelFilter.func1
	/Users/jenshausherr/src/draino/internal/kubernetes/nodefilters_test.go:235
testing.tRunner
	/opt/homebrew/Cellar/go/1.17.1/libexec/src/testing/testing.go:1259
--- FAIL: TestNodeLabelFilter (0.00s)
    --- FAIL: TestNodeLabelFilter/Panics (0.00s)
panic: interface conversion: interface {} is nil, not bool [recovered]
	panic: interface conversion: interface {} is nil, not bool

goroutine 6 [running]:
testing.tRunner.func1.2({0x101122d60, 0x1400041f4d0})
	/opt/homebrew/Cellar/go/1.17.1/libexec/src/testing/testing.go:1209 +0x258
testing.tRunner.func1(0x1400044a1a0)
	/opt/homebrew/Cellar/go/1.17.1/libexec/src/testing/testing.go:1212 +0x284
panic({0x101122d60, 0x1400041f4d0})
	/opt/homebrew/Cellar/go/1.17.1/libexec/src/runtime/panic.go:1038 +0x21c
github.com/planetlabs/draino/internal/kubernetes.NewNodeLabelFilter.func1({0x1012192e0, 0x140002e3340})
	/Users/jenshausherr/src/draino/internal/kubernetes/nodefilters.go:64 +0x238
github.com/planetlabs/draino/internal/kubernetes.TestNodeLabelFilter.func1(0x1400044a1a0)
	/Users/jenshausherr/src/draino/internal/kubernetes/nodefilters_test.go:235 +0xc8
testing.tRunner(0x1400044a1a0, 0x1400000e918)
	/opt/homebrew/Cellar/go/1.17.1/libexec/src/testing/testing.go:1259 +0x104
created by testing.(*T).Run
	/opt/homebrew/Cellar/go/1.17.1/libexec/src/testing/testing.go:1306 +0x328
FAIL	github.com/planetlabs/draino/internal/kubernetes	0.119s
FAIL

as well as

{
	name: "AlsoPanics",
	obj: &core.Node{
		ObjectMeta: meta.ObjectMeta{
			Name:   nodeName,
			Labels: map[string]string{"metadata.labels.kubernetes.io/os": "linux"},
		},
	},
	expression:   "metadata.labels.kubernetes.io/os == 'linux'",
	passesFilter: true,
},
Running tool: /opt/homebrew/bin/go test -timeout 30s -run ^TestNodeLabelFilter$ github.com/planetlabs/draino/internal/kubernetes

2021-10-04T18:10:38.596+0200	ERROR	kubernetes/nodefilters.go:62	Could not parse expression: invalid operation: int(string) (1:28)
 | metadata.labels.kubernetes.io/os == 'linux'
 | ...........................^
github.com/planetlabs/draino/internal/kubernetes.NewNodeLabelFilter.func1
	/Users/jenshausherr/src/draino/internal/kubernetes/nodefilters.go:62
github.com/planetlabs/draino/internal/kubernetes.TestNodeLabelFilter.func1
	/Users/jenshausherr/src/draino/internal/kubernetes/nodefilters_test.go:246
testing.tRunner
	/opt/homebrew/Cellar/go/1.17.1/libexec/src/testing/testing.go:1259
--- FAIL: TestNodeLabelFilter (0.00s)
    --- FAIL: TestNodeLabelFilter/AlsoPanics (0.00s)
panic: interface conversion: interface {} is nil, not bool [recovered]
	panic: interface conversion: interface {} is nil, not bool

goroutine 6 [running]:
testing.tRunner.func1.2({0x101502d60, 0x140004054a0})
	/opt/homebrew/Cellar/go/1.17.1/libexec/src/testing/testing.go:1209 +0x258
testing.tRunner.func1(0x140004301a0)
	/opt/homebrew/Cellar/go/1.17.1/libexec/src/testing/testing.go:1212 +0x284
panic({0x101502d60, 0x140004054a0})
	/opt/homebrew/Cellar/go/1.17.1/libexec/src/runtime/panic.go:1038 +0x21c
github.com/planetlabs/draino/internal/kubernetes.NewNodeLabelFilter.func1({0x1015f92e0, 0x14000249340})
	/Users/jenshausherr/src/draino/internal/kubernetes/nodefilters.go:64 +0x238
github.com/planetlabs/draino/internal/kubernetes.TestNodeLabelFilter.func1(0x140004301a0)
	/Users/jenshausherr/src/draino/internal/kubernetes/nodefilters_test.go:246 +0xc8
testing.tRunner(0x140004301a0, 0x1400000e918)
	/opt/homebrew/Cellar/go/1.17.1/libexec/src/testing/testing.go:1259 +0x104
created by testing.(*T).Run
	/opt/homebrew/Cellar/go/1.17.1/libexec/src/testing/testing.go:1306 +0x328
FAIL	github.com/planetlabs/draino/internal/kubernetes	0.403s
FAIL
{
	name: "ParseBoolean",
	obj: &core.Node{
		ObjectMeta: meta.ObjectMeta{
			Name:   nodeName,
			Labels: map[string]string{"metadata.labels.draino": "true"},
		},
	},
	expression:   "metadata.labels.draino == 'true'",
	passesFilter: true,
},

also fails:

Running tool: /opt/homebrew/bin/go test -timeout 30s -run ^TestNodeLabelFilter$ github.com/planetlabs/draino/internal/kubernetes

--- FAIL: TestNodeLabelFilter (0.00s)
    --- FAIL: TestNodeLabelFilter/ParseBoolean (0.00s)
        /Users/jenshausherr/src/draino/internal/kubernetes/nodefilters_test.go:236: 
            	Error Trace:	nodefilters_test.go:236
            	Error:      	Not equal: 
            	            	expected: true
            	            	actual  : false
            	Test:       	TestNodeLabelFilter/ParseBoolean
FAIL
FAIL	github.com/planetlabs/draino/internal/kubernetes	0.118s
FAIL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant