Merge pull request #24554 from ingvagabund/dhodovska-events-flag-for-describers
Automatic merge from submit-queue Introduce events flag for describers Printing events for a given object is not always needed. Thus, introducing --show-events=false to ``kubectl describe`` to skip events printing. Fixes: #24239
This commit is contained in:
@@ -108,6 +108,44 @@ kube::test::describe_object_assert() {
|
||||
return 0
|
||||
}
|
||||
|
||||
kube::test::describe_object_events_assert() {
|
||||
local resource=$1
|
||||
local object=$2
|
||||
local showevents=${3:-"true"}
|
||||
|
||||
if [[ -z "${3:-}" ]]; then
|
||||
result=$(eval kubectl describe "${kube_flags[@]}" $resource $object)
|
||||
else
|
||||
result=$(eval kubectl describe "${kube_flags[@]}" "--show-events=$showevents" $resource $object)
|
||||
fi
|
||||
|
||||
if [[ -n $(echo "$result" | grep "No events.\|Events:") ]]; then
|
||||
local has_events="true"
|
||||
else
|
||||
local has_events="false"
|
||||
fi
|
||||
if [[ $showevents == $has_events ]]; then
|
||||
echo -n ${green}
|
||||
echo "Successful describe"
|
||||
echo "$result"
|
||||
echo ${reset}
|
||||
return 0
|
||||
else
|
||||
echo ${bold}${red}
|
||||
echo "FAIL"
|
||||
if [[ $showevents == "false" ]]; then
|
||||
echo " Events information should not be described in:"
|
||||
else
|
||||
echo " Events information not found in:"
|
||||
fi
|
||||
echo $result
|
||||
echo ${reset}${red}
|
||||
caller
|
||||
echo ${reset}
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
kube::test::describe_resource_assert() {
|
||||
local resource=$1
|
||||
local matches=${@:2}
|
||||
@@ -136,6 +174,38 @@ kube::test::describe_resource_assert() {
|
||||
return 0
|
||||
}
|
||||
|
||||
kube::test::describe_resource_events_assert() {
|
||||
local resource=$1
|
||||
local showevents=${2:-"true"}
|
||||
|
||||
result=$(eval kubectl describe "${kube_flags[@]}" "--show-events=$showevents" $resource)
|
||||
|
||||
if [[ $(echo "$result" | grep "No events.\|Events:") ]]; then
|
||||
local has_events="true"
|
||||
else
|
||||
local has_events="false"
|
||||
fi
|
||||
if [[ $showevents == $has_events ]]; then
|
||||
echo -n ${green}
|
||||
echo "Successful describe"
|
||||
echo "$result"
|
||||
echo -n ${reset}
|
||||
return 0
|
||||
else
|
||||
echo ${bold}${red}
|
||||
echo "FAIL"
|
||||
if [[ $showevents == "false" ]]; then
|
||||
echo " Events information should not be described in:"
|
||||
else
|
||||
echo " Events information not found in:"
|
||||
fi
|
||||
echo $result
|
||||
caller
|
||||
echo ${reset}
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
kube::test::if_has_string() {
|
||||
local message=$1
|
||||
local match=$2
|
||||
|
@@ -392,9 +392,21 @@ runTests() {
|
||||
kube::test::get_object_jsonpath_assert 'pods/valid-pod' "{$id_field}" 'valid-pod'
|
||||
# Describe command should print detailed information
|
||||
kube::test::describe_object_assert pods 'valid-pod' "Name:" "Image:" "Node:" "Labels:" "Status:" "Controllers"
|
||||
# Describe command should print events information by default
|
||||
kube::test::describe_object_events_assert pods 'valid-pod'
|
||||
# Describe command should not print events information when show-events=false
|
||||
kube::test::describe_object_events_assert pods 'valid-pod' false
|
||||
# Describe command should print events information when show-events=true
|
||||
kube::test::describe_object_events_assert pods 'valid-pod' true
|
||||
# Describe command (resource only) should print detailed information
|
||||
kube::test::describe_resource_assert pods "Name:" "Image:" "Node:" "Labels:" "Status:" "Controllers"
|
||||
|
||||
# Describe command should print events information by default
|
||||
kube::test::describe_resource_events_assert pods
|
||||
# Describe command should not print events information when show-events=false
|
||||
kube::test::describe_resource_events_assert pods false
|
||||
# Describe command should print events information when show-events=true
|
||||
kube::test::describe_resource_events_assert pods true
|
||||
### Validate Export ###
|
||||
kube::test::get_object_assert 'pods/valid-pod' "{{.metadata.namespace}} {{.metadata.name}}" '<no value> valid-pod' "--export=true"
|
||||
|
||||
@@ -1244,8 +1256,20 @@ __EOF__
|
||||
kube::test::get_object_assert services "{{range.items}}{{$id_field}}:{{end}}" 'kubernetes:redis-master:'
|
||||
# Describe command should print detailed information
|
||||
kube::test::describe_object_assert services 'redis-master' "Name:" "Labels:" "Selector:" "IP:" "Port:" "Endpoints:" "Session Affinity:"
|
||||
# Describe command should print events information by default
|
||||
kube::test::describe_object_events_assert services 'redis-master'
|
||||
# Describe command should not print events information when show-events=false
|
||||
kube::test::describe_object_events_assert services 'redis-master' false
|
||||
# Describe command should print events information when show-events=true
|
||||
kube::test::describe_object_events_assert services 'redis-master' true
|
||||
# Describe command (resource only) should print detailed information
|
||||
kube::test::describe_resource_assert services "Name:" "Labels:" "Selector:" "IP:" "Port:" "Endpoints:" "Session Affinity:"
|
||||
# Describe command should print events information by default
|
||||
kube::test::describe_resource_events_assert services
|
||||
# Describe command should not print events information when show-events=false
|
||||
kube::test::describe_resource_events_assert services false
|
||||
# Describe command should print events information when show-events=true
|
||||
kube::test::describe_resource_events_assert services true
|
||||
|
||||
### Dump current redis-master service
|
||||
output_service=$(kubectl get service redis-master -o json --output-version=v1 "${kube_flags[@]}")
|
||||
@@ -1351,8 +1375,20 @@ __EOF__
|
||||
kube::test::get_object_assert rc "{{range.items}}{{$id_field}}:{{end}}" 'frontend:'
|
||||
# Describe command should print detailed information
|
||||
kube::test::describe_object_assert rc 'frontend' "Name:" "Image(s):" "Labels:" "Selector:" "Replicas:" "Pods Status:"
|
||||
# Describe command should print events information by default
|
||||
kube::test::describe_object_events_assert rc 'frontend'
|
||||
# Describe command should not print events information when show-events=false
|
||||
kube::test::describe_object_events_assert rc 'frontend' false
|
||||
# Describe command should print events information when show-events=true
|
||||
kube::test::describe_object_events_assert rc 'frontend' true
|
||||
# Describe command (resource only) should print detailed information
|
||||
kube::test::describe_resource_assert rc "Name:" "Name:" "Image(s):" "Labels:" "Selector:" "Replicas:" "Pods Status:"
|
||||
# Describe command should print events information by default
|
||||
kube::test::describe_resource_events_assert rc
|
||||
# Describe command should not print events information when show-events=false
|
||||
kube::test::describe_resource_events_assert rc false
|
||||
# Describe command should print events information when show-events=true
|
||||
kube::test::describe_resource_events_assert rc true
|
||||
|
||||
### Scale replication controller frontend with current-replicas and replicas
|
||||
# Pre-condition: 3 replicas
|
||||
@@ -1606,8 +1642,20 @@ __EOF__
|
||||
kube::test::get_object_assert rs "{{range.items}}{{$id_field}}:{{end}}" 'frontend:'
|
||||
# Describe command should print detailed information
|
||||
kube::test::describe_object_assert rs 'frontend' "Name:" "Image(s):" "Labels:" "Selector:" "Replicas:" "Pods Status:"
|
||||
# Describe command should print events information by default
|
||||
kube::test::describe_object_events_assert rs 'frontend'
|
||||
# Describe command should not print events information when show-events=false
|
||||
kube::test::describe_object_events_assert rs 'frontend' false
|
||||
# Describe command should print events information when show-events=true
|
||||
kube::test::describe_object_events_assert rs 'frontend' true
|
||||
# Describe command (resource only) should print detailed information
|
||||
kube::test::describe_resource_assert rs "Name:" "Name:" "Image(s):" "Labels:" "Selector:" "Replicas:" "Pods Status:"
|
||||
# Describe command should print events information by default
|
||||
kube::test::describe_resource_events_assert rs
|
||||
# Describe command should not print events information when show-events=false
|
||||
kube::test::describe_resource_events_assert rs false
|
||||
# Describe command should print events information when show-events=true
|
||||
kube::test::describe_resource_events_assert rs true
|
||||
|
||||
### Scale replica set frontend with current-replicas and replicas
|
||||
# Pre-condition: 3 replicas
|
||||
@@ -1901,8 +1949,20 @@ __EOF__
|
||||
kube::test::get_object_assert nodes "{{range.items}}{{$id_field}}:{{end}}" '127.0.0.1:'
|
||||
|
||||
kube::test::describe_object_assert nodes "127.0.0.1" "Name:" "Labels:" "CreationTimestamp:" "Conditions:" "Addresses:" "Capacity:" "Pods:"
|
||||
# Describe command should print events information by default
|
||||
kube::test::describe_object_events_assert nodes "127.0.0.1"
|
||||
# Describe command should not print events information when show-events=false
|
||||
kube::test::describe_object_events_assert nodes "127.0.0.1" false
|
||||
# Describe command should print events information when show-events=true
|
||||
kube::test::describe_object_events_assert nodes "127.0.0.1" true
|
||||
# Describe command (resource only) should print detailed information
|
||||
kube::test::describe_resource_assert nodes "Name:" "Labels:" "CreationTimestamp:" "Conditions:" "Addresses:" "Capacity:" "Pods:"
|
||||
# Describe command should print events information by default
|
||||
kube::test::describe_resource_events_assert nodes
|
||||
# Describe command should not print events information when show-events=false
|
||||
kube::test::describe_resource_events_assert nodes false
|
||||
# Describe command should print events information when show-events=true
|
||||
kube::test::describe_resource_events_assert nodes true
|
||||
|
||||
### kubectl patch update can mark node unschedulable
|
||||
# Pre-condition: node is schedulable
|
||||
|
@@ -378,6 +378,7 @@ service-overrides
|
||||
service-sync-period
|
||||
session-affinity
|
||||
show-all
|
||||
show-events
|
||||
show-labels
|
||||
shutdown-fd
|
||||
shutdown-fifo
|
||||
|
Reference in New Issue
Block a user