mirror of
https://github.com/argoproj/argo-cd
synced 2026-04-21 08:57:17 +00:00
fix(actions): Use correct annotation for CNPG suspend/resume (#26711)
Signed-off-by: Rouke Broersma <rouke.broersma@infosupport.com>
This commit is contained in:
parent
d6e36fc5ea
commit
ede9229353
6 changed files with 30 additions and 7 deletions
|
|
@ -1,12 +1,18 @@
|
|||
local actions = {}
|
||||
|
||||
-- https://github.com/cloudnative-pg/cloudnative-pg/tree/main/internal/cmd/plugin/restart
|
||||
actions["restart"] = {
|
||||
["iconClass"] = "fa fa-fw fa-recycle",
|
||||
["displayName"] = "Rollout restart Cluster"
|
||||
}
|
||||
|
||||
-- https://github.com/cloudnative-pg/cloudnative-pg/tree/main/internal/cmd/plugin/reload
|
||||
actions["reload"] = {
|
||||
["iconClass"] = "fa fa-fw fa-rotate-right",
|
||||
["displayName"] = "Reload all Configuration"
|
||||
}
|
||||
|
||||
-- https://github.com/cloudnative-pg/cloudnative-pg/tree/main/internal/cmd/plugin/promote
|
||||
actions["promote"] = {
|
||||
["iconClass"] = "fa fa-fw fa-angles-up",
|
||||
["displayName"] = "Promote Replica to Primary",
|
||||
|
|
@ -19,9 +25,10 @@ actions["promote"] = {
|
|||
}
|
||||
}
|
||||
|
||||
-- Check if reconciliation is currently suspended
|
||||
-- Suspend reconciliation loop for a cluster
|
||||
-- https://cloudnative-pg.io/docs/1.28/failure_modes/#disabling-reconciliation
|
||||
local isSuspended = false
|
||||
if obj.metadata and obj.metadata.annotations and obj.metadata.annotations["cnpg.io/reconciliation"] == "disabled" then
|
||||
if obj.metadata and obj.metadata.annotations and obj.metadata.annotations["cnpg.io/reconciliationLoop"] == "disabled" then
|
||||
isSuspended = true
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -6,5 +6,5 @@ if obj.metadata.annotations == nil then
|
|||
obj.metadata.annotations = {}
|
||||
end
|
||||
|
||||
obj.metadata.annotations["cnpg.io/reconciliation"] = nil
|
||||
obj.metadata.annotations["cnpg.io/reconciliationLoop"] = nil
|
||||
return obj
|
||||
|
|
|
|||
|
|
@ -6,5 +6,5 @@ if obj.metadata.annotations == nil then
|
|||
obj.metadata.annotations = {}
|
||||
end
|
||||
|
||||
obj.metadata.annotations["cnpg.io/reconciliation"] = "disabled"
|
||||
obj.metadata.annotations["cnpg.io/reconciliationLoop"] = "disabled"
|
||||
return obj
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ function hibernating(obj)
|
|||
end
|
||||
|
||||
-- Check if reconciliation is suspended, since this is an explicit user action we return the "suspended" status immediately
|
||||
if obj.metadata and obj.metadata.annotations and obj.metadata.annotations["cnpg.io/reconciliation"] == "disabled" then
|
||||
if obj.metadata and obj.metadata.annotations and obj.metadata.annotations["cnpg.io/reconciliationLoop"] == "disabled" then
|
||||
hs.status = "Suspended"
|
||||
hs.message = "Cluster reconciliation is suspended"
|
||||
return hs
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ apiVersion: postgresql.cnpg.io/v1
|
|||
kind: Cluster
|
||||
metadata:
|
||||
annotations:
|
||||
cnpg.io/reconciliation: "disabled"
|
||||
cnpg.io/reconciliationLoop: "disabled"
|
||||
kubectl.kubernetes.io/last-applied-configuration: |
|
||||
{"apiVersion":"postgresql.cnpg.io/v1","kind":"Cluster","metadata":{"annotations":{},"name":"cluster-example","namespace":"default"},"spec":{"imageName":"ghcr.io/cloudnative-pg/postgresql:13","instances":3,"storage":{"size":"1Gi"}}}
|
||||
creationTimestamp: "2025-04-25T20:44:24Z"
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@ func (t testNormalizer) Normalize(un *unstructured.Unstructured) error {
|
|||
}
|
||||
case "postgresql.cnpg.io":
|
||||
if un.GetKind() == "Cluster" {
|
||||
if err := unstructured.SetNestedStringMap(un.Object, map[string]string{"cnpg.io/reloadedAt": "0001-01-01T00:00:00Z", "kubectl.kubernetes.io/restartedAt": "0001-01-01T00:00:00Z"}, "metadata", "annotations"); err != nil {
|
||||
if err := setPgClusterAnnotations(un); err != nil {
|
||||
return fmt.Errorf("failed to normalize %s: %w", un.GetKind(), err)
|
||||
}
|
||||
if err := unstructured.SetNestedField(un.Object, nil, "status", "targetPrimaryTimestamp"); err != nil {
|
||||
|
|
@ -136,6 +136,22 @@ func setFluxRequestedAtAnnotation(un *unstructured.Unstructured) error {
|
|||
return unstructured.SetNestedStringMap(un.Object, map[string]string{"reconcile.fluxcd.io/requestedAt": "By Argo CD at: 0001-01-01T00:00:00"}, "metadata", "annotations")
|
||||
}
|
||||
|
||||
// Helper: normalize PostgreSQL CNPG Cluster annotations while preserving existing ones
|
||||
func setPgClusterAnnotations(un *unstructured.Unstructured) error {
|
||||
// Get existing annotations or create an empty map
|
||||
existingAnnotations, _, _ := unstructured.NestedStringMap(un.Object, "metadata", "annotations")
|
||||
if existingAnnotations == nil {
|
||||
existingAnnotations = make(map[string]string)
|
||||
}
|
||||
|
||||
// Update only the specific keys
|
||||
existingAnnotations["cnpg.io/reloadedAt"] = "0001-01-01T00:00:00Z"
|
||||
existingAnnotations["kubectl.kubernetes.io/restartedAt"] = "0001-01-01T00:00:00Z"
|
||||
|
||||
// Set the updated annotations back
|
||||
return unstructured.SetNestedStringMap(un.Object, existingAnnotations, "metadata", "annotations")
|
||||
}
|
||||
|
||||
func (t testNormalizer) normalizeJob(un *unstructured.Unstructured) error {
|
||||
if conditions, exist, err := unstructured.NestedSlice(un.Object, "status", "conditions"); err != nil {
|
||||
return fmt.Errorf("failed to normalize %s: %w", un.GetKind(), err)
|
||||
|
|
|
|||
Loading…
Reference in a new issue