diff --git a/keps/sig-storage/5381-mutable-pv-affinity/README.md b/keps/sig-storage/5381-mutable-pv-affinity/README.md new file mode 100644 index 00000000000..89780e7ecb7 --- /dev/null +++ b/keps/sig-storage/5381-mutable-pv-affinity/README.md @@ -0,0 +1,906 @@ + +# KEP-5381: Mutable PersistentVolume Node Affinity + + +- [Release Signoff Checklist](#release-signoff-checklist) +- [Summary](#summary) +- [Motivation](#motivation) + - [Goals](#goals) + - [Non-Goals](#non-goals) +- [Proposal](#proposal) + - [User Stories (Optional)](#user-stories-optional) + - [Story 1](#story-1) + - [Story 2](#story-2) + - [Notes/Constraints/Caveats (Optional)](#notesconstraintscaveats-optional) + - [Risks and Mitigations](#risks-and-mitigations) +- [Design Details](#design-details) + - [Handling race condition](#handling-race-condition) + - [Test Plan](#test-plan) + - [Prerequisite testing updates](#prerequisite-testing-updates) + - [Unit tests](#unit-tests) + - [Integration tests](#integration-tests) + - [e2e tests](#e2e-tests) + - [Graduation Criteria](#graduation-criteria) + - [Upgrade / Downgrade Strategy](#upgrade--downgrade-strategy) + - [Version Skew Strategy](#version-skew-strategy) +- [Production Readiness Review Questionnaire](#production-readiness-review-questionnaire) + - [Feature Enablement and Rollback](#feature-enablement-and-rollback) + - [Rollout, Upgrade and Rollback Planning](#rollout-upgrade-and-rollback-planning) + - [Monitoring Requirements](#monitoring-requirements) + - [Dependencies](#dependencies) + - [Scalability](#scalability) + - [Troubleshooting](#troubleshooting) +- [Implementation History](#implementation-history) +- [Drawbacks](#drawbacks) +- [Alternatives](#alternatives) + - [Integrate with the CSI spec and VolumeAttributeClass](#integrate-with-the-csi-spec-and-volumeattributeclass) +- [Infrastructure Needed (Optional)](#infrastructure-needed-optional) + + +## Release Signoff Checklist + + + +Items marked with (R) are required *prior to targeting to a milestone / release*. + +- [ ] (R) Enhancement issue in release milestone, which links to KEP dir in [kubernetes/enhancements] (not the initial KEP PR) +- [ ] (R) KEP approvers have approved the KEP status as `implementable` +- [ ] (R) Design details are appropriately documented +- [ ] (R) Test plan is in place, giving consideration to SIG Architecture and SIG Testing input (including test refactors) + - [ ] e2e Tests for all Beta API Operations (endpoints) + - [ ] (R) Ensure GA e2e tests meet requirements for [Conformance Tests](https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/conformance-tests.md) + - [ ] (R) Minimum Two Week Window for GA e2e tests to prove flake free +- [ ] (R) Graduation criteria is in place + - [ ] (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) +- [ ] (R) Production readiness review completed +- [ ] (R) Production readiness review approved +- [ ] "Implementation History" section is up-to-date for milestone +- [ ] User-facing documentation has been created in [kubernetes/website], for publication to [kubernetes.io] +- [ ] Supporting documentation—e.g., additional design documents, links to mailing list discussions/SIG meetings, relevant PRs/issues, release notes + + + +[kubernetes.io]: https://kubernetes.io/ +[kubernetes/enhancements]: https://git.k8s.io/enhancements +[kubernetes/kubernetes]: https://git.k8s.io/kubernetes +[kubernetes/website]: https://git.k8s.io/website + +## Summary + +This KEP proposes to make `PersistentVolume.spec.nodeAffinity` field mutable, +making it possible to change the affinity with VolumeAttributeClass. +This allows user to migrate data or enabling features without +interrupting workloads. + +## Motivation + + + +Currently, `PersistentVolume.spec.nodeAffinity` is set at creation time and cannot be changed. +But user may modify the volume to +taking advantage of new features provided by the storage provider, +or accommodate to the changes of business requirements. +These modification can be expressed by `VolumeAttributeClass` in Kubernetes. +But sometimes, A modification to volume comes with change to its accessibility, such as: +1. migration of data from one zone to regional storage; +2. enabling features that is not supported by all the client nodes. + +In these scenarios, the `nodeAffinity` becomes inaccurate, +causing the scheduler to make decisions based on outdated information. +This results in pods: +* being scheduled to nodes that cannot access the volume, getting stuck in a `ContainerCreating` state; +* or being rejected from nodes that actually can access the volume, getting stuck in a `Pending` state. + +By making `PersistentVolume.spec.nodeAffinity` field mutable, +we give storage providers a chance to propagate latest accessibility requirement to the scheduler, +improving the reliability of stateful pod scheduling. + +### Goals + +- Make `PersistentVolume.spec.nodeAffinity` field mutable. + +### Non-Goals + +- Enable CSI drivers to return a new accessibility requirement on ControllerModifyVolume. +- Modifying the core scheduling logic of Kubernetes. +- Implementing cloud provider-specific solutions within Kubernetes core. +- Re-scheduling running pods with volumes being modified, + or interrupting workloads in any way. + +## Proposal + + + +1. Change APIServer validation to allow `PersistentVolume.spec.nodeAffinity` to be mutable. +2. Ensure scheduler will re-schedule pending pods that using a PV that has been updated. + +### User Stories (Optional) + +#### Story 1 + +As the owner of a stateful workload, I want to take advantage of the new +regional storage provided by the storage provider, +to improve the availability of my application. +I need a way to tell scheduler that the volume is now accessible in every zone, +so that the pod can be scheduled to another zone when the current zone is down. + +In this case, the old affinity would be: +```yaml +required: + nodeSelectorTerms: + - matchExpressions: + - key: topology.kubernetes.io/zone + operator: In + values: + - cn-beijing-g +``` +We would like to change it to: +```yaml +required: +nodeSelectorTerms: +- matchExpressions: + - key: topology.kubernetes.io/region + operator: In + values: + - cn-beijing +``` +manually, hopefully integrated into CSI in the future. + +#### Story 2 + +As a cluster operator, I'm conducting an upgrade to new storage category provided by our storage provider. +However, once upgraded, the volume cannot be attached to some legacy nodes in the cluster. +I need a way to convey this new requirement to the scheduler, +so that my pod will not getting stuck in a `ContainerCreating` state. + +In this case, the old affinity would be: +```yaml +required: + nodeSelectorTerms: + - matchExpressions: + - key: provider.com/disktype.cloud_ssd + operator: In + values: + - available +``` + +Type A node only supports cloud_ssd, while Type B node supports both cloud_ssd and cloud_essd. +We will only allow the modification if the volume is attached to type B nodes. +And I want to make sure the Pods using new cloud_essd volume not to be scheduled to type A nodes. + +We would like to change the affinity to: +```yaml +required: + nodeSelectorTerms: + - matchExpressions: + - key: provider.com/disktype.cloud_essd + operator: In + values: + - available +``` + + +### Notes/Constraints/Caveats (Optional) + + + +`PersistentVolume.spec.nodeAffinity.required` should works like +`Pod.spec.affinity.nodeAffinity.requiredDuringSchedulingIgnoredDuringExecution`. +It is never re-evaluated when the pod is already running. +It is storage provider's responsibility to ensure that the running workload is not interrupted. + + +### Risks and Mitigations + + + +## Design Details + + + +### Handling race condition + +There is a race condition between volume modification and pod scheduling: +1. User modifies the volume from storage provider. +3. A new Pod is created and scheduler schedules it with the old affinity. +4. User sets the new affinity to the PV. +5. KCM/external-attacher attaches the volume to the node, and find the affinity mismatch. + +If this happens, the pod will be stuck in a `ContainerCreating` state. +Kubelet should detect this contidion and reject the pod. +Hopefully some other controllers (StatefulSet controller) will re-create the pod and it will be scheduled to the correct node. + +Specifically, kubelet investigates the cause of the failure by checking the status of the underlying VolumeAttachment object. +If `FailedPrecondition` error is found, and PV's nodeAffinity does not match current node, +kubelet will setting pod phase to 'Failed' + +### Test Plan + + + +[x] I/we understand the owners of the involved components may require updates to +existing tests to make this code solid enough prior to committing the changes necessary +to implement this enhancement. + +##### Prerequisite testing updates + + + +##### Unit tests + + + + + +- `pkg/apis/core/validation`: 2025-06-02 - 84.7% + +##### Integration tests + + + + + +- [test name](https://github.com/kubernetes/kubernetes/blob/2334b8469e1983c525c0c6382125710093a25883/test/integration/...): [integration master](https://testgrid.k8s.io/sig-release-master-blocking#integration-master?include-filter-by-regex=MyCoolFeature), [triage search](https://storage.googleapis.com/k8s-triage/index.html?test=MyCoolFeature) + +##### e2e tests + + + +- [test name](https://github.com/kubernetes/kubernetes/blob/2334b8469e1983c525c0c6382125710093a25883/test/e2e/...): [SIG ...](https://testgrid.k8s.io/sig-...?include-filter-by-regex=MyCoolFeature), [triage search](https://storage.googleapis.com/k8s-triage/index.html?test=MyCoolFeature) + +- Test modifing VolumeAttributeClass can properly update PV `nodeAffinity`. + +### Graduation Criteria + + + +### Upgrade / Downgrade Strategy + + + +### Version Skew Strategy + + + +## Production Readiness Review Questionnaire + + + +### Feature Enablement and Rollback + + + +###### How can this feature be enabled / disabled in a live cluster? + + + +- [ ] Feature gate (also fill in values in `kep.yaml`) + - Feature gate name: + - Components depending on the feature gate: +- [ ] Other + - Describe the mechanism: + - Will enabling / disabling the feature require downtime of the control + plane? + - Will enabling / disabling the feature require downtime or reprovisioning + of a node? + +###### Does enabling the feature change any default behavior? + + + +###### Can the feature be disabled once it has been enabled (i.e. can we roll back the enablement)? + + + +###### What happens if we reenable the feature if it was previously rolled back? + +###### Are there any tests for feature enablement/disablement? + + + +### Rollout, Upgrade and Rollback Planning + + + +###### How can a rollout or rollback fail? Can it impact already running workloads? + + + +###### What specific metrics should inform a rollback? + + + +###### Were upgrade and rollback tested? Was the upgrade->downgrade->upgrade path tested? + + + +###### Is the rollout accompanied by any deprecations and/or removals of features, APIs, fields of API types, flags, etc.? + + + +### Monitoring Requirements + + + +###### How can an operator determine if the feature is in use by workloads? + + + +###### How can someone using this feature know that it is working for their instance? + + + +- [ ] Events + - Event Reason: +- [ ] API .status + - Condition name: + - Other field: +- [ ] Other (treat as last resort) + - Details: + +###### What are the reasonable SLOs (Service Level Objectives) for the enhancement? + + + +###### What are the SLIs (Service Level Indicators) an operator can use to determine the health of the service? + + + +- [ ] Metrics + - Metric name: + - [Optional] Aggregation method: + - Components exposing the metric: +- [ ] Other (treat as last resort) + - Details: + +###### Are there any missing metrics that would be useful to have to improve observability of this feature? + + + +### Dependencies + + + +###### Does this feature depend on any specific services running in the cluster? + + + +### Scalability + + + +###### Will enabling / using this feature result in any new API calls? + + + +###### Will enabling / using this feature result in introducing new API types? + + + +###### Will enabling / using this feature result in any new calls to the cloud provider? + + + +###### Will enabling / using this feature result in increasing size or count of the existing API objects? + + + +###### Will enabling / using this feature result in increasing time taken by any operations covered by existing SLIs/SLOs? + + + +###### Will enabling / using this feature result in non-negligible increase of resource usage (CPU, RAM, disk, IO, ...) in any components? + + + +###### Can enabling / using this feature result in resource exhaustion of some node resources (PIDs, sockets, inodes, etc.)? + + + +### Troubleshooting + + + +###### How does this feature react if the API server and/or etcd is unavailable? + +###### What are other known failure modes? + + + +###### What steps should be taken if SLOs are not being met to determine the problem? + +## Implementation History + + + +## Drawbacks + + + +## Alternatives + +### Integrate with the CSI spec and VolumeAttributeClass + +We have proposed the plan to integrate in the previous version of this KEP. +But we did not reach consensus due to lack of SP want to implement this feature. +The main concerns were about race condition between scheduler and update PV. + +We will try this again in the future. + + + +## Infrastructure Needed (Optional) + + diff --git a/keps/sig-storage/5381-mutable-pv-affinity/kep.yaml b/keps/sig-storage/5381-mutable-pv-affinity/kep.yaml new file mode 100644 index 00000000000..a2e457f1f79 --- /dev/null +++ b/keps/sig-storage/5381-mutable-pv-affinity/kep.yaml @@ -0,0 +1,48 @@ +title: Mutable PersistentVolume Node Affinity +kep-number: 5381 +authors: + - "@huww98" +owning-sig: sig-storage +participating-sigs: + - sig-api-machinery + - sig-scheduling + - sig-storage +status: provisional +creation-date: 2025-06-02 +reviewers: + - "@gnuified" + - "@jsafrane" + - "@msau42" + - "@xing-yang" +approvers: + - "@xing-yang" + - "@msau42" + +# The target maturity stage in the current dev cycle for this KEP. +# If the purpose of this KEP is to deprecate a user-visible feature +# and a Deprecated feature gates are added, they should be deprecated|disabled|removed. +stage: alpha + +# The most recent milestone for which work toward delivery of this KEP has been +# done. This can be the current (upcoming) milestone, if it is being actively +# worked on. +latest-milestone: "v1.34" + +# The milestone at which this feature was, or is targeted to be, at each stage. +milestone: + alpha: "v1.34" + beta: "v1.35" + stable: "v1.37" + +# The following PRR answers are required at alpha release +# List the feature gate name and the components for which it must be enabled +feature-gates: + - name: MutablePVAffinity + components: + - kube-apiserver + - external-resizer +disable-supported: true + +# The following PRR answers are required at beta release +# metrics: +# - my_feature_metric