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 the bug that delete_local_data is dropped #3511

Merged
merged 1 commit into from
Mar 1, 2024

Conversation

jiaqiluo
Copy link
Member

@jiaqiluo jiaqiluo commented Feb 29, 2024

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:

  • ignore_daemonsets v.s. ignoreDaemonSets
  • delete_local_data v.s. deleteLocalData
  • grace_period v.s gracePeriod

In the function parseNodeDrainInput, RKE uses ghodssyaml.Unmarshal and ghodssyaml.Marshal to covert the user's config into the NodeDrainInput object. those two functions internally use json.Marshal and json.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 about ghodssyaml.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 issue

upgrade_strategy:
  max_unavailable_worker: 1
  max_unavailable_controlplane: 1
  drain: true
  node_drain_input:
    force: false
    ignore_daemonsets: true
    delete_local_data: true

The 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"

…odssyaml.Marshal function due to the same field has different names in YAML tag and JSON tag
@jiaqiluo jiaqiluo requested review from a team as code owners February 29, 2024 00:53
@jiaqiluo jiaqiluo requested a review from a team February 29, 2024 20:53
@jiaqiluo jiaqiluo merged commit 9a498c6 into rancher:release/v1.5 Mar 1, 2024
1 check passed
@jiaqiluo jiaqiluo deleted the fix-node-drain branch March 1, 2024 22:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants