mirror of
https://github.com/zalando/postgres-operator.git
synced 2026-09-30 21:30:28 +02:00
allow delete only if annotations meet configured criteria (#1069)
* define annotations for delete protection * change log level and reduce log lines for e2e tests * reduce wait_for_pod_start even further
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
acidv1 "github.com/zalando/postgres-operator/pkg/apis/acid.zalan.do/v1"
|
||||
@@ -454,6 +455,37 @@ func (c *Controller) GetReference(postgresql *acidv1.Postgresql) *v1.ObjectRefer
|
||||
return ref
|
||||
}
|
||||
|
||||
func (c *Controller) meetsClusterDeleteAnnotations(postgresql *acidv1.Postgresql) error {
|
||||
|
||||
deleteAnnotationDateKey := c.opConfig.DeleteAnnotationDateKey
|
||||
currentTime := time.Now()
|
||||
currentDate := currentTime.Format("2006-01-02") // go's reference date
|
||||
|
||||
if deleteAnnotationDateKey != "" {
|
||||
if deleteDate, ok := postgresql.Annotations[deleteAnnotationDateKey]; ok {
|
||||
if deleteDate != currentDate {
|
||||
return fmt.Errorf("annotation %s not matching the current date: got %s, expected %s", deleteAnnotationDateKey, deleteDate, currentDate)
|
||||
}
|
||||
} else {
|
||||
return fmt.Errorf("annotation %s not set in manifest to allow cluster deletion", deleteAnnotationDateKey)
|
||||
}
|
||||
}
|
||||
|
||||
deleteAnnotationNameKey := c.opConfig.DeleteAnnotationNameKey
|
||||
|
||||
if deleteAnnotationNameKey != "" {
|
||||
if clusterName, ok := postgresql.Annotations[deleteAnnotationNameKey]; ok {
|
||||
if clusterName != postgresql.Name {
|
||||
return fmt.Errorf("annotation %s not matching the cluster name: got %s, expected %s", deleteAnnotationNameKey, clusterName, postgresql.Name)
|
||||
}
|
||||
} else {
|
||||
return fmt.Errorf("annotation %s not set in manifest to allow cluster deletion", deleteAnnotationNameKey)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// hasOwnership returns true if the controller is the "owner" of the postgresql.
|
||||
// Whether it's owner is determined by the value of 'acid.zalan.do/controller'
|
||||
// annotation. If the value matches the controllerID then it owns it, or if the
|
||||
|
||||
Reference in New Issue
Block a user