Skip to content

Commit

Permalink
Brokers must have at least one service (openshift#930)
Browse files Browse the repository at this point in the history
  • Loading branch information
pmorie authored and Ville Aikas committed Jun 9, 2017
1 parent cbfa39b commit 0c08788
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pkg/controller/controller_broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package controller

import (
stderrors "errors"
"fmt"
"time"

Expand Down Expand Up @@ -205,6 +206,14 @@ func (c *controller) reconcileBroker(broker *v1alpha1.Broker) error {
}
glog.V(5).Infof("Successfully converted catalog payload from Broker %v to service-catalog API", broker.Name)

if len(catalog) == 0 {
s := fmt.Sprintf("Error getting catalog payload for broker %q; received zero services; at least one service is required", broker.Name)
glog.Warning(s)
c.recorder.Eventf(broker, api.EventTypeWarning, errorSyncingCatalogReason, s)
c.updateBrokerCondition(broker, v1alpha1.BrokerConditionReady, v1alpha1.ConditionFalse, errorSyncingCatalogReason, errorSyncingCatalogMessage+s)
return stderrors.New(s)
}

for _, serviceClass := range catalog {
glog.V(4).Infof("Reconciling serviceClass %v (broker %v)", serviceClass.Name, broker.Name)
if err := c.reconcileServiceClassFromBrokerCatalog(broker, serviceClass); err != nil {
Expand Down
28 changes: 28 additions & 0 deletions pkg/controller/controller_broker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"time"

"github.com/kubernetes-incubator/service-catalog/pkg/apis/servicecatalog/v1alpha1"
"github.com/kubernetes-incubator/service-catalog/pkg/brokerapi"
fakebrokerapi "github.com/kubernetes-incubator/service-catalog/pkg/brokerapi/fake"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -289,6 +290,33 @@ func TestReconcileBrokerErrorFetchingCatalog(t *testing.T) {
}
}

func TestReconcileBrokerZeroServices(t *testing.T) {
fakeKubeClient, fakeCatalogClient, fakeBrokerClient, testController, _ := newTestController(t)

fakeBrokerClient.CatalogClient.RetCatalog = &brokerapi.Catalog{
Services: []*brokerapi.Service{},
}
broker := getTestBroker()

testController.reconcileBroker(broker)

actions := fakeCatalogClient.Actions()
assertNumberOfActions(t, actions, 1)

updatedBroker := assertUpdateStatus(t, actions[0], broker)
assertBrokerReadyFalse(t, updatedBroker)

assertNumberOfActions(t, fakeKubeClient.Actions(), 0)

events := getRecordedEvents(testController)
assertNumEvents(t, events, 1)

expectedEvent := api.EventTypeWarning + " " + errorSyncingCatalogReason + ` Error getting catalog payload for broker "test-broker"; received zero services; at least one service is required`
if e, a := expectedEvent, events[0]; e != a {
t.Fatalf("Received unexpected event; \nexpected: %v\ngot: %v", e, a)
}
}

func TestReconcileBrokerWithAuthError(t *testing.T) {
fakeKubeClient, fakeCatalogClient, _, testController, _ := newTestController(t)

Expand Down

0 comments on commit 0c08788

Please sign in to comment.