Skip to content

Commit

Permalink
add: create ack-rds-database-instance (#244)
Browse files Browse the repository at this point in the history
  • Loading branch information
aaroniscode authored Sep 7, 2024
1 parent 2c69a5d commit f7f46f7
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cmd/create/ack.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/awslabs/eksdemo/pkg/resource/ack/efs"
"github.com/awslabs/eksdemo/pkg/resource/ack/eks"
"github.com/awslabs/eksdemo/pkg/resource/ack/iam"
"github.com/awslabs/eksdemo/pkg/resource/ack/rds"
"github.com/awslabs/eksdemo/pkg/resource/ack/s3"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -41,6 +42,7 @@ func init() {
ecr.NewResource,
iam.NewRoleResource,
eks.NewFargateProfileResource,
rds.NewDatabaseInstanceResource,
s3.NewResource,
}
}
85 changes: 85 additions & 0 deletions pkg/resource/ack/rds/database_instance.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package rds

import (
"github.com/awslabs/eksdemo/pkg/cmd"
"github.com/awslabs/eksdemo/pkg/manifest"
"github.com/awslabs/eksdemo/pkg/resource"
"github.com/awslabs/eksdemo/pkg/template"
)

type DatabaseInstanceOptions struct {
resource.CommonOptions
Password string
Storage int
}

func NewDatabaseInstanceResource() *resource.Resource {
options := &DatabaseInstanceOptions{
CommonOptions: resource.CommonOptions{
Namespace: "default",
NamespaceFlag: true,
},
Storage: 5,
}

return &resource.Resource{
Command: cmd.Command{
Name: "rds-database-instance",
Description: "RDS Database Instance",
Aliases: []string{"rds"},
CreateArgs: []string{"NAME"},
},

CreateFlags: cmd.Flags{
&cmd.StringFlag{
CommandFlag: cmd.CommandFlag{
Name: "password",
Description: "database instance root password",
Required: true,
Shorthand: "P",
},
Option: &options.Password,
},
&cmd.IntFlag{
CommandFlag: cmd.CommandFlag{
Name: "storage",
Description: "storage in gibibytes (GiB) to allocate for the DB instance",
},
Option: &options.Storage,
},
},

Manager: &manifest.ResourceManager{
Template: &template.TextTemplate{
Template: databaseInstanceYamlTemplate,
},
},

Options: options,
}
}

const databaseInstanceYamlTemplate = `---
apiVersion: v1
kind: Secret
metadata:
name: dbpass
namespace: {{ .Namespace }}
data:
password: {{ .Password | b64enc }}
---
apiVersion: rds.services.k8s.aws/v1alpha1
kind: DBInstance
metadata:
name: {{ .Name }}
namespace: {{ .Namespace }}
spec:
allocatedStorage: {{ .Storage }}
dbInstanceClass: db.t3.medium
dbInstanceIdentifier: {{ .Name }}
engine: mysql
masterUsername: root
masterUserPassword:
name: dbpass
key: password
`

0 comments on commit f7f46f7

Please sign in to comment.