Skip to content
Open
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
2 changes: 2 additions & 0 deletions api/v4/common_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ type Spec struct {

// TopologySpreadConstraint https://kubernetes.io/docs/concepts/scheduling-eviction/topology-spread-constraints/
TopologySpreadConstraints []corev1.TopologySpreadConstraint `json:"topologySpreadConstraints,omitempty"`

TerminationGracePeriodSeconds int64 `json:"terminationGracePeriodSeconds"`
}

// Phase is used to represent the current phase of a custom resource
Expand Down
3 changes: 3 additions & 0 deletions config/crd/bases/enterprise.splunk.com_clustermanagers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2338,6 +2338,9 @@ spec:
format: int32
type: integer
type: object
terminationGracePeriodSeconds:
format: int64
type: integer
tolerations:
description: Pod's tolerations for Kubernetes node's taint
items:
Expand Down
3 changes: 3 additions & 0 deletions config/crd/bases/enterprise.splunk.com_clustermasters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2334,6 +2334,9 @@ spec:
format: int32
type: integer
type: object
terminationGracePeriodSeconds:
format: int64
type: integer
tolerations:
description: Pod's tolerations for Kubernetes node's taint
items:
Expand Down
6 changes: 6 additions & 0 deletions config/crd/bases/enterprise.splunk.com_indexerclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2074,6 +2074,9 @@ spec:
format: int32
type: integer
type: object
terminationGracePeriodSeconds:
format: int64
type: integer
tolerations:
description: Pod's tolerations for Kubernetes node's taint
items:
Expand Down Expand Up @@ -6246,6 +6249,9 @@ spec:
format: int32
type: integer
type: object
terminationGracePeriodSeconds:
format: int64
type: integer
tolerations:
description: Pod's tolerations for Kubernetes node's taint
items:
Expand Down
3 changes: 3 additions & 0 deletions config/crd/bases/enterprise.splunk.com_licensemanagers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2211,6 +2211,9 @@ spec:
format: int32
type: integer
type: object
terminationGracePeriodSeconds:
format: int64
type: integer
tolerations:
description: Pod's tolerations for Kubernetes node's taint
items:
Expand Down
3 changes: 3 additions & 0 deletions config/crd/bases/enterprise.splunk.com_licensemasters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2206,6 +2206,9 @@ spec:
format: int32
type: integer
type: object
terminationGracePeriodSeconds:
format: int64
type: integer
tolerations:
description: Pod's tolerations for Kubernetes node's taint
items:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2213,6 +2213,9 @@ spec:
format: int32
type: integer
type: object
terminationGracePeriodSeconds:
format: int64
type: integer
tolerations:
description: Pod's tolerations for Kubernetes node's taint
items:
Expand Down Expand Up @@ -6730,6 +6733,9 @@ spec:
format: int32
type: integer
type: object
terminationGracePeriodSeconds:
format: int64
type: integer
tolerations:
description: Pod's tolerations for Kubernetes node's taint
items:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2224,6 +2224,9 @@ spec:
format: int32
type: integer
type: object
terminationGracePeriodSeconds:
format: int64
type: integer
tolerations:
description: Pod's tolerations for Kubernetes node's taint
items:
Expand Down Expand Up @@ -7085,6 +7088,9 @@ spec:
format: int32
type: integer
type: object
terminationGracePeriodSeconds:
format: int64
type: integer
tolerations:
description: Pod's tolerations for Kubernetes node's taint
items:
Expand Down
6 changes: 6 additions & 0 deletions config/crd/bases/enterprise.splunk.com_standalones.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2335,6 +2335,9 @@ spec:
format: int32
type: integer
type: object
terminationGracePeriodSeconds:
format: int64
type: integer
tolerations:
description: Pod's tolerations for Kubernetes node's taint
items:
Expand Down Expand Up @@ -7096,6 +7099,9 @@ spec:
format: int32
type: integer
type: object
terminationGracePeriodSeconds:
format: int64
type: integer
tolerations:
description: Pod's tolerations for Kubernetes node's taint
items:
Expand Down
31 changes: 20 additions & 11 deletions pkg/splunk/enterprise/clustermanager_test.go

Large diffs are not rendered by default.

21 changes: 14 additions & 7 deletions pkg/splunk/enterprise/clustermaster_test.go

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions pkg/splunk/enterprise/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,17 @@ func getSmartstoreConfigMap(ctx context.Context, client splcommon.ControllerClie
return configMap
}

// set the PreStop lifecycle handler for the specified container index
func setPreStopLifecycleHandler(podTemplateSpec *corev1.PodTemplateSpec, idx int) {
podTemplateSpec.Spec.Containers[idx].Lifecycle = &corev1.Lifecycle{
PreStop: &corev1.LifecycleHandler{
Exec: &corev1.ExecAction{
Command: []string{"/bin/sh", "-c", "/opt/splunk/bin/splunk", "offline", "&&", "/opt/splunk/bin/splunk", "stop"},
},
},
}
}

// updateSplunkPodTemplateWithConfig modifies the podTemplateSpec object based on configuration of the Splunk Enterprise resource.
func updateSplunkPodTemplateWithConfig(ctx context.Context, client splcommon.ControllerClient, podTemplateSpec *corev1.PodTemplateSpec, cr splcommon.MetaObject, spec *enterpriseApi.CommonSplunkSpec, instanceType InstanceType, extraEnv []corev1.EnvVar, secretToMount string) {

Expand Down Expand Up @@ -1106,7 +1117,12 @@ func updateSplunkPodTemplateWithConfig(ctx context.Context, client splcommon.Con
Type: corev1.SeccompProfileTypeRuntimeDefault,
},
}

// Use the helper function to set the lifecycle handler
setPreStopLifecycleHandler(podTemplateSpec, idx)
}

podTemplateSpec.Spec.TerminationGracePeriodSeconds = &spec.TerminationGracePeriodSeconds
}

func removeDuplicateEnvVars(sliceList []corev1.EnvVar) []corev1.EnvVar {
Expand Down
38 changes: 38 additions & 0 deletions pkg/splunk/enterprise/configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"
"math/rand"
"os"
"reflect"
"strings"
"testing"

Expand Down Expand Up @@ -1816,3 +1817,40 @@ func TestValidateLivenessProbe(t *testing.T) {
t.Errorf("Unexpected error when less than deault values passed for livenessProbe InitialDelaySeconds %d, TimeoutSeconds %d, PeriodSeconds %d. Error %s", livenessProbe.InitialDelaySeconds, livenessProbe.TimeoutSeconds, livenessProbe.PeriodSeconds, err)
}
}

func TestSetPreStopLifecycleHandler(t *testing.T) {
// Create a pod template spec with a single container
podTemplateSpec := corev1.PodTemplateSpec{
Spec: corev1.PodSpec{
Containers: []corev1.Container{
{Name: "splunk"},
},
},
}

// Index of the container to apply the lifecycle handler
idx := 0

// Set the lifecycle handler
setPreStopLifecycleHandler(&podTemplateSpec, idx)

t.Run("test lifecycle pre-stop handler", func(t *testing.T) {
// Verify that the lifecycle handler was set correctly
if podTemplateSpec.Spec.Containers[idx].Lifecycle == nil {
t.Error("Expected Lifecycle to be set, but it was nil")
}

if podTemplateSpec.Spec.Containers[idx].Lifecycle.PreStop == nil {
t.Error("Expected PreStop to be set, but it was nil")
}

if podTemplateSpec.Spec.Containers[idx].Lifecycle.PreStop.Exec == nil {
t.Error("Expected Exec to be set, but it was nil")
}

expectedCommand := []string{"/bin/sh", "-c", "/opt/splunk/bin/splunk", "offline", "&&", "/opt/splunk/bin/splunk", "stop"}
if !reflect.DeepEqual(podTemplateSpec.Spec.Containers[idx].Lifecycle.PreStop.Exec.Command, expectedCommand) {
t.Errorf("Expected command to be %v, but got %v", expectedCommand, podTemplateSpec.Spec.Containers[idx].Lifecycle.PreStop.Exec.Command)
}
})
}
Loading
Loading