forked from rancher/rancher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
extra_args_injection.go
60 lines (50 loc) · 1.33 KB
/
extra_args_injection.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
package common
import (
"net/url"
"strings"
"github.com/rancher/rancher/pkg/ref"
"github.com/rancher/rancher/pkg/settings"
"github.com/rancher/types/apis/project.cattle.io/v3"
"github.com/sirupsen/logrus"
)
type InjectAppArgsFunc func(obj *v3.App) (content map[string]string)
const (
systemCatalogName = "system-library"
)
var (
extraArgsFuncs = []InjectAppArgsFunc{
injectDefaultRegistry,
injectClusterInfo,
}
)
func injectDefaultRegistry(obj *v3.App) map[string]string {
values, err := url.Parse(obj.Spec.ExternalID)
if err != nil {
logrus.Errorf("check catalog type failed: %s", err.Error())
}
catalogWithNamespace := values.Query().Get("catalog")
split := strings.SplitN(catalogWithNamespace, "/", 2)
catalog := split[len(split)-1]
reg := settings.SystemDefaultRegistry.Get()
if catalog != systemCatalogName || reg == "" {
return nil
}
return map[string]string{"systemDefaultRegistry": reg}
}
func injectClusterInfo(obj *v3.App) map[string]string {
clusterName, projectName := ref.Parse(obj.Spec.ProjectName)
return map[string]string{
"clusterName": clusterName,
"projectName": projectName,
}
}
func GetExtraArgs(app *v3.App) map[string]string {
rtn := map[string]string{}
for _, afunc := range extraArgsFuncs {
content := afunc(app)
for k, v := range content {
rtn["global."+k] = v
}
}
return rtn
}