feat: add support for specifying annotations
As the command contains a colon, it must be handled in the commands binary as opposed to subcommands. Also include a simple bats test.
This commit is contained in:
@@ -1,13 +1,15 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/dokku/dokku/plugins/common"
|
||||
scheduler_k3s "github.com/dokku/dokku/plugins/scheduler-k3s"
|
||||
|
||||
flag "github.com/spf13/pflag"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -18,6 +20,7 @@ Manage scheduler-k3s settings for an app
|
||||
Additional commands:`
|
||||
|
||||
helpContent = `
|
||||
scheduler-k3s:annotations:set <app|--global> <property> (<value>) [--process-type PROCESS_TYPE] <--resource-type RESOURCE_TYPE>, Set or clear an annotation for a given app/process-type/resource-type combination
|
||||
scheduler-k3s:cluster-add [--insecure-allow-unknown-hosts] [--server-ip SERVER_IP] [--taint-scheduling] <ssh://user@host:port>, Adds a server node to a Dokku-managed cluster
|
||||
scheduler-k3s:cluster-list [--format json|stdout], Lists all nodes in a Dokku-managed cluster
|
||||
scheduler-k3s:cluster-remove [node-id], Removes client node to a Dokku-managed cluster
|
||||
@@ -30,10 +33,11 @@ Additional commands:`
|
||||
)
|
||||
|
||||
func main() {
|
||||
flag.Usage = usage
|
||||
flag.Parse()
|
||||
cmd := ""
|
||||
if len(os.Args) > 1 {
|
||||
cmd = os.Args[1]
|
||||
}
|
||||
|
||||
cmd := flag.Arg(0)
|
||||
switch cmd {
|
||||
case "scheduler-k3s", "scheduler-k3s:help":
|
||||
usage()
|
||||
@@ -47,6 +51,28 @@ func main() {
|
||||
} else {
|
||||
fmt.Print("\n scheduler-k3s, Manage scheduler-k3s settings for an app\n")
|
||||
}
|
||||
case "scheduler-k3s:annotations:set":
|
||||
args := flag.NewFlagSet("scheduler-k3s:annotations:set", flag.ExitOnError)
|
||||
global := args.Bool("global", false, "--global: set a global property")
|
||||
processType := args.String("process-type", "", "--process-type: scope to process-type")
|
||||
resourceType := args.String("resource-type", "", "--resource-type: scope to resource-type")
|
||||
err := args.Parse(os.Args[2:])
|
||||
if err != nil {
|
||||
common.LogFailWithError(err)
|
||||
}
|
||||
|
||||
appName := args.Arg(0)
|
||||
property := args.Arg(1)
|
||||
value := args.Arg(2)
|
||||
if *global {
|
||||
appName = "--global"
|
||||
property = args.Arg(0)
|
||||
value = args.Arg(1)
|
||||
}
|
||||
|
||||
if err := scheduler_k3s.CommandAnnotationsSet(appName, *processType, *resourceType, property, value); err != nil {
|
||||
common.LogFailWithError(err)
|
||||
}
|
||||
default:
|
||||
dokkuNotImplementExitCode, err := strconv.Atoi(os.Getenv("DOKKU_NOT_IMPLEMENTED_EXIT"))
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user