Skip to content

Commit ac7471c

Browse files
authored
Merge pull request #5575 from yuanwang04/container-restart-policy
KEP-5307: Target ContainerRestartRules for Beta
2 parents 6c75b39 + 6fbad9c commit ac7471c

File tree

3 files changed

+64
-159
lines changed

3 files changed

+64
-159
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
kep-number: 5307
22
alpha:
33
approver: "wojtek-t"
4+
beta:
5+
approver: "wojtek-t"

keps/sig-node/5307-container-restart-policy/README.md

Lines changed: 59 additions & 157 deletions
Original file line numberDiff line numberDiff line change
@@ -115,18 +115,18 @@ checklist items _must_ be updated for the enhancement to be released.
115115

116116
Items marked with (R) are required *prior to targeting to a milestone / release*.
117117

118-
- [ ] (R) Enhancement issue in release milestone, which links to KEP dir in [kubernetes/enhancements] (not the initial KEP PR)
119-
- [ ] (R) KEP approvers have approved the KEP status as `implementable`
120-
- [ ] (R) Design details are appropriately documented
121-
- [ ] (R) Test plan is in place, giving consideration to SIG Architecture and SIG Testing input (including test refactors)
122-
- [ ] e2e Tests for all Beta API Operations (endpoints)
118+
- [x] (R) Enhancement issue in release milestone, which links to KEP dir in [kubernetes/enhancements] (not the initial KEP PR)
119+
- [x] (R) KEP approvers have approved the KEP status as `implementable`
120+
- [x] (R) Design details are appropriately documented
121+
- [x] (R) Test plan is in place, giving consideration to SIG Architecture and SIG Testing input (including test refactors)
122+
- [x] e2e Tests for all Beta API Operations (endpoints)
123123
- [ ] (R) Ensure GA e2e tests meet requirements for [Conformance Tests](https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/conformance-tests.md)
124124
- [ ] (R) Minimum Two Week Window for GA e2e tests to prove flake free
125-
- [ ] (R) Graduation criteria is in place
125+
- [x] (R) Graduation criteria is in place
126126
- [ ] (R) [all GA Endpoints](https://github.com/kubernetes/community/pull/1806) must be hit by [Conformance Tests](https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/conformance-tests.md)
127-
- [ ] (R) Production readiness review completed
128-
- [ ] (R) Production readiness review approved
129-
- [ ] "Implementation History" section is up-to-date for milestone
127+
- [x] (R) Production readiness review completed
128+
- [x] (R) Production readiness review approved
129+
- [x] "Implementation History" section is up-to-date for milestone
130130
- [ ] User-facing documentation has been created in [kubernetes/website], for publication to [kubernetes.io]
131131
- [ ] Supporting documentation—e.g., additional design documents, links to mailing list discussions/SIG meetings, relevant PRs/issues, release notes
132132

@@ -603,6 +603,11 @@ are not restarted and the pod fails.
603603
- Verify that PodFailurePolicy works with the restartPolicyRules; containers restarted
604604
by the restartPolicyRules should not fail the Pod and trigger PodFailurePolicy.
605605

606+
E2E tests:
607+
- https://github.com/kubernetes/kubernetes/blob/9a3dce00ae32c81346883fb5a689a8240d48c218/test/e2e/node/pods.go#L722
608+
- https://github.com/kubernetes/kubernetes/blob/9a3dce00ae32c81346883fb5a689a8240d48c218/test/e2e/apps/job.go#L1331
609+
- https://testgrid.k8s.io/sig-release-master-informing#kind-master-alpha-beta&include-filter-by-regex=ContainerRestartRules
610+
606611
### Graduation Criteria
607612

608613
<!--
@@ -690,6 +695,9 @@ pod restart policy, container restart policy, and container restart rules.
690695
- Container restart policy functionality running behind feature flag
691696
for at least one release.
692697
- Container restart policy runs well with Job controller.
698+
- All monitoring requirements completed.
699+
- All testing requirements completed.
700+
- All known pre-release issues and gaps resolved.
693701

694702
#### GA
695703

@@ -801,10 +809,11 @@ feature.
801809
NOTE: Also set `disable-supported` to `true` or `false` in `kep.yaml`.
802810
-->
803811

804-
Yes. To roll back, the feature gate should be disabled in the API server and
805-
kubelets, and components should be restarted. If a Pod was created with the
806-
restartPolicyRules field while the gate was enabled, those rules will be ignored by
807-
kubelets once the feature is disabled.
812+
Yes. To roll back, the feature gate should be disabled in the API server and kubelets, and they should be restarted.
813+
814+
If a Pod was created with the container-level restart policy and/or restartPolicyRules while the feature gate was enabled, but later the feature gate is disabled, those container-level restart policy and rules will persist, but they will have no effect and will be ignored by the kubelet.
815+
816+
Once the feature is disabled, pods cannot be created with container-level restart policy except Sidecar init containers with restart policy Always. Pods created with restart policy rules will be silently dropped.
808817

809818
###### What happens if we reenable the feature if it was previously rolled back?
810819

@@ -827,14 +836,11 @@ You can take a look at one potential example of such test in:
827836
https://github.com/kubernetes/kubernetes/pull/97058/files#diff-7826f7adbc1996a05ab52e3f5f02429e94b68ce6bce0dc534d1be636154fded3R246-R282
828837
-->
829838

830-
- Unit test for the API's validation with the feature enabled and disabled.
831-
- Unit test for the kubelet with the feature enabled and disabled.
832-
- Unit test for API on the new field for the Pod API. First enable
833-
the feature gate, create a Pod with a container including restartRules,
834-
validation should pass and the Pod API should match the expected result.
835-
Second, disable the feature gate, validate the Pod API should still pass
836-
and it should match the expected result. Lastly, re-enable the feature
837-
gate, validate the Pod API should pass and it should match the expected result.
839+
- Unit test for the API's validation with the feature enabled and disabled:
840+
- See https://github.com/kubernetes/kubernetes/blob/9630ab9581afbac9835d53f9e620a1240a1d2d91/pkg/apis/core/validation/validation_test.go#L29065 and https://github.com/kubernetes/kubernetes/blob/9630ab9581afbac9835d53f9e620a1240a1d2d91/pkg/apis/core/validation/validation_test.go#L9357
841+
- Unit test for the kubelet with the feature enabled
842+
- See https://github.com/kubernetes/kubernetes/blob/9630ab9581afbac9835d53f9e620a1240a1d2d91/pkg/kubelet/kubelet_test.go#L2476, https://github.com/kubernetes/kubernetes/blob/9630ab9581afbac9835d53f9e620a1240a1d2d91/pkg/kubelet/kubelet_pods_test.go#L3302, and https://github.com/kubernetes/kubernetes/blob/9630ab9581afbac9835d53f9e620a1240a1d2d91/pkg/kubelet/kuberuntime/kuberuntime_manager_test.go#L2112
843+
- Unit test for API on the new field for the Pod API. First enable the feature gate, create a Pod with a container including restartRules, validation should pass and the Pod API should match the expected result. Second, disable the feature gate, validate the Pod API should still pass and it should match the expected result. Lastly, re-enable the feature gate, validate the Pod API should pass and it should match the expected result. This is achieved by the ValidationOptions, if the podSpec contains restart policy, or the feature gate is enabled, then the AllowContainerRestartPolicyRules would be true, see https://github.com/kubernetes/kubernetes/blob/9630ab9581afbac9835d53f9e620a1240a1d2d91/pkg/api/pod/util_test.go#L5965
838844

839845
### Rollout, Upgrade and Rollback Planning
840846

@@ -870,17 +876,14 @@ Repeated restart of container or pods.
870876

871877
###### Were upgrade and rollback tested? Was the upgrade->downgrade->upgrade path tested?
872878

873-
<!--
874-
Describe manual testing that was done and the outcomes.
875-
Longer term, we may want to require automated upgrade/rollback tests, but we
876-
are missing a bunch of machinery and tooling and can't do that now.
877-
-->
879+
Manual testing was performed to verify the upgrade and rollback paths.
880+
- **Upgrade:** A cluster with the feature disabled was upgraded to a version with the feature enabled. Pods with container-level `restartPolicy` and `restartPolicyRules` were deployed and observed to behave as expected.
881+
- **Rollback:** A cluster with the feature enabled was rolled back to a version with the feature disabled. Previously created pods continued to run and have the container-level `restartPolicy` and `restartPolicyRules`, but these fields were ignored. New Pods cannot be created with container-level restartPolicy, and `restartPolicyRules` are dropped silently.
882+
- **Upgrade->Downgrade->Upgrade:** This path was tested by performing the above steps sequentially. The feature behaved as expected at each stage, with `restartPolicyRules` being respected when the feature was enabled and ignored when disabled.
878883

879884
###### Is the rollout accompanied by any deprecations and/or removals of features, APIs, fields of API types, flags, etc.?
880885

881-
<!--
882-
Even if applying deprecation policies, they may still surprise some users.
883-
-->
886+
No.
884887

885888
### Monitoring Requirements
886889

@@ -893,11 +896,9 @@ previous answers based on experience in the field.
893896

894897
###### How can an operator determine if the feature is in use by workloads?
895898

896-
<!--
897-
Ideally, this should be a metric. Operations against the Kubernetes API (e.g.,
898-
checking if there are objects with field X set) may be a last resort. Avoid
899-
logs or events for this purpose.
900-
-->
899+
Operators can determine if the feature is in use by checking the Pod spec for the presence of the `restartPolicyRules` field within container definitions. Operators can track the `ContainerStatus.RestartCount` to see how many times the container has restarted.
900+
901+
Additionally, monitoring the `kube_pod_container_status_restarts_total` metric can indicate container restarts that might be governed by these rules.
901902

902903
###### How can someone using this feature know that it is working for their instance?
903904

@@ -912,175 +913,68 @@ Recall that end users cannot usually observe component logs or access metrics.
912913

913914
- [ ] Events
914915
- Event Reason:
915-
- [ ] API .status
916-
- Condition name:
917-
- Other field:
918-
- [ ] Other (treat as last resort)
919-
- Details:
916+
- [x] API .status
917+
- Other field: ContainerStatuses
918+
- Container statuses will have the history of the container restarts.
919+
- [x] Other (treat as last resort)
920+
- Details: The metric `kube_pod_container_status_restarts_total` will show the total count of container restarts.
920921

921922
###### What are the reasonable SLOs (Service Level Objectives) for the enhancement?
922923

923-
<!--
924-
This is your opportunity to define what "normal" quality of service looks like
925-
for a feature.
926-
927-
It's impossible to provide comprehensive guidance, but at the very
928-
high level (needs more precise definitions) those may be things like:
929-
- per-day percentage of API calls finishing with 5XX errors <= 1%
930-
- 99% percentile over day of absolute value from (job creation time minus expected
931-
job creation time) for cron job <= 10%
932-
- 99.9% of /health requests per day finish with 200 code
933-
934-
These goals will help you determine what you need to measure (SLIs) in the next
935-
question.
936-
-->
924+
- The rate of unexpected container restarts (i.e., not matching a `restartPolicyRules`) should remain below 1%.
925+
- The time taken for a container to restart after an exit code matching `restartPolicyRules` should be within typical container restart latencies, accounting for exponential backoff.
926+
- Kubelet SLOs should not be impacted.
937927

938928
###### What are the SLIs (Service Level Indicators) an operator can use to determine the health of the service?
939929

940-
<!--
941-
Pick one more of these and delete the rest.
942-
-->
943-
944-
- [ ] Metrics
945-
- Metric name:
946-
- [Optional] Aggregation method:
947-
- Components exposing the metric:
948-
- [ ] Other (treat as last resort)
949-
- Details:
930+
- [x] Metrics
931+
- Metric name: `kube_pod_container_status_restarts_total`
932+
- Aggregation method: Sum over time, grouped by container and pod.
933+
- Components exposing the metric: kube-state-metrics
934+
- [x] Other (treat as last resort)
935+
- Details: PodStatus API will also have a full history of containers restarted in ContainerStatuses field. Containers restarted by RestartPolicyRules will be included in the statuses history.
950936

951937
###### Are there any missing metrics that would be useful to have to improve observability of this feature?
952938

953-
<!--
954-
Describe the metrics themselves and the reasons why they weren't added (e.g., cost,
955-
implementation difficulties, etc.).
956-
-->
939+
No.
957940

958941
### Dependencies
959942

960-
<!--
961-
This section must be completed when targeting beta to a release.
962-
-->
963-
964943
###### Does this feature depend on any specific services running in the cluster?
965944

966-
<!--
967-
Think about both cluster-level services (e.g. metrics-server) as well
968-
as node-level agents (e.g. specific version of CRI). Focus on external or
969-
optional services that are needed. For example, if this feature depends on
970-
a cloud provider API, or upon an external software-defined storage or network
971-
control plane.
972-
973-
For each of these, fill in the following—thinking about running existing user workloads
974-
and creating new ones, as well as about cluster-level services (e.g. DNS):
975-
- [Dependency name]
976-
- Usage description:
977-
- Impact of its outage on the feature:
978-
- Impact of its degraded performance or high-error rates on the feature:
979-
-->
945+
No.
980946

981947
### Scalability
982948

983-
<!--
984-
For alpha, this section is encouraged: reviewers should consider these questions
985-
and attempt to answer them.
986-
987-
For beta, this section is required: reviewers must answer these questions.
988-
989-
For GA, this section is required: approvers should be able to confirm the
990-
previous answers based on experience in the field.
991-
-->
992-
993949
###### Will enabling / using this feature result in any new API calls?
994950

995-
<!--
996-
Describe them, providing:
997-
- API call type (e.g. PATCH pods)
998-
- estimated throughput
999-
- originating component(s) (e.g. Kubelet, Feature-X-controller)
1000-
Focusing mostly on:
1001-
- components listing and/or watching resources they didn't before
1002-
- API calls that may be triggered by changes of some Kubernetes resources
1003-
(e.g. update of object X triggers new updates of object Y)
1004-
- periodic API calls to reconcile state (e.g. periodic fetching state,
1005-
heartbeats, leader election, etc.)
1006-
-->
1007-
1008951
No.
1009952

1010953
###### Will enabling / using this feature result in introducing new API types?
1011954

1012-
<!--
1013-
Describe them, providing:
1014-
- API type
1015-
- Supported number of objects per cluster
1016-
- Supported number of objects per namespace (for namespace-scoped objects)
1017-
-->
1018-
1019955
Enabling this feature will introduce a new field `restartPolicyRules` on the
1020956
[Container API type](https://github.com/kubernetes/kubernetes/blob/master/pkg/apis/core/types.go#L2528).
1021957

1022958
###### Will enabling / using this feature result in any new calls to the cloud provider?
1023959

1024-
<!--
1025-
Describe them, providing:
1026-
- Which API(s):
1027-
- Estimated increase:
1028-
-->
1029-
1030960
No.
1031961

1032962
###### Will enabling / using this feature result in increasing size or count of the existing API objects?
1033963

1034-
<!--
1035-
Describe them, providing:
1036-
- API type(s):
1037-
- Estimated increase in size: (e.g., new annotation of size 32B)
1038-
- Estimated amount of new objects: (e.g., new Object X for every existing Pod)
1039-
-->
1040-
1041964
[Container API type](https://github.com/kubernetes/kubernetes/blob/master/pkg/apis/core/types.go#L2528)
1042965
will be increased. The rules can handle at most 256 int32 exit values, plus
1043966
the action name ("In" or "NotIn"), the size will increase by at most 1029B.
1044967

1045968
###### Will enabling / using this feature result in increasing time taken by any operations covered by existing SLIs/SLOs?
1046969

1047-
<!--
1048-
Look at the [existing SLIs/SLOs].
1049-
1050-
Think about adding additional work or introducing new steps in between
1051-
(e.g. need to do X to start a container), etc. Please describe the details.
1052-
1053-
[existing SLIs/SLOs]: https://git.k8s.io/community/sig-scalability/slos/slos.md#kubernetes-slisslos
1054-
-->
1055-
1056970
No.
1057971

1058972
###### Will enabling / using this feature result in non-negligible increase of resource usage (CPU, RAM, disk, IO, ...) in any components?
1059973

1060-
<!--
1061-
Things to keep in mind include: additional in-memory state, additional
1062-
non-trivial computations, excessive access to disks (including increased log
1063-
volume), significant amount of data sent and/or received over network, etc.
1064-
This through this both in small and large cases, again with respect to the
1065-
[supported limits].
1066-
1067-
[supported limits]: https://git.k8s.io/community//sig-scalability/configs-and-limits/thresholds.md
1068-
-->
1069-
1070974
No.
1071975

1072976
###### Can enabling / using this feature result in resource exhaustion of some node resources (PIDs, sockets, inodes, etc.)?
1073977

1074-
<!--
1075-
Focus not just on happy cases, but primarily on more pathological cases
1076-
(e.g. probes taking a minute instead of milliseconds, failed pods consuming resources, etc.).
1077-
If any of the resources can be exhausted, how this is mitigated with the existing limits
1078-
(e.g. pods per node) or new limits added by this KEP?
1079-
1080-
Are there any tests that were run/should be run to understand performance characteristics better
1081-
and validate the declared limits?
1082-
-->
1083-
1084978
No.
1085979

1086980
### Troubleshooting
@@ -1098,6 +992,8 @@ details). For now, we leave it here.
1098992

1099993
###### How does this feature react if the API server and/or etcd is unavailable?
1100994

995+
The container will keep running or restarted by kubelet. Deletion of the pod / container may be delayed.
996+
1101997
###### What are other known failure modes?
1102998

1103999
<!--
@@ -1113,6 +1009,8 @@ For each of them, fill in the following information by copying the below templat
11131009
- Testing: Are there any tests for failure mode? If not, describe why.
11141010
-->
11151011

1012+
If kubelet becomes unavailable or is being restarted, there might be delays in container restarts.
1013+
11161014
###### What steps should be taken if SLOs are not being met to determine the problem?
11171015

11181016
## Implementation History
@@ -1128,6 +1026,10 @@ Major milestones might include:
11281026
- when the KEP was retired or superseded
11291027
-->
11301028

1029+
- 1.34: Implemented in Alpha
1030+
- https://github.com/kubernetes/kubernetes/pull/132642
1031+
- https://github.com/kubernetes/kubernetes/pull/133243
1032+
11311033
## Drawbacks
11321034

11331035
<!--

keps/sig-node/5307-container-restart-policy/kep.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ see-also:
1919
# The target maturity stage in the current dev cycle for this KEP.
2020
# If the purpose of this KEP is to deprecate a user-visible feature
2121
# and a Deprecated feature gates are added, they should be deprecated|disabled|removed.
22-
stage: alpha
22+
stage: beta
2323

2424
# The most recent milestone for which work toward delivery of this KEP has been
2525
# done. This can be the current (upcoming) milestone, if it is being actively
2626
# worked on.
27-
latest-milestone: "v1.34"
27+
latest-milestone: "v1.35"
2828

2929
# The milestone at which this feature was, or is targeted to be, at each stage.
3030
milestone:
@@ -43,4 +43,5 @@ disable-supported: true
4343

4444
# The following PRR answers are required at beta release
4545
metrics:
46+
- "kube_pod_container_status_restarts_total"
4647

0 commit comments

Comments
 (0)