Skip to content
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
96 changes: 46 additions & 50 deletions api/v1/postgres_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,49 +29,54 @@ import (
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.

// UIDLabelName Name of the label referencing the owning Postgres resource in the control cluster
const UIDLabelName string = "postgres.database.fits.cloud/uuid"

// TenantLabelName Name of the tenant label
const TenantLabelName string = "postgres.database.fits.cloud/tenant"

// ProjectIDLabelName Name of the ProjectID label
const ProjectIDLabelName string = "postgres.database.fits.cloud/project-id"

// ManagedByLabelName Name of the managed-by label
const ManagedByLabelName string = "postgres.database.fits.cloud/managed-by"

// ManagedByLabelValue Value of the managed-by label
const ManagedByLabelValue string = "postgreslet"

// PostgresFinalizerName Name of the finalizer to use
const PostgresFinalizerName string = "postgres.finalizers.database.fits.cloud"

// Backup configure parametes of the database backup
const (
// S3URL defines the s3 endpoint URL for backup
BackupSecretS3Endpoint = "s3Endpoint"
// S3BucketName defines the name of the S3 bucket for backup
BackupSecretS3BucketName = "s3BucketName"
// Retention defines how many days a backup will persist
BackupSecretRetention = "retention"
// Schedule defines how often a backup should be made, in cron format
BackupSecretSchedule = "schedule"
BackupSecretAccessKey = "accesskey"
BackupSecretSecretKey = "secretkey"
BackupSecretProjectKey = "project"
// UIDLabelName Name of the label referencing the owning Postgres resource in the control cluster
UIDLabelName string = "postgres.database.fits.cloud/uuid"
// TenantLabelName Name of the tenant label
TenantLabelName string = "postgres.database.fits.cloud/tenant"
// ProjectIDLabelName Name of the ProjectID label
ProjectIDLabelName string = "postgres.database.fits.cloud/project-id"
// ManagedByLabelName Name of the managed-by label
ManagedByLabelName string = "postgres.database.fits.cloud/managed-by"
// ManagedByLabelValue Value of the managed-by label
ManagedByLabelValue string = "postgreslet"
// PostgresFinalizerName Name of the finalizer to use
PostgresFinalizerName string = "postgres.finalizers.database.fits.cloud"
// CreatedByAnnotationKey is used to store who in person created this database
CreatedByAnnotationKey string = "postgres.database.fits.cloud/created-by"
// BackupConfigLabelName if set to true, this secret stores the backupConfig
BackupConfigLabelName string = "postgres.database.fits.cloud/is-backup"
// BackupConfigKey defines the key under which the BackupConfig is stored in the data map.
BackupConfigKey = "config"
)

const (
Sun Weekday = iota
Mon
Tue
Wed
Thu
Fri
Sat
All
)
// BackupConfig defines all properties to configure backup of a database.
// This config is stored in the data section under the key BackupConfigKey as json payload.
type BackupConfig struct {
// ID of this backupConfig
ID string `json:"id"`
// Name is a user defined description
Name string `json:"name"`
// ProjectID the project this backup is mapped to
ProjectID string `json:"project"`
// Tenant the tenant of the backup
Tenant string `json:"tenant"`
// Retention defines how many versions should be held in s3
Retention string `json:"retention"`
// Schedule in cron syntax when to run the backup periodically
Schedule string `json:"schedule"`

// S3Endpoint the url of the s3 endpoint
S3Endpoint string `json:"s3endpoint"`
// S3BucketName is the name of the bucket where the backup should be stored.
S3BucketName string `json:"s3bucketname"`
// S3Region the region of the aws s3
S3Region string `json:"s3region"`
// S3AccessKey is the accesskey which must have write access
S3AccessKey string `json:"s3accesskey"`
// S3SecretKey is the secretkey which must match to the accesskey
S3SecretKey string `json:"s3secretkey"`
}

var ZalandoPostgresqlTypeMeta = metav1.TypeMeta{
APIVersion: "acid.zalan.do/v1",
Expand Down Expand Up @@ -154,15 +159,6 @@ type Size struct {
StorageSize string `json:"storageSize,omitempty"`
}

// Weekday defines a weekday or everyday
type Weekday int

// TimeWindow defines an interval in time
type TimeWindow struct {
Start metav1.Time `json:"start,omitempty"`
End metav1.Time `json:"end,omitempty"`
}

// PostgresStatus defines the observed state of Postgres
type PostgresStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
Expand Down Expand Up @@ -306,7 +302,7 @@ func (p *Postgres) ToPeripheralResourceName() string {
return p.generateTeamID() + "-" + p.generateDatabaseName()
}

// ToUserPasswordSecret returns the secret containing user password pairs
// ToUserPasswordsSecret returns the secret containing user password pairs
func (p *Postgres) ToUserPasswordsSecret(src *corev1.SecretList, scheme *runtime.Scheme) (*corev1.Secret, error) {
secret := &corev1.Secret{}
secret.Namespace = p.Namespace
Expand Down
32 changes: 15 additions & 17 deletions api/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 17 additions & 6 deletions controllers/postgres_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package controllers

import (
"context"
"encoding/json"
"fmt"
"net/url"
"time"
Expand Down Expand Up @@ -247,7 +248,17 @@ func (r *PostgresReconciler) createOrUpdateBackupConfig(ctx context.Context, p *
return fmt.Errorf("error while getting the backup secret from control plane cluster: %w", err)
}

s3url, err := url.Parse(string(backupSecret.Data[pg.BackupSecretS3Endpoint]))
backupConfigJSON, ok := backupSecret.Data[pg.BackupConfigKey]
if !ok {
return fmt.Errorf("no backupConfig stored in the secret")
}
var backupConfig pg.BackupConfig
err := json.Unmarshal(backupConfigJSON, &backupConfig)
if err != nil {
return fmt.Errorf("unable to unmarshal backupconfig:%w", err)
}

s3url, err := url.Parse(backupConfig.S3Endpoint)
if err != nil {
return fmt.Errorf("error while parsing the s3 endpoint url in the backup secret: %w", err)
}
Expand All @@ -259,11 +270,11 @@ func (r *PostgresReconciler) createOrUpdateBackupConfig(ctx context.Context, p *
walES3Endpoint := s3url.String()

// use the rest as provided in the secret
bucketName := string(backupSecret.Data[pg.BackupSecretS3BucketName])
awsAccessKeyID := string(backupSecret.Data[pg.BackupSecretAccessKey])
awsSecretAccessKey := string(backupSecret.Data[pg.BackupSecretSecretKey])
backupSchedule := string(backupSecret.Data[pg.BackupSecretSchedule])
backupNumToRetain := string(backupSecret.Data[pg.BackupSecretRetention])
bucketName := backupConfig.S3BucketName
awsAccessKeyID := backupConfig.S3AccessKey
awsSecretAccessKey := backupConfig.S3SecretKey
backupSchedule := backupConfig.Schedule
backupNumToRetain := backupConfig.Retention

// create updated content for pod environment configmap
data := map[string]string{
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ github.com/evanphx/json-patch v4.5.0+incompatible h1:ouOWdg56aJriqS0huScTkVXPC5I
github.com/evanphx/json-patch v4.5.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
github.com/evanphx/json-patch v4.9.0+incompatible h1:kLcOMZeuLAJvL2BPWLMIj5oaZQobrkAqrL+WFZwQses=
github.com/evanphx/json-patch v4.9.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/form3tech-oss/jwt-go v3.2.2+incompatible/go.mod h1:pbq4aXjuKjdthFRnoDwaVPLA+WlJuPGy+QneDUgJi2k=
github.com/franela/goblin v0.0.0-20200105215937-c9ffbefa60db/go.mod h1:7dvUGVsVBjqR7JHJk0brhHOZYGmfBYOrK0ZhYMEtBr4=
Expand Down