Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 2 additions & 24 deletions pkg/manager/signals/signal.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,7 @@ limitations under the License.
package signals

import (
"context"
"os"
"os/signal"
apiserver "k8s.io/apiserver/pkg/server"
)

var onlyOneSignalHandler = make(chan struct{})

// SetupSignalHandler registers for SIGTERM and SIGINT. A context is returned
// which is canceled on one of these signals. If a second signal is caught, the program
// is terminated with exit code 1.
func SetupSignalHandler() context.Context {
close(onlyOneSignalHandler) // panics when called twice

ctx, cancel := context.WithCancel(context.Background())

c := make(chan os.Signal, 2)
signal.Notify(c, shutdownSignals...)
go func() {
<-c
cancel()
<-c
os.Exit(1) // second signal. Exit directly.
}()

return ctx
}
var SetupSignalHandler = apiserver.SetupSignalContext
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I honestly prefer the copy over introducing a dependency to the apiserver code

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, thanks for your reply.
apiserver is already a dependency of cr; this PR doesn't add new packages.

Copy link
Member

@sbueringer sbueringer Aug 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but we would now depend on this code from the apiserver and we have 0 control over or visibility into how it changes over time

27 changes: 0 additions & 27 deletions pkg/manager/signals/signal_posix.go

This file was deleted.

23 changes: 0 additions & 23 deletions pkg/manager/signals/signal_windows.go

This file was deleted.