Skip to content

Commit

Permalink
make "selector" to be map of strings internally, so config file will …
Browse files Browse the repository at this point in the history
…accept a map rather than a string
  • Loading branch information
den-is committed Jun 7, 2020
1 parent 73b51eb commit 77effd2
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 7 deletions.
2 changes: 1 addition & 1 deletion cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func init() {

rootCmd.Flags().StringP("kubeconfig", "k", "", "path to kubeconfig (default is \"~/.kube/config\")")
rootCmd.Flags().StringP("namespace", "n", "", "used with -p. kubernetes namespace indicator (default is \"\" or what is provided in kubeconfig. usually \"default\")")
rootCmd.Flags().StringP("selector", "l", "", "kubernetes label selectors (default is \"\" a.k.a everything)")
rootCmd.Flags().StringToStringP("selector", "l", nil, "kubernetes label selectors (default is \"\" a.k.a everything)")
rootCmd.Flags().StringP("template", "t", "", "input template file. Required")
rootCmd.Flags().StringP("output", "o", "", "output file path (default stdout)")
rootCmd.Flags().DurationP("interval", "i", defaultDuration, "used with -d. interval between polls (default 15s)")
Expand Down
7 changes: 6 additions & 1 deletion examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,18 @@
interval: 30s
permissions: 0640

template: examples/example.tpl

selector:
app: coolweb
environment: production

log:
file: ktempl.log

values:
title: Example
port: 32835

```
## Couple template examples
Expand Down
6 changes: 6 additions & 0 deletions examples/config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
interval: 30s
permissions: 0640

template: examples/example.tpl

selector:
app: coolweb
environment: production

log:
file: ktempl.log

Expand Down
8 changes: 4 additions & 4 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ import (

type Config struct {
Kubeconfig string
Timeout string
Retries int
Selector string
Namespace string
Selector map[string]string
Pods bool
Template string
Output string
Permissions uint32
Interval time.Duration
Exec string
Values map[string]interface{}
Daemon bool
Pods bool
Timeout string
Retries int
Log logging.LoggingConfig
}

Expand Down
16 changes: 16 additions & 0 deletions pkg/render/helpers.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package render

import (
"fmt"
"os"
"strings"

Expand Down Expand Up @@ -30,3 +31,18 @@ func StringSliceToStringMap(s []string) map[string]string {
return result

}

func StringifyStringsMap(m map[string]string) string {

if m == nil {
return ""
}

var s []string
for k, v := range m {
s = append(s, fmt.Sprintf("%s=%s", k, v))
}

return strings.Join(s, ",")

}
2 changes: 1 addition & 1 deletion pkg/worker/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func Worker() {

kubeconfig := viper.GetString("kubeconfig")
namespace := viper.GetString("namespace")
selector := viper.GetString("selector")
selector := render.StringifyStringsMap(viper.GetStringMapString("selector"))
output := viper.GetString("output")
usePods := viper.GetBool("pods")

Expand Down

0 comments on commit 77effd2

Please sign in to comment.