-
Notifications
You must be signed in to change notification settings - Fork 3k
/
upgradeimpl.go
62 lines (52 loc) · 1.52 KB
/
upgradeimpl.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
package upgrade
import (
"context"
"fmt"
"github.com/rancher/rancher/pkg/controllers/user/alert/deploy"
"github.com/rancher/rancher/pkg/controllers/user/systemimage"
rv1beta2 "github.com/rancher/types/apis/apps/v1beta2"
"github.com/rancher/types/config"
"k8s.io/api/apps/v1beta2"
apierrors "k8s.io/apimachinery/pkg/api/errors"
)
var (
serviceName = "alerting"
)
type alertService struct {
clusterName string
deployments rv1beta2.DeploymentInterface
}
func init() {
systemimage.RegisterSystemService(serviceName, &alertService{})
}
func (l *alertService) Init(ctx context.Context, cluster *config.UserContext) {
l.clusterName = cluster.ClusterName
l.deployments = cluster.Apps.Deployments("")
}
func (l *alertService) Version() (string, error) {
deployment := deploy.GetDeployment()
return systemimage.DefaultGetVersion(deployment)
}
func (l *alertService) Upgrade(currentVersion string) (string, error) {
deployment := deploy.GetDeployment()
newVersion, err := systemimage.DefaultGetVersion(deployment)
if err != nil {
return "", err
}
if currentVersion == newVersion {
return currentVersion, nil
}
if err := l.upgradeDeployment(deployment); err != nil {
return "", err
}
return newVersion, nil
}
func (l *alertService) upgradeDeployment(deployment *v1beta2.Deployment) error {
if _, err := l.deployments.Update(deployment); err != nil {
if apierrors.IsNotFound(err) {
return nil
}
return fmt.Errorf("upgrade system service %s:%s failed, %v", deployment.Namespace, deployment.Name, err)
}
return nil
}