/
config-map.go
582 lines (517 loc) · 20.5 KB
/
config-map.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
/*
* This file is part of the KubeVirt project
*
* 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.
*
* Copyright 2017, 2018 Red Hat, Inc.
*
*/
package virtconfig
import (
"encoding/json"
"fmt"
"strconv"
"strings"
"sync"
k8sv1 "k8s.io/api/core/v1"
extv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
"k8s.io/apimachinery/pkg/api/resource"
"k8s.io/apimachinery/pkg/util/yaml"
"k8s.io/client-go/tools/cache"
"k8s.io/utils/pointer"
v1 "kubevirt.io/client-go/api/v1"
"kubevirt.io/client-go/log"
)
const (
ConfigMapName = "kubevirt-config"
FeatureGatesKey = "feature-gates"
EmulatedMachinesKey = "emulated-machines"
MachineTypeKey = "machine-type"
UseEmulationKey = "debug.useEmulation"
ImagePullPolicyKey = "dev.imagePullPolicy"
MigrationsConfigKey = "migrations"
CPUModelKey = "default-cpu-model"
CPURequestKey = "cpu-request"
MemoryOvercommitKey = "memory-overcommit"
LessPVCSpaceTolerationKey = "pvc-tolerate-less-space-up-to-percent"
NodeSelectorsKey = "node-selectors"
NetworkInterfaceKey = "default-network-interface"
PermitSlirpInterface = "permitSlirpInterface"
PermitBridgeInterfaceOnPodNetwork = "permitBridgeInterfaceOnPodNetwork"
NodeDrainTaintDefaultKey = "kubevirt.io/drain"
SmbiosConfigKey = "smbios"
SELinuxLauncherTypeKey = "selinuxLauncherType"
SupportedGuestAgentVersionsKey = "supported-guest-agent"
OVMFPathKey = "ovmfPath"
MemBalloonStatsPeriod = "memBalloonStatsPeriod"
CPUAllocationRatio = "cpu-allocation-ratio"
PermittedHostDevicesKey = "permittedHostDevices"
)
type ConfigModifiedFn func()
// NewClusterConfig represents the `kubevirt-config` config map. It can be used to live-update
// values if the config changes. The config update works like this:
// 1. Check if the config exists. If it does not exist, return the default config
// 2. Check if the config got updated. If so, try to parse and return it
// 3. In case of errors or no updates (resource version stays the same), it returns the values from the last good config
func NewClusterConfig(configMapInformer cache.SharedIndexInformer,
crdInformer cache.SharedIndexInformer,
kubeVirtInformer cache.SharedIndexInformer,
namespace string) *ClusterConfig {
defaultConfig := defaultClusterConfig()
c := &ClusterConfig{
configMapInformer: configMapInformer,
crdInformer: crdInformer,
kubeVirtInformer: kubeVirtInformer,
lock: &sync.Mutex{},
namespace: namespace,
lastValidConfig: defaultConfig,
defaultConfig: defaultConfig,
}
c.configMapInformer.AddEventHandler(cache.ResourceEventHandlerFuncs{
AddFunc: c.configAddedDeleted,
DeleteFunc: c.configAddedDeleted,
UpdateFunc: c.configUpdated,
})
c.crdInformer.AddEventHandler(cache.ResourceEventHandlerFuncs{
AddFunc: c.crdAddedDeleted,
DeleteFunc: c.crdAddedDeleted,
UpdateFunc: c.crdUpdated,
})
c.kubeVirtInformer.AddEventHandler(cache.ResourceEventHandlerFuncs{
AddFunc: c.configAddedDeleted,
UpdateFunc: c.configUpdated,
})
return c
}
func (c *ClusterConfig) configAddedDeleted(_ interface{}) {
go c.GetConfig()
c.lock.Lock()
defer c.lock.Unlock()
if c.configModifiedCallback != nil {
for _, callback := range c.configModifiedCallback {
go callback()
}
}
}
func (c *ClusterConfig) configUpdated(_, _ interface{}) {
go c.GetConfig()
c.lock.Lock()
defer c.lock.Unlock()
if c.configModifiedCallback != nil {
for _, callback := range c.configModifiedCallback {
go callback()
}
}
}
func isDataVolumeCrd(crd *extv1.CustomResourceDefinition) bool {
if crd.Spec.Names.Kind == "DataVolume" {
return true
}
return false
}
func (c *ClusterConfig) crdAddedDeleted(obj interface{}) {
go c.GetConfig()
crd := obj.(*extv1.CustomResourceDefinition)
if !isDataVolumeCrd(crd) {
return
}
c.lock.Lock()
defer c.lock.Unlock()
if c.configModifiedCallback != nil {
for _, callback := range c.configModifiedCallback {
go callback()
}
}
}
func (c *ClusterConfig) crdUpdated(_, cur interface{}) {
c.crdAddedDeleted(cur)
}
func defaultClusterConfig() *v1.KubeVirtConfiguration {
parallelOutboundMigrationsPerNodeDefault := ParallelOutboundMigrationsPerNodeDefault
parallelMigrationsPerClusterDefault := ParallelMigrationsPerClusterDefault
bandwithPerMigrationDefault := resource.MustParse(BandwithPerMigrationDefault)
nodeDrainTaintDefaultKey := NodeDrainTaintDefaultKey
allowAutoConverge := MigrationAllowAutoConverge
allowPostCopy := MigrationAllowPostCopy
defaultUnsafeMigrationOverride := DefaultUnsafeMigrationOverride
progressTimeout := MigrationProgressTimeout
completionTimeoutPerGiB := MigrationCompletionTimeoutPerGiB
cpuRequestDefault := resource.MustParse(DefaultCPURequest)
emulatedMachinesDefault := strings.Split(DefaultEmulatedMachines, ",")
nodeSelectorsDefault, _ := parseNodeSelectors(DefaultNodeSelectors)
defaultNetworkInterface := DefaultNetworkInterface
defaultMemBalloonStatsPeriod := DefaultMemBalloonStatsPeriod
SmbiosDefaultConfig := &v1.SMBiosConfiguration{
Family: SmbiosConfigDefaultFamily,
Manufacturer: SmbiosConfigDefaultManufacturer,
Product: SmbiosConfigDefaultProduct,
}
supportedQEMUGuestAgentVersions := strings.Split(strings.TrimRight(SupportedGuestAgentVersions, ","), ",")
return &v1.KubeVirtConfiguration{
ImagePullPolicy: DefaultImagePullPolicy,
DeveloperConfiguration: &v1.DeveloperConfiguration{
UseEmulation: DefaultUseEmulation,
MemoryOvercommit: DefaultMemoryOvercommit,
LessPVCSpaceToleration: DefaultLessPVCSpaceToleration,
MinimumReservePVCBytes: DefaultMinimumReservePVCBytes,
NodeSelectors: nodeSelectorsDefault,
CPUAllocationRatio: DefaultCPUAllocationRatio,
LogVerbosity: &v1.LogVerbosity{
VirtAPI: DefaultVirtAPILogVerbosity,
VirtOperator: DefaultVirtOperatorLogVerbosity,
VirtController: DefaultVirtControllerLogVerbosity,
VirtHandler: DefaultVirtHandlerLogVerbosity,
VirtLauncher: DefaultVirtLauncherLogVerbosity,
},
},
MigrationConfiguration: &v1.MigrationConfiguration{
ParallelMigrationsPerCluster: ¶llelMigrationsPerClusterDefault,
ParallelOutboundMigrationsPerNode: ¶llelOutboundMigrationsPerNodeDefault,
NodeDrainTaintKey: &nodeDrainTaintDefaultKey,
BandwidthPerMigration: &bandwithPerMigrationDefault,
ProgressTimeout: &progressTimeout,
CompletionTimeoutPerGiB: &completionTimeoutPerGiB,
UnsafeMigrationOverride: &defaultUnsafeMigrationOverride,
AllowAutoConverge: &allowAutoConverge,
AllowPostCopy: &allowPostCopy,
},
MachineType: DefaultMachineType,
CPURequest: &cpuRequestDefault,
EmulatedMachines: emulatedMachinesDefault,
NetworkConfiguration: &v1.NetworkConfiguration{
NetworkInterface: defaultNetworkInterface,
PermitSlirpInterface: pointer.BoolPtr(DefaultPermitSlirpInterface),
PermitBridgeInterfaceOnPodNetwork: pointer.BoolPtr(DefaultPermitBridgeInterfaceOnPodNetwork),
},
SMBIOSConfig: SmbiosDefaultConfig,
SELinuxLauncherType: DefaultSELinuxLauncherType,
SupportedGuestAgentVersions: supportedQEMUGuestAgentVersions,
OVMFPath: DefaultOVMFPath,
MemBalloonStatsPeriod: &defaultMemBalloonStatsPeriod,
}
}
type ClusterConfig struct {
configMapInformer cache.SharedIndexInformer
crdInformer cache.SharedIndexInformer
kubeVirtInformer cache.SharedIndexInformer
namespace string
lock *sync.Mutex
lastValidConfig *v1.KubeVirtConfiguration
defaultConfig *v1.KubeVirtConfiguration
lastInvalidConfigResourceVersion string
lastValidConfigResourceVersion string
configModifiedCallback []ConfigModifiedFn
}
func (c *ClusterConfig) SetConfigModifiedCallback(cb ConfigModifiedFn) {
c.lock.Lock()
defer c.lock.Unlock()
c.configModifiedCallback = append(c.configModifiedCallback, cb)
for _, callback := range c.configModifiedCallback {
go callback()
}
}
// This struct is for backward compatibility and is deprecated, no new fields should be added
type migrationConfiguration struct {
NodeDrainTaintKey *string `json:"nodeDrainTaintKey,omitempty"`
ParallelOutboundMigrationsPerNode *uint32 `json:"parallelOutboundMigrationsPerNode,string,omitempty"`
ParallelMigrationsPerCluster *uint32 `json:"parallelMigrationsPerCluster,string,omitempty"`
AllowAutoConverge *bool `json:"allowAutoConverge,string,omitempty"`
BandwidthPerMigration *resource.Quantity `json:"bandwidthPerMigration,omitempty"`
CompletionTimeoutPerGiB *int64 `json:"completionTimeoutPerGiB,string,omitempty"`
ProgressTimeout *int64 `json:"progressTimeout,string,omitempty"`
UnsafeMigrationOverride *bool `json:"unsafeMigrationOverride,string,omitempty"`
AllowPostCopy *bool `json:"allowPostCopy,string,omitempty"`
}
// setConfigFromConfigMap parses the provided config map and updates the provided config.
// Default values in the provided config stay intact.
func setConfigFromConfigMap(config *v1.KubeVirtConfiguration, configMap *k8sv1.ConfigMap) error {
// set migration options
rawConfig := strings.TrimSpace(configMap.Data[MigrationsConfigKey])
if rawConfig != "" {
migrationConfig := migrationConfiguration(*config.MigrationConfiguration)
// only sets values if they were specified, default values stay intact
err := yaml.NewYAMLOrJSONDecoder(strings.NewReader(rawConfig), 1024).Decode(&migrationConfig)
if err != nil {
return fmt.Errorf("failed to parse migration config: %v", err)
}
converted := v1.MigrationConfiguration(migrationConfig)
config.MigrationConfiguration = &converted
}
// set smbios values if they exist
smbiosConfig := strings.TrimSpace(configMap.Data[SmbiosConfigKey])
if smbiosConfig != "" {
// only set values if they were specified, default values stay intact
err := yaml.NewYAMLOrJSONDecoder(strings.NewReader(smbiosConfig), 1024).Decode(config.SMBIOSConfig)
if err != nil {
return fmt.Errorf("failed to parse SMBIOS config: %v", err)
}
}
// updates host devices in the config.
var newPermittedHostDevices *v1.PermittedHostDevices
rawConfig = strings.TrimSpace(configMap.Data[PermittedHostDevicesKey])
if rawConfig != "" {
newPermittedHostDevices = &v1.PermittedHostDevices{}
err := yaml.NewYAMLOrJSONDecoder(strings.NewReader(rawConfig), 1024).Decode(newPermittedHostDevices)
if err != nil {
return fmt.Errorf("failed to parse host devices config: %v", err)
}
}
config.PermittedHostDevices = newPermittedHostDevices
// set image pull policy
policy := strings.TrimSpace(configMap.Data[ImagePullPolicyKey])
switch policy {
case "":
// keep the default
case "Always":
config.ImagePullPolicy = k8sv1.PullAlways
case "Never":
config.ImagePullPolicy = k8sv1.PullNever
case "IfNotPresent":
config.ImagePullPolicy = k8sv1.PullIfNotPresent
default:
return fmt.Errorf("invalid dev.imagePullPolicy in config: %v", policy)
}
// set if emulation is used
useEmulation := strings.TrimSpace(configMap.Data[UseEmulationKey])
switch useEmulation {
case "":
// keep the default
case "true":
config.DeveloperConfiguration.UseEmulation = true
case "false":
config.DeveloperConfiguration.UseEmulation = false
default:
return fmt.Errorf("invalid debug.useEmulation in config: %v", useEmulation)
}
// set machine type
if machineType := strings.TrimSpace(configMap.Data[MachineTypeKey]); machineType != "" {
config.MachineType = machineType
}
if cpuModel := strings.TrimSpace(configMap.Data[CPUModelKey]); cpuModel != "" {
config.CPUModel = cpuModel
}
if cpuRequest := strings.TrimSpace(configMap.Data[CPURequestKey]); cpuRequest != "" {
*config.CPURequest = resource.MustParse(cpuRequest)
}
if memoryOvercommit := strings.TrimSpace(configMap.Data[MemoryOvercommitKey]); memoryOvercommit != "" {
if value, err := strconv.Atoi(memoryOvercommit); err == nil && value > 0 {
config.DeveloperConfiguration.MemoryOvercommit = value
} else {
return fmt.Errorf("Invalid memoryOvercommit in ConfigMap: %s", memoryOvercommit)
}
}
if cpuOvercommit := strings.TrimSpace(configMap.Data[CPUAllocationRatio]); cpuOvercommit != "" {
if value, err := strconv.ParseInt(cpuOvercommit, 10, 32); err == nil && value > 0 {
config.DeveloperConfiguration.CPUAllocationRatio = int(value)
} else {
return fmt.Errorf("Invalid cpu allocation ratio in ConfigMap: %s", cpuOvercommit)
}
}
if emulatedMachines := strings.TrimSpace(configMap.Data[EmulatedMachinesKey]); emulatedMachines != "" {
config.EmulatedMachines = stringToStringArray(emulatedMachines)
}
if featureGates := strings.TrimSpace(configMap.Data[FeatureGatesKey]); featureGates != "" {
config.DeveloperConfiguration.FeatureGates = stringToStringArray(featureGates)
}
if toleration := strings.TrimSpace(configMap.Data[LessPVCSpaceTolerationKey]); toleration != "" {
if value, err := strconv.Atoi(toleration); err != nil || value < 0 || value > 100 {
return fmt.Errorf("Invalid lessPVCSpaceToleration in ConfigMap: %s", toleration)
} else {
config.DeveloperConfiguration.LessPVCSpaceToleration = value
}
}
if nodeSelectors := strings.TrimSpace(configMap.Data[NodeSelectorsKey]); nodeSelectors != "" {
if selectors, err := parseNodeSelectors(nodeSelectors); err != nil {
return err
} else {
config.DeveloperConfiguration.NodeSelectors = selectors
}
}
// disable slirp
permitSlirp := strings.TrimSpace(configMap.Data[PermitSlirpInterface])
switch permitSlirp {
case "":
// keep the default
case "true":
config.NetworkConfiguration.PermitSlirpInterface = pointer.BoolPtr(true)
case "false":
config.NetworkConfiguration.PermitSlirpInterface = pointer.BoolPtr(false)
default:
return fmt.Errorf("invalid value for permitSlirpInterfaces in config: %v", permitSlirp)
}
// disable bridge
permitBridge := strings.TrimSpace(configMap.Data[PermitBridgeInterfaceOnPodNetwork])
switch permitBridge {
case "":
// keep the default
case "false":
config.NetworkConfiguration.PermitBridgeInterfaceOnPodNetwork = pointer.BoolPtr(false)
case "true":
config.NetworkConfiguration.PermitBridgeInterfaceOnPodNetwork = pointer.BoolPtr(true)
default:
return fmt.Errorf("invalid value for permitBridgeInterfaceOnPodNetwork in config: %v", permitBridge)
}
// set default network interface
iface := strings.TrimSpace(configMap.Data[NetworkInterfaceKey])
switch iface {
case "":
// keep the default
case string(v1.BridgeInterface), string(v1.SlirpInterface), string(v1.MasqueradeInterface):
config.NetworkConfiguration.NetworkInterface = iface
default:
return fmt.Errorf("invalid default-network-interface in config: %v", iface)
}
if selinuxLauncherType := strings.TrimSpace(configMap.Data[SELinuxLauncherTypeKey]); selinuxLauncherType != "" {
config.SELinuxLauncherType = selinuxLauncherType
}
if supportedGuestAgentVersions := strings.TrimSpace(configMap.Data[SupportedGuestAgentVersionsKey]); supportedGuestAgentVersions != "" {
vals := strings.Split(strings.TrimRight(supportedGuestAgentVersions, ","), ",")
for i := range vals {
vals[i] = strings.TrimSpace(vals[i])
}
config.SupportedGuestAgentVersions = vals
}
if ovmfPath := strings.TrimSpace(configMap.Data[OVMFPathKey]); ovmfPath != "" {
config.OVMFPath = ovmfPath
}
if memBalloonStatsPeriod := strings.TrimSpace(configMap.Data[MemBalloonStatsPeriod]); memBalloonStatsPeriod != "" {
i, err := strconv.Atoi(memBalloonStatsPeriod)
if err != nil {
return fmt.Errorf("invalid memBalloonStatsPeriod in config, %s", memBalloonStatsPeriod)
}
if i >= 0 {
mem := uint32(i)
config.MemBalloonStatsPeriod = &mem
} else {
return fmt.Errorf("invalid memBalloonStatsPeriod (negative) in config, %d", i)
}
}
return nil
}
func setConfigFromKubeVirt(config *v1.KubeVirtConfiguration, kv *v1.KubeVirt) error {
kvConfig := &kv.Spec.Configuration
overrides, err := json.Marshal(kvConfig)
if err != nil {
return err
}
err = json.Unmarshal(overrides, &config)
if err != nil {
return err
}
return nil
}
// getConfig returns the latest valid parsed config map result, or updates it
// if a newer version is available.
// XXX Rework this, to happen mostly in informer callbacks.
// This will also allow us then to react to config changes and e.g. restart some controllers
func (c *ClusterConfig) GetConfig() (config *v1.KubeVirtConfiguration) {
c.lock.Lock()
defer c.lock.Unlock()
var configMap *k8sv1.ConfigMap
var kv *v1.KubeVirt
var resourceVersion string
var resourceType string
useConfigMap := false
if obj, exists, err := c.configMapInformer.GetStore().GetByKey(c.namespace + "/" + ConfigMapName); err != nil {
log.DefaultLogger().Reason(err).Errorf("Error loading the cluster config from ConfigMap cache, falling back to last good resource version '%s'", c.lastValidConfigResourceVersion)
return c.lastValidConfig
} else if !exists {
kv = c.getConfigFromKubeVirtCR()
if kv == nil {
return c.lastValidConfig
}
resourceType = "KubeVirt"
resourceVersion = kv.ResourceVersion
} else {
useConfigMap = true
resourceType = "ConfigMap"
configMap = obj.(*k8sv1.ConfigMap)
resourceVersion = configMap.ResourceVersion
}
// if there is a configuration config map present we should use its configuration
// and ignore configuration in kubevirt
if c.lastValidConfigResourceVersion == resourceVersion ||
c.lastInvalidConfigResourceVersion == resourceVersion {
return c.lastValidConfig
}
config = defaultClusterConfig()
var err error
if useConfigMap {
err = setConfigFromConfigMap(config, configMap)
} else {
err = setConfigFromKubeVirt(config, kv)
}
if err != nil {
c.lastInvalidConfigResourceVersion = resourceVersion
log.DefaultLogger().Reason(err).Errorf("Invalid cluster config using '%s' resource version '%s', falling back to last good resource version '%s'", resourceType, resourceVersion, c.lastValidConfigResourceVersion)
return c.lastValidConfig
}
log.DefaultLogger().Infof("Updating cluster config from %s to resource version '%s'", resourceType, resourceVersion)
c.lastValidConfigResourceVersion = resourceVersion
c.lastValidConfig = config
return c.lastValidConfig
}
func (c *ClusterConfig) getConfigFromKubeVirtCR() *v1.KubeVirt {
objects := c.kubeVirtInformer.GetStore().List()
var kubeVirtName string
for _, obj := range objects {
if kv, ok := obj.(*v1.KubeVirt); ok && kv.DeletionTimestamp == nil {
if kv.Status.Phase != "" {
kubeVirtName = kv.Name
}
}
}
if kubeVirtName == "" {
return nil
}
if obj, exists, err := c.kubeVirtInformer.GetStore().GetByKey(c.namespace + "/" + kubeVirtName); err != nil {
log.DefaultLogger().Reason(err).Errorf("Error loading the cluster config from KubeVirt cache, falling back to last good resource version '%s'", c.lastValidConfigResourceVersion)
return nil
} else if !exists {
// this path should not be possible
return nil
} else {
return obj.(*v1.KubeVirt)
}
}
func (c *ClusterConfig) HasDataVolumeAPI() bool {
c.lock.Lock()
defer c.lock.Unlock()
objects := c.crdInformer.GetStore().List()
for _, obj := range objects {
if crd, ok := obj.(*extv1.CustomResourceDefinition); ok && crd.DeletionTimestamp == nil {
if isDataVolumeCrd(crd) {
return true
}
}
}
return false
}
func parseNodeSelectors(str string) (map[string]string, error) {
nodeSelectors := make(map[string]string)
for _, s := range strings.Split(strings.TrimSpace(str), "\n") {
v := strings.Split(s, "=")
if len(v) != 2 {
return nil, fmt.Errorf("Invalid node selector: %s", s)
}
nodeSelectors[v[0]] = v[1]
}
return nodeSelectors, nil
}
func stringToStringArray(str string) []string {
vals := strings.Split(str, ",")
for i := range vals {
vals[i] = strings.TrimSpace(vals[i])
}
return vals
}