37 Star 403 Fork 75

GVPrancher/rancher

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
upgradeimpl.go 1.52 KB
一键复制 编辑 原始数据 按行查看 历史
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
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/rancher/rancher.git
git@gitee.com:rancher/rancher.git
rancher
rancher
rancher
v2.1.2-rc8

搜索帮助