Fix crash when rancherd patches local cluster #1100
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.
Issue: rancher/rancher#51980
Problem
#410 introduced data directory validation to the webhook, designed to prevent users from changing data directories once the cluster has been created. Harvester leverages rancherd, which is effectively a self-bootstrapping mechanism for creating the Rancher local cluster. Part of this bootstrapping involves patching the local cluster to set the rkeConfig: {}, which result in Rancher reconciling it like any other normal CAPI cluster.
Previously, the webhook did not come up quick enough in the rancherd process, but now the webhook and it's related validatingwebhookconfiguration exists before the cluster can be patched. The data directory validation causes the webhook to panic (and reject the request), as it was not expected that a cluster would go from an rkeConfig with a nil value, to one without one.
Solution
if
oldCluster.Spec.RKEConfig == nil, accept the request.CheckList