Skip to content

Commit 4b49594

Browse files
staeblerkibbles-n-bytes
authored andcommitted
Allow deprovision after change to non-existent plan (openshift#1557)
1 parent c6e446e commit 4b49594

File tree

2 files changed

+80
-3
lines changed

2 files changed

+80
-3
lines changed

pkg/apis/servicecatalog/validation/instance.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,15 @@ func validateServiceInstanceUpdate(instance *sc.ServiceInstance) field.ErrorList
250250
if instance.Spec.ClusterServiceClassRef == nil {
251251
allErrs = append(allErrs, field.Required(field.NewPath("spec").Child("clusterServiceClassRef"), "serviceClassRef is required when currentOperation is present"))
252252
}
253-
if instance.Spec.ClusterServicePlanRef == nil {
254-
allErrs = append(allErrs, field.Required(field.NewPath("spec").Child("clusterServicePlanRef"), "servicePlanRef is required when currentOperation is present"))
253+
if instance.Status.CurrentOperation != sc.ServiceInstanceOperationDeprovision {
254+
if instance.Spec.ClusterServicePlanRef == nil {
255+
allErrs = append(allErrs, field.Required(field.NewPath("spec").Child("clusterServicePlanRef"), "servicePlanRef is required when currentOperation is present and not Deprovision"))
256+
}
257+
} else {
258+
if instance.Spec.ClusterServicePlanRef == nil &&
259+
(instance.Status.ExternalProperties == nil || instance.Status.ExternalProperties.ClusterServicePlanExternalID == "") {
260+
allErrs = append(allErrs, field.Invalid(field.NewPath("status").Child("currentOperation"), instance.Status.CurrentOperation, "spec.clusterServicePlanRef or status.externalProperties.clusterServicePlanExternalID is required when currentOperation is Deprovision"))
261+
}
255262
}
256263
}
257264
return allErrs

pkg/apis/servicecatalog/validation/instance_test.go

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,17 @@ func validServiceInstanceWithInProgressProvision() *servicecatalog.ServiceInstan
8282
return instance
8383
}
8484

85+
func validServiceInstanceWithInProgressDeprovision() *servicecatalog.ServiceInstance {
86+
instance := validServiceInstance()
87+
instance.Generation = 2
88+
instance.Status.ReconciledGeneration = 1
89+
instance.Status.CurrentOperation = servicecatalog.ServiceInstanceOperationDeprovision
90+
now := metav1.Now()
91+
instance.Status.OperationStartTime = &now
92+
instance.Status.ExternalProperties = validServiceInstancePropertiesState()
93+
return instance
94+
}
95+
8596
func validServiceInstancePropertiesState() *servicecatalog.ServiceInstancePropertiesState {
8697
return &servicecatalog.ServiceInstancePropertiesState{
8798
ClusterServicePlanExternalName: "plan-name",
@@ -516,7 +527,7 @@ func TestValidateServiceInstance(t *testing.T) {
516527
valid: false,
517528
},
518529
{
519-
name: "in-progress operation with missing service plan ref",
530+
name: "in-progress provision with missing service plan ref",
520531
instance: func() *servicecatalog.ServiceInstance {
521532
i := validServiceInstanceWithInProgressProvision()
522533
i.Spec.ClusterServicePlanRef = nil
@@ -525,6 +536,65 @@ func TestValidateServiceInstance(t *testing.T) {
525536
create: false,
526537
valid: false,
527538
},
539+
{
540+
name: "valid in-progress deprovision",
541+
instance: validServiceInstanceWithInProgressDeprovision(),
542+
create: false,
543+
valid: true,
544+
},
545+
{
546+
name: "in-progress deprovision with missing service plan ref",
547+
instance: func() *servicecatalog.ServiceInstance {
548+
i := validServiceInstanceWithInProgressDeprovision()
549+
i.Spec.ClusterServicePlanRef = nil
550+
return i
551+
}(),
552+
create: false,
553+
valid: true,
554+
},
555+
{
556+
name: "in-progress deprovision with missing external properties",
557+
instance: func() *servicecatalog.ServiceInstance {
558+
i := validServiceInstanceWithInProgressDeprovision()
559+
i.Status.ExternalProperties = nil
560+
return i
561+
}(),
562+
create: false,
563+
valid: true,
564+
},
565+
{
566+
name: "in-progress deprovision with missing external properties plan ID",
567+
instance: func() *servicecatalog.ServiceInstance {
568+
i := validServiceInstanceWithInProgressDeprovision()
569+
i.Status.ExternalProperties.ClusterServicePlanExternalID = ""
570+
return i
571+
}(),
572+
create: false,
573+
// not valid because ClusterServicePlanExternalID is required when ExternalProperties is present
574+
valid: false,
575+
},
576+
{
577+
name: "in-progress deprovision with missing service plan ref and external properties",
578+
instance: func() *servicecatalog.ServiceInstance {
579+
i := validServiceInstanceWithInProgressDeprovision()
580+
i.Spec.ClusterServicePlanRef = nil
581+
i.Status.ExternalProperties = nil
582+
return i
583+
}(),
584+
create: false,
585+
valid: false,
586+
},
587+
{
588+
name: "in-progress deprovision with missing service plan ref and external properties plan ID",
589+
instance: func() *servicecatalog.ServiceInstance {
590+
i := validServiceInstanceWithInProgressDeprovision()
591+
i.Spec.ClusterServicePlanRef = nil
592+
i.Status.ExternalProperties.ClusterServicePlanExternalID = ""
593+
return i
594+
}(),
595+
create: false,
596+
valid: false,
597+
},
528598
{
529599
name: "external and k8s name specified in Spec.PlanReference",
530600
instance: func() *servicecatalog.ServiceInstance {

0 commit comments

Comments
 (0)