Skip to content

Commit

Permalink
Move functions from eks.go
Browse files Browse the repository at this point in the history
  • Loading branch information
shogohida committed Oct 27, 2022
1 parent b440775 commit 9d42f8f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 29 deletions.
39 changes: 39 additions & 0 deletions pkg/aws/eks.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import (
"github.com/aws/aws-sdk-go-v2/aws/arn"
awseks "github.com/aws/aws-sdk-go-v2/service/eks"
ekstypes "github.com/aws/aws-sdk-go-v2/service/eks/types"

"github.com/kris-nova/logger"
"github.com/pkg/errors"

iamoidc "github.com/weaveworks/eksctl/pkg/iam/oidc"
"github.com/weaveworks/eksctl/pkg/version"
"github.com/weaveworks/eksctl/pkg/vpc"
)

func (c *ClusterManager) NewOpenIDConnectManager(spec *api.ClusterConfig) (*iamoidc.OpenIDConnectManager, error) {
if _, err := c.CanOperateWithRefresh(ctx, spec); err != nil {
return nil, err
}

if c.Status.ClusterInfo.Cluster == nil || c.Status.ClusterInfo.Cluster.Identity == nil || c.Status.ClusterInfo.Cluster.Identity.Oidc == nil || c.Status.ClusterInfo.Cluster.Identity.Oidc.Issuer == nil {
return nil, &iamoidc.UnsupportedOIDCError{Message: "unknown OIDC issuer URL"}
}

parsedARN, err := arn.Parse(spec.Status.ARN)
if err != nil {
return nil, errors.Wrapf(err, "unexpected invalid ARN: %q", spec.Status.ARN)
}
switch parsedARN.Partition {
case "aws", "aws-cn", "aws-us-gov":
default:
return nil, fmt.Errorf("unknown EKS ARN: %q", spec.Status.ARN)
}

return iamoidc.NewOpenIDConnectManager(c.AWSProvider.IAM(), parsedARN.AccountID,
*c.Status.ClusterInfo.Cluster.Identity.Oidc.Issuer, parsedARN.Partition, sharedTags(c.Status.ClusterInfo.Cluster))
}

func (c *ClusterManager) LoadClusterVPC(spec *api.ClusterConfig, stack *manager.Stack) error {
return vpc.UseFromClusterStack(ctx, c.AWSProvider, stack, spec)
}
29 changes: 0 additions & 29 deletions pkg/eks/eks.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,30 +156,6 @@ func (c *ClusterProvider) ControlPlaneVPCInfo() ekstypes.VpcConfigResponse {
return *c.Status.ClusterInfo.Cluster.ResourcesVpcConfig
}

// NewOpenIDConnectManager returns OpenIDConnectManager
func (c *ClusterProvider) NewOpenIDConnectManager(ctx context.Context, spec *api.ClusterConfig) (*iamoidc.OpenIDConnectManager, error) {
if _, err := c.CanOperateWithRefresh(ctx, spec); err != nil {
return nil, err
}

if c.Status.ClusterInfo.Cluster == nil || c.Status.ClusterInfo.Cluster.Identity == nil || c.Status.ClusterInfo.Cluster.Identity.Oidc == nil || c.Status.ClusterInfo.Cluster.Identity.Oidc.Issuer == nil {
return nil, &iamoidc.UnsupportedOIDCError{Message: "unknown OIDC issuer URL"}
}

parsedARN, err := arn.Parse(spec.Status.ARN)
if err != nil {
return nil, errors.Wrapf(err, "unexpected invalid ARN: %q", spec.Status.ARN)
}
switch parsedARN.Partition {
case "aws", "aws-cn", "aws-us-gov":
default:
return nil, fmt.Errorf("unknown EKS ARN: %q", spec.Status.ARN)
}

return iamoidc.NewOpenIDConnectManager(c.AWSProvider.IAM(), parsedARN.AccountID,
*c.Status.ClusterInfo.Cluster.Identity.Oidc.Issuer, parsedARN.Partition, sharedTags(c.Status.ClusterInfo.Cluster))
}

func sharedTags(cluster *ekstypes.Cluster) map[string]string {
return map[string]string{
api.ClusterNameTag: *cluster.Name,
Expand All @@ -188,11 +164,6 @@ func sharedTags(cluster *ekstypes.Cluster) map[string]string {

}

// LoadClusterVPC loads the VPC configuration.
func (c *ClusterProvider) LoadClusterVPC(ctx context.Context, spec *api.ClusterConfig, stack *manager.Stack) error {
return vpc.UseFromClusterStack(ctx, c.AWSProvider, stack, spec)
}

// GetCluster display details of an EKS cluster in your account
func (c *ClusterProvider) GetCluster(ctx context.Context, clusterName string) (*ekstypes.Cluster, error) {
input := &awseks.DescribeClusterInput{
Expand Down

0 comments on commit 9d42f8f

Please sign in to comment.