/
get.go
56 lines (47 loc) · 1.13 KB
/
get.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
package label
import (
"context"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/eks"
"github.com/weaveworks/eksctl/pkg/cfn/manager"
)
type Summary struct {
Cluster string
NodeGroup string
Labels map[string]string
}
func (m *Manager) Get(ctx context.Context, nodeGroupName string) ([]Summary, error) {
var (
labels map[string]string
err error
)
labels, err = m.service.GetLabels(ctx, nodeGroupName)
if err != nil {
switch {
case manager.IsStackDoesNotExistError(err):
labels, err = m.getLabelsFromUnownedNodeGroup(ctx, nodeGroupName)
if err != nil {
return nil, err
}
default:
return nil, err
}
}
return []Summary{
{
Cluster: m.clusterName,
NodeGroup: nodeGroupName,
Labels: labels,
},
}, nil
}
func (m *Manager) getLabelsFromUnownedNodeGroup(ctx context.Context, nodeGroupName string) (map[string]string, error) {
out, err := m.eksAPI.DescribeNodegroup(ctx, &eks.DescribeNodegroupInput{
ClusterName: aws.String(m.clusterName),
NodegroupName: aws.String(nodeGroupName),
})
if err != nil {
return nil, err
}
return out.Nodegroup.Labels, nil
}