From 665eaa305173ec38555e160e534f4163f7393136 Mon Sep 17 00:00:00 2001 From: Ben Ye Date: Thu, 24 Mar 2022 22:29:37 -0700 Subject: [PATCH 1/4] make termination grace seconds configurable Signed-off-by: Ben Ye --- Documentation/api.md | 1 + bundle.yaml | 12 ++++++++++++ .../monitoring.coreos.com_prometheuses.yaml | 12 ++++++++++++ jsonnet/prometheus-operator/prometheuses-crd.json | 5 +++++ pkg/apis/monitoring/v1/types.go | 10 ++++++++++ pkg/apis/monitoring/v1/zz_generated.deepcopy.go | 5 +++++ pkg/prometheus/statefulset.go | 9 ++++++--- 7 files changed, 51 insertions(+), 3 deletions(-) diff --git a/Documentation/api.md b/Documentation/api.md index e70db4f9c9..291c4491ba 100644 --- a/Documentation/api.md +++ b/Documentation/api.md @@ -810,6 +810,7 @@ PrometheusSpec is a specification of the desired behavior of the Prometheus clus | enforcedLabelValueLengthLimit | Per-scrape limit on length of labels value that will be accepted for a sample. If a label value is longer than this number post metric-relabeling, the entire scrape will be treated as failed. 0 means no limit. Only valid in Prometheus versions 2.27.0 and newer. | *uint64 | false | | enforcedBodySizeLimit | EnforcedBodySizeLimit defines the maximum size of uncompressed response body that will be accepted by Prometheus. Targets responding with a body larger than this many bytes will cause the scrape to fail. Example: 100MB. If defined, the limit will apply to all service/pod monitors and probes. This is an experimental feature, this behaviour could change or be removed in the future. Only valid in Prometheus versions 2.28.0 and newer. | ByteSize | false | | minReadySeconds | Minimum number of seconds for which a newly created pod should be ready without any of its container crashing for it to be considered available. Defaults to 0 (pod will be considered available as soon as it is ready) This is an alpha field and requires enabling StatefulSetMinReadySeconds feature gate. | *uint32 | false | +| terminationGracePeriodSeconds | Optional duration in seconds the pod needs to terminate gracefully. May be decreased in delete request. Value must be non-negative integer. The value zero indicates stop immediately via the kill signal (no opportunity to shut down). If this value is nil, the default grace period will be used instead. The grace period is the duration in seconds after the processes running in the pod are sent a termination signal and the time when the processes are forcibly halted with a kill signal. Set this value longer than the expected cleanup time for your process. Defaults to 600 seconds. | *int64 | false | | retention | Time duration Prometheus shall retain data for. Default is '24h' if retentionSize is not set, and must match the regular expression `[0-9]+(ms\|s\|m\|h\|d\|w\|y)` (milliseconds seconds minutes hours days weeks years). | string | false | | retentionSize | Maximum amount of disk space used by blocks. | ByteSize | false | | disableCompaction | Disable prometheus compaction. | bool | false | diff --git a/bundle.yaml b/bundle.yaml index 5b598f65c1..fcf121c0ba 100644 --- a/bundle.yaml +++ b/bundle.yaml @@ -17514,6 +17514,18 @@ spec: use ''image'' instead. The image tag can be specified as part of the image URL.' type: string + terminationGracePeriodSeconds: + description: Optional duration in seconds the pod needs to terminate + gracefully. May be decreased in delete request. Value must be non-negative + integer. The value zero indicates stop immediately via the kill + signal (no opportunity to shut down). If this value is nil, the + default grace period will be used instead. The grace period is the + duration in seconds after the processes running in the pod are sent + a termination signal and the time when the processes are forcibly + halted with a kill signal. Set this value longer than the expected + cleanup time for your process. Defaults to 600 seconds. + format: int64 + type: integer thanos: description: "Thanos configuration allows configuring various aspects of a Prometheus server in a Thanos environment. \n This section diff --git a/example/prometheus-operator-crd/monitoring.coreos.com_prometheuses.yaml b/example/prometheus-operator-crd/monitoring.coreos.com_prometheuses.yaml index ad20b79ba8..554e9016ec 100644 --- a/example/prometheus-operator-crd/monitoring.coreos.com_prometheuses.yaml +++ b/example/prometheus-operator-crd/monitoring.coreos.com_prometheuses.yaml @@ -6207,6 +6207,18 @@ spec: use ''image'' instead. The image tag can be specified as part of the image URL.' type: string + terminationGracePeriodSeconds: + description: Optional duration in seconds the pod needs to terminate + gracefully. May be decreased in delete request. Value must be non-negative + integer. The value zero indicates stop immediately via the kill + signal (no opportunity to shut down). If this value is nil, the + default grace period will be used instead. The grace period is the + duration in seconds after the processes running in the pod are sent + a termination signal and the time when the processes are forcibly + halted with a kill signal. Set this value longer than the expected + cleanup time for your process. Defaults to 600 seconds. + format: int64 + type: integer thanos: description: "Thanos configuration allows configuring various aspects of a Prometheus server in a Thanos environment. \n This section diff --git a/jsonnet/prometheus-operator/prometheuses-crd.json b/jsonnet/prometheus-operator/prometheuses-crd.json index d11d53e606..d0d5e4f759 100644 --- a/jsonnet/prometheus-operator/prometheuses-crd.json +++ b/jsonnet/prometheus-operator/prometheuses-crd.json @@ -5766,6 +5766,11 @@ "description": "Tag of Prometheus container image to be deployed. Defaults to the value of `version`. Version is ignored if Tag is set. Deprecated: use 'image' instead. The image tag can be specified as part of the image URL.", "type": "string" }, + "terminationGracePeriodSeconds": { + "description": "Optional duration in seconds the pod needs to terminate gracefully. May be decreased in delete request. Value must be non-negative integer. The value zero indicates stop immediately via the kill signal (no opportunity to shut down). If this value is nil, the default grace period will be used instead. The grace period is the duration in seconds after the processes running in the pod are sent a termination signal and the time when the processes are forcibly halted with a kill signal. Set this value longer than the expected cleanup time for your process. Defaults to 600 seconds.", + "format": "int64", + "type": "integer" + }, "thanos": { "description": "Thanos configuration allows configuring various aspects of a Prometheus server in a Thanos environment. \n This section is experimental, it may change significantly without deprecation notice in any release. \n This is experimental and may change significantly without backward compatibility in any release.", "properties": { diff --git a/pkg/apis/monitoring/v1/types.go b/pkg/apis/monitoring/v1/types.go index 1002759b9e..5435a248ea 100644 --- a/pkg/apis/monitoring/v1/types.go +++ b/pkg/apis/monitoring/v1/types.go @@ -335,6 +335,16 @@ type CommonPrometheusFields struct { // This is an alpha field and requires enabling StatefulSetMinReadySeconds feature gate. // +optional MinReadySeconds *uint32 `json:"minReadySeconds,omitempty"` + // Optional duration in seconds the pod needs to terminate gracefully. May be decreased in delete request. + // Value must be non-negative integer. The value zero indicates stop immediately via + // the kill signal (no opportunity to shut down). + // If this value is nil, the default grace period will be used instead. + // The grace period is the duration in seconds after the processes running in the pod are sent + // a termination signal and the time when the processes are forcibly halted with a kill signal. + // Set this value longer than the expected cleanup time for your process. + // Defaults to 600 seconds. + // +optional + TerminationGracePeriodSeconds *int64 `json:"terminationGracePeriodSeconds,omitempty"` } // Prometheus defines a Prometheus deployment. diff --git a/pkg/apis/monitoring/v1/zz_generated.deepcopy.go b/pkg/apis/monitoring/v1/zz_generated.deepcopy.go index 7df92f853f..0cca3020de 100644 --- a/pkg/apis/monitoring/v1/zz_generated.deepcopy.go +++ b/pkg/apis/monitoring/v1/zz_generated.deepcopy.go @@ -591,6 +591,11 @@ func (in *CommonPrometheusFields) DeepCopyInto(out *CommonPrometheusFields) { *out = new(uint32) **out = **in } + if in.TerminationGracePeriodSeconds != nil { + in, out := &in.TerminationGracePeriodSeconds, &out.TerminationGracePeriodSeconds + *out = new(int64) + **out = **in + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CommonPrometheusFields. diff --git a/pkg/prometheus/statefulset.go b/pkg/prometheus/statefulset.go index 4aa5585eac..c12b3140ba 100644 --- a/pkg/prometheus/statefulset.go +++ b/pkg/prometheus/statefulset.go @@ -326,8 +326,11 @@ func makeStatefulSetService(p *monitoringv1.Prometheus, config operator.Config) func makeStatefulSetSpec(p monitoringv1.Prometheus, c *operator.Config, shard int32, ruleConfigMapNames []string, tlsAssetSecrets []string, version semver.Version) (*appsv1.StatefulSetSpec, error) { // Prometheus may take quite long to shut down to checkpoint existing data. - // Allow up to 10 minutes for clean termination. - terminationGracePeriod := int64(600) + // Allow up to 10 minutes for clean termination if not specified. + if p.Spec.TerminationGracePeriodSeconds == nil { + terminationGracePeriod := int64(600) + p.Spec.TerminationGracePeriodSeconds = &terminationGracePeriod + } prometheusImagePath, err := operator.BuildImagePath( operator.StringPtrValOrDefault(p.Spec.Image, ""), @@ -1001,7 +1004,7 @@ func makeStatefulSetSpec(p monitoringv1.Prometheus, c *operator.Config, shard in AutomountServiceAccountToken: &boolTrue, NodeSelector: p.Spec.NodeSelector, PriorityClassName: p.Spec.PriorityClassName, - TerminationGracePeriodSeconds: &terminationGracePeriod, + TerminationGracePeriodSeconds: p.Spec.TerminationGracePeriodSeconds, Volumes: volumes, Tolerations: p.Spec.Tolerations, Affinity: p.Spec.Affinity, From 1687c3321be878a005f713fa54e2f50205ef0eaf Mon Sep 17 00:00:00 2001 From: Ben Ye Date: Fri, 25 Mar 2022 11:09:53 -0700 Subject: [PATCH 2/4] fix review comments Signed-off-by: Ben Ye --- Documentation/api.md | 2 +- bundle.yaml | 13 ++++++++----- .../monitoring.coreos.com_prometheuses.yaml | 13 ++++++++----- .../prometheus-operator/prometheuses-crd.json | 3 ++- pkg/apis/monitoring/v1/types.go | 7 ++++--- pkg/apis/monitoring/v1/zz_generated.deepcopy.go | 5 ----- pkg/prometheus/statefulset.go | 17 ++++++++--------- 7 files changed, 31 insertions(+), 29 deletions(-) diff --git a/Documentation/api.md b/Documentation/api.md index 291c4491ba..3b7b58cbbb 100644 --- a/Documentation/api.md +++ b/Documentation/api.md @@ -810,7 +810,7 @@ PrometheusSpec is a specification of the desired behavior of the Prometheus clus | enforcedLabelValueLengthLimit | Per-scrape limit on length of labels value that will be accepted for a sample. If a label value is longer than this number post metric-relabeling, the entire scrape will be treated as failed. 0 means no limit. Only valid in Prometheus versions 2.27.0 and newer. | *uint64 | false | | enforcedBodySizeLimit | EnforcedBodySizeLimit defines the maximum size of uncompressed response body that will be accepted by Prometheus. Targets responding with a body larger than this many bytes will cause the scrape to fail. Example: 100MB. If defined, the limit will apply to all service/pod monitors and probes. This is an experimental feature, this behaviour could change or be removed in the future. Only valid in Prometheus versions 2.28.0 and newer. | ByteSize | false | | minReadySeconds | Minimum number of seconds for which a newly created pod should be ready without any of its container crashing for it to be considered available. Defaults to 0 (pod will be considered available as soon as it is ready) This is an alpha field and requires enabling StatefulSetMinReadySeconds feature gate. | *uint32 | false | -| terminationGracePeriodSeconds | Optional duration in seconds the pod needs to terminate gracefully. May be decreased in delete request. Value must be non-negative integer. The value zero indicates stop immediately via the kill signal (no opportunity to shut down). If this value is nil, the default grace period will be used instead. The grace period is the duration in seconds after the processes running in the pod are sent a termination signal and the time when the processes are forcibly halted with a kill signal. Set this value longer than the expected cleanup time for your process. Defaults to 600 seconds. | *int64 | false | +| terminationGracePeriodSeconds | Optional duration in seconds the pod needs to terminate gracefully. May be decreased in delete request. Value must be non-negative integer. The value zero indicates stop immediately via the kill signal (no opportunity to shut down). If this value is nil, the default grace period will be used instead. Default value is set to 10 min because Prometheus may take quite long to shutdown to checkpoint existing data. The grace period is the duration in seconds after the processes running in the pod are sent a termination signal and the time when the processes are forcibly halted with a kill signal. Set this value longer than the expected cleanup time for your process. | *uint64 | false | | retention | Time duration Prometheus shall retain data for. Default is '24h' if retentionSize is not set, and must match the regular expression `[0-9]+(ms\|s\|m\|h\|d\|w\|y)` (milliseconds seconds minutes hours days weeks years). | string | false | | retentionSize | Maximum amount of disk space used by blocks. | ByteSize | false | | disableCompaction | Disable prometheus compaction. | bool | false | diff --git a/bundle.yaml b/bundle.yaml index fcf121c0ba..3d67f95071 100644 --- a/bundle.yaml +++ b/bundle.yaml @@ -17515,15 +17515,18 @@ spec: the image URL.' type: string terminationGracePeriodSeconds: + default: "600" description: Optional duration in seconds the pod needs to terminate gracefully. May be decreased in delete request. Value must be non-negative integer. The value zero indicates stop immediately via the kill signal (no opportunity to shut down). If this value is nil, the - default grace period will be used instead. The grace period is the - duration in seconds after the processes running in the pod are sent - a termination signal and the time when the processes are forcibly - halted with a kill signal. Set this value longer than the expected - cleanup time for your process. Defaults to 600 seconds. + default grace period will be used instead. Default value is set + to 10 min because Prometheus may take quite long to shutdown to + checkpoint existing data. The grace period is the duration in seconds + after the processes running in the pod are sent a termination signal + and the time when the processes are forcibly halted with a kill + signal. Set this value longer than the expected cleanup time for + your process. format: int64 type: integer thanos: diff --git a/example/prometheus-operator-crd/monitoring.coreos.com_prometheuses.yaml b/example/prometheus-operator-crd/monitoring.coreos.com_prometheuses.yaml index 554e9016ec..3e6aa0f21b 100644 --- a/example/prometheus-operator-crd/monitoring.coreos.com_prometheuses.yaml +++ b/example/prometheus-operator-crd/monitoring.coreos.com_prometheuses.yaml @@ -6208,15 +6208,18 @@ spec: the image URL.' type: string terminationGracePeriodSeconds: + default: "600" description: Optional duration in seconds the pod needs to terminate gracefully. May be decreased in delete request. Value must be non-negative integer. The value zero indicates stop immediately via the kill signal (no opportunity to shut down). If this value is nil, the - default grace period will be used instead. The grace period is the - duration in seconds after the processes running in the pod are sent - a termination signal and the time when the processes are forcibly - halted with a kill signal. Set this value longer than the expected - cleanup time for your process. Defaults to 600 seconds. + default grace period will be used instead. Default value is set + to 10 min because Prometheus may take quite long to shutdown to + checkpoint existing data. The grace period is the duration in seconds + after the processes running in the pod are sent a termination signal + and the time when the processes are forcibly halted with a kill + signal. Set this value longer than the expected cleanup time for + your process. format: int64 type: integer thanos: diff --git a/jsonnet/prometheus-operator/prometheuses-crd.json b/jsonnet/prometheus-operator/prometheuses-crd.json index d0d5e4f759..4f7eaf75ac 100644 --- a/jsonnet/prometheus-operator/prometheuses-crd.json +++ b/jsonnet/prometheus-operator/prometheuses-crd.json @@ -5767,7 +5767,8 @@ "type": "string" }, "terminationGracePeriodSeconds": { - "description": "Optional duration in seconds the pod needs to terminate gracefully. May be decreased in delete request. Value must be non-negative integer. The value zero indicates stop immediately via the kill signal (no opportunity to shut down). If this value is nil, the default grace period will be used instead. The grace period is the duration in seconds after the processes running in the pod are sent a termination signal and the time when the processes are forcibly halted with a kill signal. Set this value longer than the expected cleanup time for your process. Defaults to 600 seconds.", + "default": "600", + "description": "Optional duration in seconds the pod needs to terminate gracefully. May be decreased in delete request. Value must be non-negative integer. The value zero indicates stop immediately via the kill signal (no opportunity to shut down). If this value is nil, the default grace period will be used instead. Default value is set to 10 min because Prometheus may take quite long to shutdown to checkpoint existing data. The grace period is the duration in seconds after the processes running in the pod are sent a termination signal and the time when the processes are forcibly halted with a kill signal. Set this value longer than the expected cleanup time for your process.", "format": "int64", "type": "integer" }, diff --git a/pkg/apis/monitoring/v1/types.go b/pkg/apis/monitoring/v1/types.go index 5435a248ea..9e2b3c63cd 100644 --- a/pkg/apis/monitoring/v1/types.go +++ b/pkg/apis/monitoring/v1/types.go @@ -338,13 +338,14 @@ type CommonPrometheusFields struct { // Optional duration in seconds the pod needs to terminate gracefully. May be decreased in delete request. // Value must be non-negative integer. The value zero indicates stop immediately via // the kill signal (no opportunity to shut down). - // If this value is nil, the default grace period will be used instead. + // If this value is nil, the default grace period will be used instead. Default value is set to + // 10 min because Prometheus may take quite long to shutdown to checkpoint existing data. // The grace period is the duration in seconds after the processes running in the pod are sent // a termination signal and the time when the processes are forcibly halted with a kill signal. // Set this value longer than the expected cleanup time for your process. - // Defaults to 600 seconds. // +optional - TerminationGracePeriodSeconds *int64 `json:"terminationGracePeriodSeconds,omitempty"` + // +kubebuilder:default:="600" + TerminationGracePeriodSeconds *uint64 `json:"terminationGracePeriodSeconds,omitempty"` } // Prometheus defines a Prometheus deployment. diff --git a/pkg/apis/monitoring/v1/zz_generated.deepcopy.go b/pkg/apis/monitoring/v1/zz_generated.deepcopy.go index 0cca3020de..7df92f853f 100644 --- a/pkg/apis/monitoring/v1/zz_generated.deepcopy.go +++ b/pkg/apis/monitoring/v1/zz_generated.deepcopy.go @@ -591,11 +591,6 @@ func (in *CommonPrometheusFields) DeepCopyInto(out *CommonPrometheusFields) { *out = new(uint32) **out = **in } - if in.TerminationGracePeriodSeconds != nil { - in, out := &in.TerminationGracePeriodSeconds, &out.TerminationGracePeriodSeconds - *out = new(int64) - **out = **in - } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CommonPrometheusFields. diff --git a/pkg/prometheus/statefulset.go b/pkg/prometheus/statefulset.go index c12b3140ba..8463ad6f62 100644 --- a/pkg/prometheus/statefulset.go +++ b/pkg/prometheus/statefulset.go @@ -325,13 +325,6 @@ func makeStatefulSetService(p *monitoringv1.Prometheus, config operator.Config) func makeStatefulSetSpec(p monitoringv1.Prometheus, c *operator.Config, shard int32, ruleConfigMapNames []string, tlsAssetSecrets []string, version semver.Version) (*appsv1.StatefulSetSpec, error) { - // Prometheus may take quite long to shut down to checkpoint existing data. - // Allow up to 10 minutes for clean termination if not specified. - if p.Spec.TerminationGracePeriodSeconds == nil { - terminationGracePeriod := int64(600) - p.Spec.TerminationGracePeriodSeconds = &terminationGracePeriod - } - prometheusImagePath, err := operator.BuildImagePath( operator.StringPtrValOrDefault(p.Spec.Image, ""), operator.StringValOrDefault(p.Spec.BaseImage, c.PrometheusDefaultBaseImage), @@ -907,10 +900,16 @@ func makeStatefulSetSpec(p monitoringv1.Prometheus, c *operator.Config, shard in } } - var minReadySeconds int32 + var ( + minReadySeconds int32 + terminationGracePeriod int64 + ) if p.Spec.MinReadySeconds != nil { minReadySeconds = int32(*p.Spec.MinReadySeconds) } + if p.Spec.TerminationGracePeriodSeconds != nil { + terminationGracePeriod = int64(*p.Spec.TerminationGracePeriodSeconds) + } operatorInitContainers = append(operatorInitContainers, operator.CreateConfigReloader( @@ -1004,7 +1003,7 @@ func makeStatefulSetSpec(p monitoringv1.Prometheus, c *operator.Config, shard in AutomountServiceAccountToken: &boolTrue, NodeSelector: p.Spec.NodeSelector, PriorityClassName: p.Spec.PriorityClassName, - TerminationGracePeriodSeconds: p.Spec.TerminationGracePeriodSeconds, + TerminationGracePeriodSeconds: &terminationGracePeriod, Volumes: volumes, Tolerations: p.Spec.Tolerations, Affinity: p.Spec.Affinity, From bbcd24541ff0dceb383d16d1ffd77bfaa46b5845 Mon Sep 17 00:00:00 2001 From: Ben Ye Date: Fri, 25 Mar 2022 23:04:01 -0700 Subject: [PATCH 3/4] fix review --- bundle.yaml | 2 +- .../monitoring.coreos.com_prometheuses.yaml | 2 +- jsonnet/prometheus-operator/prometheuses-crd.json | 2 +- pkg/apis/monitoring/v1/types.go | 2 +- pkg/apis/monitoring/v1/zz_generated.deepcopy.go | 5 +++++ 5 files changed, 9 insertions(+), 4 deletions(-) diff --git a/bundle.yaml b/bundle.yaml index 3d67f95071..8e702e4b8c 100644 --- a/bundle.yaml +++ b/bundle.yaml @@ -17515,7 +17515,7 @@ spec: the image URL.' type: string terminationGracePeriodSeconds: - default: "600" + default: 600 description: Optional duration in seconds the pod needs to terminate gracefully. May be decreased in delete request. Value must be non-negative integer. The value zero indicates stop immediately via the kill diff --git a/example/prometheus-operator-crd/monitoring.coreos.com_prometheuses.yaml b/example/prometheus-operator-crd/monitoring.coreos.com_prometheuses.yaml index 3e6aa0f21b..5870bfab1c 100644 --- a/example/prometheus-operator-crd/monitoring.coreos.com_prometheuses.yaml +++ b/example/prometheus-operator-crd/monitoring.coreos.com_prometheuses.yaml @@ -6208,7 +6208,7 @@ spec: the image URL.' type: string terminationGracePeriodSeconds: - default: "600" + default: 600 description: Optional duration in seconds the pod needs to terminate gracefully. May be decreased in delete request. Value must be non-negative integer. The value zero indicates stop immediately via the kill diff --git a/jsonnet/prometheus-operator/prometheuses-crd.json b/jsonnet/prometheus-operator/prometheuses-crd.json index 4f7eaf75ac..398b35a5a4 100644 --- a/jsonnet/prometheus-operator/prometheuses-crd.json +++ b/jsonnet/prometheus-operator/prometheuses-crd.json @@ -5767,7 +5767,7 @@ "type": "string" }, "terminationGracePeriodSeconds": { - "default": "600", + "default": 600, "description": "Optional duration in seconds the pod needs to terminate gracefully. May be decreased in delete request. Value must be non-negative integer. The value zero indicates stop immediately via the kill signal (no opportunity to shut down). If this value is nil, the default grace period will be used instead. Default value is set to 10 min because Prometheus may take quite long to shutdown to checkpoint existing data. The grace period is the duration in seconds after the processes running in the pod are sent a termination signal and the time when the processes are forcibly halted with a kill signal. Set this value longer than the expected cleanup time for your process.", "format": "int64", "type": "integer" diff --git a/pkg/apis/monitoring/v1/types.go b/pkg/apis/monitoring/v1/types.go index 9e2b3c63cd..4a1fe6396b 100644 --- a/pkg/apis/monitoring/v1/types.go +++ b/pkg/apis/monitoring/v1/types.go @@ -344,7 +344,7 @@ type CommonPrometheusFields struct { // a termination signal and the time when the processes are forcibly halted with a kill signal. // Set this value longer than the expected cleanup time for your process. // +optional - // +kubebuilder:default:="600" + // +kubebuilder:default:=600 TerminationGracePeriodSeconds *uint64 `json:"terminationGracePeriodSeconds,omitempty"` } diff --git a/pkg/apis/monitoring/v1/zz_generated.deepcopy.go b/pkg/apis/monitoring/v1/zz_generated.deepcopy.go index 7df92f853f..917daa659f 100644 --- a/pkg/apis/monitoring/v1/zz_generated.deepcopy.go +++ b/pkg/apis/monitoring/v1/zz_generated.deepcopy.go @@ -591,6 +591,11 @@ func (in *CommonPrometheusFields) DeepCopyInto(out *CommonPrometheusFields) { *out = new(uint32) **out = **in } + if in.TerminationGracePeriodSeconds != nil { + in, out := &in.TerminationGracePeriodSeconds, &out.TerminationGracePeriodSeconds + *out = new(uint64) + **out = **in + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CommonPrometheusFields. From 2a61c7dc7ce74c06a5e8808695018c4b7955c289 Mon Sep 17 00:00:00 2001 From: Ben Ye Date: Sat, 26 Mar 2022 00:42:46 -0700 Subject: [PATCH 4/4] add unit test --- pkg/prometheus/statefulset_test.go | 33 ++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/pkg/prometheus/statefulset_test.go b/pkg/prometheus/statefulset_test.go index ec57d6debe..e08dfbb045 100644 --- a/pkg/prometheus/statefulset_test.go +++ b/pkg/prometheus/statefulset_test.go @@ -1998,6 +1998,39 @@ func TestExpectedStatefulSetShardNames(t *testing.T) { } } +func TestExpectStatefulSetTerminationGracePeriodSeconds(t *testing.T) { + statefulSet, err := makeStatefulSet("test", monitoringv1.Prometheus{ + Spec: monitoringv1.PrometheusSpec{}, + }, defaultTestConfig, nil, "", 0, nil) + + if err != nil { + t.Fatal(err) + } + // assert defaults to 0 if nil + if *statefulSet.Spec.Template.Spec.TerminationGracePeriodSeconds != 0 { + t.Fatalf("expected TerminationGracePeriodSeconds to be 0 but got %d", + *statefulSet.Spec.Template.Spec.TerminationGracePeriodSeconds) + } + + var expect uint64 = 5 + statefulSet, err = makeStatefulSet("test", monitoringv1.Prometheus{ + Spec: monitoringv1.PrometheusSpec{ + CommonPrometheusFields: monitoringv1.CommonPrometheusFields{ + TerminationGracePeriodSeconds: &expect, + }, + }, + }, defaultTestConfig, nil, "", 0, nil) + + if err != nil { + t.Fatal(err) + } + + if *statefulSet.Spec.Template.Spec.TerminationGracePeriodSeconds != int64(expect) { + t.Fatalf("expected TerminationGracePeriodSeconds to be %d but got %d", expect, + *statefulSet.Spec.Template.Spec.TerminationGracePeriodSeconds) + } +} + func TestExpectStatefulSetMinReadySeconds(t *testing.T) { statefulSet, err := makeStatefulSet("test", monitoringv1.Prometheus{ Spec: monitoringv1.PrometheusSpec{},