pkg/skel: improve error message for missing CNI_COMMAND env var

This makes the error message for missing CNI_COMMAND consistent with
that of other required environment variables.
This commit is contained in:
Gabe Rosenhouse 2016-07-13 22:54:22 -04:00
parent c17e700759
commit f436418525
2 changed files with 7 additions and 5 deletions

View File

@ -106,11 +106,13 @@ func (t *dispatcher) getCmdArgsFromEnv() (string, *CmdArgs, error) {
argsMissing := false argsMissing := false
for _, v := range vars { for _, v := range vars {
*v.val = t.Getenv(v.name) *v.val = t.Getenv(v.name)
if v.reqForCmd[cmd] && *v.val == "" { if *v.val == "" {
if v.reqForCmd[cmd] || v.name == "CNI_COMMAND" {
fmt.Fprintf(t.Stderr, "%v env variable missing\n", v.name) fmt.Fprintf(t.Stderr, "%v env variable missing\n", v.name)
argsMissing = true argsMissing = true
} }
} }
}
if argsMissing { if argsMissing {
return "", nil, fmt.Errorf("required env variables missing") return "", nil, fmt.Errorf("required env variables missing")

View File

@ -115,7 +115,7 @@ var _ = Describe("dispatching to the correct callback", func() {
}) })
DescribeTable("required / optional env vars", envVarChecker, DescribeTable("required / optional env vars", envVarChecker,
// TODO: Entry("command", "CNI_COMMAND", true), Entry("command", "CNI_COMMAND", true),
Entry("container id", "CNI_CONTAINER_ID", false), Entry("container id", "CNI_CONTAINER_ID", false),
Entry("net ns", "CNI_NETNS", true), Entry("net ns", "CNI_NETNS", true),
Entry("if name", "CNI_IFNAME", true), Entry("if name", "CNI_IFNAME", true),
@ -162,7 +162,7 @@ var _ = Describe("dispatching to the correct callback", func() {
}) })
DescribeTable("required / optional env vars", envVarChecker, DescribeTable("required / optional env vars", envVarChecker,
// TODO: Entry("command", "CNI_COMMAND", true), Entry("command", "CNI_COMMAND", true),
Entry("container id", "CNI_CONTAINER_ID", false), Entry("container id", "CNI_CONTAINER_ID", false),
Entry("net ns", "CNI_NETNS", false), Entry("net ns", "CNI_NETNS", false),
Entry("if name", "CNI_IFNAME", true), Entry("if name", "CNI_IFNAME", true),