-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.go
97 lines (82 loc) · 4.26 KB
/
setup.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package providers
import (
"github.com/rancher/norman/types"
"github.com/rancher/rancher/pkg/pipeline/providers/github"
"github.com/rancher/rancher/pkg/pipeline/providers/gitlab"
"github.com/rancher/rancher/pkg/pipeline/remote/model"
"github.com/rancher/rancher/pkg/pipeline/utils"
"github.com/rancher/types/apis/project.cattle.io/v3/schema"
"github.com/rancher/types/client/project/v3"
"github.com/rancher/types/config"
"k8s.io/client-go/tools/cache"
)
var (
providers = make(map[string]SourceCodeProvider)
providersByType = make(map[string]SourceCodeProvider)
)
var sourceCodeProviderConfigTypes = []string{
client.GithubPipelineConfigType,
client.GitlabPipelineConfigType,
}
func SetupSourceCodeProviderConfig(management *config.ScaledContext, schemas *types.Schemas) {
configure(management)
providerBaseSchema := schemas.Schema(&schema.Version, client.SourceCodeProviderType)
setSourceCodeProviderStore(providerBaseSchema, management)
for _, scpSubtype := range sourceCodeProviderConfigTypes {
providersByType[scpSubtype].CustomizeSchemas(schemas)
}
}
func configure(management *config.ScaledContext) {
// Indexers for looking up resources by projectName, etc.
pipelineInformer := management.Project.Pipelines("").Controller().Informer()
pipelineIndexers := map[string]cache.IndexFunc{
utils.PipelineByProjectIndex: utils.PipelineByProjectName,
}
pipelineInformer.AddIndexers(pipelineIndexers)
executionInformer := management.Project.PipelineExecutions("").Controller().Informer()
executionIndexers := map[string]cache.IndexFunc{
utils.PipelineExecutionByProjectIndex: utils.PipelineExecutionByProjectName,
}
executionInformer.AddIndexers(executionIndexers)
sourceCodeCredentialInformer := management.Project.SourceCodeCredentials("").Controller().Informer()
sourceCodeCredentialIndexers := map[string]cache.IndexFunc{
utils.SourceCodeCredentialByProjectAndTypeIndex: utils.SourceCodeCredentialByProjectNameAndType,
}
sourceCodeCredentialInformer.AddIndexers(sourceCodeCredentialIndexers)
sourceCodeRepositoryInformer := management.Project.SourceCodeRepositories("").Controller().Informer()
sourceCodeRepositoryIndexers := map[string]cache.IndexFunc{
utils.SourceCodeRepositoryByCredentialIndex: utils.SourceCodeRepositoryByCredentialName,
utils.SourceCodeRepositoryByProjectAndTypeIndex: utils.SourceCodeRepositoryByProjectNameAndType,
}
sourceCodeRepositoryInformer.AddIndexers(sourceCodeRepositoryIndexers)
ghProvider := &github.GhProvider{
SourceCodeProviderConfigs: management.Project.SourceCodeProviderConfigs(""),
SourceCodeCredentialLister: management.Project.SourceCodeCredentials("").Controller().Lister(),
SourceCodeCredentials: management.Project.SourceCodeCredentials(""),
SourceCodeRepositories: management.Project.SourceCodeRepositories(""),
Pipelines: management.Project.Pipelines(""),
PipelineExecutions: management.Project.PipelineExecutions(""),
PipelineIndexer: pipelineInformer.GetIndexer(),
PipelineExecutionIndexer: executionInformer.GetIndexer(),
SourceCodeCredentialIndexer: sourceCodeCredentialInformer.GetIndexer(),
SourceCodeRepositoryIndexer: sourceCodeRepositoryInformer.GetIndexer(),
AuthConfigs: management.Management.AuthConfigs(""),
}
providers[model.GithubType] = ghProvider
providersByType[client.GithubPipelineConfigType] = ghProvider
glProvider := &gitlab.GlProvider{
SourceCodeProviderConfigs: management.Project.SourceCodeProviderConfigs(""),
SourceCodeCredentialLister: management.Project.SourceCodeCredentials("").Controller().Lister(),
SourceCodeCredentials: management.Project.SourceCodeCredentials(""),
SourceCodeRepositories: management.Project.SourceCodeRepositories(""),
Pipelines: management.Project.Pipelines(""),
PipelineExecutions: management.Project.PipelineExecutions(""),
PipelineIndexer: pipelineInformer.GetIndexer(),
PipelineExecutionIndexer: executionInformer.GetIndexer(),
SourceCodeCredentialIndexer: sourceCodeCredentialInformer.GetIndexer(),
SourceCodeRepositoryIndexer: sourceCodeRepositoryInformer.GetIndexer(),
AuthConfigs: management.Management.AuthConfigs(""),
}
providers[model.GitlabType] = glProvider
providersByType[client.GitlabPipelineConfigType] = glProvider
}