scale.go 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. Copyright 2015 The Kubernetes Authors.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package unversioned
  14. import (
  15. "k8s.io/kubernetes/pkg/api/meta"
  16. "k8s.io/kubernetes/pkg/api/unversioned"
  17. "k8s.io/kubernetes/pkg/apis/extensions"
  18. )
  19. type ScaleNamespacer interface {
  20. Scales(namespace string) ScaleInterface
  21. }
  22. // ScaleInterface has methods to work with Scale (sub)resources.
  23. type ScaleInterface interface {
  24. Get(string, string) (*extensions.Scale, error)
  25. Update(string, *extensions.Scale) (*extensions.Scale, error)
  26. }
  27. // horizontalPodAutoscalers implements HorizontalPodAutoscalersNamespacer interface
  28. type scales struct {
  29. client *ExtensionsClient
  30. ns string
  31. }
  32. // newHorizontalPodAutoscalers returns a horizontalPodAutoscalers
  33. func newScales(c *ExtensionsClient, namespace string) *scales {
  34. return &scales{
  35. client: c,
  36. ns: namespace,
  37. }
  38. }
  39. // Get takes the reference to scale subresource and returns the subresource or error, if one occurs.
  40. func (c *scales) Get(kind string, name string) (result *extensions.Scale, err error) {
  41. result = &extensions.Scale{}
  42. // TODO this method needs to take a proper unambiguous kind
  43. fullyQualifiedKind := unversioned.GroupVersionKind{Kind: kind}
  44. resource, _ := meta.KindToResource(fullyQualifiedKind)
  45. err = c.client.Get().Namespace(c.ns).Resource(resource.Resource).Name(name).SubResource("scale").Do().Into(result)
  46. return
  47. }
  48. func (c *scales) Update(kind string, scale *extensions.Scale) (result *extensions.Scale, err error) {
  49. result = &extensions.Scale{}
  50. // TODO this method needs to take a proper unambiguous kind
  51. fullyQualifiedKind := unversioned.GroupVersionKind{Kind: kind}
  52. resource, _ := meta.KindToResource(fullyQualifiedKind)
  53. err = c.client.Put().
  54. Namespace(scale.Namespace).
  55. Resource(resource.Resource).
  56. Name(scale.Name).
  57. SubResource("scale").
  58. Body(scale).
  59. Do().
  60. Into(result)
  61. return
  62. }