Skip to content

Commit

Permalink
Support --sort-by flag for "antctl get networkpolicy" for Agent
Browse files Browse the repository at this point in the history
Previous to this change, the flag was only supported in "Controller
mode". This was a bit confusing when running "antctl get networkpolicy"
from the Agent Pod, because 1) the option shows in the examples from the
help message, and 2) the documentation doesn't make it clear that this
flag only works in "Controller mode".

Rather than update the documentation and add complexity in the help
message, I am adding support for that flag in "Agent mode". There
doesn't seem to be any reason not to.

Signed-off-by: Antonin Bas <abas@vmware.com>
  • Loading branch information
antoninbas committed Aug 16, 2021
1 parent 382f49e commit d5ed336
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
4 changes: 2 additions & 2 deletions pkg/antctl/antctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ var CommandList = &commandList{
agentEndpoint: &endpoint{
nonResourceEndpoint: &nonResourceEndpoint{
path: "/networkpolicies",
params: []flagInfo{
params: append([]flagInfo{
{
name: "name",
usage: "Get NetworkPolicy by name.",
Expand All @@ -161,7 +161,7 @@ var CommandList = &commandList{
usage: "Get NetworkPolicies with specific type. Type means the type of its source network policy: K8sNP, ACNP, ANP",
shorthand: "T",
},
},
}, getSortByFlag()),
outputType: multiple,
},
addonTransform: networkpolicy.Transform,
Expand Down
16 changes: 10 additions & 6 deletions pkg/antctl/command_definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,16 +128,20 @@ func (e *resourceEndpoint) flags() []flagInfo {
})
}
if e.groupVersionResource == &v1beta2.NetworkPolicyVersionResource {
flags = append(flags, flagInfo{
name: "sort-by",
defaultValue: "",
supportedValues: []string{sortByEffectivePriority},
usage: "Get NetworkPolicies in specific order. Current supported value is effectivePriority.",
})
flags = append(flags, getSortByFlag())
}
return flags
}

func getSortByFlag() flagInfo {
return flagInfo{
name: "sort-by",
defaultValue: "",
supportedValues: []string{sortByEffectivePriority},
usage: "Get NetworkPolicies in specific order. Current supported value is effectivePriority.",
}
}

type nonResourceEndpoint struct {
path string
params []flagInfo
Expand Down

0 comments on commit d5ed336

Please sign in to comment.