diff --git a/resource_customizations/argoproj.io/Application/actions/actions_test.yaml b/resource_customizations/argoproj.io/Application/actions/actions_test.yaml new file mode 100644 index 0000000000000..e5d1238dc8cc6 --- /dev/null +++ b/resource_customizations/argoproj.io/Application/actions/actions_test.yaml @@ -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 \ No newline at end of file diff --git a/resource_customizations/argoproj.io/Application/actions/discovery.lua b/resource_customizations/argoproj.io/Application/actions/discovery.lua new file mode 100644 index 0000000000000..cc8baa61cbf3c --- /dev/null +++ b/resource_customizations/argoproj.io/Application/actions/discovery.lua @@ -0,0 +1,3 @@ +actions = {} +actions["toggle-auto-sync"] = {} +return actions diff --git a/resource_customizations/argoproj.io/Application/actions/toggle-auto-sync/action.lua b/resource_customizations/argoproj.io/Application/actions/toggle-auto-sync/action.lua new file mode 100644 index 0000000000000..52dcf475a3d96 --- /dev/null +++ b/resource_customizations/argoproj.io/Application/actions/toggle-auto-sync/action.lua @@ -0,0 +1,18 @@ +function toggleAutoSync(obj) + if obj.spec.syncPolicy and obj.spec.syncPolicy.automated then + obj.spec.syncPolicy.automated = nil + 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) \ No newline at end of file diff --git a/resource_customizations/argoproj.io/Application/health.lua b/resource_customizations/argoproj.io/Application/health.lua new file mode 100644 index 0000000000000..ab192593c9cd5 --- /dev/null +++ b/resource_customizations/argoproj.io/Application/health.lua @@ -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 \ No newline at end of file diff --git a/resource_customizations/argoproj.io/Application/health_test.lua b/resource_customizations/argoproj.io/Application/health_test.lua new file mode 100644 index 0000000000000..1ba6ca10d5ab2 --- /dev/null +++ b/resource_customizations/argoproj.io/Application/health_test.lua @@ -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 \ No newline at end of file diff --git a/server/application/application.go b/server/application/application.go index 3b027a196af96..2cc22716fec4e 100644 --- a/server/application/application.go +++ b/server/application/application.go @@ -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 }