forked from rancher/rancher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
catalog_data.go
55 lines (50 loc) · 1.4 KB
/
catalog_data.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
package app
import (
"github.com/rancher/types/apis/management.cattle.io/v3"
"github.com/rancher/types/config"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
utilerrors "k8s.io/apimachinery/pkg/util/errors"
)
const (
libraryURL = "https://git.rancher.io/charts"
libraryBranch = "master"
libraryName = "library"
systemLibraryURL = "https://git.rancher.io/system-charts"
systemLibraryBranch = "master"
systemLibraryName = "system-library"
)
func addCatalogs(management *config.ManagementContext) error {
return utilerrors.AggregateGoroutines(
// add charts
func() error {
return doAddCatalogs(management, libraryName, libraryURL, libraryBranch)
},
// add rancher-charts
func() error {
return doAddCatalogs(management, systemLibraryName, systemLibraryURL, systemLibraryBranch)
},
)
}
func doAddCatalogs(management *config.ManagementContext, name, url, branch string) error {
catalogClient := management.Management.Catalogs("")
_, err := catalogClient.Get(name, metav1.GetOptions{})
if err != nil && !errors.IsNotFound(err) {
return err
} else if errors.IsNotFound(err) {
obj := &v3.Catalog{
ObjectMeta: metav1.ObjectMeta{
Name: name,
},
Spec: v3.CatalogSpec{
URL: url,
CatalogKind: "helm",
Branch: branch,
},
}
if _, err := catalogClient.Create(obj); err != nil {
return err
}
}
return nil
}