Skip to content

Commit f2958ee

Browse files
[CRDB-43619] Added support for terminationGracePeriod in crdbcluster CR
1 parent 116e1d7 commit f2958ee

22 files changed

+49
-5
lines changed

WORKSPACE

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,14 @@ load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies")
5757

5858
go_rules_dependencies()
5959

60+
# gazelle:repository_macro hack/build/repos.bzl%_go_dependencies
61+
go_dependencies()
62+
6063
go_register_toolchains(version = "1.17")
6164

6265
gazelle_dependencies()
6366

64-
# gazelle:repository_macro hack/build/repos.bzl%_go_dependencies
65-
go_dependencies()
67+
6668

6769
################################
6870
# begin rules_oci dependencies #

apis/v1alpha1/cluster_types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,11 @@ type CrdbClusterSpec struct {
145145
// Default: false
146146
// +optional
147147
AutomountServiceAccountToken bool `json:"automountServiceAccountToken,omitempty"`
148+
// (Optional) Amount of grace time prior to the container being forcibly terminated
149+
// when marked for deletion or restarted
150+
// Default : 300
151+
// +optional
152+
TerminationGracePeriodSecs int32 `json:"terminationGracePeriodSecs,omitempty"`
148153
}
149154

150155
// +k8s:openapi-gen=true

config/crd/bases/crdb.cockroachlabs.com_crdbclusters.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1393,6 +1393,12 @@ spec:
13931393
description: '(Optional) The SQL Port number Default: 26257'
13941394
format: int32
13951395
type: integer
1396+
terminationGracePeriodSecs:
1397+
description: '(Optional) Amount of grace time prior to the container
1398+
being forcibly terminated when marked for deletion or restarted
1399+
Default : 300'
1400+
format: int32
1401+
type: integer
13961402
tlsEnabled:
13971403
description: (Optional) TLSEnabled determines if TLS is enabled for
13981404
your CockroachDB Cluster

e2e/upgrades/upgrades_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ func TestUpgradesMinorVersionThenRollback(t *testing.T) {
221221

222222
builder := testutil.NewBuilder("crdb").
223223
WithAutomountServiceAccountToken(true).
224+
WithTerminationGracePeriodSeconds(5).
224225
WithNodeCount(3).
225226
WithTLS().
226227
WithImage(e2e.MinorVersion1).

examples/3-nodes-insecure-no-topology.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ spec:
2424
- ReadWriteOnce
2525
resources:
2626
requests:
27-
storage: 60Gi
27+
storage: 1Gi
2828
volumeMode: Filesystem
2929
image:
3030
name: cockroachdb/cockroach:v19.2.6

hack/dev.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ APP_VERSION="${APP_VERSION:-v$(cat version.txt)}"
2121
CLUSTER_NAME="dev"
2222
NODE_IMAGE="rancher/k3s:v1.23.3-k3s1"
2323
REGISTRY_NAME="registry.localhost"
24-
REGISTRY_PORT=5000
24+
REGISTRY_PORT=5002
2525
DEV_REGISTRY="${REGISTRY_NAME}:${REGISTRY_PORT}"
2626

2727
main() {

install/crds.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1391,6 +1391,12 @@ spec:
13911391
description: '(Optional) The SQL Port number Default: 26257'
13921392
format: int32
13931393
type: integer
1394+
terminationGracePeriodSecs:
1395+
description: '(Optional) Amount of grace time prior to the container
1396+
being forcibly terminated when marked for deletion or restarted
1397+
Default : 300'
1398+
format: int32
1399+
type: integer
13941400
tlsEnabled:
13951401
description: (Optional) TLSEnabled determines if TLS is enabled for
13961402
your CockroachDB Cluster

pkg/resource/cluster.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,13 @@ func (cluster Cluster) SecureMode() string {
330330
return "--insecure"
331331
}
332332

333+
func (cluster Cluster) GetTerminationGracePeriod() int32 {
334+
if cluster.Spec().TerminationGracePeriodSecs == 0 {
335+
return terminationGracePeriodSecs
336+
}
337+
return cluster.Spec().TerminationGracePeriodSecs
338+
}
339+
333340
func (cluster Cluster) LoggingConfiguration(fetcher Fetcher) (string, error) {
334341
if cluster.Spec().LogConfigMap != "" {
335342
cm := &corev1.ConfigMap{

pkg/resource/statefulset.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ func (b StatefulSetBuilder) makePodTemplate() corev1.PodTemplateSpec {
209209
RunAsUser: ptr.Int64(1000581000),
210210
FSGroup: ptr.Int64(1000581000),
211211
},
212-
TerminationGracePeriodSeconds: ptr.Int64(terminationGracePeriodSecs),
212+
TerminationGracePeriodSeconds: ptr.Int64(int64(b.GetTerminationGracePeriod())),
213213
Containers: b.MakeContainers(),
214214
AutomountServiceAccountToken: ptr.Bool(b.Spec().AutomountServiceAccountToken),
215215
ServiceAccountName: b.ServiceAccountName(),

pkg/resource/testdata/TestStatefulSetBuilder/automount_sa.golden

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ spec:
2626
car: koenigsegg
2727
spec:
2828
automountServiceAccountToken: true
29+
terminationGracePeriodSecs: 5
2930
containers:
3031
- command:
3132
- /bin/bash

0 commit comments

Comments
 (0)