Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get clusters states if a cluster was eksctl created #2779

Merged
merged 19 commits into from
Nov 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion pkg/apis/eksctl.io/v1alpha5/assets/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,9 @@
},
"type": "array"
},
"eksctlCreated": {
"$ref": "#/definitions/EKSCTLCreated"
},
"endpoint": {
"type": "string"
},
Expand All @@ -395,7 +398,8 @@
"endpoint",
"certificateAuthorityData",
"arn",
"stackName"
"stackName",
"eksctlCreated"
],
"additionalProperties": false,
"description": "hold read-only attributes of a cluster",
Expand Down Expand Up @@ -495,6 +499,9 @@
"description": "holds global subnet and all child subnets",
"x-intellij-html-description": "holds global subnet and all child subnets"
},
"EKSCTLCreated": {
"type": "string"
},
"FargateProfile": {
"required": [
"name"
Expand Down
6 changes: 3 additions & 3 deletions pkg/apis/eksctl.io/v1alpha5/schema.go

Large diffs are not rendered by default.

11 changes: 7 additions & 4 deletions pkg/apis/eksctl.io/v1alpha5/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -466,12 +466,15 @@ type KubernetesNetworkConfig struct {
ServiceIPv4CIDR string `json:"serviceIPv4CIDR,omitempty"`
}

type EKSCTLCreated string

// ClusterStatus hold read-only attributes of a cluster
type ClusterStatus struct {
Endpoint string `json:"endpoint,omitempty"`
CertificateAuthorityData []byte `json:"certificateAuthorityData,omitempty"`
ARN string `json:"arn,omitempty"`
StackName string `json:"stackName,omitempty"`
Endpoint string `json:"endpoint,omitempty"`
CertificateAuthorityData []byte `json:"certificateAuthorityData,omitempty"`
ARN string `json:"arn,omitempty"`
StackName string `json:"stackName,omitempty"`
EKSCTLCreated EKSCTLCreated `json:"eksctlCreated,omitempty"`
}

// String returns canonical representation of ClusterMeta
Expand Down
105 changes: 104 additions & 1 deletion pkg/ctl/get/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@ package get

import (
"fmt"
"os"
"strings"
"time"

awseks "github.com/aws/aws-sdk-go/service/eks"
"k8s.io/apimachinery/pkg/util/sets"

"github.com/weaveworks/eksctl/pkg/eks"
"github.com/weaveworks/eksctl/pkg/printers"

"github.com/kris-nova/logger"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -65,5 +74,99 @@ func doGetCluster(cmd *cmdutils.Cmd, params *getCmdParams, listAllRegions bool)
return err
}

return ctl.ListClusters(cfg.Metadata.Name, params.chunkSize, params.output, listAllRegions)
if cfg.Metadata.Name == "" {
return getAndPrinterClusters(ctl, params, listAllRegions)
}

return getAndPrintCluster(cfg, ctl, params)
}

func getAndPrinterClusters(ctl *eks.ClusterProvider, params *getCmdParams, listAllRegions bool) error {

printer, err := printers.NewPrinter(params.output)
if err != nil {
return err
}

if params.output == "table" {
addGetClustersSummaryTableColumns(printer.(*printers.TablePrinter))
}

clusters, err := ctl.ListClusters(params.chunkSize, listAllRegions)
if err != nil {
return err
}

return printer.PrintObjWithKind("clusters", clusters, os.Stdout)
}

func addGetClustersSummaryTableColumns(printer *printers.TablePrinter) {
printer.AddColumn("NAME", func(c *api.ClusterConfig) string {
return c.Metadata.Name
})
printer.AddColumn("REGION", func(c *api.ClusterConfig) string {
return c.Metadata.Region
})
printer.AddColumn("EKSCTL CREATED", func(c *api.ClusterConfig) api.EKSCTLCreated {
return c.Status.EKSCTLCreated
})
}

func getAndPrintCluster(cfg *api.ClusterConfig, ctl *eks.ClusterProvider, params *getCmdParams) error {
printer, err := printers.NewPrinter(params.output)
if err != nil {
return err
}

if params.output == "table" {
addGetClusterSummaryTableColumns(printer.(*printers.TablePrinter))
}

cluster, err := ctl.GetCluster(cfg.Metadata.Name)

if err != nil {
return err
}

if err := printer.PrintObjWithKind("clusters", []*awseks.Cluster{cluster}, os.Stdout); err != nil {
return err
}

return nil
}

func addGetClusterSummaryTableColumns(printer *printers.TablePrinter) {
printer.AddColumn("NAME", func(c *awseks.Cluster) string {
return *c.Name
})
printer.AddColumn("VERSION", func(c *awseks.Cluster) string {
return *c.Version
})
printer.AddColumn("STATUS", func(c *awseks.Cluster) string {
return *c.Status
})
printer.AddColumn("CREATED", func(c *awseks.Cluster) string {
return c.CreatedAt.Format(time.RFC3339)
})
printer.AddColumn("VPC", func(c *awseks.Cluster) string {
return *c.ResourcesVpcConfig.VpcId
})
printer.AddColumn("SUBNETS", func(c *awseks.Cluster) string {
subnets := sets.NewString()
for _, subnetid := range c.ResourcesVpcConfig.SubnetIds {
if api.IsSetAndNonEmptyString(subnetid) {
subnets.Insert(*subnetid)
}
}
return strings.Join(subnets.List(), ",")
})
printer.AddColumn("SECURITYGROUPS", func(c *awseks.Cluster) string {
groups := sets.NewString()
for _, sg := range c.ResourcesVpcConfig.SecurityGroupIds {
if api.IsSetAndNonEmptyString(sg) {
groups.Insert(*sg)
}
}
return strings.Join(groups.List(), ",")
})
}
Loading