Skip to content

Commit c3b72d8

Browse files
jberkhahnDoug Davis
authored andcommitted
Enforce stricly increasing broker relistRequests (openshift#1515)
Signed-off-by: Jonathan Berkhahn <[email protected]>
1 parent 01d81e5 commit c3b72d8

File tree

2 files changed

+99
-0
lines changed

2 files changed

+99
-0
lines changed

pkg/apis/servicecatalog/validation/broker.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,10 @@ func validateClusterServiceBrokerSpec(spec *sc.ClusterServiceBrokerSpec, fldPath
148148
// ValidateClusterServiceBrokerUpdate checks that when changing from an older broker to a newer broker is okay ?
149149
func ValidateClusterServiceBrokerUpdate(new *sc.ClusterServiceBroker, old *sc.ClusterServiceBroker) field.ErrorList {
150150
allErrs := field.ErrorList{}
151+
// RelistRequests can be increasing to relist the broker, or equal to update other fields
152+
if new.Spec.RelistRequests < old.Spec.RelistRequests {
153+
allErrs = append(allErrs, field.Invalid(field.NewPath("spec").Child("relistRequests"), old.Spec.RelistRequests, "RelistRequests must be strictly increasing"))
154+
}
151155
allErrs = append(allErrs, ValidateClusterServiceBroker(new)...)
152156
return allErrs
153157
}

pkg/apis/servicecatalog/validation/broker_test.go

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,4 +344,99 @@ func TestValidateClusterServiceBroker(t *testing.T) {
344344
t.Errorf("%v: unexpected success", tc.name)
345345
}
346346
}
347+
348+
updateCases := []struct {
349+
name string
350+
newBroker *servicecatalog.ClusterServiceBroker
351+
oldBroker *servicecatalog.ClusterServiceBroker
352+
valid bool
353+
}{
354+
{
355+
name: "valid broker update - equal relistRequests value",
356+
newBroker: &servicecatalog.ClusterServiceBroker{
357+
ObjectMeta: metav1.ObjectMeta{
358+
Name: "test-broker",
359+
},
360+
Spec: servicecatalog.ClusterServiceBrokerSpec{
361+
URL: "http://example.com",
362+
RelistBehavior: servicecatalog.ServiceBrokerRelistBehaviorDuration,
363+
RelistDuration: &metav1.Duration{Duration: 15 * time.Minute},
364+
RelistRequests: 1,
365+
},
366+
},
367+
oldBroker: &servicecatalog.ClusterServiceBroker{
368+
ObjectMeta: metav1.ObjectMeta{
369+
Name: "test-broker",
370+
},
371+
Spec: servicecatalog.ClusterServiceBrokerSpec{
372+
URL: "http://example.com",
373+
RelistBehavior: servicecatalog.ServiceBrokerRelistBehaviorDuration,
374+
RelistDuration: &metav1.Duration{Duration: 15 * time.Minute},
375+
RelistRequests: 1,
376+
},
377+
},
378+
valid: true,
379+
},
380+
{
381+
name: "valid broker update - increasing relistRequests value",
382+
newBroker: &servicecatalog.ClusterServiceBroker{
383+
ObjectMeta: metav1.ObjectMeta{
384+
Name: "test-broker",
385+
},
386+
Spec: servicecatalog.ClusterServiceBrokerSpec{
387+
URL: "http://example.com",
388+
RelistBehavior: servicecatalog.ServiceBrokerRelistBehaviorDuration,
389+
RelistDuration: &metav1.Duration{Duration: 15 * time.Minute},
390+
RelistRequests: 2,
391+
},
392+
},
393+
oldBroker: &servicecatalog.ClusterServiceBroker{
394+
ObjectMeta: metav1.ObjectMeta{
395+
Name: "test-broker",
396+
},
397+
Spec: servicecatalog.ClusterServiceBrokerSpec{
398+
URL: "http://example.com",
399+
RelistBehavior: servicecatalog.ServiceBrokerRelistBehaviorDuration,
400+
RelistDuration: &metav1.Duration{Duration: 15 * time.Minute},
401+
RelistRequests: 1,
402+
},
403+
},
404+
valid: true,
405+
},
406+
{
407+
name: "invalid broker update - nonincreasing relistRequests value",
408+
newBroker: &servicecatalog.ClusterServiceBroker{
409+
ObjectMeta: metav1.ObjectMeta{
410+
Name: "test-broker",
411+
},
412+
Spec: servicecatalog.ClusterServiceBrokerSpec{
413+
URL: "http://example.com",
414+
RelistBehavior: servicecatalog.ServiceBrokerRelistBehaviorDuration,
415+
RelistDuration: &metav1.Duration{Duration: 15 * time.Minute},
416+
RelistRequests: 1,
417+
},
418+
},
419+
oldBroker: &servicecatalog.ClusterServiceBroker{
420+
ObjectMeta: metav1.ObjectMeta{
421+
Name: "test-broker",
422+
},
423+
Spec: servicecatalog.ClusterServiceBrokerSpec{
424+
URL: "http://example.com",
425+
RelistBehavior: servicecatalog.ServiceBrokerRelistBehaviorDuration,
426+
RelistDuration: &metav1.Duration{Duration: 15 * time.Minute},
427+
RelistRequests: 2,
428+
},
429+
},
430+
valid: false,
431+
},
432+
}
433+
for _, tc := range updateCases {
434+
errs := ValidateClusterServiceBrokerUpdate(tc.newBroker, tc.oldBroker)
435+
if len(errs) != 0 && tc.valid {
436+
t.Errorf("%v: unexpected error: %v", tc.name, errs)
437+
continue
438+
} else if len(errs) == 0 && !tc.valid {
439+
t.Errorf("%v: unexpected success", tc.name)
440+
}
441+
}
347442
}

0 commit comments

Comments
 (0)