Skip to content

Commit

Permalink
test: add command and prestop into test pod options (kubernetes-sigs#973
Browse files Browse the repository at this point in the history
)
  • Loading branch information
njtran authored Jan 27, 2024
1 parent 85de9dd commit a77f847
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions pkg/test/pods.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ type PodOptions struct {
TerminationGracePeriodSeconds *int64
ReadinessProbe *v1.Probe
LivenessProbe *v1.Probe
PreStopSleep *int64
Command []string
}

type PDBOptions struct {
Expand Down Expand Up @@ -143,6 +145,25 @@ func Pod(overrides ...PodOptions) *v1.Pod {
Phase: options.Phase,
},
}
// If PreStopSleep is enabled, add it to each of the containers.
// Can't use v1.LifecycleHandler == v1.SleepAction as that's a feature gate in Alpha 1.29.
// https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/#hook-handler-implementations
if options.PreStopSleep != nil {
p.Spec.Containers[0].Lifecycle = &v1.Lifecycle{
PreStop: &v1.LifecycleHandler{
Exec: &v1.ExecAction{
Command: []string{
"/bin/sh",
"-c",
fmt.Sprintf("sleep %d", *options.PreStopSleep),
},
},
},
}
}
if options.Command != nil {
p.Spec.Containers[0].Command = options.Command
}
if options.InitImage != "" {
p.Spec.InitContainers = []v1.Container{{
Name: RandomName(),
Expand Down

0 comments on commit a77f847

Please sign in to comment.