Skip to content

Commit

Permalink
start a command for running the template service broker
Browse files Browse the repository at this point in the history
  • Loading branch information
deads2k committed Aug 7, 2017
1 parent 490f9e1 commit db64b1f
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/cmd/server/start/start_allinone.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ import (
"k8s.io/kubernetes/pkg/kubectl/cmd/templates"
kcmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"

tsbcmd "github.com/openshift/origin/pkg/openservicebroker/cmd/server"
"github.com/openshift/origin/pkg/cmd/server/admin"
configapi "github.com/openshift/origin/pkg/cmd/server/api"
"github.com/openshift/origin/pkg/cmd/server/crypto"
"github.com/openshift/origin/pkg/cmd/server/start/kubernetes"
cmdutil "github.com/openshift/origin/pkg/cmd/util"
"k8s.io/apimachinery/pkg/util/wait"
)

type AllInOneOptions struct {
Expand Down Expand Up @@ -125,10 +127,12 @@ func NewCommandStartAllInOne(basename string, out, errout io.Writer) (*cobra.Com
startNode, _ := NewCommandStartNode(basename, out, errout)
startNodeNetwork, _ := NewCommandStartNetwork(basename, out, errout)
startEtcdServer, _ := NewCommandStartEtcdServer(RecommendedStartEtcdServerName, basename, out, errout)
startTSBServer := tsbcmd.NewCommandStartTemplateServiceBrokerServer(out, errout, wait.NeverStop)
cmds.AddCommand(startMaster)
cmds.AddCommand(startNode)
cmds.AddCommand(startNodeNetwork)
cmds.AddCommand(startEtcdServer)
cmds.AddCommand(startTSBServer)

startKube := kubernetes.NewCommand("kubernetes", basename, out, errout)
cmds.AddCommand(startKube)
Expand Down
105 changes: 105 additions & 0 deletions pkg/openservicebroker/cmd/server/start.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
package server

import (
"fmt"
"io"
"net"

"github.com/spf13/cobra"

genericapiserver "k8s.io/apiserver/pkg/server"
genericoptions "k8s.io/apiserver/pkg/server/options"

"github.com/openshift/origin/pkg/openservicebroker/server"
)

const defaultEtcdPathPrefix = "/registry/templateservicebroker.openshift.io"

type TemplateServiceBrokerServerOptions struct {
RecommendedOptions *genericoptions.RecommendedOptions

StdOut io.Writer
StdErr io.Writer

TemplateNamespaces []string
}

func NewTemplateServiceBrokerServerOptions(out, errOut io.Writer) *TemplateServiceBrokerServerOptions {
o := &TemplateServiceBrokerServerOptions{
RecommendedOptions: genericoptions.NewRecommendedOptions(defaultEtcdPathPrefix, server.Scheme, server.Codecs.LegacyCodec()),

StdOut: out,
StdErr: errOut,
}

return o
}

func NewCommandStartTemplateServiceBrokerServer(out, errOut io.Writer, stopCh <-chan struct{}) *cobra.Command {
o := NewTemplateServiceBrokerServerOptions(out, errOut)

cmd := &cobra.Command{
Use: "template-service-broker",
Short: "Launch a template service broker server",
Long: "Launch a template service broker server",
RunE: func(c *cobra.Command, args []string) error {
if err := o.Complete(); err != nil {
return err
}
if err := o.Validate(args); err != nil {
return err
}
if err := o.RunTemplateServiceBrokerServer(stopCh); err != nil {
return err
}
return nil
},
}

flags := cmd.Flags()
o.RecommendedOptions.AddFlags(flags)
flags.StringSliceVar(&o.TemplateNamespaces, "template-namespace", o.TemplateNamespaces, "TemplateNamespaces indicates the namespace(s) in which the template service broker looks for templates to serve to the catalog.")

return cmd
}

func (o TemplateServiceBrokerServerOptions) Validate(args []string) error {
return nil
}

func (o *TemplateServiceBrokerServerOptions) Complete() error {
return nil
}

func (o TemplateServiceBrokerServerOptions) Config() (*server.TemplateServiceBrokerConfig, error) {
// TODO have a "real" external address
if err := o.RecommendedOptions.SecureServing.MaybeDefaultWithSelfSignedCerts("localhost", nil, []net.IP{net.ParseIP("127.0.0.1")}); err != nil {
return nil, fmt.Errorf("error creating self-signed certificates: %v", err)
}

serverConfig := genericapiserver.NewConfig(server.Codecs)
if err := o.RecommendedOptions.ApplyTo(serverConfig); err != nil {
return nil, err
}

config := &server.TemplateServiceBrokerConfig{
GenericConfig: serverConfig,

TemplateNamespaces: o.TemplateNamespaces,
// TODO add the code to set up the client and informers that you need here
}
return config, nil
}

func (o TemplateServiceBrokerServerOptions) RunTemplateServiceBrokerServer(stopCh <-chan struct{}) error {
config, err := o.Config()
if err != nil {
return err
}

server, err := config.Complete().New(genericapiserver.EmptyDelegate)
if err != nil {
return err
}
return server.GenericAPIServer.PrepareRun().Run(stopCh)
}
23 changes: 23 additions & 0 deletions pkg/openservicebroker/server/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ import (
"time"

kapierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/apimachinery/announced"
"k8s.io/apimachinery/pkg/apimachinery/registered"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/runtime/serializer"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/apimachinery/pkg/util/wait"
genericapiserver "k8s.io/apiserver/pkg/server"
Expand All @@ -22,6 +27,24 @@ import (
// pkg/template/servicebroker; assuming that the latter will move out of origin
// in 3.7, will leave as is for now.

var (
groupFactoryRegistry = make(announced.APIGroupFactoryRegistry)
registry = registered.NewOrDie("")
Scheme = runtime.NewScheme()
Codecs = serializer.NewCodecFactory(Scheme)

// if you modify this, make sure you update the crEncoder
unversionedVersion = schema.GroupVersion{Group: "", Version: "v1"}
unversionedTypes = []runtime.Object{
&metav1.Status{},
&metav1.WatchEvent{},
&metav1.APIVersions{},
&metav1.APIGroupList{},
&metav1.APIGroup{},
&metav1.APIResourceList{},
}
)

type TemplateServiceBrokerConfig struct {
GenericConfig *genericapiserver.Config

Expand Down

0 comments on commit db64b1f

Please sign in to comment.