Skip to content
This repository was archived by the owner on May 6, 2022. It is now read-only.

Commit e320dbe

Browse files
MHBauerpmorie
authored andcommitted
add the context-profile from osb (#686)
* add the context-profile from osb - test to makes sure fields are set * Adding a flag for OSBAPI Context Profile enablement
1 parent 77f5c9a commit e320dbe

File tree

8 files changed

+53
-12
lines changed

8 files changed

+53
-12
lines changed

cmd/controller-manager/app/controller_manager.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ func StartControllers(s *options.ControllerManagerServer,
292292
serviceCatalogSharedInformers.Instances(),
293293
serviceCatalogSharedInformers.Bindings(),
294294
openservicebroker.NewClient,
295+
s.OSBAPIContextProfile,
295296
)
296297
if err != nil {
297298
return err

cmd/controller-manager/app/options/options.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ const defaultBindAddress = "0.0.0.0"
4141
const defaultPort = 10000
4242
const defaultK8sKubeconfigPath = "./kubeconfig"
4343
const defaultServiceCatalogKubeconfigPath = "./service-catalog-kubeconfig"
44+
const defaultOSBAPIContextProfile = true
4445

4546
// NewControllerManagerServer creates a new ControllerManagerServer with a
4647
// default config.
@@ -53,6 +54,7 @@ func NewControllerManagerServer() *ControllerManagerServer {
5354
K8sKubeconfigPath: defaultK8sKubeconfigPath,
5455
ServiceCatalogKubeconfigPath: defaultServiceCatalogKubeconfigPath,
5556
ResyncInterval: defaultResyncInterval,
57+
OSBAPIContextProfile: defaultOSBAPIContextProfile,
5658
},
5759
}
5860
}
@@ -67,4 +69,5 @@ func (s *ControllerManagerServer) AddFlags(fs *pflag.FlagSet) {
6769
fs.StringVar(&s.ServiceCatalogAPIServerURL, "service-catalog-api-server-url", "", "The URL for the service-catalog API server")
6870
fs.StringVar(&s.ServiceCatalogKubeconfigPath, "service-catalog-kubeconfig", s.ServiceCatalogKubeconfigPath, "Path to service-catalog kubeconfig")
6971
fs.DurationVar(&s.ResyncInterval, "resync-interval", s.ResyncInterval, "The interval on which the controller will resync its informers")
72+
fs.BoolVar(&s.OSBAPIContextProfile, "enable-osb-api-context-profile", s.OSBAPIContextProfile, "Whether or not to send the proposed optional OpenServiceBroker API Context Profile field")
7073
}

pkg/apis/componentconfig/types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,8 @@ type ControllerManagerConfiguration struct {
5656
// ResyncInterval is the interval on which the controller should re-sync
5757
// all informers.
5858
ResyncInterval time.Duration
59+
60+
// Whether or not to send the proposed optional
61+
// OpenServiceBroker API Context Profile field
62+
OSBAPIContextProfile bool
5963
}

pkg/brokerapi/fake/fake.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package fake
1818

1919
import (
20+
"errors"
2021
"fmt"
2122

2223
"github.com/kubernetes-incubator/service-catalog/pkg/brokerapi"
@@ -91,6 +92,13 @@ func (i *InstanceClient) CreateServiceInstance(
9192
if i.exists(id) {
9293
return nil, ErrInstanceAlreadyExists
9394
}
95+
// context profile and contents should always (optionally) exist.
96+
if req.ContextProfile.Platform != brokerapi.ContextProfilePlatformKubernetes {
97+
return nil, errors.New("OSB context profile not set to " + brokerapi.ContextProfilePlatformKubernetes)
98+
}
99+
if req.ContextProfile.Namespace == "" {
100+
return nil, errors.New("missing valid OSB context profile namespace")
101+
}
94102

95103
i.Instances[id] = convertInstanceRequest(req)
96104
return &brokerapi.CreateServiceInstanceResponse{}, nil

pkg/brokerapi/service_instance.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,20 @@ type CreateServiceInstanceRequest struct {
4040
SpaceID string `json:"space_guid,omitempty"`
4141
Parameters map[string]interface{} `json:"parameters,omitempty"`
4242
AcceptsIncomplete bool `json:"accepts_incomplete,omitempty"`
43+
ContextProfile ContextProfile `json:"context,omitempty"`
44+
}
45+
46+
// ContextProfilePlatformKubernetes is a constant to send when the
47+
// client is representing a kubernetes style ecosystem.
48+
const ContextProfilePlatformKubernetes string = "kubernetes"
49+
50+
// ContextProfile implements the optional OSB field
51+
// https://github.com/duglin/servicebroker/blob/CFisms/context-profiles.md#kubernetes
52+
type ContextProfile struct {
53+
// Platform is always `kubernetes`
54+
Platform string `json:"platform,omitempty"`
55+
// Namespace is the Kubernetes namespace in which the service instance will be visible.
56+
Namespace string `json:"namespace,omitempty"`
4357
}
4458

4559
// CreateServiceInstanceResponse represents the response from a broker after a

pkg/controller/controller.go

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ func NewController(
5252
instanceInformer informers.InstanceInformer,
5353
bindingInformer informers.BindingInformer,
5454
brokerClientCreateFunc brokerapi.CreateFunc,
55+
osbAPIContextProfile bool,
5556
) (Controller, error) {
5657

5758
var (
@@ -60,12 +61,13 @@ func NewController(
6061
instanceLister = instanceInformer.Lister()
6162

6263
controller = &controller{
63-
kubeClient: kubeClient,
64-
serviceCatalogClient: serviceCatalogClient,
65-
brokerClientCreateFunc: brokerClientCreateFunc,
66-
brokerLister: brokerLister,
67-
serviceClassLister: serviceClassLister,
68-
instanceLister: instanceLister,
64+
kubeClient: kubeClient,
65+
serviceCatalogClient: serviceCatalogClient,
66+
brokerClientCreateFunc: brokerClientCreateFunc,
67+
brokerLister: brokerLister,
68+
serviceClassLister: serviceClassLister,
69+
instanceLister: instanceLister,
70+
enableOSBAPIContextProfle: osbAPIContextProfile,
6971
}
7072
)
7173

@@ -105,12 +107,13 @@ type Controller interface {
105107

106108
// controller is a concrete Controller.
107109
type controller struct {
108-
kubeClient kubernetes.Interface
109-
serviceCatalogClient servicecatalogclientset.ServicecatalogV1alpha1Interface
110-
brokerClientCreateFunc brokerapi.CreateFunc
111-
brokerLister listers.BrokerLister
112-
serviceClassLister listers.ServiceClassLister
113-
instanceLister listers.InstanceLister
110+
kubeClient kubernetes.Interface
111+
serviceCatalogClient servicecatalogclientset.ServicecatalogV1alpha1Interface
112+
brokerClientCreateFunc brokerapi.CreateFunc
113+
brokerLister listers.BrokerLister
114+
serviceClassLister listers.ServiceClassLister
115+
instanceLister listers.InstanceLister
116+
enableOSBAPIContextProfle bool
114117
}
115118

116119
// Run runs the controller until the given stop channel can be read from.
@@ -548,6 +551,12 @@ func (c *controller) reconcileInstance(instance *v1alpha1.Instance) {
548551
SpaceID: string(ns.UID),
549552
AcceptsIncomplete: true,
550553
}
554+
if c.enableOSBAPIContextProfle {
555+
request.ContextProfile = brokerapi.ContextProfile{
556+
Platform: brokerapi.ContextProfilePlatformKubernetes,
557+
Namespace: instance.Namespace,
558+
}
559+
}
551560

552561
// TODO: handle async provisioning
553562

pkg/controller/controller_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1866,6 +1866,7 @@ func newTestController(t *testing.T) (
18661866
serviceCatalogSharedInformers.Instances(),
18671867
serviceCatalogSharedInformers.Bindings(),
18681868
brokerClFunc,
1869+
true,
18691870
)
18701871
if err != nil {
18711872
t.Fatal(err)

test/integration/controller_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ func newTestController(t *testing.T) (
275275
serviceCatalogSharedInformers.Instances(),
276276
serviceCatalogSharedInformers.Bindings(),
277277
brokerClFunc,
278+
true,
278279
)
279280
t.Log("controller start")
280281
if err != nil {

0 commit comments

Comments
 (0)