Apply suggestions from code review

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: MrJack <36191829+biagiopietro@users.noreply.github.com>
pull/31616/head
MrJack 3 weeks ago committed by GitHub
parent a2624e633b
commit 74dc48a3ed
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -421,22 +421,25 @@ func (i *Install) RunWithContext(ctx context.Context, ch ci.Charter, vals map[st
// Bail out here if it is a dry run
if isDryRun(i.DryRunStrategy) {
// For server-side dry-run, validate resources against the API server
// For server-side dry-run, validate resources against the API server.
// Force server-side apply in this path because kube dry-run semantics are
// only honored by the server-side apply create/update code paths.
if i.DryRunStrategy == DryRunServer {
serverSideDryRun := true
var err error
if len(toBeAdopted) == 0 && len(resources) > 0 {
_, err = i.cfg.KubeClient.Create(
resources,
kube.ClientCreateOptionServerSideApply(i.ServerSideApply, false),
kube.ClientCreateOptionServerSideApply(serverSideDryRun, false),
kube.ClientCreateOptionDryRun(true),
)
} else if len(resources) > 0 {
updateThreeWayMergeForUnstructured := i.TakeOwnership && !i.ServerSideApply
updateThreeWayMergeForUnstructured := i.TakeOwnership && !serverSideDryRun
_, err = i.cfg.KubeClient.Update(
toBeAdopted,
resources,
kube.ClientUpdateOptionForceReplace(i.ForceReplace),
kube.ClientUpdateOptionServerSideApply(i.ServerSideApply, i.ForceConflicts),
kube.ClientUpdateOptionServerSideApply(serverSideDryRun, i.ForceConflicts),
kube.ClientUpdateOptionDryRun(true),
kube.ClientUpdateOptionThreeWayMergeForUnstructured(updateThreeWayMergeForUnstructured),
kube.ClientUpdateOptionUpgradeClientSideFieldManager(true),

@ -400,12 +400,17 @@ func (u *Upgrade) performUpgrade(ctx context.Context, originalRelease, upgradedR
u.cfg.Logger().Debug("dry run for release", "name", upgradedRelease.Name)
// For server-side dry-run, validate resources against the API server
if u.DryRunStrategy == DryRunServer {
upgradeClientSideFieldManager := isReleaseApplyMethodClientSideApply(originalRelease.ApplyMethod) && serverSideApply
// Ensure this validation request is strictly non-mutating by always using
// server-side apply and disabling force-replace, regardless of the user's
// normal upgrade options.
dryRunServerSideApply := true
dryRunForceReplace := false
upgradeClientSideFieldManager := isReleaseApplyMethodClientSideApply(originalRelease.ApplyMethod) && dryRunServerSideApply
_, err := u.cfg.KubeClient.Update(
current,
target,
kube.ClientUpdateOptionForceReplace(u.ForceReplace),
kube.ClientUpdateOptionServerSideApply(serverSideApply, u.ForceConflicts),
kube.ClientUpdateOptionForceReplace(dryRunForceReplace),
kube.ClientUpdateOptionServerSideApply(dryRunServerSideApply, u.ForceConflicts),
kube.ClientUpdateOptionDryRun(true),
kube.ClientUpdateOptionUpgradeClientSideFieldManager(upgradeClientSideFieldManager),
)

Loading…
Cancel
Save