Fix concurrency issues with helm install

Address a race condition that arises when running two `helm install`
commands, both of which specify a namespace that does not already exist.

In this specific instance, attempting to create a `namespace` which
already exists shouldn't be a failure which causes `helm install` to
terminate.
pull/4135/head
mattjmcnaughton 7 years ago
parent 3771ef8635
commit 53c8e9b67e

@ -40,7 +40,16 @@ func getNamespace(client internalclientset.Interface, namespace string) (*core.N
func ensureNamespace(client internalclientset.Interface, namespace string) error {
_, err := getNamespace(client, namespace)
if err != nil && errors.IsNotFound(err) {
return createNamespace(client, namespace)
err = createNamespace(client, namespace)
// If multiple commands which run `ensureNamespace` are run in
// parallel, then protect against the race condition in which
// the namespace did not exist when `getNamespace` was executed,
// but did exist when `createNamespace` was executed. If that
// happens, we can just proceed as normal.
if errors.IsAlreadyExists(err) {
return nil
}
}
return err
}

@ -98,8 +98,6 @@ type Engine interface {
type KubeClient interface {
// Create creates one or more resources.
//
// namespace must contain a valid existing namespace.
//
// reader must contain a YAML stream (one or more YAML documents separated
// by "\n---\n").
Create(namespace string, reader io.Reader, timeout int64, shouldWait bool) error

Loading…
Cancel
Save