forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
templateservicebroker.go
71 lines (59 loc) · 2.65 KB
/
templateservicebroker.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package openshift
import (
"fmt"
"time"
"github.com/golang/glog"
kapierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait"
kapi "k8s.io/kubernetes/pkg/api"
"github.com/openshift/origin/pkg/cmd/util/clientcmd"
"github.com/openshift/origin/pkg/cmd/util/variable"
"github.com/openshift/origin/pkg/oc/bootstrap/docker/errors"
)
const (
tsbNamespace = "openshift-template-service-broker"
tsbTemplateName = "template-service-broker"
tsbTemplateLocation = "examples/templateservicebroker/templateservicebroker-template.yaml"
)
// InstallServiceCatalog checks whether the template service broker is installed and installs it if not already installed
func (h *Helper) InstallTemplateServiceBroker(f *clientcmd.Factory, imageFormat string, serverLogLevel int) error {
osClient, kubeClient, err := f.Clients()
if err != nil {
return errors.NewError("cannot obtain API clients").WithCause(err).WithDetails(h.OriginLog())
}
// create the namespace if needed. This is a reserved namespace, so you can't do it with the create project request
if _, err := kubeClient.Core().Namespaces().Create(&kapi.Namespace{ObjectMeta: metav1.ObjectMeta{Name: tsbNamespace}}); err != nil && !kapierrors.IsAlreadyExists(err) {
return errors.NewError("cannot create template service broker project").WithCause(err)
}
// create the template in the tsbNamespace to make it easy to instantiate
if err := ImportObjects(f, tsbNamespace, tsbTemplateLocation); err != nil {
return errors.NewError("cannot create template service broker template").WithCause(err)
}
// create the actual resources required
imageTemplate := variable.NewDefaultImageTemplate()
imageTemplate.Format = imageFormat
imageTemplate.Latest = false
if err = instantiateTemplate(osClient, clientcmd.ResourceMapper(f), tsbNamespace, tsbTemplateName, tsbNamespace, map[string]string{
"IMAGE": imageTemplate.ExpandOrDie(""),
"LOGLEVEL": fmt.Sprint(serverLogLevel),
}, true); err != nil {
return errors.NewError("cannot instantiate logger accounts").WithCause(err)
}
// Wait for the apiserver endpoint to become available
err = wait.Poll(5*time.Second, 600*time.Second, func() (bool, error) {
glog.V(2).Infof("polling for template service broker api server endpoint availability")
ds, err := kubeClient.Extensions().DaemonSets(tsbNamespace).Get("apiserver", metav1.GetOptions{})
if err != nil {
return false, err
}
if ds.Status.NumberReady > 0 {
return true, nil
}
return false, nil
})
if err != nil {
return errors.NewError(fmt.Sprintf("failed to start the template service broker apiserver: %v", err))
}
return nil
}