Open piotrminkina opened 1 year ago
First of all, I suggest not to use default
for the required
property. It makes no sense for the user: if property is marked as required, it has to be set by the user in the ConfigMap. There is an issue https://github.com/deckhouse/deckhouse/issues/2987 that inspired a long discussion about default
/required
contract. We came to a conclusion that required property should not have a default value.
Second, it seems you think of defaults
in JSON schema as a fillers for missing values in the ConfigMap. In short, these defaults
are default values that user may override in the ConfigMap. Addon-operator instantiates defaults starting from the empty map before merging ConfigMap, so it can't support patternProperties by design, see ApplyDefault and moduleManager.GlobalValues.
Overall you've faced a triple combo:
defaults: {}
for the child
and treats parent: {}
as validThe workaround is to define a default for the root object if child
is optional or remove a default if child
is required:
type: object
additionalProperties: false
default:
parent:
child: {}
patternProperties:
^parent$:
type: object
properties:
child:
type: object
type: object
additionalProperties: false
patternProperties:
^parent$:
type: object
required:
- child
properties:
child:
type: object
Expected behavior (what you expected to happen): The configuration is validated correctly. The default values for the fields in the object defined as
patternProperties
should be in the file pointed to by theVALUES_PATH
variable.Actual behavior (what actually happened): The configuration is validated correctly. The default values for the fields in the object defined as
patternProperties
are not available in the file pointed to by theVALUES_PATH
variable.Steps to reproduce:
/global-hooks/openapi/config-values.yaml
with the following content:Create a executable hook file
/global-hooks/check-if-child-object-exists.bash
with the following content:msg="\"Child Object exists! {}\""
message in the console log, but you will seemsg="\"Child Object does NOT exist!\""
.Environment: