Skip to content

Commit 6910fc4

Browse files
committed
Provide workaround for StringSlice seperator not being respected
Signed-off-by: Derek Nola <[email protected]>
1 parent 4c4f746 commit 6910fc4

File tree

18 files changed

+144
-124
lines changed

18 files changed

+144
-124
lines changed

cmd/agent/main.go

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ func main() {
1717
app.Commands = []*cli.Command{
1818
cmds.NewAgentCommand(agent.Run),
1919
}
20+
app.DisableSliceFlagSeparator = true
2021

2122
if err := app.Run(configfilearg.MustParse(os.Args)); err != nil && !errors.Is(err, context.Canceled) {
2223
logrus.Fatalf("Error: %v", err)

cmd/k3s/main.go

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ func main() {
5151
// Handle subcommand invocation (k3s server, k3s crictl, etc)
5252
app := cmds.NewApp()
5353
app.EnableBashCompletion = true
54+
app.DisableSliceFlagSeparator = true
5455
app.Commands = []*cli.Command{
5556
cmds.NewServerCommand(internalCLIAction(version.Program+"-server"+programPostfix, dataDir, os.Args)),
5657
cmds.NewAgentCommand(internalCLIAction(version.Program+"-agent"+programPostfix, dataDir, os.Args)),

cmd/server/main.go

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ func main() {
4343
os.Args[0] = cmd
4444

4545
app := cmds.NewApp()
46+
app.DisableSliceFlagSeparator = true
4647
app.Commands = []*cli.Command{
4748
cmds.NewServerCommand(server.Run),
4849
cmds.NewAgentCommand(agent.Run),

main.go

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525

2626
func main() {
2727
app := cmds.NewApp()
28+
app.DisableSliceFlagSeparator = true
2829
app.Commands = []*cli.Command{
2930
cmds.NewServerCommand(server.Run),
3031
cmds.NewAgentCommand(agent.Run),

pkg/agent/config/config.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -514,10 +514,10 @@ func get(ctx context.Context, envInfo *cmds.Agent, proxy proxy.Proxy) (*config.N
514514
// Overwrite nodeip and flannel interface and throw a warning if user explicitly set those parameters
515515
if len(vpnIPs) != 0 {
516516
logrus.Infof("Node-ip changed to %v due to VPN", vpnIPs)
517-
if len(envInfo.NodeIP.Value()) != 0 {
517+
if len(envInfo.NodeIP) != 0 {
518518
logrus.Warn("VPN provider overrides configured node-ip parameter")
519519
}
520-
if len(envInfo.NodeExternalIP.Value()) != 0 {
520+
if len(envInfo.NodeExternalIP) != 0 {
521521
logrus.Warn("VPN provider overrides node-external-ip parameter")
522522
}
523523
nodeIPs = vpnIPs
@@ -676,13 +676,13 @@ func get(ctx context.Context, envInfo *cmds.Agent, proxy proxy.Proxy) (*config.N
676676
}
677677

678678
var nodeExternalDNSs []string
679-
for _, dnsString := range envInfo.NodeExternalDNS.Value() {
679+
for _, dnsString := range envInfo.NodeExternalDNS {
680680
nodeExternalDNSs = append(nodeExternalDNSs, strings.Split(dnsString, ",")...)
681681
}
682682
nodeConfig.AgentConfig.NodeExternalDNSs = nodeExternalDNSs
683683

684684
var nodeInternalDNSs []string
685-
for _, dnsString := range envInfo.NodeInternalDNS.Value() {
685+
for _, dnsString := range envInfo.NodeInternalDNS {
686686
nodeInternalDNSs = append(nodeInternalDNSs, strings.Split(dnsString, ",")...)
687687
}
688688
nodeConfig.AgentConfig.NodeInternalDNSs = nodeInternalDNSs
@@ -761,7 +761,7 @@ func get(ctx context.Context, envInfo *cmds.Agent, proxy proxy.Proxy) (*config.N
761761
}
762762

763763
nodeConfig.AgentConfig.PauseImage = envInfo.PauseImage
764-
nodeConfig.AgentConfig.AirgapExtraRegistry = envInfo.AirgapExtraRegistry.Value()
764+
nodeConfig.AgentConfig.AirgapExtraRegistry = envInfo.AirgapExtraRegistry
765765
nodeConfig.AgentConfig.SystemDefaultRegistry = controlConfig.SystemDefaultRegistry
766766

767767
// Apply SystemDefaultRegistry to PauseImage and AirgapExtraRegistry
@@ -774,10 +774,10 @@ func get(ctx context.Context, envInfo *cmds.Agent, proxy proxy.Proxy) (*config.N
774774
}
775775
}
776776

777-
nodeConfig.AgentConfig.ExtraKubeletArgs = envInfo.ExtraKubeletArgs.Value()
778-
nodeConfig.AgentConfig.ExtraKubeProxyArgs = envInfo.ExtraKubeProxyArgs.Value()
779-
nodeConfig.AgentConfig.NodeTaints = envInfo.Taints.Value()
780-
nodeConfig.AgentConfig.NodeLabels = envInfo.Labels.Value()
777+
nodeConfig.AgentConfig.ExtraKubeletArgs = envInfo.ExtraKubeletArgs
778+
nodeConfig.AgentConfig.ExtraKubeProxyArgs = envInfo.ExtraKubeProxyArgs
779+
nodeConfig.AgentConfig.NodeTaints = envInfo.Taints
780+
nodeConfig.AgentConfig.NodeLabels = envInfo.Labels
781781
nodeConfig.AgentConfig.ImageCredProvBinDir = envInfo.ImageCredProvBinDir
782782
nodeConfig.AgentConfig.ImageCredProvConfig = envInfo.ImageCredProvConfig
783783
nodeConfig.AgentConfig.DisableCCM = controlConfig.DisableCCM

pkg/agent/run.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ func Run(ctx context.Context, cfg cmds.Agent) error {
310310
}
311311

312312
if cfg.Rootless && !cfg.RootlessAlreadyUnshared {
313-
dualNode, err := utilsnet.IsDualStackIPStrings(cfg.NodeIP.Value())
313+
dualNode, err := utilsnet.IsDualStackIPStrings(cfg.NodeIP)
314314
if err != nil {
315315
return err
316316
}

pkg/cli/agent/agent.go

+14-2
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,13 @@ func Run(ctx *cli.Context) error {
7272
return fmt.Errorf("--server is required")
7373
}
7474

75-
if cmds.AgentConfig.FlannelIface != "" && len(cmds.AgentConfig.NodeIP.Value()) == 0 {
75+
cmds.AgentConfig.NodeIP = ctx.StringSlice("node-ip")
76+
if cmds.AgentConfig.FlannelIface != "" && len(cmds.AgentConfig.NodeIP) == 0 {
7677
ip, err := util.GetIPFromInterface(cmds.AgentConfig.FlannelIface)
7778
if err != nil {
7879
return err
7980
}
80-
cmds.AgentConfig.NodeIP.Set(ip)
81+
cmds.AgentConfig.NodeIP = []string{ip}
8182
}
8283

8384
logrus.Info("Starting " + version.Program + " agent " + ctx.App.Version)
@@ -91,6 +92,17 @@ func Run(ctx *cli.Context) error {
9192
cfg.Debug = ctx.Bool("debug")
9293
cfg.DataDir = dataDir
9394

95+
// Due to https://github.com/urfave/cli/issues/2069, we need to extract any StringSlice flag
96+
// via the ctx.StringSlice() method to avoid the flag being split by the SliceFlagSeparator
97+
cfg.NodeExternalIP = ctx.StringSlice("node-external-ip")
98+
cfg.NodeInternalDNS = ctx.StringSlice("node-internal-dns")
99+
cfg.NodeExternalDNS = ctx.StringSlice("node-external-dns")
100+
cfg.AirgapExtraRegistry = ctx.StringSlice("airgap-extra-registry")
101+
cfg.ExtraKubeProxyArgs = ctx.StringSlice("kube-proxy-arg")
102+
cfg.ExtraKubeletArgs = ctx.StringSlice("kubelet-arg")
103+
cfg.Labels = ctx.StringSlice("node-label")
104+
cfg.Taints = ctx.StringSlice("node-taint")
105+
94106
contextCtx := signals.SetupSignalContext()
95107

96108
go cmds.WriteCoverage(contextCtx)

pkg/cli/cert/cert.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,10 @@ func check(app *cli.Context, cfg *cmds.Server) error {
7979
return err
8080
}
8181
logrus.Infof("Agent detected, checking agent certificates")
82-
cmds.ServicesList = cli.NewStringSlice(services.Agent...)
82+
cmds.ServicesList = *cli.NewStringSlice(services.Agent...)
8383
} else {
8484
logrus.Infof("Server detected, checking agent and server certificates")
85-
cmds.ServicesList = cli.NewStringSlice(services.All...)
85+
cmds.ServicesList = *cli.NewStringSlice(services.All...)
8686
}
8787
}
8888

@@ -179,10 +179,10 @@ func rotate(app *cli.Context, cfg *cmds.Server) error {
179179
return err
180180
}
181181
logrus.Infof("Agent detected, rotating agent certificates")
182-
cmds.ServicesList = cli.NewStringSlice(services.Agent...)
182+
cmds.ServicesList = *cli.NewStringSlice(services.Agent...)
183183
} else {
184184
logrus.Infof("Server detected, rotating agent and server certificates")
185-
cmds.ServicesList = cli.NewStringSlice(services.All...)
185+
cmds.ServicesList = *cli.NewStringSlice(services.All...)
186186
}
187187
}
188188

pkg/cli/cmds/agent.go

+9-18
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ type Agent struct {
2121
ResolvConf string
2222
DataDir string
2323
BindAddress string
24-
NodeIP cli.StringSlice
25-
NodeExternalIP cli.StringSlice
26-
NodeInternalDNS cli.StringSlice
27-
NodeExternalDNS cli.StringSlice
24+
NodeIP []string
25+
NodeExternalIP []string
26+
NodeInternalDNS []string
27+
NodeExternalDNS []string
2828
NodeName string
2929
PauseImage string
3030
Snapshotter string
@@ -49,11 +49,11 @@ type Agent struct {
4949
ClusterReset bool
5050
PrivateRegistry string
5151
SystemDefaultRegistry string
52-
AirgapExtraRegistry cli.StringSlice
53-
ExtraKubeletArgs cli.StringSlice
54-
ExtraKubeProxyArgs cli.StringSlice
55-
Labels cli.StringSlice
56-
Taints cli.StringSlice
52+
AirgapExtraRegistry []string
53+
ExtraKubeletArgs []string
54+
ExtraKubeProxyArgs []string
55+
Labels []string
56+
Taints []string
5757
ImageCredProvBinDir string
5858
ImageCredProvConfig string
5959
ContainerRuntimeReady chan<- struct{}
@@ -78,22 +78,18 @@ var (
7878
Name: "node-ip",
7979
Aliases: []string{"i"},
8080
Usage: "(agent/networking) IPv4/IPv6 addresses to advertise for node",
81-
Value: &AgentConfig.NodeIP,
8281
}
8382
NodeExternalIPFlag = &cli.StringSliceFlag{
8483
Name: "node-external-ip",
8584
Usage: "(agent/networking) IPv4/IPv6 external IP addresses to advertise for node",
86-
Value: &AgentConfig.NodeExternalIP,
8785
}
8886
NodeInternalDNSFlag = &cli.StringSliceFlag{
8987
Name: "node-internal-dns",
9088
Usage: "(agent/networking) internal DNS addresses to advertise for node",
91-
Value: &AgentConfig.NodeInternalDNS,
9289
}
9390
NodeExternalDNSFlag = &cli.StringSliceFlag{
9491
Name: "node-external-dns",
9592
Usage: "(agent/networking) external DNS addresses to advertise for node",
96-
Value: &AgentConfig.NodeExternalDNS,
9793
}
9894
NodeNameFlag = &cli.StringFlag{
9995
Name: "node-name",
@@ -153,7 +149,6 @@ var (
153149
AirgapExtraRegistryFlag = &cli.StringSliceFlag{
154150
Name: "airgap-extra-registry",
155151
Usage: "(agent/runtime) Additional registry to tag airgap images as being sourced from",
156-
Value: &AgentConfig.AirgapExtraRegistry,
157152
Hidden: true,
158153
}
159154
PauseImageFlag = &cli.StringFlag{
@@ -204,22 +199,18 @@ var (
204199
ExtraKubeletArgs = &cli.StringSliceFlag{
205200
Name: "kubelet-arg",
206201
Usage: "(agent/flags) Customized flag for kubelet process",
207-
Value: &AgentConfig.ExtraKubeletArgs,
208202
}
209203
ExtraKubeProxyArgs = &cli.StringSliceFlag{
210204
Name: "kube-proxy-arg",
211205
Usage: "(agent/flags) Customized flag for kube-proxy process",
212-
Value: &AgentConfig.ExtraKubeProxyArgs,
213206
}
214207
NodeTaints = &cli.StringSliceFlag{
215208
Name: "node-taint",
216209
Usage: "(agent/node) Registering kubelet with set of taints",
217-
Value: &AgentConfig.Taints,
218210
}
219211
NodeLabels = &cli.StringSliceFlag{
220212
Name: "node-label",
221213
Usage: "(agent/node) Registering and starting kubelet with set of labels",
222-
Value: &AgentConfig.Labels,
223214
}
224215
ImageCredProvBinDirFlag = &cli.StringFlag{
225216
Name: "image-credential-provider-bin-dir",

pkg/cli/cmds/certs.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ type CertRotateCA struct {
1313
}
1414

1515
var (
16-
ServicesList *cli.StringSlice
16+
ServicesList cli.StringSlice
1717
CertRotateCAConfig CertRotateCA
1818
CertRotateCommandFlags = []cli.Flag{
1919
DebugFlag,
@@ -25,7 +25,7 @@ var (
2525
Name: "service",
2626
Aliases: []string{"s"},
2727
Usage: "List of services to manage certificates for. Options include (admin, api-server, controller-manager, scheduler, supervisor, " + version.Program + "-controller, " + version.Program + "-server, cloud-controller, etcd, auth-proxy, kubelet, kube-proxy)",
28-
Value: ServicesList,
28+
Value: &ServicesList,
2929
},
3030
}
3131
CertRotateCACommandFlags = []cli.Flag{

0 commit comments

Comments
 (0)