Skip to content

Commit

Permalink
Merge pull request #55 from cybertec-postgresql/improve_cs_pgbackrest
Browse files Browse the repository at this point in the history
Improve cs pgbackrest
  • Loading branch information
Schmaetz authored Aug 7, 2024
2 parents 7670593 + ee20c5c commit 82b71c2
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 7 deletions.
9 changes: 9 additions & 0 deletions pkg/apis/cpo.opensource.cybertec.at/v1/crds.go
Original file line number Diff line number Diff line change
Expand Up @@ -1186,6 +1186,15 @@ var PostgresCRDResourceValidation = apiextv1.CustomResourceValidation{
"region": {
Type: "string",
},
"account": {
Type: "string",
},
"key": {
Type: "string",
},
"keyType": {
Type: "string",
},
"schedule": {
Type: "object",
Properties: map[string]apiextv1.JSONSchemaProps{
Expand Down
3 changes: 3 additions & 0 deletions pkg/apis/cpo.opensource.cybertec.at/v1/postgresql_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,9 @@ type Repo struct {
Resource string `json:"resource"`
Endpoint string `json:"endpoint"`
Region string `json:"region"`
Account string `json:"account"`
Key string `json:"key"`
KeyType string `json:"keyType"`
Schedule map[string]string `json:"schedule"`
Volume `json:"volume,omitempty"`
}
Expand Down
33 changes: 26 additions & 7 deletions pkg/cluster/k8sres.go
Original file line number Diff line number Diff line change
Expand Up @@ -2935,11 +2935,7 @@ func ensurePath(file string, defaultDir string, defaultFile string) string {
func (c *Cluster) generatePgbackrestConfigmap() (*v1.ConfigMap, error) {
config := "[db]\npg1-path = /home/postgres/pgdata/pgroot/data\npg1-port = 5432\npg1-socket-path = /var/run/postgresql/\n"
config += "\n[global]\nlog-path = /home/postgres/pgdata/pgbackrest/log\nspool-path = /home/postgres/pgdata/pgbackrest/spool-path"
config += "\ntls-server-address=*"
config += "\ntls-server-ca-file = /etc/pgbackrest/certs/pgbackrest.ca-roots"
config += "\ntls-server-cert-file = /etc/pgbackrest/certs/pgbackrest-client.crt"
config += "\ntls-server-key-file = /etc/pgbackrest/certs/pgbackrest-client.key"
config += "\ntls-server-auth = " + c.clientCommonName() + "=*"

if c.Postgresql.Spec.Backup != nil && c.Postgresql.Spec.Backup.Pgbackrest != nil {
if global := c.Postgresql.Spec.Backup.Pgbackrest.Global; global != nil {
for k, v := range global {
Expand All @@ -2950,20 +2946,43 @@ func (c *Cluster) generatePgbackrestConfigmap() (*v1.ConfigMap, error) {

if len(repos) >= 1 {
for i, repo := range repos {
if repo.Storage == "pvc" {
switch repo.Storage {
case "pvc":
c.logger.Debugf("DEBUG_OUTPUT %s %s", c.clusterName().Name, c.Namespace)
config += "\ntls-server-address=*"
config += "\ntls-server-ca-file = /etc/pgbackrest/certs/pgbackrest.ca-roots"
config += "\ntls-server-cert-file = /etc/pgbackrest/certs/pgbackrest-client.crt"
config += "\ntls-server-key-file = /etc/pgbackrest/certs/pgbackrest-client.key"
config += "\ntls-server-auth = " + c.clientCommonName() + "=*"
config += "\nrepo" + fmt.Sprintf("%d", i+1) + "-host = " + c.clusterName().Name + "-pgbackrest-repo-host-0." + c.serviceName(ClusterPods) + "." + c.Namespace + ".svc." + c.OpConfig.ClusterDomain
config += "\nrepo" + fmt.Sprintf("%d", i+1) + "-host-ca-file = /etc/pgbackrest/certs/pgbackrest.ca-roots"
config += "\nrepo" + fmt.Sprintf("%d", i+1) + "-host-cert-file = /etc/pgbackrest/certs/pgbackrest-client.crt"
config += "\nrepo" + fmt.Sprintf("%d", i+1) + "-host-key-file = /etc/pgbackrest/certs/pgbackrest-client.key"
config += "\nrepo" + fmt.Sprintf("%d", i+1) + "-host-type = tls"
config += "\nrepo" + fmt.Sprintf("%d", i+1) + "-host-user = postgres"
} else {

case "s3":
config += fmt.Sprintf("\n%s-%s-bucket = %s", repo.Name, repo.Storage, repo.Resource)
config += fmt.Sprintf("\n%s-%s-endpoint = %s", repo.Name, repo.Storage, repo.Endpoint)
config += fmt.Sprintf("\n%s-%s-region = %s", repo.Name, repo.Storage, repo.Region)
config += fmt.Sprintf("\n%s-type = %s", repo.Name, repo.Storage)

case "gcs":
config += fmt.Sprintf("\n%s-%s-bucket = %s", repo.Name, repo.Storage, repo.Resource)
config += fmt.Sprintf("\n%s-%s-key = /etc/pgbackrest/conf.d/%s", repo.Name, repo.Storage, repo.Key)
config += fmt.Sprintf("\n%s-%s-key-type = %s", repo.Name, repo.Storage, repo.KeyType)
config += fmt.Sprintf("\n%s-type = %s", repo.Name, repo.Storage)

case "azure":
config += fmt.Sprintf("\n%s-%s-container = %s", repo.Name, repo.Storage, repo.Resource)
config += fmt.Sprintf("\n%s-%s-endpoint = %s", repo.Name, repo.Storage, repo.Endpoint)
config += fmt.Sprintf("\n%s-%s-key = %s", repo.Name, repo.Storage, repo.Key)
config += fmt.Sprintf("\n%s-%s-account = %s", repo.Name, repo.Storage, repo.Account)

config += fmt.Sprintf("\n%s-type = %s", repo.Name, repo.Storage)
default:
}

}
}
}
Expand Down

0 comments on commit 82b71c2

Please sign in to comment.