2014-10-21 21:14:35 +00:00
|
|
|
/*
|
2015-05-01 16:19:44 +00:00
|
|
|
Copyright 2014 The Kubernetes Authors All rights reserved.
|
2014-10-21 21:14:35 +00:00
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
2015-08-12 17:35:07 +00:00
|
|
|
package unversioned
|
2014-10-21 21:14:35 +00:00
|
|
|
|
|
|
|
import (
|
2015-08-05 22:03:47 +00:00
|
|
|
"k8s.io/kubernetes/pkg/api"
|
2015-11-17 09:59:13 +00:00
|
|
|
"k8s.io/kubernetes/pkg/api/unversioned"
|
2015-11-06 17:55:31 +00:00
|
|
|
"k8s.io/kubernetes/pkg/util"
|
2015-08-05 22:03:47 +00:00
|
|
|
"k8s.io/kubernetes/pkg/watch"
|
2014-10-21 21:14:35 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// ServicesNamespacer has methods to work with Service resources in a namespace
|
|
|
|
type ServicesNamespacer interface {
|
|
|
|
Services(namespace string) ServiceInterface
|
|
|
|
}
|
|
|
|
|
|
|
|
// ServiceInterface has methods to work with Service resources.
|
|
|
|
type ServiceInterface interface {
|
2015-12-02 11:12:57 +00:00
|
|
|
List(opts unversioned.ListOptions) (*api.ServiceList, error)
|
2014-10-21 21:14:35 +00:00
|
|
|
Get(name string) (*api.Service, error)
|
|
|
|
Create(srv *api.Service) (*api.Service, error)
|
|
|
|
Update(srv *api.Service) (*api.Service, error)
|
|
|
|
Delete(name string) error
|
2015-11-26 15:27:45 +00:00
|
|
|
Watch(opts unversioned.ListOptions) (watch.Interface, error)
|
2015-11-06 17:55:31 +00:00
|
|
|
ProxyGet(scheme, name, port, path string, params map[string]string) ResponseWrapper
|
2014-10-21 21:14:35 +00:00
|
|
|
}
|
|
|
|
|
2015-08-25 11:56:08 +00:00
|
|
|
// services implements ServicesNamespacer interface
|
2014-10-24 15:45:16 +00:00
|
|
|
type services struct {
|
2014-10-21 21:14:35 +00:00
|
|
|
r *Client
|
|
|
|
ns string
|
|
|
|
}
|
|
|
|
|
2015-08-25 11:56:08 +00:00
|
|
|
// newServices returns a services
|
2014-10-24 15:45:16 +00:00
|
|
|
func newServices(c *Client, namespace string) *services {
|
|
|
|
return &services{c, namespace}
|
2014-10-21 21:14:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// List takes a selector, and returns the list of services that match that selector
|
2015-12-02 11:12:57 +00:00
|
|
|
func (c *services) List(opts unversioned.ListOptions) (result *api.ServiceList, err error) {
|
2014-10-21 21:14:35 +00:00
|
|
|
result = &api.ServiceList{}
|
2015-03-10 04:45:35 +00:00
|
|
|
err = c.r.Get().
|
|
|
|
Namespace(c.ns).
|
|
|
|
Resource("services").
|
2015-11-26 10:06:01 +00:00
|
|
|
VersionedParams(&opts, api.Scheme).
|
2015-03-10 04:45:35 +00:00
|
|
|
Do().
|
|
|
|
Into(result)
|
2014-10-21 21:14:35 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get returns information about a particular service.
|
2014-10-24 15:45:16 +00:00
|
|
|
func (c *services) Get(name string) (result *api.Service, err error) {
|
2014-10-21 21:14:35 +00:00
|
|
|
result = &api.Service{}
|
2014-12-26 20:06:25 +00:00
|
|
|
err = c.r.Get().Namespace(c.ns).Resource("services").Name(name).Do().Into(result)
|
2014-10-21 21:14:35 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create creates a new service.
|
2014-10-24 15:45:16 +00:00
|
|
|
func (c *services) Create(svc *api.Service) (result *api.Service, err error) {
|
2014-10-21 21:14:35 +00:00
|
|
|
result = &api.Service{}
|
2015-04-15 18:35:23 +00:00
|
|
|
err = c.r.Post().Namespace(c.ns).Resource("services").Body(svc).Do().Into(result)
|
2014-10-21 21:14:35 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update updates an existing service.
|
2014-10-24 15:45:16 +00:00
|
|
|
func (c *services) Update(svc *api.Service) (result *api.Service, err error) {
|
2014-10-21 21:14:35 +00:00
|
|
|
result = &api.Service{}
|
2015-04-15 18:35:23 +00:00
|
|
|
err = c.r.Put().Namespace(c.ns).Resource("services").Name(svc.Name).Body(svc).Do().Into(result)
|
2014-10-21 21:14:35 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Delete deletes an existing service.
|
2014-10-24 15:45:16 +00:00
|
|
|
func (c *services) Delete(name string) error {
|
2015-04-15 18:35:23 +00:00
|
|
|
return c.r.Delete().Namespace(c.ns).Resource("services").Name(name).Do().Error()
|
2014-10-21 21:14:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Watch returns a watch.Interface that watches the requested services.
|
2015-11-26 15:27:45 +00:00
|
|
|
func (c *services) Watch(opts unversioned.ListOptions) (watch.Interface, error) {
|
2014-10-21 21:14:35 +00:00
|
|
|
return c.r.Get().
|
2014-12-26 20:06:25 +00:00
|
|
|
Prefix("watch").
|
2014-12-16 21:11:45 +00:00
|
|
|
Namespace(c.ns).
|
2014-12-26 20:06:25 +00:00
|
|
|
Resource("services").
|
2015-10-16 13:07:14 +00:00
|
|
|
VersionedParams(&opts, api.Scheme).
|
2014-10-21 21:14:35 +00:00
|
|
|
Watch()
|
|
|
|
}
|
2015-08-25 11:56:08 +00:00
|
|
|
|
|
|
|
// ProxyGet returns a response of the service by calling it through the proxy.
|
2015-11-06 17:55:31 +00:00
|
|
|
func (c *services) ProxyGet(scheme, name, port, path string, params map[string]string) ResponseWrapper {
|
2015-08-25 11:56:08 +00:00
|
|
|
request := c.r.Get().
|
|
|
|
Prefix("proxy").
|
|
|
|
Namespace(c.ns).
|
|
|
|
Resource("services").
|
2015-11-06 17:55:31 +00:00
|
|
|
Name(util.JoinSchemeNamePort(scheme, name, port)).
|
2015-08-25 11:56:08 +00:00
|
|
|
Suffix(path)
|
|
|
|
for k, v := range params {
|
|
|
|
request = request.Param(k, v)
|
|
|
|
}
|
|
|
|
return request
|
|
|
|
}
|