Skip to content

Commit 484078a

Browse files
committed
✨ mv pkg/{runtime,manager}/signals
pkg/runtime is a bit of a odd collection right now. This starts to move stuff out of it, leaving aliases in place instead. Since signals are used to control managers, this functionality now lives in a subpackage of manager.
1 parent 68ec58f commit 484078a

File tree

13 files changed

+62
-29
lines changed

13 files changed

+62
-29
lines changed

alias.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626
"sigs.k8s.io/controller-runtime/pkg/reconcile"
2727
"sigs.k8s.io/controller-runtime/pkg/log"
2828
"sigs.k8s.io/controller-runtime/pkg/runtime/scheme"
29-
"sigs.k8s.io/controller-runtime/pkg/runtime/signals"
29+
"sigs.k8s.io/controller-runtime/pkg/manager/signals"
3030
)
3131

3232
// Builder builds an Application ControllerManagedBy (e.g. Operator) and returns a manager.Manager to start it.

doc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ limitations under the License.
5454
// common dependencies (pkg/runtime/inject), like shared caches and clients, as
5555
// well as managing leader election (pkg/leaderelection). Managers are
5656
// generally configured to gracefully shut down controllers on pod termination
57-
// by wiring up a signal handler (pkg/runtime/signals).
57+
// by wiring up a signal handler (pkg/manager/signals).
5858
//
5959
// Controllers
6060
//

example/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import (
3131
"sigs.k8s.io/controller-runtime/pkg/manager"
3232
logf "sigs.k8s.io/controller-runtime/pkg/log"
3333
"sigs.k8s.io/controller-runtime/pkg/log/zap"
34-
"sigs.k8s.io/controller-runtime/pkg/runtime/signals"
34+
"sigs.k8s.io/controller-runtime/pkg/manager/signals"
3535
"sigs.k8s.io/controller-runtime/pkg/source"
3636
"sigs.k8s.io/controller-runtime/pkg/webhook"
3737
"sigs.k8s.io/controller-runtime/pkg/webhook/admission/builder"

pkg/builder/example_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import (
3030
"sigs.k8s.io/controller-runtime/pkg/client/config"
3131
"sigs.k8s.io/controller-runtime/pkg/manager"
3232
"sigs.k8s.io/controller-runtime/pkg/reconcile"
33-
"sigs.k8s.io/controller-runtime/pkg/runtime/signals"
33+
"sigs.k8s.io/controller-runtime/pkg/manager/signals"
3434
)
3535

3636
// This example creates a simple application ControllerManagedBy that is configured for ReplicaSets and Pods.

pkg/controller/example_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
"sigs.k8s.io/controller-runtime/pkg/manager"
2828
"sigs.k8s.io/controller-runtime/pkg/reconcile"
2929
logf "sigs.k8s.io/controller-runtime/pkg/log"
30-
"sigs.k8s.io/controller-runtime/pkg/runtime/signals"
30+
"sigs.k8s.io/controller-runtime/pkg/manager/signals"
3131
"sigs.k8s.io/controller-runtime/pkg/source"
3232
)
3333

pkg/manager/example_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
"sigs.k8s.io/controller-runtime/pkg/client/config"
2323
"sigs.k8s.io/controller-runtime/pkg/manager"
2424
logf "sigs.k8s.io/controller-runtime/pkg/log"
25-
"sigs.k8s.io/controller-runtime/pkg/runtime/signals"
25+
"sigs.k8s.io/controller-runtime/pkg/manager/signals"
2626
)
2727

2828
var (
File renamed without changes.

pkg/manager/signals/signal.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
Copyright 2017 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package signals
18+
19+
import (
20+
"os"
21+
"os/signal"
22+
)
23+
24+
var onlyOneSignalHandler = make(chan struct{})
25+
26+
// SetupSignalHandler registers for SIGTERM and SIGINT. A stop channel is returned
27+
// which is closed on one of these signals. If a second signal is caught, the program
28+
// is terminated with exit code 1.
29+
func SetupSignalHandler() (stopCh <-chan struct{}) {
30+
close(onlyOneSignalHandler) // panics when called twice
31+
32+
stop := make(chan struct{})
33+
c := make(chan os.Signal, 2)
34+
signal.Notify(c, shutdownSignals...)
35+
go func() {
36+
<-c
37+
close(stop)
38+
<-c
39+
os.Exit(1) // second signal. Exit directly.
40+
}()
41+
42+
return stop
43+
}

pkg/runtime/signals/signal.go

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2017 The Kubernetes Authors.
2+
Copyright 2019 The Kubernetes Authors.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -14,30 +14,20 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17+
// Package signals contains libraries for handling signals to gracefully
18+
// shutdown the manager in combination with Kubernetes pod graceful termination
19+
// policy.
20+
//
21+
// Deprecated: use pkg/manager/signals instead.
1722
package signals
1823

1924
import (
20-
"os"
21-
"os/signal"
25+
"sigs.k8s.io/controller-runtime/pkg/manager/signals"
2226
)
2327

24-
var onlyOneSignalHandler = make(chan struct{})
25-
26-
// SetupSignalHandler registered for SIGTERM and SIGINT. A stop channel is returned
27-
// which is closed on one of these signals. If a second signal is caught, the program
28-
// is terminated with exit code 1.
29-
func SetupSignalHandler() (stopCh <-chan struct{}) {
30-
close(onlyOneSignalHandler) // panics when called twice
31-
32-
stop := make(chan struct{})
33-
c := make(chan os.Signal, 2)
34-
signal.Notify(c, shutdownSignals...)
35-
go func() {
36-
<-c
37-
close(stop)
38-
<-c
39-
os.Exit(1) // second signal. Exit directly.
40-
}()
41-
42-
return stop
43-
}
28+
var (
29+
// SetupSignalHandler registers for SIGTERM and SIGINT. A stop channel is returned
30+
// which is closed on one of these signals. If a second signal is caught, the program
31+
// is terminated with exit code 1.
32+
SetupSignalHandler = signals.SetupSignalHandler
33+
)

0 commit comments

Comments
 (0)