Skip to content

Commit 9e30bb0

Browse files
authored
Merge pull request #1194 from yati1998/feature-gate
include feature gate in snapshotter
2 parents d37087c + 85b60dd commit 9e30bb0

32 files changed

+2851
-13
lines changed

cmd/csi-snapshotter/main.go

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3232
"k8s.io/apimachinery/pkg/labels"
3333
"k8s.io/apimachinery/pkg/runtime"
34+
utilfeature "k8s.io/apiserver/pkg/util/feature"
3435
coreinformers "k8s.io/client-go/informers"
3536
"k8s.io/client-go/kubernetes"
3637
"k8s.io/client-go/kubernetes/scheme"
@@ -44,8 +45,10 @@ import (
4445
"github.com/kubernetes-csi/csi-lib-utils/leaderelection"
4546
"github.com/kubernetes-csi/csi-lib-utils/metrics"
4647
csirpc "github.com/kubernetes-csi/csi-lib-utils/rpc"
48+
"github.com/kubernetes-csi/external-snapshotter/v8/pkg/features"
4749
controller "github.com/kubernetes-csi/external-snapshotter/v8/pkg/sidecar-controller"
4850
"github.com/kubernetes-csi/external-snapshotter/v8/pkg/snapshotter"
51+
utilflag "k8s.io/component-base/cli/flag"
4952

5053
clientset "github.com/kubernetes-csi/external-snapshotter/client/v8/clientset/versioned"
5154
snapshotscheme "github.com/kubernetes-csi/external-snapshotter/client/v8/clientset/versioned/scheme"
@@ -80,16 +83,15 @@ var (
8083
kubeAPIQPS = flag.Float64("kube-api-qps", 5, "QPS to use while communicating with the kubernetes apiserver. Defaults to 5.0.")
8184
kubeAPIBurst = flag.Int("kube-api-burst", 10, "Burst to use while communicating with the kubernetes apiserver. Defaults to 10.")
8285

83-
metricsAddress = flag.String("metrics-address", "", "(deprecated) The TCP network address where the prometheus metrics endpoint will listen (example: `:8080`). The default is empty string, which means metrics endpoint is disabled. Only one of `--metrics-address` and `--http-endpoint` can be set.")
84-
httpEndpoint = flag.String("http-endpoint", "", "The TCP network address where the HTTP server for diagnostics, including metrics and leader election health check, will listen (example: `:8080`). The default is empty string, which means the server is disabled. Only one of `--metrics-address` and `--http-endpoint` can be set.")
85-
metricsPath = flag.String("metrics-path", "/metrics", "The HTTP path where prometheus metrics will be exposed. Default is `/metrics`.")
86-
retryIntervalStart = flag.Duration("retry-interval-start", time.Second, "Initial retry interval of failed volume snapshot creation or deletion. It doubles with each failure, up to retry-interval-max. Default is 1 second.")
87-
retryIntervalMax = flag.Duration("retry-interval-max", 5*time.Minute, "Maximum retry interval of failed volume snapshot creation or deletion. Default is 5 minutes.")
88-
enableNodeDeployment = flag.Bool("node-deployment", false, "Enables deploying the sidecar controller together with a CSI driver on nodes to manage snapshots for node-local volumes.")
89-
enableVolumeGroupSnapshots = flag.Bool("enable-volume-group-snapshots", false, "Enables the volume group snapshot feature, allowing the user to create a snapshot of a group of volumes.")
90-
86+
metricsAddress = flag.String("metrics-address", "", "(deprecated) The TCP network address where the prometheus metrics endpoint will listen (example: `:8080`). The default is empty string, which means metrics endpoint is disabled. Only one of `--metrics-address` and `--http-endpoint` can be set.")
87+
httpEndpoint = flag.String("http-endpoint", "", "The TCP network address where the HTTP server for diagnostics, including metrics and leader election health check, will listen (example: `:8080`). The default is empty string, which means the server is disabled. Only one of `--metrics-address` and `--http-endpoint` can be set.")
88+
metricsPath = flag.String("metrics-path", "/metrics", "The HTTP path where prometheus metrics will be exposed. Default is `/metrics`.")
89+
retryIntervalStart = flag.Duration("retry-interval-start", time.Second, "Initial retry interval of failed volume snapshot creation or deletion. It doubles with each failure, up to retry-interval-max. Default is 1 second.")
90+
retryIntervalMax = flag.Duration("retry-interval-max", 5*time.Minute, "Maximum retry interval of failed volume snapshot creation or deletion. Default is 5 minutes.")
91+
enableNodeDeployment = flag.Bool("node-deployment", false, "Enables deploying the sidecar controller together with a CSI driver on nodes to manage snapshots for node-local volumes.")
9192
groupSnapshotNamePrefix = flag.String("groupsnapshot-name-prefix", "groupsnapshot", "Prefix to apply to the name of a created group snapshot")
9293
groupSnapshotNameUUIDLength = flag.Int("groupsnapshot-name-uuid-length", -1, "Length in characters for the generated uuid of a created group snapshot. Defaults behavior is to NOT truncate.")
94+
featureGates map[string]bool
9395
)
9496

9597
var (
@@ -98,10 +100,17 @@ var (
98100
)
99101

100102
func main() {
103+
flag.Var(utilflag.NewMapStringBool(&featureGates), "feature-gates", "Comma-seprated list of key=value pairs that describe feature gates for alpha/experimental features. "+
104+
"Options are:\n"+strings.Join(utilfeature.DefaultFeatureGate.KnownFeatures(), "\n"))
105+
101106
klog.InitFlags(nil)
102107
flag.Set("logtostderr", "true")
103108
flag.Parse()
104109

110+
if err := utilfeature.DefaultMutableFeatureGate.SetFromMap(featureGates); err != nil {
111+
klog.Fatal("Error while parsing feature gates: ", err)
112+
}
113+
105114
if *showVersion {
106115
fmt.Println(os.Args[0], version)
107116
os.Exit(0)
@@ -234,7 +243,7 @@ func main() {
234243

235244
snapShotter := snapshotter.NewSnapshotter(csiConn)
236245
var groupSnapshotter group_snapshotter.GroupSnapshotter
237-
if *enableVolumeGroupSnapshots {
246+
if utilfeature.DefaultFeatureGate.Enabled(features.VolumeGroupSnapshot) {
238247
tctx, cancel = context.WithTimeout(ctx, *csiTimeout)
239248
defer cancel()
240249
supportsCreateVolumeGroupSnapshot, err := supportsGroupControllerCreateVolumeGroupSnapshot(tctx, csiConn)
@@ -266,7 +275,7 @@ func main() {
266275
*groupSnapshotNameUUIDLength,
267276
*extraCreateMetadata,
268277
workqueue.NewItemExponentialFailureRateLimiter(*retryIntervalStart, *retryIntervalMax),
269-
*enableVolumeGroupSnapshots,
278+
utilfeature.DefaultFeatureGate.Enabled(features.VolumeGroupSnapshot),
270279
snapshotContentfactory.Groupsnapshot().V1alpha1().VolumeGroupSnapshotContents(),
271280
snapshotContentfactory.Groupsnapshot().V1alpha1().VolumeGroupSnapshotClasses(),
272281
workqueue.NewItemExponentialFailureRateLimiter(*retryIntervalStart, *retryIntervalMax),

cmd/snapshot-controller/main.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"net/http"
2626
"os"
2727
"os/signal"
28+
"strings"
2829
"sync"
2930
"time"
3031

@@ -43,12 +44,15 @@ import (
4344

4445
"github.com/kubernetes-csi/csi-lib-utils/leaderelection"
4546
controller "github.com/kubernetes-csi/external-snapshotter/v8/pkg/common-controller"
47+
"github.com/kubernetes-csi/external-snapshotter/v8/pkg/features"
4648
"github.com/kubernetes-csi/external-snapshotter/v8/pkg/metrics"
4749

4850
clientset "github.com/kubernetes-csi/external-snapshotter/client/v8/clientset/versioned"
4951
snapshotscheme "github.com/kubernetes-csi/external-snapshotter/client/v8/clientset/versioned/scheme"
5052
informers "github.com/kubernetes-csi/external-snapshotter/client/v8/informers/externalversions"
53+
utilfeature "k8s.io/apiserver/pkg/util/feature"
5154
coreinformers "k8s.io/client-go/informers"
55+
utilflag "k8s.io/component-base/cli/flag"
5256
)
5357

5458
// Command line flags
@@ -73,9 +77,9 @@ var (
7377
retryIntervalMax = flag.Duration("retry-interval-max", 5*time.Minute, "Maximum retry interval of failed volume snapshot creation or deletion. Default is 5 minutes.")
7478
enableDistributedSnapshotting = flag.Bool("enable-distributed-snapshotting", false, "Enables each node to handle snapshotting for the local volumes created on that node")
7579
preventVolumeModeConversion = flag.Bool("prevent-volume-mode-conversion", true, "Prevents an unauthorised user from modifying the volume mode when creating a PVC from an existing VolumeSnapshot.")
76-
enableVolumeGroupSnapshots = flag.Bool("enable-volume-group-snapshots", false, "Enables the volume group snapshot feature, allowing the user to create a snapshot of a group of volumes.")
7780

7881
retryCRDIntervalMax = flag.Duration("retry-crd-interval-max", 30*time.Second, "Maximum time to wait for CRDs to appear. The default is 30 seconds.")
82+
featureGates map[string]bool
7983
)
8084

8185
var version = "unknown"
@@ -147,10 +151,17 @@ func ensureCustomResourceDefinitionsExist(client *clientset.Clientset, enableVol
147151
}
148152

149153
func main() {
154+
flag.Var(utilflag.NewMapStringBool(&featureGates), "feature-gates", "Comma-seprated list of key=value pairs that describe feature gates for alpha/experimental features. "+
155+
"Options are:\n"+strings.Join(utilfeature.DefaultFeatureGate.KnownFeatures(), "\n"))
156+
150157
klog.InitFlags(nil)
151158
flag.Set("logtostderr", "true")
152159
flag.Parse()
153160

161+
if err := utilfeature.DefaultMutableFeatureGate.SetFromMap(featureGates); err != nil {
162+
klog.Fatal("Error while parsing feature gates: ", err)
163+
}
164+
154165
if *showVersion {
155166
fmt.Println(os.Args[0], version)
156167
os.Exit(0)
@@ -228,10 +239,10 @@ func main() {
228239
workqueue.NewItemExponentialFailureRateLimiter(*retryIntervalStart, *retryIntervalMax),
229240
*enableDistributedSnapshotting,
230241
*preventVolumeModeConversion,
231-
*enableVolumeGroupSnapshots,
242+
utilfeature.DefaultFeatureGate.Enabled(features.VolumeGroupSnapshot),
232243
)
233244

234-
if err := ensureCustomResourceDefinitionsExist(snapClient, *enableVolumeGroupSnapshots); err != nil {
245+
if err := ensureCustomResourceDefinitionsExist(snapClient, utilfeature.DefaultFeatureGate.Enabled(features.VolumeGroupSnapshot)); err != nil {
235246
klog.Errorf("Exiting due to failure to ensure CRDs exist during startup: %+v", err)
236247
os.Exit(1)
237248
}

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ require (
2020
google.golang.org/protobuf v1.35.1
2121
k8s.io/api v0.31.0
2222
k8s.io/apimachinery v0.31.0
23+
k8s.io/apiserver v0.31.0
2324
k8s.io/client-go v0.31.0
2425
k8s.io/component-base v0.31.0
2526
k8s.io/component-helpers v0.31.0

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,8 @@ k8s.io/api v0.31.0 h1:b9LiSjR2ym/SzTOlfMHm1tr7/21aD7fSkqgD/CVJBCo=
197197
k8s.io/api v0.31.0/go.mod h1:0YiFF+JfFxMM6+1hQei8FY8M7s1Mth+z/q7eF1aJkTE=
198198
k8s.io/apimachinery v0.31.0 h1:m9jOiSr3FoSSL5WO9bjm1n6B9KROYYgNZOb4tyZ1lBc=
199199
k8s.io/apimachinery v0.31.0/go.mod h1:rsPdaZJfTfLsNJSQzNHQvYoTmxhoOEofxtOsF3rtsMo=
200+
k8s.io/apiserver v0.31.0 h1:p+2dgJjy+bk+B1Csz+mc2wl5gHwvNkC9QJV+w55LVrY=
201+
k8s.io/apiserver v0.31.0/go.mod h1:KI9ox5Yu902iBnnyMmy7ajonhKnkeZYJhTZ/YI+WEMk=
200202
k8s.io/client-go v0.31.0 h1:QqEJzNjbN2Yv1H79SsS+SWnXkBgVu4Pj3CJQgbx0gI8=
201203
k8s.io/client-go v0.31.0/go.mod h1:Y9wvC76g4fLjmU0BA+rV+h2cncoadjvjjkkIGoTLcGU=
202204
k8s.io/component-base v0.31.0 h1:/KIzGM5EvPNQcYgwq5NwoQBaOlVFrghoVGr8lG6vNRs=

pkg/features/features.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
Copyright 2024 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package features
18+
19+
import (
20+
"k8s.io/apiserver/pkg/util/feature"
21+
"k8s.io/component-base/featuregate"
22+
)
23+
24+
const (
25+
// Enable usage of volume group snapshot
26+
VolumeGroupSnapshot featuregate.Feature = "CSIVolumeGroupSnapshot"
27+
)
28+
29+
func init() {
30+
feature.DefaultMutableFeatureGate.Add(defaultKubernetesFeatureGates)
31+
}
32+
33+
// defaultKubernetesFeatureGates consists of all known feature keys specific to external-snapshotter.
34+
// To add a new feature, define a key for it above and add it here.
35+
var defaultKubernetesFeatureGates = map[featuregate.Feature]featuregate.FeatureSpec{
36+
VolumeGroupSnapshot: {Default: false, PreRelease: featuregate.Beta},
37+
}

vendor/github.com/prometheus/client_golang/prometheus/collectors/collectors.go

Lines changed: 40 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/prometheus/client_golang/prometheus/collectors/dbstats_collector.go

Lines changed: 119 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)