From d463324c45b98fa1786cd40dd5df6c6259469edd Mon Sep 17 00:00:00 2001 From: Ilya Dmitrichenko Date: Thu, 31 May 2018 15:31:41 +0100 Subject: [PATCH] More sensible naming of types --- cmd/eksctl/create.go | 6 +- cmd/eksctl/delete.go | 4 +- cmd/eksctl/get.go | 4 +- pkg/eks/api.go | 153 +++++++++++++++++++++++++++++++++++++ pkg/eks/auth.go | 20 ++--- pkg/eks/cfn.go | 176 +++++-------------------------------------- pkg/eks/eks.go | 24 +++--- pkg/eks/nodegroup.go | 6 +- 8 files changed, 205 insertions(+), 188 deletions(-) create mode 100644 pkg/eks/api.go diff --git a/cmd/eksctl/create.go b/cmd/eksctl/create.go index b7be0c7965..c2b4fe6139 100644 --- a/cmd/eksctl/create.go +++ b/cmd/eksctl/create.go @@ -41,7 +41,7 @@ var ( ) func createClusterCmd() *cobra.Command { - cfg := &eks.Config{} + cfg := &eks.ClusterConfig{} cmd := &cobra.Command{ Use: "cluster", @@ -73,7 +73,7 @@ func createClusterCmd() *cobra.Command { return cmd } -func doCreateCluster(cfg *eks.Config) error { +func doCreateCluster(cfg *eks.ClusterConfig) error { ctl := eks.New(cfg) if err := ctl.CheckAuth(); err != nil { @@ -99,7 +99,7 @@ func doCreateCluster(cfg *eks.Config) error { { // core action taskErr := make(chan error) // create each of the core cloudformation stacks - ctl.CreateAllStacks(taskErr) + ctl.CreateCluster(taskErr) // read any errors (it only gets non-nil errors) for err := range taskErr { return err diff --git a/cmd/eksctl/delete.go b/cmd/eksctl/delete.go index fb581bad1c..129b08c4a3 100644 --- a/cmd/eksctl/delete.go +++ b/cmd/eksctl/delete.go @@ -25,7 +25,7 @@ func deleteCmd() *cobra.Command { } func deleteClusterCmd() *cobra.Command { - cfg := &eks.Config{} + cfg := &eks.ClusterConfig{} cmd := &cobra.Command{ Use: "cluster", @@ -45,7 +45,7 @@ func deleteClusterCmd() *cobra.Command { return cmd } -func doDeleteCluster(cfg *eks.Config) error { +func doDeleteCluster(cfg *eks.ClusterConfig) error { ctl := eks.New(cfg) if err := ctl.CheckAuth(); err != nil { diff --git a/cmd/eksctl/get.go b/cmd/eksctl/get.go index 0637c6add3..d6a58cd0dd 100644 --- a/cmd/eksctl/get.go +++ b/cmd/eksctl/get.go @@ -24,7 +24,7 @@ func getCmd() *cobra.Command { } func getClusterCmd() *cobra.Command { - cfg := &eks.Config{} + cfg := &eks.ClusterConfig{} cmd := &cobra.Command{ Use: "cluster", @@ -45,7 +45,7 @@ func getClusterCmd() *cobra.Command { return cmd } -func doGetCluster(cfg *eks.Config) error { +func doGetCluster(cfg *eks.ClusterConfig) error { ctl := eks.New(cfg) if err := ctl.CheckAuth(); err != nil { diff --git a/pkg/eks/api.go b/pkg/eks/api.go new file mode 100644 index 0000000000..fb50970a48 --- /dev/null +++ b/pkg/eks/api.go @@ -0,0 +1,153 @@ +package eks + +import ( + "os" + "sync" + + "github.com/pkg/errors" + + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/aws/session" + "github.com/aws/aws-sdk-go/service/cloudformation" + "github.com/aws/aws-sdk-go/service/ec2" + "github.com/aws/aws-sdk-go/service/eks" + "github.com/aws/aws-sdk-go/service/sts" + + "github.com/kubicorn/kubicorn/pkg/logger" +) + +const ClusterNameTag = "eksctl.cluster.k8s.io/v1alpha1/cluster-name" + +type ClusterProvider struct { + cfg *ClusterConfig + svc *providerServices +} + +type providerServices struct { + cfn *cloudformation.CloudFormation + eks *eks.EKS + ec2 *ec2.EC2 + sts *sts.STS + arn string +} + +// simple config, to be replaced with Cluster API +type ClusterConfig struct { + Region string + ClusterName string + NodeAMI string + NodeType string + Nodes int + MinNodes int + MaxNodes int + + SSHPublicKeyPath string + SSHPublicKey []byte + + keyName string + clusterRoleARN string + securityGroup string + subnetsList string + clusterVPC string + + nodeInstanceRoleARN string + + MasterEndpoint string + CertificateAuthorityData []byte +} + +func New(clusterConfig *ClusterConfig) *ClusterProvider { + // we might want to use bits from kops, although right now it seems like too many thing we + // don't want yet + // https://github.com/kubernetes/kops/blob/master/upup/pkg/fi/cloudup/awsup/aws_cloud.go#L179 + config := aws.NewConfig() + config = config.WithRegion(clusterConfig.Region) + config = config.WithCredentialsChainVerboseErrors(true) + + s := session.Must(session.NewSession(config)) + + cfn := &ClusterProvider{ + cfg: clusterConfig, + svc: &providerServices{ + cfn: cloudformation.New(s), + eks: eks.New(s), + ec2: ec2.New(s), + sts: sts.New(s), + }, + } + + // override sessions if any custom endpoints specified + if endpoint, ok := os.LookupEnv("AWS_CLOUDFORMATION_ENDPOINT"); ok { + s := session.Must(session.NewSession(config.WithEndpoint(endpoint))) + cfn.svc.cfn = cloudformation.New(s) + } + if endpoint, ok := os.LookupEnv("AWS_EKS_ENDPOINT"); ok { + s := session.Must(session.NewSession(config.WithEndpoint(endpoint))) + cfn.svc.eks = eks.New(s) + } + if endpoint, ok := os.LookupEnv("AWS_EC2_ENDPOINT"); ok { + s := session.Must(session.NewSession(config.WithEndpoint(endpoint))) + cfn.svc.ec2 = ec2.New(s) + } + if endpoint, ok := os.LookupEnv("AWS_STS_ENDPOINT"); ok { + s := session.Must(session.NewSession(config.WithEndpoint(endpoint))) + cfn.svc.sts = sts.New(s) + } + + return cfn +} + +func (c *ClusterProvider) CheckAuth() error { + { + input := &sts.GetCallerIdentityInput{} + output, err := c.svc.sts.GetCallerIdentity(input) + if err != nil { + return errors.Wrap(err, "checking AWS STS access – cannot get role ARN for current session") + } + c.svc.arn = *output.Arn + logger.Debug("role ARN for the current session is %q", c.svc.arn) + } + { + input := &cloudformation.ListStacksInput{} + if _, err := c.svc.cfn.ListStacks(input); err != nil { + return errors.Wrap(err, "checking AWS CloudFormation access – cannot list stacks") + } + } + return nil +} + +func (c *ClusterProvider) runCreateTask(tasks map[string]func(chan error) error, taskErrs chan error) { + wg := &sync.WaitGroup{} + wg.Add(len(tasks)) + for taskName := range tasks { + task := tasks[taskName] + go func(tn string) { + defer wg.Done() + logger.Debug("task %q started", tn) + errs := make(chan error) + if err := task(errs); err != nil { + taskErrs <- err + return + } + if err := <-errs; err != nil { + taskErrs <- err + return + } + logger.Debug("task %q returned without errors", tn) + }(taskName) + } + logger.Debug("waiting for %d tasks to complete", len(tasks)) + wg.Wait() +} + +func (c *ClusterProvider) CreateCluster(taskErrs chan error) { + c.runCreateTask(map[string]func(chan error) error{ + "createStackServiceRole": func(errs chan error) error { return c.createStackServiceRole(errs) }, + "createStackVPC": func(errs chan error) error { return c.createStackVPC(errs) }, + }, taskErrs) + c.runCreateTask(map[string]func(chan error) error{ + "createControlPlane": func(errs chan error) error { return c.createControlPlane(errs) }, + "createStackDefaultNodeGroup": func(errs chan error) error { return c.createStackDefaultNodeGroup(errs) }, + }, taskErrs) + close(taskErrs) +} diff --git a/pkg/eks/auth.go b/pkg/eks/auth.go index 4ff4dba44d..ef1d835a8b 100644 --- a/pkg/eks/auth.go +++ b/pkg/eks/auth.go @@ -22,7 +22,7 @@ import ( "k8s.io/kops/upup/pkg/fi/utils" ) -func (c *CloudFormation) LoadSSHPublicKey() error { +func (c *ClusterProvider) LoadSSHPublicKey() error { c.cfg.SSHPublicKeyPath = utils.ExpandPath(c.cfg.SSHPublicKeyPath) sshPublicKey, err := ioutil.ReadFile(c.cfg.SSHPublicKeyPath) if err != nil { @@ -32,7 +32,7 @@ func (c *CloudFormation) LoadSSHPublicKey() error { input := &ec2.DescribeKeyPairsInput{ KeyNames: aws.StringSlice([]string{c.cfg.SSHPublicKeyPath}), } - output, err := c.ec2.DescribeKeyPairs(input) + output, err := c.svc.ec2.DescribeKeyPairs(input) if err != nil { return errors.Wrap(err, "cannot find EC2 key pair") } @@ -54,35 +54,35 @@ func (c *CloudFormation) LoadSSHPublicKey() error { PublicKeyMaterial: c.cfg.SSHPublicKey, } logger.Info("importing SSH public key %q as %q", c.cfg.SSHPublicKeyPath, c.cfg.keyName) - if _, err := c.ec2.ImportKeyPair(input); err != nil { + if _, err := c.svc.ec2.ImportKeyPair(input); err != nil { return errors.Wrap(err, "importing SSH public key") } } return nil } -func (c *CloudFormation) MaybeDeletePublicSSHKey() { +func (c *ClusterProvider) MaybeDeletePublicSSHKey() { input := &ec2.DeleteKeyPairInput{ KeyName: aws.String("EKS-" + c.cfg.ClusterName), } - c.ec2.DeleteKeyPair(input) + c.svc.ec2.DeleteKeyPair(input) } -func (c *CloudFormation) getUsername() string { - usernameParts := strings.Split(c.arn, "/") +func (c *ClusterProvider) getUsername() string { + usernameParts := strings.Split(c.svc.arn, "/") username := usernameParts[len(usernameParts)-1] return username } type ClientConfig struct { Client *clientcmdapi.Config - Cluster *Config + Cluster *ClusterConfig roleARN string } // based on "k8s.io/kubernetes/cmd/kubeadm/app/util/kubeconfig" // these are small, so we can copy these, and no need to deal with k/k as dependency -func (c *CloudFormation) NewClientConfig() (*ClientConfig, error) { +func (c *ClusterProvider) NewClientConfig() (*ClientConfig, error) { clusterName := fmt.Sprintf("%s.%s.eksctl.io", c.cfg.ClusterName, c.cfg.Region) contextName := fmt.Sprintf("%s@%s", c.getUsername(), clusterName) @@ -106,7 +106,7 @@ func (c *CloudFormation) NewClientConfig() (*ClientConfig, error) { }, CurrentContext: contextName, }, - roleARN: c.arn, + roleARN: c.svc.arn, } return clientConfig, nil diff --git a/pkg/eks/cfn.go b/pkg/eks/cfn.go index 71618fcb55..e8914057a7 100644 --- a/pkg/eks/cfn.go +++ b/pkg/eks/cfn.go @@ -2,121 +2,22 @@ package eks import ( "fmt" - "os" "regexp" - "sync" "time" "github.com/pkg/errors" "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/cloudformation" - "github.com/aws/aws-sdk-go/service/ec2" - "github.com/aws/aws-sdk-go/service/eks" - "github.com/aws/aws-sdk-go/service/sts" "github.com/kubicorn/kubicorn/pkg/logger" ) //go:generate go-bindata -pkg $GOPACKAGE -prefix assets/1.10.0/2018-05-09 -o cfn_templates.go assets/1.10.0/2018-05-09 -const ClusterNameTag = "eksctl.cluster.k8s.io/v1alpha1/cluster-name" - -type CloudFormation struct { - cfg *Config - svc *cloudformation.CloudFormation - eks *eks.EKS - ec2 *ec2.EC2 - sts *sts.STS - arn string -} - -// simple config, to be replaced with Cluster API -type Config struct { - Region string - ClusterName string - NodeAMI string - NodeType string - Nodes int - MinNodes int - MaxNodes int - - SSHPublicKeyPath string - SSHPublicKey []byte - - keyName string - clusterRoleARN string - securityGroup string - subnetsList string - clusterVPC string - - nodeInstanceRoleARN string - - MasterEndpoint string - CertificateAuthorityData []byte -} type Stack = cloudformation.Stack -func New(clusterConfig *Config) *CloudFormation { - // we might want to use bits from kops, although right now it seems like too many thing we - // don't want yet - // https://github.com/kubernetes/kops/blob/master/upup/pkg/fi/cloudup/awsup/aws_cloud.go#L179 - config := aws.NewConfig() - config = config.WithRegion(clusterConfig.Region) - config = config.WithCredentialsChainVerboseErrors(true) - - s := session.Must(session.NewSession(config)) - - cfn := &CloudFormation{ - cfg: clusterConfig, - svc: cloudformation.New(s), - eks: eks.New(s), - ec2: ec2.New(s), - sts: sts.New(s), - } - - // override sessions if any custom endpoints specified - if endpoint, ok := os.LookupEnv("AWS_CLOUDFORMATION_ENDPOINT"); ok { - s := session.Must(session.NewSession(config.WithEndpoint(endpoint))) - cfn.svc = cloudformation.New(s) - } - if endpoint, ok := os.LookupEnv("AWS_EKS_ENDPOINT"); ok { - s := session.Must(session.NewSession(config.WithEndpoint(endpoint))) - cfn.eks = eks.New(s) - } - if endpoint, ok := os.LookupEnv("AWS_EC2_ENDPOINT"); ok { - s := session.Must(session.NewSession(config.WithEndpoint(endpoint))) - cfn.ec2 = ec2.New(s) - } - if endpoint, ok := os.LookupEnv("AWS_STS_ENDPOINT"); ok { - s := session.Must(session.NewSession(config.WithEndpoint(endpoint))) - cfn.sts = sts.New(s) - } - - return cfn -} - -func (c *CloudFormation) CheckAuth() error { - { - input := &sts.GetCallerIdentityInput{} - output, err := c.sts.GetCallerIdentity(input) - if err != nil { - return errors.Wrap(err, "checking AWS STS access – cannot get role ARN for current session") - } - c.arn = *output.Arn - logger.Debug("role ARN for the current session is %q", c.arn) - } - { - input := &cloudformation.ListStacksInput{} - if _, err := c.svc.ListStacks(input); err != nil { - return errors.Wrap(err, "checking AWS CloudFormation access – cannot list stacks") - } - } - return nil -} - -func (c *CloudFormation) CreateStack(name string, templateBody []byte, parameters map[string]string, withIAM bool, stack chan Stack, errs chan error) error { +func (c *ClusterProvider) CreateStack(name string, templateBody []byte, parameters map[string]string, withIAM bool, stack chan Stack, errs chan error) error { input := &cloudformation.CreateStackInput{} input.SetStackName(name) input.SetTags([]*cloudformation.Tag{ @@ -139,7 +40,7 @@ func (c *CloudFormation) CreateStack(name string, templateBody []byte, parameter // TODO(p1): looks like we can block on this forever, if parameters are invalid logger.Debug("input = %#v", input) - s, err := c.svc.CreateStack(input) + s, err := c.svc.cfn.CreateStack(input) if err != nil { return errors.Wrap(err, fmt.Sprintf("creating CloudFormation stack %q", name)) } @@ -195,21 +96,20 @@ func (c *CloudFormation) CreateStack(name string, templateBody []byte, parameter }() return nil - } -func (c *CloudFormation) describeStack(name *string) (*Stack, error) { +func (c *ClusterProvider) describeStack(name *string) (*Stack, error) { input := &cloudformation.DescribeStacksInput{ StackName: name, } - resp, err := c.svc.DescribeStacks(input) + resp, err := c.svc.cfn.DescribeStacks(input) if err != nil { return nil, errors.Wrap(err, fmt.Sprintf("describing CloudFormation stack %q", *name)) } return resp.Stacks[0], nil } -func (c *CloudFormation) ListReadyStacks(nameRegex string) ([]*Stack, error) { +func (c *ClusterProvider) ListReadyStacks(nameRegex string) ([]*Stack, error) { var ( subErr error stack *Stack @@ -233,7 +133,7 @@ func (c *CloudFormation) ListReadyStacks(nameRegex string) ([]*Stack, error) { } return true } - if err := c.svc.ListStacksPages(input, pager); err != nil { + if err := c.svc.cfn.ListStacksPages(input, pager); err != nil { return nil, err } if subErr != nil { @@ -242,53 +142,17 @@ func (c *CloudFormation) ListReadyStacks(nameRegex string) ([]*Stack, error) { return stacks, nil } -func (c *CloudFormation) CreateStacks(tasks map[string]func(chan error) error, taskErrs chan error) { - wg := &sync.WaitGroup{} - wg.Add(len(tasks)) - for taskName := range tasks { - task := tasks[taskName] - go func(tn string) { - defer wg.Done() - logger.Debug("task %q started", tn) - errs := make(chan error) - if err := task(errs); err != nil { - taskErrs <- err - return - } - if err := <-errs; err != nil { - taskErrs <- err - return - } - logger.Debug("task %q returned without errors", tn) - }(taskName) - } - logger.Debug("waiting for %d tasks to complete", len(tasks)) - wg.Wait() -} - -func (c *CloudFormation) CreateAllStacks(taskErrs chan error) { - c.CreateStacks(map[string]func(chan error) error{ - "createStackServiceRole": func(errs chan error) error { return c.createStackServiceRole(errs) }, - "createStackVPC": func(errs chan error) error { return c.createStackVPC(errs) }, - }, taskErrs) - c.CreateStacks(map[string]func(chan error) error{ - "createControlPlane": func(errs chan error) error { return c.createControlPlane(errs) }, - "createStackDefaultNodeGroup": func(errs chan error) error { return c.createStackDefaultNodeGroup(errs) }, - }, taskErrs) - close(taskErrs) -} - -func (c *CloudFormation) stackNameVPC() string { +func (c *ClusterProvider) stackNameVPC() string { return "EKS-" + c.cfg.ClusterName + "-VPC" } -func (c *CloudFormation) stackParamsVPC() map[string]string { +func (c *ClusterProvider) stackParamsVPC() map[string]string { return map[string]string{ "ClusterName": c.cfg.ClusterName, } } -func (c *CloudFormation) createStackVPC(errs chan error) error { +func (c *ClusterProvider) createStackVPC(errs chan error) error { name := c.stackNameVPC() logger.Info("creating VPC stack %q", name) templateBody, err := amazonEksVpcSampleYamlBytes() @@ -345,7 +209,7 @@ func (c *CloudFormation) createStackVPC(errs chan error) error { return nil } -func (c *CloudFormation) DeleteStackVPC() error { +func (c *ClusterProvider) DeleteStackVPC() error { name := c.stackNameVPC() s, err := c.describeStack(&name) if err != nil { @@ -356,17 +220,17 @@ func (c *CloudFormation) DeleteStackVPC() error { StackName: s.StackName, } - if _, err := c.svc.DeleteStack(input); err != nil { + if _, err := c.svc.cfn.DeleteStack(input); err != nil { return errors.Wrap(err, "not able to delete VPC stack") } return nil } -func (c *CloudFormation) stackNameServiceRole() string { +func (c *ClusterProvider) stackNameServiceRole() string { return "EKS-" + c.cfg.ClusterName + "-ServiceRole" } -func (c *CloudFormation) createStackServiceRole(errs chan error) error { +func (c *ClusterProvider) createStackServiceRole(errs chan error) error { name := c.stackNameServiceRole() logger.Info("creating ServiceRole stack %q", name) templateBody, err := amazonEksServiceRoleYamlBytes() @@ -409,7 +273,7 @@ func (c *CloudFormation) createStackServiceRole(errs chan error) error { return nil } -func (c *CloudFormation) DeleteStackServiceRole() error { +func (c *ClusterProvider) DeleteStackServiceRole() error { name := c.stackNameServiceRole() s, err := c.describeStack(&name) if err != nil { @@ -420,17 +284,17 @@ func (c *CloudFormation) DeleteStackServiceRole() error { StackName: s.StackName, } - if _, err := c.svc.DeleteStack(input); err != nil { + if _, err := c.svc.cfn.DeleteStack(input); err != nil { return errors.Wrap(err, "not able to delete ServiceRole stack") } return nil } -func (c *CloudFormation) stackNameDefaultNodeGroup() string { +func (c *ClusterProvider) stackNameDefaultNodeGroup() string { return "EKS-" + c.cfg.ClusterName + "-DefaultNodeGroup" } -func (c *CloudFormation) stackParamsDefaultNodeGroup() map[string]string { +func (c *ClusterProvider) stackParamsDefaultNodeGroup() map[string]string { regionalAMIs := map[string]string{ "us-west-2": "ami-993141e1", } @@ -458,7 +322,7 @@ func (c *CloudFormation) stackParamsDefaultNodeGroup() map[string]string { } } -func (c *CloudFormation) createStackDefaultNodeGroup(errs chan error) error { +func (c *ClusterProvider) createStackDefaultNodeGroup(errs chan error) error { name := c.stackNameDefaultNodeGroup() logger.Info("creating DefaultNodeGroup stack %q", name) templateBody, err := amazonEksNodegroupYamlBytes() @@ -502,7 +366,7 @@ func (c *CloudFormation) createStackDefaultNodeGroup(errs chan error) error { return nil } -func (c *CloudFormation) DeleteStackDefaultNodeGroup() error { +func (c *ClusterProvider) DeleteStackDefaultNodeGroup() error { name := c.stackNameDefaultNodeGroup() s, err := c.describeStack(&name) if err != nil { @@ -513,7 +377,7 @@ func (c *CloudFormation) DeleteStackDefaultNodeGroup() error { StackName: s.StackName, } - if _, err := c.svc.DeleteStack(input); err != nil { + if _, err := c.svc.cfn.DeleteStack(input); err != nil { return errors.Wrap(err, "not able to delete DefaultNodeGroup stack") } return nil diff --git a/pkg/eks/eks.go b/pkg/eks/eks.go index cf92fbe22c..b64d35aa16 100644 --- a/pkg/eks/eks.go +++ b/pkg/eks/eks.go @@ -13,7 +13,7 @@ import ( "github.com/kubicorn/kubicorn/pkg/logger" ) -func (c *CloudFormation) CreateControlPlane() error { +func (c *ClusterProvider) CreateControlPlane() error { input := &eks.CreateClusterInput{ ClusterName: &c.cfg.ClusterName, RoleArn: &c.cfg.clusterRoleARN, @@ -21,7 +21,7 @@ func (c *CloudFormation) CreateControlPlane() error { SecurityGroups: aws.StringSlice([]string{c.cfg.securityGroup}), // TODO(p1): find out why there are not tags } - output, err := c.eks.CreateCluster(input) + output, err := c.svc.eks.CreateCluster(input) if err != nil { return errors.Wrap(err, "unable to create cluster control plane") } @@ -29,18 +29,18 @@ func (c *CloudFormation) CreateControlPlane() error { return nil } -func (c *CloudFormation) DescribeControlPlane() (*eks.Cluster, error) { +func (c *ClusterProvider) DescribeControlPlane() (*eks.Cluster, error) { input := &eks.DescribeClusterInput{ ClusterName: &c.cfg.ClusterName, } - output, err := c.eks.DescribeCluster(input) + output, err := c.svc.eks.DescribeCluster(input) if err != nil { return nil, errors.Wrap(err, "unable to describe cluster control plane") } return output.Cluster, nil } -func (c *CloudFormation) DeleteControlPlane() error { +func (c *ClusterProvider) DeleteControlPlane() error { cluster, err := c.DescribeControlPlane() if err != nil { return errors.Wrap(err, "not able to get control plane for deletion") @@ -50,13 +50,13 @@ func (c *CloudFormation) DeleteControlPlane() error { ClusterName: cluster.ClusterName, } - if _, err := c.eks.DeleteCluster(input); err != nil { + if _, err := c.svc.eks.DeleteCluster(input); err != nil { return errors.Wrap(err, "unable to delete cluster control plane") } return nil } -func (c *CloudFormation) createControlPlane(errs chan error) error { +func (c *ClusterProvider) createControlPlane(errs chan error) error { logger.Info("creating control plane %q", c.cfg.ClusterName) clusterChan := make(chan eks.Cluster) @@ -119,7 +119,7 @@ func (c *CloudFormation) createControlPlane(errs chan error) error { return nil } -func (c *CloudFormation) ListClusters() error { +func (c *ClusterProvider) ListClusters() error { if c.cfg.ClusterName != "" { return c.doListCluster(&c.cfg.ClusterName) } @@ -127,7 +127,7 @@ func (c *CloudFormation) ListClusters() error { // TODO(p1): collect results into a data structure (or at least a nicely formatted string) // TODO(p2): paging input := &eks.ListClustersInput{} - output, err := c.eks.ListClusters(input) + output, err := c.svc.eks.ListClusters(input) if err != nil { return errors.Wrap(err, "listing control planes") } @@ -139,11 +139,11 @@ func (c *CloudFormation) ListClusters() error { return nil } -func (c *CloudFormation) doListCluster(clusterName *string) error { +func (c *ClusterProvider) doListCluster(clusterName *string) error { input := &eks.DescribeClusterInput{ ClusterName: clusterName, } - output, err := c.eks.DescribeCluster(input) + output, err := c.svc.eks.DescribeCluster(input) if err != nil { return errors.Wrapf(err, "unable to describe control plane %q", *clusterName) } @@ -160,7 +160,7 @@ func (c *CloudFormation) doListCluster(clusterName *string) error { return nil } -func (c *CloudFormation) ListAllTaggedResources() error { +func (c *ClusterProvider) ListAllTaggedResources() error { // TODO(p1): need this for showing any half-made clusters and pruning them return nil } diff --git a/pkg/eks/nodegroup.go b/pkg/eks/nodegroup.go index 6192796494..8cc3a40755 100644 --- a/pkg/eks/nodegroup.go +++ b/pkg/eks/nodegroup.go @@ -14,7 +14,7 @@ import ( clientset "k8s.io/client-go/kubernetes" ) -func (c *Config) newNodeAuthConfigMap() (*corev1.ConfigMap, error) { +func (c *ClusterConfig) newNodeAuthConfigMap() (*corev1.ConfigMap, error) { mapRoles := make([]map[string]interface{}, 1) mapRoles[0] = make(map[string]interface{}) @@ -44,7 +44,7 @@ func (c *Config) newNodeAuthConfigMap() (*corev1.ConfigMap, error) { return cm, nil } -func (c *Config) CreateDefaultNodeGroupAuthConfigMap(clientSet *clientset.Clientset) error { +func (c *ClusterConfig) CreateDefaultNodeGroupAuthConfigMap(clientSet *clientset.Clientset) error { cm, err := c.newNodeAuthConfigMap() if err != nil { return errors.Wrap(err, "contructing auth ConfigMap for DefaultNodeGroup") @@ -81,7 +81,7 @@ func getNodes(clientSet *clientset.Clientset) (int, error) { return len(nodes.Items), nil } -func (c *Config) WaitForNodes(clientSet *clientset.Clientset) error { +func (c *ClusterConfig) WaitForNodes(clientSet *clientset.Clientset) error { timeoutAfter := 20 * time.Minute timer := time.After(timeoutAfter) timeout := false