-
Notifications
You must be signed in to change notification settings - Fork 4
/
_kubectl
1497 lines (1351 loc) · 81.4 KB
/
_kubectl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#compdef kubectl
# nnao45/zsh-kubectl-completion's version: v0.1.12
#
# Support kubectl version v1.13.5
# Inspired by
# https://github.com/zsh-users/zsh-completionsrfe/blob/master/src/_golang
# https://github.com/felixr/docker-zsh-completion/blob/master/_docker
# https://github.com/git/git/blob/master/contrib/completion/git-completion.zsh
__parse_kube_get(){
local -a _ns _cl _ur _cx _sv
if [ ! -z ${_filter_namespace} ];then
_ns="--namespace ${_filter_namespace}"
fi
if [ ! -z ${_filter_cluster} ];then
_cl="--cluster ${_filter_cluster}"
fi
if [ ! -z ${_filter_user} ];then
_ur="--user ${_filter_user}"
fi
if [ ! -z ${_filter_context} ];then
_cx="--context ${_filter_context}"
fi
if [ ! -z ${_filter_server} ];then
_sv="--server ${_filter_server}"
fi
if [ ! -z ${_filter_kubeconfig} ];then
_kc="--kubeconfig ${_filter_kubeconfig}"
fi
if [ ${1} = 'api-resources' ]; then
eval kubectl ${1} ${_ns} ${_cl} ${_ur} ${_cx} ${_sv} ${_kc} -o wide 2>/dev/null
elif [ ${1} = 'contexts' ]; then
eval kubectl config get-contexts ${_ns} ${_cl} ${_ur} ${_cx} ${_sv} ${_kc} 2>/dev/null
else
eval kubectl get ${1} ${_ns} ${_cl} ${_ur} ${_cx} ${_sv} ${_kc} -o wide 2>/dev/null
fi
}
__parse_cmd_result(){
echo ${1} | tail -n +2 | tr ' ' '$'
}
__parse_cmd_result_withoutcomment(){
echo ${1} | tail -n +2 | awk '{print $1}'
}
__parse_print2list(){
echo ${1} | tr '$' ' ' | awk '{print $'${2}'}'
}
__kube_get_exec(){
local -a _parse_result _parse_list _cmd_result
integer ret=1
_cmd_result=$(__parse_kube_get ${1})
if [ ! -z ${_cmd_result} ]; then
_parse_result=($(__parse_cmd_result ${_cmd_result}))
_parse_list=()
for _r in ${_parse_result}
do
_parse_list+=("$(${2} ${_r})")
done
_values "${1}" ${_parse_list[@]} && ret=0
fi
return ret
}
__kube_get_exec_contexts(){
local -a _parse_result _parse_list _cmd_result
integer ret=1
_cmd_result=$(__parse_kube_get ${1})
if [ ! -z ${_cmd_result} ]; then
_parse_result=($(__parse_cmd_result ${_cmd_result}))
_parse_list=()
for _r in ${_parse_result}
do
_parse_list+=("$(${2} ${_r})")
done
compadd ${_parse_list[@]} && ret=0
fi
return ret
}
__kube_get_exec_nocomment(){
local -a _parse_list _cmd_result
integer ret=1
_cmd_result=$(__parse_kube_get ${1})
if [ ! -z ${_cmd_result} ]; then
_parse_list=($(__parse_cmd_result_withoutcomment ${_cmd_result}))
_values "${2}" ${_parse_list[@]} && ret=0
fi
return ret
}
__output_flag(){
local -a _default_output_flags _output_withfile_flags
integer ret=1
_default_output_flags=(
'json'
'yaml'
'name'
'custom-columns'
'custom-columns-file'
'go-template'
'go-template-file'
'jsonpath'
'jsonpath-file'
)
case $words[1] in
expose | get | edit | delete)
compadd $_default_output_flags[@] 'wide' && ret=0
;;
api-resources)
compadd 'wide' 'name' && ret=0
;;
version)
compadd 'yaml' 'json' && ret=0
;;
*)
compadd $_default_output_flags[@] && ret=0
;;
esac
return ret
}
__kube_get_pods_comment(){
echo -n $(__parse_print2list ${1} 1)'[ready: '$(__parse_print2list ${1} 2)' status: '$(__parse_print2list ${1} 3)' IP: '$(__parse_print2list ${1} 6)' node: '$(__parse_print2list ${1} 7)']'
}
__kube_get_pods(){
__kube_get_exec 'pods' __kube_get_pods_comment
}
__kube_get_replicationcontrollers_comment(){
echo -n $(__parse_print2list ${1} 1)'[image: '$(__parse_print2list ${1} 7)']'
}
__kube_get_api_replicationcontrollers(){
__kube_get_exec 'replicationcontrollers' __kube_get_replicationcontrollers_comment
}
__kube_get_namespaces_comment(){
echo -n $(__parse_print2list ${1} 1)'['$(__parse_print2list ${1} 2)']'
}
__kube_get_namespaces(){
__kube_get_exec 'namespaces' __kube_get_namespaces_comment
}
__kube_get_nodes_comment(){
echo -n $(__parse_print2list ${1} 1)'[status: '$(__parse_print2list ${1} 2)' role: '$(__parse_print2list ${1} 3)']'
}
__kube_get_nodes(){
__kube_get_exec 'nodes' __kube_get_nodes_comment
}
__kube_get_services_comment(){
echo -n $(__parse_print2list ${1} 1)'[type: '$(__parse_print2list ${1} 2)' listen: '$(__parse_print2list ${1} 5)']'
}
__kube_get_services(){
__kube_get_exec 'services' __kube_get_services_comment
}
__kube_get_componentstatuses_comment(){
echo -n $(__parse_print2list ${1} 1)'['$(__parse_print2list ${1} 2)']'
}
__kube_get_componentstatuses(){
__kube_get_exec 'componentstatuses' __kube_get_componentstatuses_comment
}
__kube_get_configmaps_comment(){
echo -n $(__parse_print2list ${1} 1)
}
__kube_get_configmaps(){
__kube_get_exec_nocomment 'configmaps' ''
}
__kube_get_podsecuritypolicies(){
__kube_get_exec_nocomment 'podsecuritypolicies' ''
}
__kube_get_api_resources(){
local -a comment
case ${7} in
explain)
comment='kubectl explain RESOURCE [options]'
;;
get)
comment='kubectl get [(-o|--output=)json|yaml|wide|custom-columns=...|custom-columns-file=...|go-template=...|go-template-file=...|jsonpath=...|jsonpath-file=...](TYPE[.VERSION][.GROUP] [NAME | -l label] | TYPE[.VERSION][.GROUP]/NAME ...) [flags] [options]'
;;
describe)
comment='kubectl describe (-f FILENAME | TYPE [NAME_PREFIX | -l label] | TYPE/NAME) [options]'
;;
delete)
comment='kubectl delete ([-f FILENAME] | TYPE [(NAME | -l label | --all)]) [options]'
;;
patch)
comment='kubectl patch (-f FILENAME | TYPE NAME) -p PATCH [options]'
;;
label)
comment='kubectl label [--overwrite] (-f FILENAME | TYPE NAME) KEY_1=VAL_1 ... KEY_N=VAL_N [--resource-version=version] [options]'
;;
annotate)
comment='kubectl annotate [--overwrite] (-f FILENAME | TYPE NAME) KEY_1=VAL_1 ... KEY_N=VAL_N [--resource-version=version] [options]'
;;
autoscale)
comment='kubectl autoscale (-f FILENAME | TYPE NAME | TYPE/NAME) [--min=MINPODS] --max=MAXPODS [--cpu-percent=CPU] [options]'
;;
*)
comment='api resources'
;;
esac
__kube_get_exec_nocomment 'api-resources' ${comment}
}
__kube_get_api_resources2name(){
local -a _parse_result __pre_parse_list _parse_list _cmd_result comment
integer ret=1
case ${7} in
wait)
comment='kubectl wait resource.group/name [--for=delete|--for condition=available] [options]'
;;
port-forward)
comment='kubectl port-forward TYPE/NAME [options] [LOCAL_PORT:]REMOTE_PORT [...[LOCAL_PORT_N:]REMOTE_PORT_N]'
;;
edit)
comment='kubectl edit (RESOURCE/NAME | -f FILENAME) [options]'
;;
logs)
comment='kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER] [options]'
;;
*)
comment='api resources'
;;
esac
_cmd_result=$(__parse_kube_get api-resources)
_pre_parse_list=()
_parse_list=()
if [ ! -z ${_cmd_result} ]; then
_pre_parse_list=($(__parse_cmd_result_withoutcomment ${_cmd_result}))
fi
for _a in ${_pre_parse_list}
do
case ${_a} in
bindings)
#TODO
;;
componentstatuses)
_parse_list+=('componentstatuses:componentstatuses:__kube_get_componentstatuses')
;;
configmaps)
_parse_list+=('configmaps:configmaps:__kube_get_configmaps')
;;
endpoints)
_parse_list+=('endpoints:endpoints:__kube_get_endpoints')
;;
events)
_parse_list+=('events:events:__kube_get_events')
;;
limitranges)
_parse_list+=('limitranges:limitranges:__kube_get_limitranges')
;;
namespaces)
_parse_list+=('namespaces:namespaces:__kube_get_namespaces')
;;
nodes)
_parse_list+=('nodes:nodes:__kube_get_nodes')
;;
persistentvolumeclaims)
_parse_list+=('persistentvolumeclaims:persistentvolumeclaims:__kube_get_persistentvolumeclaims')
;;
persistentvolumes)
_parse_list+=('persistentvolumes:persistentvolumes:__kube_get_persistentvolumes')
;;
pods)
_parse_list+=('pods:pods:__kube_get_pods')
;;
podtemplates)
#TODO
;;
replicationcontrollers)
_parse_list+=('replicationcontrollers:replicationcontrollers:__kube_get_replicationcontrollers')
;;
resourcequotas)
_parse_list+=('resourcequotas:resourcequotas:__kube_get_resourcequotas')
;;
secrets)
_parse_list+=('secrets:secrets:__kube_get_secrets')
;;
serviceaccounts)
_parse_list+=('serviceaccounts:serviceaccounts:__kube_get_serviceaccounts')
;;
services)
_parse_list+=('services:services:__kube_get_services')
;;
mutatingwebhookconfigurations)
#TODO
;;
validatingwebhookconfigurations)
#TODO
;;
customresourcedefinitions)
_parse_list+=('customresourcedefinitions:customresourcedefinitions:__kube_get_customresourcedefinitions')
;;
apiservices)
_parse_list+=('apiservices:apiservices:__kube_get_apiservices')
;;
controllerrevisions)
_parse_list+=('controllerrevisions:controllerrevisions:__kube_get_controllerrevisions')
;;
daemonsets)
_parse_list+=('daemonsets:daemonsets:__kube_get_daemonsets')
;;
deployments)
_parse_list+=('deployments:deployments:__kube_get_deployments')
;;
statefulsets)
_parse_list+=('statefulsets:statefulsets:__kube_get_statefulsets')
;;
ingresses)
_parse_list+=('ingresses:ingresses:__kube_get_ingresses')
;;
networkpolicies)
_parse_list+=('networkpolicies:networkpolicies:__kube_get_networkpolicies')
;;
podsecuritypolicies)
_parse_list+=('podsecuritypolicies:podsecuritypolicies:__kube_get_podsecuritypolicies')
;;
clusterrolebindings)
_parse_list+=('clusterrolebindings:clusterrolebindings:__kube_get_clusterrolebindings')
;;
clusterroles)
_parse_list+=('clusterroles:clusterroles:__kube_get_clusterroles')
;;
rolebindings)
_parse_list+=('rolebindings:rolebindings:__kube_get_rolebindings')
;;
roles)
_parse_list+=('roles:roles:__kube_get_roles')
;;
storageclasses)
_parse_list+=('storageclasses:storageclasses:__kube_get_storageclasses')
;;
volumeattachments)
#TODO
;;
esac
done
_values -S '/' ${comment} $_parse_list && ret=0
return ret
}
__kube_rollout_resources2name(){
local -a _parse_list
integer ret=1
_parse_list=()
_parse_list+=('daemonsets:daemonsets:__kube_get_daemonsets')
_parse_list+=('deployments:deployments:__kube_get_deployments')
_parse_list+=('statefulsets:statefulsets:__kube_get_statefulsets')
_values -S '/' 'kubectl rollout SUBCOMMAND [options]' $_parse_list && ret=0
return ret
}
__kube_get_endpoints_comment(){
echo -n $(__parse_print2list ${1} 1)'[listen: '$(__parse_print2list ${1} 2)']'
}
__kube_get_endpoints(){
__kube_get_exec 'endpoints' __kube_get_endpoints_comment
}
__kube_get_events_comment(){
echo -n $(__parse_print2list ${1} 4)'[reasen: '$(__parse_print2list ${1} 7)']'
}
__kube_get_events(){
__kube_get_exec 'events' __kube_get_events_comment
}
__kube_get_limitranges_comment(){
echo -n $(__parse_print2list ${1} 1)'[created_at: '$(__parse_print2list ${1} 2)']'
}
__kube_get_limitranges(){
__kube_get_exec 'limitranges' __kube_get_limitranges_comment
}
__kube_get_resourcequotas_comment(){
echo -n $(__parse_print2list ${1} 1)'[created_at: '$(__parse_print2list ${1} 2)']'
}
__kube_get_resourcequotas(){
__kube_get_exec 'resourcequotas' __kube_get_resourcequotas_comment
}
__kube_get_customresourcedefinitions_comment(){
echo -n $(__parse_print2list ${1} 1)'[created_at: '$(__parse_print2list ${1} 2)']'
}
__kube_get_customresourcedefinitions(){
__kube_get_exec 'customresourcedefinitions' __kube_get_customresourcedefinitions_comment
}
__kube_get_persistentvolumeclaims_comment(){
echo -n $(__parse_print2list ${1} 1)'[volume: '$(__parse_print2list ${1} 4)' storageclass: '$(__parse_print2list ${1} 6)']'
}
__kube_get_persistentvolumeclaims(){
__kube_get_exec 'persistentvolumeclaims' __kube_get_persistentvolumeclaims_comment
}
__kube_get_persistentvolumes_comment(){
_pv_claim=$(echo ${1} | tr '$' ' ' | awk '{print $6}')
echo -n $(__parse_print2list ${1} 1)'[claim: '$(echo ${_pv_claim} | awk -F '/' '{print $2}')' storageclass: '$(__parse_print2list ${1} 7)']'
}
__kube_get_persistentvolumes(){
__kube_get_exec 'persistentvolumes' __kube_get_persistentvolumes_comment
}
__kube_get_secrets_comment(){
echo -n $(__parse_print2list ${1} 1)'['$(__parse_print2list ${1} 2)']'
}
__kube_get_secrets(){
__kube_get_exec 'secrets' __kube_get_secrets_comment
}
__kube_get_serviceaccounts(){
__kube_get_exec_nocomment 'serviceaccounts' ${7}
}
__kube_get_apiservices_comment(){
echo -n $(__parse_print2list ${1} 1)'[created_at: '$(__parse_print2list ${1} 2)']'
}
__kube_get_apiservices(){
__kube_get_exec_nocomment 'apiservices' ${7}
}
__kube_get_controllerrevisions_comment(){
echo -n $(__parse_print2list ${1} 1)'['$(__parse_print2list ${1} 2)']'
}
__kube_get_controllerrevisions(){
__kube_get_exec 'controllerrevisions' __kube_get_controllerrevisions_comment
}
__kube_get_daemonsets_comment(){
echo -n $(__parse_print2list ${1} 1)'[desired: '$(__parse_print2list ${1} 2)' current: '$(__parse_print2list ${1} 3)' ready: '$(__parse_print2list ${1} 4)' up-to-date: '$(__parse_print2list ${1} 5)' available: '$(__parse_print2list ${1} 6)']'
}
__kube_get_daemonsets(){
__kube_get_exec 'daemonsets' __kube_get_daemonsets_comment
}
__kube_get_deployments_comment(){
echo -n $(__parse_print2list ${1} 1)'[desired: '$(__parse_print2list ${1} 2)' current: '$(__parse_print2list ${1} 3)' up-to-date: '$(__parse_print2list ${1} 4)' available: '$(__parse_print2list ${1} 5)']'
}
__kube_get_deployments(){
__kube_get_exec 'deployments' __kube_get_deployments_comment
}
__kube_get_statefulsets_comment(){
echo -n $(__parse_print2list ${1} 1)'[desired: '$(__parse_print2list ${1} 2)' current: '$(__parse_print2list ${1} 3)' up-to-date: '$(__parse_print2list ${1} 4)']'
}
__kube_get_statefulsets(){
__kube_get_exec 'statefulsets' __kube_get_statefulsets_comment
}
__kube_get_ingresses_comment(){
echo -n $(__parse_print2list ${1} 1)'[hosts: '$(__parse_print2list ${1} 2)' lieten '$(__parse_print2list ${1} 3)':'$(__parse_print2list ${1} 4)']'
}
__kube_get_ingresses(){
__kube_get_exec 'ingresses' __kube_get_ingresses_comment
}
__kube_get_networkpolicies_comment(){
echo -n $(__parse_print2list ${1} 1)'[pod-selector: '$(__parse_print2list ${1} 2)']'
}
__kube_get_networkpolicies(){
__kube_get_exec 'networkpolicies' __kube_get_networkpolicies_comment
}
__kube_get_clusterrolebindings(){
__kube_get_exec_nocomment 'clusterrolebindings' ''
}
__kube_get_clusterroles(){
__kube_get_exec_nocomment 'clusterroles' ''
}
__kube_get_rolebindings(){
__kube_get_exec_nocomment 'rolebindings' ''
}
__kube_get_roles(){
__kube_get_exec_nocomment 'roles' ''
}
__kube_get_storageclasses_comment(){
echo -n $(__parse_print2list ${1} 1)'[provisioner: '$(__parse_print2list ${1} 2)']'
}
__kube_get_storageclasses(){
__kube_get_exec 'storageclasses' __kube_get_storageclasses_comment
}
__kube_get_contexts_comment(){
if echo ${1} | grep '*' > /dev/null 2>&1; then
echo -n $(__parse_print2list ${1} 2)
else
echo -n $(__parse_print2list ${1} 1)
fi
}
__kube_get_contexts(){
__kube_get_exec_contexts 'contexts' __kube_get_contexts_comment
}
__hook_api_resources(){
case $words[2] in
bindings)
#TODO
;;
componentstatuses)
__kube_get_componentstatuses
;;
configmaps)
__kube_get_configmaps
;;
endpoints)
__kube_get_endpoints
;;
events)
__kube_get_events
;;
limitranges)
__kube_get_limitranges
;;
namespaces)
__kube_get_namespaces
;;
nodes)
__kube_get_nodes
;;
persistentvolumeclaims)
__kube_get_persistentvolumeclaims
;;
persistentvolumes)
__kube_get_persistentvolumes
;;
pods)
__kube_get_pods
;;
podtemplates)
#TODO
;;
replicationcontrollers)
__kube_get_api_replicationcontrollers
;;
resourcequotas)
__kube_get_resourcequotas
;;
secrets)
__kube_get_secrets
;;
serviceaccounts)
__kube_get_serviceaccounts
;;
services)
__kube_get_services
;;
mutatingwebhookconfigurations)
#TODO
;;
validatingwebhookconfigurations)
#TODO
;;
customresourcedefinitions)
__kube_get_customresourcedefinitions
;;
apiservices)
__kube_get_apiservices
;;
controllerrevisions)
__kube_get_controllerrevisions
;;
daemonsets)
__kube_get_daemonsets
;;
deployments)
__kube_get_deployments
;;
statefulsets)
__kube_get_statefulsets
;;
ingresses)
__kube_get_ingresses
;;
networkpolicies)
__kube_get_networkpolicies
;;
podsecuritypolicies)
__kube_get_podsecuritypolicies
;;
clusterrolebindings)
__kube_get_clusterrolebindings
;;
clusterroles)
__kube_get_clusterroles
;;
rolebindings)
__kube_get_rolebindings
;;
roles)
__kube_get_roles
;;
storageclasses)
__kube_get_storageclasses
;;
volumeattachments)
#TODO
;;
esac
}
__create_cmd(){
local -a _create_cmds
integer ret=1
_create_cmds=(
'clusterrole[Create a ClusterRole.]'
'clusterrolebinding[Create a ClusterRoleBinding for a particular ClusterRole]'
'configmap[Create a configmap from a local file, directory or literal value]'
'deployment[Create a deployment with the specified name.]'
'job[Create a job with the specified name.]'
'help[Get more information about a this command help]'
'namespace[Create a namespace with the specified name.]'
'poddisruptionbudget[Create a pod disruption budget with the specified name.]'
'priorityclass[Create a priorityclass with the specified name.]'
'quota[Create a quota with the specified name.]'
'role[Create a role with single rule.]'
'rolebinding[Create a RoleBinding for a particular Role or ClusterRole]'
'secret[Create a secret using specified subcommand]'
'service[Create a service using specified subcommand.]'
'serviceaccount[Create a service account with the specified name.]'
)
_values 'kubectl create -f FILENAME [options]' $_create_cmds[@] && ret=0
return ret
}
__expose_cmd(){
local -a _expose_cmds
integer ret=1
_expose_cmds=(
'pod:pod:__kube_get_pods'
'service:service:__kube_get_services'
'replicationcontroller'
'deployment:deployment:__kube_get_deployments'
'replicaset'
)
_values 'kubectl expose (-f FILENAME | TYPE NAME) [--port=port] [--protocol=TCP|UDP|SCTP] [--target-port=number-or-name] [--name=name] [--external-ip=external-ip-of-service] [--type=type] [options]' $_expose_cmds[@] && ret=0
return ret
}
__set_cmd(){
local -a _set_cmds
integer ret=1
_set_cmds=(
'env[Update environment variables on a pod template]'
'image[Update image of a pod template]'
'resources[Update resource requests/limits on objects with pod templates]'
'selector[Set the selector on a resource]'
'serviceaccount[Update ServiceAccount of a resource]'
'subject[Update User, Group or ServiceAccount in a RoleBinding/ClusterRoleBinding]'
)
_values 'kubectl set SUBCOMMAND [options]' $_set_cmds[@] && ret=0
return ret
}
__rollout_cmd(){
local -a _rollout_cmds
integer ret=1
_rollout_cmds=(
'history[View rollout history]'
'pause[Mark the provided resource as paused]'
'resume[Resume a paused resource]'
'status[Show the status of the rollout]'
'undo[Undo a previous rollout]'
)
_values 'kubectl rollout SUBCOMMAND [options]' $_rollout_cmds[@] && ret=0
return ret
}
__scale_cmd() {
local -a _scale_cmds
integer ret=1
_scale_cmds=(
'--replicas[The new desired number of replicas. Required.]'
)
_values 'kubectl scale [--resource-version=version] [--current-replicas=count] --replicas=COUNT (-f FILENAME | TYPE NAME) [options]' $_scale_cmds[@] && ret=0
return ret
}
__hook_autoscale_cmd() {
local -a _hook_autoscale_cmds
integer ret=1
_hook_autoscale_cmds=(
'--max[The upper limit for the number of pods that can be set by the autoscaler. Required.]'
)
_values 'kubectl autoscale (-f FILENAME | TYPE NAME | TYPE/NAME) [--min=MINPODS] --max=MAXPODS [--cpu-percent=CPU] [options]' $_hook_autoscale_cmds[@] && ret=0
return ret
}
__certificate_cmd(){
local -a _certificate_cmds
integer ret=1
_certificate_cmds=(
'approve[Approve a certificate signing request]'
'deny[Deny a certificate signing request]'
)
_values 'certificate command' $_certificate_cmds[@] && ret=0
return ret
}
__clusterinfo_cmd(){
local -a _clusterinfo_cmds
integer ret=1
_clusterinfo_cmds=(
'dump[Dump lots of relevant info for debugging and diagnosis]'
)
_values 'clusterinfo command' $_clusterinfo_cmds[@] && ret=0
return ret
}
__top_cmd(){
local -a _top_cmds
integer ret=1
_top_cmds=(
'node[Display Resource (CPU/Memory/Storage) usage of nodes]'
'pod[Display Resource (CPU/Memory/Storage) usage of pods]'
)
_values 'kubectl top [flags] [options]' $_top_cmds[@] && ret=0
return ret
}
__auth_cmd(){
local -a _auth_cmds
integer ret=1
_auth_cmds=(
'can-i[Check whether an action is allowed]'
'reconcile[Reconciles rules for RBAC Role, RoleBinding, ClusterRole, and ClusterRole binding objects]'
)
_values 'kubectl auth [flags] [options]' $_auth_cmds[@] && ret=0
return ret
}
__completion_cmd(){
local -a _completion_cmds
integer ret=1
_completion_cmds=(
'zsh[Shell designed for interactive use, although it is also a powerful scripting language.]'
'bash[Unix shell and command language written by Brian Fox for the GNU Project as a free software replacement for the Bourne shell.]'
)
_values 'completion command' $_completion_cmds[@] && ret=0
return ret
}
# No alpha commands are available in this version of kubectl
# __alpha_cmd(){
# local -a _alpha_cmds
# integer ret=1
# _alpha_cmds=(
# )
# _values 'alpha command' $_alpha_cmds[@] && ret=0
#
# return ret
# }
__config_cmd(){
local -a _config_cmds
integer ret=1
_config_cmds=(
'current-context[Displays the current-context]'
'delete-cluster[Delete the specified cluster from the kubeconfig]'
'delete-context[Delete the specified context from the kubeconfig]'
'get-clusters[Display clusters defined in the kubeconfig]'
'get-contexts[Describe one or many contexts]'
'rename-context[Renames a context from the kubeconfig file.]'
'set[Sets an individual value in a kubeconfig file]'
'set-cluster[Sets a cluster entry in kubeconfig]'
'set-context[Sets a context entry in kubeconfig]'
'set-credentials[Sets a user entry in kubeconfig]'
'unset[Unsets an individual value in a kubeconfig file]'
'use-context[Sets the current-context in a kubeconfig file]'
'view[Display merged kubeconfig settings or a specified kubeconfig file]'
)
_values 'kubectl config SUBCOMMAND [options]' $_config_cmds[@] && ret=0
return ret
}
__plugin_cmd(){
local -a _plugin_cmds
integer ret=1
_plugin_cmds=(
'list[list all visible plugin executables on a user'\''s PATH]'
)
_values 'kubectl plugin [flags] [options]' $_plugin_cmds[@] && ret=0
return ret
}
__basic_cmd(){
local -a _basic_cmds
integer ret=1
_basic_cmds=(
'create[Create a resource from a file or from stdin.]'
'expose[Take a replication controller, service, deployment or pod and expose it as a new Kubernetes Service]'
'run[Run a particular image on the cluster]'
'set[Set specific features on objects]'
'explain[Documentation of resources]'
'get[Display one or many resources]'
'edit[Edit a resource on the server]'
'delete[Delete resources by filenames, stdin, resources and names, or by resources and label selector]'
'rollout[Manage the rollout of a resource]'
'scale[Set a new size for a Deployment, ReplicaSet, Replication Controller, or Job]'
'autoscale[Auto-scale a Deployment, ReplicaSet, or ReplicationController]'
'certificate[Modify certificate resources.]'
'cluster-info[Display cluster info]'
'top[Display Resource (CPU/Memory/Storage) usage.]'
'cordon[Mark node as unschedulable]'
'uncordon[Mark node as schedulable]'
'drain[Drain node in preparation for maintenance]'
'taint[Update the taints on one or more nodes]'
'describe[Show details of a specific resource or group of resources]'
'logs[Print the logs for a container in a pod]'
'attach[Attach to a running container]'
'exec[Execute a command in a container]'
'port-forward[Forward one or more local ports to a pod]'
'proxy[Run a proxy to the Kubernetes API server]'
'cp[Copy files and directories to and from containers.]'
'auth[Inspect authorization]'
'diff[Diff live version against would-be applied version]'
'apply[Apply a configuration to a resource by filename or stdin]'
'patch[Update field(s) of a resource using strategic merge patch]'
'replace[Replace a resource by filename or stdin]'
'wait[Experimental: Wait for a specific condition on one or many resources.]'
'convert[Convert config files between different API versions]'
'label[Update the labels on a resource]'
'annotate[Update the annotations on a resource]'
'completion[Output shell completion code for the specified shell (bash or zsh)]'
# No alpha commands are available in this version of kubectl
# 'alpha[Commands for features in alpha]'
'api-resources[Print the supported API resources on the server]'
'api-versions[Print the supported API versions on the server, in the form of \"group/version\"]'
'config[Modify kubeconfig files]'
'plugin[Provides utilities for interacting with plugins.]'
'version[Print the client and server version information]'
'help[Help about any command]'
'options[List of global command-line options (applies to all commands).]'
)
_values 'kubectl [flags] [options]' $_basic_cmds[@] && ret=0
return ret
}
_kubectl(){
typeset -A opt_args
integer ret=1
local -a _global_flags
_global_flags=(
'--alsologtostderr[log to standard error as well as files]'
'--as[Username to impersonate for the operation]'
'--as-group[Group to impersonate for the operation, this flag can be repeated to specify multiple groups.]'
'--cache-dir[Default HTTP cache directory]'
'--certificate-authority[Path to a cert file for the certificate authority]'
'--client-certificate[Path to a client certificate file for TLS]'
'--client-key[Path to a client key file for TLS]'
'--cluster[The name of the kubeconfig cluster to use]'
'--context[The name of the kubeconfig context to use]:contexts:__kube_get_contexts'
'--help[Get more information about a this command help]'
'--insecure-skip-tls-verify[If true, the server'\''s certificate will not be checked for validity. This will make your HTTPS connections insecure]'
'--kubeconfig[Path to the kubeconfig file to use for CLI requests.]:kubeconfig:_files'
'--log-backtrace-at[when logging hits line file[N, emit a stack trace]'
'--log-dir[If non-empty, write log files in this directory]:dirs:_files'
'--log-flush-frequency[Maximum number of seconds between log flushes]'
'--logtostderr=true[log to standard error instead of files]'
'--match-server-version[Require server version to match client version]'
{-n,--namespace}'[If present, the namespace scope for this CLI request]:namespaces:__kube_get_namespaces'
'--password[Password for basic authentication to the API server]'
'--profile[Name of profile to capture. One of (none|cpu|heap|goroutine|threadcreate|block|mutex)]'
'--profile-output[Name of the file to write the profile to]'
'--request-timeout[The length of time to wait before giving up on a single server request. Non-zero values should contain a corresponding time unit (e.g. 1s, 2m, 3h). A value of zero means don'\''t timeout requests.]'
{-s,--server}'[The address and port of the Kubernetes API server]'
'--stderrthreshold[logs at or above this threshold go to stderr]'
'--token[Bearer token for authentication to the API server]'
'--user[The name of the kubeconfig user to use]'
'--username[Username for basic authentication to the API server]'
{-v,--v}'[level for V logs]'
'--vmodule[comma-separated list of pattern=N settings for file-filtered logging]'
)
_arguments \
${_global_flags[@]} \
"1: :{_alternative ':basic_cmd:__basic_cmd'}" \
'*:: :->args' && ret=0
case $state in
args)
if [ ! -z ${opt_args[-n]} ]; then
_filter_namespace=${opt_args[-n]}
fi
if [ ! -z ${opt_args[--namespace]} ]; then
_filter_namespace=${opt_args[--namespace]}
fi
if [ ! -z ${opt_args[--cluster]} ]; then
_filter_cluster=${opt_args[--cluster]}
fi
if [ ! -z ${opt_args[--user]} ]; then
_filter_user=${opt_args[--user]}
fi
if [ ! -z ${opt_args[--context]} ]; then
_filter_context=${opt_args[--context]}
fi
if [ ! -z ${opt_args[--server]} ]; then
_filter_server=${opt_args[--server]}
fi
if [ ! -z ${opt_args[--kubeconfig]} ]; then
_filter_kubeconfig=${opt_args[--kubeconfig]}
fi
case $words[1] in
create)
_arguments \
${_global_flags[@]} \
'--allow-missing-template-keys[If true, ignore any errors in templates when a field or map key is missing in the template. Only applies to golang and jsonpath output formats.]' \
'--dry-run[If true, only print the object that would be sent, without sending it.]' \
'--edit[Edit the API resource before creating]' \
'(-f --filename)'{-f,--filename}'[Filename, directory, or URL to files to use to create the resource]:files:_files' \
'--help[Get more information about a this command help]' \
'(-o --output)'{-o,--output}'[Output format. One of:json|yaml|wide|name|custom-columns=...|custom-columns-file=...|go-template=...|go-template-file=...|jsonpath=...|jsonpath-file=...See custom columns \[http://kubernetes.io/docs/user-guide/kubectl-overview/#custom-columns\], golang template \[http://golang.org/pkg/text/template/#pkg-overview\] and jsonpath template \[http://kubernetes.io/docs/user-guide/jsonpath\].]:output_flag:__output_flag' \
'--raw[Raw URI to POST to the server. Uses the transport specified by the kubeconfig file.]' \
'--record[Record current kubectl command in the resource annotation. If set to false, do not record the command. If set to true, record the command. If not set, default to updating the existing annotation value only if one already exists.]' \
'(-R --recursive)'{-R,--recursive}'[Process the directory used in -f, --filename recursively. Useful when you want to manage related manifests organized within the same directory.]' \
'--save-config[If true, the configuration of current object will be saved in its annotation. Otherwise, the annotation will be unchanged. This flag is useful when you want to perform kubectl apply on this object in the future.]' \
'(-l --selector)'{-l,--selector}'[Selector (label query) to filter on, supports '=', '==', and '!='.(e.g. -l key1=value1,key2=value2)]' \
'--template[Template string or path to template file to use when -o=go-template, -o=go-template-file. The template format is golang templates \[http://golang.org/pkg/text/template/#pkg-overview\].]' \
'--validate[If true, use a schema to validate the input before sending it]' \
'--windows-line-endings[Only relevant if --edit=true. Defaults to the line ending native to your platform.]' \
"1: :{_alternative ':create_cmd:__create_cmd' }" && ret=0
;;
expose)
_arguments \
${_global_flags[@]} \
'--allow-missing-template-keys[If true, ignore any errors in templates when a field or map key is missing in the template. Only applies to golang and jsonpath output formats.]' \
'--cluster-ip[ClusterIP to be assigned to the service. Leave empty to auto-allocate, or set to '\''None'\'' to create a headless service.]' \
'--dry-run[If true, only print the object that would be sent, without sending it.]' \
'--external-ip[Additional external IP address (not managed by Kubernetes) to accept for the service. If this IP is routed to a node, the service can be accessed by this IP in addition to its generated service IP.]' \
'(-f --filename)'{-f,--filename}'[Filename, directory, or URL to files identifying the resource to expose a service]:files:_files' \
'--generator[The name of the API generator to use. There are 2 generators: '\''service/v1'\'' and '\''service/v2'\''. The only difference between them is that service port in v1 is named '\''default'\'', while it is left unnamed in v2. Default is '\''service/v2'\''.]' \
'--help[Get more information about a this command help]' \