Skip to content

Commit 1a464e9

Browse files
committed
Merge branch 'master' into use-central-flags
2 parents b83e678 + fe9e0f4 commit 1a464e9

File tree

20 files changed

+2075
-1619
lines changed

20 files changed

+2075
-1619
lines changed

.prow.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#! /bin/bash
2-
# We need to hardcode e2e version for resizer for now, because
3-
# we need fixes from latest release-1.31 branch for all e2es to pass
4-
export CSI_PROW_E2E_VERSION="release-1.31"
2+
export CSI_PROW_E2E_FOCUS_1_34="\[FeatureGate:VolumeAttributesClass\]"
53
. release-tools/prow.sh
64
main
5+

CHANGELOG/CHANGELOG-2.0.md

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
## Release notes for 2.0.0
2+
3+
[Documentation](https://kubernetes-csi.github.io)
4+
5+
## Urgent Upgrade Notes
6+
7+
### (No, really, you MUST read this before you upgrade)
8+
9+
- This resizer version needs Kubernetes 1.34.0+ to support volume modification via the VolumeAttributeClass APIs, as the storage/v1 VolumeAttributesClass object is available starting in v1.34. If the emulation version is below 1.34 and the v1beta1 VolumeAttributeClass API is disabled, the volume modification feature will be disabled. Once the emulated version is updated to 1.34, a resizer restart is required.
10+
11+
# Changelog since 1.14.0
12+
13+
## Changes by Kind
14+
15+
### Feature
16+
17+
- Annotate PVCs that don't require node expansion, so as kubelet can skip them ([#496](https://github.com/kubernetes-csi/external-resizer/pull/496), [@gnufied](https://github.com/gnufied))
18+
- Promote VolumeAttributesClass to GA ([#515](https://github.com/kubernetes-csi/external-resizer/pull/515), [@carlory](https://github.com/carlory))
19+
- Support rolling back when modify failed ([#513](https://github.com/kubernetes-csi/external-resizer/pull/513), [@huww98](https://github.com/huww98))
20+
- VolumeAttributesClass feature gate defaults to false if VAC API v1 is not available ([#532](https://github.com/kubernetes-csi/external-resizer/pull/532), [@huww98](https://github.com/huww98))
21+
- Rbac change for VolumeAttributesClass ([#537](https://github.com/kubernetes-csi/external-resizer/pull/537), [@sunnylovestiramisu](https://github.com/sunnylovestiramisu))
22+
23+
### Bug or Regression
24+
25+
- BugFix: rare flake when resizing close to creation time (no requeue over "PV bound to PVC not found") ([#521](https://github.com/kubernetes-csi/external-resizer/pull/521), [@akalenyu](https://github.com/akalenyu))
26+
27+
### Other (Cleanup or Flake)
28+
29+
- Removed the slowset utility and moved it to the shared csi-lib-utils. ([#494](https://github.com/kubernetes-csi/external-resizer/pull/494), [@mdzraf](https://github.com/mdzraf))
30+
- Update kubernetes dependencies to v1.34.0 ([#525](https://github.com/kubernetes-csi/external-resizer/pull/525), [@dfajmon](https://github.com/dfajmon))
31+
- Update CSI spec to v1.12.0 which moves volume modification feature to stable ([#534](https://github.com/kubernetes-csi/external-resizer/pull/534), [@gnufied](https://github.com/gnufied))
32+
33+
34+
## Dependencies
35+
36+
### Added
37+
- github.com/antihax/optional: [v1.0.0](https://github.com/antihax/optional/tree/v1.0.0)
38+
- github.com/envoyproxy/go-control-plane/envoy: [v1.32.4](https://github.com/envoyproxy/go-control-plane/envoy/tree/v1.32.4)
39+
- github.com/envoyproxy/go-control-plane/ratelimit: [v0.1.0](https://github.com/envoyproxy/go-control-plane/ratelimit/tree/v0.1.0)
40+
- github.com/go-jose/go-jose/v4: [v4.0.4](https://github.com/go-jose/go-jose/v4/tree/v4.0.4)
41+
- github.com/godbus/dbus/v5: [v5.0.4](https://github.com/godbus/dbus/v5/tree/v5.0.4)
42+
- github.com/golang-jwt/jwt/v5: [v5.2.2](https://github.com/golang-jwt/jwt/v5/tree/v5.2.2)
43+
- github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus: [v1.0.1](https://github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus/tree/v1.0.1)
44+
- github.com/grpc-ecosystem/go-grpc-middleware/v2: [v2.3.0](https://github.com/grpc-ecosystem/go-grpc-middleware/v2/tree/v2.3.0)
45+
- github.com/matttproud/golang_protobuf_extensions: [v1.0.1](https://github.com/matttproud/golang_protobuf_extensions/tree/v1.0.1)
46+
- github.com/rogpeppe/fastuuid: [v1.2.0](https://github.com/rogpeppe/fastuuid/tree/v1.2.0)
47+
- github.com/spiffe/go-spiffe/v2: [v2.5.0](https://github.com/spiffe/go-spiffe/v2/tree/v2.5.0)
48+
- github.com/zeebo/errs: [v1.4.0](https://github.com/zeebo/errs/tree/v1.4.0)
49+
- go.etcd.io/raft/v3: v3.6.0
50+
- go.yaml.in/yaml/v2: v2.4.2
51+
- go.yaml.in/yaml/v3: v3.0.4
52+
- sigs.k8s.io/structured-merge-diff/v6: v6.3.0
53+
54+
### Changed
55+
- cel.dev/expr: v0.19.1 → v0.24.0
56+
- cloud.google.com/go/compute/metadata: v0.5.2 → v0.6.0
57+
- github.com/GoogleCloudPlatform/opentelemetry-operations-go/detectors/gcp: [v1.24.2 → v1.26.0](https://github.com/GoogleCloudPlatform/opentelemetry-operations-go/detectors/gcp/compare/v1.24.2...v1.26.0)
58+
- github.com/cncf/xds/go: [b4127c9 → 2f00578](https://github.com/cncf/xds/go/compare/b4127c9...2f00578)
59+
- github.com/container-storage-interface/spec: [v1.11.0 → v1.12.0](https://github.com/container-storage-interface/spec/compare/v1.11.0...v1.12.0)
60+
- github.com/cpuguy83/go-md2man/v2: [v2.0.4 → v2.0.6](https://github.com/cpuguy83/go-md2man/v2/compare/v2.0.4...v2.0.6)
61+
- github.com/emicklei/go-restful/v3: [v3.12.1 → v3.12.2](https://github.com/emicklei/go-restful/v3/compare/v3.12.1...v3.12.2)
62+
- github.com/envoyproxy/go-control-plane: [v0.13.1 → v0.13.4](https://github.com/envoyproxy/go-control-plane/compare/v0.13.1...v0.13.4)
63+
- github.com/envoyproxy/protoc-gen-validate: [v1.1.0 → v1.2.1](https://github.com/envoyproxy/protoc-gen-validate/compare/v1.1.0...v1.2.1)
64+
- github.com/fsnotify/fsnotify: [v1.7.0 → v1.9.0](https://github.com/fsnotify/fsnotify/compare/v1.7.0...v1.9.0)
65+
- github.com/fxamacker/cbor/v2: [v2.7.0 → v2.9.0](https://github.com/fxamacker/cbor/v2/compare/v2.7.0...v2.9.0)
66+
- github.com/golang/glog: [v1.2.2 → v1.2.4](https://github.com/golang/glog/compare/v1.2.2...v1.2.4)
67+
- github.com/google/cel-go: [v0.23.2 → v0.26.0](https://github.com/google/cel-go/compare/v0.23.2...v0.26.0)
68+
- github.com/google/gnostic-models: [v0.6.9 → v0.7.0](https://github.com/google/gnostic-models/compare/v0.6.9...v0.7.0)
69+
- github.com/grpc-ecosystem/grpc-gateway/v2: [v2.24.0 → v2.26.3](https://github.com/grpc-ecosystem/grpc-gateway/v2/compare/v2.24.0...v2.26.3)
70+
- github.com/jonboulle/clockwork: [v0.4.0 → v0.5.0](https://github.com/jonboulle/clockwork/compare/v0.4.0...v0.5.0)
71+
- github.com/modern-go/reflect2: [v1.0.2 → 35a7c28](https://github.com/modern-go/reflect2/compare/v1.0.2...35a7c28)
72+
- github.com/spf13/cobra: [v1.8.1 → v1.9.1](https://github.com/spf13/cobra/compare/v1.8.1...v1.9.1)
73+
- github.com/spf13/pflag: [v1.0.5 → v1.0.6](https://github.com/spf13/pflag/compare/v1.0.5...v1.0.6)
74+
- go.etcd.io/bbolt: v1.3.11 → v1.4.2
75+
- go.etcd.io/etcd/api/v3: v3.5.21 → v3.6.4
76+
- go.etcd.io/etcd/client/pkg/v3: v3.5.21 → v3.6.4
77+
- go.etcd.io/etcd/client/v3: v3.5.21 → v3.6.4
78+
- go.etcd.io/etcd/pkg/v3: v3.5.21 → v3.6.4
79+
- go.etcd.io/etcd/server/v3: v3.5.21 → v3.6.4
80+
- go.opentelemetry.io/contrib/detectors/gcp: v1.31.0 → v1.34.0
81+
- go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc: v0.58.0 → v0.60.0
82+
- go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc: v1.33.0 → v1.34.0
83+
- go.opentelemetry.io/otel/exporters/otlp/otlptrace: v1.33.0 → v1.34.0
84+
- go.opentelemetry.io/otel/metric: v1.33.0 → v1.35.0
85+
- go.opentelemetry.io/otel/sdk/metric: v1.31.0 → v1.34.0
86+
- go.opentelemetry.io/otel/sdk: v1.33.0 → v1.34.0
87+
- go.opentelemetry.io/otel/trace: v1.33.0 → v1.35.0
88+
- go.opentelemetry.io/otel: v1.33.0 → v1.35.0
89+
- go.opentelemetry.io/proto/otlp: v1.4.0 → v1.5.0
90+
- google.golang.org/genproto/googleapis/api: e6fa225 → a0af3ef
91+
- google.golang.org/genproto/googleapis/rpc: 5f5ef82 → a0af3ef
92+
- google.golang.org/grpc: v1.69.2 → v1.72.1
93+
- k8s.io/api: v0.33.0 → v0.34.0
94+
- k8s.io/apimachinery: v0.33.0 → v0.34.0
95+
- k8s.io/apiserver: v0.33.0 → v0.34.0
96+
- k8s.io/client-go: v0.33.0 → v0.34.0
97+
- k8s.io/component-base: v0.33.0 → v0.34.0
98+
- k8s.io/csi-translation-lib: v0.33.0 → v0.34.0
99+
- k8s.io/gengo/v2: a7b603a → 85fd79d
100+
- k8s.io/kms: v0.33.0 → v0.34.0
101+
- k8s.io/kube-openapi: c8a335a → f3f2b99
102+
- k8s.io/utils: 24370be → 4c0f3b2
103+
- sigs.k8s.io/yaml: v1.4.0 → v1.6.0
104+
105+
### Removed
106+
- github.com/census-instrumentation/opencensus-proto: [v0.4.1](https://github.com/census-instrumentation/opencensus-proto/tree/v0.4.1)
107+
- github.com/golang-jwt/jwt/v4: [v4.5.2](https://github.com/golang-jwt/jwt/v4/tree/v4.5.2)
108+
- github.com/grpc-ecosystem/go-grpc-middleware: [v1.3.0](https://github.com/grpc-ecosystem/go-grpc-middleware/tree/v1.3.0)
109+
- github.com/grpc-ecosystem/grpc-gateway: [v1.16.0](https://github.com/grpc-ecosystem/grpc-gateway/tree/v1.16.0)
110+
- go.etcd.io/etcd/client/v2: v2.305.21
111+
- go.etcd.io/etcd/raft/v3: v3.5.21
112+
- google.golang.org/genproto: ef43131

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ This information reflects the head of this branch.
1414

1515
| Compatible with CSI Version | Container Image | [Min K8s Version](https://kubernetes-csi.github.io/docs/kubernetes-compatibility.html#minimum-version) | [Recommended K8s Version](https://kubernetes-csi.github.io/docs/kubernetes-compatibility.html#recommended-version) |
1616
|---------------------------------------------------------------------------------------------|------------------------------------|--------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------|
17-
| [CSI Spec v1.10.0](https://github.com/container-storage-interface/spec/releases/tag/v1.5.0) | k8s.gcr.io/sig-storage/csi-resizer | 1.16 | 1.32 |
17+
| [CSI Spec v1.12.0](https://github.com/container-storage-interface/spec/releases/tag/v2.0.0) | k8s.gcr.io/sig-storage/csi-resizer | 1.16 | 1.34 |
1818

1919
## Feature status
2020

@@ -27,7 +27,7 @@ The following table reflects the head of this branch.
2727
| VolumeExpansion | Stable | On | [Support for expanding CSI volumes](https://kubernetes.io/docs/concepts/storage/persistent-volumes/#csi-volume-expansion). |
2828
| ReadWriteOncePod | Stable | On | [Single pod access mode for PersistentVolumes](https://kubernetes.io/docs/concepts/storage/persistent-volumes/#access-modes). |
2929
| RecoverVolumeExpansionFailure | Beta | On | [Recover from volume expansion failure](https://kubernetes.io/docs/concepts/storage/persistent-volumes/#recovering-from-failure-when-expanding-volumes) |
30-
| VolumeAttributesClass | Beta | Off | [Volume Attributes Classes](https://kubernetes.io/docs/concepts/storage/volume-attributes-classes). |
30+
| VolumeAttributesClass | Stable | On | [Volume Attributes Classes](https://kubernetes.io/docs/concepts/storage/volume-attributes-classes). |
3131

3232

3333
## Usage

cmd/csi-resizer/main.go

Lines changed: 56 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package main
1818

1919
import (
2020
"context"
21+
"errors"
2122
"flag"
2223
"fmt"
2324
"net/http"
@@ -134,6 +135,21 @@ func main() {
134135
klog.ErrorS(err, "Failed to create kube client")
135136
klog.FlushAndExit(klog.ExitFlushTimeout, 1)
136137
}
138+
// if feature gate is not explicitly set, probe if we have VAC API available
139+
if !utilfeature.DefaultMutableFeatureGate.ExplicitlySet(features.VolumeAttributesClass) {
140+
enabled, err := features.IsVolumeAttributesClassV1Enabled(kubeClient.Discovery())
141+
switch {
142+
case err != nil:
143+
klog.ErrorS(err, "Failed to check VolumeAttributesClass V1 API availability")
144+
case enabled:
145+
klog.InfoS("VolumeAttributesClass v1 API is available")
146+
default:
147+
klog.InfoS("Disabling VolumeAttributesClass feature gate because the VolumeAttributesClass v1 API is not available")
148+
if err := utilfeature.DefaultMutableFeatureGate.OverrideDefault(features.VolumeAttributesClass, false); err != nil {
149+
klog.Fatalf("Failed to disable VolumeAttributesClass feature gate: %v", err)
150+
}
151+
}
152+
}
137153

138154
informerFactory := informers.NewSharedInformerFactory(kubeClient, *resyncPeriod)
139155

@@ -176,7 +192,9 @@ func main() {
176192
*timeout,
177193
kubeClient,
178194
driverName)
179-
if err != nil {
195+
if err != nil && errors.Is(err, resizer.ResizeNotSupportErr) {
196+
klog.InfoS("Resize not supported", "message", err)
197+
} else if err != nil {
180198
klog.ErrorS(err, "Failed to create CSI resizer")
181199
klog.FlushAndExit(klog.ExitFlushTimeout, 1)
182200
}
@@ -188,11 +206,17 @@ func main() {
188206
informerFactory,
189207
*extraModifyMetadata,
190208
driverName)
191-
if err != nil {
209+
if err != nil && errors.Is(err, modifier.ModifyNotSupportErr) {
210+
klog.InfoS("Modify not supported", "message", err)
211+
} else if err != nil {
192212
klog.ErrorS(err, "Failed to create CSI modifier")
193213
klog.FlushAndExit(klog.ExitFlushTimeout, 1)
194214
}
195215

216+
if csiResizer == nil && csiModifier == nil {
217+
klog.Fatalf("CSI driver does not support resize nor modify")
218+
}
219+
196220
// Start HTTP server for metrics + leader election healthz
197221
if addr != "" {
198222
metricsManager.RegisterToServer(mux, standardflags.Configuration.MetricsPath)
@@ -207,17 +231,30 @@ func main() {
207231
}()
208232
}
209233

210-
resizerName := csiResizer.Name()
211-
rc := controller.NewResizeController(resizerName, csiResizer, kubeClient, *resyncPeriod, informerFactory,
212-
workqueue.NewTypedItemExponentialFailureRateLimiter[string](*retryIntervalStart, *retryIntervalMax),
213-
*handleVolumeInUseError, *retryIntervalMax)
234+
leaseHolder := ""
235+
var rc controller.ResizeController
236+
if csiResizer != nil {
237+
resizerName := csiResizer.Name()
238+
rc = controller.NewResizeController(resizerName, csiResizer, kubeClient, *resyncPeriod, informerFactory,
239+
workqueue.NewTypedItemExponentialFailureRateLimiter[string](*retryIntervalStart, *retryIntervalMax),
240+
*handleVolumeInUseError, *retryIntervalMax)
241+
242+
leaseHolder = resizerName
243+
}
214244

215-
modifierName := csiModifier.Name()
216245
var mc modifycontroller.ModifyController
217-
// Add modify controller only if the feature gate is enabled
218-
if utilfeature.DefaultFeatureGate.Enabled(features.VolumeAttributesClass) {
219-
mc = modifycontroller.NewModifyController(modifierName, csiModifier, kubeClient, *resyncPeriod, *retryIntervalMax, *extraModifyMetadata, informerFactory,
220-
workqueue.NewTypedItemExponentialFailureRateLimiter[string](*retryIntervalStart, *retryIntervalMax))
246+
if csiModifier != nil {
247+
modifierName := csiModifier.Name()
248+
// Add modify controller only if the feature gate is enabled
249+
if utilfeature.DefaultFeatureGate.Enabled(features.VolumeAttributesClass) {
250+
mc = modifycontroller.NewModifyController(modifierName, csiModifier, kubeClient, *resyncPeriod,
251+
*retryIntervalMax, *extraModifyMetadata, informerFactory,
252+
workqueue.NewTypedItemExponentialFailureRateLimiter[string](*retryIntervalStart, *retryIntervalMax))
253+
}
254+
255+
if leaseHolder == "" {
256+
leaseHolder = modifierName
257+
}
221258
}
222259

223260
// handle SIGTERM and SIGINT by cancelling the context.
@@ -247,16 +284,20 @@ func main() {
247284
informerFactory.Start(ctx.Done())
248285
if utilfeature.DefaultFeatureGate.Enabled(features.ReleaseLeaderElectionOnExit) {
249286
var wg sync.WaitGroup
250-
go rc.Run(*workers, controllerCtx, &wg)
251-
if utilfeature.DefaultFeatureGate.Enabled(features.VolumeAttributesClass) {
287+
if rc != nil {
288+
go rc.Run(*workers, controllerCtx, &wg)
289+
}
290+
if mc != nil && utilfeature.DefaultFeatureGate.Enabled(features.VolumeAttributesClass) {
252291
go mc.Run(*workers, controllerCtx, &wg)
253292
}
254293
<-controllerCtx.Done()
255294
wg.Wait()
256295
terminate()
257296
} else {
258-
go rc.Run(*workers, ctx, nil)
259-
if utilfeature.DefaultFeatureGate.Enabled(features.VolumeAttributesClass) {
297+
if rc != nil {
298+
go rc.Run(*workers, ctx, nil)
299+
}
300+
if mc != nil && utilfeature.DefaultFeatureGate.Enabled(features.VolumeAttributesClass) {
260301
go mc.Run(*workers, ctx, nil)
261302
}
262303
<-ctx.Done()

deploy/kubernetes/rbac.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ rules:
4242
- apiGroups: [""]
4343
resources: ["events"]
4444
verbs: ["list", "watch", "create", "update", "patch"]
45-
# only required if enabling the alpha volume modify feature
4645
- apiGroups: ["storage.k8s.io"]
4746
resources: ["volumeattributesclasses"]
4847
verbs: ["get", "list", "watch"]

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/kubernetes-csi/external-resizer
33
go 1.24.6
44

55
require (
6-
github.com/container-storage-interface/spec v1.11.0
6+
github.com/container-storage-interface/spec v1.12.0
77
github.com/google/go-cmp v0.7.0
88
github.com/kubernetes-csi/csi-lib-utils v0.23.0
99
google.golang.org/grpc v1.72.1

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK3
1212
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
1313
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
1414
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
15-
github.com/container-storage-interface/spec v1.11.0 h1:H/YKTOeUZwHtyPOr9raR+HgFmGluGCklulxDYxSdVNM=
16-
github.com/container-storage-interface/spec v1.11.0/go.mod h1:DtUvaQszPml1YJfIK7c00mlv6/g4wNMLanLgiUbKFRI=
15+
github.com/container-storage-interface/spec v1.12.0 h1:zrFOEqpR5AghNaaDG4qyedwPBqU2fU0dWjLQMP/azK0=
16+
github.com/container-storage-interface/spec v1.12.0/go.mod h1:txsm+MA2B2WDa5kW69jNbqPnvTtfvZma7T/zsAZ9qX8=
1717
github.com/coreos/go-semver v0.3.1 h1:yi21YpKnrx1gt5R+la8n5WgS0kCrsPp33dmEyHReZr4=
1818
github.com/coreos/go-semver v0.3.1/go.mod h1:irMmmIw/7yzSRPWryHsK7EYSg09caPQL03VsM8rvUec=
1919
github.com/coreos/go-systemd/v22 v22.5.0 h1:RrqgGjYQKalulkV8NGVIfkXQf6YYmOyiJKk8iXXhfZs=

pkg/features/features.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@ limitations under the License.
1717
package features
1818

1919
import (
20+
"slices"
21+
22+
"k8s.io/apimachinery/pkg/api/errors"
23+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2024
utilfeature "k8s.io/apiserver/pkg/util/feature"
25+
"k8s.io/client-go/discovery"
2126
"k8s.io/component-base/featuregate"
2227
)
2328

@@ -59,3 +64,21 @@ var defaultResizerFeatureGates = map[featuregate.Feature]featuregate.FeatureSpec
5964
VolumeAttributesClass: {Default: true, PreRelease: featuregate.GA},
6065
ReleaseLeaderElectionOnExit: {Default: false, PreRelease: featuregate.Alpha},
6166
}
67+
68+
// IsVolumeAttributesClassV1Enabled checks if the VolumeAttributesClass v1 API is enabled.
69+
func IsVolumeAttributesClassV1Enabled(d discovery.DiscoveryInterface) (bool, error) {
70+
return resourceExists(d, "storage.k8s.io/v1", "VolumeAttributesClass")
71+
}
72+
73+
func resourceExists(d discovery.DiscoveryInterface, groupVersion, kind string) (bool, error) {
74+
res, err := d.ServerResourcesForGroupVersion(groupVersion)
75+
if err != nil {
76+
if errors.IsNotFound(err) {
77+
return false, nil
78+
}
79+
return false, err
80+
}
81+
return slices.ContainsFunc(res.APIResources, func(r metav1.APIResource) bool {
82+
return r.Kind == kind
83+
}), nil
84+
}

0 commit comments

Comments
 (0)