-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
addon_helper.go
39 lines (33 loc) · 1.09 KB
/
addon_helper.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
package addon
import (
"context"
"fmt"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/eks"
api "github.com/weaveworks/eksctl/pkg/apis/eksctl.io/v1alpha5"
)
// Helper is a helper for validating nodegroup creation.
type Helper struct {
// ClusterName holds the cluster name.
ClusterName string
// Lister lists addons.
Lister Lister
}
// A Lister lists addons.
type Lister interface {
ListAddons(ctx context.Context, params *eks.ListAddonsInput, optFns ...func(*eks.Options)) (*eks.ListAddonsOutput, error)
}
// ValidateNodeGroupCreation validates whether the cluster has core networking addons.
func (a *Helper) ValidateNodeGroupCreation(ctx context.Context) error {
output, err := a.Lister.ListAddons(ctx, &eks.ListAddonsInput{
ClusterName: aws.String(a.ClusterName),
})
if err != nil {
return fmt.Errorf("listing addons: %w", err)
}
if !api.HasAllDefaultAddons(output.Addons) {
return fmt.Errorf("core networking addons which are required to create nodegroups are missing in the cluster; " +
"please create them using `eksctl create addon`")
}
return nil
}