Skip to content

Commit

Permalink
Cleanup and refactor ctl.GetCredentials
Browse files Browse the repository at this point in the history
  • Loading branch information
errordeveloper committed Dec 27, 2018
1 parent 2b7d68c commit 1bd9df4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 25 deletions.
18 changes: 2 additions & 16 deletions pkg/ctl/create/nodegroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (

"strings"

awseks "github.com/aws/aws-sdk-go/service/eks"
"github.com/kubicorn/kubicorn/pkg/logger"
"github.com/pkg/errors"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -92,21 +91,8 @@ func doCreateNodeGroup(p *api.ProviderConfig, cfg *api.ClusterConfig, ng *api.No

logger.Debug("cfg = %#v", cfg)

// Check the cluster exists and is active
eksCluster, err := ctl.DescribeControlPlane(cfg.Metadata)
if err != nil {
return err
}
if *eksCluster.Status != awseks.ClusterStatusActive {
return fmt.Errorf("cluster %s status is %s, it needs to be active to add a nodegroup", *eksCluster.Name, *eksCluster.Status)
}
logger.Info("found cluster %s", *eksCluster.Name)
logger.Debug("cluster = %#v", eksCluster)

// Populate cfg with the endopoint, CA data, and so on obtained from the described control-plane
// So that we won't end up rendering a incomplete useradata missing those things
if err = ctl.GetCredentials(*eksCluster, cfg); err != nil {
return err
if err := ctl.GetCredentials(cfg); err != nil {
return errors.Wrapf(err, "getting credentials for cluster %q", cfg.Metadata.Name)
}

{
Expand Down
9 changes: 1 addition & 8 deletions pkg/ctl/utils/write_kubeconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,7 @@ func doWriteKubeconfigCmd(p *api.ProviderConfig, cfg *api.ClusterConfig, nameArg
writeKubeconfigOutputPath = kubeconfig.AutoPath(cfg.Metadata.Name)
}

cluster, err := ctl.DescribeControlPlane(cfg.Metadata)
if err != nil {
return err
}

logger.Debug("cluster = %#v", cluster)

if err = ctl.GetCredentials(*cluster, cfg); err != nil {
if err := ctl.GetCredentials(cfg); err != nil {
return err
}

Expand Down
12 changes: 11 additions & 1 deletion pkg/eks/eks.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,17 @@ func (c *ClusterProvider) DeprecatedDeleteControlPlane(cl *api.ClusterMeta) erro
}

// GetCredentials retrieves the certificate authority data
func (c *ClusterProvider) GetCredentials(cluster awseks.Cluster, spec *api.ClusterConfig) error {
func (c *ClusterProvider) GetCredentials(spec *api.ClusterConfig) error {
// Check the cluster exists and is active
cluster, err := c.DescribeControlPlane(spec.Metadata)
if err != nil {
return err
}
if *cluster.Status != awseks.ClusterStatusActive {
return fmt.Errorf("status of cluster %q is %q, has to be %q", *cluster.Name, *cluster.Status, awseks.ClusterStatusActive)
}
logger.Debug("cluster = %#v", cluster)

spec.Endpoint = *cluster.Endpoint

data, err := base64.StdEncoding.DecodeString(*cluster.CertificateAuthority.Data)
Expand Down

0 comments on commit 1bd9df4

Please sign in to comment.