mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-30 15:05:27 +00:00
Add event listing and printing to kubecfg
This commit is contained in:
parent
10214457b7
commit
68a784439b
@ -46,6 +46,7 @@ var (
|
||||
preventSkew = flag.Bool("expect_version_match", false, "Fail if server's version doesn't match own version.")
|
||||
config = flag.String("c", "", "Path or URL to the config file, or '-' to read from STDIN")
|
||||
selector = flag.String("l", "", "Selector (label query) to use for listing")
|
||||
fieldSelector = flag.String("fields", "", "Selector (field query) to use for listing")
|
||||
updatePeriod = flag.Duration("u", 60*time.Second, "Update interval period")
|
||||
portSpec = flag.String("p", "", "The port spec, comma-separated list of <external>:<internal>,...")
|
||||
servicePort = flag.Int("s", -1, "If positive, create and run a corresponding service on this port, only used with 'run'")
|
||||
@ -376,6 +377,9 @@ func executeAPIRequest(ctx api.Context, method string, c *client.Client) bool {
|
||||
if len(*selector) > 0 {
|
||||
r.ParseSelectorParam("labels", *selector)
|
||||
}
|
||||
if len(*fieldSelector) > 0 {
|
||||
r.ParseSelectorParam("fields", *fieldSelector)
|
||||
}
|
||||
if setBody {
|
||||
if len(version) > 0 {
|
||||
data := readConfig(storage, c.RESTClient.Codec)
|
||||
|
@ -143,6 +143,7 @@ var replicationControllerColumns = []string{"ID", "Image(s)", "Selector", "Repli
|
||||
var serviceColumns = []string{"ID", "Labels", "Selector", "Port"}
|
||||
var minionColumns = []string{"Minion identifier"}
|
||||
var statusColumns = []string{"Status"}
|
||||
var eventColumns = []string{"Name", "Kind", "Status", "Reason", "Message"}
|
||||
|
||||
// addDefaultHandlers adds print handlers for default Kubernetes types.
|
||||
func (h *HumanReadablePrinter) addDefaultHandlers() {
|
||||
@ -155,6 +156,8 @@ func (h *HumanReadablePrinter) addDefaultHandlers() {
|
||||
h.Handler(minionColumns, printMinion)
|
||||
h.Handler(minionColumns, printMinionList)
|
||||
h.Handler(statusColumns, printStatus)
|
||||
h.Handler(eventColumns, printEvent)
|
||||
h.Handler(eventColumns, printEventList)
|
||||
}
|
||||
|
||||
func (h *HumanReadablePrinter) unknown(data []byte, w io.Writer) error {
|
||||
@ -256,6 +259,27 @@ func printStatus(status *api.Status, w io.Writer) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func printEvent(event *api.Event, w io.Writer) error {
|
||||
_, err := fmt.Fprintf(
|
||||
w, "%s\t%s\t%s\t%s\t%s\n",
|
||||
event.InvolvedObject.Name,
|
||||
event.InvolvedObject.Kind,
|
||||
event.Status,
|
||||
event.Reason,
|
||||
event.Message,
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
||||
func printEventList(list *api.EventList, w io.Writer) error {
|
||||
for i := range list.Items {
|
||||
if err := printEvent(&list.Items[i], w); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Print parses the data as JSON, then prints the parsed data in a human-friendly
|
||||
// format according to the type of the data.
|
||||
func (h *HumanReadablePrinter) Print(data []byte, output io.Writer) error {
|
||||
|
Loading…
Reference in New Issue
Block a user