37 Star 411 Fork 76

GVPrancher/rancher

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
sync.go 1.90 KB
一键复制 编辑 原始数据 按行查看 历史
Daishan Peng 提交于 2018-08-23 14:21 . check nil when deleting catalog
package manager
import (
"github.com/rancher/types/apis/management.cattle.io/v3"
"github.com/sirupsen/logrus"
kerrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
func (m *Manager) Sync(key string, obj *v3.Catalog) error {
if obj == nil {
templates, err := m.getTemplateMap(key)
if err != nil {
return err
}
tvToDelete := map[string]struct{}{}
for _, t := range templates {
tvs, err := m.getTemplateVersion(t.Name)
if err != nil {
return err
}
for k := range tvs {
tvToDelete[k] = struct{}{}
}
}
go func() {
for {
for k := range templates {
if err := m.templateClient.Delete(k, &metav1.DeleteOptions{}); err != nil && !kerrors.IsNotFound(err) {
logrus.Warnf("Deleting template %v doesn't succeed. Continue loop", k)
continue
}
}
for k := range tvToDelete {
if err := m.templateVersionClient.Delete(k, &metav1.DeleteOptions{}); err != nil && !kerrors.IsNotFound(err) {
logrus.Warnf("Deleting templateVersion %v doesn't succeed. Continue loop", k)
continue
}
}
break
}
}()
return nil
}
// always get a refresh catalog from etcd
catalog, err := m.catalogClient.Get(key, metav1.GetOptions{})
if err != nil {
return err
}
repoPath, commit, err := m.prepareRepoPath(*catalog)
if err != nil {
v3.CatalogConditionRefreshed.False(catalog)
v3.CatalogConditionRefreshed.ReasonAndMessageFromError(catalog, err)
m.catalogClient.Update(catalog)
return err
}
if commit == catalog.Status.Commit {
logrus.Debugf("Catalog %s is already up to date", catalog.Name)
if v3.CatalogConditionRefreshed.IsUnknown(catalog) {
v3.CatalogConditionRefreshed.True(catalog)
v3.CatalogConditionRefreshed.Reason(catalog, "")
m.catalogClient.Update(catalog)
}
return nil
}
logrus.Infof("Updating catalog %s", catalog.Name)
return m.traverseAndUpdate(repoPath, commit, catalog)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/rancher/rancher.git
git@gitee.com:rancher/rancher.git
rancher
rancher
rancher
v2.1.0-rc3

搜索帮助

0d507c66 1850385 C8b1a773 1850385