-
Notifications
You must be signed in to change notification settings - Fork 374
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
Implement antctl agent-info #318
Conversation
Thanks for your PR. The following commands are available:
These commands can only be run by members of the vmware-tanzu organization. |
/test-all |
/test-all |
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.
Would be great to be able to merge this before the 0.3.0 release (Jan 22nd), this way we would have at least one useful CLI command.
pkg/antctl/handlers/agentinfo.go
Outdated
var _ Factory = new(AgentInfo) | ||
|
||
// ComponentAgentInfoResponse describes the internal response struct of agent-info command. | ||
// It only contains agent's node subnet and connection status of controller, OVSDB and openflow. |
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 you can remove this second line of comment: what is included in the response is clear from the structure definition and we should not have to update the struct-level comment every time we add some extra information to the response. However, you may want to add some comments to the struct members when needed (e.g.: "Subnet is the subnet range from the Pod CIDR allocated to the Node" or something like this).
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 agree. Updated.
pkg/antctl/handlers/agentinfo.go
Outdated
// It only contains agent's node subnet and connection status of controller, OVSDB and openflow. | ||
type ComponentAgentInfoResponse struct { | ||
ControllerConn string `json:"controllerConn,omitempty" yaml:"controllerConn,omitempty"` | ||
OVSDBConn string `json:"ovsdbConn,omitempty" yaml:"ovsdbConn,omitempty"` |
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.
Do you think we can do something like this, which is more in line with the K8s style for serializable structs:
type ConnStatus string
const (
ConnStatusUp ConnStatus = "UP"
ConnStatusDown ConnStatus = "DOWN"
)
type ComponentAgentInfoResponse struct {
ControllerConn ConnStatus `json:"controllerConn,omitempty" yaml:"controllerConn,omitempty"`
// ...
}
This makes it clear that the "*Conn" fields can only be set to "UP" or "DOWN" and helps document the response IMO.
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.
Yes, it is better. I have updated the code. I put ConnStatus at package monitor because maybe other cli will need this.
pkg/antctl/handlers/agentinfo.go
Outdated
type AgentInfo struct{} | ||
|
||
// Handler returns the function which can handle queries issued by agent-info commands, | ||
// the handler function populate component's agnet-info to the ComponentAgentInfoResponse. |
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: s/agnet-info/agent-info
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.
Updated.
controllerConn string | ||
ovsdbConn string | ||
ofConn string | ||
subent string |
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: s/subent/subnet (here and below)
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.
Updated.
pkg/antctl/antctl.go
Outdated
{ | ||
Use: "agent-info", | ||
Short: "Print agent's information", | ||
Long: "Print agent's information of the antctl.", |
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.
What does "of the antctl" mean here? Maybe we can come up with a better help message.
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.
Updated the message.
pkg/antctl/antctl.go
Outdated
GroupVersion: &systemGroup, | ||
TransformedResponse: reflect.TypeOf(transformedAgentInfoResponse{}), | ||
Agent: true, | ||
Controller: false, |
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.
nit: no need to specify negative values.
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.
Thanks. I have removed "Controller" and "AddTransform" fields.
/test-all |
pkg/antctl/handlers/agentinfo.go
Outdated
// ComponentAgentInfoResponse describes the internal response struct of agent-info command. | ||
// The first three fields refer to connection between the agent and controller, OVSDB and | ||
// openflow. Subnet refers to the subnet range from the Pod CIDR allocated to the Node. | ||
type ComponentAgentInfoResponse struct { |
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 it possible to reuse the AgentInfo CRD struct?
@mengdie-song
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.
That covers more than what we need 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.
I know it is more than what this PR supports, but does it make sense to show all in the AgentInfo CRD with this get agent-info cmd?
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 got what you mean now. Shall we just dump these important info for this milestone ? I will discuss with Mengdie about dumping all info afterwards ?
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.
Ok to me if we can catch the 0.3.0 release, but I do hope we revisit all CLI design items after 0.3.0.
Ideally we should keep API/CLI compatible across some number of releases, but maybe not a big deal at this stage.
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.
@jianjuns @lzhecheng Sorry the late review. We can dump all the information in AntreaAgentInfo via this API. Seems this patch now focuses more on the condition information.
Maybe this CLI output can follow the struct AntreaAgentInfo, put these condition information in a subcategory like Agent Conditions?
Since CRD will only be updated every minute, the information stored in CRD is not up to date.
I would suggest to follow https://github.com/vmware-tanzu/antrea/blob/master/pkg/monitor/monitor.go#L267 to get all needed information by CLI itself.
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.
@jianjuns @mengdie-song Thank you. I use struct AntreaAgentInfo as response now and updated the code.
09fb408
to
4809274
Compare
/test-all |
/test-all |
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.
LGTM, will let @jianjuns give the approval since he has made a change request about the response.
"net/http/httptest" | ||
"testing" | ||
|
||
monitor "github.com/vmware-tanzu/antrea/pkg/monitor" |
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.
The alias is not needed, though generated code has it.
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 seems generated code doesn’t have ConnStatus.
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.
Sorry, I didn't get your mean, I mean the alias "monitor" is not needed
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.
My bad. I misunderstood. Alias removed.
/test-all |
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.
LGTM
It seems that at the moment we can only query the agent-info from within the agent Pod. Is there any plan to support getting that information from outside the cluster using the kubeconfig and the Node's name?
antctl -k <path to kubeconfig> agent-info <node name>
@antoninbas yes, we are going to implement remote mode for antctl. These implemented are planned for this milestone. |
/test-all |
@jianjuns can we merge this local mode command ? I think the redesign is more about remote mode. |
Last, I hope after the Agent/Controller info commands, you guys can revisit the design, and decouple API server implementation from antctl, as (again and again) the API will be consumed by other clients besides antctl, and we need to make it generic. If we continue to add more and more commands based on the current framework, it will be become harder to change later. |
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.
@lzhecheng : can you provide an example output of this command?
var _ Factory = new(AgentInfo) | ||
|
||
// AgentInfo is the implementation of the Factory interface for the agent-info command. | ||
type AgentInfo struct{} |
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.
Humm...
Question - what is the convention of this handler struct. Do we assume it includes the real result data and how about other commands? If so, should we add AntreaAgentInfo into the struct?
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 have put an example in the PR description.
This struct doesn't contain data or result. It is only for command handler below:
func (v *AgentInfo) Handler(aq monitor.AgentQuerier, cq monitor.ControllerQuerier) http.HandlerFunc
pkg/monitor/querier.go
Outdated
@@ -151,6 +152,16 @@ func (monitor *agentMonitor) GetAgentConditions(ovsConnected bool) []v1beta1.Age | |||
} | |||
} | |||
|
|||
// GetAgentInfo gets the antrea agent information. | |||
func (monitor *agentMonitor) GetAgentInfo() *v1beta1.AntreaAgentInfo { | |||
info, err := monitor.client.ClusterinformationV1beta1().AntreaAgentInfos().Get(monitor.GetSelfNode().Name, metav1.GetOptions{}) |
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.
As I have mentioned previously, you cannot get the latest information for CLI if you query CRD directly.
In my point of view, CLI should get the latest information rather than the information which may be a minute late.
If so, you can extract the AntreaAgentInfo construction part of code here from monitor.go.
@jianjuns @tnqn What do you think?
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 would second what @mengdie-song said.
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.
Thank you Mengdie and Jianjun! I have updated the code.
4fa65b1
to
bb8aae1
Compare
pkg/antctl/handlers/agentinfo.go
Outdated
// the handler function populate component's agent-info to the response. | ||
func (v *AgentInfo) Handler(aq monitor.AgentQuerier, cq monitor.ControllerQuerier) http.HandlerFunc { | ||
return func(w http.ResponseWriter, r *http.Request) { | ||
var m *v1beta1.AntreaAgentInfo |
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.
why is m
the variable name? what is it standing for?
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.
Thank you for reminding me. I changed it to "info" and I think it makes more sense.
pkg/monitor/querier.go
Outdated
// GetAgentInfo gets the antrea agent information. | ||
func (monitor *agentMonitor) GetAgentInfo() *v1beta1.AntreaAgentInfo { | ||
return monitor.getAntreaAgentInfo(monitor.GetSelfNode().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.
The methods GetAgentInfo
, getAntreaAgentInfo
, getAgentCRD
in monitor would be confusing, maybe you can just use GetAgentInfo
as name of getAntreaAgentInfo
method.
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.
Yes, I changed them to GetAgentInfo().
926fa8f
to
3368d94
Compare
pkg/monitor/monitor.go
Outdated
@@ -264,12 +264,12 @@ func (monitor *agentMonitor) getAgentCRD(crdName string) *v1beta1.AntreaAgentInf | |||
return agentCRD | |||
} | |||
|
|||
func (monitor *agentMonitor) createAgentCRD(crdName string) (*v1beta1.AntreaAgentInfo, error) { | |||
func (monitor *agentMonitor) GetAgentInfo(name string) *v1beta1.AntreaAgentInfo { |
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 see the argument name
is necessary, it's kept as name
field of agentMonitor
, why we are passing it and have to make clients fetch the name via another method first? So do createAgentCRD
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.
Updated.
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.
LGTM
/test-all |
In the outputs, the "metadata" field looks strange, which should not be needed for CLI outputs, and it is also confusing like we are dumping a K8s resource. Do we have a way to exclude a field? |
@jianjuns I think we'd better use a new struct. TypeMeta and ObjectMeta only have json omitempty tag but we have other output format like yaml, so leaving these value unset won't help. |
Ok. If no way to filter the fields, probably let us still create a new struct. Sorry for the confusion. |
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.
LGTM
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.
LGTM
/test-all |
@lzhecheng : do you plan to make any further changes for this PR? I hope it can get into 0.4.0. |
@jianjuns I am ok to merge it. But there will be change after the antctl framework is refactored. If you want to have this command for 0.4.0 and then we can merge it. Shall we ? |
/test-networkpolicy |
It failed on #386. If it keeps failing, you can rebase on master. /test-networkpolicy |
Issue #275
Output should be like this: