Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
tests:
- given:
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: test-app
spec:
syncPolicy:
automated:
enabled: true
prune: true
selfHeal: true
when:
action: toggle-auto-sync
expect:
spec:
syncPolicy:
automated:
enabled: false
prune: true
selfHeal: true

- given:
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: test-app
spec:
syncPolicy:
automated:
enabled: false
prune: true
selfHeal: true
when:
action: toggle-auto-sync
expect:
spec:
syncPolicy:
automated:
enabled: true
prune: true
selfHeal: true

- given:
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: test-app
spec: {}
when:
action: toggle-auto-sync
expect:
spec:
syncPolicy:
automated:
enabled: false
prune: false
selfHeal: false
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
actions = {}
actions["toggle-auto-sync"] = {}
return actions
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
function toggleAutoSync(obj)
if obj.spec.syncPolicy and obj.spec.syncPolicy.automated then
obj.spec.syncPolicy.automated = nil
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing a check to set obj.spec.syncPolicy.automated.enabled = false if it is currently true

if not next(obj.spec.syncPolicy) then
obj.spec.syncPolicy = nil
end
else
if not obj.spec.syncPolicy then
obj.spec.syncPolicy = {}
end
obj.spec.syncPolicy.automated = {
enabled = true
}
end
return obj
end

return toggleAutoSync(obj)
12 changes: 12 additions & 0 deletions resource_customizations/argoproj.io/Application/health.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
health_status = {}
if obj.status ~= nil then
if obj.status.health ~= nil then
health_status.status = obj.status.health.status
health_status.message = obj.status.health.message
end
end
if health_status.status == nil then
health_status.status = "Progressing"
health_status.message = "Waiting for application to be reconciled"
end
return health_status
47 changes: 47 additions & 0 deletions resource_customizations/argoproj.io/Application/health_test.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
tests = {
{
given = {
status = {
health = {
status = "Healthy",
message = "Application is healthy"
}
}
},
want = {
status = "Healthy",
message = "Application is healthy"
}
},
{
given = {
status = {
health = {
status = "Degraded",
message = "Application has issues"
}
}
},
want = {
status = "Degraded",
message = "Application has issues"
}
},
{
given = {},
want = {
status = "Progressing",
message = "Waiting for application to be reconciled"
}
}
}

for _, test in ipairs(tests) do
local state = health(test.given)
if state.status ~= test.want.status then
error(string.format("Expected status %s but got %s", test.want.status, state.status))
end
if state.message ~= test.want.message then
error(string.format("Expected message '%s' but got '%s'", test.want.message, state.message))
end
end
7 changes: 7 additions & 0 deletions server/application/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -2380,6 +2380,13 @@ 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,
})

if err = s.enf.EnforceErr(ctx.Value("claims"), rbac.ResourceApplications, rbacRequest, app.RBACName(s.ns)); err != nil {
return nil, nil, nil, nil, err
}
Expand Down
Loading