-
Notifications
You must be signed in to change notification settings - Fork 4k
/
clusterapi_controller.go
716 lines (605 loc) · 21.5 KB
/
clusterapi_controller.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
/*
Copyright 2020 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 clusterapi
import (
"context"
"fmt"
"os"
"strings"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/discovery"
"k8s.io/client-go/dynamic"
"k8s.io/client-go/dynamic/dynamicinformer"
"k8s.io/client-go/informers"
kubeinformers "k8s.io/client-go/informers"
kubeclient "k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/cache"
"k8s.io/klog"
"k8s.io/utils/pointer"
)
const (
machineProviderIDIndex = "machineProviderIDIndex"
nodeProviderIDIndex = "nodeProviderIDIndex"
defaultCAPIGroup = "cluster.x-k8s.io"
// CAPIGroupEnvVar contains the environment variable name which allows overriding defaultCAPIGroup.
CAPIGroupEnvVar = "CAPI_GROUP"
resourceNameMachine = "machines"
resourceNameMachineSet = "machinesets"
resourceNameMachineDeployment = "machinedeployments"
failedMachinePrefix = "failed-machine-"
)
// machineController watches for Nodes, Machines, MachineSets and
// MachineDeployments as they are added, updated and deleted on the
// cluster. Additionally, it adds indices to the node informers to
// satisfy lookup by node.Spec.ProviderID.
type machineController struct {
kubeInformerFactory kubeinformers.SharedInformerFactory
machineInformerFactory dynamicinformer.DynamicSharedInformerFactory
machineDeploymentInformer informers.GenericInformer
machineInformer informers.GenericInformer
machineSetInformer informers.GenericInformer
nodeInformer cache.SharedIndexInformer
dynamicclient dynamic.Interface
machineSetResource *schema.GroupVersionResource
machineResource *schema.GroupVersionResource
machineDeploymentResource *schema.GroupVersionResource
}
type machineSetFilterFunc func(machineSet *MachineSet) error
func indexMachineByProviderID(obj interface{}) ([]string, error) {
u, ok := obj.(*unstructured.Unstructured)
if !ok {
return nil, nil
}
providerID, found, err := unstructured.NestedString(u.Object, "spec", "providerID")
if err != nil || !found {
return nil, nil
}
if providerID == "" {
return nil, nil
}
return []string{string(normalizedProviderString(providerID))}, nil
}
func indexNodeByProviderID(obj interface{}) ([]string, error) {
if node, ok := obj.(*corev1.Node); ok {
if node.Spec.ProviderID != "" {
return []string{string(normalizedProviderString(node.Spec.ProviderID))}, nil
}
return []string{}, nil
}
return []string{}, nil
}
func (c *machineController) findMachine(id string) (*Machine, error) {
item, exists, err := c.machineInformer.Informer().GetStore().GetByKey(id)
if err != nil {
return nil, err
}
if !exists {
return nil, nil
}
u, ok := item.(*unstructured.Unstructured)
if !ok {
return nil, fmt.Errorf("internal error; unexpected type: %T", item)
}
machine := newMachineFromUnstructured(u.DeepCopy())
if machine == nil {
return nil, nil
}
return machine, nil
}
func (c *machineController) findMachineDeployment(id string) (*MachineDeployment, error) {
item, exists, err := c.machineDeploymentInformer.Informer().GetStore().GetByKey(id)
if err != nil {
return nil, err
}
if !exists {
return nil, nil
}
u, ok := item.(*unstructured.Unstructured)
if !ok {
return nil, fmt.Errorf("internal error; unexpected type: %T", item)
}
machineDeployment := newMachineDeploymentFromUnstructured(u.DeepCopy())
if machineDeployment == nil {
return nil, nil
}
return machineDeployment, nil
}
// findMachineOwner returns the machine set owner for machine, or nil
// if there is no owner. A DeepCopy() of the object is returned on
// success.
func (c *machineController) findMachineOwner(machine *Machine) (*MachineSet, error) {
machineOwnerRef := machineOwnerRef(machine)
if machineOwnerRef == nil {
return nil, nil
}
store := c.machineSetInformer.Informer().GetStore()
item, exists, err := store.GetByKey(fmt.Sprintf("%s/%s", machine.Namespace, machineOwnerRef.Name))
if err != nil {
return nil, err
}
if !exists {
return nil, nil
}
u, ok := item.(*unstructured.Unstructured)
if !ok {
return nil, fmt.Errorf("internal error; unexpected type: %T", item)
}
u = u.DeepCopy()
machineSet := newMachineSetFromUnstructured(u)
if machineSet == nil {
return nil, nil
}
if !machineIsOwnedByMachineSet(machine, machineSet) {
return nil, nil
}
return machineSet, nil
}
// run starts shared informers and waits for the informer cache to
// synchronize.
func (c *machineController) run(stopCh <-chan struct{}) error {
c.kubeInformerFactory.Start(stopCh)
c.machineInformerFactory.Start(stopCh)
syncFuncs := []cache.InformerSynced{
c.nodeInformer.HasSynced,
c.machineInformer.Informer().HasSynced,
c.machineSetInformer.Informer().HasSynced,
}
if c.machineDeploymentResource != nil {
syncFuncs = append(syncFuncs, c.machineDeploymentInformer.Informer().HasSynced)
}
klog.V(4).Infof("waiting for caches to sync")
if !cache.WaitForCacheSync(stopCh, syncFuncs...) {
return fmt.Errorf("syncing caches failed")
}
return nil
}
// findMachineByProviderID finds machine matching providerID. A
// DeepCopy() of the object is returned on success.
func (c *machineController) findMachineByProviderID(providerID normalizedProviderID) (*Machine, error) {
objs, err := c.machineInformer.Informer().GetIndexer().ByIndex(machineProviderIDIndex, string(providerID))
if err != nil {
return nil, err
}
switch n := len(objs); {
case n > 1:
return nil, fmt.Errorf("internal error; expected len==1, got %v", n)
case n == 1:
u, ok := objs[0].(*unstructured.Unstructured)
if !ok {
return nil, fmt.Errorf("internal error; unexpected type %T", objs[0])
}
machine := newMachineFromUnstructured(u.DeepCopy())
if machine != nil {
return machine, nil
}
}
if isFailedMachineProviderID(providerID) {
machine, err := c.findMachine(machineKeyFromFailedProviderID(providerID))
if err != nil {
return nil, err
}
if machine != nil {
return machine.DeepCopy(), nil
}
}
// If the machine object has no providerID--maybe actuator
// does not set this value (e.g., OpenStack)--then first
// lookup the node using ProviderID. If that is successful
// then the machine can be found using the annotation (should
// it exist).
node, err := c.findNodeByProviderID(providerID)
if err != nil {
return nil, err
}
if node == nil {
return nil, nil
}
return c.findMachine(node.Annotations[machineAnnotationKey])
}
func isFailedMachineProviderID(providerID normalizedProviderID) bool {
return strings.HasPrefix(string(providerID), failedMachinePrefix)
}
func machineKeyFromFailedProviderID(providerID normalizedProviderID) string {
namespaceName := strings.TrimPrefix(string(providerID), failedMachinePrefix)
return strings.Replace(namespaceName, "_", "/", 1)
}
// findNodeByNodeName finds the Node object keyed by name.. Returns
// nil if it cannot be found. A DeepCopy() of the object is returned
// on success.
func (c *machineController) findNodeByNodeName(name string) (*corev1.Node, error) {
item, exists, err := c.nodeInformer.GetIndexer().GetByKey(name)
if err != nil {
return nil, err
}
if !exists {
return nil, nil
}
node, ok := item.(*corev1.Node)
if !ok {
return nil, fmt.Errorf("internal error; unexpected type %T", item)
}
return node.DeepCopy(), nil
}
// machinesInMachineSet returns all the machines that belong to
// machineSet. For each machine in the set a DeepCopy() of the object
// is returned.
func (c *machineController) machinesInMachineSet(machineSet *MachineSet) ([]*Machine, error) {
machines, err := c.listMachines(machineSet.Namespace, labels.SelectorFromSet(machineSet.Labels))
if err != nil {
return nil, err
}
if machines == nil {
return nil, nil
}
var result []*Machine
for _, machine := range machines {
if machineIsOwnedByMachineSet(machine, machineSet) {
result = append(result, machine)
}
}
return result, nil
}
// getCAPIGroup returns a string that specifies the group for the API.
// It will return either the value from the
// CAPI_GROUP environment variable, or the default value i.e cluster.x-k8s.io.
func getCAPIGroup() string {
g := os.Getenv(CAPIGroupEnvVar)
if g == "" {
g = defaultCAPIGroup
}
klog.V(4).Infof("Using API Group %q", g)
return g
}
// newMachineController constructs a controller that watches Nodes,
// Machines and MachineSet as they are added, updated and deleted on
// the cluster.
func newMachineController(
dynamicclient dynamic.Interface,
kubeclient kubeclient.Interface,
discoveryclient discovery.DiscoveryInterface,
) (*machineController, error) {
kubeInformerFactory := kubeinformers.NewSharedInformerFactory(kubeclient, 0)
informerFactory := dynamicinformer.NewFilteredDynamicSharedInformerFactory(dynamicclient, 0, metav1.NamespaceAll, nil)
CAPIGroup := getCAPIGroup()
CAPIVersion, err := getAPIGroupPreferredVersion(discoveryclient, CAPIGroup)
if err != nil {
return nil, fmt.Errorf("could not find preferred version for CAPI group %q: %v", CAPIGroup, err)
}
klog.Infof("Using version %q for API group %q", CAPIVersion, CAPIGroup)
var gvrMachineDeployment *schema.GroupVersionResource
var machineDeploymentInformer informers.GenericInformer
machineDeployment, err := groupVersionHasResource(discoveryclient,
fmt.Sprintf("%s/%s", CAPIGroup, CAPIVersion), resourceNameMachineDeployment)
if err != nil {
return nil, fmt.Errorf("failed to validate if resource %q is available for group %q: %v",
resourceNameMachineDeployment, fmt.Sprintf("%s/%s", CAPIGroup, CAPIVersion), err)
}
if machineDeployment {
gvrMachineDeployment = &schema.GroupVersionResource{
Group: CAPIGroup,
Version: CAPIVersion,
Resource: resourceNameMachineDeployment,
}
machineDeploymentInformer = informerFactory.ForResource(*gvrMachineDeployment)
machineDeploymentInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{})
}
gvrMachineSet := &schema.GroupVersionResource{
Group: CAPIGroup,
Version: CAPIVersion,
Resource: resourceNameMachineSet,
}
machineSetInformer := informerFactory.ForResource(*gvrMachineSet)
machineSetInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{})
gvrMachine := &schema.GroupVersionResource{
Group: CAPIGroup,
Version: CAPIVersion,
Resource: resourceNameMachine,
}
machineInformer := informerFactory.ForResource(*gvrMachine)
machineInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{})
nodeInformer := kubeInformerFactory.Core().V1().Nodes().Informer()
nodeInformer.AddEventHandler(cache.ResourceEventHandlerFuncs{})
if err := machineInformer.Informer().GetIndexer().AddIndexers(cache.Indexers{
machineProviderIDIndex: indexMachineByProviderID,
}); err != nil {
return nil, fmt.Errorf("cannot add machine indexer: %v", err)
}
if err := nodeInformer.GetIndexer().AddIndexers(cache.Indexers{
nodeProviderIDIndex: indexNodeByProviderID,
}); err != nil {
return nil, fmt.Errorf("cannot add node indexer: %v", err)
}
return &machineController{
kubeInformerFactory: kubeInformerFactory,
machineInformerFactory: informerFactory,
machineDeploymentInformer: machineDeploymentInformer,
machineInformer: machineInformer,
machineSetInformer: machineSetInformer,
nodeInformer: nodeInformer,
dynamicclient: dynamicclient,
machineSetResource: gvrMachineSet,
machineResource: gvrMachine,
machineDeploymentResource: gvrMachineDeployment,
}, nil
}
func groupVersionHasResource(client discovery.DiscoveryInterface, groupVersion, resourceName string) (bool, error) {
resourceList, err := client.ServerResourcesForGroupVersion(groupVersion)
if err != nil {
return false, fmt.Errorf("failed to get ServerGroups: %v", err)
}
for _, r := range resourceList.APIResources {
klog.Infof("Resource %q available", r.Name)
if r.Name == resourceName {
return true, nil
}
}
return false, nil
}
func getAPIGroupPreferredVersion(client discovery.DiscoveryInterface, APIGroup string) (string, error) {
groupList, err := client.ServerGroups()
if err != nil {
return "", fmt.Errorf("failed to get ServerGroups: %v", err)
}
for _, group := range groupList.Groups {
if group.Name == APIGroup {
return group.PreferredVersion.Version, nil
}
}
return "", fmt.Errorf("failed to find API group %q", APIGroup)
}
func (c *machineController) machineSetProviderIDs(machineSet *MachineSet) ([]string, error) {
machines, err := c.machinesInMachineSet(machineSet)
if err != nil {
return nil, fmt.Errorf("error listing machines: %v", err)
}
var providerIDs []string
for _, machine := range machines {
if machine.Spec.ProviderID == nil || *machine.Spec.ProviderID == "" {
klog.Warningf("Machine %q has no providerID", machine.Name)
}
if machine.Spec.ProviderID != nil && *machine.Spec.ProviderID != "" {
providerIDs = append(providerIDs, *machine.Spec.ProviderID)
continue
}
if machine.Status.FailureMessage != nil {
klog.V(4).Infof("Status.FailureMessage of machine %q is %q", machine.Name, *machine.Status.FailureMessage)
// Provide a fake ID to allow the autoscaler to track machines that will never
// become nodes and mark the nodegroup unhealthy after maxNodeProvisionTime.
// Fake ID needs to be recognised later and converted into a machine key.
// Use an underscore as a separator between namespace and name as it is not a
// valid character within a namespace name.
providerIDs = append(providerIDs, fmt.Sprintf("%s%s_%s", failedMachinePrefix, machine.Namespace, machine.Name))
continue
}
if machine.Status.NodeRef == nil {
klog.V(4).Infof("Status.NodeRef of machine %q is currently nil", machine.Name)
continue
}
if machine.Status.NodeRef.Kind != "Node" {
klog.Errorf("Status.NodeRef of machine %q does not reference a node (rather %q)", machine.Name, machine.Status.NodeRef.Kind)
continue
}
node, err := c.findNodeByNodeName(machine.Status.NodeRef.Name)
if err != nil {
return nil, fmt.Errorf("unknown node %q", machine.Status.NodeRef.Name)
}
if node != nil {
providerIDs = append(providerIDs, node.Spec.ProviderID)
}
}
klog.V(4).Infof("nodegroup %s has nodes %v", machineSet.Name, providerIDs)
return providerIDs, nil
}
func (c *machineController) filterAllMachineSets(f machineSetFilterFunc) error {
return c.filterMachineSets(metav1.NamespaceAll, f)
}
func (c *machineController) filterMachineSets(namespace string, f machineSetFilterFunc) error {
machineSets, err := c.listMachineSets(namespace, labels.Everything())
if err != nil {
return nil
}
for _, machineSet := range machineSets {
if err := f(machineSet); err != nil {
return err
}
}
return nil
}
func (c *machineController) machineSetNodeGroups() ([]*nodegroup, error) {
var nodegroups []*nodegroup
if err := c.filterAllMachineSets(func(machineSet *MachineSet) error {
if machineSetHasMachineDeploymentOwnerRef(machineSet) {
return nil
}
ng, err := newNodegroupFromMachineSet(c, machineSet)
if err != nil {
return err
}
if ng.MaxSize()-ng.MinSize() > 0 && pointer.Int32PtrDerefOr(machineSet.Spec.Replicas, 0) > 0 {
nodegroups = append(nodegroups, ng)
}
return nil
}); err != nil {
return nil, err
}
return nodegroups, nil
}
func (c *machineController) machineDeploymentNodeGroups() ([]*nodegroup, error) {
machineDeployments, err := c.listMachineDeployments(metav1.NamespaceAll, labels.Everything())
if err != nil {
return nil, err
}
var nodegroups []*nodegroup
for _, md := range machineDeployments {
ng, err := newNodegroupFromMachineDeployment(c, md)
if err != nil {
return nil, err
}
// add nodegroup iff it has the capacity to scale
if ng.MaxSize()-ng.MinSize() > 0 && pointer.Int32PtrDerefOr(md.Spec.Replicas, 0) > 0 {
nodegroups = append(nodegroups, ng)
}
}
return nodegroups, nil
}
func (c *machineController) nodeGroups() ([]*nodegroup, error) {
machineSets, err := c.machineSetNodeGroups()
if err != nil {
return nil, err
}
if c.machineDeploymentResource != nil {
machineDeployments, err := c.machineDeploymentNodeGroups()
if err != nil {
return nil, err
}
machineSets = append(machineSets, machineDeployments...)
}
return machineSets, nil
}
func (c *machineController) nodeGroupForNode(node *corev1.Node) (*nodegroup, error) {
machine, err := c.findMachineByProviderID(normalizedProviderString(node.Spec.ProviderID))
if err != nil {
return nil, err
}
if machine == nil {
return nil, nil
}
machineSet, err := c.findMachineOwner(machine)
if err != nil {
return nil, err
}
if machineSet == nil {
return nil, nil
}
if c.machineDeploymentResource != nil {
if ref := machineSetMachineDeploymentRef(machineSet); ref != nil {
key := fmt.Sprintf("%s/%s", machineSet.Namespace, ref.Name)
machineDeployment, err := c.findMachineDeployment(key)
if err != nil {
return nil, fmt.Errorf("unknown MachineDeployment %q: %v", key, err)
}
if machineDeployment == nil {
return nil, fmt.Errorf("unknown MachineDeployment %q", key)
}
nodegroup, err := newNodegroupFromMachineDeployment(c, machineDeployment)
if err != nil {
return nil, fmt.Errorf("failed to build nodegroup for node %q: %v", node.Name, err)
}
// We don't scale from 0 so nodes must belong
// to a nodegroup that has a scale size of at
// least 1.
if nodegroup.MaxSize()-nodegroup.MinSize() < 1 {
return nil, nil
}
return nodegroup, nil
}
}
nodegroup, err := newNodegroupFromMachineSet(c, machineSet)
if err != nil {
return nil, fmt.Errorf("failed to build nodegroup for node %q: %v", node.Name, err)
}
// We don't scale from 0 so nodes must belong to a nodegroup
// that has a scale size of at least 1.
if nodegroup.MaxSize()-nodegroup.MinSize() < 1 {
return nil, nil
}
klog.V(4).Infof("node %q is in nodegroup %q", node.Name, machineSet.Name)
return nodegroup, nil
}
// findNodeByProviderID find the Node object keyed by provideID.
// Returns nil if it cannot be found. A DeepCopy() of the object is
// returned on success.
func (c *machineController) findNodeByProviderID(providerID normalizedProviderID) (*corev1.Node, error) {
objs, err := c.nodeInformer.GetIndexer().ByIndex(nodeProviderIDIndex, string(providerID))
if err != nil {
return nil, err
}
switch n := len(objs); {
case n == 0:
return nil, nil
case n > 1:
return nil, fmt.Errorf("internal error; expected len==1, got %v", n)
}
node, ok := objs[0].(*corev1.Node)
if !ok {
return nil, fmt.Errorf("internal error; unexpected type %T", objs[0])
}
return node.DeepCopy(), nil
}
func (c *machineController) getMachine(namespace, name string, options metav1.GetOptions) (*Machine, error) {
u, err := c.dynamicclient.Resource(*c.machineResource).Namespace(namespace).Get(context.TODO(), name, options)
if err != nil {
return nil, err
}
return newMachineFromUnstructured(u.DeepCopy()), nil
}
func (c *machineController) getMachineSet(namespace, name string, options metav1.GetOptions) (*MachineSet, error) {
u, err := c.dynamicclient.Resource(*c.machineSetResource).Namespace(namespace).Get(context.TODO(), name, options)
if err != nil {
return nil, err
}
return newMachineSetFromUnstructured(u.DeepCopy()), nil
}
func (c *machineController) getMachineDeployment(namespace, name string, options metav1.GetOptions) (*MachineDeployment, error) {
u, err := c.dynamicclient.Resource(*c.machineDeploymentResource).Namespace(namespace).Get(context.TODO(), name, options)
if err != nil {
return nil, err
}
return newMachineDeploymentFromUnstructured(u.DeepCopy()), nil
}
func (c *machineController) listMachines(namespace string, selector labels.Selector) ([]*Machine, error) {
objs, err := c.machineInformer.Lister().ByNamespace(namespace).List(selector)
if err != nil {
return nil, err
}
var machines []*Machine
for _, x := range objs {
u := x.(*unstructured.Unstructured).DeepCopy()
if machine := newMachineFromUnstructured(u); machine != nil {
machines = append(machines, machine)
}
}
return machines, nil
}
func (c *machineController) listMachineSets(namespace string, selector labels.Selector) ([]*MachineSet, error) {
objs, err := c.machineSetInformer.Lister().ByNamespace(namespace).List(selector)
if err != nil {
return nil, err
}
var machineSets []*MachineSet
for _, x := range objs {
u := x.(*unstructured.Unstructured).DeepCopy()
if machineSet := newMachineSetFromUnstructured(u); machineSet != nil {
machineSets = append(machineSets, machineSet)
}
}
return machineSets, nil
}
func (c *machineController) listMachineDeployments(namespace string, selector labels.Selector) ([]*MachineDeployment, error) {
objs, err := c.machineDeploymentInformer.Lister().ByNamespace(namespace).List(selector)
if err != nil {
return nil, err
}
var machineDeployments []*MachineDeployment
for _, x := range objs {
u := x.(*unstructured.Unstructured).DeepCopy()
if machineDeployment := newMachineDeploymentFromUnstructured(u); machineDeployment != nil {
machineDeployments = append(machineDeployments, machineDeployment)
}
}
return machineDeployments, nil
}