forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
template_service_broker.go
90 lines (75 loc) · 2.93 KB
/
template_service_broker.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package template_service_broker
import (
"fmt"
"path"
"github.com/golang/glog"
"github.com/openshift/origin/pkg/oc/clusteradd/components/register-template-service-broker"
"github.com/openshift/origin/pkg/oc/clusterup/coreinstall/kubeapiserver"
"github.com/openshift/origin/pkg/oc/clusterup/manifests"
"k8s.io/client-go/kubernetes"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"github.com/openshift/origin/pkg/cmd/util/variable"
"github.com/openshift/origin/pkg/oc/clusteradd/componentinstall"
"github.com/openshift/origin/pkg/oc/clusterup/docker/dockerhelper"
"github.com/openshift/origin/pkg/oc/errors"
)
const (
tsbNamespace = "openshift-template-service-broker"
)
type TemplateServiceBrokerComponentOptions struct {
InstallContext componentinstall.Context
}
func (c *TemplateServiceBrokerComponentOptions) Name() string {
return "openshift-template-service-broker"
}
func (c *TemplateServiceBrokerComponentOptions) Install(dockerClient dockerhelper.Interface) error {
kubeAdminClient, err := kubernetes.NewForConfig(c.InstallContext.ClusterAdminClientConfig())
if err != nil {
return errors.NewError("cannot obtain API clients").WithCause(err)
}
// create the actual resources required
imageTemplate := variable.NewDefaultImageTemplate()
imageTemplate.Format = c.InstallContext.ImageFormat()
imageTemplate.Latest = false
params := map[string]string{
"IMAGE": imageTemplate.ExpandOrDie("template-service-broker"),
"LOGLEVEL": fmt.Sprintf("%d", c.InstallContext.ComponentLogLevel()),
"OPENSHIFT_PULL_POLICY": c.InstallContext.ImagePullPolicy(),
"NAMESPACE": tsbNamespace,
}
glog.V(2).Infof("instantiating template service broker template with parameters %v", params)
component := componentinstall.Template{
Name: "template-service-broker-apiserver",
Namespace: tsbNamespace,
RBACTemplate: manifests.MustAsset("install/templateservicebroker/rbac-template.yaml"),
InstallTemplate: manifests.MustAsset("install/templateservicebroker/apiserver-template.yaml"),
// wait until the apiservice is ready
WaitCondition: func() (bool, error) {
glog.V(2).Infof("polling for template service broker api server endpoint availability")
ds, err := kubeAdminClient.AppsV1().DaemonSets(tsbNamespace).Get("apiserver", metav1.GetOptions{})
if err != nil {
return false, err
}
if ds.Status.NumberAvailable > 0 {
return true, nil
}
return false, nil
},
}
err = component.MakeReady(
c.InstallContext.ClientImage(),
c.InstallContext.BaseDir(),
params).Install(dockerClient)
if err != nil {
return err
}
masterConfigDir := path.Join(c.InstallContext.BaseDir(), kubeapiserver.KubeAPIServerDirName)
// the service catalog may not be here, but as a best effort try to register
register_template_service_broker.RegisterTemplateServiceBroker(
dockerClient,
c.InstallContext.ClientImage(),
c.InstallContext.BaseDir(),
masterConfigDir,
)
return nil
}