drone-kuboard/main.go
2023-10-17 16:46:41 +08:00

111 lines
2.4 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package main
import (
"github.com/urfave/cli/v2"
"log"
"os"
"strings"
)
type payload struct {
Kind string `json:"kind"`
Name string `json:"name"`
Namespace string `json:"namespace"`
Images map[string]string `json:"images,omitempty"`
}
type errorResponse struct {
Reason string
}
func main() {
// 默认是重启
action := restart
// 判断是啥操作
if actionKey := os.Getenv("PLUGIN_ACTION"); actionKey != "" {
switch strings.ToLower(actionKey) {
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
}
}
app := &cli.App{
Name: "drone-kuboard",
Usage: "Update Kuboard Workloads Image Tag",
Authors: []*cli.Author{
&cli.Author{
Name: "lxh",
Email: "lxh@cxh.cn",
},
},
Action: action,
Flags: []cli.Flag{
&cli.StringFlag{
Required: true,
Name: "cluster",
Usage: "cluster name",
EnvVars: []string{"PLUGIN_CLUSTER"},
},
&cli.StringFlag{
Required: true,
Name: "kind",
Usage: "workload type",
EnvVars: []string{"PLUGIN_KIND"},
},
&cli.StringFlag{
Required: true,
Name: "name",
Usage: "workload name",
EnvVars: []string{"PLUGIN_NAME"},
},
&cli.StringFlag{
Required: true,
Name: "namespace",
Usage: "workload namespace",
EnvVars: []string{"PLUGIN_NAMESPACE"},
},
&cli.StringFlag{
Name: "image",
Usage: "image uri",
EnvVars: []string{"PLUGIN_IMAGE"},
},
&cli.StringFlag{
Name: "tag",
Usage: "image tag",
EnvVars: []string{"PLUGIN_TAG"},
},
&cli.StringFlag{
Required: true,
Name: "kuboard_uri",
Usage: "kuboard uri",
EnvVars: []string{"PLUGIN_KUBOARD_URI"},
},
&cli.StringFlag{
Required: true,
Name: "kuboard_username",
Usage: "kuboard username",
EnvVars: []string{"PLUGIN_KUBOARD_USERNAME"},
},
&cli.StringFlag{
Required: true,
Name: "kuboard_key",
Usage: "kuboard access key",
EnvVars: []string{"PLUGIN_KUBOARD_KEY"},
},
},
}
if err := app.Run(os.Args); err != nil {
log.Fatal(err)
}
log.Println("The image version was successfully updated.")
}