forked from rancher/rancher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cluster_catalog_sync.go
53 lines (44 loc) · 1.45 KB
/
cluster_catalog_sync.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
package manager
import (
helmlib "github.com/rancher/rancher/pkg/catalog/helm"
v3 "github.com/rancher/types/apis/management.cattle.io/v3"
"github.com/sirupsen/logrus"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/tools/cache"
)
func (m *Manager) updateClusterCatalogError(clusterCatalog *v3.ClusterCatalog, err error) (runtime.Object, error) {
setRefreshedError(&clusterCatalog.Catalog, err)
m.clusterCatalogClient.Update(clusterCatalog)
return nil, err
}
func (m *Manager) ClusterCatalogSync(key string, obj *v3.ClusterCatalog) (runtime.Object, error) {
ns, name, err := cache.SplitMetaNamespaceKey(key)
if err != nil {
return nil, err
}
if obj == nil {
return nil, m.deleteTemplates(name, ns)
}
// always get a refresh catalog from etcd
clusterCatalog, err := m.clusterCatalogClient.GetNamespaced(ns, name, metav1.GetOptions{})
if err != nil {
return nil, err
}
commit, helm, err := helmlib.NewForceUpdate(&clusterCatalog.Catalog)
if err != nil {
return m.updateClusterCatalogError(clusterCatalog, err)
}
if isUpToDate(commit, &clusterCatalog.Catalog) {
if setRefreshed(&clusterCatalog.Catalog) {
m.clusterCatalogClient.Update(clusterCatalog)
}
return nil, nil
}
cmt := &CatalogInfo{
catalog: &clusterCatalog.Catalog,
clusterCatalog: clusterCatalog,
}
logrus.Infof("Updating cluster catalog %s", clusterCatalog.Name)
return nil, m.traverseAndUpdate(helm, commit, cmt)
}