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

Override provider from the db YAML #81

Merged
merged 1 commit into from
Mar 23, 2021
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
16 changes: 0 additions & 16 deletions .travis.yml

This file was deleted.

1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ spec:
multiaz: true # multi AZ support
storagetype: gp2 # type of the underlying storage
tags: "key=value,key1=value1"
provider: aws # Optional either aws or local, will overrides the value the operator was started with

```

Expand Down
14 changes: 8 additions & 6 deletions crd/crd.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,19 +155,21 @@ type DatabaseSpec struct {
Username string `json:"username"`
Password v1.SecretKeySelector `json:"password"`
DBName string `json:"dbname"`
Engine string `json:"engine"` // "postgres"
Version string `json:"version"` // version of the engine / database
Class string `json:"class"` // like "db.t2.micro"
Size int64 `json:"size"` // size in gb
MaxAllocatedSize int64 `json:"MaxAllocatedSize"` // size in gb
Engine string `json:"engine"` // "postgres"
Version string `json:"version"` // version of the engine / database
Class string `json:"class"` // like "db.t2.micro"
Size int64 `json:"size"` // size in gb
MaxAllocatedSize int64 `json:"MaxAllocatedSize"` // size in gb
MultiAZ bool `json:"multiaz,omitempty"`
PubliclyAccessible bool `json:"publicaccess,omitempty"`
StorageEncrypted bool `json:"encrypted,omitempty"`
StorageType string `json:"storagetype,omitempty"`
Iops int64 `json:"iops,omitempty"`
BackupRetentionPeriod int64 `json:"backupretentionperiod,omitempty"` // between 0 and 35, zero means disable
DeleteProtection bool `json:"deleteprotection,omitempty"`
Tags string `json:"tags,omitempty"` // key=value,key1=value1
Tags string `json:"tags,omitempty"` // key=value,key1=value1
Provider string `json:"provider,omitempty"` // local or aws

}

type DatabaseStatus struct {
Expand Down
2 changes: 2 additions & 0 deletions crd/crd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func TestMarshal(t *testing.T) {
StorageEncrypted: true,
StorageType: "gp2",
Username: "dbuser",
Provider: "local",
},
}
j, err := yaml.Marshal(d)
Expand All @@ -52,6 +53,7 @@ func TestCRDValidationWithValidInput(t *testing.T) {
StorageEncrypted: true,
StorageType: "gp2",
Username: "dbuser",
Provider: "local",
},
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/sorenmat/k8s-rds

go 1.14
go 1.16

require (
github.com/aws/aws-sdk-go-v2 v0.11.0
Expand Down
7 changes: 5 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ func execute(dbprovider string, excludeNamespaces, includeNamespaces []string, r
return
}
log.Printf("deleting database: %s \n", db.Name)

r, err := getProvider(db, dbprovider, repository)
if err != nil {
log.Println(err)
Expand Down Expand Up @@ -171,7 +170,11 @@ func getProvider(db *crd.Database, dbprovider, repository string) (provider.Data
log.Println(err)
return nil, err
}
switch dbprovider {
provider := dbprovider
if db.Spec.Provider != "" {
provider = db.Spec.Provider
}
switch provider {
Comment on lines +173 to +177
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
provider := dbprovider
if db.Spec.Provider != "" {
provider = db.Spec.Provider
}
switch provider {
if db.Spec.Provider != "" {
dbprovider = db.Spec.Provider
}
switch dbprovider {

case "aws":
r, err := rds.New(db, kubectl)
if err != nil {
Expand Down