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

(7.0) Add Postgres Cloud SQL support #5941

Merged
merged 1 commit into from
Mar 22, 2021
Merged
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
Add Postgres Cloud SQL support
  • Loading branch information
r0mant committed Mar 22, 2021

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit b3366034a3b133c05a365296ed0ac9a5ff779ef4
52 changes: 47 additions & 5 deletions api/types/databaseserver.go
Original file line number Diff line number Diff line change
@@ -64,12 +64,16 @@ type DatabaseServer interface {
GetURI() string
// GetCA returns the database CA certificate bytes.
GetCA() []byte
// GetRegion returns the AWS region for RDS/Aurora databases.
GetRegion() string
// GetAWS returns AWS information for RDS/Aurora databases.
GetAWS() AWS
// GetGCP returns GCP information for Cloud SQL databases.
GetGCP() GCPCloudSQL
// GetType returns the database type, self-hosted or AWS RDS.
GetType() string
// IsRDS returns true if this is an RDS/Aurora database.
IsRDS() bool
// IsCloudSQL returns true if this is a Cloud SQL database.
IsCloudSQL() bool
// CheckAndSetDefaults checks and set default values for any missing fields.
CheckAndSetDefaults() error
// Copy returns a copy of this database server object.
@@ -235,21 +239,34 @@ func (s *DatabaseServerV3) GetCA() []byte {
return s.Spec.CACert
}

// GetRegion returns the AWS region for RDS/Aurora databases.
func (s *DatabaseServerV3) GetRegion() string {
return s.Spec.AWS.Region
// GetAWS returns AWS information for RDS/Aurora databases.
func (s *DatabaseServerV3) GetAWS() AWS {
return s.Spec.AWS
}

// GetGCP returns GCP information for Cloud SQL databases.
func (s *DatabaseServerV3) GetGCP() GCPCloudSQL {
return s.Spec.GCP
}

// IsRDS returns true if this database represents AWS RDS/Aurora instance.
func (s *DatabaseServerV3) IsRDS() bool {
return s.GetType() == DatabaseTypeRDS
}

// IsCloudSQL returns true if this database is a Cloud SQL instance.
func (s *DatabaseServerV3) IsCloudSQL() bool {
return s.GetType() == DatabaseTypeCloudSQL
}

// GetType returns the database type, self-hosted or AWS RDS.
func (s *DatabaseServerV3) GetType() string {
if s.Spec.AWS.Region != "" {
return DatabaseTypeRDS
}
if s.Spec.GCP.ProjectID != "" {
return DatabaseTypeCloudSQL
}
return DatabaseTypeSelfHosted
}

@@ -297,6 +314,8 @@ const (
DatabaseTypeSelfHosted = "self-hosted"
// DatabaseTypeRDS is AWS-hosted RDS or Aurora database.
DatabaseTypeRDS = "rds"
// DatabaseTypeCloudSQL is GCP-hosted Cloud SQL database.
DatabaseTypeCloudSQL = "gcp"
)

// SortedDatabaseServers implements sorter for database servers.
@@ -310,3 +329,26 @@ func (s SortedDatabaseServers) Less(i, j int) bool { return s[i].GetName() < s[j

// Swap swaps two database servers.
func (s SortedDatabaseServers) Swap(i, j int) { s[i], s[j] = s[j], s[i] }

// DatabaseServers is a list of database servers.
type DatabaseServers []DatabaseServer

// HasRDS returns true if an AWS RDS database is present among this list.
func (s DatabaseServers) HasRDS() bool {
for _, d := range s {
if d.IsRDS() {
return true
}
}
return false
}

// HasGCP returns true if a GCP Cloud SQL database is present among this list.
func (s DatabaseServers) HasGCP() bool {
for _, d := range s {
if d.IsCloudSQL() {
return true
}
}
return false
}
Loading