Move locks from global var to the structs

Signed-off-by: Stephane Moser <moser.sts@gmail.com>
pull/9180/head
Stephane Moser 4 years ago
parent 660183d659
commit c6c4157c43

@ -69,8 +69,6 @@ const notesFileSuffix = "NOTES.txt"
const defaultDirectoryPermission = 0755
var installLock sync.Mutex
// Install performs an installation operation.
type Install struct {
cfg *Configuration
@ -109,6 +107,8 @@ type Install struct {
// OutputDir/<ReleaseName>
UseReleaseName bool
PostRenderer postrender.PostRenderer
// Lock to control raceconditions when the process receives a SIGTERM
Lock sync.Mutex
}
// ChartPathOptions captures common options used for controlling chart paths
@ -420,12 +420,12 @@ func (i *Install) handleSignals(c chan<- resultMessage, rel *release.Release) {
}()
}
func (i *Install) reportToRun(c chan<- resultMessage, rel *release.Release, err error) {
installLock.Lock()
i.Lock.Lock()
if err != nil {
rel, err = i.failRelease(rel, err)
}
c <- resultMessage{r: rel, e: err}
installLock.Unlock()
i.Lock.Unlock()
}
func (i *Install) failRelease(rel *release.Release, err error) (*release.Release, error) {
rel.SetStatus(release.StatusFailed, fmt.Sprintf("Release %q failed: %s", i.ReleaseName, err.Error()))

@ -40,8 +40,6 @@ import (
"helm.sh/helm/v3/pkg/storage/driver"
)
var upgradeLock sync.Mutex
// Upgrade is the action for upgrading releases.
//
// It provides the implementation of 'helm upgrade'.
@ -106,6 +104,8 @@ type Upgrade struct {
DisableOpenAPIValidation bool
// Get missing dependencies
DependencyUpdate bool
// Lock to control raceconditions when the process receives a SIGTERM
Lock sync.Mutex
}
type resultMessage struct {
@ -329,12 +329,12 @@ func (u *Upgrade) performUpgrade(originalRelease, upgradedRelease *release.Relea
// In that case the upgrade will finish before the rollback is finished so it is necessary to wait for the rollback to finish.
// The rollback will be trigger by the function failRelease
func (u *Upgrade) reportToPerformUpgrade(c chan<- resultMessage, rel *release.Release, created kube.ResourceList, err error) {
upgradeLock.Lock()
u.Lock.Lock()
if err != nil {
rel, err = u.failRelease(rel, created, err)
}
c <- resultMessage{r: rel, e: err}
upgradeLock.Unlock()
u.Lock.Unlock()
}
// Setup listener for SIGINT and SIGTERM

Loading…
Cancel
Save