mirror of
https://github.com/argoproj/argo-cd
synced 2026-04-21 08:57:17 +00:00
Signed-off-by: vikasrao23 <vikasrao23@users.noreply.github.com> Co-authored-by: vikasrao23 <vikasrao23@users.noreply.github.com>
This commit is contained in:
parent
b8da88a288
commit
48f18e2905
5 changed files with 116 additions and 0 deletions
1
docs/operator-manual/resource_actions_builtin.md
generated
1
docs/operator-manual/resource_actions_builtin.md
generated
|
|
@ -6,6 +6,7 @@
|
|||
- [apps/StatefulSet/restart](https://github.com/argoproj/argo-cd/blob/master/resource_customizations/apps/StatefulSet/actions/restart/action.lua)
|
||||
- [apps/StatefulSet/scale](https://github.com/argoproj/argo-cd/blob/master/resource_customizations/apps/StatefulSet/actions/scale/action.lua)
|
||||
- [argoproj.io/AnalysisRun/terminate](https://github.com/argoproj/argo-cd/blob/master/resource_customizations/argoproj.io/AnalysisRun/actions/terminate/action.lua)
|
||||
- [argoproj.io/Application/toggle-auto-sync](https://github.com/argoproj/argo-cd/blob/master/resource_customizations/argoproj.io/Application/actions/toggle-auto-sync/action.lua)
|
||||
- [argoproj.io/CronWorkflow/create-workflow](https://github.com/argoproj/argo-cd/blob/master/resource_customizations/argoproj.io/CronWorkflow/actions/create-workflow/action.lua)
|
||||
- [argoproj.io/Rollout/abort](https://github.com/argoproj/argo-cd/blob/master/resource_customizations/argoproj.io/Rollout/actions/abort/action.lua)
|
||||
- [argoproj.io/Rollout/pause](https://github.com/argoproj/argo-cd/blob/master/resource_customizations/argoproj.io/Rollout/actions/pause/action.lua)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,76 @@
|
|||
tests:
|
||||
# Scenario 1: autosync enabled (enabled=nil, i.e. default) with prune+selfHeal -> disable (set enabled=false, preserve prune/selfHeal)
|
||||
- given:
|
||||
apiVersion: argoproj.io/v1alpha1
|
||||
kind: Application
|
||||
metadata:
|
||||
name: test-app
|
||||
spec:
|
||||
syncPolicy:
|
||||
automated:
|
||||
prune: true
|
||||
selfHeal: true
|
||||
when:
|
||||
action: toggle-auto-sync
|
||||
expect:
|
||||
spec:
|
||||
syncPolicy:
|
||||
automated:
|
||||
prune: true
|
||||
selfHeal: true
|
||||
enabled: false
|
||||
|
||||
# Scenario 2: autosync disabled (enabled=false) with prune+selfHeal -> enable (set enabled=true, preserve prune/selfHeal)
|
||||
- given:
|
||||
apiVersion: argoproj.io/v1alpha1
|
||||
kind: Application
|
||||
metadata:
|
||||
name: test-app
|
||||
spec:
|
||||
syncPolicy:
|
||||
automated:
|
||||
prune: true
|
||||
selfHeal: true
|
||||
enabled: false
|
||||
when:
|
||||
action: toggle-auto-sync
|
||||
expect:
|
||||
spec:
|
||||
syncPolicy:
|
||||
automated:
|
||||
prune: true
|
||||
selfHeal: true
|
||||
enabled: true
|
||||
|
||||
# Scenario 3: autosync explicitly enabled (enabled=true) -> disable
|
||||
- given:
|
||||
apiVersion: argoproj.io/v1alpha1
|
||||
kind: Application
|
||||
metadata:
|
||||
name: test-app
|
||||
spec:
|
||||
syncPolicy:
|
||||
automated:
|
||||
enabled: true
|
||||
when:
|
||||
action: toggle-auto-sync
|
||||
expect:
|
||||
spec:
|
||||
syncPolicy:
|
||||
automated:
|
||||
enabled: false
|
||||
|
||||
# Scenario 4: no automated block (autosync off) -> enable (create automated with enabled=true)
|
||||
- given:
|
||||
apiVersion: argoproj.io/v1alpha1
|
||||
kind: Application
|
||||
metadata:
|
||||
name: test-app
|
||||
spec: {}
|
||||
when:
|
||||
action: toggle-auto-sync
|
||||
expect:
|
||||
spec:
|
||||
syncPolicy:
|
||||
automated:
|
||||
enabled: true
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
local actions = {}
|
||||
local autoSyncEnabled = false
|
||||
if obj.spec ~= nil and obj.spec.syncPolicy ~= nil and obj.spec.syncPolicy.automated ~= nil then
|
||||
local enabled = obj.spec.syncPolicy.automated.enabled
|
||||
autoSyncEnabled = (enabled == true or enabled == nil)
|
||||
end
|
||||
actions["toggle-auto-sync"] = {
|
||||
["displayName"] = autoSyncEnabled and "Disable Auto-Sync" or "Enable Auto-Sync",
|
||||
["disabled"] = false
|
||||
}
|
||||
return actions
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
if obj.spec == nil then
|
||||
obj.spec = {}
|
||||
end
|
||||
if obj.spec.syncPolicy == nil then
|
||||
obj.spec.syncPolicy = {}
|
||||
end
|
||||
|
||||
local automated = obj.spec.syncPolicy.automated
|
||||
local isEnabled = automated ~= nil and (automated.enabled == true or automated.enabled == nil)
|
||||
|
||||
if isEnabled then
|
||||
-- Currently ENABLED (enabled=true or enabled=nil): disable it
|
||||
automated.enabled = false
|
||||
else
|
||||
-- Currently DISABLED (automated absent or enabled=false): enable it
|
||||
if automated == nil then
|
||||
obj.spec.syncPolicy.automated = { enabled = true }
|
||||
else
|
||||
automated.enabled = true
|
||||
end
|
||||
end
|
||||
|
||||
return obj
|
||||
|
|
@ -2540,6 +2540,11 @@ func (s *Server) getUnstructuredLiveResourceOrApp(ctx context.Context, rbacReque
|
|||
if err != nil {
|
||||
return nil, nil, nil, nil, err
|
||||
}
|
||||
app.SetGroupVersionKind(schema.GroupVersionKind{
|
||||
Group: applicationType.Group,
|
||||
Version: v1alpha1.SchemeGroupVersion.Version,
|
||||
Kind: applicationType.ApplicationKind,
|
||||
})
|
||||
err = s.enf.EnforceErr(ctx.Value("claims"), rbac.ResourceApplications, rbacRequest, app.RBACName(s.ns))
|
||||
if err != nil {
|
||||
return nil, nil, nil, nil, err
|
||||
|
|
|
|||
Loading…
Reference in a new issue