Move events command to top level

This commit is contained in:
Maciej Szulik 2022-11-10 14:32:14 +01:00
parent 77b027936a
commit 50c7ebb5b4
No known key found for this signature in database
GPG Key ID: F15E55D276FA84C4
5 changed files with 21 additions and 21 deletions

View File

@ -21,7 +21,6 @@ import (
"k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/kubectl/pkg/cmd/auth" "k8s.io/kubectl/pkg/cmd/auth"
"k8s.io/kubectl/pkg/cmd/events"
cmdutil "k8s.io/kubectl/pkg/cmd/util" cmdutil "k8s.io/kubectl/pkg/cmd/util"
"k8s.io/kubectl/pkg/util/i18n" "k8s.io/kubectl/pkg/util/i18n"
"k8s.io/kubectl/pkg/util/templates" "k8s.io/kubectl/pkg/util/templates"
@ -37,7 +36,6 @@ func NewCmdAlpha(f cmdutil.Factory, streams genericclioptions.IOStreams) *cobra.
// Alpha commands should be added here. As features graduate from alpha they should move // Alpha commands should be added here. As features graduate from alpha they should move
// from here to the CommandGroups defined by NewKubeletCommand() in cmd.go. // from here to the CommandGroups defined by NewKubeletCommand() in cmd.go.
cmd.AddCommand(events.NewCmdEvents(f, streams))
authCmds := &cobra.Command{ authCmds := &cobra.Command{
Use: "auth", Use: "auth",

View File

@ -50,6 +50,7 @@ import (
"k8s.io/kubectl/pkg/cmd/diff" "k8s.io/kubectl/pkg/cmd/diff"
"k8s.io/kubectl/pkg/cmd/drain" "k8s.io/kubectl/pkg/cmd/drain"
"k8s.io/kubectl/pkg/cmd/edit" "k8s.io/kubectl/pkg/cmd/edit"
"k8s.io/kubectl/pkg/cmd/events"
cmdexec "k8s.io/kubectl/pkg/cmd/exec" cmdexec "k8s.io/kubectl/pkg/cmd/exec"
"k8s.io/kubectl/pkg/cmd/explain" "k8s.io/kubectl/pkg/cmd/explain"
"k8s.io/kubectl/pkg/cmd/expose" "k8s.io/kubectl/pkg/cmd/expose"
@ -399,6 +400,7 @@ func NewKubectlCommand(o KubectlOptions) *cobra.Command {
cp.NewCmdCp(f, o.IOStreams), cp.NewCmdCp(f, o.IOStreams),
auth.NewCmdAuth(f, o.IOStreams), auth.NewCmdAuth(f, o.IOStreams),
debug.NewCmdDebug(f, o.IOStreams), debug.NewCmdDebug(f, o.IOStreams),
events.NewCmdEvents(f, o.IOStreams),
}, },
}, },
{ {

View File

@ -48,7 +48,7 @@ import (
var ( var (
eventsLong = templates.LongDesc(i18n.T(` eventsLong = templates.LongDesc(i18n.T(`
Experimental: Display events Display events
Prints a table of the most important information about events. Prints a table of the most important information about events.
You can request events for a namespace, for all namespace, or You can request events for a namespace, for all namespace, or
@ -56,19 +56,19 @@ var (
eventsExample = templates.Examples(i18n.T(` eventsExample = templates.Examples(i18n.T(`
# List recent events in the default namespace. # List recent events in the default namespace.
kubectl alpha events kubectl events
# List recent events in all namespaces. # List recent events in all namespaces.
kubectl alpha events --all-namespaces kubectl events --all-namespaces
# List recent events for the specified pod, then wait for more events and list them as they arrive. # List recent events for the specified pod, then wait for more events and list them as they arrive.
kubectl alpha events --for pod/web-pod-13je7 --watch kubectl events --for pod/web-pod-13je7 --watch
# List recent events in given format. Supported ones, apart from default, are json and yaml. # List recent events in given format. Supported ones, apart from default, are json and yaml.
kubectl alpha events -oyaml kubectl events -oyaml
# List recent only events in given event types # List recent only events in given event types
kubectl alpha events --types=Warning,Normal`)) kubectl events --types=Warning,Normal`))
) )
// EventsFlags directly reflect the information that CLI is gathering via flags. They will be converted to Options, which // EventsFlags directly reflect the information that CLI is gathering via flags. They will be converted to Options, which
@ -122,7 +122,7 @@ func NewCmdEvents(restClientGetter genericclioptions.RESTClientGetter, streams g
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: fmt.Sprintf("events [(-o|--output=)%s] [--for TYPE/NAME] [--watch] [--event=Normal,Warning]", strings.Join(flags.PrintFlags.AllowedFormats(), "|")), Use: fmt.Sprintf("events [(-o|--output=)%s] [--for TYPE/NAME] [--watch] [--event=Normal,Warning]", strings.Join(flags.PrintFlags.AllowedFormats(), "|")),
DisableFlagsInUseLine: true, DisableFlagsInUseLine: true,
Short: i18n.T("Experimental: List events"), Short: i18n.T("List events"),
Long: eventsLong, Long: eventsLong,
Example: eventsExample, Example: eventsExample,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {

View File

@ -35,7 +35,7 @@ run_kubectl_events_tests() {
kube::test::get_object_assert 'namespaces/test-events' "{{$id_field}}" 'test-events' kube::test::get_object_assert 'namespaces/test-events' "{{$id_field}}" 'test-events'
# Pre-condition: event does not exist for Cronjob/pi in any namespace # Pre-condition: event does not exist for Cronjob/pi in any namespace
output_message=$(kubectl alpha events -A "${kube_flags[@]:?}" 2>&1) output_message=$(kubectl events -A "${kube_flags[@]:?}" 2>&1)
kube::test::if_has_not_string "${output_message}" "Warning" "InvalidSchedule" "Cronjob/pi" kube::test::if_has_not_string "${output_message}" "Warning" "InvalidSchedule" "Cronjob/pi"
# Pre-condition: cronjob does not exist in test-events namespace # Pre-condition: cronjob does not exist in test-events namespace
@ -46,40 +46,40 @@ run_kubectl_events_tests() {
kube::test::get_object_assert 'cronjob/pi --namespace=test-events' "{{$id_field}}" 'pi' kube::test::get_object_assert 'cronjob/pi --namespace=test-events' "{{$id_field}}" 'pi'
# Post-Condition: events --all-namespaces returns event for Cronjob/pi # Post-Condition: events --all-namespaces returns event for Cronjob/pi
output_message=$(kubectl alpha events -A "${kube_flags[@]:?}" 2>&1) output_message=$(kubectl events -A "${kube_flags[@]:?}" 2>&1)
kube::test::if_has_string "${output_message}" "Warning" "InvalidSchedule" "Cronjob/pi" kube::test::if_has_string "${output_message}" "Warning" "InvalidSchedule" "Cronjob/pi"
# Post-Condition: events for test-events namespace returns event for Cronjob/pi # Post-Condition: events for test-events namespace returns event for Cronjob/pi
output_message=$(kubectl alpha events -n test-events "${kube_flags[@]:?}" 2>&1) output_message=$(kubectl events -n test-events "${kube_flags[@]:?}" 2>&1)
kube::test::if_has_string "${output_message}" "Warning" "InvalidSchedule" "Cronjob/pi" kube::test::if_has_string "${output_message}" "Warning" "InvalidSchedule" "Cronjob/pi"
# Post-Condition: events returns event for Cronjob/pi when --for flag is used # Post-Condition: events returns event for Cronjob/pi when --for flag is used
output_message=$(kubectl alpha events -n test-events --for=Cronjob/pi "${kube_flags[@]:?}" 2>&1) output_message=$(kubectl events -n test-events --for=Cronjob/pi "${kube_flags[@]:?}" 2>&1)
kube::test::if_has_string "${output_message}" "Warning" "InvalidSchedule" "Cronjob/pi" kube::test::if_has_string "${output_message}" "Warning" "InvalidSchedule" "Cronjob/pi"
# Post-Condition: events returns event for Cronjob/pi when watch is enabled # Post-Condition: events returns event for Cronjob/pi when watch is enabled
output_message=$(kubectl alpha events -n test-events --for=Cronjob/pi --watch --request-timeout=1 "${kube_flags[@]:?}" 2>&1) output_message=$(kubectl events -n test-events --for=Cronjob/pi --watch --request-timeout=1 "${kube_flags[@]:?}" 2>&1)
kube::test::if_has_string "${output_message}" "Warning" "InvalidSchedule" "Cronjob/pi" kube::test::if_has_string "${output_message}" "Warning" "InvalidSchedule" "Cronjob/pi"
# Post-Condition: events returns event for Cronjob/pi when filtered by Warning # Post-Condition: events returns event for Cronjob/pi when filtered by Warning
output_message=$(kubectl alpha events -n test-events --for=Cronjob/pi --types=Warning "${kube_flags[@]:?}" 2>&1) output_message=$(kubectl events -n test-events --for=Cronjob/pi --types=Warning "${kube_flags[@]:?}" 2>&1)
kube::test::if_has_string "${output_message}" "Warning" "InvalidSchedule" "Cronjob/pi" kube::test::if_has_string "${output_message}" "Warning" "InvalidSchedule" "Cronjob/pi"
# Post-Condition: events not returns event for Cronjob/pi when filtered only by Normal # Post-Condition: events not returns event for Cronjob/pi when filtered only by Normal
output_message=$(kubectl alpha events -n test-events --for=Cronjob/pi --types=Normal "${kube_flags[@]:?}" 2>&1) output_message=$(kubectl events -n test-events --for=Cronjob/pi --types=Normal "${kube_flags[@]:?}" 2>&1)
kube::test::if_has_not_string "${output_message}" "Warning" "InvalidSchedule" "Cronjob/pi" kube::test::if_has_not_string "${output_message}" "Warning" "InvalidSchedule" "Cronjob/pi"
# Post-Condition: events returns event for Cronjob/pi without headers # Post-Condition: events returns event for Cronjob/pi without headers
output_message=$(kubectl alpha events -n test-events --for=Cronjob/pi --no-headers "${kube_flags[@]:?}" 2>&1) output_message=$(kubectl events -n test-events --for=Cronjob/pi --no-headers "${kube_flags[@]:?}" 2>&1)
kube::test::if_has_not_string "${output_message}" "LAST SEEN" "TYPE" "REASON" kube::test::if_has_not_string "${output_message}" "LAST SEEN" "TYPE" "REASON"
kube::test::if_has_string "${output_message}" "Warning" "InvalidSchedule" "Cronjob/pi" kube::test::if_has_string "${output_message}" "Warning" "InvalidSchedule" "Cronjob/pi"
# Post-Condition: events returns event for Cronjob/pi in json format # Post-Condition: events returns event for Cronjob/pi in json format
output_message=$(kubectl alpha events -n test-events --for=Cronjob/pi --output=json "${kube_flags[@]:?}" 2>&1) output_message=$(kubectl events -n test-events --for=Cronjob/pi --output=json "${kube_flags[@]:?}" 2>&1)
kube::test::if_has_string "${output_message}" "Warning" "InvalidSchedule" "Cronjob/pi" kube::test::if_has_string "${output_message}" "Warning" "InvalidSchedule" "Cronjob/pi"
# Post-Condition: events returns event for Cronjob/pi in yaml format # Post-Condition: events returns event for Cronjob/pi in yaml format
output_message=$(kubectl alpha events -n test-events --for=Cronjob/pi --output=yaml "${kube_flags[@]:?}" 2>&1) output_message=$(kubectl events -n test-events --for=Cronjob/pi --output=yaml "${kube_flags[@]:?}" 2>&1)
kube::test::if_has_string "${output_message}" "Warning" "InvalidSchedule" "Cronjob/pi" kube::test::if_has_string "${output_message}" "Warning" "InvalidSchedule" "Cronjob/pi"
#Clean up #Clean up

View File

@ -1955,7 +1955,7 @@ metadata:
} }
ginkgo.By("show started event for this pod") ginkgo.By("show started event for this pod")
events := e2ekubectl.RunKubectlOrDie(ns, "alpha", "events", "--for=pod/"+podName) events := e2ekubectl.RunKubectlOrDie(ns, "events", "--for=pod/"+podName)
// replace multi spaces into single white space // replace multi spaces into single white space
eventsStr := strings.Join(strings.Fields(strings.TrimSpace(events)), " ") eventsStr := strings.Join(strings.Fields(strings.TrimSpace(events)), " ")
@ -1964,7 +1964,7 @@ metadata:
} }
ginkgo.By("expect not showing any WARNING message except timeouts") ginkgo.By("expect not showing any WARNING message except timeouts")
events = e2ekubectl.RunKubectlOrDie(ns, "alpha", "events", "--types=WARNING", "--for=pod/"+podName) events = e2ekubectl.RunKubectlOrDie(ns, "events", "--types=WARNING", "--for=pod/"+podName)
if events != "" && !strings.Contains(events, "timed out") { if events != "" && !strings.Contains(events, "timed out") {
framework.Failf("unexpected WARNING event fired") framework.Failf("unexpected WARNING event fired")
} }