Repository: helm/helm
File: pkg/action/install.go (Go)

Code before:

// isDryRun returns true if Upgrade is set to run as a DryRun
func (i *Install) isDryRun() bool {
	if i.DryRun || i.DryRunOption == "client" || i.DryRunOption == "server" || i.DryRunOption == "true" {
		return true
	}
	return false
}

func (i *Install) performInstall(rel *release.Release, toBeAdopted kube.ResourceList, resources kube.ResourceList) (*release.Release, error) {
	var err error
	// pre-install hooks
	if !i.DisableHooks {
		if err := i.cfg.execHook(rel, release.HookPreInstall, i.Timeout); err != nil {
			return rel, fmt.Errorf("failed pre-install: %s", err)
		}
	}

	// At this point, we can do the install. Note that before we were detecting whether to
	// do an update, but it's not clear whether we WANT to do an update if the reuse is set
	// to true, since that is basically an upgrade operation.
	if len(toBeAdopted) == 0 && len(resources) > 0 {
		_, err = i.cfg.KubeClient.Create(resources)
	} else if len(resources) > 0 {
		if i.TakeOwnership {
			if kubeClient, ok := i.cfg.KubeClient.(kube.InterfaceThreeWayMerge); ok {
				_, err = kubeClient.UpdateThreeWayMerge(toBeAdopted, resources, i.Force)
			}
		} else {
			_, err = i.cfg.KubeClient.Update(toBeAdopted, resources, i.Force)
		}
	}
	if err != nil {
		return rel, err
	}

	if i.Wait {
		if i.WaitForJobs {
			err = i.cfg.KubeClient.WaitWithJobs(resources, i.Timeout)
		} else {
			err = i.cfg.KubeClient.Wait(resources, i.Timeout)
		}
		if err != nil {
			return rel, err
		}
	}

	if !i.DisableHooks {
		if err := i.cfg.execHook(rel, release.HookPostInstall, i.Timeout); err != nil {
			return rel, fmt.Errorf("failed post-install: %s", err)
		}

Review comment (refactor):
nit: You could remove this check since there is `var _ InterfaceThreeWayMerge = (*Client)(nil)` check that ensures the client implements this API. If you want to keep this check, then return an error in an `else` block

Code after:
		err := ctx.Err()
		return rel, err
	case msg := <-resultChan:
		return msg.r, msg.e
	}
}

// isDryRun returns true if Upgrade is set to run as a DryRun
func (i *Install) isDryRun() bool {
	if i.DryRun || i.DryRunOption == "client" || i.DryRunOption == "server" || i.DryRunOption == "true" {
		return true
	}
	return false
}

func (i *Install) performInstall(rel *release.Release, toBeAdopted kube.ResourceList, resources kube.ResourceList) (*release.Release, error) {
	var err error
	// pre-install hooks
	if !i.DisableHooks {
		if err := i.cfg.execHook(rel, release.HookPreInstall, i.WaitStrategy, i.Timeout); err != nil {
			return rel, fmt.Errorf("failed pre-install: %s", err)
		}
	}

	// At this point, we can do the install. Note that before we were detecting whether to
	// do an update, but it's not clear whether we WANT to do an update if the reuse is set
	// to true, since that is basically an upgrade operation.
	if len(toBeAdopted) == 0 && len(resources) > 0 {
		_, err = i.cfg.KubeClient.Create(resources)
	} else if len(resources) > 0 {
		if i.TakeOwnership {
			_, err = i.cfg.KubeClient.(kube.InterfaceThreeWayMerge).UpdateThreeWayMerge(toBeAdopted, resources, i.Force)
		} else {
			_, err = i.cfg.KubeClient.Update(toBeAdopted, resources, i.Force)
		}
	}
	if err != nil {
		return rel, err
	}

	waiter, err := i.cfg.KubeClient.GetWaiter(i.WaitStrategy)
	if err != nil {
		return rel, fmt.Errorf("failed to get waiter: %w", err)
	}

	if i.WaitForJobs {
		err = waiter.WaitWithJobs(resources, i.Timeout)
	} else {
		err = waiter.Wait(resources, i.Timeout)
	}
	if err != nil {