feat: implement autoscaling-auth:report

This commit is contained in:
Jose Diaz-Gonzalez
2024-03-06 00:33:45 -05:00
parent 5b0bc0b132
commit 6b74cd1d6b
5 changed files with 76 additions and 9 deletions

View File

@@ -6,6 +6,7 @@
```
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:autoscaling-auth:set <app|--global> <trigger> [<--metadata key=value>...], Set or clear a scheduler-k3s autoscaling keda trigger authentication resource for an app
scheduler-k3s:autoscaling-auth:report <app|--global> [--format stdout|json] [--include-metadata] # Displays a scheduler-k3s autoscaling auth report for an app
scheduler-k3s:cluster-add [ssh://user@host:port] # Adds a server node to a Dokku-managed cluster
scheduler-k3s:cluster-list # Lists all nodes in a Dokku-managed cluster
scheduler-k3s:cluster-remove [node-id] # Removes client node to a Dokku-managed cluster
@@ -433,7 +434,7 @@ If the `--global` flag is specified instead of an app name, a custom helm chart
##### Removing Authentication Resources
To remove a configured authenticatin resource, run the `scheduler-k3s:autoscaling-auth:set` command with no parameters specified. Subsequent deploys will not include these resources.
To remove a configured authenticatin resource, run the `scheduler-k3s:autoscaling-auth:set` command with no metadata specified. Subsequent deploys will not include these resources.
```shell
dokku scheduler-k3s:autoscaling-auth:set $APP $TRIGGER_TYPE
@@ -444,7 +445,7 @@ dokku scheduler-k3s:autoscaling-auth:set $APP $TRIGGER_TYPE
To see a list of authentication resources managed by Dokku, run the `scheduler-k3s:autoscaling-auth:report` command.
```shell
dokku scheduler-k3s:autoscaling-auth:report $APP
dokku scheduler-k3s:autoscaling-auth:report node-js-app
```
```
@@ -452,17 +453,18 @@ dokku scheduler-k3s:autoscaling-auth:report $APP
datadog: configured
```
By default, the report will not display configured parameters - making it safe to include in Dokku report output. To include parameters, add the `--include-parameters` flag:
By default, the report will not display configured metadata - making it safe to include in Dokku report output. To include metadata and their values, add the `--include-metadata` flag:
```shell
dokku scheduler-k3s:autoscaling-auth:report $APP --include-parameters
dokku scheduler-k3s:autoscaling-auth:report node-js-app --include-metadata
```
```
====> $APP autoscaling-auth report
datadog: configured
datadog-apiKey: some-api-key
datadog-appKey: some-app-key
====> node-js-app autoscaling-auth report
Datadog: configured
Datadog apiKey: 1234567890
Datadog appKey: asdfghjkl
Datadog datadogSite: us5.datadoghq.com
```
### Using kubectl remotely

View File

@@ -1,4 +1,4 @@
SUBCOMMANDS = subcommands/annotations:set subcommands/autoscaling-auth:set subcommands/cluster-add subcommands/cluster-list subcommands/cluster-remove subcommands/initialize subcommands/labels:set subcommands/report subcommands/set subcommands/show-kubeconfig subcommands/uninstall
SUBCOMMANDS = subcommands/annotations:set subcommands/autoscaling-auth:set subcommands/autoscaling-auth:report subcommands/cluster-add subcommands/cluster-list subcommands/cluster-remove subcommands/initialize subcommands/labels:set subcommands/report subcommands/set subcommands/show-kubeconfig subcommands/uninstall
TRIGGERS = triggers/install triggers/post-app-clone-setup triggers/post-app-rename-setup triggers/post-delete triggers/report triggers/scheduler-deploy triggers/scheduler-enter triggers/scheduler-logs triggers/scheduler-post-delete triggers/scheduler-run triggers/scheduler-run-list triggers/scheduler-stop
BUILD = commands subcommands triggers
PLUGIN_NAME = scheduler-k3s

View File

@@ -1,6 +1,9 @@
package scheduler_k3s
import (
"fmt"
"strings"
"github.com/dokku/dokku/plugins/common"
)
@@ -45,6 +48,37 @@ func ReportSingleApp(appName string, format string, infoFlag string) error {
return common.ReportSingleApp("scheduler-k3s", appName, infoFlag, infoFlags, flagKeys, format, trimPrefix, uppercaseFirstCharacter)
}
// ReportAutoscalingAuthSingleApp is an internal function that displays the scheduler-k3s autoscaling-auth report for one app
func ReportAutoscalingAuthSingleApp(appName string, format string, includeMetadata bool) error {
properties, err := common.PropertyGetAllByPrefix("scheduler-k3s", appName, TriggerAuthPropertyPrefix)
if err != nil {
return fmt.Errorf("Unable to get property list: %w", err)
}
infoFlags := map[string]string{}
for key, value := range properties {
metadataKey := strings.TrimPrefix(key, TriggerAuthPropertyPrefix)
authType := strings.SplitN(metadataKey, ".", 2)[0]
if authType == "" {
continue
}
infoFlags[authType] = "configured"
if includeMetadata {
infoFlags[strings.ReplaceAll(metadataKey, ".", "-")] = value
}
}
flagKeys := []string{}
for flagKey := range infoFlags {
flagKeys = append(flagKeys, flagKey)
}
trimPrefix := false
uppercaseFirstCharacter := true
return common.ReportSingleApp("scheduler-k3s", appName, "", infoFlags, flagKeys, format, trimPrefix, uppercaseFirstCharacter)
}
func reportComputedDeployTimeout(appName string) string {
return getComputedDeployTimeout(appName)
}

View File

@@ -46,6 +46,14 @@ func main() {
trigger = args.Arg(0)
}
err = scheduler_k3s.CommandAutoscalingAuthSet(appName, trigger, *metadata, *global)
case "autoscaling-auth:report":
args := flag.NewFlagSet("scheduler-k3s:autoscaling-auth:report", flag.ExitOnError)
global := args.Bool("global", false, "--global: show a global report")
includeMetadata := args.Bool("include-metadata", false, "--include-metadata: include metadata in the report")
format := args.String("format", "stdout", "format: [ stdout | json ]")
args.Parse(os.Args[2:])
appName := args.Arg(0)
err = scheduler_k3s.CommandAutoscalingAuthReport(appName, *format, *global, *includeMetadata)
case "cluster-add":
args := flag.NewFlagSet("scheduler-k3s:cluster-add", flag.ExitOnError)
allowUknownHosts := args.Bool("insecure-allow-unknown-hosts", false, "insecure-allow-unknown-hosts: allow unknown hosts")

View File

@@ -86,6 +86,29 @@ func CommandAutoscalingAuthSet(appName string, trigger string, metadata map[stri
return nil
}
// CommandAutoscalingAuthReport displays a scheduler-k3s autoscaling keda trigger authentication report for one or more apps
func CommandAutoscalingAuthReport(appName string, format string, global bool, includeMetadata bool) error {
if len(appName) == 0 && !global {
return fmt.Errorf("Missing required app name or --global flag")
}
if len(appName) > 0 && global {
return fmt.Errorf("Cannot specify both app name and --global flag")
}
if !global {
if err := common.VerifyAppName(appName); err != nil {
return err
}
}
if len(appName) > 0 {
return ReportAutoscalingAuthSingleApp(appName, format, includeMetadata)
}
return ReportAutoscalingAuthSingleApp("--global", format, includeMetadata)
}
// CommandInitialize initializes a k3s cluster on the local server
func CommandInitialize(ingressClass string, serverIP string, taintScheduling bool) error {
if ingressClass != "nginx" && ingressClass != "traefik" {