github.com/timstclair/heapster@v0.20.0-alpha1/Godeps/_workspace/src/k8s.io/kubernetes/pkg/client/unversioned/deployment.go (about)

     1  /*
     2  Copyright 2015 The Kubernetes Authors All rights reserved.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package unversioned
    18  
    19  import (
    20  	"k8s.io/kubernetes/pkg/api"
    21  	"k8s.io/kubernetes/pkg/apis/extensions"
    22  	"k8s.io/kubernetes/pkg/fields"
    23  	"k8s.io/kubernetes/pkg/labels"
    24  	"k8s.io/kubernetes/pkg/watch"
    25  )
    26  
    27  // DeploymentsNamespacer has methods to work with Deployment resources in a namespace
    28  type DeploymentsNamespacer interface {
    29  	Deployments(namespace string) DeploymentInterface
    30  }
    31  
    32  // DeploymentInterface has methods to work with Deployment resources.
    33  type DeploymentInterface interface {
    34  	List(label labels.Selector, field fields.Selector) (*extensions.DeploymentList, error)
    35  	Get(name string) (*extensions.Deployment, error)
    36  	Delete(name string, options *api.DeleteOptions) error
    37  	Create(*extensions.Deployment) (*extensions.Deployment, error)
    38  	Update(*extensions.Deployment) (*extensions.Deployment, error)
    39  	UpdateStatus(*extensions.Deployment) (*extensions.Deployment, error)
    40  	Watch(label labels.Selector, field fields.Selector, opts api.ListOptions) (watch.Interface, error)
    41  }
    42  
    43  // deployments implements DeploymentInterface
    44  type deployments struct {
    45  	client *ExtensionsClient
    46  	ns     string
    47  }
    48  
    49  // newDeployments returns a Deployments
    50  func newDeployments(c *ExtensionsClient, namespace string) *deployments {
    51  	return &deployments{
    52  		client: c,
    53  		ns:     namespace,
    54  	}
    55  }
    56  
    57  // List takes label and field selectors, and returns the list of Deployments that match those selectors.
    58  func (c *deployments) List(label labels.Selector, field fields.Selector) (result *extensions.DeploymentList, err error) {
    59  	result = &extensions.DeploymentList{}
    60  	err = c.client.Get().Namespace(c.ns).Resource("deployments").LabelsSelectorParam(label).FieldsSelectorParam(field).Do().Into(result)
    61  	return
    62  }
    63  
    64  // Get takes name of the deployment, and returns the corresponding deployment object, and an error if there is any.
    65  func (c *deployments) Get(name string) (result *extensions.Deployment, err error) {
    66  	result = &extensions.Deployment{}
    67  	err = c.client.Get().Namespace(c.ns).Resource("deployments").Name(name).Do().Into(result)
    68  	return
    69  }
    70  
    71  // Delete takes name of the deployment and deletes it. Returns an error if one occurs.
    72  func (c *deployments) Delete(name string, options *api.DeleteOptions) error {
    73  	if options == nil {
    74  		return c.client.Delete().Namespace(c.ns).Resource("deployments").Name(name).Do().Error()
    75  	}
    76  	body, err := api.Scheme.EncodeToVersion(options, c.client.APIVersion())
    77  	if err != nil {
    78  		return err
    79  	}
    80  	return c.client.Delete().Namespace(c.ns).Resource("deployments").Name(name).Body(body).Do().Error()
    81  }
    82  
    83  // Create takes the representation of a deployment and creates it.  Returns the server's representation of the deployment, and an error, if there is any.
    84  func (c *deployments) Create(deployment *extensions.Deployment) (result *extensions.Deployment, err error) {
    85  	result = &extensions.Deployment{}
    86  	err = c.client.Post().Namespace(c.ns).Resource("deployments").Body(deployment).Do().Into(result)
    87  	return
    88  }
    89  
    90  // Update takes the representation of a deployment and updates it. Returns the server's representation of the deployment, and an error, if there is any.
    91  func (c *deployments) Update(deployment *extensions.Deployment) (result *extensions.Deployment, err error) {
    92  	result = &extensions.Deployment{}
    93  	err = c.client.Put().Namespace(c.ns).Resource("deployments").Name(deployment.Name).Body(deployment).Do().Into(result)
    94  	return
    95  }
    96  
    97  func (c *deployments) UpdateStatus(deployment *extensions.Deployment) (result *extensions.Deployment, err error) {
    98  	result = &extensions.Deployment{}
    99  	err = c.client.Put().Namespace(c.ns).Resource("deployments").Name(deployment.Name).SubResource("status").Body(deployment).Do().Into(result)
   100  	return
   101  }
   102  
   103  // Watch returns a watch.Interface that watches the requested deployments.
   104  func (c *deployments) Watch(label labels.Selector, field fields.Selector, opts api.ListOptions) (watch.Interface, error) {
   105  	return c.client.Get().
   106  		Prefix("watch").
   107  		Namespace(c.ns).
   108  		Resource("deployments").
   109  		Param("resourceVersion", opts.ResourceVersion).
   110  		TimeoutSeconds(TimeoutFromListOptions(opts)).
   111  		LabelsSelectorParam(label).
   112  		FieldsSelectorParam(field).
   113  		Watch()
   114  }