Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parameter validation issues #97

Merged
merged 1 commit into from
Nov 10, 2023
Merged
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
26 changes: 20 additions & 6 deletions operator/resourceclaim.py
Original file line number Diff line number Diff line change
Expand Up @@ -863,6 +863,7 @@ async def validate_with_provider(self,
parameter_values = self.spec.get('provider', {}).get('parameterValues', {})
parameter_states = self.status.get('provider', {}).get('parameterValues')

# Collect parameter values from status and resource provider defaults
for parameter in resource_provider.get_parameters():
if parameter.name not in parameter_values:
if parameter_states and parameter.name in parameter_states:
Expand All @@ -880,7 +881,7 @@ async def validate_with_provider(self,
parameter_names.add(parameter.name)
if parameter.name in parameter_values:
value = parameter_values[parameter.name]
if parameter_states:
if parameter_states != None:
if value == parameter_states.get(parameter.name):
# Unchanged from current state is automatically considered valid
# even if validation rules have changed.
Expand All @@ -894,10 +895,11 @@ async def validate_with_provider(self,
parameter.open_api_v3_schema_validator.validate(value)
except Exception as exception:
validation_errors.append(f"Parameter {parameter.name} schema validation failed: {exception}")
continue

for validation_check in parameter.validation_checks:
try:
successful = recursive_process_template_strings(
check_successful = recursive_process_template_strings(
'{{(' + validation_check.check + ')|bool}}',
variables = { **vars_, **parameter_values, "value": value }
)
Expand All @@ -916,15 +918,27 @@ async def validate_with_provider(self,
if name not in parameter_names:
validation_errors.append(f"No such parameter {name}.")

if parameter_values != parameter_states \
or validation_errors != self.status.get('provider', {}).get('validationErrors'):
if validation_errors:
if validation_errors == self.status.get('provider', {}).get('validationErrors'):
return
logger.info(f"Validation failed with {validation_errors}")
await self.merge_patch_status({
"provider": {
"name": resource_provider.name,
"validationErrors": validation_errors,
}
})
return

if parameter_values != parameter_states or 'validationErrors' in self.status.get('provider', {}):
patch = {
"provider": {
"name": resource_provider.name,
"parameterValues": parameter_values if parameter_values else None,
"validationErrors": validation_errors if validation_errors else None,
"parameterValues": parameter_values,
"validationErrors": None,
}
}

if 'resources' not in self.status:
resources = await resource_provider.get_claim_resources(
parameter_values = parameter_values,
Expand Down
3 changes: 2 additions & 1 deletion test/roles/poolboy_test_simple/tasks/test-parameters-01.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@
namespace: "{{ poolboy_test_namespace }}"
parameters:
- name: stringvar
allowUpdate: true
required: true
validation:
openAPIV3Schema:
type: sting
type: string
default: one
enum:
- one
Expand Down
6 changes: 4 additions & 2 deletions test/roles/poolboy_test_simple/tasks/test-parameters-02.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@
namespace: "{{ poolboy_test_namespace }}"
parameters:
- name: stringvar
allowUpdate: true
required: true
validation:
openAPIV3Schema:
type: sting
type: string
default: one
enum:
- one
Expand Down Expand Up @@ -79,10 +80,11 @@
namespace: "{{ poolboy_test_namespace }}"
parameters:
- name: stringvar
allowUpdate: true
required: true
validation:
openAPIV3Schema:
type: sting
type: string
default: one
enum:
- one
Expand Down
9 changes: 6 additions & 3 deletions test/roles/poolboy_test_simple/tasks/test-parameters-03.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,23 @@
namespace: "{{ poolboy_test_namespace }}"
parameters:
- name: optionalvar
allowUpdate: true
validation:
openAPIV3Schema:
type: sting
type: string
- name: requiredvar
allowUpdate: true
required: true
validation:
openAPIV3Schema:
type: sting
type: string
- name: varwithdefault
allowUpdate: true
required: true
validation:
openAPIV3Schema:
default: defaultvalue
type: sting
type: string
template:
definition:
spec:
Expand Down
6 changes: 6 additions & 0 deletions test/roles/poolboy_test_simple/tasks/test-parameters-04.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,27 @@
namespace: "{{ poolboy_test_namespace }}"
parameters:
- name: string_with_default_value
allowUpdate: true
default:
value: foo
- name: int_with_default_value
allowUpdate: true
default:
value: 23
- name: boolean_with_default_value
allowUpdate: true
default:
value: true
- name: string_with_default_template
allowUpdate: true
default:
template: "{% raw %}{{ '[0-9a-f]{8}' | strgen }}{% endraw %}"
- name: int_with_default_template
allowUpdate: true
default:
template: "{% raw %}{{ (13 + 10) | int }}{% endraw %}"
- name: boolean_with_default_template
allowUpdate: true
default:
template: "{% raw %}{{ 'true' | bool }}{% endraw %}"
template:
Expand Down
Loading
Loading