mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-02 16:29:21 +00:00
commit
acfdefe3b4
@ -38,9 +38,8 @@ __has_resource()
|
|||||||
}
|
}
|
||||||
|
|
||||||
# call kubectl get $1,
|
# call kubectl get $1,
|
||||||
# exclude blank lines
|
# use the first column in compgen
|
||||||
# skip the header stuff kubectl prints on the first 2 lines
|
# we could use templates, but then would need a template per resource
|
||||||
# append $1/ to the first column and use that in compgen
|
|
||||||
__kubectl_parse_get()
|
__kubectl_parse_get()
|
||||||
{
|
{
|
||||||
local kubectl_output out
|
local kubectl_output out
|
||||||
@ -50,6 +49,18 @@ __kubectl_parse_get()
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# $1 is the name of the pod we want to get the list of containers inside
|
||||||
|
__kubectl_get_containers()
|
||||||
|
{
|
||||||
|
local template
|
||||||
|
template="{{ range .DesiredState.Manifest.Containers }}{{ .Name }} {{ end }}"
|
||||||
|
|
||||||
|
local kubectl_out
|
||||||
|
if kubectl_out=$(kubectl get -o template --template="${template}" pods "$1" 2>/dev/null); then
|
||||||
|
COMPREPLY=( $( compgen -W "${kubectl_out[*]}" -- "$cur" ) )
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
__kubectl_pre_command()
|
__kubectl_pre_command()
|
||||||
{
|
{
|
||||||
local flags=(
|
local flags=(
|
||||||
@ -61,6 +72,9 @@ __kubectl_pre_command()
|
|||||||
--client-key=
|
--client-key=
|
||||||
--insecure-skip-tls-verify=
|
--insecure-skip-tls-verify=
|
||||||
--match-server-version=
|
--match-server-version=
|
||||||
|
-n
|
||||||
|
--namespace=
|
||||||
|
--ns-path=
|
||||||
-s
|
-s
|
||||||
--server=
|
--server=
|
||||||
)
|
)
|
||||||
@ -71,7 +85,7 @@ __kubectl_pre_command()
|
|||||||
COMPREPLY=( $(compgen -W "${api_versions[*]}" -- "$cur") )
|
COMPREPLY=( $(compgen -W "${api_versions[*]}" -- "$cur") )
|
||||||
return 0
|
return 0
|
||||||
;;
|
;;
|
||||||
-a | --auth-path | --certificate-authority | --client-certificate | --client-key)
|
-a | --auth-path | --certificate-authority | --client-certificate | --client-key | --ns-path)
|
||||||
_filedir
|
_filedir
|
||||||
return 0
|
return 0
|
||||||
;;
|
;;
|
||||||
@ -79,7 +93,7 @@ __kubectl_pre_command()
|
|||||||
COMPREPLY=( $(compgen -W "true false" -- "$cur") )
|
COMPREPLY=( $(compgen -W "true false" -- "$cur") )
|
||||||
return 0
|
return 0
|
||||||
;;
|
;;
|
||||||
-s | --server)
|
-n | --namespace | -s | --server)
|
||||||
return 0
|
return 0
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
@ -120,22 +134,25 @@ __kubectl_require_file()
|
|||||||
__kubectl_handle_flags_resources()
|
__kubectl_handle_flags_resources()
|
||||||
{
|
{
|
||||||
case $prev in
|
case $prev in
|
||||||
pod | pods)
|
po | pod | pods)
|
||||||
__kubectl_parse_get pods
|
__kubectl_parse_get pods
|
||||||
return 0
|
return 0
|
||||||
;;
|
;;
|
||||||
replicationController | replicationControllers)
|
rc | replicationController | replicationControllers)
|
||||||
__kubectl_parse_get replicationControllers
|
__kubectl_parse_get replicationControllers
|
||||||
return 0
|
return 0
|
||||||
;;
|
;;
|
||||||
service | services)
|
se | service | services)
|
||||||
__kubectl_parse_get services
|
__kubectl_parse_get services
|
||||||
return 0
|
return 0
|
||||||
;;
|
;;
|
||||||
minion | minions)
|
me | minion | minions)
|
||||||
__kubectl_parse_get minions
|
__kubectl_parse_get minions
|
||||||
return 0
|
return 0
|
||||||
;;
|
;;
|
||||||
|
ev | event | events)
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
case $cur in
|
case $cur in
|
||||||
@ -184,7 +201,7 @@ __kubectl_get()
|
|||||||
|
|
||||||
case $prev in
|
case $prev in
|
||||||
-o | --output)
|
-o | --output)
|
||||||
COMPREPLY=( $(compgen -W "table json yaml template" -- "$cur") )
|
COMPREPLY=( $(compgen -W "json yaml template templatefile" -- "$cur") )
|
||||||
return 0
|
return 0
|
||||||
;;
|
;;
|
||||||
-t | --template)
|
-t | --template)
|
||||||
@ -195,6 +212,22 @@ __kubectl_get()
|
|||||||
__kubectl_handle_flags_resources
|
__kubectl_handle_flags_resources
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Require both a pod and a container to be specified
|
||||||
|
__kubectl_require_pod_and_container()
|
||||||
|
{
|
||||||
|
# check is cword-1 is $command
|
||||||
|
if [[ $prev == $command ]]; then
|
||||||
|
__kubectl_parse_get pods
|
||||||
|
return 0
|
||||||
|
fi;
|
||||||
|
|
||||||
|
# this is safe, we know $command is back there somewhere and we know cword-1
|
||||||
|
if [[ ${words[cword-2]} == $command ]]; then
|
||||||
|
__kubectl_get_containers $prev
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
__kubectl_describe()
|
__kubectl_describe()
|
||||||
{
|
{
|
||||||
local resources=()
|
local resources=()
|
||||||
@ -243,7 +276,7 @@ __kubectl_delete()
|
|||||||
__kubectl_post_command()
|
__kubectl_post_command()
|
||||||
{
|
{
|
||||||
case $command in
|
case $command in
|
||||||
create | update)
|
apply | create | update)
|
||||||
__kubectl_require_file
|
__kubectl_require_file
|
||||||
return 0
|
return 0
|
||||||
;;
|
;;
|
||||||
@ -259,6 +292,10 @@ __kubectl_post_command()
|
|||||||
__kubectl_delete
|
__kubectl_delete
|
||||||
return 0
|
return 0
|
||||||
;;
|
;;
|
||||||
|
log)
|
||||||
|
__kubectl_require_pod_and_container
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
*)
|
*)
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
@ -272,10 +309,11 @@ _kubectl()
|
|||||||
_expand || return 0
|
_expand || return 0
|
||||||
COMPREPLY=()
|
COMPREPLY=()
|
||||||
|
|
||||||
local commands=(version proxy get describe create update delete help)
|
local commands=(version proxy get describe create update delete namespace log apply help)
|
||||||
local two_word_flags=(
|
local two_word_flags=(
|
||||||
-a
|
-a
|
||||||
-s
|
-s
|
||||||
|
-n
|
||||||
)
|
)
|
||||||
|
|
||||||
# figure out which command they are running, remembering that arguments to
|
# figure out which command they are running, remembering that arguments to
|
||||||
|
Loading…
Reference in New Issue
Block a user