Skip to content

Instantly share code, notes, and snippets.

@eriknelson
Created August 28, 2017 18:14
Show Gist options
  • Save eriknelson/fd4b73ff0d35bb8f80a498041e18ed68 to your computer and use it in GitHub Desktop.
Save eriknelson/fd4b73ff0d35bb8f80a498041e18ed68 to your computer and use it in GitHub Desktop.
From 5d9afb10f694bc0a0d34ddfc43c545d546ed1351 Mon Sep 17 00:00:00 2001
From: Erik Nelson <[email protected]>
Date: Wed, 23 Aug 2017 17:11:41 -0400
Subject: [PATCH] initial relist commit
* Adds proposed fields to the ServiceBroker
---
pkg/apis/servicecatalog/testing/fuzzer.go | 4 ++++
pkg/apis/servicecatalog/types.go | 22 ++++++++++++++++++++++
pkg/apis/servicecatalog/v1alpha1/defaults.go | 12 ++++++++++++
pkg/apis/servicecatalog/v1alpha1/defaults_test.go | 16 ++++++++++++++++
pkg/apis/servicecatalog/v1alpha1/types.go | 22 ++++++++++++++++++++++
pkg/storage/tpr/storage_interface_test.go | 21 ++++++++++++++++++++-
6 files changed, 96 insertions(+), 1 deletion(-)
diff --git a/pkg/apis/servicecatalog/testing/fuzzer.go b/pkg/apis/servicecatalog/testing/fuzzer.go
index 1bb6307cf1..d01bef50a1 100644
--- a/pkg/apis/servicecatalog/testing/fuzzer.go
+++ b/pkg/apis/servicecatalog/testing/fuzzer.go
@@ -192,6 +192,10 @@ func FuzzerFor(t *testing.T, version schema.GroupVersion, src rand.Source) *fuzz
// Set the bytes field on the RawExtension
r.Raw = bytes
},
+ func(bs *servicecatalog.ServiceBrokerSpec, c fuzz.Continue) {
+ c.FuzzNoCustom(bs)
+ bs.SyncBehavior = "Duration"
+ },
func(is *servicecatalog.ServiceInstanceSpec, c fuzz.Continue) {
c.FuzzNoCustom(is)
is.ExternalID = uuid.NewV4().String()
diff --git a/pkg/apis/servicecatalog/types.go b/pkg/apis/servicecatalog/types.go
index da6cb4d31f..06878357fe 100644
--- a/pkg/apis/servicecatalog/types.go
+++ b/pkg/apis/servicecatalog/types.go
@@ -60,8 +60,30 @@ type ServiceBrokerSpec struct {
// CABundle is a PEM encoded CA bundle which will be used to validate a Broker's serving certificate.
// +optional
CABundle []byte
+
+ // SyncBehavior specifies the type of sync behavior the catalog should exhibit
+ // when syncing ServiceClasses available from a broker
+ SyncBehavior ServiceBrokerSyncBehavior
+
+ ////SyncDuration is the frequency by which a controller will sync with the broker
+ ////when the SyncBehavior is set to ServiceBrokerSyncBehaviorDuration
+ //SyncDuration *metav1.Duration
+ ////SyncRequests is a strictly increasing integer counter that can be manually incremented
+ ////by a user to manually trigger a sync
+ //SyncRequests int64
}
+// ServiceBrokerSyncBehavior represents a type of broker sync behavior
+type ServiceBrokerSyncBehavior string
+
+const (
+ // ServiceBrokerSyncBehaviorDuration will allow the SyncDuration frequency to be configured
+ ServiceBrokerSyncBehaviorDuration ServiceBrokerSyncBehavior = "Duration"
+ // ServiceBrokerSyncBehaviorManual will configure the catalog to only perform future
+ // syncs based on triggering PUT /brokers/sync
+ ServiceBrokerSyncBehaviorManual ServiceBrokerSyncBehavior = "Manual"
+)
+
// ServiceBrokerAuthInfo is a union type that contains information on one of the authentication methods
// the the service catalog and brokers may support, according to the OpenServiceBroker API
// specification (https://github.com/openservicebrokerapi/servicebroker/blob/master/spec.md).
diff --git a/pkg/apis/servicecatalog/v1alpha1/defaults.go b/pkg/apis/servicecatalog/v1alpha1/defaults.go
index f078346585..7b24258717 100644
--- a/pkg/apis/servicecatalog/v1alpha1/defaults.go
+++ b/pkg/apis/servicecatalog/v1alpha1/defaults.go
@@ -18,13 +18,25 @@ package v1alpha1
import (
"github.com/satori/go.uuid"
+ //metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
+ //"time"
)
func addDefaultingFuncs(scheme *runtime.Scheme) error {
return RegisterDefaults(scheme)
}
+func SetDefaults_ServiceBrokerSpec(spec *ServiceBrokerSpec) {
+ if spec.SyncBehavior == "" {
+ spec.SyncBehavior = ServiceBrokerSyncBehaviorDuration
+ }
+
+ //if spec.SyncBehavior == ServiceBrokerSyncBehaviorDuration {
+ //spec.SyncDuration = &metav1.Duration{15 * time.Minute}
+ //}
+}
+
func SetDefaults_ServiceInstanceSpec(spec *ServiceInstanceSpec) {
if spec.ExternalID == "" {
spec.ExternalID = uuid.NewV4().String()
diff --git a/pkg/apis/servicecatalog/v1alpha1/defaults_test.go b/pkg/apis/servicecatalog/v1alpha1/defaults_test.go
index dc7801087e..74015e6fb5 100644
--- a/pkg/apis/servicecatalog/v1alpha1/defaults_test.go
+++ b/pkg/apis/servicecatalog/v1alpha1/defaults_test.go
@@ -68,6 +68,22 @@ func roundTrip(t *testing.T, obj runtime.Object) runtime.Object {
return obj3
}
+func TestSetDefaultServiceBroker(t *testing.T) {
+ b := &versioned.ServiceBroker{}
+ obj2 := roundTrip(t, runtime.Object(b))
+ b2 := obj2.(*versioned.ServiceBroker)
+
+ if b2.Spec.SyncBehavior == "" {
+ t.Error("Expected a default SyncBehavior of ServiceBrokerSyncBehaviorDuration, but got none")
+ }
+
+ //incorrectDefaultSyncBehavior := b2.Spec.SyncBehavior != "" &&
+ //b2.Spec.SyncBehavior != versioned.ServiceBrokerSyncBehaviorDuration
+ //if incorrectDefaultSyncBehavior {
+ //t.Error("Expected a default SyncBehavior of ServiceBrokerSyncBehaviorDuration, but got something else")
+ //}
+}
+
func TestSetDefaultServiceInstance(t *testing.T) {
i := &versioned.ServiceInstance{}
obj2 := roundTrip(t, runtime.Object(i))
diff --git a/pkg/apis/servicecatalog/v1alpha1/types.go b/pkg/apis/servicecatalog/v1alpha1/types.go
index 4b89f7f414..83a5715f54 100644
--- a/pkg/apis/servicecatalog/v1alpha1/types.go
+++ b/pkg/apis/servicecatalog/v1alpha1/types.go
@@ -60,8 +60,30 @@ type ServiceBrokerSpec struct {
// CABundle is a PEM encoded CA bundle which will be used to validate a Broker's serving certificate.
// +optional
CABundle []byte `json:"caBundle,omitempty"`
+
+ // SyncBehavior specifies the type of sync behavior the catalog should exhibit
+ // when syncing ServiceClasses available from a broker
+ SyncBehavior ServiceBrokerSyncBehavior `json:"syncBehavior"`
+
+ //// SyncDuration is the frequency by which a controller will sync with the broker
+ //// when the SyncBehavior is set to BrokerSyncBehaviorDuration
+ //SyncDuration *metav1.Duration `json:"syncDuration"`
+ //// SyncRequests is a strictly increasing integer counter that can be manually incremented
+ //// by a user to manually trigger a sync
+ //SyncRequests int64 `json:"syncRequests"`
}
+// ServiceBrokerSyncBehavior represents a type of broker sync behavior
+type ServiceBrokerSyncBehavior string
+
+const (
+ // ServiceBrokerSyncBehaviorDuration will allow the SyncDuration frequency to be configured
+ ServiceBrokerSyncBehaviorDuration ServiceBrokerSyncBehavior = "Duration"
+ // ServiceBrokerSyncBehaviorManual will configure the catalog to only perform future
+ // syncs based on triggering PUT /brokers/sync
+ ServiceBrokerSyncBehaviorManual ServiceBrokerSyncBehavior = "Manual"
+)
+
// ServiceBrokerAuthInfo is a union type that contains information on one of the authentication methods
// the the service catalog and brokers may support, according to the OpenServiceBroker API
// specification (https://github.com/openservicebrokerapi/servicebroker/blob/master/spec.md).
diff --git a/pkg/storage/tpr/storage_interface_test.go b/pkg/storage/tpr/storage_interface_test.go
index 75f3da5194..b6048b4f0a 100644
--- a/pkg/storage/tpr/storage_interface_test.go
+++ b/pkg/storage/tpr/storage_interface_test.go
@@ -140,7 +140,8 @@ func TestCreateWithNoNamespace(t *testing.T) {
inputServiceBroker := &sc.ServiceBroker{
ObjectMeta: metav1.ObjectMeta{Name: name},
Spec: sc.ServiceBrokerSpec{
- URL: "http://my-awesome-broker.io",
+ URL: "http://my-awesome-broker.io",
+ SyncBehavior: "Duration",
},
}
key, err := keyer.Key(request.NewContext(), name)
@@ -336,6 +337,9 @@ func TestGetWithNoNamespace(t *testing.T) {
// Ensure an existing broker
fakeCl.Storage.Set(globalNamespace, ServiceBrokerKind.URLName(), name, &sc.ServiceBroker{
ObjectMeta: metav1.ObjectMeta{Name: name},
+ Spec: sc.ServiceBrokerSpec{
+ SyncBehavior: "Duration",
+ },
})
key, err := keyer.Key(request.NewContext(), name)
if err != nil {
@@ -505,6 +509,9 @@ func TestGetListWithNoNamespace(t *testing.T) {
// Ensure an existing broker
fakeCl.Storage.Set(globalNamespace, ServiceBrokerKind.URLName(), name, &sc.ServiceBroker{
ObjectMeta: metav1.ObjectMeta{Name: name},
+ Spec: sc.ServiceBrokerSpec{
+ SyncBehavior: "Duration",
+ },
})
list := &sc.ServiceBrokerList{}
if err := iface.List(
@@ -873,6 +880,9 @@ func TestDeleteWithNoNamespace(t *testing.T) {
Name: name,
ResourceVersion: fmt.Sprintf("%d", origRev),
},
+ Spec: sc.ServiceBrokerSpec{
+ SyncBehavior: "Duration",
+ },
}
brokerWithFinalizers := *brokerNoFinalizers
brokerWithFinalizers.Finalizers = append(brokerWithFinalizers.Finalizers, v1alpha1.FinalizerServiceCatalog)
@@ -993,6 +1003,9 @@ func TestWatchWithNoNamespace(t *testing.T) {
obj := &sc.ServiceBroker{
TypeMeta: metav1.TypeMeta{Kind: ServiceBrokerKind.String()},
ObjectMeta: metav1.ObjectMeta{Name: name},
+ Spec: sc.ServiceBrokerSpec{
+ SyncBehavior: "Duration",
+ },
}
// send an unversioned object into the watch test. it sends this object to the
// fake REST client, which encodes the unversioned object into bytes & sends them
@@ -1052,9 +1065,15 @@ func TestWatchListWithNoNamespace(t *testing.T) {
Items: []sc.ServiceBroker{
{
ObjectMeta: metav1.ObjectMeta{Name: fmt.Sprintf("%s1", name)},
+ Spec: sc.ServiceBrokerSpec{
+ SyncBehavior: "Duration",
+ },
},
{
ObjectMeta: metav1.ObjectMeta{Name: fmt.Sprintf("%s2", name)},
+ Spec: sc.ServiceBrokerSpec{
+ SyncBehavior: "Duration",
+ },
},
},
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment