forked from kubernetes/dashboard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
resourcechannels.go
914 lines (769 loc) · 26.5 KB
/
resourcechannels.go
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
// Copyright 2017 The Kubernetes Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package common
import (
"github.com/kubernetes/dashboard/src/app/backend/api"
apps "k8s.io/api/apps/v1beta2"
autoscaling "k8s.io/api/autoscaling/v1"
batch "k8s.io/api/batch/v1"
batch2 "k8s.io/api/batch/v1beta1"
"k8s.io/api/core/v1"
extensions "k8s.io/api/extensions/v1beta1"
rbac "k8s.io/api/rbac/v1"
storage "k8s.io/api/storage/v1"
metaV1 "k8s.io/apimachinery/pkg/apis/meta/v1"
client "k8s.io/client-go/kubernetes"
)
// ResourceChannels struct holds channels to resource lists. Each list channel is paired with
// an error channel which *must* be read sequentially: first read the list channel and then
// the error channel.
//
// This struct can be used when there are multiple clients that want to process, e.g., a
// list of pods. With this helper, the list can be read only once from the backend and
// distributed asynchronously to clients that need it.
//
// When a channel is nil, it means that no resource list is available for getting.
//
// Each channel pair can be read up to N times. N is specified upon creation of the channels.
type ResourceChannels struct {
// List and error channels to Replication Controllers.
ReplicationControllerList ReplicationControllerListChannel
// List and error channels to Replica Sets.
ReplicaSetList ReplicaSetListChannel
// List and error channels to Deployments.
DeploymentList DeploymentListChannel
// List and error channels to Daemon Sets.
DaemonSetList DaemonSetListChannel
// List and error channels to Jobs.
JobList JobListChannel
// List and error channels to Cron Jobs.
CronJobList CronJobListChannel
// List and error channels to Services.
ServiceList ServiceListChannel
// List and error channels to Endpoints.
EndpointList EndpointListChannel
// List and error channels to Ingresses.
IngressList IngressListChannel
// List and error channels to Pods.
PodList PodListChannel
// List and error channels to Events.
EventList EventListChannel
// List and error channels to LimitRanges.
LimitRangeList LimitRangeListChannel
// List and error channels to Nodes.
NodeList NodeListChannel
// List and error channels to Namespaces.
NamespaceList NamespaceListChannel
// List and error channels to StatefulSets.
StatefulSetList StatefulSetListChannel
// List and error channels to ConfigMaps.
ConfigMapList ConfigMapListChannel
// List and error channels to Secrets.
SecretList SecretListChannel
// List and error channels to PersistentVolumes
PersistentVolumeList PersistentVolumeListChannel
// List and error channels to PersistentVolumeClaims
PersistentVolumeClaimList PersistentVolumeClaimListChannel
// List and error channels to ResourceQuotas
ResourceQuotaList ResourceQuotaListChannel
// List and error channels to HorizontalPodAutoscalers
HorizontalPodAutoscalerList HorizontalPodAutoscalerListChannel
// List and error channels to StorageClasses
StorageClassList StorageClassListChannel
// List and error channels to Roles
RoleList RoleListChannel
// List and error channels to ClusterRoles
ClusterRoleList ClusterRoleListChannel
// List and error channels to RoleBindings
RoleBindingList RoleBindingListChannel
// List and error channels to ClusterRoleBindings
ClusterRoleBindingList ClusterRoleBindingListChannel
}
// ServiceListChannel is a list and error channels to Services.
type ServiceListChannel struct {
List chan *v1.ServiceList
Error chan error
}
// GetServiceListChannel returns a pair of channels to a Service list and errors that both
// must be read numReads times.
func GetServiceListChannel(client client.Interface, nsQuery *NamespaceQuery,
numReads int) ServiceListChannel {
channel := ServiceListChannel{
List: make(chan *v1.ServiceList, numReads),
Error: make(chan error, numReads),
}
go func() {
list, err := client.CoreV1().Services(nsQuery.ToRequestParam()).List(api.ListEverything)
var filteredItems []v1.Service
for _, item := range list.Items {
if nsQuery.Matches(item.ObjectMeta.Namespace) {
filteredItems = append(filteredItems, item)
}
}
list.Items = filteredItems
for i := 0; i < numReads; i++ {
channel.List <- list
channel.Error <- err
}
}()
return channel
}
// IngressListChannel is a list and error channels to Ingresss.
type IngressListChannel struct {
List chan *extensions.IngressList
Error chan error
}
// GetIngressListChannel returns a pair of channels to an Ingress list and errors that both
// must be read numReads times.
func GetIngressListChannel(client client.Interface, nsQuery *NamespaceQuery,
numReads int) IngressListChannel {
channel := IngressListChannel{
List: make(chan *extensions.IngressList, numReads),
Error: make(chan error, numReads),
}
go func() {
list, err := client.ExtensionsV1beta1().Ingresses(nsQuery.ToRequestParam()).List(api.ListEverything)
var filteredItems []extensions.Ingress
for _, item := range list.Items {
if nsQuery.Matches(item.ObjectMeta.Namespace) {
filteredItems = append(filteredItems, item)
}
}
list.Items = filteredItems
for i := 0; i < numReads; i++ {
channel.List <- list
channel.Error <- err
}
}()
return channel
}
// LimitRangeListChannel is a list and error channels to LimitRanges.
type LimitRangeListChannel struct {
List chan *v1.LimitRangeList
Error chan error
}
// GetLimitRangeListChannel returns a pair of channels to a LimitRange list and errors that
// both must be read numReads times.
func GetLimitRangeListChannel(client client.Interface, nsQuery *NamespaceQuery,
numReads int) LimitRangeListChannel {
channel := LimitRangeListChannel{
List: make(chan *v1.LimitRangeList, numReads),
Error: make(chan error, numReads),
}
go func() {
list, err := client.CoreV1().LimitRanges(nsQuery.ToRequestParam()).List(api.ListEverything)
for i := 0; i < numReads; i++ {
channel.List <- list
channel.Error <- err
}
}()
return channel
}
// NodeListChannel is a list and error channels to Nodes.
type NodeListChannel struct {
List chan *v1.NodeList
Error chan error
}
// GetNodeListChannel returns a pair of channels to a Node list and errors that both must be read
// numReads times.
func GetNodeListChannel(client client.Interface, numReads int) NodeListChannel {
channel := NodeListChannel{
List: make(chan *v1.NodeList, numReads),
Error: make(chan error, numReads),
}
go func() {
list, err := client.CoreV1().Nodes().List(api.ListEverything)
for i := 0; i < numReads; i++ {
channel.List <- list
channel.Error <- err
}
}()
return channel
}
// NamespaceListChannel is a list and error channels to Namespaces.
type NamespaceListChannel struct {
List chan *v1.NamespaceList
Error chan error
}
// GetNamespaceListChannel returns a pair of channels to a Namespace list and errors that both must
// be read
// numReads times.
func GetNamespaceListChannel(client client.Interface, numReads int) NamespaceListChannel {
channel := NamespaceListChannel{
List: make(chan *v1.NamespaceList, numReads),
Error: make(chan error, numReads),
}
go func() {
list, err := client.CoreV1().Namespaces().List(api.ListEverything)
for i := 0; i < numReads; i++ {
channel.List <- list
channel.Error <- err
}
}()
return channel
}
// EventListChannel is a list and error channels to Nodes.
type EventListChannel struct {
List chan *v1.EventList
Error chan error
}
// GetEventListChannel returns a pair of channels to an Event list and errors that both must be read
// numReads times.
func GetEventListChannel(client client.Interface,
nsQuery *NamespaceQuery, numReads int) EventListChannel {
return GetEventListChannelWithOptions(client, nsQuery, api.ListEverything, numReads)
}
// GetEventListChannelWithOptions is GetEventListChannel plus list options.
func GetEventListChannelWithOptions(client client.Interface,
nsQuery *NamespaceQuery, options metaV1.ListOptions, numReads int) EventListChannel {
channel := EventListChannel{
List: make(chan *v1.EventList, numReads),
Error: make(chan error, numReads),
}
go func() {
list, err := client.CoreV1().Events(nsQuery.ToRequestParam()).List(options)
var filteredItems []v1.Event
for _, item := range list.Items {
if nsQuery.Matches(item.ObjectMeta.Namespace) {
filteredItems = append(filteredItems, item)
}
}
list.Items = filteredItems
for i := 0; i < numReads; i++ {
channel.List <- list
channel.Error <- err
}
}()
return channel
}
// EndpointListChannel is a list and error channels to Endpoints.
type EndpointListChannel struct {
List chan *v1.EndpointsList
Error chan error
}
func GetEndpointListChannel(client client.Interface, nsQuery *NamespaceQuery, numReads int) EndpointListChannel {
return GetEndpointListChannelWithOptions(client, nsQuery, api.ListEverything, numReads)
}
// GetEndpointListChannelWithOptions is GetEndpointListChannel plus list options.
func GetEndpointListChannelWithOptions(client client.Interface,
nsQuery *NamespaceQuery, opt metaV1.ListOptions, numReads int) EndpointListChannel {
channel := EndpointListChannel{
List: make(chan *v1.EndpointsList, numReads),
Error: make(chan error, numReads),
}
go func() {
list, err := client.CoreV1().Endpoints(nsQuery.ToRequestParam()).List(opt)
for i := 0; i < numReads; i++ {
channel.List <- list
channel.Error <- err
}
}()
return channel
}
// PodListChannel is a list and error channels to Nodes.
type PodListChannel struct {
List chan *v1.PodList
Error chan error
}
// GetPodListChannel returns a pair of channels to a Pod list and errors that both must be read
// numReads times.
func GetPodListChannel(client client.Interface,
nsQuery *NamespaceQuery, numReads int) PodListChannel {
return GetPodListChannelWithOptions(client, nsQuery, api.ListEverything, numReads)
}
// GetPodListChannelWithOptions is GetPodListChannel plus listing options.
func GetPodListChannelWithOptions(client client.Interface, nsQuery *NamespaceQuery,
options metaV1.ListOptions, numReads int) PodListChannel {
channel := PodListChannel{
List: make(chan *v1.PodList, numReads),
Error: make(chan error, numReads),
}
go func() {
list, err := client.CoreV1().Pods(nsQuery.ToRequestParam()).List(options)
var filteredItems []v1.Pod
for _, item := range list.Items {
if nsQuery.Matches(item.ObjectMeta.Namespace) {
filteredItems = append(filteredItems, item)
}
}
list.Items = filteredItems
for i := 0; i < numReads; i++ {
channel.List <- list
channel.Error <- err
}
}()
return channel
}
// ReplicationControllerListChannel is a list and error channels to Nodes.
type ReplicationControllerListChannel struct {
List chan *v1.ReplicationControllerList
Error chan error
}
// GetReplicationControllerListChannel Returns a pair of channels to a
// Replication Controller list and errors that both must be read
// numReads times.
func GetReplicationControllerListChannel(client client.Interface,
nsQuery *NamespaceQuery, numReads int) ReplicationControllerListChannel {
channel := ReplicationControllerListChannel{
List: make(chan *v1.ReplicationControllerList, numReads),
Error: make(chan error, numReads),
}
go func() {
list, err := client.CoreV1().ReplicationControllers(nsQuery.ToRequestParam()).
List(api.ListEverything)
var filteredItems []v1.ReplicationController
for _, item := range list.Items {
if nsQuery.Matches(item.ObjectMeta.Namespace) {
filteredItems = append(filteredItems, item)
}
}
list.Items = filteredItems
for i := 0; i < numReads; i++ {
channel.List <- list
channel.Error <- err
}
}()
return channel
}
// DeploymentListChannel is a list and error channels to Deployments.
type DeploymentListChannel struct {
List chan *apps.DeploymentList
Error chan error
}
// GetDeploymentListChannel returns a pair of channels to a Deployment list and errors
// that both must be read numReads times.
func GetDeploymentListChannel(client client.Interface,
nsQuery *NamespaceQuery, numReads int) DeploymentListChannel {
channel := DeploymentListChannel{
List: make(chan *apps.DeploymentList, numReads),
Error: make(chan error, numReads),
}
go func() {
list, err := client.AppsV1beta2().Deployments(nsQuery.ToRequestParam()).
List(api.ListEverything)
var filteredItems []apps.Deployment
for _, item := range list.Items {
if nsQuery.Matches(item.ObjectMeta.Namespace) {
filteredItems = append(filteredItems, item)
}
}
list.Items = filteredItems
for i := 0; i < numReads; i++ {
channel.List <- list
channel.Error <- err
}
}()
return channel
}
// ReplicaSetListChannel is a list and error channels to Replica Sets.
type ReplicaSetListChannel struct {
List chan *apps.ReplicaSetList
Error chan error
}
// GetReplicaSetListChannel returns a pair of channels to a ReplicaSet list and
// errors that both must be read numReads times.
func GetReplicaSetListChannel(client client.Interface,
nsQuery *NamespaceQuery, numReads int) ReplicaSetListChannel {
return GetReplicaSetListChannelWithOptions(client, nsQuery, api.ListEverything, numReads)
}
// GetReplicaSetListChannelWithOptions returns a pair of channels to a ReplicaSet list filtered
// by provided options and errors that both must be read numReads times.
func GetReplicaSetListChannelWithOptions(client client.Interface, nsQuery *NamespaceQuery,
options metaV1.ListOptions, numReads int) ReplicaSetListChannel {
channel := ReplicaSetListChannel{
List: make(chan *apps.ReplicaSetList, numReads),
Error: make(chan error, numReads),
}
go func() {
list, err := client.AppsV1beta2().ReplicaSets(nsQuery.ToRequestParam()).
List(options)
var filteredItems []apps.ReplicaSet
for _, item := range list.Items {
if nsQuery.Matches(item.ObjectMeta.Namespace) {
filteredItems = append(filteredItems, item)
}
}
list.Items = filteredItems
for i := 0; i < numReads; i++ {
channel.List <- list
channel.Error <- err
}
}()
return channel
}
// DaemonSetListChannel is a list and error channels to Nodes.
type DaemonSetListChannel struct {
List chan *apps.DaemonSetList
Error chan error
}
// GetDaemonSetListChannel returns a pair of channels to a DaemonSet list and errors that both must be read
// numReads times.
func GetDaemonSetListChannel(client client.Interface, nsQuery *NamespaceQuery, numReads int) DaemonSetListChannel {
channel := DaemonSetListChannel{
List: make(chan *apps.DaemonSetList, numReads),
Error: make(chan error, numReads),
}
go func() {
list, err := client.AppsV1beta2().DaemonSets(nsQuery.ToRequestParam()).List(api.ListEverything)
var filteredItems []apps.DaemonSet
for _, item := range list.Items {
if nsQuery.Matches(item.ObjectMeta.Namespace) {
filteredItems = append(filteredItems, item)
}
}
list.Items = filteredItems
for i := 0; i < numReads; i++ {
channel.List <- list
channel.Error <- err
}
}()
return channel
}
// JobListChannel is a list and error channels to Nodes.
type JobListChannel struct {
List chan *batch.JobList
Error chan error
}
// GetJobListChannel returns a pair of channels to a Job list and errors that both must be read numReads times.
func GetJobListChannel(client client.Interface,
nsQuery *NamespaceQuery, numReads int) JobListChannel {
channel := JobListChannel{
List: make(chan *batch.JobList, numReads),
Error: make(chan error, numReads),
}
go func() {
list, err := client.BatchV1().Jobs(nsQuery.ToRequestParam()).List(api.ListEverything)
var filteredItems []batch.Job
for _, item := range list.Items {
if nsQuery.Matches(item.ObjectMeta.Namespace) {
filteredItems = append(filteredItems, item)
}
}
list.Items = filteredItems
for i := 0; i < numReads; i++ {
channel.List <- list
channel.Error <- err
}
}()
return channel
}
// CronJobListChannel is a list and error channels to Cron Jobs.
type CronJobListChannel struct {
List chan *batch2.CronJobList
Error chan error
}
// GetCronJobListChannel returns a pair of channels to a Cron Job list and errors that both must be read numReads times.
func GetCronJobListChannel(client client.Interface, nsQuery *NamespaceQuery, numReads int) CronJobListChannel {
channel := CronJobListChannel{
List: make(chan *batch2.CronJobList, numReads),
Error: make(chan error, numReads),
}
go func() {
list, err := client.BatchV1beta1().CronJobs(nsQuery.ToRequestParam()).List(api.ListEverything)
var filteredItems []batch2.CronJob
for _, item := range list.Items {
if nsQuery.Matches(item.ObjectMeta.Namespace) {
filteredItems = append(filteredItems, item)
}
}
list.Items = filteredItems
for i := 0; i < numReads; i++ {
channel.List <- list
channel.Error <- err
}
}()
return channel
}
// StatefulSetListChannel is a list and error channels to Nodes.
type StatefulSetListChannel struct {
List chan *apps.StatefulSetList
Error chan error
}
// GetStatefulSetListChannel returns a pair of channels to a StatefulSet list and errors that both must be read
// numReads times.
func GetStatefulSetListChannel(client client.Interface,
nsQuery *NamespaceQuery, numReads int) StatefulSetListChannel {
channel := StatefulSetListChannel{
List: make(chan *apps.StatefulSetList, numReads),
Error: make(chan error, numReads),
}
go func() {
statefulSets, err := client.AppsV1beta2().StatefulSets(nsQuery.ToRequestParam()).List(api.ListEverything)
var filteredItems []apps.StatefulSet
for _, item := range statefulSets.Items {
if nsQuery.Matches(item.ObjectMeta.Namespace) {
filteredItems = append(filteredItems, item)
}
}
statefulSets.Items = filteredItems
for i := 0; i < numReads; i++ {
channel.List <- statefulSets
channel.Error <- err
}
}()
return channel
}
// ConfigMapListChannel is a list and error channels to ConfigMaps.
type ConfigMapListChannel struct {
List chan *v1.ConfigMapList
Error chan error
}
// GetConfigMapListChannel returns a pair of channels to a ConfigMap list and errors that both must be read
// numReads times.
func GetConfigMapListChannel(client client.Interface, nsQuery *NamespaceQuery,
numReads int) ConfigMapListChannel {
channel := ConfigMapListChannel{
List: make(chan *v1.ConfigMapList, numReads),
Error: make(chan error, numReads),
}
go func() {
list, err := client.CoreV1().ConfigMaps(nsQuery.ToRequestParam()).List(api.ListEverything)
var filteredItems []v1.ConfigMap
for _, item := range list.Items {
if nsQuery.Matches(item.ObjectMeta.Namespace) {
filteredItems = append(filteredItems, item)
}
}
list.Items = filteredItems
for i := 0; i < numReads; i++ {
channel.List <- list
channel.Error <- err
}
}()
return channel
}
// SecretListChannel is a list and error channels to Secrets.
type SecretListChannel struct {
List chan *v1.SecretList
Error chan error
}
// GetSecretListChannel returns a pair of channels to a Secret list and errors that
// both must be read numReads times.
func GetSecretListChannel(client client.Interface, nsQuery *NamespaceQuery,
numReads int) SecretListChannel {
channel := SecretListChannel{
List: make(chan *v1.SecretList, numReads),
Error: make(chan error, numReads),
}
go func() {
list, err := client.CoreV1().Secrets(nsQuery.ToRequestParam()).List(api.ListEverything)
var filteredItems []v1.Secret
for _, item := range list.Items {
if nsQuery.Matches(item.ObjectMeta.Namespace) {
filteredItems = append(filteredItems, item)
}
}
list.Items = filteredItems
for i := 0; i < numReads; i++ {
channel.List <- list
channel.Error <- err
}
}()
return channel
}
// RoleListChannel is a list and error channels to Roles.
type RoleListChannel struct {
List chan *rbac.RoleList
Error chan error
}
// GetRoleListChannel returns a pair of channels to a Role list for a namespace and errors that
// both must be read numReads times.
func GetRoleListChannel(client client.Interface, numReads int) RoleListChannel {
channel := RoleListChannel{
List: make(chan *rbac.RoleList, numReads),
Error: make(chan error, numReads),
}
go func() {
list, err := client.RbacV1().Roles("").List(api.ListEverything)
for i := 0; i < numReads; i++ {
channel.List <- list
channel.Error <- err
}
}()
return channel
}
// ClusterRoleListChannel is a list and error channels to ClusterRoles.
type ClusterRoleListChannel struct {
List chan *rbac.ClusterRoleList
Error chan error
}
// GetClusterRoleListChannel returns a pair of channels to a ClusterRole list and errors that
// both must be read numReads times.
func GetClusterRoleListChannel(client client.Interface, numReads int) ClusterRoleListChannel {
channel := ClusterRoleListChannel{
List: make(chan *rbac.ClusterRoleList, numReads),
Error: make(chan error, numReads),
}
go func() {
list, err := client.RbacV1().ClusterRoles().List(api.ListEverything)
for i := 0; i < numReads; i++ {
channel.List <- list
channel.Error <- err
}
}()
return channel
}
// RoleBindingListChannel is a list and error channels to RoleBindings.
type RoleBindingListChannel struct {
List chan *rbac.RoleBindingList
Error chan error
}
// GetRoleBindingListChannel returns a pair of channels to a RoleBinding list for a namespace and errors that
// both must be read numReads times.
func GetRoleBindingListChannel(client client.Interface, numReads int) RoleBindingListChannel {
channel := RoleBindingListChannel{
List: make(chan *rbac.RoleBindingList, numReads),
Error: make(chan error, numReads),
}
go func() {
list, err := client.RbacV1().RoleBindings("").List(api.ListEverything)
for i := 0; i < numReads; i++ {
channel.List <- list
channel.Error <- err
}
}()
return channel
}
// ClusterRoleBindingListChannel is a list and error channels to ClusterRoleBindings.
type ClusterRoleBindingListChannel struct {
List chan *rbac.ClusterRoleBindingList
Error chan error
}
// GetClusterRoleBindingListChannel returns a pair of channels to a ClusterRoleBinding list and
// errors that both must be read numReads times.
func GetClusterRoleBindingListChannel(client client.Interface,
numReads int) ClusterRoleBindingListChannel {
channel := ClusterRoleBindingListChannel{
List: make(chan *rbac.ClusterRoleBindingList, numReads),
Error: make(chan error, numReads),
}
go func() {
list, err := client.RbacV1().ClusterRoleBindings().List(api.ListEverything)
for i := 0; i < numReads; i++ {
channel.List <- list
channel.Error <- err
}
}()
return channel
}
// PersistentVolumeListChannel is a list and error channels to PersistentVolumes.
type PersistentVolumeListChannel struct {
List chan *v1.PersistentVolumeList
Error chan error
}
// GetPersistentVolumeListChannel returns a pair of channels to a PersistentVolume list and errors
// that both must be read numReads times.
func GetPersistentVolumeListChannel(client client.Interface,
numReads int) PersistentVolumeListChannel {
channel := PersistentVolumeListChannel{
List: make(chan *v1.PersistentVolumeList, numReads),
Error: make(chan error, numReads),
}
go func() {
list, err := client.CoreV1().PersistentVolumes().List(api.ListEverything)
for i := 0; i < numReads; i++ {
channel.List <- list
channel.Error <- err
}
}()
return channel
}
// PersistentVolumeClaimListChannel is a list and error channels to PersistentVolumeClaims.
type PersistentVolumeClaimListChannel struct {
List chan *v1.PersistentVolumeClaimList
Error chan error
}
// GetPersistentVolumeClaimListChannel returns a pair of channels to a PersistentVolumeClaim list
// and errors that both must be read numReads times.
func GetPersistentVolumeClaimListChannel(client client.Interface, nsQuery *NamespaceQuery,
numReads int) PersistentVolumeClaimListChannel {
channel := PersistentVolumeClaimListChannel{
List: make(chan *v1.PersistentVolumeClaimList, numReads),
Error: make(chan error, numReads),
}
go func() {
list, err := client.CoreV1().PersistentVolumeClaims(nsQuery.ToRequestParam()).List(api.ListEverything)
for i := 0; i < numReads; i++ {
channel.List <- list
channel.Error <- err
}
}()
return channel
}
// ResourceQuotaListChannel is a list and error channels to ResourceQuotas.
type ResourceQuotaListChannel struct {
List chan *v1.ResourceQuotaList
Error chan error
}
// GetResourceQuotaListChannel returns a pair of channels to a ResourceQuota list and errors that
// both must be read numReads times.
func GetResourceQuotaListChannel(client client.Interface, nsQuery *NamespaceQuery,
numReads int) ResourceQuotaListChannel {
channel := ResourceQuotaListChannel{
List: make(chan *v1.ResourceQuotaList, numReads),
Error: make(chan error, numReads),
}
go func() {
list, err := client.CoreV1().ResourceQuotas(nsQuery.ToRequestParam()).List(api.ListEverything)
for i := 0; i < numReads; i++ {
channel.List <- list
channel.Error <- err
}
}()
return channel
}
// HorizontalPodAutoscalerListChannel is a list and error channels.
type HorizontalPodAutoscalerListChannel struct {
List chan *autoscaling.HorizontalPodAutoscalerList
Error chan error
}
// GetPodListMetricsChannel returns a pair of channels to MetricsByPod and errors that
// both must be read numReads times.
func GetHorizontalPodAutoscalerListChannel(client client.Interface, nsQuery *NamespaceQuery,
numReads int) HorizontalPodAutoscalerListChannel {
channel := HorizontalPodAutoscalerListChannel{
List: make(chan *autoscaling.HorizontalPodAutoscalerList, numReads),
Error: make(chan error, numReads),
}
go func() {
list, err := client.AutoscalingV1().HorizontalPodAutoscalers(nsQuery.ToRequestParam()).
List(api.ListEverything)
for i := 0; i < numReads; i++ {
channel.List <- list
channel.Error <- err
}
}()
return channel
}
// StorageClassListChannel is a list and error channels to storage classes.
type StorageClassListChannel struct {
List chan *storage.StorageClassList
Error chan error
}
// GetStorageClassListChannel returns a pair of channels to a storage class list and
// errors that both must be read numReads times.
func GetStorageClassListChannel(client client.Interface, numReads int) StorageClassListChannel {
channel := StorageClassListChannel{
List: make(chan *storage.StorageClassList, numReads),
Error: make(chan error, numReads),
}
go func() {
list, err := client.StorageV1().StorageClasses().List(api.ListEverything)
for i := 0; i < numReads; i++ {
channel.List <- list
channel.Error <- err
}
}()
return channel
}