forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservice_catalog.go
155 lines (137 loc) · 5.64 KB
/
service_catalog.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
package service_catalog
import (
"net/url"
"path"
"github.com/golang/glog"
rbacv1 "k8s.io/api/rbac/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
aggregatorclient "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset"
rbacv1helpers "k8s.io/kubernetes/pkg/apis/rbac/v1"
"k8s.io/kubernetes/pkg/registry/rbac/reconciliation"
"github.com/openshift/origin/pkg/cmd/util/variable"
"github.com/openshift/origin/pkg/oc/clusteradd/componentinstall"
"github.com/openshift/origin/pkg/oc/clusterup/coreinstall/kubeapiserver"
"github.com/openshift/origin/pkg/oc/clusterup/docker/dockerhelper"
"github.com/openshift/origin/pkg/oc/clusterup/docker/errors"
"github.com/openshift/origin/pkg/oc/clusterup/manifests"
)
const (
catalogNamespace = "kube-service-catalog"
ServiceCatalogServiceIP = "172.30.1.2"
)
type ServiceCatalogComponentOptions struct {
InstallContext componentinstall.Context
}
func (c *ServiceCatalogComponentOptions) Name() string {
return "openshift-service-catalog"
}
func (c *ServiceCatalogComponentOptions) Install(dockerClient dockerhelper.Interface) error {
kubeAdminClient, err := kubernetes.NewForConfig(c.InstallContext.ClusterAdminClientConfig())
if err != nil {
return err
}
for _, role := range getServiceCatalogClusterRoles() {
if _, err := (&reconciliation.ReconcileRoleOptions{
Confirm: true,
RemoveExtraPermissions: false,
Role: reconciliation.ClusterRoleRuleOwner{ClusterRole: &role},
Client: reconciliation.ClusterRoleModifier{
Client: kubeAdminClient.RbacV1().ClusterRoles(),
},
}).Run(); err != nil {
return errors.NewError("could not reconcile service catalog cluster role %s", role.Name).WithCause(err)
}
}
// Instantiate service catalog
imageTemplate := variable.NewDefaultImageTemplate()
imageTemplate.Format = c.InstallContext.ImageFormat()
imageTemplate.Latest = false
masterConfigPath := path.Join(c.InstallContext.BaseDir(), kubeapiserver.KubeAPIServerDirName, "master-config.yaml")
masterConfig, err := componentinstall.ReadMasterConfig(masterConfigPath)
if err != nil {
return err
}
masterURL, err := url.Parse(masterConfig.MasterPublicURL)
if err != nil {
return err
}
params := map[string]string{
"SERVICE_CATALOG_SERVICE_IP": ServiceCatalogServiceIP,
"CORS_ALLOWED_ORIGIN": masterURL.Hostname(),
"SERVICE_CATALOG_IMAGE": imageTemplate.ExpandOrDie("service-catalog"),
}
aggregatorClient, err := aggregatorclient.NewForConfig(c.InstallContext.ClusterAdminClientConfig())
if err != nil {
return err
}
// Stands up the service catalog apiserver, etcd, and controller manager
component := componentinstall.Template{
Name: "service-catalog",
Namespace: catalogNamespace,
RBACTemplate: manifests.MustAsset("examples/service-catalog/service-catalog-rbac.yaml"),
InstallTemplate: manifests.MustAsset("examples/service-catalog/service-catalog.yaml"),
// Wait for the apiserver endpoint to become available
WaitCondition: func() (bool, error) {
glog.V(2).Infof("polling for service catalog api server endpoint availability")
deployment, err := kubeAdminClient.AppsV1().Deployments(catalogNamespace).Get("apiserver", metav1.GetOptions{})
if err != nil {
return false, err
}
if deployment.Status.AvailableReplicas == 0 {
return false, nil
}
return componentinstall.CheckForAPIs(aggregatorClient, "v1beta1.servicecatalog.k8s.io")
},
}
err = component.MakeReady(
c.InstallContext.ClientImage(),
c.InstallContext.BaseDir(),
params).Install(dockerClient)
if err != nil {
return err
}
return nil
}
// TODO move to template
func getServiceCatalogClusterRoles() []rbacv1.ClusterRole {
return []rbacv1.ClusterRole{
{
ObjectMeta: metav1.ObjectMeta{
Name: "system:openshift:service-catalog:aggregate-to-admin",
Labels: map[string]string{"rbac.authorization.k8s.io/aggregate-to-admin": "true"},
},
Rules: []rbacv1.PolicyRule{
rbacv1helpers.NewRule("create", "update", "delete", "get", "list", "watch", "patch").Groups("servicecatalog.k8s.io").Resources("serviceinstances", "servicebindings", "servicebrokers", "serviceclasses", "serviceplans").RuleOrDie(),
rbacv1helpers.NewRule("create", "update", "delete", "get", "list", "watch").Groups("settings.k8s.io").Resources("podpresets").RuleOrDie(),
},
},
{
ObjectMeta: metav1.ObjectMeta{
Name: "system:openshift:service-catalog:aggregate-to-edit",
Labels: map[string]string{"rbac.authorization.k8s.io/aggregate-to-edit": "true"},
},
Rules: []rbacv1.PolicyRule{
rbacv1helpers.NewRule("create", "update", "delete", "get", "list", "watch", "patch").Groups("servicecatalog.k8s.io").Resources("serviceinstances", "servicebindings", "servicebrokers", "serviceclasses", "serviceplans").RuleOrDie(),
rbacv1helpers.NewRule("create", "update", "delete", "get", "list", "watch").Groups("settings.k8s.io").Resources("podpresets").RuleOrDie(),
},
},
{
ObjectMeta: metav1.ObjectMeta{
Name: "system:openshift:service-catalog:aggregate-to-view",
Labels: map[string]string{"rbac.authorization.k8s.io/aggregate-to-view": "true"},
},
Rules: []rbacv1.PolicyRule{
rbacv1helpers.NewRule("get", "list", "watch").Groups("servicecatalog.k8s.io").Resources("serviceinstances", "servicebindings", "servicebrokers", "serviceclasses", "serviceplans").RuleOrDie(),
},
},
{
ObjectMeta: metav1.ObjectMeta{
Name: "system:openshift:clusterservicebroker-client",
},
Rules: []rbacv1.PolicyRule{
rbacv1helpers.NewRule("create", "update", "delete", "get", "list", "watch", "patch").Groups("servicecatalog.k8s.io").Resources("clusterservicebrokers").RuleOrDie(),
},
},
}
}