mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-13 18:43:34 +00:00
rebase: bump sigs.k8s.io/controller-runtime
Bumps the k8s-dependencies group with 1 update in the / directory: [sigs.k8s.io/controller-runtime](https://github.com/kubernetes-sigs/controller-runtime). Updates `sigs.k8s.io/controller-runtime` from 0.17.3 to 0.18.2 - [Release notes](https://github.com/kubernetes-sigs/controller-runtime/releases) - [Changelog](https://github.com/kubernetes-sigs/controller-runtime/blob/main/RELEASE.md) - [Commits](https://github.com/kubernetes-sigs/controller-runtime/compare/v0.17.3...v0.18.2) --- updated-dependencies: - dependency-name: sigs.k8s.io/controller-runtime dependency-type: direct:production update-type: version-update:semver-minor dependency-group: k8s-dependencies ... Signed-off-by: dependabot[bot] <support@github.com>
This commit is contained in:
committed by
mergify[bot]
parent
c8af2b638a
commit
c1ee11261e
74
vendor/sigs.k8s.io/controller-runtime/pkg/manager/server.go
generated
vendored
74
vendor/sigs.k8s.io/controller-runtime/pkg/manager/server.go
generated
vendored
@ -21,34 +21,67 @@ import (
|
||||
"errors"
|
||||
"net"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/go-logr/logr"
|
||||
crlog "sigs.k8s.io/controller-runtime/pkg/log"
|
||||
)
|
||||
|
||||
// server is a general purpose HTTP server Runnable for a manager
|
||||
// to serve some internal handlers such as health probes, metrics and profiling.
|
||||
type server struct {
|
||||
Kind string
|
||||
Log logr.Logger
|
||||
Server *http.Server
|
||||
var (
|
||||
_ Runnable = (*Server)(nil)
|
||||
_ LeaderElectionRunnable = (*Server)(nil)
|
||||
)
|
||||
|
||||
// Server is a general purpose HTTP server Runnable for a manager.
|
||||
// It is used to serve some internal handlers for health probes and profiling,
|
||||
// but it can also be used to run custom servers.
|
||||
type Server struct {
|
||||
// Name is an optional string that describes the purpose of the server. It is used in logs to distinguish
|
||||
// among multiple servers.
|
||||
Name string
|
||||
|
||||
// Server is the HTTP server to run. It is required.
|
||||
Server *http.Server
|
||||
|
||||
// Listener is an optional listener to use. If not set, the server start a listener using the server.Addr.
|
||||
// Using a listener is useful when the port reservation needs to happen in advance of this runnable starting.
|
||||
Listener net.Listener
|
||||
|
||||
// OnlyServeWhenLeader is an optional bool that indicates that the server should only be started when the manager is the leader.
|
||||
OnlyServeWhenLeader bool
|
||||
|
||||
// ShutdownTimeout is an optional duration that indicates how long to wait for the server to shutdown gracefully. If not set,
|
||||
// the server will wait indefinitely for all connections to close.
|
||||
ShutdownTimeout *time.Duration
|
||||
}
|
||||
|
||||
func (s *server) Start(ctx context.Context) error {
|
||||
log := s.Log.WithValues("kind", s.Kind, "addr", s.Listener.Addr())
|
||||
// Start starts the server. It will block until the server is stopped or an error occurs.
|
||||
func (s *Server) Start(ctx context.Context) error {
|
||||
log := crlog.FromContext(ctx)
|
||||
if s.Name != "" {
|
||||
log = log.WithValues("name", s.Name)
|
||||
}
|
||||
log = log.WithValues("addr", s.addr())
|
||||
|
||||
serverShutdown := make(chan struct{})
|
||||
go func() {
|
||||
<-ctx.Done()
|
||||
log.Info("shutting down server")
|
||||
if err := s.Server.Shutdown(context.Background()); err != nil {
|
||||
|
||||
shutdownCtx := context.Background()
|
||||
if s.ShutdownTimeout != nil {
|
||||
var shutdownCancel context.CancelFunc
|
||||
shutdownCtx, shutdownCancel = context.WithTimeout(context.Background(), *s.ShutdownTimeout)
|
||||
defer shutdownCancel()
|
||||
}
|
||||
|
||||
if err := s.Server.Shutdown(shutdownCtx); err != nil {
|
||||
log.Error(err, "error shutting down server")
|
||||
}
|
||||
close(serverShutdown)
|
||||
}()
|
||||
|
||||
log.Info("starting server")
|
||||
if err := s.Server.Serve(s.Listener); err != nil && !errors.Is(err, http.ErrServerClosed) {
|
||||
if err := s.serve(); err != nil && !errors.Is(err, http.ErrServerClosed) {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -56,6 +89,21 @@ func (s *server) Start(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *server) NeedLeaderElection() bool {
|
||||
return false
|
||||
// NeedLeaderElection returns true if the server should only be started when the manager is the leader.
|
||||
func (s *Server) NeedLeaderElection() bool {
|
||||
return s.OnlyServeWhenLeader
|
||||
}
|
||||
|
||||
func (s *Server) addr() string {
|
||||
if s.Listener != nil {
|
||||
return s.Listener.Addr().String()
|
||||
}
|
||||
return s.Server.Addr
|
||||
}
|
||||
|
||||
func (s *Server) serve() error {
|
||||
if s.Listener != nil {
|
||||
return s.Server.Serve(s.Listener)
|
||||
}
|
||||
return s.Server.ListenAndServe()
|
||||
}
|
||||
|
Reference in New Issue
Block a user