feat(platform): add applicationDefaults value

An administrator has no single place to set what every new application
of a kind should start with, such as a storage class or a registry
mirror, so each user repeats it in every spec. The value is keyed by
the application plural and rendered into a ConfigMap in cozy-system,
which the API reads when an application is created.

Assisted-by: LLM
Signed-off-by: Myasnikov Daniil <myasnikovdaniil2001@gmail.com>
This commit is contained in:
Myasnikov Daniil committed 2026-11-26 14:20:05 +00:00
1 parent c51ea43fee
commit e43dac3a69
3 files changed
+137

No files matched your search

@@ -0,0 +1,11 @@
{{- $defaults := .Values.applicationDefaults }}
{{- if kindIs "invalid" $defaults }}
{{- $defaults = dict }}
{{- end }}
apiVersion: v1
kind: ConfigMap
metadata:
name: cozystack-application-defaults
namespace: cozy-system
data:
defaults.json: {{ $defaults | toJson | quote }}
@@ -0,0 +1,51 @@
suite: installation application defaults
templates:
- templates/application-defaults.yaml
- templates/apps.yaml
tests:
- it: renders an empty configuration as a JSON object
template: templates/application-defaults.yaml
asserts:
- isKind:
of: ConfigMap
- equal:
path: metadata.name
value: cozystack-application-defaults
- equal:
path: metadata.namespace
value: cozy-system
- equal:
path: data["defaults.json"]
value: '{}'
- it: treats a null Helm value as empty configuration
template: templates/application-defaults.yaml
set:
applicationDefaults: null
asserts:
- equal:
path: data["defaults.json"]
value: '{}'
- it: stores partial specs by application plural
template: templates/application-defaults.yaml
set:
applicationDefaults:
widgets:
enabled: false
replicas: 0
options: {}
otherwidgets:
size: small
asserts:
- equal:
path: data["defaults.json"]
value: '{"otherwidgets":{"size":"small"},"widgets":{"enabled":false,"options":{},"replicas":0}}'
- it: does not forward defaults to chart values
template: templates/apps.yaml
set:
applicationDefaults:
widgets:
uniqueDefaultsMarker: secret-value
asserts:
- notMatchRegex:
path: stringData["values.yaml"]
pattern: 'applicationDefaults|uniqueDefaultsMarker|cozystack-application-defaults'
+75
View File
@@ -1,3 +1,78 @@
# Partial application specs, keyed by ApplicationDefinition.spec.application.plural.
# Applies to every application, including external catalogs. Precedence:
# user-supplied values > applicationDefaults > developer chart/schema defaults.
# The API applies installation defaults only on creation, including apply-create
# and dry-run previews (a dry-run stores nothing), and saves them in
# HelmRelease.spec.values. Changes here never modify or re-render existing
# applications; edit their saved spec to change their settings.
#
# Nonempty objects with declared properties merge recursively. Arrays, dictionaries
# (additionalProperties), free-form objects and objects whose schema marks
# x-kubernetes-map-type: atomic are replaced as a whole, so a pool that sets its
# own registryMirrors never receives platform entries. Explicit {}, [], false, 0,
# "" and permitted null values win. An empty object disables installation defaults
# for that object.
# An object whose children are alternatives that each stand complete carries the
# atomic marker, or a default for one child is merged into an application that
# chose another. In the platform packages that is the worker image of a node pool,
# a vm-disk source and the custom OIDC configuration of a Kubernetes cluster and
# of a monitoring stack. docs/agents/overview.md says when the marker fits and when
# it does not.
# Existing normalization of required, non-nullable null fields still applies.
# A null set here for a field that also has a developer default is stored as null
# by kubectl and Terraform, but the dashboard form shows the developer default and
# stores that instead.
# Quote quantities such as cpu: "2". The dashboard form validates integer-or-string
# fields as strings and rejects a number, although the API accepts it.
# Terraform and other clients may send their own defaults; those are user values
# and take precedence. Developer defaults retain their chart/schema behavior.
#
# The platform renders cozy-system/cozystack-application-defaults with defaults.json.
# The merge runs only in Go. The dashboard asks for one server-side dry-run when
# the order page opens and submits the displayed spec; edit uses saved values. It
# does not read the ConfigMap or compute defaults locally and needs no extra
# ConfigMap RBAC. Missing configuration means no installation defaults. Invalid
# JSON, structure or reserved top-level fields also skip defaulting: creation
# continues with the submitted spec, ordinary validation/admission still runs, and
# the client gets a warning. These checks cover the whole map, so one entry that is
# not an object, or one reserved top-level field in any entry, makes every create
# of every application skip defaults until it is fixed. The warning does not say
# why; the reason is in the cozystack-api log.
# Before merging, the API checks the selected entry against its application's
# OpenAPI schema. Unknown fields require an explicit dictionary or free-form
# declaration. Properties of an object that merges recursively may be omitted.
# What is stored as a whole must be complete: array rows, dictionary values,
# free-form objects and atomic objects are checked with their required fields and
# their own oneOf. The oneOf of an object that merges recursively is not
# evaluated, since it cannot be judged on a partial object.
# Invalid configured values or missing/unreadable schemas skip the selected entry
# without merging any part of it. Other applications' schemas are checked when
# creating their instances. Saving this ConfigMap does not validate its payload;
# inspect the result with kubectl create --dry-run=server -o yaml and a name that
# is not in use, and again after upgrading an application, whose new schema may no
# longer accept a configured value.
# A plural that matches no application gives no message, so a mistyped key does
# nothing. List the served plurals with:
# kubectl get applicationdefinitions -o custom-columns=NAME:.metadata.name,PLURAL:.spec.application.plural
# Validating admission and policies see the merged spec; a mutating webhook runs
# before the defaults are applied and does not.
# Do not put secrets here. Applied values are visible in application specs.
# These values are not forwarded through cozystack-values or valuesFrom.
#
# Example:
# applicationDefaults:
# postgreses:
# storageClass: replicated
# size: 20Gi
# kubernetesnodeses:
# talos:
# imageFactoryURL: https://factory.example.com
# installerRepository: registry.example.com/installer
# registryMirrors:
# ghcr.io:
# endpoints: [https://registry.example.com]
applicationDefaults: {}
sourceRef:
kind: OCIRepository
name: cozystack-platform