Skip to content

Commit

Permalink
Merge pull request #15580 from jim-minter/issue15405
Browse files Browse the repository at this point in the history
Automatic merge from submit-queue

create template-service-broker SA during API server startup

fixes #15405 
(builds on #15568)
  • Loading branch information
openshift-merge-robot authored Aug 4, 2017
2 parents dc4d146 + 00ea18e commit 7b225ea
Showing 1 changed file with 37 additions and 4 deletions.
41 changes: 37 additions & 4 deletions pkg/openservicebroker/server/apiserver.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
package server

import (
"fmt"
"time"

kapierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/apimachinery/pkg/util/wait"
genericapiserver "k8s.io/apiserver/pkg/server"
"k8s.io/kubernetes/pkg/api"
kclientsetinternal "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"

"github.com/openshift/origin/pkg/cmd/server/bootstrappolicy"
templateapi "github.com/openshift/origin/pkg/template/apis/template"
templateinformer "github.com/openshift/origin/pkg/template/generated/informers/internalversion"
templateservicebroker "github.com/openshift/origin/pkg/template/servicebroker"
genericapiserver "k8s.io/apiserver/pkg/server"
)

// TODO: this file breaks the layering of pkg/openservicebroker and
// pkg/template/servicebroker; assuming that the latter will move out of origin
// in 3.7, will leave as is for now.

type TemplateServiceBrokerConfig struct {
GenericConfig *genericapiserver.Config

Expand Down Expand Up @@ -62,9 +74,30 @@ func (c completedTemplateServiceBrokerConfig) New(delegationTarget genericapiser

// TODO, when/if the TSB becomes a separate entity, this should stop creating the SA and instead die if it cannot find it
s.GenericAPIServer.AddPostStartHook("template-service-broker-ensure-service-account", func(context genericapiserver.PostStartHookContext) error {
// TODO jim-minter - this is the spot to create the namespace if needed and create the SA if needed.
// be tolerant of failures and retry a few times.
return nil
kc, err := kclientsetinternal.NewForConfig(context.LoopbackClientConfig)
if err != nil {
utilruntime.HandleError(fmt.Errorf("template service broker: failed to get client: %v", err))
return err
}

err = wait.PollImmediate(time.Second, 30*time.Second, func() (done bool, err error) {
kc.Namespaces().Create(&api.Namespace{ObjectMeta: metav1.ObjectMeta{Name: bootstrappolicy.DefaultOpenShiftInfraNamespace}})

_, err = kc.ServiceAccounts(bootstrappolicy.DefaultOpenShiftInfraNamespace).Create(&api.ServiceAccount{ObjectMeta: metav1.ObjectMeta{Name: bootstrappolicy.InfraTemplateServiceBrokerServiceAccountName}})
switch {
case err == nil || kapierrors.IsAlreadyExists(err):
done, err = true, nil
case kapierrors.IsNotFound(err):
err = nil
}

return
})

if err != nil {
utilruntime.HandleError(fmt.Errorf("creation of template-service-broker SA failed: %v", err))
}
return err
})

return s, nil
Expand Down

0 comments on commit 7b225ea

Please sign in to comment.