forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scale.go
63 lines (54 loc) · 2.11 KB
/
scale.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package client
import (
"fmt"
"k8s.io/kubernetes/pkg/api/errors"
"k8s.io/kubernetes/pkg/apis/extensions"
unversioned_extensions "k8s.io/kubernetes/pkg/client/typed/generated/extensions/unversioned"
kclient "k8s.io/kubernetes/pkg/client/unversioned"
"github.com/openshift/origin/pkg/api/latest"
)
type delegatingScaleInterface struct {
dcs DeploymentConfigInterface
scales kclient.ScaleInterface
}
type delegatingScaleNamespacer struct {
dcNS DeploymentConfigsNamespacer
scaleNS kclient.ScaleNamespacer
}
func (c *delegatingScaleNamespacer) Scales(namespace string) unversioned_extensions.ScaleInterface {
return &delegatingScaleInterface{
dcs: c.dcNS.DeploymentConfigs(namespace),
scales: c.scaleNS.Scales(namespace),
}
}
func NewDelegatingScaleNamespacer(dcNamespacer DeploymentConfigsNamespacer, sNamespacer kclient.ScaleNamespacer) unversioned_extensions.ScalesGetter {
return &delegatingScaleNamespacer{
dcNS: dcNamespacer,
scaleNS: sNamespacer,
}
}
// Get takes the reference to scale subresource and returns the subresource or error, if one occurs.
func (c *delegatingScaleInterface) Get(kind string, name string) (result *extensions.Scale, err error) {
switch {
case kind == "DeploymentConfig":
return c.dcs.GetScale(name)
// TODO: This is borked because the interface for Get is broken. Kind is insufficient.
case latest.IsKindInAnyOriginGroup(kind):
return nil, errors.NewBadRequest(fmt.Sprintf("Kind %s has no Scale subresource", kind))
default:
return c.scales.Get(kind, name)
}
}
// Update takes a scale subresource object, updates the stored version to match it, and
// returns the subresource or error, if one occurs.
func (c *delegatingScaleInterface) Update(kind string, scale *extensions.Scale) (result *extensions.Scale, err error) {
switch {
case kind == "DeploymentConfig":
return c.dcs.UpdateScale(scale)
// TODO: This is borked because the interface for Update is broken. Kind is insufficient.
case latest.IsKindInAnyOriginGroup(kind):
return nil, errors.NewBadRequest(fmt.Sprintf("Kind %s has no Scale subresource", kind))
default:
return c.scales.Update(kind, scale)
}
}