From 14250ad7ae3dd36279746aeaffa5cee024dfbbaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=AF=BB=E6=AC=A2?= Date: Tue, 17 Oct 2023 16:46:41 +0800 Subject: [PATCH] :bug: Fix a bug. --- main.go | 54 +++++++++++++++++++++++++++++++++--------------------- 1 file changed, 33 insertions(+), 21 deletions(-) diff --git a/main.go b/main.go index dd10a93..96ed084 100644 --- a/main.go +++ b/main.go @@ -27,6 +27,11 @@ func main() { case "restart": action = restart case "update": + // 如果image和tag有空值,报错 + if os.Getenv("PLUGIN_IMAGE") == "" || os.Getenv("PLUGIN_TAG") == "" { + panic("Configuration item image or tag must not be empty") + return + } action = update } } @@ -43,24 +48,28 @@ func main() { Action: action, Flags: []cli.Flag{ &cli.StringFlag{ - Name: "cluster", - Usage: "cluster name", - EnvVars: []string{"PLUGIN_CLUSTER"}, + Required: true, + Name: "cluster", + Usage: "cluster name", + EnvVars: []string{"PLUGIN_CLUSTER"}, }, &cli.StringFlag{ - Name: "kind", - Usage: "workload type", - EnvVars: []string{"PLUGIN_KIND"}, + Required: true, + Name: "kind", + Usage: "workload type", + EnvVars: []string{"PLUGIN_KIND"}, }, &cli.StringFlag{ - Name: "name", - Usage: "workload name", - EnvVars: []string{"PLUGIN_NAME"}, + Required: true, + Name: "name", + Usage: "workload name", + EnvVars: []string{"PLUGIN_NAME"}, }, &cli.StringFlag{ - Name: "namespace", - Usage: "workload namespace", - EnvVars: []string{"PLUGIN_NAMESPACE"}, + Required: true, + Name: "namespace", + Usage: "workload namespace", + EnvVars: []string{"PLUGIN_NAMESPACE"}, }, &cli.StringFlag{ Name: "image", @@ -73,19 +82,22 @@ func main() { EnvVars: []string{"PLUGIN_TAG"}, }, &cli.StringFlag{ - Name: "kuboard_uri", - Usage: "kuboard uri", - EnvVars: []string{"PLUGIN_KUBOARD_URI"}, + Required: true, + Name: "kuboard_uri", + Usage: "kuboard uri", + EnvVars: []string{"PLUGIN_KUBOARD_URI"}, }, &cli.StringFlag{ - Name: "kuboard_username", - Usage: "kuboard username", - EnvVars: []string{"PLUGIN_KUBOARD_USERNAME"}, + Required: true, + Name: "kuboard_username", + Usage: "kuboard username", + EnvVars: []string{"PLUGIN_KUBOARD_USERNAME"}, }, &cli.StringFlag{ - Name: "kuboard_key", - Usage: "kuboard access key", - EnvVars: []string{"PLUGIN_KUBOARD_KEY"}, + Required: true, + Name: "kuboard_key", + Usage: "kuboard access key", + EnvVars: []string{"PLUGIN_KUBOARD_KEY"}, }, }, }