fix the bug that delete_local_data is dropped #3511
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.
fix the bug where the value of delete_local_data is dropped by the ghodssyaml.Marshal function due to the same field has different names in YAML tag and JSON tag
Issue:
#3412
rancher/rancher#44564
Problem
In the declaration of the type
NodeDrainInput
(here), the name of the same field is different in the YAML format v.s. JSON format:In the function parseNodeDrainInput, RKE uses
ghodssyaml.Unmarshal
andghodssyaml.Marshal
to covert the user's config into theNodeDrainInput
object. those two functions internally usejson.Marshal
andjson.Unmarshal
to do the convention. However because the names of the same field are different, those values are dropped in the final output. This is also why there is inline comment aboutghodssyaml.Marshal
is losing the user-provided value for GracePeriod.Solution
Add the value of
delete_local_data
back if it is set in the cluster config file.Testing
The fix is validated by using a local build of RKE from this PR and a config file that contains the
upgrade_strategy
from the linked issueThe following message in the output indicates the value
delete_local_data
is preserved:INFO[0063] [controlplane] Processing controlplane hosts for upgrade 1 at a time INFO[0063] [controlplane] Parameters provided to drain command: "Force: false, IgnoreAllDaemonSets: true, DeleteEmptyDirData: true, Timeout: 2m0s, GracePeriodSeconds: -1"