Skip to content

Commit

Permalink
refactor: create ACK resources (#245)
Browse files Browse the repository at this point in the history
  • Loading branch information
aaroniscode committed Sep 8, 2024
1 parent f7f46f7 commit 6695774
Show file tree
Hide file tree
Showing 9 changed files with 186 additions and 209 deletions.
4 changes: 2 additions & 2 deletions cmd/create/ack.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
61 changes: 29 additions & 32 deletions pkg/resource/ack/amp/logging_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,52 +19,49 @@ 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",
Aliases: []string{"amp-logging-config", "amp-logging", "amp-log"},
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 {
Expand Down
45 changes: 21 additions & 24 deletions pkg/resource/ack/ec2/security_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,44 +13,41 @@ 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",
Aliases: []string{"security-groups", "sg"},
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 = `---
Expand Down
59 changes: 28 additions & 31 deletions pkg/resource/ack/ec2/subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,51 +15,48 @@ 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",
Aliases: []string{"subnets"},
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 {
Expand Down
45 changes: 21 additions & 24 deletions pkg/resource/ack/ec2/vpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,44 +13,41 @@ 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)",
Aliases: []string{"vpcs"},
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 = `---
Expand Down
63 changes: 30 additions & 33 deletions pkg/resource/ack/ecr/ecr.go → pkg/resource/ack/ecr/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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:
Expand Down
Loading

0 comments on commit 6695774

Please sign in to comment.