-
Notifications
You must be signed in to change notification settings - Fork 6.4k
feat(actions): Add cloudnativepg reload, restart, promote, suspend and resume actions #24192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
rouke-broersma
wants to merge
24
commits into
argoproj:master
Choose a base branch
from
rouke-broersma:cloudnativepg-actions
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
2ef96ea
Add cloudnativepg cluster actions
rouke-broersma b41ee6f
Add tests
rouke-broersma 844bcad
Add actions to built_in_actions docs
rouke-broersma 81006c4
Merge branch 'master' into cloudnativepg-actions
rouke-broersma d5c80a2
Add extra null check in case there is no instance status available
rouke-broersma 14189d1
fix test files
rouke-broersma afe759c
String is not available
rouke-broersma 9e525e7
fix test names
rouke-broersma 9c46a1b
fix test data paths
rouke-broersma a378994
Merge remote-tracking branch 'upstream/master' into cloudnativepg-act…
rouke-broersma bb3052e
Remove referenced action
rouke-broersma 8c46daa
Remove unneccesary fields from test fields
rouke-broersma 219ffac
fix test data
rouke-broersma ef7dd6f
Add custom normalizations for Cluster
rouke-broersma 6e8de97
remove toString
rouke-broersma f72203d
Merge remote-tracking branch 'upstream/master' into cloudnativepg-act…
rouke-broersma 134c1e9
Add suspend/resume reconcile action and health status
rouke-broersma 207b8ab
Add suspend and resume actions
rouke-broersma bd452e8
Use recycle icon for restart action
rouke-broersma ec75073
rename
rouke-broersma e225aa8
Validate api versions in resource actions normalization
rouke-broersma b29e848
reverse
rouke-broersma 6bf161e
Merge remote-tracking branch 'upstream/master' into cloudnativepg-act…
rouke-broersma 83fe3b1
Merge remote-tracking branch 'upstream/master' into cloudnativepg-act…
rouke-broersma File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
33 changes: 33 additions & 0 deletions
33
resource_customizations/postgresql.cnpg.io/Cluster/actions/action_test.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
actionTests: | ||
- action: promote | ||
inputPath: testdata/cluster_healthy.yaml | ||
expectedOutputPath: testdata/cluster_promoting.yaml | ||
parameters: | ||
instance: 'any' | ||
- action: promote | ||
inputPath: testdata/cluster_healthy.yaml | ||
expectedOutputPath: testdata/cluster_promoting.yaml | ||
parameters: | ||
instance: '2' | ||
- action: promote | ||
inputPath: testdata/cluster_healthy.yaml | ||
expectedOutputPath: testdata/cluster_promoting.yaml | ||
parameters: | ||
instance: 'cluster-example-2' | ||
- action: promote | ||
inputPath: testdata/cluster_healthy.yaml | ||
expectedErrorMessage: 'Could not find a healthy instance matching the criteria: nonexistent-instance' | ||
parameters: | ||
instance: 'nonexistent-instance' | ||
- action: reload | ||
inputPath: testdata/cluster_healthy.yaml | ||
expectedOutputPath: testdata/cluster_reload.yaml | ||
- action: restart | ||
inputPath: testdata/cluster_healthy.yaml | ||
expectedOutputPath: testdata/cluster_restart.yaml | ||
- action: suspend | ||
inputPath: testdata/cluster_healthy.yaml | ||
expectedOutputPath: testdata/cluster_reconcile_suspended.yaml | ||
- action: resume | ||
inputPath: testdata/cluster_reconcile_suspended.yaml | ||
expectedOutputPath: testdata/cluster_healthy.yaml |
41 changes: 41 additions & 0 deletions
41
resource_customizations/postgresql.cnpg.io/Cluster/actions/discovery.lua
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
local actions = {} | ||
actions["restart"] = { | ||
["iconClass"] = "fa fa-fw fa-recycle", | ||
["displayName"] = "Rollout restart Cluster" | ||
} | ||
actions["reload"] = { | ||
["iconClass"] = "fa fa-fw fa-rotate-right", | ||
["displayName"] = "Reload all Configuration" | ||
} | ||
actions["promote"] = { | ||
["iconClass"] = "fa fa-fw fa-angles-up", | ||
["displayName"] = "Promote Replica to Primary", | ||
["disabled"] = (not obj.status.instancesStatus or not obj.status.instancesStatus.healthy or #obj.status.instancesStatus.healthy < 2), | ||
["params"] = { | ||
{ | ||
["name"] = "instance", | ||
["default"] = "any" | ||
} | ||
} | ||
} | ||
|
||
-- Check if reconciliation is currently suspended | ||
local isSuspended = false | ||
if obj.metadata and obj.metadata.annotations and obj.metadata.annotations["cnpg.io/reconciliation"] == "disabled" then | ||
isSuspended = true | ||
end | ||
|
||
-- Add suspend/resume actions based on current state | ||
if isSuspended then | ||
actions["resume"] = { | ||
["iconClass"] = "fa fa-fw fa-play", | ||
["displayName"] = "Resume Reconciliation" | ||
} | ||
else | ||
actions["suspend"] = { | ||
["iconClass"] = "fa fa-fw fa-pause", | ||
["displayName"] = "Suspend Reconciliation" | ||
} | ||
end | ||
|
||
return actions |
48 changes: 48 additions & 0 deletions
48
resource_customizations/postgresql.cnpg.io/Cluster/actions/promote/action.lua
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
local os = require("os") | ||
local instance = actionParams["instance"] | ||
local healthy = obj.status.instancesStatus.healthy | ||
local selected = nil | ||
|
||
if instance == "any" then | ||
-- Select next healthy instance after currentPrimary | ||
local nextIndex = 0 | ||
for index, node in ipairs(healthy) do | ||
if node == obj.status.currentPrimary then | ||
nextIndex = index + 1 | ||
if nextIndex > #healthy then | ||
nextIndex = 1 | ||
end | ||
break | ||
end | ||
end | ||
if nextIndex > 0 then | ||
selected = healthy[nextIndex] | ||
end | ||
elseif type(instance) == "string" and tonumber(instance) then | ||
-- Select by instance number | ||
local wanted = (obj.metadata and obj.metadata.name or "") .. "-" .. instance | ||
for _, node in ipairs(healthy or {}) do | ||
if node == wanted then | ||
selected = node | ||
break | ||
end | ||
end | ||
elseif type(instance) == "string" then | ||
-- Select by full name | ||
for _, node in ipairs(healthy) do | ||
if node == instance then | ||
selected = node | ||
break | ||
end | ||
end | ||
end | ||
|
||
if selected then | ||
obj.status.targetPrimary = selected | ||
obj.status.targetPrimaryTimestamp = os.date("!%Y-%m-%dT%XZ") | ||
obj.status.phase = "Switchover in progress" | ||
obj.status.phaseReason = "Switching over to " .. selected | ||
else | ||
error("Could not find a healthy instance matching the criteria: " .. instance, 0) | ||
end | ||
return obj |
9 changes: 9 additions & 0 deletions
9
resource_customizations/postgresql.cnpg.io/Cluster/actions/reload/action.lua
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
local os = require("os") | ||
if obj.metadata == nil then | ||
obj.metadata = {} | ||
end | ||
if obj.metadata.annotations == nil then | ||
obj.metadata.annotations = {} | ||
end | ||
obj.metadata.annotations["cnpg.io/reloadedAt"] = os.date("!%Y-%m-%dT%XZ") | ||
return obj |
9 changes: 9 additions & 0 deletions
9
resource_customizations/postgresql.cnpg.io/Cluster/actions/restart/action.lua
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
local os = require("os") | ||
if obj.metadata == nil then | ||
obj.metadata = {} | ||
end | ||
if obj.metadata.annotations == nil then | ||
obj.metadata.annotations = {} | ||
end | ||
obj.metadata.annotations["kubectl.kubernetes.io/restartedAt"] = os.date("!%Y-%m-%dT%XZ") | ||
return obj |
10 changes: 10 additions & 0 deletions
10
resource_customizations/postgresql.cnpg.io/Cluster/actions/resume/action.lua
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
if obj.metadata == nil then | ||
obj.metadata = {} | ||
end | ||
|
||
if obj.metadata.annotations == nil then | ||
obj.metadata.annotations = {} | ||
end | ||
|
||
obj.metadata.annotations["cnpg.io/reconciliation"] = "disabled" | ||
return obj |
10 changes: 10 additions & 0 deletions
10
resource_customizations/postgresql.cnpg.io/Cluster/actions/suspend/action.lua
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
if obj.metadata == nil then | ||
obj.metadata = {} | ||
end | ||
|
||
if obj.metadata.annotations == nil then | ||
obj.metadata.annotations = {} | ||
end | ||
|
||
obj.metadata.annotations["cnpg.io/reconciliation"] = nil | ||
return obj |
23 changes: 23 additions & 0 deletions
23
resource_customizations/postgresql.cnpg.io/Cluster/actions/testdata/cluster_healthy.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
apiVersion: postgresql.cnpg.io/v1 | ||
kind: Cluster | ||
metadata: | ||
creationTimestamp: "2025-04-25T20:44:24Z" | ||
generation: 1 | ||
name: cluster-example | ||
namespace: default | ||
resourceVersion: "20230" | ||
uid: 987fe1ba-bba7-4021-9d25-f06ca9a8c0d2 | ||
spec: | ||
imageName: ghcr.io/cloudnative-pg/postgresql:13 | ||
instances: 3 | ||
status: | ||
currentPrimary: cluster-example-1 | ||
currentPrimaryTimestamp: "2025-04-25T20:44:38.190232Z" | ||
instancesStatus: | ||
healthy: | ||
- cluster-example-1 | ||
- cluster-example-2 | ||
- cluster-example-3 | ||
phase: Cluster in healthy state | ||
targetPrimary: cluster-example-1 | ||
targetPrimaryTimestamp: "2025-04-25T20:44:26.214164Z" |
24 changes: 24 additions & 0 deletions
24
resource_customizations/postgresql.cnpg.io/Cluster/actions/testdata/cluster_promoting.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
apiVersion: postgresql.cnpg.io/v1 | ||
kind: Cluster | ||
metadata: | ||
creationTimestamp: "2025-04-25T20:44:24Z" | ||
generation: 1 | ||
name: cluster-example | ||
namespace: default | ||
resourceVersion: "20230" | ||
uid: 987fe1ba-bba7-4021-9d25-f06ca9a8c0d2 | ||
spec: | ||
imageName: ghcr.io/cloudnative-pg/postgresql:13 | ||
instances: 3 | ||
status: | ||
currentPrimary: cluster-example-1 | ||
currentPrimaryTimestamp: "2025-04-25T20:44:38.190232Z" | ||
instancesStatus: | ||
healthy: | ||
- cluster-example-1 | ||
- cluster-example-2 | ||
- cluster-example-3 | ||
phase: Switchover in progress | ||
phaseReason: Switching over to cluster-example-2 | ||
targetPrimary: cluster-example-2 | ||
targetPrimaryTimestamp: "0001-01-01T00:00:00Z" | ||
23 changes: 23 additions & 0 deletions
23
...stomizations/postgresql.cnpg.io/Cluster/actions/testdata/cluster_reconcile_suspended.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
apiVersion: postgresql.cnpg.io/v1 | ||
kind: Cluster | ||
metadata: | ||
creationTimestamp: "2025-04-25T20:44:24Z" | ||
generation: 1 | ||
name: cluster-example | ||
namespace: default | ||
resourceVersion: "20230" | ||
uid: 987fe1ba-bba7-4021-9d25-f06ca9a8c0d2 | ||
spec: | ||
imageName: ghcr.io/cloudnative-pg/postgresql:13 | ||
instances: 3 | ||
status: | ||
currentPrimary: cluster-example-1 | ||
currentPrimaryTimestamp: "2025-04-25T20:44:38.190232Z" | ||
instancesStatus: | ||
healthy: | ||
- cluster-example-1 | ||
- cluster-example-2 | ||
- cluster-example-3 | ||
phase: Cluster in healthy state | ||
targetPrimary: cluster-example-1 | ||
targetPrimaryTimestamp: "2025-04-25T20:44:26.214164Z" |
25 changes: 25 additions & 0 deletions
25
resource_customizations/postgresql.cnpg.io/Cluster/actions/testdata/cluster_reload.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
apiVersion: postgresql.cnpg.io/v1 | ||
kind: Cluster | ||
metadata: | ||
annotations: | ||
cnpg.io/reloadedAt: "0001-01-01T00:00:00Z" | ||
rouke-broersma marked this conversation as resolved.
Show resolved
Hide resolved
|
||
creationTimestamp: "2025-04-25T20:44:24Z" | ||
generation: 1 | ||
name: cluster-example | ||
namespace: default | ||
resourceVersion: "20230" | ||
uid: 987fe1ba-bba7-4021-9d25-f06ca9a8c0d2 | ||
spec: | ||
imageName: ghcr.io/cloudnative-pg/postgresql:13 | ||
instances: 3 | ||
status: | ||
currentPrimary: cluster-example-1 | ||
currentPrimaryTimestamp: "2025-04-25T20:44:38.190232Z" | ||
instancesStatus: | ||
healthy: | ||
- cluster-example-1 | ||
- cluster-example-2 | ||
- cluster-example-3 | ||
phase: Cluster in healthy state | ||
targetPrimary: cluster-example-1 | ||
targetPrimaryTimestamp: "2025-04-25T20:44:26.214164Z" |
25 changes: 25 additions & 0 deletions
25
resource_customizations/postgresql.cnpg.io/Cluster/actions/testdata/cluster_restart.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
apiVersion: postgresql.cnpg.io/v1 | ||
kind: Cluster | ||
metadata: | ||
annotations: | ||
kubectl.kubernetes.io/restartedAt: "0001-01-01T00:00:00Z" | ||
rouke-broersma marked this conversation as resolved.
Show resolved
Hide resolved
|
||
creationTimestamp: "2025-04-25T20:44:24Z" | ||
generation: 1 | ||
name: cluster-example | ||
namespace: default | ||
resourceVersion: "20230" | ||
uid: 987fe1ba-bba7-4021-9d25-f06ca9a8c0d2 | ||
spec: | ||
imageName: ghcr.io/cloudnative-pg/postgresql:13 | ||
instances: 3 | ||
status: | ||
currentPrimary: cluster-example-1 | ||
currentPrimaryTimestamp: "2025-04-25T20:44:38.190232Z" | ||
instancesStatus: | ||
healthy: | ||
- cluster-example-1 | ||
- cluster-example-2 | ||
- cluster-example-3 | ||
phase: Cluster in healthy state | ||
targetPrimary: cluster-example-1 | ||
targetPrimaryTimestamp: "2025-04-25T20:44:26.214164Z" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.