mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-04 15:05:20 +00:00
pkg/controlplane: split up config into generic controlplane and kube-related part
Signed-off-by: Dr. Stefan Schimanski <stefan.schimanski@gmail.com>
This commit is contained in:
@@ -84,7 +84,7 @@ func setupWithResources(t *testing.T, groupVersions []schema.GroupVersion, resou
|
||||
resourceConfig := controlplane.DefaultAPIResourceConfigSource()
|
||||
resourceConfig.EnableVersions(groupVersions...)
|
||||
resourceConfig.EnableResources(resources...)
|
||||
config.ExtraConfig.APIResourceConfigSource = resourceConfig
|
||||
config.ControlPlane.Extra.APIResourceConfigSource = resourceConfig
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
@@ -155,7 +155,7 @@ func TestConcurrencyIsolation(t *testing.T) {
|
||||
},
|
||||
ModifyServerConfig: func(config *controlplane.Config) {
|
||||
// Wrap default authorizer with one that delays requests from noxu clients
|
||||
config.GenericConfig.Authorization.Authorizer = &noxuDelayingAuthorizer{config.GenericConfig.Authorization.Authorizer}
|
||||
config.ControlPlane.Generic.Authorization.Authorizer = &noxuDelayingAuthorizer{config.ControlPlane.Generic.Authorization.Authorizer}
|
||||
},
|
||||
})
|
||||
defer closeFn()
|
||||
|
||||
@@ -77,8 +77,8 @@ func TestEnablingOpenAPIEnumTypes(t *testing.T) {
|
||||
|
||||
_, kubeConfig, tearDownFn := framework.StartTestServer(tCtx, t, framework.TestServerSetup{
|
||||
ModifyServerConfig: func(config *controlplane.Config) {
|
||||
config.GenericConfig.OpenAPIConfig = framework.DefaultOpenAPIConfig()
|
||||
config.GenericConfig.OpenAPIConfig.GetDefinitions = getDefinitionsFn
|
||||
config.ControlPlane.Generic.OpenAPIConfig = framework.DefaultOpenAPIConfig()
|
||||
config.ControlPlane.Generic.OpenAPIConfig.GetDefinitions = getDefinitionsFn
|
||||
},
|
||||
})
|
||||
defer tearDownFn()
|
||||
|
||||
@@ -61,7 +61,7 @@ func multiEtcdSetup(ctx context.Context, t *testing.T) (clientset.Interface, fra
|
||||
},
|
||||
ModifyServerConfig: func(config *controlplane.Config) {
|
||||
// Switch off endpoints reconciler to avoid unnecessary operations.
|
||||
config.ExtraConfig.EndpointReconcilerType = reconcilers.NoneEndpointReconcilerType
|
||||
config.Extra.EndpointReconcilerType = reconcilers.NoneEndpointReconcilerType
|
||||
},
|
||||
})
|
||||
|
||||
@@ -170,7 +170,7 @@ func BenchmarkListFromWatchCache(b *testing.B) {
|
||||
c, _, tearDownFn := framework.StartTestServer(tCtx, b, framework.TestServerSetup{
|
||||
ModifyServerConfig: func(config *controlplane.Config) {
|
||||
// Switch off endpoints reconciler to avoid unnecessary operations.
|
||||
config.ExtraConfig.EndpointReconcilerType = reconcilers.NoneEndpointReconcilerType
|
||||
config.Extra.EndpointReconcilerType = reconcilers.NoneEndpointReconcilerType
|
||||
},
|
||||
})
|
||||
defer tearDownFn()
|
||||
|
||||
@@ -62,9 +62,9 @@ func TestSubjectAccessReview(t *testing.T) {
|
||||
clientset, _, tearDownFn := framework.StartTestServer(tCtx, t, framework.TestServerSetup{
|
||||
ModifyServerConfig: func(config *controlplane.Config) {
|
||||
// Unset BearerToken to disable BearerToken authenticator.
|
||||
config.GenericConfig.LoopbackClientConfig.BearerToken = ""
|
||||
config.GenericConfig.Authentication.Authenticator = authenticator.RequestFunc(alwaysAlice)
|
||||
config.GenericConfig.Authorization.Authorizer = sarAuthorizer{}
|
||||
config.ControlPlane.Generic.LoopbackClientConfig.BearerToken = ""
|
||||
config.ControlPlane.Generic.Authentication.Authenticator = authenticator.RequestFunc(alwaysAlice)
|
||||
config.ControlPlane.Generic.Authorization.Authorizer = sarAuthorizer{}
|
||||
},
|
||||
})
|
||||
defer tearDownFn()
|
||||
@@ -172,9 +172,9 @@ func TestSelfSubjectAccessReview(t *testing.T) {
|
||||
clientset, _, tearDownFn := framework.StartTestServer(tCtx, t, framework.TestServerSetup{
|
||||
ModifyServerConfig: func(config *controlplane.Config) {
|
||||
// Unset BearerToken to disable BearerToken authenticator.
|
||||
config.GenericConfig.LoopbackClientConfig.BearerToken = ""
|
||||
config.GenericConfig.Authentication.Authenticator = authenticator.RequestFunc(authenticatorFunc)
|
||||
config.GenericConfig.Authorization.Authorizer = sarAuthorizer{}
|
||||
config.ControlPlane.Generic.LoopbackClientConfig.BearerToken = ""
|
||||
config.ControlPlane.Generic.Authentication.Authenticator = authenticator.RequestFunc(authenticatorFunc)
|
||||
config.ControlPlane.Generic.Authorization.Authorizer = sarAuthorizer{}
|
||||
},
|
||||
})
|
||||
defer tearDownFn()
|
||||
@@ -256,9 +256,9 @@ func TestLocalSubjectAccessReview(t *testing.T) {
|
||||
clientset, _, tearDownFn := framework.StartTestServer(tCtx, t, framework.TestServerSetup{
|
||||
ModifyServerConfig: func(config *controlplane.Config) {
|
||||
// Unset BearerToken to disable BearerToken authenticator.
|
||||
config.GenericConfig.LoopbackClientConfig.BearerToken = ""
|
||||
config.GenericConfig.Authentication.Authenticator = authenticator.RequestFunc(alwaysAlice)
|
||||
config.GenericConfig.Authorization.Authorizer = sarAuthorizer{}
|
||||
config.ControlPlane.Generic.LoopbackClientConfig.BearerToken = ""
|
||||
config.ControlPlane.Generic.Authentication.Authenticator = authenticator.RequestFunc(alwaysAlice)
|
||||
config.ControlPlane.Generic.Authorization.Authorizer = sarAuthorizer{}
|
||||
},
|
||||
})
|
||||
defer tearDownFn()
|
||||
|
||||
@@ -813,7 +813,7 @@ func TestImpersonateIsForbidden(t *testing.T) {
|
||||
},
|
||||
ModifyServerConfig: func(config *controlplane.Config) {
|
||||
// Prepend an impersonation authorizer with specific opinions about alice and bob
|
||||
config.GenericConfig.Authorization.Authorizer = unionauthz.New(impersonateAuthorizer{}, config.GenericConfig.Authorization.Authorizer)
|
||||
config.ControlPlane.Generic.Authorization.Authorizer = unionauthz.New(impersonateAuthorizer{}, config.ControlPlane.Generic.Authorization.Authorizer)
|
||||
},
|
||||
})
|
||||
defer tearDownFn()
|
||||
@@ -1118,7 +1118,7 @@ func TestAuthorizationAttributeDetermination(t *testing.T) {
|
||||
opts.Authentication.TokenFile.TokenFile = "testdata/tokens.csv"
|
||||
},
|
||||
ModifyServerConfig: func(config *controlplane.Config) {
|
||||
config.GenericConfig.Authorization.Authorizer = unionauthz.New(config.GenericConfig.Authorization.Authorizer, trackingAuthorizer)
|
||||
config.ControlPlane.Generic.Authorization.Authorizer = unionauthz.New(config.ControlPlane.Generic.Authorization.Authorizer, trackingAuthorizer)
|
||||
},
|
||||
})
|
||||
defer tearDownFn()
|
||||
@@ -1458,9 +1458,9 @@ func testWebhookTokenAuthenticator(customDialer bool, t *testing.T) {
|
||||
opts.Authorization.PolicyFile = "testdata/allowalice.jsonl"
|
||||
},
|
||||
ModifyServerConfig: func(config *controlplane.Config) {
|
||||
config.GenericConfig.Authentication.Authenticator = group.NewAuthenticatedGroupAdder(authenticator)
|
||||
config.ControlPlane.Generic.Authentication.Authenticator = group.NewAuthenticatedGroupAdder(authenticator)
|
||||
// Disable checking API audiences that is set by testserver by default.
|
||||
config.GenericConfig.Authentication.APIAudiences = nil
|
||||
config.ControlPlane.Generic.Authentication.APIAudiences = nil
|
||||
},
|
||||
})
|
||||
defer tearDownFn()
|
||||
|
||||
@@ -128,7 +128,7 @@ func TestBootstrapTokenAuth(t *testing.T) {
|
||||
opts.Authorization.Modes = []string{"AlwaysAllow"}
|
||||
},
|
||||
ModifyServerConfig: func(config *controlplane.Config) {
|
||||
config.GenericConfig.Authentication.Authenticator = authenticator
|
||||
config.ControlPlane.Generic.Authentication.Authenticator = authenticator
|
||||
},
|
||||
})
|
||||
defer tearDownFn()
|
||||
|
||||
@@ -81,7 +81,7 @@ type testRESTOptionsGetter struct {
|
||||
}
|
||||
|
||||
func (getter *testRESTOptionsGetter) GetRESTOptions(resource schema.GroupResource) (generic.RESTOptions, error) {
|
||||
storageConfig, err := getter.config.ExtraConfig.StorageFactory.NewConfig(resource)
|
||||
storageConfig, err := getter.config.ControlPlane.Extra.StorageFactory.NewConfig(resource)
|
||||
if err != nil {
|
||||
return generic.RESTOptions{}, fmt.Errorf("failed to get storage: %v", err)
|
||||
}
|
||||
@@ -556,11 +556,11 @@ func TestRBAC(t *testing.T) {
|
||||
},
|
||||
ModifyServerConfig: func(config *controlplane.Config) {
|
||||
// Append our custom test authenticator
|
||||
config.GenericConfig.Authentication.Authenticator = unionauthn.New(config.GenericConfig.Authentication.Authenticator, authenticator)
|
||||
config.ControlPlane.Generic.Authentication.Authenticator = unionauthn.New(config.ControlPlane.Generic.Authentication.Authenticator, authenticator)
|
||||
// Append our custom test authorizer
|
||||
var rbacAuthz authorizer.Authorizer
|
||||
rbacAuthz, tearDownAuthorizerFn = newRBACAuthorizer(t, config)
|
||||
config.GenericConfig.Authorization.Authorizer = unionauthz.New(config.GenericConfig.Authorization.Authorizer, rbacAuthz)
|
||||
config.ControlPlane.Generic.Authorization.Authorizer = unionauthz.New(config.ControlPlane.Generic.Authorization.Authorizer, rbacAuthz)
|
||||
},
|
||||
})
|
||||
defer tearDownFn()
|
||||
|
||||
@@ -101,8 +101,8 @@ func TestGetsSelfAttributes(t *testing.T) {
|
||||
},
|
||||
ModifyServerConfig: func(config *controlplane.Config) {
|
||||
// Unset BearerToken to disable BearerToken authenticator.
|
||||
config.GenericConfig.LoopbackClientConfig.BearerToken = ""
|
||||
config.GenericConfig.Authentication.Authenticator = authenticator.RequestFunc(func(req *http.Request) (*authenticator.Response, bool, error) {
|
||||
config.ControlPlane.Generic.LoopbackClientConfig.BearerToken = ""
|
||||
config.ControlPlane.Generic.Authentication.Authenticator = authenticator.RequestFunc(func(req *http.Request) (*authenticator.Response, bool, error) {
|
||||
respMu.RLock()
|
||||
defer respMu.RUnlock()
|
||||
return &authenticator.Response{User: response}, true, nil
|
||||
@@ -215,8 +215,8 @@ func TestGetsSelfAttributesError(t *testing.T) {
|
||||
},
|
||||
ModifyServerConfig: func(config *controlplane.Config) {
|
||||
// Unset BearerToken to disable BearerToken authenticator.
|
||||
config.GenericConfig.LoopbackClientConfig.BearerToken = ""
|
||||
config.GenericConfig.Authentication.Authenticator = authenticator.RequestFunc(func(req *http.Request) (*authenticator.Response, bool, error) {
|
||||
config.ControlPlane.Generic.LoopbackClientConfig.BearerToken = ""
|
||||
config.ControlPlane.Generic.Authentication.Authenticator = authenticator.RequestFunc(func(req *http.Request) (*authenticator.Response, bool, error) {
|
||||
if toggle.Load().(bool) {
|
||||
return &authenticator.Response{
|
||||
User: &user.DefaultInfo{
|
||||
|
||||
@@ -104,10 +104,10 @@ func TestServiceAccountTokenCreate(t *testing.T) {
|
||||
},
|
||||
ModifyServerConfig: func(config *controlplane.Config) {
|
||||
// extract token generator
|
||||
tokenGenerator = config.ExtraConfig.ServiceAccountIssuer
|
||||
tokenGenerator = config.ControlPlane.Extra.ServiceAccountIssuer
|
||||
|
||||
config.ExtraConfig.ServiceAccountMaxExpiration = maxExpirationDuration
|
||||
config.ExtraConfig.ExtendExpiration = true
|
||||
config.ControlPlane.Extra.ServiceAccountMaxExpiration = maxExpirationDuration
|
||||
config.ControlPlane.Extra.ExtendExpiration = true
|
||||
},
|
||||
})
|
||||
defer tearDownFn()
|
||||
|
||||
@@ -1178,7 +1178,7 @@ func TestUpdateStatusDespitePodCreationFailure(t *testing.T) {
|
||||
limitedPodNumber := 2
|
||||
ctx, closeFn, dc, informers, clientset := setupWithServerSetup(t, framework.TestServerSetup{
|
||||
ModifyServerConfig: func(config *controlplane.Config) {
|
||||
config.GenericConfig.AdmissionControl = &fakePodFailAdmission{
|
||||
config.ControlPlane.Generic.AdmissionControl = &fakePodFailAdmission{
|
||||
limitedPodNumber: limitedPodNumber,
|
||||
}
|
||||
},
|
||||
|
||||
@@ -32,8 +32,8 @@ func TestAdmission(t *testing.T) {
|
||||
tCtx := ktesting.Init(t)
|
||||
client, _, tearDownFn := framework.StartTestServer(tCtx, t, framework.TestServerSetup{
|
||||
ModifyServerConfig: func(cfg *controlplane.Config) {
|
||||
cfg.GenericConfig.EnableProfiling = true
|
||||
cfg.GenericConfig.AdmissionControl = defaulttolerationseconds.NewDefaultTolerationSeconds()
|
||||
cfg.ControlPlane.Generic.EnableProfiling = true
|
||||
cfg.ControlPlane.Generic.AdmissionControl = defaulttolerationseconds.NewDefaultTolerationSeconds()
|
||||
},
|
||||
})
|
||||
defer tearDownFn()
|
||||
|
||||
@@ -47,11 +47,11 @@ func TestWebhookLoopback(t *testing.T) {
|
||||
},
|
||||
ModifyServerConfig: func(config *controlplane.Config) {
|
||||
// Avoid resolvable kubernetes service
|
||||
config.ExtraConfig.EndpointReconcilerType = reconcilers.NoneEndpointReconcilerType
|
||||
config.Extra.EndpointReconcilerType = reconcilers.NoneEndpointReconcilerType
|
||||
|
||||
// Hook into audit to watch requests
|
||||
config.GenericConfig.AuditBackend = auditSinkFunc(func(events ...*auditinternal.Event) {})
|
||||
config.GenericConfig.AuditPolicyRuleEvaluator = auditPolicyRuleEvaluator(func(attrs authorizer.Attributes) audit.RequestAuditConfig {
|
||||
config.ControlPlane.Generic.AuditBackend = auditSinkFunc(func(events ...*auditinternal.Event) {})
|
||||
config.ControlPlane.Generic.AuditPolicyRuleEvaluator = auditPolicyRuleEvaluator(func(attrs authorizer.Attributes) audit.RequestAuditConfig {
|
||||
if attrs.GetPath() == webhookPath {
|
||||
if attrs.GetUser().GetName() != "system:apiserver" {
|
||||
t.Errorf("expected user %q, got %q", "system:apiserver", attrs.GetUser().GetName())
|
||||
|
||||
@@ -182,7 +182,7 @@ func StartTestServer(ctx context.Context, t testing.TB, setup TestServerSetup) (
|
||||
}()
|
||||
|
||||
// Adjust the loopback config for external use (external server name and CA)
|
||||
kubeAPIServerClientConfig := rest.CopyConfig(kubeAPIServerConfig.GenericConfig.LoopbackClientConfig)
|
||||
kubeAPIServerClientConfig := rest.CopyConfig(kubeAPIServerConfig.ControlPlane.Generic.LoopbackClientConfig)
|
||||
kubeAPIServerClientConfig.CAFile = path.Join(certDir, "apiserver.crt")
|
||||
kubeAPIServerClientConfig.CAData = nil
|
||||
kubeAPIServerClientConfig.ServerName = ""
|
||||
|
||||
@@ -50,7 +50,7 @@ func TestServicesFinalizersRepairLoop(t *testing.T) {
|
||||
opts.ServiceClusterIPRanges = serviceCIDR
|
||||
},
|
||||
ModifyServerConfig: func(cfg *controlplane.Config) {
|
||||
cfg.ExtraConfig.RepairServicesInterval = interval
|
||||
cfg.Extra.RepairServicesInterval = interval
|
||||
},
|
||||
})
|
||||
defer tearDownFn()
|
||||
|
||||
@@ -21,17 +21,20 @@ import (
|
||||
|
||||
genericapiserver "k8s.io/apiserver/pkg/server"
|
||||
"k8s.io/kubernetes/pkg/controlplane"
|
||||
controlplaneapiserver "k8s.io/kubernetes/pkg/controlplane/apiserver"
|
||||
)
|
||||
|
||||
// This test references methods that OpenShift uses to customize the apiserver on startup, that
|
||||
// are not referenced directly by an instance.
|
||||
func TestApiserverExportsSymbols(t *testing.T) {
|
||||
_ = &controlplane.Config{
|
||||
GenericConfig: &genericapiserver.Config{
|
||||
EnableMetrics: true,
|
||||
},
|
||||
ExtraConfig: controlplane.ExtraConfig{
|
||||
EnableLogsSupport: false,
|
||||
ControlPlane: controlplaneapiserver.Config{
|
||||
Generic: &genericapiserver.Config{
|
||||
EnableMetrics: true,
|
||||
},
|
||||
Extra: controlplaneapiserver.Extra{
|
||||
EnableLogsSupport: false,
|
||||
},
|
||||
},
|
||||
}
|
||||
_ = &controlplane.Instance{
|
||||
|
||||
@@ -376,7 +376,7 @@ func startServiceAccountTestServerAndWaitForCaches(ctx context.Context, t *testi
|
||||
|
||||
return authorizer.DecisionNoOpinion, fmt.Sprintf("User %s is denied (ns=%s, readonly=%v, resource=%s)", username, ns, attrs.IsReadOnly(), attrs.GetResource()), nil
|
||||
})
|
||||
config.GenericConfig.Authorization.Authorizer = unionauthz.New(config.GenericConfig.Authorization.Authorizer, authorizer)
|
||||
config.ControlPlane.Generic.Authorization.Authorizer = unionauthz.New(config.ControlPlane.Generic.Authorization.Authorizer, authorizer)
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
@@ -381,7 +381,7 @@ func TestStatefulSetStatusWithPodFail(t *testing.T) {
|
||||
limitedPodNumber := 2
|
||||
c, config, closeFn := framework.StartTestServer(tCtx, t, framework.TestServerSetup{
|
||||
ModifyServerConfig: func(config *controlplane.Config) {
|
||||
config.GenericConfig.AdmissionControl = &fakePodFailAdmission{
|
||||
config.ControlPlane.Generic.AdmissionControl = &fakePodFailAdmission{
|
||||
limitedPodNumber: limitedPodNumber,
|
||||
}
|
||||
},
|
||||
|
||||
@@ -518,7 +518,7 @@ func InitTestAPIServer(t *testing.T, nsPrefix string, admission admission.Interf
|
||||
},
|
||||
ModifyServerConfig: func(config *controlplane.Config) {
|
||||
if admission != nil {
|
||||
config.GenericConfig.AdmissionControl = admission
|
||||
config.ControlPlane.Generic.AdmissionControl = admission
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user