mirror of
https://github.com/zalando/postgres-operator.git
synced 2026-10-09 08:16:08 +02:00
add unit test and documentation for finalizers (#2509)
* add unit test and documentation for finalizers * error msg with lower case and cover sync case * try to avoid adding json-patch dependency * use Update to remove finalizer * changing status and finalizer during create * do not call Delete() twice
This commit is contained in:
@@ -213,6 +213,37 @@ func (client *KubernetesClient) SetPostgresCRDStatus(clusterName spec.Namespaced
|
||||
return pg, nil
|
||||
}
|
||||
|
||||
// SetFinalizer of Postgres cluster
|
||||
func (client *KubernetesClient) SetFinalizer(clusterName spec.NamespacedName, pg *apiacidv1.Postgresql, finalizers []string) (*apiacidv1.Postgresql, error) {
|
||||
var (
|
||||
updatedPg *apiacidv1.Postgresql
|
||||
patch []byte
|
||||
err error
|
||||
)
|
||||
pg.ObjectMeta.SetFinalizers(finalizers)
|
||||
|
||||
if len(finalizers) > 0 {
|
||||
patch, err = json.Marshal(struct {
|
||||
PgMetadata interface{} `json:"metadata"`
|
||||
}{&pg.ObjectMeta})
|
||||
if err != nil {
|
||||
return pg, fmt.Errorf("could not marshal ObjectMeta: %v", err)
|
||||
}
|
||||
|
||||
updatedPg, err = client.PostgresqlsGetter.Postgresqls(clusterName.Namespace).Patch(
|
||||
context.TODO(), clusterName.Name, types.MergePatchType, patch, metav1.PatchOptions{})
|
||||
} else {
|
||||
// in case finalizers are empty and update is needed to remove
|
||||
updatedPg, err = client.PostgresqlsGetter.Postgresqls(clusterName.Namespace).Update(
|
||||
context.TODO(), pg, metav1.UpdateOptions{})
|
||||
}
|
||||
if err != nil {
|
||||
return updatedPg, fmt.Errorf("could not set finalizer: %v", err)
|
||||
}
|
||||
|
||||
return updatedPg, nil
|
||||
}
|
||||
|
||||
// SamePDB compares the PodDisruptionBudgets
|
||||
func SamePDB(cur, new *apipolicyv1.PodDisruptionBudget) (match bool, reason string) {
|
||||
//TODO: improve comparison
|
||||
|
||||
Reference in New Issue
Block a user