github.com/timstclair/heapster@v0.20.0-alpha1/Godeps/_workspace/src/k8s.io/kubernetes/pkg/client/unversioned/scale.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/meta"
    21  	"k8s.io/kubernetes/pkg/apis/extensions"
    22  )
    23  
    24  type ScaleNamespacer interface {
    25  	Scales(namespace string) ScaleInterface
    26  }
    27  
    28  // ScaleInterface has methods to work with Scale (sub)resources.
    29  type ScaleInterface interface {
    30  	Get(string, string) (*extensions.Scale, error)
    31  	Update(string, *extensions.Scale) (*extensions.Scale, error)
    32  }
    33  
    34  // horizontalPodAutoscalers implements HorizontalPodAutoscalersNamespacer interface
    35  type scales struct {
    36  	client *ExtensionsClient
    37  	ns     string
    38  }
    39  
    40  // newHorizontalPodAutoscalers returns a horizontalPodAutoscalers
    41  func newScales(c *ExtensionsClient, namespace string) *scales {
    42  	return &scales{
    43  		client: c,
    44  		ns:     namespace,
    45  	}
    46  }
    47  
    48  // Get takes the reference to scale subresource and returns the subresource or error, if one occurs.
    49  func (c *scales) Get(kind string, name string) (result *extensions.Scale, err error) {
    50  	result = &extensions.Scale{}
    51  	resource, _ := meta.KindToResource(kind, false)
    52  	err = c.client.Get().Namespace(c.ns).Resource(resource).Name(name).SubResource("scale").Do().Into(result)
    53  	return
    54  }
    55  
    56  func (c *scales) Update(kind string, scale *extensions.Scale) (result *extensions.Scale, err error) {
    57  	result = &extensions.Scale{}
    58  	resource, _ := meta.KindToResource(kind, false)
    59  	err = c.client.Put().
    60  		Namespace(scale.Namespace).
    61  		Resource(resource).
    62  		Name(scale.Name).
    63  		SubResource("scale").
    64  		Body(scale).
    65  		Do().
    66  		Into(result)
    67  	return
    68  }