-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.go
97 lines (84 loc) · 4.01 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/bitbucketcloud"
"github.com/rancher/rancher/pkg/pipeline/providers/bitbucketserver"
"github.com/rancher/rancher/pkg/pipeline/providers/common"
"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)
)
func SetupSourceCodeProviderConfig(management *config.ScaledContext, schemas *types.Schemas) {
configure(management)
providerBaseSchema := schemas.Schema(&schema.Version, client.SourceCodeProviderType)
setSourceCodeProviderStore(providerBaseSchema, management)
for _, provider := range providers {
provider.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)
baseProvider := common.BaseProvider{
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(),
}
ghProvider := &github.GhProvider{
BaseProvider: baseProvider,
AuthConfigs: management.Management.AuthConfigs(""),
}
glProvider := &gitlab.GlProvider{
BaseProvider: baseProvider,
}
bcProvider := &bitbucketcloud.BcProvider{
BaseProvider: baseProvider,
}
bsProvider := &bitbucketserver.BsProvider{
BaseProvider: baseProvider,
}
providers[model.GithubType] = ghProvider
providers[model.GitlabType] = glProvider
providers[model.BitbucketCloudType] = bcProvider
providers[model.BitbucketServerType] = bsProvider
providersByType[client.GithubPipelineConfigType] = ghProvider
providersByType[client.GitlabPipelineConfigType] = glProvider
providersByType[client.BitbucketCloudPipelineConfigType] = bcProvider
providersByType[client.BitbucketServerPipelineConfigType] = bsProvider
}