Skip to content

Commit

Permalink
Merge pull request pmorie#13 from pmorie/wire-it-up
Browse files Browse the repository at this point in the history
Add chart and wire skeleton binary up
  • Loading branch information
pmorie authored Jan 27, 2018
2 parents 9bd2b6e + 2105ac8 commit 3d1b691
Show file tree
Hide file tree
Showing 35 changed files with 11,408 additions and 4 deletions.
8 changes: 7 additions & 1 deletion Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,18 @@
# version = "2.4.0"


[[constraint]]
branch = "master"
name = "github.com/golang/glog"

[[constraint]]
name = "github.com/gorilla/mux"
version = "1.6.1"

[[constraint]]
branch = "master"
name = "github.com/pmorie/go-open-service-broker-client"

[[constraint]]
branch = "v2"
name = "gopkg.in/yaml.v2"
3 changes: 3 additions & 0 deletions charts/servicebroker/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name: service-broker-skeleton
description: a chart for the service-broker-skeleton
version: 0.0.1
9 changes: 9 additions & 0 deletions charts/servicebroker/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{{/* vim: set filetype=mustache: */}}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
*/}}
{{- define "fullname" -}}
{{- printf "%s-%s" .Release.Name .Chart.Name | trunc 63 | trimSuffix "-" -}}
{{- end -}}
57 changes: 57 additions & 0 deletions charts/servicebroker/templates/broker-deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
kind: Deployment
apiVersion: extensions/v1beta1
metadata:
name: {{ template "fullname" . }}
labels:
app: {{ template "fullname" . }}
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
release: "{{ .Release.Name }}"
heritage: "{{ .Release.Service }}"
spec:
replicas: 1
selector:
matchLabels:
app: {{ template "fullname" . }}
template:
metadata:
labels:
app: {{ template "fullname" . }}
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
release: "{{ .Release.Name }}"
heritage: "{{ .Release.Service }}"
spec:
containers:
- name: service-broker-skeleton
image: {{ .Values.image }}
imagePullPolicy: {{ .Values.imagePullPolicy }}
command:
- /opt/servicebroker/servicebroker
args:
- --port
- "8080"
{{- if .Values.tls.cert}}
- --tlsCert
- "{{ .Values.tls.cert }}"
{{- end}}
{{- if .Values.tls.key}}
- --tlsKey
- "{{ .Values.tls.key }}"
{{- end}}
ports:
- containerPort: 8080
readinessProbe:
tcpSocket:
port: 8080
failureThreshold: 1
initialDelaySeconds: 10
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 2
livenessProbe:
tcpSocket:
port: 8080
failureThreshold: 3
initialDelaySeconds: 10
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 2
16 changes: 16 additions & 0 deletions charts/servicebroker/templates/broker-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
kind: Service
apiVersion: v1
metadata:
name: {{ template "fullname" . }}
labels:
app: {{ template "fullname" . }}
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
release: "{{ .Release.Name }}"
heritage: "{{ .Release.Service }}"
spec:
selector:
app: {{ template "fullname" . }}
ports:
- protocol: TCP
port: 80
targetPort: 8080
6 changes: 6 additions & 0 deletions charts/servicebroker/templates/broker.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: servicecatalog.k8s.io/v1beta1
kind: ClusterServiceBroker
metadata:
name: broker-skeleton
spec:
url: http://broker-skeleton-service-broker-skeleton.broker-skeleton.svc.cluster.local
11 changes: 11 additions & 0 deletions charts/servicebroker/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Default values for the broker-skeleton
# Image to use
image: osb-skeleton/servicebroker:latest
# ImagePullPolicy; valid values are "IfNotPresent", "Never", and "Always"
imagePullPolicy: Always
# Certificate details to use for TLS. Leave blank to not use TLS
tls:
# base-64 encoded PEM data for the TLS certificate
cert:
# base-64 encoded PEM data for the private key matching the certificate
key:
4 changes: 4 additions & 0 deletions cmd/servicebroker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@ import (

"github.com/golang/glog"

"github.com/pmorie/go-open-service-broker-skeleton/cmd/servicebroker/user"
"github.com/pmorie/go-open-service-broker-skeleton/pkg/broker"
"github.com/pmorie/go-open-service-broker-skeleton/pkg/server"
)

var options struct {
user.Options

Port int
TLSCert string
TLSKey string
Expand All @@ -26,6 +29,7 @@ func init() {
flag.IntVar(&options.Port, "port", 8005, "use '--port' option to specify the port for broker to listen on")
flag.StringVar(&options.TLSCert, "tlsCert", "", "base-64 encoded PEM block to use as the certificate for TLS. If '--tlsCert' is used, then '--tlsKey' must also be used. If '--tlsCert' is not used, then TLS will not be used.")
flag.StringVar(&options.TLSKey, "tlsKey", "", "base-64 encoded PEM block to use as the private key matching the TLS certificate. If '--tlsKey' is used, then '--tlsCert' must also be used")
user.AddUserFlags(&options.Options)
flag.Parse()
}

Expand Down
19 changes: 19 additions & 0 deletions cmd/servicebroker/user/options.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package user

import (
"flag"
)

// Options holds the options specified by the user's code on the command
// line. Users should add their own options here and add flags for them in
// AddUserFlags().
type Options struct {
CatalogPath string
}

// AddUserFlags is a hook called to initialize the CLI flags for user options it
// is called after the flags are added for the skeleton and before flag.Parse is
// called.
func AddUserFlags(o *Options) {
flag.StringVar(&o.CatalogPath, "catalogPath", "", "The path to the catalog")
}
1 change: 1 addition & 0 deletions image/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
FROM busybox

ADD catalog.yaml /opt/servicebroker/catalog.yaml
ADD servicebroker /opt/servicebroker/servicebroker
CMD /opt/servicebroker/servicebroker --help
5 changes: 3 additions & 2 deletions pkg/broker/broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ func NewAPISurface() *APISurface {
router := mux.NewRouter()

s := &APISurface{
Router: router,
Router: router,
BusinessLogic: &Implementation{},
}

// TODO: update
Expand Down Expand Up @@ -216,5 +217,5 @@ func writeError(w http.ResponseWriter, err error) {
return
}

writeResponse(w, http.StatusInternalServerError, err)
writeErrorResponse(w, http.StatusInternalServerError, err)
}
26 changes: 25 additions & 1 deletion pkg/broker/logic.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package broker
import (
"net/http"

"gopkg.in/yaml.v2"

osb "github.com/pmorie/go-open-service-broker-client/v2"
)

Expand Down Expand Up @@ -141,7 +143,29 @@ var _ BusinessLogic = &Implementation{}

func (b *Implementation) GetCatalog(w http.ResponseWriter, r *http.Request) (*osb.CatalogResponse, error) {
// Your catalog business logic goes here
return nil, nil
response := &osb.CatalogResponse{}

data := `
---
services:
- name: skeleton-example-service
id: 4f6e6cf6-ffdd-425f-a2c7-3c9258ad246a
description: The example service from the broker skeleton!
bindable: true
plan_updateable: true
plans:
- name: default
id: 86064792-7ea2-467b-af93-ac9694d96d5b
description: The default plan for the skeleton example service
free: true
`

err := yaml.Unmarshal([]byte(data), &response)
if err != nil {
return nil, err
}

return response, nil
}

func (b *Implementation) Provision(pr *osb.ProvisionRequest, w http.ResponseWriter, r *http.Request) (*osb.ProvisionResponse, error) {
Expand Down
13 changes: 13 additions & 0 deletions pkg/broker/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,19 @@ func writeResponse(w http.ResponseWriter, code int, object interface{}) {
w.Write(data)
}

type e struct {
Error string
}

func writeErrorResponse(w http.ResponseWriter, code int, err error) {
type e struct {
Error string
}
writeResponse(w, code, &e{
Error: err.Error(),
})
}

func unmarshalRequestBody(request *http.Request, obj interface{}) error {
body, err := ioutil.ReadAll(request.Body)
if err != nil {
Expand Down
9 changes: 9 additions & 0 deletions vendor/gopkg.in/yaml.v2/.travis.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 3d1b691

Please sign in to comment.