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

Commit

Permalink
add the context-profile from osb (#686)
Browse files Browse the repository at this point in the history
* add the context-profile from osb

 - test to makes sure fields are set

* Adding a flag for OSBAPI Context Profile enablement
  • Loading branch information
MHBauer authored and pmorie committed Apr 14, 2017
1 parent 77f5c9a commit e320dbe
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 12 deletions.
1 change: 1 addition & 0 deletions cmd/controller-manager/app/controller_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ func StartControllers(s *options.ControllerManagerServer,
serviceCatalogSharedInformers.Instances(),
serviceCatalogSharedInformers.Bindings(),
openservicebroker.NewClient,
s.OSBAPIContextProfile,
)
if err != nil {
return err
Expand Down
3 changes: 3 additions & 0 deletions cmd/controller-manager/app/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const defaultBindAddress = "0.0.0.0"
const defaultPort = 10000
const defaultK8sKubeconfigPath = "./kubeconfig"
const defaultServiceCatalogKubeconfigPath = "./service-catalog-kubeconfig"
const defaultOSBAPIContextProfile = true

// NewControllerManagerServer creates a new ControllerManagerServer with a
// default config.
Expand All @@ -53,6 +54,7 @@ func NewControllerManagerServer() *ControllerManagerServer {
K8sKubeconfigPath: defaultK8sKubeconfigPath,
ServiceCatalogKubeconfigPath: defaultServiceCatalogKubeconfigPath,
ResyncInterval: defaultResyncInterval,
OSBAPIContextProfile: defaultOSBAPIContextProfile,
},
}
}
Expand All @@ -67,4 +69,5 @@ func (s *ControllerManagerServer) AddFlags(fs *pflag.FlagSet) {
fs.StringVar(&s.ServiceCatalogAPIServerURL, "service-catalog-api-server-url", "", "The URL for the service-catalog API server")
fs.StringVar(&s.ServiceCatalogKubeconfigPath, "service-catalog-kubeconfig", s.ServiceCatalogKubeconfigPath, "Path to service-catalog kubeconfig")
fs.DurationVar(&s.ResyncInterval, "resync-interval", s.ResyncInterval, "The interval on which the controller will resync its informers")
fs.BoolVar(&s.OSBAPIContextProfile, "enable-osb-api-context-profile", s.OSBAPIContextProfile, "Whether or not to send the proposed optional OpenServiceBroker API Context Profile field")
}
4 changes: 4 additions & 0 deletions pkg/apis/componentconfig/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,8 @@ type ControllerManagerConfiguration struct {
// ResyncInterval is the interval on which the controller should re-sync
// all informers.
ResyncInterval time.Duration

// Whether or not to send the proposed optional
// OpenServiceBroker API Context Profile field
OSBAPIContextProfile bool
}
8 changes: 8 additions & 0 deletions pkg/brokerapi/fake/fake.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package fake

import (
"errors"
"fmt"

"github.com/kubernetes-incubator/service-catalog/pkg/brokerapi"
Expand Down Expand Up @@ -91,6 +92,13 @@ func (i *InstanceClient) CreateServiceInstance(
if i.exists(id) {
return nil, ErrInstanceAlreadyExists
}
// context profile and contents should always (optionally) exist.
if req.ContextProfile.Platform != brokerapi.ContextProfilePlatformKubernetes {
return nil, errors.New("OSB context profile not set to " + brokerapi.ContextProfilePlatformKubernetes)
}
if req.ContextProfile.Namespace == "" {
return nil, errors.New("missing valid OSB context profile namespace")
}

i.Instances[id] = convertInstanceRequest(req)
return &brokerapi.CreateServiceInstanceResponse{}, nil
Expand Down
14 changes: 14 additions & 0 deletions pkg/brokerapi/service_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,20 @@ type CreateServiceInstanceRequest struct {
SpaceID string `json:"space_guid,omitempty"`
Parameters map[string]interface{} `json:"parameters,omitempty"`
AcceptsIncomplete bool `json:"accepts_incomplete,omitempty"`
ContextProfile ContextProfile `json:"context,omitempty"`
}

// ContextProfilePlatformKubernetes is a constant to send when the
// client is representing a kubernetes style ecosystem.
const ContextProfilePlatformKubernetes string = "kubernetes"

// ContextProfile implements the optional OSB field
// https://github.com/duglin/servicebroker/blob/CFisms/context-profiles.md#kubernetes
type ContextProfile struct {
// Platform is always `kubernetes`
Platform string `json:"platform,omitempty"`
// Namespace is the Kubernetes namespace in which the service instance will be visible.
Namespace string `json:"namespace,omitempty"`
}

// CreateServiceInstanceResponse represents the response from a broker after a
Expand Down
33 changes: 21 additions & 12 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func NewController(
instanceInformer informers.InstanceInformer,
bindingInformer informers.BindingInformer,
brokerClientCreateFunc brokerapi.CreateFunc,
osbAPIContextProfile bool,
) (Controller, error) {

var (
Expand All @@ -60,12 +61,13 @@ func NewController(
instanceLister = instanceInformer.Lister()

controller = &controller{
kubeClient: kubeClient,
serviceCatalogClient: serviceCatalogClient,
brokerClientCreateFunc: brokerClientCreateFunc,
brokerLister: brokerLister,
serviceClassLister: serviceClassLister,
instanceLister: instanceLister,
kubeClient: kubeClient,
serviceCatalogClient: serviceCatalogClient,
brokerClientCreateFunc: brokerClientCreateFunc,
brokerLister: brokerLister,
serviceClassLister: serviceClassLister,
instanceLister: instanceLister,
enableOSBAPIContextProfle: osbAPIContextProfile,
}
)

Expand Down Expand Up @@ -105,12 +107,13 @@ type Controller interface {

// controller is a concrete Controller.
type controller struct {
kubeClient kubernetes.Interface
serviceCatalogClient servicecatalogclientset.ServicecatalogV1alpha1Interface
brokerClientCreateFunc brokerapi.CreateFunc
brokerLister listers.BrokerLister
serviceClassLister listers.ServiceClassLister
instanceLister listers.InstanceLister
kubeClient kubernetes.Interface
serviceCatalogClient servicecatalogclientset.ServicecatalogV1alpha1Interface
brokerClientCreateFunc brokerapi.CreateFunc
brokerLister listers.BrokerLister
serviceClassLister listers.ServiceClassLister
instanceLister listers.InstanceLister
enableOSBAPIContextProfle bool
}

// Run runs the controller until the given stop channel can be read from.
Expand Down Expand Up @@ -548,6 +551,12 @@ func (c *controller) reconcileInstance(instance *v1alpha1.Instance) {
SpaceID: string(ns.UID),
AcceptsIncomplete: true,
}
if c.enableOSBAPIContextProfle {
request.ContextProfile = brokerapi.ContextProfile{
Platform: brokerapi.ContextProfilePlatformKubernetes,
Namespace: instance.Namespace,
}
}

// TODO: handle async provisioning

Expand Down
1 change: 1 addition & 0 deletions pkg/controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1866,6 +1866,7 @@ func newTestController(t *testing.T) (
serviceCatalogSharedInformers.Instances(),
serviceCatalogSharedInformers.Bindings(),
brokerClFunc,
true,
)
if err != nil {
t.Fatal(err)
Expand Down
1 change: 1 addition & 0 deletions test/integration/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ func newTestController(t *testing.T) (
serviceCatalogSharedInformers.Instances(),
serviceCatalogSharedInformers.Bindings(),
brokerClFunc,
true,
)
t.Log("controller start")
if err != nil {
Expand Down

0 comments on commit e320dbe

Please sign in to comment.