-
Notifications
You must be signed in to change notification settings - Fork 156
/
hack.go
173 lines (157 loc) · 7.4 KB
/
hack.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/*
Copyright 2020 The Kubermatic Kubernetes Platform contributors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package hack
import (
"net/http"
kubermaticv1 "k8c.io/kubermatic/v2/pkg/crd/kubermatic/v1"
v2 "k8c.io/kubermatic/v2/pkg/handler/v2"
"k8c.io/kubermatic/v2/pkg/resources/certificates"
"k8c.io/kubermatic/v2/pkg/version/kubermatic"
"github.com/gorilla/mux"
prometheusapi "github.com/prometheus/client_golang/api"
"github.com/prometheus/client_golang/prometheus"
"k8c.io/kubermatic/v2/pkg/handler"
"k8c.io/kubermatic/v2/pkg/handler/auth"
"k8c.io/kubermatic/v2/pkg/handler/test"
"k8c.io/kubermatic/v2/pkg/handler/v1/common"
kubermaticlog "k8c.io/kubermatic/v2/pkg/log"
"k8c.io/kubermatic/v2/pkg/provider"
"k8c.io/kubermatic/v2/pkg/provider/kubernetes"
"k8c.io/kubermatic/v2/pkg/serviceaccount"
"k8c.io/kubermatic/v2/pkg/version"
"k8c.io/kubermatic/v2/pkg/watcher"
"k8s.io/apimachinery/pkg/util/sets"
)
// NewTestRouting is a hack that helps us avoid circular imports
// for example handler package uses v1/dc and v1/dc needs handler for testing
func NewTestRouting(
adminProvider provider.AdminProvider,
settingsProvider provider.SettingsProvider,
userInfoGetter provider.UserInfoGetter,
seedsGetter provider.SeedsGetter,
seedClientGetter provider.SeedClientGetter,
clusterProvidersGetter provider.ClusterProviderGetter,
addonProviderGetter provider.AddonProviderGetter,
addonConfigProvider provider.AddonConfigProvider,
sshKeyProvider provider.SSHKeyProvider,
privilegedSSHKeyProvider provider.PrivilegedSSHKeyProvider,
userProvider provider.UserProvider,
serviceAccountProvider provider.ServiceAccountProvider,
privilegedServiceAccountProvider provider.PrivilegedServiceAccountProvider,
serviceAccountTokenProvider provider.ServiceAccountTokenProvider,
privilegedServiceAccountTokenProvider provider.PrivilegedServiceAccountTokenProvider,
projectProvider provider.ProjectProvider,
privilegedProjectProvider provider.PrivilegedProjectProvider,
issuerVerifier auth.OIDCIssuerVerifier,
tokenVerifiers auth.TokenVerifier,
tokenExtractors auth.TokenExtractor,
prometheusClient prometheusapi.Client,
projectMemberProvider *kubernetes.ProjectMemberProvider,
privilegedProjectMemberProvider provider.PrivilegedProjectMemberProvider,
versions []*version.Version,
updates []*version.Update,
saTokenAuthenticator serviceaccount.TokenAuthenticator,
saTokenGenerator serviceaccount.TokenGenerator,
eventRecorderProvider provider.EventRecorderProvider,
presetsProvider provider.PresetProvider,
admissionPluginProvider provider.AdmissionPluginsProvider,
settingsWatcher watcher.SettingsWatcher,
userWatcher watcher.UserWatcher,
externalClusterProvider provider.ExternalClusterProvider,
privilegedExternalClusterProvider provider.PrivilegedExternalClusterProvider,
constraintTemplateProvider provider.ConstraintTemplateProvider,
constraintProvider provider.ConstraintProvider,
privilegedConstraintProvider provider.PrivilegedConstraintProvider,
kubermaticVersions kubermatic.Versions) http.Handler {
updateManager := version.New(versions, updates)
routingParams := handler.RoutingParams{
Log: kubermaticlog.Logger,
PresetsProvider: presetsProvider,
SeedsGetter: seedsGetter,
SeedsClientGetter: seedClientGetter,
SSHKeyProvider: sshKeyProvider,
PrivilegedSSHKeyProvider: privilegedSSHKeyProvider,
UserProvider: userProvider,
ServiceAccountProvider: serviceAccountProvider,
PrivilegedServiceAccountProvider: privilegedServiceAccountProvider,
ServiceAccountTokenProvider: serviceAccountTokenProvider,
PrivilegedServiceAccountTokenProvider: privilegedServiceAccountTokenProvider,
ProjectProvider: projectProvider,
PrivilegedProjectProvider: privilegedProjectProvider,
OIDCIssuerVerifier: issuerVerifier,
TokenVerifiers: tokenVerifiers,
TokenExtractors: tokenExtractors,
ClusterProviderGetter: clusterProvidersGetter,
AddonProviderGetter: addonProviderGetter,
AddonConfigProvider: addonConfigProvider,
UpdateManager: updateManager,
PrometheusClient: prometheusClient,
ProjectMemberProvider: projectMemberProvider,
PrivilegedProjectMemberProvider: privilegedProjectMemberProvider,
UserProjectMapper: projectMemberProvider, /*satisfies also a different interface*/
SATokenAuthenticator: saTokenAuthenticator,
SATokenGenerator: saTokenGenerator,
EventRecorderProvider: eventRecorderProvider,
ExposeStrategy: kubermaticv1.ExposeStrategyNodePort,
AccessibleAddons: sets.String{},
UserInfoGetter: userInfoGetter,
SettingsProvider: settingsProvider,
AdminProvider: adminProvider,
AdmissionPluginProvider: admissionPluginProvider,
SettingsWatcher: settingsWatcher,
UserWatcher: userWatcher,
ExternalClusterProvider: externalClusterProvider,
PrivilegedExternalClusterProvider: privilegedExternalClusterProvider,
ConstraintTemplateProvider: constraintTemplateProvider,
ConstraintProvider: constraintProvider,
PrivilegedConstraintProvider: privilegedConstraintProvider,
Versions: kubermaticVersions,
CABundle: certificates.NewFakeCABundle().CertPool(),
}
r := handler.NewRouting(routingParams)
rv2 := v2.NewV2Routing(routingParams)
mainRouter := mux.NewRouter()
v1Router := mainRouter.PathPrefix("/api/v1").Subrouter()
v2Router := mainRouter.PathPrefix("/api/v2").Subrouter()
r.RegisterV1(v1Router, generateDefaultMetrics())
r.RegisterV1Legacy(v1Router)
r.RegisterV1Optional(v1Router,
true,
*generateDefaultOicdCfg(),
mainRouter,
)
r.RegisterV1Admin(v1Router)
r.RegisterV1Websocket(v1Router)
rv2.RegisterV2(v2Router, generateDefaultMetrics())
return mainRouter
}
// generateDefaultOicdCfg creates test configuration for OpenID clients
func generateDefaultOicdCfg() *common.OIDCConfiguration {
return &common.OIDCConfiguration{
URL: test.IssuerURL,
ClientID: test.IssuerClientID,
ClientSecret: test.IssuerClientSecret,
OfflineAccessAsScope: true,
}
}
func generateDefaultMetrics() common.ServerMetrics {
return common.ServerMetrics{
InitNodeDeploymentFailures: prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "kubermatic_api_init_node_deployment_failures",
Help: "The number of times initial node deployment couldn't be created within the timeout",
},
[]string{"cluster", "datacenter"},
),
}
}