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 months ago
parent d136bf0aa6
commit 0c5a044bac

@ -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 // Bail out here if it is a dry run
if isDryRun(i.DryRunStrategy) { 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 { if i.DryRunStrategy == DryRunServer {
serverSideDryRun := true
var err error var err error
if len(toBeAdopted) == 0 && len(resources) > 0 { if len(toBeAdopted) == 0 && len(resources) > 0 {
_, err = i.cfg.KubeClient.Create( _, err = i.cfg.KubeClient.Create(
resources, resources,
kube.ClientCreateOptionServerSideApply(i.ServerSideApply, false), kube.ClientCreateOptionServerSideApply(serverSideDryRun, false),
kube.ClientCreateOptionDryRun(true), kube.ClientCreateOptionDryRun(true),
) )
} else if len(resources) > 0 { } else if len(resources) > 0 {
updateThreeWayMergeForUnstructured := i.TakeOwnership && !i.ServerSideApply updateThreeWayMergeForUnstructured := i.TakeOwnership && !serverSideDryRun
_, err = i.cfg.KubeClient.Update( _, err = i.cfg.KubeClient.Update(
toBeAdopted, toBeAdopted,
resources, resources,
kube.ClientUpdateOptionForceReplace(i.ForceReplace), kube.ClientUpdateOptionForceReplace(i.ForceReplace),
kube.ClientUpdateOptionServerSideApply(i.ServerSideApply, i.ForceConflicts), kube.ClientUpdateOptionServerSideApply(serverSideDryRun, i.ForceConflicts),
kube.ClientUpdateOptionDryRun(true), kube.ClientUpdateOptionDryRun(true),
kube.ClientUpdateOptionThreeWayMergeForUnstructured(updateThreeWayMergeForUnstructured), kube.ClientUpdateOptionThreeWayMergeForUnstructured(updateThreeWayMergeForUnstructured),
kube.ClientUpdateOptionUpgradeClientSideFieldManager(true), kube.ClientUpdateOptionUpgradeClientSideFieldManager(true),

@ -399,12 +399,17 @@ func (u *Upgrade) performUpgrade(ctx context.Context, originalRelease, upgradedR
u.cfg.Logger().Debug("dry run for release", "name", upgradedRelease.Name) u.cfg.Logger().Debug("dry run for release", "name", upgradedRelease.Name)
// For server-side dry-run, validate resources against the API server // For server-side dry-run, validate resources against the API server
if u.DryRunStrategy == DryRunServer { 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( _, err := u.cfg.KubeClient.Update(
current, current,
target, target,
kube.ClientUpdateOptionForceReplace(u.ForceReplace), kube.ClientUpdateOptionForceReplace(dryRunForceReplace),
kube.ClientUpdateOptionServerSideApply(serverSideApply, u.ForceConflicts), kube.ClientUpdateOptionServerSideApply(dryRunServerSideApply, u.ForceConflicts),
kube.ClientUpdateOptionDryRun(true), kube.ClientUpdateOptionDryRun(true),
kube.ClientUpdateOptionUpgradeClientSideFieldManager(upgradeClientSideFieldManager), kube.ClientUpdateOptionUpgradeClientSideFieldManager(upgradeClientSideFieldManager),
) )

Loading…
Cancel
Save