Skip to content

Commit

Permalink
Shrink VersionResponse
Browse files Browse the repository at this point in the history
Signed-off-by: Weiqiang TANG <[email protected]>
  • Loading branch information
weiqiangt committed Dec 12, 2019
1 parent 59b9d6c commit 81c90ed
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
17 changes: 12 additions & 5 deletions pkg/antctl/definitions.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,26 @@ import (
"github.com/vmware-tanzu/antrea/pkg/version"
)

type VersionResponse struct {
handlers.ComponentVersionResponse
AntctlVersion string `json:"antctlVersion,omitempty" yaml:"antctlVersion,omitempty"`
}

func versionTransform(reader io.Reader, single bool) (interface{}, error) {
b, err := ioutil.ReadAll(reader)
klog.Infof("version transform received: %s", string(b))
if err != nil {
return nil, err
}
var v handlers.VersionResponse
err = json.Unmarshal(b, &v)
var cv handlers.ComponentVersionResponse
err = json.Unmarshal(b, &cv)
if err != nil {
return nil, err
}
v.AntctlVersion = version.GetFullVersion()
return &v, nil
return &VersionResponse{
ComponentVersionResponse: cv,
AntctlVersion: version.GetFullVersion(),
}, nil
}

// Definition defines command related options of the antctl.
Expand All @@ -50,7 +57,7 @@ var Definition = &CommandBundle{
Short: "Print version information",
Long: "Print version information of the client and the ${component}",
HandlerFactory: new(handlers.Version),
ResponseStruct: new(handlers.VersionResponse),
ResponseStruct: new(VersionResponse),
Agent: true,
Controller: true,
Singleton: true,
Expand Down
13 changes: 6 additions & 7 deletions pkg/antctl/handlers/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,24 @@ import (

var _ Factory = new(Version)

// VersionResponse describes the response of the version command.
type VersionResponse struct {
// ComponentVersionResponse describes the response of the version command.
type ComponentVersionResponse struct {
AgentVersion string `json:"agentVersion,omitempty" yaml:"agentVersion,omitempty"`
ControllerVersion string `json:"controllerVersion,omitempty" yaml:"controllerVersion,omitempty"`
AntctlVersion string `json:"antctlVersion,omitempty" yaml:"antctlVersion,omitempty"`
}

// Version is the implementation of Factory for `version` command.
type Version struct{}

// Handler returns the function which can handle version query, the handler function writes the VersionResponse in JSON format.
// Handler returns the function which can handle version query, the handler function writes the ComponentVersionResponse
// in JSON format.
func (v *Version) Handler(agentQuerier monitor.AgentQuerier, controllerQuerier monitor.ControllerQuerier) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var m VersionResponse
var m ComponentVersionResponse

if agentQuerier != nil {
m.AgentVersion = agentQuerier.GetVersion()
}
if controllerQuerier != nil {
} else if controllerQuerier != nil {
m.ControllerVersion = controllerQuerier.GetVersion()
}

Expand Down

0 comments on commit 81c90ed

Please sign in to comment.