diff --git a/cmd/create/ack.go b/cmd/create/ack.go index bf1ccac..1b2ff4d 100644 --- a/cmd/create/ack.go +++ b/cmd/create/ack.go @@ -39,10 +39,10 @@ func init() { ec2.NewSubnetResource, ec2.NewVpcResource, efs.NewFileSystemResource, - ecr.NewResource, + ecr.NewRepositoryResource, iam.NewRoleResource, eks.NewFargateProfileResource, rds.NewDatabaseInstanceResource, - s3.NewResource, + s3.NewBucketResource, } } diff --git a/pkg/resource/ack/amp/logging_configuration.go b/pkg/resource/ack/amp/logging_configuration.go index 5b31b49..b56a9e1 100644 --- a/pkg/resource/ack/amp/logging_configuration.go +++ b/pkg/resource/ack/amp/logging_configuration.go @@ -19,7 +19,15 @@ type LoggingConfigurationOptions struct { } func NewLoggingConfigurationResource() *resource.Resource { - res := &resource.Resource{ + options := &LoggingConfigurationOptions{ + CommonOptions: resource.CommonOptions{ + Name: "ack-amp-logging-configuration", + Namespace: "default", + NamespaceFlag: true, + }, + } + + return &resource.Resource{ Command: cmd.Command{ Name: "amp-logging-configuration", Description: "AMP Logging Configuration", @@ -27,44 +35,33 @@ func NewLoggingConfigurationResource() *resource.Resource { CreateArgs: []string{"NAME"}, }, + CreateFlags: cmd.Flags{ + &cmd.StringFlag{ + CommandFlag: cmd.CommandFlag{ + Name: "alias", + Description: "workspace alias to configure logging", + Required: true, + }, + Option: &options.Alias, + }, + &cmd.StringFlag{ + CommandFlag: cmd.CommandFlag{ + Name: "log-group", + Description: "name of CloudWatch Log Group", + Required: true, + }, + Option: &options.LogGroupName, + }, + }, + Manager: &manifest.ResourceManager{ Template: &template.TextTemplate{ Template: loggingYamlTemplate, }, }, - } - options := &LoggingConfigurationOptions{ - CommonOptions: resource.CommonOptions{ - Name: "ack-amp-logging-configuration", - Namespace: "default", - NamespaceFlag: true, - }, + Options: options, } - - flags := cmd.Flags{ - &cmd.StringFlag{ - CommandFlag: cmd.CommandFlag{ - Name: "alias", - Description: "workspace alias to configure logging", - Required: true, - }, - Option: &options.Alias, - }, - &cmd.StringFlag{ - CommandFlag: cmd.CommandFlag{ - Name: "log-group", - Description: "name of CloudWatch Log Group", - Required: true, - }, - Option: &options.LogGroupName, - }, - } - - res.Options = options - res.CreateFlags = flags - - return res } func (o *LoggingConfigurationOptions) PreCreate() error { diff --git a/pkg/resource/ack/ec2/security_group.go b/pkg/resource/ack/ec2/security_group.go index 9701686..9eb7554 100644 --- a/pkg/resource/ack/ec2/security_group.go +++ b/pkg/resource/ack/ec2/security_group.go @@ -13,7 +13,15 @@ type SecurityGroupOptions struct { } func NewSecurityGroupResource() *resource.Resource { - res := &resource.Resource{ + options := &SecurityGroupOptions{ + CommonOptions: resource.CommonOptions{ + Name: "ack-ec2-security-group", + Namespace: "default", + NamespaceFlag: true, + }, + } + + return &resource.Resource{ Command: cmd.Command{ Name: "security-group", Description: "EC2 Security Group", @@ -21,36 +29,25 @@ func NewSecurityGroupResource() *resource.Resource { CreateArgs: []string{"NAME"}, }, + CreateFlags: cmd.Flags{ + &cmd.StringFlag{ + CommandFlag: cmd.CommandFlag{ + Name: "desc", + Description: "description", + Required: true, + }, + Option: &options.Description, + }, + }, + Manager: &manifest.ResourceManager{ Template: &template.TextTemplate{ Template: securityGroupYamlTemplate, }, }, - } - - options := &SecurityGroupOptions{ - CommonOptions: resource.CommonOptions{ - Name: "ack-ec2-security-group", - Namespace: "default", - NamespaceFlag: true, - }, - } - flags := cmd.Flags{ - &cmd.StringFlag{ - CommandFlag: cmd.CommandFlag{ - Name: "desc", - Description: "description", - Required: true, - }, - Option: &options.Description, - }, + Options: options, } - - res.Options = options - res.CreateFlags = flags - - return res } const securityGroupYamlTemplate = `--- diff --git a/pkg/resource/ack/ec2/subnet.go b/pkg/resource/ack/ec2/subnet.go index bb2b7a5..d7cfb00 100644 --- a/pkg/resource/ack/ec2/subnet.go +++ b/pkg/resource/ack/ec2/subnet.go @@ -15,7 +15,15 @@ type SubnetOptions struct { } func NewSubnetResource() *resource.Resource { - res := &resource.Resource{ + options := &SubnetOptions{ + CommonOptions: resource.CommonOptions{ + Name: "ack-ec2-subnet", + Namespace: "default", + NamespaceFlag: true, + }, + } + + return &resource.Resource{ Command: cmd.Command{ Name: "subnet", Description: "EC2 Subnet", @@ -23,43 +31,32 @@ func NewSubnetResource() *resource.Resource { CreateArgs: []string{"NAME"}, }, + CreateFlags: cmd.Flags{ + &cmd.StringFlag{ + CommandFlag: cmd.CommandFlag{ + Name: "cidr", + Description: "ipv4 network range for the VPC, in CIDR notation", + Required: true, + }, + Option: &options.CidrBlock, + }, + &cmd.StringFlag{ + CommandFlag: cmd.CommandFlag{ + Name: "vpc-id", + Description: "ip of the VPC to create the subnet (defaults to cluster VPC)", + }, + Option: &options.VpcId, + }, + }, + Manager: &manifest.ResourceManager{ Template: &template.TextTemplate{ Template: subnetYamlTemplate, }, }, - } - options := &SubnetOptions{ - CommonOptions: resource.CommonOptions{ - Name: "ack-ec2-subnet", - Namespace: "default", - NamespaceFlag: true, - }, + Options: options, } - - flags := cmd.Flags{ - &cmd.StringFlag{ - CommandFlag: cmd.CommandFlag{ - Name: "cidr", - Description: "ipv4 network range for the VPC, in CIDR notation", - Required: true, - }, - Option: &options.CidrBlock, - }, - &cmd.StringFlag{ - CommandFlag: cmd.CommandFlag{ - Name: "vpc-id", - Description: "ip of the VPC to create the subnet (defaults to cluster VPC)", - }, - Option: &options.VpcId, - }, - } - - res.Options = options - res.CreateFlags = flags - - return res } func (o *SubnetOptions) PreCreate() error { diff --git a/pkg/resource/ack/ec2/vpc.go b/pkg/resource/ack/ec2/vpc.go index 5e325b7..daf20ac 100644 --- a/pkg/resource/ack/ec2/vpc.go +++ b/pkg/resource/ack/ec2/vpc.go @@ -13,7 +13,16 @@ type VpcOptions struct { } func NewVpcResource() *resource.Resource { - res := &resource.Resource{ + options := &VpcOptions{ + CommonOptions: resource.CommonOptions{ + Name: "ack-ec2-vpc", + Namespace: "default", + NamespaceFlag: true, + }, + CidrBlocks: []string{"10.0.0.0/16"}, + } + + return &resource.Resource{ Command: cmd.Command{ Name: "vpc", Description: "Virtual Private Cloud (VPC)", @@ -21,36 +30,24 @@ func NewVpcResource() *resource.Resource { CreateArgs: []string{"NAME"}, }, + CreateFlags: cmd.Flags{ + &cmd.StringSliceFlag{ + CommandFlag: cmd.CommandFlag{ + Name: "cidrs", + Description: "list of IPv4 CIDR blocks for your VPC", + }, + Option: &options.CidrBlocks, + }, + }, + Manager: &manifest.ResourceManager{ Template: &template.TextTemplate{ Template: vpcYamlTemplate, }, }, - } - - options := &VpcOptions{ - CommonOptions: resource.CommonOptions{ - Name: "ack-ec2-vpc", - Namespace: "default", - NamespaceFlag: true, - }, - CidrBlocks: []string{"10.0.0.0/16"}, - } - flags := cmd.Flags{ - &cmd.StringSliceFlag{ - CommandFlag: cmd.CommandFlag{ - Name: "cidrs", - Description: "list of IPv4 CIDR blocks for your VPC", - }, - Option: &options.CidrBlocks, - }, + Options: options, } - - res.Options = options - res.CreateFlags = flags - - return res } const vpcYamlTemplate = `--- diff --git a/pkg/resource/ack/ecr/ecr.go b/pkg/resource/ack/ecr/repository.go similarity index 62% rename from pkg/resource/ack/ecr/ecr.go rename to pkg/resource/ack/ecr/repository.go index 7ff59d9..3c83106 100644 --- a/pkg/resource/ack/ecr/ecr.go +++ b/pkg/resource/ack/ecr/repository.go @@ -13,22 +13,7 @@ type EcrOptions struct { ScanOnPush bool } -func NewResource() *resource.Resource { - res := &resource.Resource{ - Command: cmd.Command{ - Name: "ecr-repo", - Description: "ECR Repository", - Aliases: []string{"ecr"}, - CreateArgs: []string{"NAME"}, - }, - - Manager: &manifest.ResourceManager{ - Template: &template.TextTemplate{ - Template: yamlTemplate, - }, - }, - } - +func NewRepositoryResource() *resource.Resource { options := &EcrOptions{ CommonOptions: resource.CommonOptions{ Name: "ack-ecr-repo", @@ -37,30 +22,42 @@ func NewResource() *resource.Resource { }, } - flags := cmd.Flags{ - &cmd.BoolFlag{ - CommandFlag: cmd.CommandFlag{ - Name: "immutable-tags", - Description: "all image tags within the repository will be immutable", - }, - Option: &options.ImmutableTags, + return &resource.Resource{ + Command: cmd.Command{ + Name: "ecr-repo", + Description: "ECR Repository", + Aliases: []string{"ecr"}, + CreateArgs: []string{"NAME"}, }, - &cmd.BoolFlag{ - CommandFlag: cmd.CommandFlag{ - Name: "scan-on-push", - Description: "scan image when it's pushed to the repository", + + CreateFlags: cmd.Flags{ + &cmd.BoolFlag{ + CommandFlag: cmd.CommandFlag{ + Name: "immutable-tags", + Description: "all image tags within the repository will be immutable", + }, + Option: &options.ImmutableTags, + }, + &cmd.BoolFlag{ + CommandFlag: cmd.CommandFlag{ + Name: "scan-on-push", + Description: "scan image when it's pushed to the repository", + }, + Option: &options.ScanOnPush, }, - Option: &options.ScanOnPush, }, - } - res.Options = options - res.CreateFlags = flags + Manager: &manifest.ResourceManager{ + Template: &template.TextTemplate{ + Template: repoYamlTemplate, + }, + }, - return res + Options: options, + } } -const yamlTemplate = `--- +const repoYamlTemplate = `--- apiVersion: ecr.services.k8s.aws/v1alpha1 kind: Repository metadata: diff --git a/pkg/resource/ack/eks/fargate.go b/pkg/resource/ack/eks/fargate_profile.go similarity index 75% rename from pkg/resource/ack/eks/fargate.go rename to pkg/resource/ack/eks/fargate_profile.go index 8f9a3fe..ca29a50 100644 --- a/pkg/resource/ack/eks/fargate.go +++ b/pkg/resource/ack/eks/fargate_profile.go @@ -19,21 +19,6 @@ type FargateProfileOptions struct { } func NewFargateProfileResource() *resource.Resource { - res := &resource.Resource{ - Command: cmd.Command{ - Name: "eks-fargate-profile", - Description: "Fargate Profile", - Aliases: []string{"eks-fargate", "fargate-profile", "fargate", "fp"}, - CreateArgs: []string{"NAME"}, - }, - - Manager: &manifest.ResourceManager{ - Template: &template.TextTemplate{ - Template: subnetYamlTemplate, - }, - }, - } - options := &FargateProfileOptions{ CommonOptions: resource.CommonOptions{ Name: "ack-eks-fargate-profile", @@ -43,27 +28,39 @@ func NewFargateProfileResource() *resource.Resource { FargateNamespace: "default", } - flags := cmd.Flags{ - &cmd.StringFlag{ - CommandFlag: cmd.CommandFlag{ - Name: "fargate-namespace", - Description: "namespace selector to run pods on fargate", - }, - Option: &options.FargateNamespace, + return &resource.Resource{ + Command: cmd.Command{ + Name: "eks-fargate-profile", + Description: "EKS Fargate Profile", + Aliases: []string{"eks-fargate", "fargate-profile", "fargate", "fp"}, + CreateArgs: []string{"NAME"}, }, - &cmd.StringSliceFlag{ - CommandFlag: cmd.CommandFlag{ - Name: "subnets", - Description: "subnets for fargate pods (defaults to all private subnets)", + + CreateFlags: cmd.Flags{ + &cmd.StringFlag{ + CommandFlag: cmd.CommandFlag{ + Name: "fargate-namespace", + Description: "namespace selector to run pods on fargate", + }, + Option: &options.FargateNamespace, + }, + &cmd.StringSliceFlag{ + CommandFlag: cmd.CommandFlag{ + Name: "subnets", + Description: "subnets for fargate pods (defaults to all private subnets)", + }, + Option: &options.Subnets, }, - Option: &options.Subnets, }, - } - res.Options = options - res.CreateFlags = flags + Manager: &manifest.ResourceManager{ + Template: &template.TextTemplate{ + Template: fargateProfileYamlTemplate, + }, + }, - return res + Options: options, + } } func (o *FargateProfileOptions) PreCreate() error { @@ -87,7 +84,7 @@ func (o *FargateProfileOptions) PreCreate() error { return nil } -const subnetYamlTemplate = `--- +const fargateProfileYamlTemplate = `--- apiVersion: eks.services.k8s.aws/v1alpha1 kind: FargateProfile metadata: diff --git a/pkg/resource/ack/iam/role.go b/pkg/resource/ack/iam/role.go index ecfcd50..b27b135 100644 --- a/pkg/resource/ack/iam/role.go +++ b/pkg/resource/ack/iam/role.go @@ -13,21 +13,6 @@ type RoleOptions struct { } func NewRoleResource() *resource.Resource { - res := &resource.Resource{ - Command: cmd.Command{ - Name: "iam-role", - Description: "ECR Repository", - Aliases: []string{"role"}, - CreateArgs: []string{"NAME"}, - }, - - Manager: &manifest.ResourceManager{ - Template: &template.TextTemplate{ - Template: yamlTemplate, - }, - }, - } - options := &RoleOptions{ CommonOptions: resource.CommonOptions{ Name: "ack-iam-role", @@ -37,20 +22,32 @@ func NewRoleResource() *resource.Resource { Description: "ACK test role", } - flags := cmd.Flags{ - &cmd.StringFlag{ - CommandFlag: cmd.CommandFlag{ - Name: "description", - Description: "role description", + return &resource.Resource{ + Command: cmd.Command{ + Name: "iam-role", + Description: "IAM Role", + Aliases: []string{"role"}, + CreateArgs: []string{"NAME"}, + }, + + CreateFlags: cmd.Flags{ + &cmd.StringFlag{ + CommandFlag: cmd.CommandFlag{ + Name: "description", + Description: "role description", + }, + Option: &options.Description, }, - Option: &options.Description, }, - } - res.Options = options - res.CreateFlags = flags + Manager: &manifest.ResourceManager{ + Template: &template.TextTemplate{ + Template: yamlTemplate, + }, + }, - return res + Options: options, + } } const yamlTemplate = `--- diff --git a/pkg/resource/ack/s3/s3.go b/pkg/resource/ack/s3/buckert.go similarity index 83% rename from pkg/resource/ack/s3/s3.go rename to pkg/resource/ack/s3/buckert.go index 93d0996..99ee1ca 100644 --- a/pkg/resource/ack/s3/s3.go +++ b/pkg/resource/ack/s3/buckert.go @@ -7,8 +7,8 @@ import ( "github.com/awslabs/eksdemo/pkg/template" ) -func NewResource() *resource.Resource { - res := &resource.Resource{ +func NewBucketResource() *resource.Resource { + return &resource.Resource{ Command: cmd.Command{ Name: "s3-bucket", Description: "Amazon S3 bucket", @@ -18,7 +18,7 @@ func NewResource() *resource.Resource { Manager: &manifest.ResourceManager{ Template: &template.TextTemplate{ - Template: yamlTemplate, + Template: bucketYamlTemplate, }, }, @@ -28,11 +28,9 @@ func NewResource() *resource.Resource { NamespaceFlag: true, }, } - - return res } -const yamlTemplate = `--- +const bucketYamlTemplate = `--- apiVersion: s3.services.k8s.aws/v1alpha1 kind: Bucket metadata: