-
Notifications
You must be signed in to change notification settings - Fork 178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
netmaster cli refactor #1088
netmaster cli refactor #1088
Conversation
TODO: update container entrypoint scripts |
build pr |
build PR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work!
netmaster/main.go
Outdated
Name: "infra, infra-type", | ||
Value: "default", | ||
EnvVar: "CONTIV_NETMASTER_PLUGIN_HOST", | ||
Usage: "set netmaster infra tyoe, options [aci, default]", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo: tyoe -> type
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
netmaster/main.go
Outdated
|
||
if err := parseOpts(&opts); err != nil { | ||
log.Fatalf("Failed to parse cli options. Error: %s", err) | ||
internalAddress := ctx.String("interal-address") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo: interal -> internal
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
netmaster/main.go
Outdated
log.Fatalf("Failed to parse cli options. Error: %s", err) | ||
internalAddress := ctx.String("interal-address") | ||
if internalAddress == "" { | ||
return nil, errors.New("netmaster interal-address is not set") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo: interal -> internal
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
netmaster/main.go
Outdated
} | ||
|
||
// execute options | ||
execOpts(&opts) | ||
logrus.Infof("Using netmaster interal-address: %s", internalAddress) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo: interal -> internal
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
netmaster/main.go
Outdated
} | ||
|
||
func main() { | ||
localIP, _ := netutils.GetDefaultAddr() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check error here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
netplugin/netd.go
Outdated
if networkMode == "vxlan" && vtepIP == "" { | ||
return plugin.Config{}, fmt.Errorf("vtep-ip should be set when using VXLAN mode") | ||
if netConfigs.NetworkMode == "vxlan" && vtepIP == "" { | ||
return nil, fmt.Errorf("vtep-ip should be set when using VXLAN mode") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should -> must
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
netplugin/netd.go
Outdated
if networkMode == "vlan" && len(vlanUpLinks) == 0 { | ||
return plugin.Config{}, fmt.Errorf("vlan-uplinks should be set when using VLAN mode") | ||
if netConfigs.NetworkMode == "vlan" && len(vlanUpLinks) == 0 { | ||
return nil, fmt.Errorf("vlan-uplinks should be set when using VLAN mode") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should -> must
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
test/integration/integ_test.go
Outdated
@@ -53,7 +54,8 @@ func TestMain(m *M) { | |||
flag.StringVar(&integ.arpMode, "arp-mode", "proxy", "ARP mode [ proxy | flood ]") | |||
flag.StringVar(&integ.encap, "encap", "vlan", "Encap [ vlan | vxlan ]") | |||
flag.StringVar(&integ.fabricMode, "fabric-mode", "default", "fabric-mode [ aci | default ]") | |||
flag.StringVar(&integ.clusterStore, "cluster-store", "etcd://127.0.0.1:2379", "Cluster store URL") | |||
flag.StringVar(&integ.clusterStoreDriver, "cluster-store-driver", "etcd", "Cluster store dirver") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo: dirver -> driver
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
utils/configs.go
Outdated
|
||
hook, err = logrus_syslog.NewSyslogHook(syslogURL.Scheme, syslogURL.Host, priority, binary) | ||
if err != nil { | ||
return fmt.Errorf("Failed connectting to syslog %q: %v", syslogRawURL, err.Error()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo: connectting -> connecting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
utils/netutils/netutils.go
Outdated
port, err := strconv.Atoi(addr[1]) | ||
if err != nil { | ||
return fmt.Errorf("bind port is a integer, got %v", port) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe validate that the port is >= 1 and <= 65535 here?
(I don't think we need to support listening on port 0 lol)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@tiewei How do you feel about raising an error if etcd and consul endpoints are set? Right now it says "consul endpoints are ignored if etcd endpoints are set"... if both of them are set, we can't really determine what the user intent was IMO. I think we should just explode in that case. |
@chrisplo mentioned that as well in last commit ... i'll error it out then |
netmaster/main.go
Outdated
@@ -161,7 +160,9 @@ func main() { | |||
if err != nil { | |||
errmsg := err.Error() | |||
logrus.Error(errmsg) | |||
return cli.NewExitError(errmsg, (len(errmsg)%254 + 1)) | |||
// use 22 Invalid argument as error return code | |||
// http://www-numi.fnal.gov/offline_software/srt_public_context/WebDocs/Errors/unix_system_errors.html |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice 👍
Refactor netmaster cli to use "github.com/urfave/cli", it brings benefit like setting forarding mode, infra type and network mode, allows setting multi etcd/consul endpoints and using SSL, enabling syslog,json log and multi log levels. Signed-off-by: Wei Tie <wtie@cisco.com>
build PR |
What release is this meant to be included in? It'd be nice to deprecate the old flags instead of removing them. This should make it easier if we make a 1.2 release which is still backwards compatible and some users upgrade an existing setup. What do you think? |
Most old flag was kept except |
netmaster/main.go
Outdated
cli.StringFlag{ | ||
Name: "infra, infra-type", | ||
Value: "default", | ||
EnvVar: "CONTIV_NETMASTER_PLUGIN_HOST", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be CONTIV_NETMASTER_INFRA
netmaster/main.go
Outdated
cli.StringFlag{ | ||
Name: "name, plugin-name", | ||
Value: "netplugin", | ||
EnvVar: "CONTIV_NETMASTER_PLUGIN_HOST", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be CONTIV_NETMASTER_PLUGIN_NAME
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3/4 done, some of the below I'd strongly suggest but they probably all slide under non-blocking
apiConfig := &objApi.APIControllerConfig{ | ||
NetForwardMode: d.NetForwardMode, | ||
NetInfraType: d.NetInfraType, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFACT this isn't supposed to be modifiable, why not have NewAPIController accept APIControllerConfig by value?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this object only got used here (and integ testings), I used object was because of intending to add more parameters from configs .
have NewAPIController accept APIControllerConfig by value
this is troublesome in golang, especially when having the parameters in different type
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think the struct is fine, just dunno why you need a pointer to it
if err != nil { | ||
log.Fatalf("Error connecting to state store: %v. Err: %v", d.ClusterStore, err) | ||
log.Fatalf("Error connecting to state store: driver %q, URLs %q. Err: %v", d.ClusterStoreDriver, d.ClusterStoreURL, err) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think we should check for ':' in ControlURL and ListenURL since those are parsed later in startListeners
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it actually got checked in the CLI part
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah I see it now
internalAddr := strings.Split(d.ControlURL, ":") | ||
if externalAddr[0] == "0.0.0.0" && externalAddr[1] == internalAddr[1] { | ||
// ignore internal bind if external and internal are on the same port and external bind on 0.0.0.0 | ||
log.Infof("Ignore creating API listener on %q because %q covers it", d.ControlURL, d.ListenURL) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems we could have external and internal on same IP as well?
externalAddr[1] == internalAddr[1] && (externalAddr[0] == "0.0.0.0" || externalAddr[0] == internalAddr[0])
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if they are on the same ip but different port will go to else
where create a listener on different port with same ip. Only got ignored when they have overlapping
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh nvm, I wasn't looking at the outer if restriction
|
||
// FlattenFlags concatenate slices of flags into one slice | ||
func FlattenFlags(flagSlices ...[]cli.Flag) []cli.Flag { | ||
flags := flagSlices[0] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
start with flags := [] then range starting at 0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or, I think you can just do instead of this function:
append(flags, flagsA..., flagsB...)
where the ...
is a literal
https://stackoverflow.com/a/16248257/1322463
https://golang.org/ref/spec#Passing_arguments_to_..._parameters
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i don't think golang allows more than one slice parameter ( it only works for the last parameter)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and here, i thought i was on to something . . ok fine, though now I wonder if this could be ...[]interface{} arg and be a general purpose
Anyway . . . I'm back to first comment, start range at 0 so that you can handle 0 length input?
utils/configs.go
Outdated
cli.BoolFlag{ | ||
Name: "use-syslog, syslog", | ||
EnvVar: fmt.Sprintf("CONTIV_%s_USE_SYSLOG", binUpper), | ||
Usage: fmt.Sprintf("set %s send log to syslog or not", binLower), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe say what true value does to be more explicit?
true value sends logs to syslog
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think the parameter is pretty self-explained ... --use-syslog
is actually not used as --use-syslog=True
, it is if flag --use-syslog
is provided, this var is treated as True.
I'll update the Usage
to make it more clear
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
k
command = "sudo " + self.binpath + "/netplugin --vlan-if eth2 --vlan-if eth3 " + fwd_arg + fwd_arg + store_args + args + "> /tmp/netplugin.log 2>&1" | ||
# NOTE: this testing only used in mesos-docker | ||
mode_args = " --fwdmode bridge --netmode vlan --mode docker " | ||
command = "sudo " + self.binpath + "/netplugin --vlan-if eth2 --vlan-if eth3 " + mode_args + gen_cluster_store_args() + args + "> /tmp/netplugin.log 2>&1" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wrap?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'd make it in different PR, codes under systest are pretty sick
} else { | ||
storeArgs = " --consul-endpoints " + strings.Replace(cStore, "consul", "http", 1) + " " | ||
storeArgs = " --consul-endpoints " + d.node.suite.basicInfo.ClusterStoreURLs + " " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
d.node.suite.basicInfo.ClusterStoreURLs + " "
could be added to storeArgs outside the if block, not asking for change, just sayin
storeArgs = " --consul-endpoints " + k.node.suite.basicInfo.ClusterStoreURLs + " " | ||
} | ||
return " --netmode " + netMode + " --fwdmode " + fwdMode + " --mode " + mode + storeArgs | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is the only diff with docker setup tset is the mode? reuse?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's due to the way how our sys testing was done, k8setpup_test.go
and docker_test.go
are separated scheduler and codes between them are not able to share, to fix this we need to introduce a new util and generates shared codes ... i'd leave it in different PR
} | ||
return " --netmode " + netMode + " --fwdmode " + fwdMode + " --mode " + mode + storeArgs | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
duplicate?
var podName string | ||
for retry := 60; retry > 0; retry-- { | ||
// only get running pods name | ||
podNameCmd := `kubectl -n kube-system get pods -o wide | grep Running | grep ` + podRegex + ` | grep ` + nodeName + ` | cut -d " " -f 1` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe there is a better kubectl query for this? dunno if this helps, there is also all that json path stuff
kubectl get pods --field-selector=status.phase=Running
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah this is better, what i did this this line is just added grep Running
piece ... I'd add it into the systest improvement PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is not supported until 1.9
kubernetes/kubernetes#50140
reviewing own comments, none are truly blockers
Signed-off-by: Wei Tie <nuaafe@gmail.com>
Build PR |
logrus.Infof("Starting netplugin on %s", w.node.Name()) | ||
|
||
cmd := "sudo " + w.node.suite.basicInfo.BinPath + "/netplugin --netmode " + netMode + " --fwdmode " + fwdMode + " --plugin-mode docker --vlan-if " + w.node.suite.hostInfo.HostDataInterfaces + storeArgs + args + "&> /tmp/netplugin.log" | ||
cmd := "sudo " + w.node.suite.basicInfo.BinPath + "/netplugin --vlan-if " + w.node.suite.hostInfo.HostDataInterfaces + w.commonArgs() + args + "&> /tmp/netplugin.log" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wrap?
if w.node.suite.basicInfo.AciMode == "on" { | ||
infraType = " --infra aci " | ||
} | ||
return w.node.tbnode.RunCommandBackground("sudo " + w.node.suite.basicInfo.BinPath + "/netmaster" + infraType + w.commonArgs() + " &> /tmp/netmaster.log") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wrap?
|
||
// FlattenFlags concatenate slices of flags into one slice | ||
func FlattenFlags(flagSlices ...[]cli.Flag) []cli.Flag { | ||
flags := flagSlices[0] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and here, i thought i was on to something . . ok fine, though now I wonder if this could be ...[]interface{} arg and be a general purpose
Anyway . . . I'm back to first comment, start range at 0 so that you can handle 0 length input?
if [[ $# -gt 9 ]] && [[ $10 != "" ]]; then | ||
shift; shift; shift; shift; shift; shift; shift; shift; shift | ||
if [[ $# -gt 10 ]] && [[ ${11} != "" ]]; then | ||
shift; shift; shift; shift; shift; shift; shift; shift; shift; shift |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please use shift 10
instead
@@ -166,7 +167,9 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| | |||
end | |||
node.vm.provision "shell" do |s| | |||
s.inline = provision_common_once | |||
s.args = [node_name, node_addr, cluster_ip_nodes, ENV["http_proxy"] || "", ENV["https_proxy"] || "", ENV["NIGHTLY_RELEASE"] || "", ENV["CONTIV_CLUSTER_STORE"] || "etcd://localhost:2379", ENV["CONTIV_DOCKER_VERSION"] || "", ENV['CONTIV_NODE_OS'] || "", *ENV['CONTIV_ENV']] | |||
s.args = [node_name, node_addr, cluster_ip_nodes, ENV["http_proxy"] || "", ENV["https_proxy"] || "", ENV["NIGHTLY_RELEASE"] || "", \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
more than 80 here?
if [[ $# -gt 9 ]] && [[ $10 != "" ]]; then | ||
shift; shift; shift; shift; shift; shift; shift; shift; shift | ||
if [[ $# -gt 10 ]] && [[ ${11} != "" ]]; then | ||
shift; shift; shift; shift; shift; shift; shift; shift; shift; shift |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shift 10
internalAddr := strings.Split(d.ControlURL, ":") | ||
if externalAddr[0] == "0.0.0.0" && externalAddr[1] == internalAddr[1] { | ||
// ignore internal bind if external and internal are on the same port and external bind on 0.0.0.0 | ||
log.Infof("Ignore creating API listener on %q because %q covers it", d.ControlURL, d.ListenURL) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh nvm, I wasn't looking at the outer if restriction
cli.BoolFlag{ | ||
Name: "use-json-log, json-log", | ||
EnvVar: fmt.Sprintf("CONTIV_%s_USE_JSON_LOG", binUpper), | ||
Usage: fmt.Sprintf("set %s log format to json if this flag is provided", binLower), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is OK, but might be easier to read "format logs with json"
cli.BoolFlag{ | ||
Name: "use-syslog, syslog", | ||
EnvVar: fmt.Sprintf("CONTIV_%s_USE_SYSLOG", binUpper), | ||
Usage: fmt.Sprintf("set %s send log to syslog if this flag is provided", binLower), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is OK, but might be easier to read "send logs to syslog"
utils/configs.go
Outdated
cli.BoolFlag{ | ||
Name: "use-syslog, syslog", | ||
EnvVar: fmt.Sprintf("CONTIV_%s_USE_SYSLOG", binUpper), | ||
Usage: fmt.Sprintf("set %s send log to syslog or not", binLower), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
k
overall substance looks good, just some style nits |
Refactor netmaster cli to use "github.com/urfave/cli", it brings
benefit like setting forwarding mode, infra type and network mode,
allows setting multi etcd/consul endpoints and using SSL, enabling
syslog,json log and multi log levels.
Signed-off-by: Wei Tie wtie@cisco.com