-
Notifications
You must be signed in to change notification settings - Fork 344
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
Add sort-by effectivePriority for antctl get networkpolicy #1530
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -127,6 +127,13 @@ func (e *resourceEndpoint) flags() []flagInfo { | |
usage: "Filter the resource by namespace", | ||
}) | ||
} | ||
if e.groupVersionResource == &v1beta2.NetworkPolicyVersionResource { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in a future PR, we can consider extending this flag to other resources & other fields. Would you mind opening a Github issue for that, I think it would make a "good first issue" as well There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Opened #1605 |
||
flags = append(flags, flagInfo{ | ||
name: "sort-by", | ||
defaultValue: "", | ||
usage: "Get NetworkPolicies in specific order. Current supported value is effectivePriority.", | ||
}) | ||
} | ||
return flags | ||
} | ||
|
||
|
@@ -151,7 +158,7 @@ type endpoint struct { | |
// addonTransform is used to transform or update the response data received | ||
// from the handler, it must returns an interface which has same type as | ||
// TransformedResponse. | ||
addonTransform func(reader io.Reader, single bool) (interface{}, error) | ||
addonTransform func(reader io.Reader, single bool, opts map[string]string) (interface{}, error) | ||
} | ||
|
||
// flagInfo represents a command-line flag that can be provided when invoking an antctl command. | ||
|
@@ -200,7 +207,7 @@ func (cd *commandDefinition) namespaced() bool { | |
return false | ||
} | ||
|
||
func (cd *commandDefinition) getAddonTransform() func(reader io.Reader, single bool) (interface{}, error) { | ||
func (cd *commandDefinition) getAddonTransform() func(reader io.Reader, single bool, opts map[string]string) (interface{}, error) { | ||
if runtime.Mode == runtime.ModeAgent && cd.agentEndpoint != nil { | ||
return cd.agentEndpoint.addonTransform | ||
} else if runtime.Mode == runtime.ModeController && cd.controllerEndpoint != nil { | ||
|
@@ -681,7 +688,7 @@ func (cd *commandDefinition) tableOutput(obj interface{}, writer io.Writer) erro | |
// format. If the AddonTransform is set, it will use the function to transform | ||
// the data first. It will try to output the resp in the format ft specified after | ||
// doing transform. | ||
func (cd *commandDefinition) output(resp io.Reader, writer io.Writer, ft formatterType, single bool) (err error) { | ||
func (cd *commandDefinition) output(resp io.Reader, writer io.Writer, ft formatterType, single bool, args map[string]string) (err error) { | ||
var obj interface{} | ||
addonTransform := cd.getAddonTransform() | ||
|
||
|
@@ -695,7 +702,7 @@ func (cd *commandDefinition) output(resp io.Reader, writer io.Writer, ft formatt | |
return fmt.Errorf("error when decoding response %v: %w", resp, err) | ||
} | ||
} else { | ||
obj, err = addonTransform(resp, single) | ||
obj, err = addonTransform(resp, single, args) | ||
if err != nil { | ||
return fmt.Errorf("error when doing local transform: %w", err) | ||
} | ||
|
@@ -780,7 +787,7 @@ func (cd *commandDefinition) newCommandRunE(c *client) func(*cobra.Command, []st | |
return err | ||
} | ||
isSingle := cd.getEndpoint().OutputType() != multiple && (cd.getEndpoint().OutputType() == single || argGet) | ||
return cd.output(resp, os.Stdout, formatterType(outputFormat), isSingle) | ||
return cd.output(resp, os.Stdout, formatterType(outputFormat), isSingle, argMap) | ||
} | ||
} | ||
|
||
|
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.
@Dyanngg I am confused as to why the check is done on the server-side, and only for the agent?
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.
You are totally right. Reverted that and added the check on the client-side