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

Stricter linting #240

Merged
merged 1 commit into from
Oct 8, 2018
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
15 changes: 12 additions & 3 deletions .gometalinter.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
{
"Errors": true,
"Enable": ["vet", "golint", "errcheck", "deadcode"],
"Exclude": ["^vendor\/", "^build\/"],
"Enable": [
"vet",
"golint",
"errcheck",
"deadcode"
],
"Exclude": [
"^vendor\/",
"^build\/",
"^pkg\/nodebootstrap\/assets.go",
"\/usr\/local\/go"
],
"Deadline": "5m"
}
30 changes: 18 additions & 12 deletions cmd/eksctl/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ func createCmd() *cobra.Command {
Use: "create",
Short: "Create resource(s)",
Run: func(c *cobra.Command, _ []string) {
c.Help()
if err := c.Help(); err != nil {
logger.Debug("ignoring error %q", err.Error())
}
},
}

Expand All @@ -31,9 +33,10 @@ func createCmd() *cobra.Command {
}

const (
DEFAULT_NODE_COUNT = 2
DEFAULT_NODE_TYPE = "m5.large"
DEFAULT_SSH_PUBLIC_KEY = "~/.ssh/id_rsa.pub"
// DefaultNodeCount defines the default number of nodes to be created
DefaultNodeCount = 2
defaultNodeType = "m5.large"
defaultSSHPublicKey = "~/.ssh/id_rsa.pub"
)

var (
Expand Down Expand Up @@ -68,8 +71,8 @@ func createClusterCmd() *cobra.Command {
fs.StringVarP(&cfg.Profile, "profile", "p", "", "AWS credentials profile to use (overrides the AWS_PROFILE environment variable)")
fs.StringToStringVarP(&cfg.Tags, "tags", "", map[string]string{}, `A list of KV pairs used to tag the AWS resources (e.g. "Owner=John Doe,Team=Some Team")`)

fs.StringVarP(&cfg.NodeType, "node-type", "t", DEFAULT_NODE_TYPE, "node instance type")
fs.IntVarP(&cfg.Nodes, "nodes", "N", DEFAULT_NODE_COUNT, "total number of nodes (for a static ASG)")
fs.StringVarP(&cfg.NodeType, "node-type", "t", defaultNodeType, "node instance type")
fs.IntVarP(&cfg.Nodes, "nodes", "N", DefaultNodeCount, "total number of nodes (for a static ASG)")

// TODO: https://github.com/weaveworks/eksctl/issues/28
fs.IntVarP(&cfg.MinNodes, "nodes-min", "m", 0, "minimum nodes in ASG")
Expand All @@ -80,15 +83,18 @@ func createClusterCmd() *cobra.Command {
fs.StringSliceVar(&availabilityZones, "zones", nil, "(auto-select if unspecified)")

fs.BoolVar(&cfg.NodeSSH, "ssh-access", false, "control SSH access for nodes")
fs.StringVar(&cfg.SSHPublicKeyPath, "ssh-public-key", DEFAULT_SSH_PUBLIC_KEY, "SSH public key to use for nodes (import from local path, or use existing EC2 key pair)")
fs.StringVar(&cfg.SSHPublicKeyPath, "ssh-public-key", defaultSSHPublicKey, "SSH public key to use for nodes (import from local path, or use existing EC2 key pair)")

fs.BoolVar(&writeKubeconfig, "write-kubeconfig", true, "toggle writing of kubeconfig")
fs.BoolVar(&autoKubeconfigPath, "auto-kubeconfig", false, fmt.Sprintf("save kubconfig file by cluster name, e.g. %q", kubeconfig.AutoPath(exampleClusterName)))
fs.StringVar(&kubeconfigPath, "kubeconfig", kubeconfig.DefaultPath, "path to write kubeconfig (incompatible with --auto-kubeconfig)")
fs.BoolVar(&setContext, "set-kubeconfig-context", true, "if true then current-context will be set in kubeconfig; if a context is already set then it will be overwritten")

fs.DurationVar(&cfg.WaitTimeout, "aws-api-timeout", api.DefaultWaitTimeout, "")
fs.MarkHidden("aws-api-timeout") // TODO deprecate in 0.2.0
// TODO deprecate in 0.2.0
if err := fs.MarkHidden("aws-api-timeout"); err != nil {
logger.Debug("ignoring error %q", err.Error())
}
fs.DurationVar(&cfg.WaitTimeout, "timeout", api.DefaultWaitTimeout, "max wait time in any polling operations")

fs.BoolVar(&cfg.Addons.WithIAM.PolicyAmazonEC2ContainerRegistryPowerUser, "full-ecr-access", false, "enable full access to ECR")
Expand All @@ -103,12 +109,12 @@ func doCreateCluster(cfg *api.ClusterConfig, name string) error {
ctl := eks.New(cfg)

if cfg.Region == "" {
logger.Debug("no region specified in flags or config, setting to %s", api.DEFAULT_EKS_REGION)
cfg.Region = api.DEFAULT_EKS_REGION
logger.Debug("no region specified in flags or config, setting to %s", api.DefaultEKSRegion)
cfg.Region = api.DefaultEKSRegion
}

if cfg.Region != api.EKS_REGION_US_WEST_2 && cfg.Region != api.EKS_REGION_US_EAST_1 && cfg.Region != api.EKS_REGION_EU_WEST_1 {
return fmt.Errorf("%s is not supported only %s, %s and %s are supported", cfg.Region, api.EKS_REGION_US_WEST_2, api.EKS_REGION_US_EAST_1, api.EKS_REGION_EU_WEST_1)
if cfg.Region != api.EKSRegionUSWest2 && cfg.Region != api.EKSRegionUSEast1 && cfg.Region != api.EKSRegionEUWest1 {
return fmt.Errorf("%s is not supported only %s, %s and %s are supported", cfg.Region, api.EKSRegionUSWest2, api.EKSRegionUSEast1, api.EKSRegionEUWest1)
}

if err := ctl.CheckAuth(); err != nil {
Expand Down
6 changes: 4 additions & 2 deletions cmd/eksctl/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ func deleteCmd() *cobra.Command {
Use: "delete",
Short: "Delete resource(s)",
Run: func(c *cobra.Command, _ []string) {
c.Help()
if err := c.Help(); err != nil {
logger.Debug("ignoring error %q", err.Error())
}
},
}

Expand Down Expand Up @@ -58,7 +60,7 @@ func doDeleteCluster(cfg *api.ClusterConfig, name string) error {
ctl := eks.New(cfg)

if cfg.Region == "" {
cfg.Region = api.DEFAULT_EKS_REGION
cfg.Region = api.DefaultEKSRegion
}

if err := ctl.CheckAuth(); err != nil {
Expand Down
10 changes: 6 additions & 4 deletions cmd/eksctl/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

const (
DEFAULT_CHUNK_SIZE = 100
defaultChunkSize = 100
)

var (
Expand All @@ -25,7 +25,9 @@ func getCmd() *cobra.Command {
Use: "get",
Short: "Get resource(s)",
Run: func(c *cobra.Command, _ []string) {
c.Help()
if err := c.Help(); err != nil {
logger.Debug("ignoring error %q", err.Error())
}
},
}

Expand All @@ -52,7 +54,7 @@ func getClusterCmd() *cobra.Command {
fs := cmd.Flags()

fs.StringVarP(&cfg.ClusterName, "name", "n", "", "EKS cluster name")
fs.IntVar(&chunkSize, "chunk-size", DEFAULT_CHUNK_SIZE, "Return large lists in chunks rather than all at once. Pass 0 to disable.")
fs.IntVar(&chunkSize, "chunk-size", defaultChunkSize, "Return large lists in chunks rather than all at once. Pass 0 to disable.")

fs.StringVarP(&cfg.Region, "region", "r", "", "AWS region")
fs.StringVarP(&cfg.Profile, "profile", "p", "", "AWS credentials profile to use (overrides the AWS_PROFILE environment variable)")
Expand All @@ -65,7 +67,7 @@ func doGetCluster(cfg *api.ClusterConfig, name string) error {
ctl := eks.New(cfg)

if cfg.Region == "" {
cfg.Region = api.DEFAULT_EKS_REGION
cfg.Region = api.DefaultEKSRegion
}

if err := ctl.CheckAuth(); err != nil {
Expand Down
4 changes: 3 additions & 1 deletion cmd/eksctl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ var rootCmd = &cobra.Command{
Use: "eksctl",
Short: "a CLI for Amazon EKS",
Run: func(c *cobra.Command, _ []string) {
c.Help()
if err := c.Help(); err != nil {
logger.Debug("ignoring error %q", err.Error())
}
},
}

Expand Down
10 changes: 6 additions & 4 deletions cmd/eksctl/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ func utilsCmd() *cobra.Command {
Use: "utils",
Short: "Various utils",
Run: func(c *cobra.Command, _ []string) {
c.Help()
if err := c.Help(); err != nil {
logger.Debug("ignoring error %q", err.Error())
}
},
}

Expand Down Expand Up @@ -61,7 +63,7 @@ func waitNodesCmd() *cobra.Command {
fs := cmd.Flags()

fs.StringVar(&utilsKubeconfigInputPath, "kubeconfig", "kubeconfig", "path to read kubeconfig")
fs.IntVarP(&cfg.MinNodes, "nodes-min", "m", DEFAULT_NODE_COUNT, "minimum number of nodes to wait for")
fs.IntVarP(&cfg.MinNodes, "nodes-min", "m", DefaultNodeCount, "minimum number of nodes to wait for")
fs.DurationVar(&cfg.WaitTimeout, "timeout", api.DefaultWaitTimeout, "how long to wait")

return cmd
Expand Down Expand Up @@ -123,7 +125,7 @@ func doWriteKubeconfigCmd(cfg *api.ClusterConfig, name string) error {
ctl := eks.New(cfg)

if cfg.Region == "" {
cfg.Region = api.DEFAULT_EKS_REGION
cfg.Region = api.DefaultEKSRegion
}

if err := ctl.CheckAuth(); err != nil {
Expand Down Expand Up @@ -207,7 +209,7 @@ func doDescribeStacksCmd(cfg *api.ClusterConfig, name string) error {
ctl := eks.New(cfg)

if cfg.Region == "" {
cfg.Region = api.DEFAULT_EKS_REGION
cfg.Region = api.DefaultEKSRegion
}

if err := ctl.CheckAuth(); err != nil {
Expand Down
1 change: 1 addition & 0 deletions humans.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Josh Carp @jmcarp
Kirsten Schumy @kschumy
Karinna Iniguez @karinnainiguez
Michael Seiwald @mseiwald
Anton Gruebel @gruebel

/* Thanks */

Expand Down
3 changes: 3 additions & 0 deletions pkg/ami/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ import (
)

const (
// DefaultImageFamily defines the default image family for the worker nodes
DefaultImageFamily = ImageFamilyAmazonLinux2

// ImageFamilyAmazonLinux2 represents Amazon Linux 2 family
ImageFamilyAmazonLinux2 = "AmazonLinux2"

// ResolverStatic is used to indicate that the static (i.e. compiled into eksctl) AMIs should be used
Expand All @@ -22,6 +24,7 @@ const (
ResolverAuto = "auto"
)

// Variations of iamge classes
const (
ImageClassGeneral int = iota
ImageClassGPU
Expand Down
1 change: 1 addition & 0 deletions pkg/az/az.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
)

const (
// DefaultRequiredAvailabilityZones defines the number of required availability zones
DefaultRequiredAvailabilityZones = 3
)

Expand Down
24 changes: 15 additions & 9 deletions pkg/cfn/builder/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,24 @@ const (
cfnOutputClusterStackName = "ClusterStackName"
)

type clusterResourceSet struct {
// ClusterResourceSet stores the resource information of the cluster
type ClusterResourceSet struct {
rs *resourceSet
spec *api.ClusterConfig
subnets []*gfn.Value
securityGroups []*gfn.Value
}

func NewClusterResourceSet(spec *api.ClusterConfig) *clusterResourceSet {
return &clusterResourceSet{
// NewClusterResourceSet returns a resource set for the new cluster
func NewClusterResourceSet(spec *api.ClusterConfig) *ClusterResourceSet {
return &ClusterResourceSet{
rs: newResourceSet(),
spec: spec,
}
}

func (c *clusterResourceSet) AddAllResources() error {
// AddAllResources adds all the information about the cluster to the resource set
func (c *ClusterResourceSet) AddAllResources() error {
c.rs.template.Description = clusterTemplateDescription
c.rs.template.Description += clusterTemplateDescriptionDefaultFeatures
c.rs.template.Description += templateDescriptionSuffix
Expand All @@ -51,19 +54,21 @@ func (c *clusterResourceSet) AddAllResources() error {
return nil
}

func (c *clusterResourceSet) RenderJSON() ([]byte, error) {
// RenderJSON returns the rendered JSON
func (c *ClusterResourceSet) RenderJSON() ([]byte, error) {
return c.rs.renderJSON()
}

func (c *clusterResourceSet) Template() gfn.Template {
// Template returns the CloudFormation template
func (c *ClusterResourceSet) Template() gfn.Template {
return *c.rs.template
}

func (c *clusterResourceSet) newResource(name string, resource interface{}) *gfn.Value {
func (c *ClusterResourceSet) newResource(name string, resource interface{}) *gfn.Value {
return c.rs.newResource(name, resource)
}

func (c *clusterResourceSet) addResourcesForControlPlane(version string) {
func (c *ClusterResourceSet) addResourcesForControlPlane(version string) {
c.newResource("ControlPlane", &gfn.AWSEKSCluster{
Name: gfn.NewString(c.spec.ClusterName),
RoleArn: gfn.MakeFnGetAttString("ServiceRole.Arn"),
Expand All @@ -79,6 +84,7 @@ func (c *clusterResourceSet) addResourcesForControlPlane(version string) {
c.rs.newOutputFromAtt(cfnOutputClusterARN, "ControlPlane.Arn", true)
}

func (c *clusterResourceSet) GetAllOutputs(stack cfn.Stack) error {
// GetAllOutputs collects all outputs of the cluster
func (c *ClusterResourceSet) GetAllOutputs(stack cfn.Stack) error {
return c.rs.GetAllOutputs(stack, c.spec)
}
10 changes: 6 additions & 4 deletions pkg/cfn/builder/iam.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,12 @@ func (c *resourceSet) attachAllowPolicy(name string, refRole *gfn.Value, resourc
})
}

func (c *clusterResourceSet) WithIAM() bool {
// WithIAM states, if IAM roles will be created or not
func (c *ClusterResourceSet) WithIAM() bool {
return c.rs.withIAM
}

func (c *clusterResourceSet) addResourcesForIAM() {
func (c *ClusterResourceSet) addResourcesForIAM() {
c.rs.withIAM = true

refSR := c.newResource("ServiceRole", &gfn.AWSIAMRole{
Expand All @@ -75,11 +76,12 @@ func (c *clusterResourceSet) addResourcesForIAM() {
})
}

func (n *nodeGroupResourceSet) WithIAM() bool {
// WithIAM states, if IAM roles will be created or not
func (n *NodeGroupResourceSet) WithIAM() bool {
return n.rs.withIAM
}

func (n *nodeGroupResourceSet) addResourcesForIAM() {
func (n *NodeGroupResourceSet) addResourcesForIAM() {
n.rs.withIAM = true

if len(n.spec.NodePolicyARNs) == 0 {
Expand Down
24 changes: 15 additions & 9 deletions pkg/cfn/builder/nodegroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import (
"github.com/weaveworks/eksctl/pkg/nodebootstrap"
)

type nodeGroupResourceSet struct {
// NodeGroupResourceSet stores the resource information of the node group
type NodeGroupResourceSet struct {
rs *resourceSet
id int
spec *api.ClusterConfig
Expand All @@ -29,8 +30,9 @@ type awsCloudFormationResource struct {
UpdatePolicy map[string]map[string]string
}

func NewNodeGroupResourceSet(spec *api.ClusterConfig, clusterStackName string, id int) *nodeGroupResourceSet {
return &nodeGroupResourceSet{
// NewNodeGroupResourceSet returns a resource set for the new node group
func NewNodeGroupResourceSet(spec *api.ClusterConfig, clusterStackName string, id int) *NodeGroupResourceSet {
return &NodeGroupResourceSet{
rs: newResourceSet(),
id: id,
clusterStackName: clusterStackName,
Expand All @@ -39,7 +41,8 @@ func NewNodeGroupResourceSet(spec *api.ClusterConfig, clusterStackName string, i
}
}

func (n *nodeGroupResourceSet) AddAllResources() error {
// AddAllResources adds all the information about the node group to the resource set
func (n *NodeGroupResourceSet) AddAllResources() error {
n.rs.template.Description = nodeGroupTemplateDescription
n.rs.template.Description += nodeGroupTemplateDescriptionDefaultFeatures
n.rs.template.Description += templateDescriptionSuffix
Expand All @@ -64,19 +67,21 @@ func (n *nodeGroupResourceSet) AddAllResources() error {
return nil
}

func (n *nodeGroupResourceSet) RenderJSON() ([]byte, error) {
// RenderJSON returns the rendered JSON
func (n *NodeGroupResourceSet) RenderJSON() ([]byte, error) {
return n.rs.renderJSON()
}

func (n *nodeGroupResourceSet) Template() gfn.Template {
// Template returns the CloudFormation template
func (n *NodeGroupResourceSet) Template() gfn.Template {
return *n.rs.template
}

func (n *nodeGroupResourceSet) newResource(name string, resource interface{}) *gfn.Value {
func (n *NodeGroupResourceSet) newResource(name string, resource interface{}) *gfn.Value {
return n.rs.newResource(name, resource)
}

func (n *nodeGroupResourceSet) addResourcesForNodeGroup() {
func (n *NodeGroupResourceSet) addResourcesForNodeGroup() {
lc := &gfn.AWSAutoScalingLaunchConfiguration{
AssociatePublicIpAddress: gfn.True(),
IamInstanceProfile: n.instanceProfile,
Expand Down Expand Up @@ -129,6 +134,7 @@ func (n *nodeGroupResourceSet) addResourcesForNodeGroup() {
})
}

func (n *nodeGroupResourceSet) GetAllOutputs(stack cfn.Stack) error {
// GetAllOutputs collects all outputs of the node group
func (n *NodeGroupResourceSet) GetAllOutputs(stack cfn.Stack) error {
return n.rs.GetAllOutputs(stack, n.spec)
}
Loading