546 Commits
Author SHA1 Message Date
kubernetes-prow[bot] b1add3ae9a Merge pull request #141536 from obarisk/feat/storage-metrics-beta
metrics: graduate volume_operation_total_errors to BETA
2026-09-16 21:53:22 +00:00
kubernetes-prow[bot] 1b2ebe523c Merge pull request #141618 from thc1006/pv-explicit-binding-capacity-cmp
persistentvolume: compare storage sizes with Quantity.Cmp
2026-09-10 22:36:33 +00:00
kubernetes-prow[bot] 81bda630de Merge pull request #141718 from pohly/scheduler-client-go-context
kube-controller-manager: use context-aware client-go
2026-09-09 20:31:00 +00:00
thc1006 aa5deb1d42 persistentvolume: compare storage sizes with Quantity.Cmp
checkVolumeSatisfyClaim compared PV capacity and PVC request through
Quantity.Value(), which projects onto int64 and overflows for storage
quantities past that range, so a large capacity or request was misordered.
FindMatchingVolume already compares the same two quantities with Cmp, so
use Cmp here too and keep the explicit-binding path in agreement.

Signed-off-by: thc1006 <84045975+thc1006@users.noreply.github.com>
2026-09-08 00:27:38 +08:00
Patrick Ohly 2579861734 kube-controller-manager: use context-aware client-go
Kubernetes 1.37 finished the introduction of context-aware client-go APIs.
Components like kube-controller-manager which are meant to support contextual
logging should use those new APIs.

This is not enforced yet because existing code must be updated first. Once
that is done, enforcement of everything touched here can be enabled tree-wide.
2026-09-07 16:49:09 +02:00
胡玮文 efa9bb55af Use assumecache in the PV controller to fix storeObjectUpdate races
The PV controller kept its own PV/PVC caches (ctrl.volumes, ctrl.claims)
separate from the shared informers, reconciled via storeObjectUpdate().
That split brain caused:

  - an in-flight controller update could re-add an object the informer had
    already observed as deleted, resurrecting a phantom PV/PVC, and
  - concurrent read-compare-write of the separate store could overwrite a
    newer version with a stale one.

Replace both caches and storeObjectUpdate() with a single
assumecache.AssumeCache[T] layered on each shared informer. The informer
indexer is the source of truth; the controller's own writes are recorded
with AssumeWritten() (comparable ResourceVersions, KEP-5504) so reads
observe them until the informer catches up, and never resurrect a deleted
object.

Details:
  - The accessmodes index moves onto the PV shared informer; the ordered
    index and matching helpers now read through the assume cache.
  - Delete follow-up (schedule the bound partner's sync, clean up the
    operation-timestamp cache and metrics) moves into the informer delete
    handlers, which still hold the deleted object.
  - syncVolumeByKey/syncClaimByKey read from the assume cache via
    GetAssumed() and skip the sync when the object is still being served
    from the controller's own not-yet-observed write. This matches
    the old storeObjectUpdate() "skip older ResourceVersion" guard.
    The 15s resync is also preserved.
  - initializeCaches() is removed; the informer indexer is already
    populated once the caches have synced.

All reads go through assumption-aware methods so they observe the
controller's own writes: AssumeCache grows List() (used by the metrics
collector) and ListIndexValues() (used to enumerate access-mode index
keys) alongside Get()/GetAssumed()/ByIndex(). AssumeCache.Indexer()
remains only as a low-level seam for tests to seed informer state; it is
never used for production reads.

The RV-ordering logic previously unit-tested via storeObjectUpdate() is
now covered by the assumecache package tests.
2026-09-05 19:44:14 +08:00
胡玮文 a722fb1cd0 Cache the object returned by the API server, not the sent copy
removeDeletionProtectionFinalizer() and rescheduleProvisioning() throw
away the object returned by Update() and put the copy they sent into the
controller cache instead. That copy still carries the ResourceVersion the
object had before the write, so the cache ends up holding content from
version N+1 labelled as version N. All the other writers in this
controller store the API server's response; do the same here, and name
the variables like they do.

This works today only because storeObjectUpdate() lets an equal
ResourceVersion pass, which happens to overwrite the entry. A cache that
decides what to keep by comparing ResourceVersions cannot make that call
correctly, so fix the input first.
2026-09-05 19:43:51 +08:00
obarisk ce05248bd6 chore: fix comment for RecordVolumeOperationErrorMetric 2026-08-23 15:15:56 +08:00
obarisk f2ca601f3c metrics: graduate volume_operation_total_errors to beta 2026-08-22 21:31:34 +08:00
Daniel Fajmon 331d23ec18 persistentvolume: fix pv_collector_total_pv_count reporting N/A plugin_name for CSI volumes
Commit 9e29f95618 ("Refactor controller-manager volume plugins")
replaced ProbeControllerVolumePlugins with
ProbeProvisionableRecyclableVolumePlugins for the PV binder controller.
The new function filters plugins to those implementing
Provisionable/Deletable/Recyclable interfaces; the CSI plugin implements
none of these (it delegates to external drivers), so it was excluded
from volumePluginMgr.

metrics.Register was still passing &ctrl.volumePluginMgr, so
getPVPluginName() -> FindPluginBySpec() failed for any CSI PV,
falling back to pluginNameNotAvailable ("N/A") instead of the expected
"kubernetes.io/csi:<driver>" label value.

Fix by initializing a dedicated metricsPluginMgr from
ProbePersistentVolumePlugins (all plugins, no filter) and passing it
to metrics.Register.
2026-07-27 15:24:22 +02:00
kubernetes-prow[bot] aedfaadf0d Merge pull request #139944 from krishhna24/volume-event-handler-remaining
volume: use AddEventHandlerWithOptions in more controllers
2026-07-22 13:06:07 +00:00
kubernetes-prow[bot] 3473c0534f Merge pull request #140121 from richabanker/storage-metrics-nh
Defer storage histogram metrics registration to runtime
2026-07-10 22:07:51 +00:00
Richa Banker b62df1d392 Defer storage histogram metrics registration to runtime
Signed-off-by: Richa Banker <richabanker@google.com>
2026-07-09 20:33:12 +00:00
Joe Betz e89ecc6af0 generate 2026-06-30 18:02:28 -04:00
krishhna_dev be9d051dbb volume: return error instead of panicking on handler registration
AddEventHandlerWithOptions returns an error, but several controller
constructors passed it to runtime.Must, which panics the whole
controller-manager. Since these constructors already return an error,
return the wrapped error instead, matching the existing pattern in the
selinux warning controller.
2026-06-24 07:45:54 +00:00
krishhna_dev 6914a47c7e volume: use AddEventHandlerWithOptions in more controllers
The attachdetach, expand, ephemeral, selinuxwarning and persistentvolume
controllers registered their informer event handlers via AddEventHandler,
which logs through the global klog.Background() logger. Switch them to
AddEventHandlerWithOptions and pass the controller's contextual logger so
event-handler logging is contextual.

For the controllers that previously discarded the registration result, the
returned error is now surfaced via runtime.Must instead of being ignored.

This is a follow-up to the protection controllers for the remaining volume
controllers.
2026-06-23 08:03:38 +00:00
Joe Betz 119a1460c1 Generate deepcopy 2026-05-11 12:27:56 -04:00
Davanum Srinivas 72b6f1b590 persistentvolume: deflake TestControllerSync 5-2-3 startup race
Subtest 5-2-3 starts the controller with both the claim and the volume
already present and with the volume annotated as controller-bound. That
setup depends on watch/list ordering during controller startup: if the
initial objects are observed in a different order, the test can time out
even though the controller later converges to the expected state.

Model the scenario more explicitly. Start with the unbound volume only,
then inject the claim through AddClaimEvent after the controller is
running. Also drop the pre-set controller-bound annotation from the
initial volume since the binding is what the test wants the controller to
establish.

Tested:
go test -race ./pkg/controller/volume/persistentvolume -run TestControllerSync -count=50
2026-03-14 11:58:33 -04:00
Kubernetes Prow Robot 6d92449054 Merge pull request #134290 from huww98/kcm-no-get-pv
Do not get PV for externally deleting volume
2026-03-12 05:13:35 +05:30
Kubernetes Prow Robot c6f70e3a38 Merge pull request #136399 from tico88612/feat/storage-metric-beta
Rename metric `volume_operation_total_errors` to `volume_operation_errors_total`
2026-03-06 00:46:18 +05:30
Mads Jensen f11bb48738 Remove redundant re-assignment in for-loops under pkg
This the forvar rule from modernize. The semantics of the for-loop
changed from Go 1.22 to make this pattern obsolete.
2026-03-02 08:47:43 +01:00
ChengHao Yang 5c88906dca Rename volume_operation_total_errors to volume_operation_errors_total
Raname this because facing lint error, counter metrics should have
"_total" suffix. Add the test `volume_operation_errors_total`
Marked `volume_operation_total_errors` as deprecated

Signed-off-by: ChengHao Yang <17496418+tico88612@users.noreply.github.com>
2026-02-28 20:08:07 +08:00
Stephen Kitt d42d1e3d1f Deprecate obsolete slice utility functions
... and update users to use standard library functions.

Signed-off-by: Stephen Kitt <skitt@redhat.com>
2026-02-16 10:04:33 +01:00
胡玮文 6b4a37194a Do not get PV for externally deleting volume
Currently, we get each released PV every 15s, and in parallel. If there are a lot of released PV and we cannot finish all the get in 15s, it will starve other request by making the queue waiting for client-side throttling very long.

Even in a normal cluster, these requests are taking majority of all get requests from KCM (58% or 470 qps) in our stress test.
2026-02-16 08:51:08 +08:00
carlory 4bc5464553 Remove feature gate HonorPVReclaimPolicy
Signed-off-by: carlory <baofa.fan@daocloud.io>
2026-02-06 13:31:16 +08:00
carlory be0e68ba84 remove featureGate from PluginManager
Signed-off-by: carlory <baofa.fan@daocloud.io>
2026-01-19 11:35:30 +08:00
carlory 6d1afce678 remove GetHostName func from the VolumeHost interface
Signed-off-by: carlory <baofa.fan@daocloud.io>
2026-01-19 11:35:30 +08:00
Kubernetes Prow Robot df9a0bda18 Merge pull request #133797 from tico88612/cleanup/new-fake-with-options
Replace apimachinery/pkg/watch.NewFake with NewFakeWithOptions in pkg/controller
2026-01-08 03:01:38 +05:30
carlory f8e8e55f1d locked the feature-gate VolumeAttributesClass to default (true) and switch storage version from v1beta1 to v1
Signed-off-by: carlory <baofa.fan@daocloud.io>
2025-12-18 15:59:33 +08:00
xigang 8f1ff1d8ce Refactor PV controller to use rate-limiting queues and improve error handling
Signed-off-by: xigang <wangxigang2014@gmail.com>
2025-12-01 19:11:52 +08:00
Ondra Kupka ed74779a0f controller/volume/persistentvolume: Improve goroutine mgmt
Make sure all threads are terminated when Run returns.
2025-11-04 23:58:15 +01:00
Aditi Gupta af231d2153 Replace WaitForNamedCacheSync with WaitForNamedCacheSyncWithContext in pkg/controller/ 2025-09-16 14:51:34 -07:00
ChengHao Yang ef96d9cbd2 Replace NewFake with NewFakeWithOptions in pkg/controller
CreateTestClient add the argument logger for support contextual logging

Signed-off-by: ChengHao Yang <17496418+tico88612@users.noreply.github.com>
2025-09-11 08:39:49 +08:00
Kubernetes Prow Robot 566d6acb70 Merge pull request #131759 from carlory/clean-volumehost
Remove unused GetHostIP method
2025-07-12 05:35:28 -07:00
PatrickLaabs baf71997f5 chore: depr. pointer pkg replacement for pkg/controller 2025-07-07 13:22:36 +02:00
Kubernetes Prow Robot f407bd6d24 Merge pull request #132254 from carlory/cleanup-MountContainers
Cleanup after Alpha feature MountContainers was removed
2025-06-18 17:24:50 -07:00
Davanum SrinivasandJordan Liggitt 03afe6471b Add a replacement for cmp.Diff using json+go-difflib
Co-authored-by: Jordan Liggitt <jordan@liggitt.net>
Signed-off-by: Davanum Srinivas <davanum@gmail.com>
2025-06-16 17:10:42 -04:00
carlory 85bc3cb096 Remove GetExec method from VolumeHost
Signed-off-by: carlory <baofa.fan@daocloud.io>
2025-06-13 10:58:37 +08:00
carlory f0dde38234 Remove pluginName param from GetMounter and GetExec
Signed-off-by: carlory <baofa.fan@daocloud.io>
2025-06-12 17:29:17 +08:00
carlory fe1b1fff7c Remove unused GetHostIP method 2025-05-14 14:50:59 +08:00
carlory 28d359beec promote HonorPVReclaimPolicy to GA
Signed-off-by: carlory <baofa.fan@daocloud.io>
2025-02-27 14:01:22 +08:00
Davanum Srinivas 4e05bc20db Linter to ensure go-cmp/cmp is used ONLY in tests
Signed-off-by: Davanum Srinivas <davanum@gmail.com>
2025-01-24 20:49:14 -05:00
Patrick Ohly 8a908e0c0b remove import doc comments
The "// import <path>" comment has been superseded by Go modules.
We don't have to remove them, but doing so has some advantages:

- They are used inconsistently, which is confusing.
- We can then also remove the (currently broken) hack/update-vanity-imports.sh.
- Last but not least, it would be a first step towards avoiding the k8s.io domain.

This commit was generated with
   sed -i -e 's;^package \(.*\) // import.*;package \1;' $(git grep -l '^package.*// import' | grep -v 'vendor/')

Everything was included, except for
   package labels // import k8s.io/kubernetes/pkg/util/labels
because that package is marked as "read-only".
2024-12-02 16:59:34 +01:00
Abhishek Kr SrivastavandRajalakshmi-Girish 95860cff1c Fix Go vet errors for master golang
Co-authored-by: Rajalakshmi-Girish <rajalakshmi.girish1@ibm.com>
Co-authored-by: Abhishek Kr Srivastav <Abhishek.kr.srivastav@ibm.com>
2024-09-20 12:36:38 +05:30
Joe Betz 2595aa1309 generate 2024-09-03 14:26:26 -04:00
carlory c4851c64a0 remove volumeoptions from VolumePlugin and BlockVolumePlugin 2024-07-24 14:07:02 +08:00
Drew Sirenko 16c2ad5b84 Add labels to PVCollector bound/unbound PVC metrics for VolumeAttributesClass Feature (#126166)
* Add labels to PVCollector bound/unbound PVC metrics

* fixup! Add labels to PVCollector bound/unbound PVC metrics

* wip: Fix 'Unknown
    Decorator'

* fixup! Add labels to PVCollector bound/unbound PVC metrics
2024-07-23 12:21:29 -07:00
carlory 3a6a4830df pvc bind pv with vac 2024-07-23 15:04:11 +08:00
carlory cd2c8cb5fd Fix pv reclaim failed due to its phase is wrongly updated to the Failed state by kcm 2024-06-28 01:25:45 +08:00
Kubernetes Prow Robot aeed1d0e1a Merge pull request #124842 from carlory/honor-pv-reclaim-policy-e2e
Promote HonorPVReclaimPolicy to beta and enable it by default
2024-06-19 13:26:41 -07:00