mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 12:43:23 +00:00
kube-apiserver: fix tests which don't use tls yet
This commit is contained in:
parent
e15ac9eb72
commit
6bb3aba23d
@ -113,6 +113,9 @@ func setUp(t *testing.T) (*etcdtesting.EtcdTestServer, Config, informers.SharedI
|
|||||||
TLSClientConfig: &tls.Config{},
|
TLSClientConfig: &tls.Config{},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// set fake SecureServingInfo because the listener port is needed for the kubernetes service
|
||||||
|
config.GenericConfig.SecureServing = &genericapiserver.SecureServingInfo{Listener: fakeLocalhost443Listener{}}
|
||||||
|
|
||||||
clientset, err := kubernetes.NewForConfig(config.GenericConfig.LoopbackClientConfig)
|
clientset, err := kubernetes.NewForConfig(config.GenericConfig.LoopbackClientConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to create client set due to %v", err)
|
t.Fatalf("unable to create client set due to %v", err)
|
||||||
@ -122,6 +125,23 @@ func setUp(t *testing.T) (*etcdtesting.EtcdTestServer, Config, informers.SharedI
|
|||||||
return server, *config, sharedInformers, assert.New(t)
|
return server, *config, sharedInformers, assert.New(t)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type fakeLocalhost443Listener struct{}
|
||||||
|
|
||||||
|
func (fakeLocalhost443Listener) Accept() (net.Conn, error) {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fakeLocalhost443Listener) Close() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fakeLocalhost443Listener) Addr() net.Addr {
|
||||||
|
return &net.TCPAddr{
|
||||||
|
IP: net.IPv4(127, 0, 0, 1),
|
||||||
|
Port: 443,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TestLegacyRestStorageStrategies ensures that all Storage objects which are using the generic registry Store have
|
// TestLegacyRestStorageStrategies ensures that all Storage objects which are using the generic registry Store have
|
||||||
// their various strategies properly wired up. This surfaced as a bug where strategies defined Export functions, but
|
// their various strategies properly wired up. This surfaced as a bug where strategies defined Export functions, but
|
||||||
// they were never used outside of unit tests because the export strategies were not assigned inside the Store.
|
// they were never used outside of unit tests because the export strategies were not assigned inside the Store.
|
||||||
|
@ -34,6 +34,7 @@ import (
|
|||||||
|
|
||||||
func TestNewWithDelegate(t *testing.T) {
|
func TestNewWithDelegate(t *testing.T) {
|
||||||
delegateConfig := NewConfig(codecs)
|
delegateConfig := NewConfig(codecs)
|
||||||
|
delegateConfig.ExternalAddress = "192.168.10.4:443"
|
||||||
delegateConfig.PublicAddress = net.ParseIP("192.168.10.4")
|
delegateConfig.PublicAddress = net.ParseIP("192.168.10.4")
|
||||||
delegateConfig.LegacyAPIGroupPrefixes = sets.NewString("/api")
|
delegateConfig.LegacyAPIGroupPrefixes = sets.NewString("/api")
|
||||||
delegateConfig.LoopbackClientConfig = &rest.Config{}
|
delegateConfig.LoopbackClientConfig = &rest.Config{}
|
||||||
@ -64,6 +65,7 @@ func TestNewWithDelegate(t *testing.T) {
|
|||||||
delegateServer.PrepareRun()
|
delegateServer.PrepareRun()
|
||||||
|
|
||||||
wrappingConfig := NewConfig(codecs)
|
wrappingConfig := NewConfig(codecs)
|
||||||
|
wrappingConfig.ExternalAddress = "192.168.10.4:443"
|
||||||
wrappingConfig.PublicAddress = net.ParseIP("192.168.10.4")
|
wrappingConfig.PublicAddress = net.ParseIP("192.168.10.4")
|
||||||
wrappingConfig.LegacyAPIGroupPrefixes = sets.NewString("/api")
|
wrappingConfig.LegacyAPIGroupPrefixes = sets.NewString("/api")
|
||||||
wrappingConfig.LoopbackClientConfig = &rest.Config{}
|
wrappingConfig.LoopbackClientConfig = &rest.Config{}
|
||||||
|
@ -125,6 +125,7 @@ func testGetOpenAPIDefinitions(_ kubeopenapi.ReferenceCallback) map[string]kubeo
|
|||||||
// setUp is a convience function for setting up for (most) tests.
|
// setUp is a convience function for setting up for (most) tests.
|
||||||
func setUp(t *testing.T) (Config, *assert.Assertions) {
|
func setUp(t *testing.T) (Config, *assert.Assertions) {
|
||||||
config := NewConfig(codecs)
|
config := NewConfig(codecs)
|
||||||
|
config.ExternalAddress = "192.168.10.4:443"
|
||||||
config.PublicAddress = net.ParseIP("192.168.10.4")
|
config.PublicAddress = net.ParseIP("192.168.10.4")
|
||||||
config.LegacyAPIGroupPrefixes = sets.NewString("/api")
|
config.LegacyAPIGroupPrefixes = sets.NewString("/api")
|
||||||
config.LoopbackClientConfig = &restclient.Config{}
|
config.LoopbackClientConfig = &restclient.Config{}
|
||||||
|
@ -225,6 +225,10 @@ func NewIntegrationTestMasterConfig() *master.Config {
|
|||||||
masterConfig := NewMasterConfig()
|
masterConfig := NewMasterConfig()
|
||||||
masterConfig.GenericConfig.PublicAddress = net.ParseIP("192.168.10.4")
|
masterConfig.GenericConfig.PublicAddress = net.ParseIP("192.168.10.4")
|
||||||
masterConfig.ExtraConfig.APIResourceConfigSource = master.DefaultAPIResourceConfigSource()
|
masterConfig.ExtraConfig.APIResourceConfigSource = master.DefaultAPIResourceConfigSource()
|
||||||
|
|
||||||
|
// TODO: get rid of these tests or port them to secure serving
|
||||||
|
masterConfig.GenericConfig.SecureServing = &genericapiserver.SecureServingInfo{Listener: fakeLocalhost443Listener{}}
|
||||||
|
|
||||||
return masterConfig
|
return masterConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -291,6 +295,9 @@ func NewMasterConfig() *master.Config {
|
|||||||
genericConfig.Version = &kubeVersion
|
genericConfig.Version = &kubeVersion
|
||||||
genericConfig.Authorization.Authorizer = authorizerfactory.NewAlwaysAllowAuthorizer()
|
genericConfig.Authorization.Authorizer = authorizerfactory.NewAlwaysAllowAuthorizer()
|
||||||
|
|
||||||
|
// TODO: get rid of these tests or port them to secure serving
|
||||||
|
genericConfig.SecureServing = &genericapiserver.SecureServingInfo{Listener: fakeLocalhost443Listener{}}
|
||||||
|
|
||||||
err := etcdOptions.ApplyWithStorageFactoryTo(storageFactory, genericConfig)
|
err := etcdOptions.ApplyWithStorageFactoryTo(storageFactory, genericConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
@ -329,3 +336,20 @@ func SharedEtcd() *storagebackend.Config {
|
|||||||
cfg.ServerList = []string{GetEtcdURL()}
|
cfg.ServerList = []string{GetEtcdURL()}
|
||||||
return cfg
|
return cfg
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type fakeLocalhost443Listener struct{}
|
||||||
|
|
||||||
|
func (fakeLocalhost443Listener) Accept() (net.Conn, error) {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fakeLocalhost443Listener) Close() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fakeLocalhost443Listener) Addr() net.Addr {
|
||||||
|
return &net.TCPAddr{
|
||||||
|
IP: net.IPv4(127, 0, 0, 1),
|
||||||
|
Port: 443,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user