From 00ea8f485bad79b06b272d3557322bf7bd16b4a6 Mon Sep 17 00:00:00 2001 From: Doug Davis Date: Wed, 28 Mar 2018 13:16:00 -0700 Subject: [PATCH] add a feature gate to disable instance locking Signed-off-by: Doug Davis --- .../servicecatalog/validation/instance.go | 27 ++++++++++++------- pkg/features/features.go | 7 +++++ 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/pkg/apis/servicecatalog/validation/instance.go b/pkg/apis/servicecatalog/validation/instance.go index ebd3fbec2c8..f758b95db09 100644 --- a/pkg/apis/servicecatalog/validation/instance.go +++ b/pkg/apis/servicecatalog/validation/instance.go @@ -23,6 +23,8 @@ import ( sc "github.com/kubernetes-incubator/service-catalog/pkg/apis/servicecatalog" "github.com/kubernetes-incubator/service-catalog/pkg/controller" + scfeatures "github.com/kubernetes-incubator/service-catalog/pkg/features" + utilfeature "k8s.io/apiserver/pkg/util/feature" ) // validateServiceInstanceName is the validation function for Instance names. @@ -260,20 +262,25 @@ func validateServiceInstanceUpdate(instance *sc.ServiceInstance) field.ErrorList func internalValidateServiceInstanceUpdateAllowed(new *sc.ServiceInstance, old *sc.ServiceInstance) field.ErrorList { errors := field.ErrorList{} - oldUID := "" - newUID := "" + // If the DisableInstanceLocking feature is not set then only allow the + // same user to edit the Instance. + if !utilfeature.DefaultFeatureGate.Enabled(scfeatures.DisableInstanceLocking) { + oldUID, newUID := "", "" - if old.Spec.UserInfo != nil { - oldUID = old.Spec.UserInfo.UID - } + if old.Spec.UserInfo != nil { + oldUID = old.Spec.UserInfo.UID + } - if new.Spec.UserInfo != nil { - newUID = new.Spec.UserInfo.UID - } + if new.Spec.UserInfo != nil { + newUID = new.Spec.UserInfo.UID + } + + if old.Generation != new.Generation && old.Status.CurrentOperation != "" && oldUID != newUID { + errors = append(errors, field.Forbidden(field.NewPath("spec"), "Another update for this service instance is in progress")) + } - if old.Generation != new.Generation && old.Status.CurrentOperation != "" && oldUID != newUID { - errors = append(errors, field.Forbidden(field.NewPath("spec"), "Another update for this service instance is in progress")) } + if old.Spec.ClusterServicePlanExternalName != new.Spec.ClusterServicePlanExternalName && new.Spec.ClusterServicePlanRef != nil { errors = append(errors, field.Forbidden(field.NewPath("spec").Child("clusterServicePlanRef"), "clusterServicePlanRef must not be present when clusterServicePlanExternalName is being changed")) } diff --git a/pkg/features/features.go b/pkg/features/features.go index 037617d9129..f59633c7740 100644 --- a/pkg/features/features.go +++ b/pkg/features/features.go @@ -52,6 +52,12 @@ const ( // owner: @eriknelson & @jeremyrickard // alpha: v0.1.10 NamespacedServiceBroker utilfeature.Feature = "NamespacedServiceBroker" + + // DisableInstanceLocking disables the locking of Instances so that + // more than one user can modify an Instance at a time. + // owner: @duglin + // alpha: v0.1.12 + DisableInstanceLocking utilfeature.Feature = "DisableInstanceLocking" ) func init() { @@ -66,4 +72,5 @@ var defaultServiceCatalogFeatureGates = map[utilfeature.Feature]utilfeature.Feat OriginatingIdentity: {Default: false, PreRelease: utilfeature.Alpha}, AsyncBindingOperations: {Default: false, PreRelease: utilfeature.Alpha}, NamespacedServiceBroker: {Default: false, PreRelease: utilfeature.Alpha}, + DisableInstanceLocking: {Default: false, PreRelease: utilfeature.Alpha}, }