2014-06-06 23:40:48 +00:00
|
|
|
/*
|
|
|
|
Copyright 2014 Google Inc. All rights reserved.
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
2014-07-25 19:28:20 +00:00
|
|
|
"encoding/json"
|
2014-06-06 23:40:48 +00:00
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
2014-07-25 19:28:20 +00:00
|
|
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/version"
|
2014-06-06 23:40:48 +00:00
|
|
|
)
|
|
|
|
|
2014-08-28 09:42:18 +00:00
|
|
|
// Interface holds the methods for clients of Kubernetes,
|
2014-07-10 23:51:34 +00:00
|
|
|
// an interface to allow mock testing.
|
|
|
|
type Interface interface {
|
2014-10-21 21:14:35 +00:00
|
|
|
PodsNamespacer
|
|
|
|
ReplicationControllersNamespacer
|
|
|
|
ServicesNamespacer
|
2014-11-13 14:25:47 +00:00
|
|
|
EndpointsNamespacer
|
2014-08-21 21:14:06 +00:00
|
|
|
VersionInterface
|
2014-10-21 21:14:35 +00:00
|
|
|
MinionsInterface
|
2014-11-14 03:09:03 +00:00
|
|
|
EventNamespacer
|
2014-08-21 21:14:06 +00:00
|
|
|
}
|
|
|
|
|
2014-10-21 21:14:35 +00:00
|
|
|
func (c *Client) ReplicationControllers(namespace string) ReplicationControllerInterface {
|
2014-10-24 15:45:16 +00:00
|
|
|
return newReplicationControllers(c, namespace)
|
2014-08-21 21:14:06 +00:00
|
|
|
}
|
2014-06-06 23:40:48 +00:00
|
|
|
|
2014-10-21 21:14:35 +00:00
|
|
|
func (c *Client) Minions() MinionInterface {
|
2014-10-24 15:45:16 +00:00
|
|
|
return newMinions(c)
|
2014-08-21 21:14:06 +00:00
|
|
|
}
|
2014-06-06 23:40:48 +00:00
|
|
|
|
2014-11-14 03:09:03 +00:00
|
|
|
func (c *Client) Events(namespace string) EventInterface {
|
|
|
|
return newEvents(c, namespace)
|
2014-08-29 02:31:41 +00:00
|
|
|
}
|
2014-08-15 21:14:22 +00:00
|
|
|
|
2014-10-21 21:14:35 +00:00
|
|
|
func (c *Client) Endpoints(namespace string) EndpointsInterface {
|
2014-10-24 15:45:16 +00:00
|
|
|
return newEndpoints(c, namespace)
|
2014-06-06 23:40:48 +00:00
|
|
|
}
|
|
|
|
|
2014-10-21 21:14:35 +00:00
|
|
|
func (c *Client) Pods(namespace string) PodInterface {
|
2014-10-24 15:45:16 +00:00
|
|
|
return newPods(c, namespace)
|
2014-10-21 21:14:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) Services(namespace string) ServiceInterface {
|
2014-10-24 15:45:16 +00:00
|
|
|
return newServices(c, namespace)
|
2014-10-11 00:46:38 +00:00
|
|
|
}
|
|
|
|
|
2014-09-02 10:00:28 +00:00
|
|
|
// VersionInterface has a method to retrieve the server version.
|
2014-08-21 21:14:06 +00:00
|
|
|
type VersionInterface interface {
|
|
|
|
ServerVersion() (*version.Info, error)
|
2014-11-11 07:11:45 +00:00
|
|
|
ServerAPIVersions() (*api.APIVersions, error)
|
2014-08-21 21:14:06 +00:00
|
|
|
}
|
|
|
|
|
2014-09-30 00:15:00 +00:00
|
|
|
// APIStatus is exposed by errors that can be converted to an api.Status object
|
|
|
|
// for finer grained details.
|
|
|
|
type APIStatus interface {
|
|
|
|
Status() api.Status
|
2014-06-06 23:40:48 +00:00
|
|
|
}
|
|
|
|
|
2014-09-30 00:15:00 +00:00
|
|
|
// Client is the implementation of a Kubernetes client.
|
|
|
|
type Client struct {
|
|
|
|
*RESTClient
|
2014-06-22 21:18:01 +00:00
|
|
|
}
|
|
|
|
|
2014-07-25 19:28:20 +00:00
|
|
|
// ServerVersion retrieves and parses the server's version.
|
|
|
|
func (c *Client) ServerVersion() (*version.Info, error) {
|
|
|
|
body, err := c.Get().AbsPath("/version").Do().Raw()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
var info version.Info
|
|
|
|
err = json.Unmarshal(body, &info)
|
|
|
|
if err != nil {
|
2014-11-20 10:00:36 +00:00
|
|
|
return nil, fmt.Errorf("got '%s': %v", string(body), err)
|
2014-07-25 19:28:20 +00:00
|
|
|
}
|
|
|
|
return &info, nil
|
|
|
|
}
|
2014-10-29 00:20:40 +00:00
|
|
|
|
|
|
|
// ServerAPIVersions retrieves and parses the list of API versions the server supports.
|
2014-11-11 07:11:45 +00:00
|
|
|
func (c *Client) ServerAPIVersions() (*api.APIVersions, error) {
|
2014-10-29 00:20:40 +00:00
|
|
|
body, err := c.Get().AbsPath("/api").Do().Raw()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2014-11-11 07:11:45 +00:00
|
|
|
var v api.APIVersions
|
2014-10-29 00:20:40 +00:00
|
|
|
err = json.Unmarshal(body, &v)
|
|
|
|
if err != nil {
|
2014-11-20 10:00:36 +00:00
|
|
|
return nil, fmt.Errorf("got '%s': %v", string(body), err)
|
2014-10-29 00:20:40 +00:00
|
|
|
}
|
|
|
|
return &v, nil
|
|
|
|
}
|