Return error for empty sysctl names
This commit is contained in:
parent
e258d0bc4b
commit
e6acc08d96
@ -577,7 +577,7 @@ func SysctlsFromPodAnnotation(annotation string) ([]Sysctl, error) {
|
|||||||
sysctls := make([]Sysctl, len(kvs))
|
sysctls := make([]Sysctl, len(kvs))
|
||||||
for i, kv := range kvs {
|
for i, kv := range kvs {
|
||||||
cs := strings.Split(kv, "=")
|
cs := strings.Split(kv, "=")
|
||||||
if len(cs) != 2 {
|
if len(cs) != 2 || len(cs[0]) == 0 {
|
||||||
return nil, fmt.Errorf("sysctl %q not of the format sysctl_name=value", kv)
|
return nil, fmt.Errorf("sysctl %q not of the format sysctl_name=value", kv)
|
||||||
}
|
}
|
||||||
sysctls[i].Name = cs[0]
|
sysctls[i].Name = cs[0]
|
||||||
|
@ -508,6 +508,14 @@ func TestSysctlsFromPodAnnotation(t *testing.T) {
|
|||||||
annotation: "foo.bar",
|
annotation: "foo.bar",
|
||||||
expectErr: true,
|
expectErr: true,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
annotation: "=123",
|
||||||
|
expectErr: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
annotation: "foo.bar=",
|
||||||
|
expectValue: []Sysctl{{Name: "foo.bar", Value: ""}},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
annotation: "foo.bar=42",
|
annotation: "foo.bar=42",
|
||||||
expectValue: []Sysctl{{Name: "foo.bar", Value: "42"}},
|
expectValue: []Sysctl{{Name: "foo.bar", Value: "42"}},
|
||||||
|
Loading…
Reference in New Issue
Block a user