├── README.md └── _oc /README.md: -------------------------------------------------------------------------------- 1 | **Note that lately zsh completion should work out of the box with openshift origin, you just have to do a ```source <(oc completion zsh)``` from your shell and it should give you completion. There is still things that this plugin do better in some cases but down the line the effort should be focused on improving the completion inside openshift-origin** 2 | 3 | ## Synopsis 4 | 5 | This is a `oh-my-zsh` plugin to provide shell completion of the OpenShift v3 commands with ZSH. 6 | 7 | `oh-my-zsh` is a zsh framworks making it easy to customise your ZSH Shell. You can find out more about it here : 8 | 9 | http://ohmyz.sh/ 10 | 11 | ## Motivation 12 | 13 | There is a bash completion in the openshift source that are autogenerated by OpenShift but I never got it to work with `bashcompctl` or even with bash directly under MacosX so I wrote my own from scratch. 14 | 15 | ## Installation 16 | 17 | Install `oh-my-zsh` if you haven't it installed following this : 18 | 19 | https://github.com/robbyrussell/oh-my-zsh/#basic-installation 20 | 21 | and execute this : 22 | 23 | > $ git clone https://github.com/chmouel/oh-my-zsh-openshift ~/.oh-my-zsh/custom/plugins/oc 24 | 25 | you can edit your ~/.zshrc and add `oc` to the `plugins` variable like for example : 26 | 27 | > plugins=(oc git) 28 | 29 | ## Installation without oh-myzsh 30 | 31 | I actually don't use `oh-my-zsh` so if you want to use the vanilla zsh you can just checkout this to a directory like `~/.zsh/oc` : 32 | 33 | > $ mkdir -p ~/.zsh/;git clone https://github.com/chmouel/oh-my-zsh-openshift ~/.zsh/oc 34 | 35 | ## Configure (after install both with and without oh-my-zsh) 36 | 37 | In your `~/.zshrc` put thing like this : 38 | 39 | ```bash 40 | typeset -U fpath # Optinal for oh-my-zsh users 41 | fpath=(~/.zsh/oc $fpath) 42 | autoload -U compinit 43 | compinit -i 44 | ``` 45 | 46 | ## Authors 47 | 48 | * Chmouel Boudjnah 49 | * Vincent Behar 50 | 51 | 52 | ## License 53 | 54 | APL 1.0 -- http://opensource.org/licenses/APL-1.0 55 | -------------------------------------------------------------------------------- /_oc: -------------------------------------------------------------------------------- 1 | #compdef oc 2 | 3 | _oc_output_format=( 4 | {-o,--output}"[Output format]:output:(json yaml template templatefile wide)" 5 | ) 6 | 7 | __oc_top_commands() { 8 | local -a list 9 | # oc help | grep -iv deprecated:|gsed -n "/Basic Command/,/Use .oc help/ { /^ / { s/^[ ]*//; p;; } ;}"|gsed -r "s/ +/:'/;s/$/'/;s/^/ /"|sort -n 10 | list=( 11 | adm:'Tools for managing a cluster' 12 | annotate:'Update the annotations on a resource' 13 | apply:'Apply a configuration to a resource by filename or stdin' 14 | attach:'Attach to a running container.' 15 | autoscale:'Autoscale a deployment config or replication controller' 16 | cancel-build:'Cancel a pending or running build' 17 | config:'Change configuration files for the client' 18 | convert:'Convert config files between different API versions' 19 | create:'Create a resource by filename or stdin' 20 | debug:'Launch a new instance of a pod for debugging' 21 | delete:'Delete one or more resources' 22 | deploy:'View, start, cancel, or retry a deployment' 23 | describe:'Show details of a specific resource or group of resources' 24 | edit:'Edit a resource on the server' 25 | exec:'Execute a command in a container.' 26 | explain:'Documentation of resources.' 27 | export:'Export resources so they can be used elsewhere' 28 | expose:'Expose a replicated application as a service or route' 29 | get:'Display one or many resources' 30 | help:'Help about any command' 31 | import-image:'Imports images from a Docker registry' 32 | label:'Update the labels on a resource' 33 | login:'Log in to a server' 34 | logout:'End the current server session' 35 | logs:'Print the logs for a resource.' 36 | new-app:'Create a new application' 37 | new-build:'Create a new build configuration' 38 | new-project:'Request a new project' 39 | patch:'Update field(s) of a resource using strategic merge patch.' 40 | policy:'Manage authorization policy' 41 | port-forward:'Forward one or more local ports to a pod.' 42 | process:'Process a template into list of resources' 43 | project:'Switch to another project' 44 | proxy:'Run a proxy to the Kubernetes API server' 45 | replace:'Replace a resource by filename or stdin.' 46 | rollback:'Revert part of an application back to a previous deployment' 47 | rsh:'Start a shell session in a pod' 48 | rsync:'Copy files between local filesystem and a pod' 49 | run:'Run a particular image on the cluster.' 50 | scale:'Change the number of pods in a deployment' 51 | secrets:'Manage secrets' 52 | serviceaccounts:'Manage service accounts in your project.' 53 | set:'Commands that help set specific features on objects' 54 | start-build:'Start a new build' 55 | status:'Show an overview of the current project' 56 | tag:'Tag existing images into image streams' 57 | types:'An introduction to concepts and types' 58 | version:'Display version' 59 | whoami:'Return information about the current session' 60 | ) 61 | _describe -t top-commands 'top commands' list 62 | } 63 | 64 | __oc_set_commands() { 65 | local -a list 66 | #oc set -h 2>&1 | grep -iv deprecated:|gsed -n "/Configure application resources/,/Use .oc set COMMAND/ { /^ / { s/^[ ]*//; p;; } ;}"|gsed -r "s/ +/:'/;s/$/'/;s/^/ /"|sort -n 67 | list=( 68 | env:'Update environment variables on a pod template' 69 | oc:'set COMMAND [options]' 70 | probe:'Update a probe on a pod template' 71 | triggers:'Update the triggers on a build or deployment config' 72 | volumes:'Update volumes on a pod template' 73 | ) 74 | _describe -t top-commands 'oc set commands' list 75 | } 76 | 77 | __oc_adm_top_commands() { 78 | local -a list 79 | # oc adm -h 2>&1 | grep -iv deprecated:|gsed -n "/Basic Command/,/Use .oc adm help/ { /^ / { s/^[ ]*//; p;; } ;}"|gsed -r "s/ +/:'/;s/$/'/;s/^/ /"|sort -n 80 | list=( 81 | build-chain:'Output the inputs and dependencies of your builds' 82 | ca:'Manage certificates and keys' 83 | config:'Change configuration files for the client' 84 | create-api-client-config:'Create a config file for connecting to the server as a user' 85 | create-bootstrap-policy-file:'Create the default bootstrap policy' 86 | create-bootstrap-project-template:'Create a bootstrap project template' 87 | create-error-template:'Create an error page template' 88 | create-kubeconfig:'Create a basic .kubeconfig file from client certs' 89 | create-login-template:'Create a login template' 90 | create-node-config:'Create a configuration bundle for a node' 91 | create-provider-selection-template:'Create a provider selection template' 92 | diagnostics:'Diagnose common cluster problems' 93 | groups:'Manage groups' 94 | ipfailover:'Install an IP failover group to a set of nodes' 95 | manage-node:'Manage nodes - list pods, evacuate, or mark ready' 96 | new-project:'Create a new project' 97 | overwrite-policy:'Reset the policy to the default values' 98 | pod-network:'Manage pod network' 99 | policy:'Manage policy' 100 | prune:'Remove older versions of resources from the server' 101 | registry:'Install the integrated Docker registry' 102 | router:'Install a router' 103 | ) 104 | _describe -t top-commands 'top commands' list 105 | } 106 | 107 | __oc_adm_policy_top_commands() { 108 | local -a list 109 | # oc adm policy -h 2>&1 | grep -iv deprecated:|gsed -n "/Discover/,/Use .oc adm policy help/ { /^ / { s/^[ ]*//; p;; } ;}"|gsed -r "s/ +/:'/;s/$/'/;s/^/ /"|sort -n 110 | list=( 111 | add-cluster-role-to-group:'Add groups to a role for all projects in the cluster' 112 | add-cluster-role-to-user:'Add users to a role for all projects in the cluster' 113 | add-role-to-group:'Add groups to a role in the current project' 114 | add-role-to-user:'Add users or serviceaccounts to a role in the current project' 115 | add-scc-to-group:'Add groups to a security context constraint' 116 | add-scc-to-user:'Add users or serviceaccount to a security context constraint' 117 | reconcile-cluster-role-bindings:'Replace cluster role bindings to match the recommended bootstrap policy' 118 | reconcile-cluster-roles:'Replace cluster roles to match the recommended bootstrap policy' 119 | reconcile-sccs:'Replace cluster SCCs to match the recommended bootstrap policy' 120 | remove-cluster-role-from-group:'Remove group from role for all projects in the cluster' 121 | remove-cluster-role-from-user:'Remove user from role for all projects in the cluster' 122 | remove-group:'Remove group from the current project' 123 | remove-role-from-group:'Remove group from role in the current project' 124 | remove-role-from-user:'Remove user from role in the current project' 125 | remove-scc-from-group:'Remove group from scc' 126 | remove-scc-from-user:'Remove user from scc' 127 | remove-user:'Remove user from the current project' 128 | who-can:'List who can perform the specified action on a resource' 129 | ) 130 | _describe -t top-commands 'top commands' list 131 | } 132 | 133 | __oc_resources() { 134 | local -a kresources oresources 135 | # curl -H "Authorization: Bearer XXXXX" https://openshift-master:8443/api/v1/ | jq '[.resources[].name]' | grep -iv '/' | gsed -r 's/ +"//;s/",$//;s/^/ /' | sort -n 136 | kresources=( 137 | bindings 138 | componentstatuses 139 | configmaps 140 | endpoints 141 | events 142 | limitranges 143 | namespaces 144 | nodes 145 | persistentvolumeclaims 146 | persistentvolumes 147 | pods 148 | podtemplates 149 | replicationcontrollers 150 | resourcequotas 151 | secrets 152 | securitycontextconstraints 153 | serviceaccounts 154 | services 155 | ) 156 | # curl -H "Authorization: Bearer XXXXX" https://openshift-master:8443/oapi/v1/ | jq '[.resources[].name]' | grep -iv '/' | gsed -r 's/ +"//;s/",$//;s/^/ /' | sort -n 157 | oresources=( 158 | buildconfigs 159 | builds 160 | clusternetworks 161 | clusterpolicies 162 | clusterpolicybindings 163 | clusterrolebindings 164 | clusterroles 165 | deploymentconfigrollbacks 166 | deploymentconfigs 167 | generatedeploymentconfigs 168 | groups 169 | hostsubnets 170 | identities 171 | images 172 | imagestreamimages 173 | imagestreamimports 174 | imagestreammappings 175 | imagestreams 176 | imagestreamtags 177 | localresourceaccessreviews 178 | localsubjectaccessreviews 179 | netnamespaces 180 | oauthaccesstokens 181 | oauthauthorizetokens 182 | oauthclientauthorizations 183 | oauthclients 184 | policies 185 | policybindings 186 | processedtemplates 187 | projectrequests 188 | projects 189 | resourceaccessreviews 190 | rolebindings 191 | roles 192 | routes 193 | subjectaccessreviews 194 | templates 195 | useridentitymappings 196 | users 197 | ) 198 | _describe -t kresources 'kubernetes resources' kresources 199 | _describe -t oresources 'openshift resources' oresources 200 | } 201 | 202 | __oc_types () { 203 | local -a k8t ost 204 | 205 | k8t=(pods po 206 | replicationcontrollers rc 207 | daemonsets ds 208 | services svc 209 | events ev 210 | secrets 211 | configmaps 212 | persistentvolumes pv 213 | persistentvolumeclaims pvc 214 | limitranges limits 215 | resourcequotas quota 216 | nodes no 217 | namespaces ns 218 | componentstatuses cs 219 | endpoints ep 220 | serviceaccounts sa 221 | securitycontextconstraints scc) 222 | 223 | ost=(deploymentconfigs dc 224 | buildconfigs bc 225 | builds 226 | routes 227 | projects 228 | images 229 | imagestreams is 230 | imagestreamtags istag 231 | imagestreamimages isimage 232 | templates 233 | users 234 | groups 235 | identities 236 | policies 237 | policybindings 238 | roles 239 | rolebindings 240 | clusterpolicies 241 | clusterpolicybindings 242 | clusterroles 243 | clusterrolebindings 244 | oauthclients 245 | oauthaccesstokens 246 | hostsubnets 247 | clusternetworks) 248 | 249 | k8t_str="openshift_types:OpenShift Types:compadd -a k8t" 250 | ost_str="openshift_types:OpenShift Types:compadd -a ost" 251 | [[ $1 == "k8" ]] && astr=$k8t_str 252 | [[ $1 == "os" ]] && astr=$ost_str 253 | [[ -z $astr ]] && astr="$k8t_str $ost_str" 254 | 255 | _alternative $astr 256 | } 257 | 258 | __oc_k8s_types() { __oc_types k8 ;} 259 | 260 | __oc_contexts () { 261 | compadd $(oc config view -o template \ 262 | --template='{{$dot := .}}{{range $element := (index $dot "contexts")}}{{ .name }} {{end}}') 263 | } 264 | 265 | __oc_all_roles() { 266 | __oc_get_clusterroles 267 | __oc_get_roles 268 | } 269 | __oc_containers () { compadd $(oc get pods -o template --template='{{range.items}}{{range .spec.containers}}{{.name}} 270 | {{end}}{{end}}' | sort | uniq | tr '\n' ' ') } 271 | __oc_get () { compadd $(oc get $1 $2 -o template --template='{{range.items}}{{.metadata.name}} {{end}}')} 272 | __oc_pods () { __oc_get pods} 273 | __oc_pods_running () { __oc_get pods } 274 | __oc_build_pods () { __oc_get pods "-l openshift.io/build.name" } 275 | __oc_deployed_pods () { __oc_get pods "-l deploymentconfig" } 276 | __oc_build () { __oc_get build } 277 | __oc_build_configs () { __oc_get bc } 278 | __oc_deployment_configs () { __oc_get dc } 279 | __oc_project () {__oc_get project } 280 | __oc_namespace () {__oc_get ns } 281 | __oc_route () {__oc_get route } 282 | __oc_get_persistentVolumes () {__oc_get pv } 283 | __oc_get_persistentVolumeClaims () {__oc_get pvc } 284 | __oc_get_imageStream () {__oc_get is } 285 | __oc_get_imageStreamTags () { compadd $(oc get is -o template --template='{{range .items}}{{$is:=.metadata.name}}{{range .status.tags}}{{$is}}:{{.tag}} {{end}}{{end}}') } 286 | __oc_get_imageStreamImages () { compadd $(oc get is -o template --template='{{range .items}}{{$is:=.metadata.name}}{{range .status.tags}}{{range .items}}{{$is}}@{{.image}} {{end}}{{end}}{{end}}') } 287 | __oc_get_template () {__oc_get template } 288 | __oc_get_secrets () {__oc_get secrets } 289 | __oc_get_configmaps () {__oc_get configmaps } 290 | __oc_get_replicationControllers () { __oc_get rc } 291 | __oc_get_serviceAccounts () { __oc_get sa } 292 | __oc_get_service () { __oc_get service } 293 | __oc_get_node () { __oc_get node } 294 | __oc_get_policies () { __oc_get policies } 295 | __oc_get_rolebindings () { __oc_get rolebindings } 296 | __oc_get_limits () { __oc_get limits } 297 | __oc_get_quota () { __oc_get quota } 298 | __oc_get_users () { __oc_get users } 299 | __oc_get_groups () { __oc_get groups } 300 | __oc_get_endpoints () { __oc_get endpoints } 301 | __oc_get_securityContextConstraints () { __oc_get scc } 302 | __oc_get_policyBindings () { __oc_get policybindings } 303 | __oc_get_roles () { __oc_get roles } 304 | __oc_get_oauthclients () { __oc_get oauthclients } 305 | __oc_get_clusterpolicies () { __oc_get clusterpolicies } 306 | __oc_get_clusterpolicybindings () { __oc_get clusterpolicybindings } 307 | __oc_get_clusterroles () { __oc_get clusterroles } 308 | __oc_get_clusterrolebindings () { __oc_get clusterrolebindings } 309 | 310 | __oc_avail_shell() { 311 | rets=(/bin/zsh /bin/sh /bin/bash) 312 | [[ -e /etc/shells ]] && rets=(${(Z+Cn+)"$(command' \ 340 | '(-)*:: :->option-or-argument' 341 | case $state in 342 | (command) 343 | __oc_adm_top_commands 344 | ;; 345 | (option-or-argument) 346 | curcontext=${curcontext%:*:*}:oc-$words[1]: 347 | __oc_adm_subcommand 348 | ;; 349 | esac 350 | ;; 351 | (set) 352 | local curcontext="$curcontext" state 353 | _arguments -C \ 354 | '(-): :->command' \ 355 | '(-)*:: :->option-or-argument' 356 | case $state in 357 | (command) 358 | __oc_set_commands 359 | ;; 360 | (option-or-argument) 361 | curcontext=${curcontext%:*:*}:oc-$words[1]: 362 | #TODO(chmouel): Lazy b* 363 | ;; 364 | esac 365 | ;; 366 | (annotate) 367 | _arguments '1: :__oc_types' 368 | ;; 369 | (build-logs) 370 | _arguments -C -s -S -A "-*" \ 371 | {-f,--follow}"[Specify whether logs should be followed; default is true]" \ 372 | {-w,--nowait}"[Specify whether to return immediately without waiting for logs to be available; default is false]" \ 373 | '1:ocbuild:__oc_build' 374 | ;; 375 | (cancel-build) 376 | _arguments -C -s -S -A "-*" \ 377 | "--dump-logs[Specify if the build logs for the cancelled build should be shown]" \ 378 | "--restart[Specify if a new build should be created after the current build is cancelled]" \ 379 | '1:ocbuild:__oc_build' 380 | ;; 381 | (config) 382 | _arguments \ 383 | '1: :(view use-context)' 384 | ;; 385 | (create) 386 | _arguments \ 387 | {-f,--filename=}"[Filename, directory, or URL to file to use to create the resource]:filename:_files" \ 388 | '1:command:(namespace secret configmap serviceaccount route)' 389 | ;; 390 | (apply|replace|process) 391 | _arguments \ 392 | {-f,--filename=}"[Filename, directory, or URL to file to use to create the resource]:filename:_files" 393 | ;; 394 | (exec) 395 | _arguments -C -s -S -A "-*" \ 396 | {-p,--pod}"[Pod name]:pod:__oc_pods_running" \ 397 | {-i,--stdin}"[Pass stdin to the container]" \ 398 | {-t,--tty}"[Stdin is a TTY]" \ 399 | '*::arguments: _normal' 400 | ;; 401 | (get|export) 402 | _arguments \ 403 | $_oc_output_format \ 404 | "--all-namespaces[Select all resources in the namespace of the specified resource types]" \ 405 | ':octypes:__oc_types' 406 | ;; 407 | (deploy) 408 | _arguments \ 409 | $_oc_output_format \ 410 | "--cancel[Cancel the in-progress deployment]" \ 411 | "--enable-triggers[Enables all image triggers for the deployment config]" \ 412 | "--latest[Start a new deployment now]" \ 413 | "--retry[etry the latest failed deployment.]" \ 414 | ':octypes:__oc_deployment_configs' 415 | ;; 416 | (delete|describe|edit|volume) 417 | _arguments \ 418 | ':octypes:__oc_types' 419 | ;; 420 | (start-build) 421 | _arguments -C -s -S -A "-*" \ 422 | "--follow[Start a build and watch its logs until it completes or fails]" \ 423 | "--from-build=[Specify the name of a build which should be re-run]:from-build:" \ 424 | "--from-webhook=[Specify a webhook URL for an existing BuildConfign to trigger]:from-webhook:" \ 425 | "--git-post-receive=[The contents of the post-receive hook to trigger a build]:" \ 426 | "--git-repository=[The path to the git repository for post-receive; defaults to the current directory]:git-repo:_files -/" \ 427 | "--list-webhooks=[List the webhooks for the specified BuildConfig or build]:webhooks:(all generic github)" \ 428 | '1:ocbuild:__oc_build_configs' 429 | ;; 430 | (rsh) 431 | _arguments -C -s -S -A "-*" \ 432 | {-s,--shell}"[shell]:shells:__oc_avail_shell" \ 433 | ':ocrunning:__oc_pods_running' 434 | ;; 435 | (login) 436 | _arguments \ 437 | {-u,--user}"[Username, will prompt if not provided]:users:_users" \ 438 | {-p,--password}"[Password, will prompt if not provided]:password:" \ 439 | ':host_port:_oc_hosts_default_port' 440 | ;; 441 | (logs) 442 | _arguments \ 443 | "--all-containers[Get all containerss logs in the pod(s)]" \ 444 | "--limit-bytes=[Maximum bytes of logs to return. Defaults to no limit.]:" \ 445 | "--pod-running-timeout=[The length of time (like 5s, 2m) to wait until at least one pod is running]:" \ 446 | {-l,--selector}="[Selector (label query) to filter on]" \ 447 | {-f,--follow}"[Specify if the logs should be streamed.]" \ 448 | "--tail=[Lines of recent log file to display]" \ 449 | {-p,--previous}"[Print the logs for the previous instance of the container in a pod if it exists.]" \ 450 | {-c,--container}"[The container to use for printing its logs]:container:__oc_containers" \ 451 | '1:ocrunning:__oc_pods' 452 | ;; 453 | (new-app) 454 | _arguments -C \ 455 | "--code=[Source code to use to build this application]:code_path:_path_files -/" \ 456 | "--context-dir=[Context directory to be used for the build]:context_dir:_path_files -/" \ 457 | "--docker-image=[Name of a Docker image to include in the app]:docker_image:" \ 458 | {-e,--env}"[Specify key value pairs of environment variables to set into each container]:envs:" \ 459 | {-f,--file}"[Path to a template file to use for the app]:template_file:_files" \ 460 | "--group=[Indicate components that should be grouped together as +]:group:" \ 461 | "--image=[Name of an image stream to use in the app. (deprecated)]:image:" \ 462 | {-i,--image-stream}"[Name of an image stream to use in the app]:image_stream:__oc_get_imageStream" \ 463 | "--insecure-registry[Insecure registry]" \ 464 | {-l,--label}"[Label to set in all resources for this application]:labels:" \ 465 | {-L,--list}"[List all local templates and image streams that can be used to create]:list:" \ 466 | "--no-headers[When using the default output, don't print headers]" \ 467 | "--name=[Set name to use for generated application artifacts]:name:" \ 468 | $_oc_output_format \ 469 | "--output_template=[Template string or path to template file to use]:template:_files" \ 470 | "--output-version=[Output the formatted object with the given version]:output_version" \ 471 | {-p,--param}"[Specify a list of key value pairs to override]:params:" \ 472 | {-S,--search}"[Search for components that match the arguments provided and print the results]" \ 473 | "--strategy=[Specify the build strategy to use if you don't want to detect]:strategy:(docker source)" \ 474 | "--template=[Name of a stored template to use in the app]:stored_template:__oc_get_template" \ 475 | ':path:_files' 476 | ;; 477 | (new-project) 478 | _arguments \ 479 | "--description=[Project description]:description:" \ 480 | "--display-name=[Project display name]:displayname:" 481 | ;; 482 | (project) 483 | _arguments '1:ocrunning:__oc_project' 484 | ;; 485 | (rsync) 486 | _arguments -C \ 487 | {-c,--container}"[Container within the pod]:running containers:__oc_containers" \ 488 | "--delete=[Delete files not present in source]:delete_file:(true false)" \ 489 | {-q,--quiet=}"[Suppress non-error messages]:quiet:(true false)" \ 490 | "--strategy=[Specify which strategy to use for copy: rsync, rsync-daemon, or tar]:strategy:(rsync rsync-daemon tar)" \ 491 | '1:files:__pods_and_files' \ 492 | '2:files:__pods_and_files' 493 | ;; 494 | (secrets) 495 | _arguments '1:ocrunning:(new new-basicauth new-sshauth new-dockercfg add)' # TODO(chmouel): extend properly 496 | ;; 497 | (serviceaccounts) 498 | _arguments \ 499 | '1:command:(get-token new-token)' \ 500 | '2:service account:__oc_get_serviceAccounts' 501 | ;; 502 | (import-image) 503 | _arguments '1:ocrunning:__oc_get_imageStream' 504 | ;; 505 | (scale) 506 | _arguments \ 507 | "--current-replicas=[Precondition for current size.]:current-replicas:" \ 508 | "--replicas=[The new desired number of replicas.]:replicas:" \ 509 | '1:ocscale:(rc dc)' 510 | ;; 511 | (expose) 512 | _arguments \ 513 | "--dry-run=[If true, only print the object that would be sent, without creating it.]:dry-run:" \ 514 | "--hostname=[Set a hostname for the new route]:hostname:" \ 515 | "--name=[The name for the newly created object.]:name:" \ 516 | "--port=[The port that the service should serve on. Copied from the resource being exposed, if unspecified]:port:" \ 517 | "--protocol=[The network protocol for the service to be created. Default is 'tcp'.]:protocol:" \ 518 | "--selector=[A label selector to use for this service. If empty (the default) infer the selector from the replication controller.]:selector:" \ 519 | "--session-affinity=[If non-empty, set the session affinity for the service to this; legal values: 'None', 'ClientIP']:session-affinity:" \ 520 | "--target-port=[Name or number for the port on the container that the service should direct traffic to. Optional.]:target-port:" \ 521 | "--type=[Type for this service: ClusterIP, NodePort, or LoadBalancer. Default is 'ClusterIP'.]:type:" \ 522 | '1:ocexpose:(pod rc dc svc)' 523 | ;; 524 | (explain) 525 | _arguments \ 526 | "--recursive=[Print the fields of fields (Currently only 1 level deep)]:recursive:" \ 527 | '1:ocexplain:__oc_k8s_types' 528 | ;; 529 | (port-forward) 530 | _arguments \ 531 | '1:ocportforward:__oc_deployed_pods' 532 | ;; 533 | (status) 534 | _arguments \ 535 | "-o=[Output format]:output:(dot)" 536 | ;; 537 | (whoami) 538 | _arguments \ 539 | {-c,--context}"[Print the current user context name]::" \ 540 | {-t,--token}"[Print the token the current session is using]::" 541 | ;; 542 | (help) 543 | _arguments \ 544 | ':top-commands:__oc_top_commands' 545 | ;; 546 | (*) 547 | _message 'Unkown sub command' 548 | esac 549 | 550 | case "$words[2]" in 551 | (po|pod|pods) __oc_pods ;; 552 | (rc|replicationcontrollers|replicationControllers) __oc_get_replicationControllers ;; 553 | (svc|service|services) __oc_get_service;; 554 | (dc|deploymentConfigs|deploymentConfig) __oc_deployment_configs;; 555 | (bc|buildConfigs|buildConfig) __oc_build_configs ;; 556 | (build|builds) __oc_build;; 557 | (route|routes) __oc_route;; 558 | (project|projects) __oc_project;; 559 | (secret|secrets) __oc_get_secrets;; 560 | (configmap|configmaps) __oc_get_configmaps;; 561 | (is|imageStreams) __oc_get_imageStream;; 562 | (istag|imageStreamTags) __oc_get_imageStreamTags;; 563 | (isimage|imageStreamImages) __oc_get_imageStreamImages;; 564 | (pv|persistentVolumes) __oc_get_persistentVolumes;; 565 | (pvc|persistentVolumeClaims) __oc_get_persistentVolumeClaims;; 566 | (sa|serviceAccounts) __oc_get_serviceAccounts;; 567 | (template|templates) __oc_get_template;; 568 | (policy|policies) __oc_get_policies;; 569 | (rolebinding|rolebindings) __oc_get_rolebindings;; 570 | (limits|limitranges) __oc_get_limits;; 571 | (quota|resourcequotas) __oc_get_quota;; 572 | (no|node|nodes) __oc_get_node;; 573 | (ns|namespace|namespaces) __oc_namespace;; 574 | (user|users) __oc_get_users;; 575 | (group|groups) __oc_get_groups;; 576 | (ep|endpoint|endpoints) __oc_get_endpoints;; 577 | (scc|securitycontextconstraints) __oc_get_securityContextConstraints;; 578 | (policybindings|policybindingss) __oc_get_policyBindings;; 579 | (role|roles) __oc_get_roles;; 580 | (oauthclient|oauthclients) __oc_get_oauthclients;; 581 | (clusterpolicy|clusterpolicies) __oc_get_clusterpolicies;; 582 | (clusterpolicybinding|clusterpolicybindings) __oc_get_clusterpolicybindings;; 583 | (clusterrole|clusterroles) __oc_get_clusterroles;; 584 | (clusterrolebinding|clusterrolebindings) __oc_get_clusterrolebindings;; 585 | (use-context) __oc_contexts;; 586 | esac 587 | 588 | } 589 | 590 | __oc_adm_subcommand () { 591 | case "$words[1]" in 592 | (diagnostics) 593 | _arguments \ 594 | "--host=[Look for systemd and journald units even without master/node config]:host:(true false)" \ 595 | "--prevent-modification=[May be set to prevent diagnostics making any changes via the API]:preventmodif:(true false)" \ 596 | {-l,--diaglevel}'[Level of diagnostic output (0-4)]:diaglevel:((0\:"Debug" 1\:"Info" 2\:"Notice" 3\:"Warn" 4\:"Error"))' \ 597 | '*:diagnostic:(AnalyzeLogs ClusterRegistry ClusterRoleBindings ClusterRoles ClusterRouter ConfigContexts DiagnosticPod MasterConfigCheck MasterNode NodeConfigCheck NodeDefinitions UnitStatus)' 598 | ;; 599 | (new-project) 600 | _arguments \ 601 | "--admin=[Project admin username]:user:__oc_get_users" \ 602 | "--admin-role=[Project admin role name in the cluster policy]:role:__oc_all_roles" \ 603 | "--description=[Project description]:description:" \ 604 | "--display-name=[Project display name]:display name:" \ 605 | "--node-selector=[Restrict pods onto nodes matching given label selector. Format: '=, =...'. Specifying \"\" means any node, not default. If unspecified, cluster default node selector will be used]:node selector:" \ 606 | '1:project:()' 607 | ;; 608 | (manage-node) 609 | _arguments \ 610 | "--schedulable=[Control pod schedulability on the node]:schedulable:(true false)" \ 611 | "--evacuate=[Migrate all/selected pods on the node]:evacuate:(true false)" \ 612 | "--list-pods=[List all/selected pods on the node. Printer flags --output, etc. are only valid for this option.]:list:(true false)" \ 613 | '1:node:__oc_get_node' 614 | ;; 615 | (build-chain) 616 | _arguments \ 617 | "--all=[Build dependency tree for the specified image stream tag across all namespaces]:all:(true false)" \ 618 | "--trigger-only=[If true, only include dependencies based on build triggers. If false, include all dependencies.]:evacuate:(true false)" \ 619 | '1:ist:__oc_get_imageStreamTags' 620 | ;; 621 | (groups) 622 | local curcontext="$curcontext" state 623 | _arguments -C \ 624 | '(-): :->command' \ 625 | '(-)*:: :->option-or-argument' 626 | case $state in 627 | (command) 628 | compadd "new" "add-users" "remove-users" "sync" "prune" 629 | ;; 630 | (option-or-argument) 631 | curcontext=${curcontext%:*:*}:oc-$words[1]: 632 | __oc_adm_groups_subcommand 633 | ;; 634 | esac 635 | ;; 636 | (policy) 637 | local curcontext="$curcontext" state 638 | _arguments -C \ 639 | '(-): :->command' \ 640 | '(-)*:: :->option-or-argument' 641 | case $state in 642 | (command) 643 | __oc_adm_policy_top_commands 644 | ;; 645 | (option-or-argument) 646 | curcontext=${curcontext%:*:*}:oc-$words[1]: 647 | __oc_adm_policy_subcommand 648 | ;; 649 | esac 650 | ;; 651 | (*) 652 | _message 'Unkown sub command' 653 | esac 654 | } 655 | 656 | __oc_adm_groups_subcommand () { 657 | case "$words[1]" in 658 | (new) 659 | _arguments \ 660 | '1:group:()' \ 661 | '*:users:__oc_get_users' 662 | ;; 663 | (add-users|remove-user) 664 | _arguments \ 665 | '1:group:__oc_get_groups' \ 666 | '*:users:__oc_get_users' 667 | ;; 668 | esac 669 | } 670 | 671 | __oc_adm_policy_subcommand () { 672 | case "$words[1]" in 673 | (add-role-to-group|remove-role-from-group) 674 | _arguments \ 675 | '1:role:__oc_all_roles' \ 676 | '*:groups:__oc_get_groups' 677 | ;; 678 | (add-role-to-user|remove-role-from-user) 679 | _arguments \ 680 | '1:role:__oc_all_roles' \ 681 | '*:users:__oc_get_users' 682 | ;; 683 | (add-cluster-role-to-group|remove-cluster-role-from-group) 684 | _arguments \ 685 | '1:clusterrole:__oc_get_clusterroles' \ 686 | '*:groups:__oc_get_groups' 687 | ;; 688 | (add-cluster-role-to-user|remove-cluster-role-from-user) 689 | _arguments \ 690 | '1:clusterrole:__oc_get_clusterroles' \ 691 | '*:users:__oc_get_users' 692 | ;; 693 | (add-scc-to-group|remove-scc-from-group) 694 | _arguments \ 695 | '1:scc:__oc_get_securityContextConstraints' \ 696 | '*:groups:__oc_get_groups' 697 | ;; 698 | (add-scc-to-user|remove-scc-from-user) 699 | _arguments \ 700 | {-z,--serviceaccount}"[service account in the current namespace to use as a user]:service account:__oc_get_serviceAccounts" \ 701 | '1:scc:__oc_get_securityContextConstraints' \ 702 | '*:users:__oc_get_users' 703 | ;; 704 | (remove-group) 705 | _arguments \ 706 | '*:groups:__oc_get_groups' 707 | ;; 708 | (remove-user) 709 | _arguments \ 710 | '*:users:__oc_get_users' 711 | ;; 712 | (who-can) 713 | _arguments \ 714 | "--all-namespaces[If present, list who can perform the specified action in all namespaces.]" \ 715 | '1:verb:(get list create update delete deletecollection watch)' \ 716 | '2:resource:__oc_resources' 717 | ;; 718 | (*) 719 | _message 'Unkown sub command' 720 | esac 721 | } 722 | 723 | _oc () { 724 | local curcontext="$curcontext" state common_options 725 | common_options=( 726 | '--alsologtostderr=[log to standard error as well as files]:log also to stderr:(true false)' 727 | '--api-version=[The API version to use when talking to the server]:api version:' 728 | '--certificate-authority=[Path to a cert. file for the certificate authority.]:certa auth:_files' 729 | '--client-certificate=[Path to a client cert file for TLS.]:client cert:_files' 730 | '--client-key=[Path to a client key file for TLS.]:client key:_files' 731 | '--cluster=[The name of the kubeconfig cluster to use]:cluster:' 732 | '--config=[Path to the config file to use for CLI requests.]:config file:_files' 733 | '--context=[The name of the kubeconfig context to use]:context:__oc_contexts' 734 | '--google-json-key=[The Google Cloud Platform Service Account JSON Key to use for authentication.]:google json:' 735 | '--httptest.serve=[if non-empty, httptest.NewServer serves on this address and blocks]:httptest:' 736 | '--insecure-skip-tls-verify=[If use insecure HTTPS connections.]:insecure:(true false)' 737 | '--log-backtrace-at=[when logging hits line file:N, emit a stack trace]:log backtrace:' 738 | '--log-dir=[If non-empty, write log files in this directory]:log dir:_directories' 739 | '--log-flush-frequency=[Maximum number of seconds between log flushes]:log flush:' 740 | '--loglevel=[Set the level of log output (0-5)]:loglevel:(0 1 2 3 4 5)' 741 | '--logtostderr=[log to standard error instead of files]:log to stderr:(true false)' 742 | '--match-server-version=[Require server version to match client version]:match version:(true false)' 743 | {-n,--namespace}'[If present, the namespace scope for this CLI request.]:namespace:__oc_project' 744 | '--server=[The address and port of the Kubernetes API server]:server:' 745 | '--stderrthreshold=[logs at or above this threshold go to stderr]:stderr:' 746 | '--token=[Bearer token for authentication to the API server.]:token:' 747 | '--user=[The name of the kubeconfig user to use]:user:' 748 | '--v=[log level for V logs]:' 749 | '--validate=[If true, use a schema to validate the input before sending it]:validate:(true false)' 750 | '--vmodule=[comma-separated list of pattern=N settings for file-filtered logging]:vmodule:') 751 | 752 | _arguments -C \ 753 | ${common_options} \ 754 | '(-): :->command' \ 755 | '(-)*:: :->option-or-argument' 756 | case $state in 757 | (command) 758 | __oc_top_commands 759 | ;; 760 | (option-or-argument) 761 | curcontext=${curcontext%:*:*}:oc-$words[1]: 762 | __oc_subcommand 763 | ;; 764 | esac 765 | } 766 | 767 | _oc "$@" 768 | 769 | # Local Variables: 770 | # mode: sh 771 | # End: 772 | # vim: ft=zsh 773 | --------------------------------------------------------------------------------