forked from juju/juju
/
scale.go
39 lines (34 loc) · 1.01 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
// Copyright 2021 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package application
import (
"context"
"github.com/juju/errors"
"github.com/DavinZhang/juju/caas"
"github.com/DavinZhang/juju/caas/kubernetes/provider/scale"
)
// Scale scales the Application's unit to the value specificied. Scale must
// be >= 0. Application units will be removed or added to meet the scale
// defined.
func (a *app) Scale(scaleTo int) error {
switch a.deploymentType {
case caas.DeploymentStateful:
return scale.PatchReplicasToScale(
context.Background(),
a.name,
int32(scaleTo),
scale.StatefulSetScalePatcher(a.client.AppsV1().StatefulSets(a.namespace)),
)
case caas.DeploymentStateless:
return scale.PatchReplicasToScale(
context.Background(),
a.name,
int32(scaleTo),
scale.DeploymentScalePatcher(a.client.AppsV1().Deployments(a.namespace)),
)
default:
return errors.NotSupportedf(
"application %q deployment type %q cannot be scaled",
a.name, a.deploymentType)
}
}