U/kkasp/tron 2414 fix broken config parse #1045
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In #1043 I added a config value for the number of items in a write transaction. The previous validation flow (i.e.
validate_contents
->post_validation
->set_defaults
) caused errors whenpost_validation
attempted to access this optional field when it was omitted in the config.Since
set_defaults
hadn't run yet, accessing the key (using.get()
) would yieldNone
in the dictionary passed topost_validation
, leading to crashes if the logic expected a default value to be present (e.g. checkingif not 1 <= max_transact <= 100
would check1 <= None
).What
This change modifies the core Validator to run
set_defaults
beforepost_validation
. The new order ofvalidate_contents
->set_defaults
->post_validation
prevents these errors by applying defaults beforepost_validation
runs.Why
Even without the specific config issue I encountered, this new order is more intuitive as
post_validation
now validates the intended state of the config object, which includes any applicable defaults. It also simplifies futurepost_validation
logic, as we don't need to explicitly handle cases where an optional key with a default might be missing from the input dictionary.SecretVolumeItem
I needed to handle the case where the items key (which defaults to None) was explicitly set to None by
set_defaults
beforepost_validation
ran. The previous logic would fail with a TypeError when checkinglen(None)
. The fix usesvalid_input.get("items") or []
to ensure iteration works.default_mode
My changes to the Validator broke some tests and in the course of addressing those I noticed that the logic for propagating a SecretVolume's
default_mode
to items lacking their own mode was flawed. We were callingitem._replace()
but ignoring the return, meaningdefault_mode
was never actually applied. My fix uses the value from_replace()
and reconstructs theitems
tuple if modifications were needed.The impact of this is minimal right now, both because it's unused (only defined in one disabled job), and because "If not specified, the volume defaultMode will be used." (from V1SecretVolumeSource.items -> V1KeyToPath). That said, we probably don't want to rely on a fallback, especially when we allow for explicit config.
Example
Tron Job config with secret_volumes like:
The podspec produced:
TestValidMesosAction
This check needs adjustment because
set_defaults
now ensures keys likedocker_image
(which defaults toNone
) are present. This check feels pretty irrelevant these days, so I opted to remove it instead of updating.