Skip to content

Commit

Permalink
agent: replace arrayFlags with tags.CommaSeparatedStrings
Browse files Browse the repository at this point in the history
  • Loading branch information
navigaid committed Mar 20, 2024
1 parent 992d713 commit 5c31510
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 30 deletions.
8 changes: 8 additions & 0 deletions go_repos.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -953,6 +953,14 @@ def go_repositories():
sum = "h1:tXLz7isF3VeSQGLZUQCWgaM5tZIbb78nn1QW9/nkI7s=",
version = "v0.0.1",
)
go_repository(
name = "com_github_btwiuse_tags",
build_file_generation = "on",
build_file_proto_mode = "disable",
importpath = "github.com/btwiuse/tags",
sum = "h1:TWL6rwde+Ye1Oa0X7kRQh33rdT+PmukOHWKnxxHSjIg=",
version = "v0.0.2",
)
go_repository(
name = "com_github_btwiuse_version",
build_file_generation = "on",
Expand Down
1 change: 1 addition & 0 deletions pkg/agent/config/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ go_library(
"//pkg/agent/info:go_default_library",
"@com_github_btwiuse_pretty//:go_default_library",
"@com_github_btwiuse_rng//:go_default_library",
"@com_github_btwiuse_tags//:go_default_library",
"@com_github_btwiuse_version//:go_default_library",
"@com_github_denisbrodbeck_machineid//:go_default_library",
"@in_gopkg_yaml_v3//:go_default_library",
Expand Down
44 changes: 15 additions & 29 deletions pkg/agent/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (

"github.com/btwiuse/pretty"
"github.com/btwiuse/rng"
"github.com/btwiuse/tags"
"github.com/btwiuse/version"
"github.com/denisbrodbeck/machineid"
"gopkg.in/yaml.v3"
Expand All @@ -24,26 +25,11 @@ import (
"k0s.io/pkg/agent/info"
)

type arrayFlags []string

func (i *arrayFlags) String() string {
return strings.Join(*i, ",")
}

func (i *arrayFlags) Set(value string) error {
if value == "" {
return nil
}
tags := strings.Split(value, ",")
*i = append(*i, tags...)
return nil
}

type Config struct {
ID string `json:"id" yaml:"-"`
Name string `json:"name" yaml:"name"`
Tags []string `json:"tags" yaml:"tags"`
Htpasswd map[string]string `json:"htpasswd,omitempty" yaml:"htpasswd"`
ID string `json:"id" yaml:"-"`
Name string `json:"name" yaml:"name"`
Tags tags.CommaSeparatedStrings `json:"tags" yaml:"tags"`
Htpasswd map[string]string `json:"htpasswd,omitempty" yaml:"htpasswd"`

agent.Info `json:"meta" yaml:"-"`

Expand Down Expand Up @@ -291,16 +277,16 @@ func Parse(args []string) *Config {
SetID(id),
}

hubapi *string = fset.String("hub", k0s.DEFAULT_HUB_ADDRESS, "Hub address.")
verbose *bool = fset.Bool("verbose", false, "Verbose log.")
version *bool = fset.Bool("version", false, "Show agent/hub version info.")
ro *bool = fset.Bool("ro", false, "Make shell readonly.")
insecure *bool = fset.Bool("insecure", false, "Allow insecure server connections when using SSL.")
pet *bool = fset.Bool("pet", false, "Run the agent like a pet, on real hardware.")
name *string = fset.String("name", rng.NewDocker(), "Set agent name.")
cmd *string = fset.String("cmd", "", "Command to run.")
c *string = fset.String("c", probeConfigFile(), "Config file location.")
tags arrayFlags = []string{}
hubapi *string = fset.String("hub", k0s.DEFAULT_HUB_ADDRESS, "Hub address.")
verbose *bool = fset.Bool("verbose", false, "Verbose log.")
version *bool = fset.Bool("version", false, "Show agent/hub version info.")
ro *bool = fset.Bool("ro", false, "Make shell readonly.")
insecure *bool = fset.Bool("insecure", false, "Allow insecure server connections when using SSL.")
pet *bool = fset.Bool("pet", false, "Run the agent like a pet, on real hardware.")
name *string = fset.String("name", rng.NewDocker(), "Set agent name.")
cmd *string = fset.String("cmd", "", "Command to run.")
c *string = fset.String("c", probeConfigFile(), "Config file location.")
tags tags.CommaSeparatedStrings = []string{}
)

// Should be comma separated values like foo,bar
Expand Down
1 change: 1 addition & 0 deletions pkg/agent/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
github.com/ActiveState/termtest/conpty v0.5.0
github.com/btwiuse/pretty v0.2.1
github.com/btwiuse/rng v0.0.0
github.com/btwiuse/tags v0.0.2
github.com/btwiuse/version v0.0.0
github.com/creack/pty v1.1.21
github.com/denisbrodbeck/machineid v1.0.1
Expand Down
2 changes: 1 addition & 1 deletion pkg/agent/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"io"
"net"

"k0s.io/pkg/api"
"github.com/btwiuse/version"
"k0s.io/pkg/api"
)

type Info interface {
Expand Down

0 comments on commit 5c31510

Please sign in to comment.