-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
nodegroup.go
63 lines (54 loc) · 1.87 KB
/
nodegroup.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
package cmdutils
import (
"context"
"github.com/aws/aws-sdk-go-v2/service/eks"
"github.com/kris-nova/logger"
api "github.com/weaveworks/eksctl/pkg/apis/eksctl.io/v1alpha5"
"github.com/weaveworks/eksctl/pkg/cfn/manager"
)
func PopulateNodegroup(ctx context.Context, stackManager manager.StackManager, name string, cfg *api.ClusterConfig, ctl api.ClusterProvider) error {
nodeGroupType, err := stackManager.GetNodeGroupStackType(ctx, manager.GetNodegroupOption{
NodeGroupName: name,
})
if err != nil {
logger.Debug("failed to fetch nodegroup %q stack: %v", name, err)
_, err := ctl.EKS().DescribeNodegroup(ctx, &eks.DescribeNodegroupInput{
ClusterName: &cfg.Metadata.Name,
NodegroupName: &name,
})
if err != nil {
return err
}
nodeGroupType = api.NodeGroupTypeUnowned
}
return PopulateNodegroupFromStack(nodeGroupType, name, cfg)
}
// PopulateNodegroupFromStack populates the nodegroup field of an api.ClusterConfig by type from its CF stack.
func PopulateNodegroupFromStack(nodeGroupType api.NodeGroupType, nodeGroupName string, cfg *api.ClusterConfig) error {
switch nodeGroupType {
case api.NodeGroupTypeUnmanaged:
PopulateUnmanagedNodegroup(nodeGroupName, cfg)
case api.NodeGroupTypeManaged:
cfg.ManagedNodeGroups = append(cfg.ManagedNodeGroups, &api.ManagedNodeGroup{
NodeGroupBase: &api.NodeGroupBase{
Name: nodeGroupName,
},
})
case api.NodeGroupTypeUnowned:
cfg.ManagedNodeGroups = append(cfg.ManagedNodeGroups, &api.ManagedNodeGroup{
NodeGroupBase: &api.NodeGroupBase{
Name: nodeGroupName,
},
Unowned: true,
})
}
return nil
}
// PopulateUnmanagedNodegroup populates the unmanaged nodegroup field of a ClusterConfig.
func PopulateUnmanagedNodegroup(nodeGroupName string, cfg *api.ClusterConfig) {
cfg.NodeGroups = append(cfg.NodeGroups, &api.NodeGroup{
NodeGroupBase: &api.NodeGroupBase{
Name: nodeGroupName,
},
})
}