Merge pull request #109901 from aojea/integration_shutdown

integration: force close httpserver on exit
This commit is contained in:
Kubernetes Prow Robot 2022-05-09 11:17:30 -07:00 committed by GitHub
commit b059f99951
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -181,12 +181,25 @@ func startAPIServerOrDie(controlPlaneConfig *controlplane.Config, incomingServer
}
stopCh := make(chan struct{})
// the APIServer implements logic to handle the shutdown process, taking care of draining
// the connections, closing the listener socket, running the preShutdown hooks, stopping the postStartHooks, ...
// In the integration framework we don't have that logic so we try to emulate a similar shutdown process.
// Ref: staging/src/k8s.io/apiserver/pkg/server/genericapiserver.go
closeFn := func() {
if m != nil {
m.GenericAPIServer.RunPreShutdownHooks()
}
// Signal RunPostStartHooks to finish
close(stopCh)
// Clean up APIServer resources
m.GenericAPIServer.Destroy()
// At this point the APIserver was already "destroyed", new requests will not be processed,
// however, the httptest.Server.Close() method will block if there are active connections.
// To avoid that any spurious connection keeps the test hanging, we forcefully close the
// connections before shuting down the server. There is a small window where new connections
// can be initiated but is unlikely those move to active, hanging the server shutdown.
s.CloseClientConnections()
s.Close()
}