Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Weiqiang TANG <weiqiangt@vmware.com>
  • Loading branch information
weiqiangt committed Jan 13, 2020
1 parent 44dd4e4 commit cb6da3d
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 25 deletions.
2 changes: 0 additions & 2 deletions build/yamls/antrea-ipsec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,6 @@ spec:
- args:
- --config
- /etc/antrea/antrea-controller.conf
- -v
- "1000"
command:
- antrea-controller
env:
Expand Down
2 changes: 0 additions & 2 deletions build/yamls/antrea.yml
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,6 @@ spec:
- args:
- --config
- /etc/antrea/antrea-controller.conf
- -v
- "1000"
command:
- antrea-controller
env:
Expand Down
2 changes: 1 addition & 1 deletion build/yamls/base/controller.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ spec:
- name: antrea-controller
image: antrea
command: ["antrea-controller"]
args: ["--config", "/etc/antrea/antrea-controller.conf", "-v", "1000"]
args: ["--config", "/etc/antrea/antrea-controller.conf"]
env:
# Provide pod and node information for clusterinformation CRD.
- name: POD_NAME
Expand Down
3 changes: 1 addition & 2 deletions cmd/antctl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ var rootCmd = &cobra.Command{

func init() {
// prevent any unexpected output at beginning
flag.Set("logtostderr", "true")
flag.Set("alsologtostderr", "true")
flag.Set("logtostderr", "false")
flag.Set("v", "0")
pflag.CommandLine.MarkHidden("log-flush-frequency")
}
Expand Down
9 changes: 5 additions & 4 deletions pkg/antctl/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,14 @@ type RequestOption struct {
// Args are the parameters of the ongoing request.
Args map[string]string
// Timeout specifies a time limit for requests made by the client. The timeout
// includes connection time, any redirects, and reading the response body.
// duration includes connection setup, all redirects, and reading of the
// response body.
TimeOut time.Duration
}

// client issues requests to an antctl server and gets the response.
type client struct {
// inPod tells the running mode of the client.
// inPod indicate whether the client is running in a pod or not.
inPod bool
// codec is the CodecFactory for this command, it is needed for remote accessing.
codec serializer.CodecFactory
Expand All @@ -57,7 +58,7 @@ type client struct {
// resolveKubeconfig tries to load the kubeconfig specified in the RequestOption.
// It will return error if the stating of the file failed or the kubeconfig is malformed.
// It will not try to look up InCluster configuration. If the kubeconfig is loaded,
// The groupVersion and the codec in the RequestOption will be populated into the
// the groupVersion and the codec in the RequestOption will be populated into the
// kubeconfig object.
func (c *client) resolveKubeconfig(opt *RequestOption) (*rest.Config, error) {
kubeconfig, err := clientcmd.BuildConfigFromFlags("", opt.Kubeconfig)
Expand Down Expand Up @@ -108,7 +109,7 @@ func (c *client) localRequest(opt *RequestOption) (io.Reader, error) {
// data.
func (c *client) Request(opt *RequestOption) (io.Reader, error) {
if c.inPod {
klog.Infoln("Antctl runs as local mode")
klog.Infoln("antctl runs as local mode")
return c.localRequest(opt)
}
kubeconfig, err := c.resolveKubeconfig(opt)
Expand Down
4 changes: 2 additions & 2 deletions pkg/antctl/command_definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const (
// antctl framework will generate a same name sub-command of the root command for
// each of them, any commands specified as one of these group will need to be invoked
// as:
// antctl <commandGroup> <command>
// antctl <commandGroup> <command>
type commandGroup uint

const (
Expand Down Expand Up @@ -164,7 +164,7 @@ func (cd *commandDefinition) applySubCommandToRoot(root *cobra.Command, client *
// validate checks if the commandDefinition is valid.
func (cd *commandDefinition) validate() []error {
var errs []error
if len(cd.Use) == 0 { // must have a use string
if len(cd.Use) == 0 {
errs = append(errs, fmt.Errorf("the command does not have name"))
}
if cd.TransformedResponse == nil {
Expand Down
19 changes: 8 additions & 11 deletions pkg/antctl/command_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ func (cl *commandList) InstallToAPIServer(apiServer *server.GenericAPIServer, cq
}

// applyToMux adds the handler function of each commandDefinition in the
// commandList to the mux with path /<api prefix>/<cmd>, it also adds a dummy discovery
// handler with path /<api prefix>. It sets up a discovery handler for the
// service available checking of the kubernetes apiserver.
// commandList to the mux with path /apis/<group_version>/<cmd>. It also adds
// corresponding discovery handlers at /apis/<group_version> for kubernetes service
// discovery.
func (cl *commandList) applyToMux(mux *mux.PathRecorderMux, aq monitor.AgentQuerier, cq monitor.ControllerQuerier) {
resources := map[string][]metav1.APIResource{}
for _, def := range cl.definitions {
Expand Down Expand Up @@ -100,8 +100,8 @@ func (cl *commandList) applyFlagsToRootCommand(root *cobra.Command) {
root.PersistentFlags().DurationP("timeout", "t", 0, "time limit of the execution of the command")
}

// ApplyToRootCommand applies the commandList to the root cobra applySubCommandToRoot, it applies
// each commandDefinition of it to the root applySubCommandToRoot as a sub-applySubCommandToRoot.
// ApplyToRootCommand applies the commandList to the root cobra command, it applies
// each commandDefinition of it to the root command as a sub-command.
func (cl *commandList) ApplyToRootCommand(root *cobra.Command, isAgent bool, inPod bool) {
client := &client{
inPod: inPod,
Expand All @@ -116,6 +116,7 @@ func (cl *commandList) ApplyToRootCommand(root *cobra.Command, isAgent bool, inP
continue
}
def.applySubCommandToRoot(root, client, isAgent)
klog.Infof("Added command %s", def.Use)
}
cl.applyFlagsToRootCommand(root)
root.PersistentPreRunE = func(cmd *cobra.Command, args []string) error {
Expand All @@ -127,10 +128,6 @@ func (cl *commandList) ApplyToRootCommand(root *cobra.Command, isAgent bool, inP
if err != nil {
return err
}
err = flag.Set("alsologtostderr", fmt.Sprint(enableVerbose))
if err != nil {
return err
}
if enableVerbose {
err := flag.Set("v", fmt.Sprint(math.MaxInt32))
if err != nil {
Expand All @@ -145,10 +142,10 @@ func (cl *commandList) ApplyToRootCommand(root *cobra.Command, isAgent bool, inP
// validate checks the validation of the commandList.
func (cl *commandList) validate() []error {
var errs []error
if len(cl.definitions) == 0 { // must have at least one applySubCommandToRoot
if len(cl.definitions) == 0 {
return []error{fmt.Errorf("no command found in the command list")}
}
for i, c := range cl.definitions { // each commandDefinition must be valid
for i, c := range cl.definitions {
for _, err := range c.validate() {
errs = append(errs, fmt.Errorf("#%d command<%s>: %w", i, c.Use, err))
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/antctl/handlers/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (

// Factory is the interface to generate command handlers.
type Factory interface {
// Handler returns net/http.HandlerFunc which will be used to handle
// Handler returns a net/http.HandlerFunc which will be used to handle
// requests issued by commands from the antctl client. An implementation
// needs to determine the component it is running in by checking nullable
// of the AgentQuerier or the ControllerQuerier. If the antctl server is
Expand Down

0 comments on commit cb6da3d

Please sign in to comment.