44 "context"
55 "encoding/json"
66 "io"
7- "net/url"
8- "os"
97 "time"
108
119 "github.com/fabric8-services/fabric8-wit/app"
@@ -17,10 +15,10 @@ import (
1715
1816 "github.com/goadesign/goa"
1917 errs "github.com/pkg/errors"
20- uuid "github.com/satori/go.uuid"
18+ "github.com/satori/go.uuid"
2119 "golang.org/x/net/websocket"
2220 metaV1 "k8s.io/apimachinery/pkg/apis/meta/v1"
23- v1 "k8s.io/client-go/pkg/api/v1"
21+ "k8s.io/client-go/pkg/api/v1"
2422 "k8s.io/client-go/tools/cache"
2523)
2624
@@ -31,17 +29,6 @@ type DeploymentsController struct {
3129 ClientGetter
3230}
3331
34- // ClientGetter creates an instances of clients used by this controller
35- type ClientGetter interface {
36- GetKubeClient (ctx context.Context ) (kubernetes.KubeClientInterface , error )
37- GetAndCheckOSIOClient (ctx context.Context ) (OpenshiftIOClient , error )
38- }
39-
40- // Default implementation of KubeClientGetter and OSIOClientGetter used by NewDeploymentsController
41- type defaultClientGetter struct {
42- config * configuration.Registry
43- }
44-
4532// NewDeploymentsController creates a deployments controller.
4633func NewDeploymentsController (service * goa.Service , config * configuration.Registry ) * DeploymentsController {
4734 return & DeploymentsController {
@@ -61,41 +48,6 @@ func tostring(item interface{}) string {
6148 return string (bytes )
6249}
6350
64- func (g * defaultClientGetter ) GetAndCheckOSIOClient (ctx context.Context ) (OpenshiftIOClient , error ) {
65-
66- // defaults
67- host := "localhost"
68- scheme := "https"
69-
70- req := goa .ContextRequest (ctx )
71- if req != nil {
72- // Note - it's probably more efficient to force a loopback host, and only use the port number here
73- // (on some systems using a non-loopback interface forces a network stack traverse)
74- host = req .Host
75- scheme = req .URL .Scheme
76- }
77-
78- // The deployments API communicates with the rest of WIT via the stnadard WIT API.
79- // This environment variable is used for local development of the deployments API, to point ot a remote WIT.
80- witURLStr := os .Getenv ("FABRIC8_WIT_API_URL" )
81- if witURLStr != "" {
82- witurl , err := url .Parse (witURLStr )
83- if err != nil {
84- log .Error (ctx , map [string ]interface {}{
85- "FABRIC8_WIT_API_URL" : witURLStr ,
86- "err" : err ,
87- }, "cannot parse FABRIC8_WIT_API_URL: %s" , witURLStr )
88- return nil , errs .Wrapf (err , "cannot parse FABRIC8_WIT_API_URL: %s" , witURLStr )
89- }
90- host = witurl .Host
91- scheme = witurl .Scheme
92- }
93-
94- oc := NewOSIOClient (ctx , scheme , host )
95-
96- return oc , nil
97- }
98-
9951// getSpaceNameFromSpaceID() converts an OSIO Space UUID to an OpenShift space name.
10052// will return an error if the space is not found.
10153func (c * DeploymentsController ) getSpaceNameFromSpaceID (ctx context.Context , spaceID uuid.UUID ) (* string , error ) {
@@ -116,74 +68,6 @@ func (c *DeploymentsController) getSpaceNameFromSpaceID(ctx context.Context, spa
11668 return osioSpace .Attributes .Name , nil
11769}
11870
119- func (g * defaultClientGetter ) getNamespaceName (ctx context.Context ) (* string , error ) {
120-
121- osioclient , err := g .GetAndCheckOSIOClient (ctx )
122- if err != nil {
123- return nil , err
124- }
125-
126- kubeSpaceAttr , err := osioclient .GetNamespaceByType (ctx , nil , "user" )
127- if err != nil {
128- return nil , errs .Wrap (err , "unable to retrieve 'user' namespace" )
129- }
130- if kubeSpaceAttr == nil {
131- return nil , errors .NewNotFoundError ("namespace" , "user" )
132- }
133-
134- return kubeSpaceAttr .Name , nil
135- }
136-
137- // GetKubeClient creates a kube client for the appropriate cluster assigned to the current user
138- func (g * defaultClientGetter ) GetKubeClient (ctx context.Context ) (kubernetes.KubeClientInterface , error ) {
139-
140- kubeNamespaceName , err := g .getNamespaceName (ctx )
141- if err != nil {
142- log .Error (ctx , map [string ]interface {}{
143- "err" : err ,
144- }, "could not retrieve namespace name" )
145- return nil , errs .Wrap (err , "could not retrieve namespace name" )
146- }
147-
148- osioclient , err := g .GetAndCheckOSIOClient (ctx )
149- if err != nil {
150- log .Error (ctx , map [string ]interface {}{
151- "err" : err ,
152- }, "could not create OSIO client" )
153- return nil , err
154- }
155-
156- baseURLProvider , err := NewURLProvider (ctx , g .config , osioclient )
157- if err != nil {
158- log .Error (ctx , map [string ]interface {}{
159- "err" : err ,
160- }, "could not retrieve tenant data" )
161- return nil , errs .Wrap (err , "could not retrieve tenant data" )
162- }
163-
164- /* Timeout used per HTTP request to Kubernetes/OpenShift API servers.
165- * Communication with Hawkular currently uses a hard-coded 30 second
166- * timeout per request, and does not use this parameter. */
167- // create the cluster API client
168- kubeConfig := & kubernetes.KubeClientConfig {
169- BaseURLProvider : baseURLProvider ,
170- UserNamespace : * kubeNamespaceName ,
171- Timeout : g .config .GetDeploymentsHTTPTimeoutSeconds (),
172- }
173- kc , err := kubernetes .NewKubeClient (kubeConfig )
174- if err != nil {
175- url , _ := baseURLProvider .GetAPIURL ()
176- log .Error (ctx , map [string ]interface {}{
177- "err" : err ,
178- "user_namespace" : * kubeNamespaceName ,
179- "cluster" : * url ,
180- }, "could not create Kubernetes client object" )
181- return nil , errs .Wrap (err , "could not create Kubernetes client object" )
182- }
183- return kc , nil
184- }
185-
186- // SetDeployment runs the setDeployment action.
18771func (c * DeploymentsController ) SetDeployment (ctx * app.SetDeploymentDeploymentsContext ) error {
18872
18973 // we double check podcount here, because in the future we might have different query parameters
0 commit comments