Skip to content

Commit 28da116

Browse files
committed
feat: Add stopsignal to container lifecycle field in podspec
1 parent a3e1320 commit 28da116

File tree

2 files changed

+85
-0
lines changed

2 files changed

+85
-0
lines changed

pkg/k8s.io/api/core/v1/types.go

+77
Original file line numberDiff line numberDiff line change
@@ -1309,6 +1309,78 @@ type Handler struct {
13091309
TCPSocket *TCPSocketAction `json:"tcpSocket,omitempty"`
13101310
}
13111311

1312+
// Signal defines the stop signal of containers
1313+
// +enum
1314+
type Signal string
1315+
1316+
const (
1317+
SIGABRT Signal = "SIGABRT"
1318+
SIGALRM Signal = "SIGALRM"
1319+
SIGBUS Signal = "SIGBUS"
1320+
SIGCHLD Signal = "SIGCHLD"
1321+
SIGCLD Signal = "SIGCLD"
1322+
SIGCONT Signal = "SIGCONT"
1323+
SIGFPE Signal = "SIGFPE"
1324+
SIGHUP Signal = "SIGHUP"
1325+
SIGILL Signal = "SIGILL"
1326+
SIGINT Signal = "SIGINT"
1327+
SIGIO Signal = "SIGIO"
1328+
SIGIOT Signal = "SIGIOT"
1329+
SIGKILL Signal = "SIGKILL"
1330+
SIGPIPE Signal = "SIGPIPE"
1331+
SIGPOLL Signal = "SIGPOLL"
1332+
SIGPROF Signal = "SIGPROF"
1333+
SIGPWR Signal = "SIGPWR"
1334+
SIGQUIT Signal = "SIGQUIT"
1335+
SIGSEGV Signal = "SIGSEGV"
1336+
SIGSTKFLT Signal = "SIGSTKFLT"
1337+
SIGSTOP Signal = "SIGSTOP"
1338+
SIGSYS Signal = "SIGSYS"
1339+
SIGTERM Signal = "SIGTERM"
1340+
SIGTRAP Signal = "SIGTRAP"
1341+
SIGTSTP Signal = "SIGTSTP"
1342+
SIGTTIN Signal = "SIGTTIN"
1343+
SIGTTOU Signal = "SIGTTOU"
1344+
SIGURG Signal = "SIGURG"
1345+
SIGUSR1 Signal = "SIGUSR1"
1346+
SIGUSR2 Signal = "SIGUSR2"
1347+
SIGVTALRM Signal = "SIGVTALRM"
1348+
SIGWINCH Signal = "SIGWINCH"
1349+
SIGXCPU Signal = "SIGXCPU"
1350+
SIGXFSZ Signal = "SIGXFSZ"
1351+
SIGRTMIN Signal = "SIGRTMIN"
1352+
SIGRTMINPLUS1 Signal = "SIGRTMIN+1"
1353+
SIGRTMINPLUS2 Signal = "SIGRTMIN+2"
1354+
SIGRTMINPLUS3 Signal = "SIGRTMIN+3"
1355+
SIGRTMINPLUS4 Signal = "SIGRTMIN+4"
1356+
SIGRTMINPLUS5 Signal = "SIGRTMIN+5"
1357+
SIGRTMINPLUS6 Signal = "SIGRTMIN+6"
1358+
SIGRTMINPLUS7 Signal = "SIGRTMIN+7"
1359+
SIGRTMINPLUS8 Signal = "SIGRTMIN+8"
1360+
SIGRTMINPLUS9 Signal = "SIGRTMIN+9"
1361+
SIGRTMINPLUS10 Signal = "SIGRTMIN+10"
1362+
SIGRTMINPLUS11 Signal = "SIGRTMIN+11"
1363+
SIGRTMINPLUS12 Signal = "SIGRTMIN+12"
1364+
SIGRTMINPLUS13 Signal = "SIGRTMIN+13"
1365+
SIGRTMINPLUS14 Signal = "SIGRTMIN+14"
1366+
SIGRTMINPLUS15 Signal = "SIGRTMIN+15"
1367+
SIGRTMAXMINUS14 Signal = "SIGRTMAX-14"
1368+
SIGRTMAXMINUS13 Signal = "SIGRTMAX-13"
1369+
SIGRTMAXMINUS12 Signal = "SIGRTMAX-12"
1370+
SIGRTMAXMINUS11 Signal = "SIGRTMAX-11"
1371+
SIGRTMAXMINUS10 Signal = "SIGRTMAX-10"
1372+
SIGRTMAXMINUS9 Signal = "SIGRTMAX-9"
1373+
SIGRTMAXMINUS8 Signal = "SIGRTMAX-8"
1374+
SIGRTMAXMINUS7 Signal = "SIGRTMAX-7"
1375+
SIGRTMAXMINUS6 Signal = "SIGRTMAX-6"
1376+
SIGRTMAXMINUS5 Signal = "SIGRTMAX-5"
1377+
SIGRTMAXMINUS4 Signal = "SIGRTMAX-4"
1378+
SIGRTMAXMINUS3 Signal = "SIGRTMAX-3"
1379+
SIGRTMAXMINUS2 Signal = "SIGRTMAX-2"
1380+
SIGRTMAXMINUS1 Signal = "SIGRTMAX-1"
1381+
SIGRTMAX Signal = "SIGRTMAX"
1382+
)
1383+
13121384
// Lifecycle describes actions that the management system should take in response to container lifecycle
13131385
// events. For the PostStart and PreStop lifecycle handlers, management of the container blocks
13141386
// until the action is complete, unless the container process fails, in which case the handler is aborted.
@@ -1331,6 +1403,11 @@ type Lifecycle struct {
13311403
// More info: https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/#container-hooks
13321404
// +optional
13331405
PreStop *Handler `json:"preStop,omitempty"`
1406+
// StopSignal defines which signal will be sent to a container when it is being stopped.
1407+
// If not specified, the default is defined by the container runtime in use.
1408+
// StopSignal can only be set for Pods with a non-empty .spec.os.name
1409+
// +optional
1410+
StopSignal *Signal `json:"stopSignal,omitempty"`
13341411
}
13351412

13361413
type ConditionStatus string

pkg/specgen/generate/kube/kube.go

+8
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,14 @@ func ToSpecGen(ctx context.Context, opts *CtrSpecGenOptions) (*specgen.SpecGener
341341
s.StopSignal = &stopSignal
342342
}
343343
}
344+
if lifecycle := opts.Container.Lifecycle; lifecycle != nil && lifecycle.StopSignal != nil && len(*lifecycle.StopSignal) > 0 {
345+
stopSignal, err := util.ParseSignal(string(*lifecycle.StopSignal))
346+
if err != nil {
347+
return nil, err
348+
}
349+
s.StopSignal = &stopSignal
350+
}
351+
344352
// If only the yaml.Command is specified, set it as the entrypoint and drop the image Cmd
345353
if !opts.IsInfra && len(opts.Container.Command) != 0 {
346354
s.Entrypoint = opts.Container.Command

0 commit comments

Comments
 (0)