/
kubescheduler.go
561 lines (484 loc) · 19.4 KB
/
kubescheduler.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
/*
Copyright © 2023 k-cloud-labs org
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 framework
import (
"context"
"encoding/json"
"errors"
"fmt"
"os"
"sync"
"time"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
resourcev1alpha1 "k8s.io/api/resource/v1alpha1"
storagev1 "k8s.io/api/storage/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/sets"
utilfeature "k8s.io/apiserver/pkg/util/feature"
"k8s.io/client-go/dynamic"
"k8s.io/client-go/dynamic/dynamicinformer"
"k8s.io/client-go/informers"
coreinformers "k8s.io/client-go/informers/core/v1"
clientset "k8s.io/client-go/kubernetes"
restclient "k8s.io/client-go/rest"
"k8s.io/client-go/testing"
"k8s.io/client-go/tools/cache"
"k8s.io/client-go/tools/events"
"k8s.io/klog/v2"
schedconfig "k8s.io/kubernetes/cmd/kube-scheduler/app/config"
"k8s.io/kubernetes/pkg/api/legacyscheme"
"k8s.io/kubernetes/pkg/features"
"k8s.io/kubernetes/pkg/scheduler"
kubeschedulerconfig "k8s.io/kubernetes/pkg/scheduler/apis/config"
"k8s.io/kubernetes/pkg/scheduler/framework"
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/defaultbinder"
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/defaultpreemption"
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/volumebinding"
frameworkruntime "k8s.io/kubernetes/pkg/scheduler/framework/runtime"
"k8s.io/kubernetes/pkg/scheduler/profile"
"sigs.k8s.io/controller-runtime/pkg/client/apiutil"
"github.com/k-cloud-labs/kluster-capacity/pkg"
"github.com/k-cloud-labs/kluster-capacity/pkg/plugins/generic"
"github.com/k-cloud-labs/kluster-capacity/pkg/utils"
)
func init() {
if err := corev1.AddToScheme(legacyscheme.Scheme); err != nil {
fmt.Printf("err: %v\n", err)
}
// add your own scheme here to use dynamic informer factory when you have some custom filter plugins
// which uses other resources than defined in scheduler.
// for details, refer to k8s.io/kubernetes/pkg/scheduler/eventhandlers.go
}
var (
initResources = map[schema.GroupVersionKind]func() runtime.Object{
corev1.SchemeGroupVersion.WithKind("Namespace"): func() runtime.Object { return &corev1.Namespace{} },
corev1.SchemeGroupVersion.WithKind("Pod"): func() runtime.Object { return &corev1.Pod{} },
corev1.SchemeGroupVersion.WithKind("Node"): func() runtime.Object { return &corev1.Node{} },
corev1.SchemeGroupVersion.WithKind("PersistentVolume"): func() runtime.Object { return &corev1.PersistentVolume{} },
corev1.SchemeGroupVersion.WithKind("PersistentVolumeClaim"): func() runtime.Object { return &corev1.PersistentVolumeClaim{} },
corev1.SchemeGroupVersion.WithKind("Service"): func() runtime.Object { return &corev1.Service{} },
corev1.SchemeGroupVersion.WithKind("ReplicationController"): func() runtime.Object { return &corev1.ReplicationController{} },
appsv1.SchemeGroupVersion.WithKind("StatefulSet"): func() runtime.Object { return &appsv1.StatefulSet{} },
appsv1.SchemeGroupVersion.WithKind("ReplicaSet"): func() runtime.Object { return &appsv1.ReplicaSet{} },
storagev1.SchemeGroupVersion.WithKind("StorageClass"): func() runtime.Object { return &storagev1.StorageClass{} },
storagev1.SchemeGroupVersion.WithKind("CSINode"): func() runtime.Object { return &storagev1.CSINode{} },
storagev1.SchemeGroupVersion.WithKind("CSIDriver"): func() runtime.Object { return &storagev1.CSIDriver{} },
storagev1.SchemeGroupVersion.WithKind("CSIStorageCapacity"): func() runtime.Object { return &storagev1.CSIStorageCapacity{} },
resourcev1alpha1.SchemeGroupVersion.WithKind("PodScheduling"): func() runtime.Object {
if utilfeature.DefaultFeatureGate.Enabled(features.DynamicResourceAllocation) {
return &resourcev1alpha1.PodScheduling{}
}
return nil
},
resourcev1alpha1.SchemeGroupVersion.WithKind("ResourceClaim"): func() runtime.Object {
if utilfeature.DefaultFeatureGate.Enabled(features.DynamicResourceAllocation) {
return &resourcev1alpha1.ResourceClaim{}
}
return nil
},
}
once sync.Once
initObjects []runtime.Object
)
type kubeschedulerFramework struct {
// fake clientset used by scheduler
fakeClient clientset.Interface
// fake informer factory used by scheduler
fakeInformerFactory informers.SharedInformerFactory
// TODO: follow kubernetes master branch code
dynInformerFactory dynamicinformer.DynamicSharedInformerFactory
restMapper meta.RESTMapper
// real dynamic client to init the world
dynamicClient *dynamic.DynamicClient
// scheduler
scheduler *scheduler.Scheduler
excludeNodes sets.Set[string]
withScheduledPods bool
withNodeImages bool
ignorePodsOnExcludesNode bool
// deletionTimestamp is not nil and phase is not succeed or failed
withTerminatingPods bool
outOfTreeRegistry frameworkruntime.Registry
customBind kubeschedulerconfig.PluginSet
customPreBind kubeschedulerconfig.PluginSet
customPostBind kubeschedulerconfig.PluginSet
customEventHandlers []func()
postBindHook func(*corev1.Pod) error
// for scheduler and informer
informerCh chan struct{}
schedulerCh chan struct{}
// for simulator
stopCh chan struct{}
stopMux sync.Mutex
stopped bool
// final status
status *pkg.Status
// save status to this file if specified
saveTo string
}
type Option func(*kubeschedulerFramework)
func WithExcludeNodes(excludeNodes []string) Option {
return func(s *kubeschedulerFramework) {
s.excludeNodes = sets.New[string](excludeNodes...)
}
}
func WithOutOfTreeRegistry(registry frameworkruntime.Registry) Option {
return func(s *kubeschedulerFramework) {
s.outOfTreeRegistry = registry
}
}
func WithCustomBind(plugins kubeschedulerconfig.PluginSet) Option {
return func(s *kubeschedulerFramework) {
s.customBind = plugins
}
}
func WithCustomPreBind(plugins kubeschedulerconfig.PluginSet) Option {
return func(s *kubeschedulerFramework) {
s.customPreBind = plugins
}
}
func WithCustomPostBind(plugins kubeschedulerconfig.PluginSet) Option {
return func(s *kubeschedulerFramework) {
s.customPostBind = plugins
}
}
func WithCustomEventHandlers(handlers []func()) Option {
return func(s *kubeschedulerFramework) {
s.customEventHandlers = handlers
}
}
func WithNodeImages(with bool) Option {
return func(s *kubeschedulerFramework) {
s.withNodeImages = with
}
}
func WithScheduledPods(with bool) Option {
return func(s *kubeschedulerFramework) {
s.withScheduledPods = with
}
}
func WithIgnorePodsOnExcludesNode(with bool) Option {
return func(s *kubeschedulerFramework) {
s.ignorePodsOnExcludesNode = with
}
}
func WithPostBindHook(postBindHook func(*corev1.Pod) error) Option {
return func(s *kubeschedulerFramework) {
s.postBindHook = postBindHook
}
}
func WithSaveTo(to string) Option {
return func(s *kubeschedulerFramework) {
s.saveTo = to
}
}
func WithTerminatingPods(with bool) Option {
return func(s *kubeschedulerFramework) {
s.withTerminatingPods = with
}
}
// NewKubeSchedulerFramework create a generic simulator for ce, cc, ss simulator which is completely independent of apiserver so no need
// for kubeconfig nor for apiserver url
func NewKubeSchedulerFramework(kubeSchedulerConfig *schedconfig.CompletedConfig, restConfig *restclient.Config, options ...Option) (pkg.Framework, error) {
kubeSchedulerConfig.InformerFactory.InformerFor(&corev1.Pod{}, newPodInformer)
dynamicClient := dynamic.NewForConfigOrDie(restConfig)
restMapper, err := apiutil.NewDynamicRESTMapper(restConfig)
if err != nil {
return nil, err
}
s := &kubeschedulerFramework{
fakeClient: kubeSchedulerConfig.Client,
dynamicClient: dynamicClient,
restMapper: restMapper,
stopCh: make(chan struct{}),
fakeInformerFactory: kubeSchedulerConfig.InformerFactory,
informerCh: make(chan struct{}),
schedulerCh: make(chan struct{}),
withScheduledPods: true,
ignorePodsOnExcludesNode: false,
withNodeImages: true,
withTerminatingPods: true,
status: &pkg.Status{},
}
for _, option := range options {
option(s)
}
// only for latest k8s version
if restConfig != nil {
dynClient := dynamic.NewForConfigOrDie(restConfig)
s.dynInformerFactory = dynamicinformer.NewFilteredDynamicSharedInformerFactory(dynClient, 0, corev1.NamespaceAll, nil)
}
scheduler, err := s.createScheduler(kubeSchedulerConfig)
if err != nil {
return nil, err
}
s.scheduler = scheduler
s.fakeInformerFactory.Start(s.informerCh)
if s.dynInformerFactory != nil {
s.dynInformerFactory.Start(s.informerCh)
}
return s, nil
}
func (s *kubeschedulerFramework) GetPodsByNode(nodeName string) ([]*corev1.Pod, error) {
dump := s.scheduler.Cache.Dump()
var res []*corev1.Pod
if dump != nil && dump.Nodes[nodeName] != nil {
podInfos := dump.Nodes[nodeName].Pods
for i := range podInfos {
if podInfos[i].Pod != nil {
res = append(res, podInfos[i].Pod)
}
}
}
if res == nil {
return nil, errors.New("cannot get pods on the node because dump is nil")
}
return res, nil
}
// InitTheWorld use objs outside or default init resources to initialize the scheduler
// the objs outside must be typed object.
func (s *kubeschedulerFramework) InitTheWorld(objs ...runtime.Object) error {
if len(objs) == 0 {
// black magic
klog.V(2).InfoS("Init the world form running cluster")
initObjects := getInitObjects(s.restMapper, s.dynamicClient)
for _, unstructuredObj := range initObjects {
obj := initResources[unstructuredObj.GetObjectKind().GroupVersionKind()]()
if err := runtime.DefaultUnstructuredConverter.FromUnstructured(unstructuredObj.(*unstructured.Unstructured).UnstructuredContent(), obj); err != nil {
return err
}
if needAdd, obj := s.preAdd(obj); needAdd {
if err := s.fakeClient.(testing.FakeClient).Tracker().Add(obj); err != nil {
return err
}
}
}
} else {
klog.V(2).InfoS("Init the world form snapshot")
for _, obj := range objs {
if _, ok := obj.(runtime.Unstructured); ok {
return errors.New("type of objs used to init the world must not be unstructured")
}
if needAdd, obj := s.preAdd(obj); needAdd {
if err := s.fakeClient.(testing.FakeClient).Tracker().Add(obj); err != nil {
return err
}
}
}
}
return nil
}
func (s *kubeschedulerFramework) UpdateEstimationPods(pod ...*corev1.Pod) {
s.status.PodsForEstimation = append(s.status.PodsForEstimation, pod...)
}
func (s *kubeschedulerFramework) UpdateNodesToScaleDown(nodeName string) {
s.status.NodesToScaleDown = append(s.status.NodesToScaleDown, nodeName)
}
func (s *kubeschedulerFramework) Status() *pkg.Status {
return s.status
}
func (s *kubeschedulerFramework) Stop(reason string) error {
s.stopMux.Lock()
defer func() {
s.stopMux.Unlock()
}()
if s.stopped {
return nil
}
nodeMap := make(map[string]corev1.Node)
nodeList, _ := s.fakeClient.CoreV1().Nodes().List(context.TODO(), metav1.ListOptions{ResourceVersion: "0"})
for _, node := range nodeList.Items {
nodeMap[node.Name] = node
}
s.status.Nodes = nodeMap
podList, _ := s.fakeClient.CoreV1().Pods(metav1.NamespaceAll).List(context.TODO(), metav1.ListOptions{ResourceVersion: "0"})
s.status.Pods = podList.Items
s.status.StopReason = reason
if len(s.saveTo) > 0 {
file, err := os.OpenFile(s.saveTo, os.O_CREATE|os.O_RDWR, 0755)
if err != nil {
panic(err)
}
defer file.Close()
bytes, err := json.Marshal(s.status)
if err != nil {
return err
}
_, err = file.Write(bytes)
if err != nil {
return err
}
}
defer func() {
close(s.stopCh)
close(s.informerCh)
close(s.schedulerCh)
}()
s.stopped = true
return nil
}
func (s *kubeschedulerFramework) CreatePod(pod *corev1.Pod) error {
_, err := s.fakeClient.CoreV1().Pods(pod.Namespace).Create(context.TODO(), pod, metav1.CreateOptions{})
return err
}
func (s *kubeschedulerFramework) Run() error {
// wait for all informer cache synced
s.fakeInformerFactory.WaitForCacheSync(s.informerCh)
if s.dynInformerFactory != nil {
s.dynInformerFactory.WaitForCacheSync(s.informerCh)
}
go s.scheduler.Run(context.TODO())
<-s.stopCh
return nil
}
func (s *kubeschedulerFramework) createScheduler(cc *schedconfig.CompletedConfig) (*scheduler.Scheduler, error) {
// custom event handlers
for _, handler := range s.customEventHandlers {
handler()
}
// register default generic plugin
if s.outOfTreeRegistry == nil {
s.outOfTreeRegistry = make(frameworkruntime.Registry)
}
err := s.outOfTreeRegistry.Register(generic.Name, func(configuration runtime.Object, f framework.Handle) (framework.Plugin, error) {
return generic.New(s.postBindHook, s.fakeClient, s.status)
})
if err != nil {
return nil, err
}
cc.ComponentConfig.Profiles[0].Plugins.PreBind.Enabled = append(cc.ComponentConfig.Profiles[0].Plugins.PreBind.Enabled, kubeschedulerconfig.Plugin{Name: generic.Name})
cc.ComponentConfig.Profiles[0].Plugins.PreBind.Disabled = append(cc.ComponentConfig.Profiles[0].Plugins.PreBind.Disabled, kubeschedulerconfig.Plugin{Name: volumebinding.Name})
cc.ComponentConfig.Profiles[0].Plugins.Bind.Enabled = append(cc.ComponentConfig.Profiles[0].Plugins.Bind.Enabled, kubeschedulerconfig.Plugin{Name: generic.Name})
cc.ComponentConfig.Profiles[0].Plugins.Bind.Disabled = append(cc.ComponentConfig.Profiles[0].Plugins.Bind.Disabled, kubeschedulerconfig.Plugin{Name: defaultbinder.Name})
cc.ComponentConfig.Profiles[0].Plugins.PostBind.Enabled = append(cc.ComponentConfig.Profiles[0].Plugins.PostBind.Enabled, kubeschedulerconfig.Plugin{Name: generic.Name})
cc.ComponentConfig.Profiles[0].Plugins.PostFilter.Disabled = append(cc.ComponentConfig.Profiles[0].Plugins.PostFilter.Disabled, kubeschedulerconfig.Plugin{Name: defaultpreemption.Name})
// custom bind plugin
cc.ComponentConfig.Profiles[0].Plugins.PreBind.Enabled = append(cc.ComponentConfig.Profiles[0].Plugins.PreBind.Enabled, s.customPreBind.Enabled...)
cc.ComponentConfig.Profiles[0].Plugins.PreBind.Disabled = append(cc.ComponentConfig.Profiles[0].Plugins.PreBind.Disabled, s.customPreBind.Disabled...)
cc.ComponentConfig.Profiles[0].Plugins.Bind.Enabled = append(cc.ComponentConfig.Profiles[0].Plugins.Bind.Enabled, s.customBind.Enabled...)
cc.ComponentConfig.Profiles[0].Plugins.Bind.Disabled = append(cc.ComponentConfig.Profiles[0].Plugins.Bind.Disabled, s.customBind.Disabled...)
cc.ComponentConfig.Profiles[0].Plugins.PostBind.Enabled = append(cc.ComponentConfig.Profiles[0].Plugins.PostBind.Enabled, s.customPostBind.Enabled...)
cc.ComponentConfig.Profiles[0].Plugins.PostBind.Disabled = append(cc.ComponentConfig.Profiles[0].Plugins.PostBind.Disabled, s.customPostBind.Disabled...)
// create the scheduler.
return scheduler.New(
s.fakeClient,
s.fakeInformerFactory,
s.dynInformerFactory,
getRecorderFactory(cc),
s.schedulerCh,
scheduler.WithComponentConfigVersion(cc.ComponentConfig.TypeMeta.APIVersion),
scheduler.WithKubeConfig(cc.KubeConfig),
scheduler.WithProfiles(cc.ComponentConfig.Profiles...),
scheduler.WithPercentageOfNodesToScore(cc.ComponentConfig.PercentageOfNodesToScore),
scheduler.WithFrameworkOutOfTreeRegistry(s.outOfTreeRegistry),
scheduler.WithPodMaxBackoffSeconds(cc.ComponentConfig.PodMaxBackoffSeconds),
scheduler.WithPodInitialBackoffSeconds(cc.ComponentConfig.PodInitialBackoffSeconds),
scheduler.WithExtenders(cc.ComponentConfig.Extenders...),
scheduler.WithParallelism(cc.ComponentConfig.Parallelism),
)
}
func (s *kubeschedulerFramework) preAdd(obj runtime.Object) (bool, runtime.Object) {
// filter exclude nodes and pods and update pod, node spec and status property
if pod, ok := obj.(*corev1.Pod); ok {
// ignore ds pods on exclude nodes
if s.excludeNodes != nil {
if _, ok := s.excludeNodes[pod.Spec.NodeName]; ok {
if s.ignorePodsOnExcludesNode || pod.OwnerReferences != nil && utils.IsDaemonsetPod(pod.OwnerReferences) {
return false, nil
}
}
}
if pod.Status.Phase == corev1.PodSucceeded || pod.Status.Phase == corev1.PodFailed {
return false, nil
}
if pod.DeletionTimestamp != nil && !s.withTerminatingPods {
return false, nil
}
if !s.withScheduledPods && !utils.IsDaemonsetPod(pod.OwnerReferences) {
pod := utils.InitPod(pod)
pod.Status.Phase = corev1.PodPending
return true, pod
}
} else if node, ok := obj.(*corev1.Node); ok && s.excludeNodes != nil {
if _, ok := s.excludeNodes[node.Name]; ok {
return false, nil
} else if !s.withNodeImages {
node.Status.Images = nil
return true, node
}
}
return true, obj
}
func newPodInformer(cs clientset.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer {
selector := fmt.Sprintf("status.phase!=%v,status.phase!=%v", corev1.PodSucceeded, corev1.PodFailed)
tweakListOptions := func(options *metav1.ListOptions) {
options.FieldSelector = selector
}
return coreinformers.NewFilteredPodInformer(cs, metav1.NamespaceAll, resyncPeriod, nil, tweakListOptions)
}
func getRecorderFactory(cc *schedconfig.CompletedConfig) profile.RecorderFactory {
return func(name string) events.EventRecorder {
return cc.EventBroadcaster.NewRecorder(name)
}
}
// getInitObjects return all objects need to add to scheduler.
// it's pkg scope for multi scheduler to avoid calling too much times of real kube-apiserver
func getInitObjects(restMapper meta.RESTMapper, dynClient dynamic.Interface) []runtime.Object {
once.Do(func() {
// each item is UnstructuredList
for gvk := range initResources {
restMapping, err := restMapper.RESTMapping(gvk.GroupKind(), gvk.Version)
if err != nil && !meta.IsNoMatchError(err) {
fmt.Printf("unable to get rest mapping for %s, error: %s", gvk.String(), err.Error())
os.Exit(1)
}
if restMapping != nil {
var (
list *unstructured.UnstructuredList
err error
)
if restMapping.Scope.Name() == meta.RESTScopeNameRoot {
list, err = dynClient.Resource(restMapping.Resource).List(context.TODO(), metav1.ListOptions{ResourceVersion: "0"})
if err != nil && !apierrors.IsNotFound(err) {
fmt.Printf("unable to list %s, error: %s", gvk.String(), err.Error())
os.Exit(1)
}
} else {
if restMapping.Resource.Resource == "pods" {
list, err = dynClient.Resource(restMapping.Resource).Namespace(metav1.NamespaceAll).List(context.TODO(), metav1.ListOptions{
ResourceVersion: "0",
FieldSelector: fmt.Sprintf("status.phase!=%v,status.phase!=%v", corev1.PodSucceeded, corev1.PodFailed),
})
} else {
list, err = dynClient.Resource(restMapping.Resource).Namespace(metav1.NamespaceAll).List(context.TODO(), metav1.ListOptions{ResourceVersion: "0"})
}
if err != nil && !apierrors.IsNotFound(err) {
fmt.Printf("unable to list %s, error: %s", gvk.String(), err.Error())
os.Exit(1)
}
}
_ = list.EachListItem(func(object runtime.Object) error {
initObjects = append(initObjects, object)
return nil
})
}
}
})
return initObjects
}