Skip to content

Commit

Permalink
include feature gate in snapshotter
Browse files Browse the repository at this point in the history
this commit includes feature gate method
to enable the volumeGroupSnapshot

Signed-off-by: yati1998 <[email protected]>
  • Loading branch information
yati1998 committed Nov 18, 2024
1 parent 3aefaf5 commit d916fc4
Show file tree
Hide file tree
Showing 32 changed files with 2,845 additions and 4 deletions.
15 changes: 13 additions & 2 deletions cmd/csi-snapshotter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
utilfeature "k8s.io/apiserver/pkg/util/feature"
coreinformers "k8s.io/client-go/informers"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/kubernetes/scheme"
Expand All @@ -44,8 +45,10 @@ import (
"github.com/kubernetes-csi/csi-lib-utils/leaderelection"
"github.com/kubernetes-csi/csi-lib-utils/metrics"
csirpc "github.com/kubernetes-csi/csi-lib-utils/rpc"
"github.com/kubernetes-csi/external-snapshotter/v8/pkg/features"
controller "github.com/kubernetes-csi/external-snapshotter/v8/pkg/sidecar-controller"
"github.com/kubernetes-csi/external-snapshotter/v8/pkg/snapshotter"
utilflag "k8s.io/component-base/cli/flag"

clientset "github.com/kubernetes-csi/external-snapshotter/client/v8/clientset/versioned"
snapshotscheme "github.com/kubernetes-csi/external-snapshotter/client/v8/clientset/versioned/scheme"
Expand Down Expand Up @@ -90,6 +93,7 @@ var (

groupSnapshotNamePrefix = flag.String("groupsnapshot-name-prefix", "groupsnapshot", "Prefix to apply to the name of a created group snapshot")
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.")
featureGates map[string]bool
)

var (
Expand All @@ -98,10 +102,17 @@ var (
)

func main() {
flag.Var(utilflag.NewMapStringBool(&featureGates), "feature-gates", "Comma-seprated list of key=value pairs that describe feature gates for alpha/experimental features. "+
"Options are:\n"+strings.Join(utilfeature.DefaultFeatureGate.KnownFeatures(), "\n"))

klog.InitFlags(nil)
flag.Set("logtostderr", "true")
flag.Parse()

if err := utilfeature.DefaultMutableFeatureGate.SetFromMap(featureGates); err != nil {
klog.Fatal("Error while parsing feature gates: ", err)
}

if *showVersion {
fmt.Println(os.Args[0], version)
os.Exit(0)
Expand Down Expand Up @@ -234,7 +245,7 @@ func main() {

snapShotter := snapshotter.NewSnapshotter(csiConn)
var groupSnapshotter group_snapshotter.GroupSnapshotter
if *enableVolumeGroupSnapshots {
if utilfeature.DefaultFeatureGate.Enabled(features.VolumeGroupSnapshot) {
tctx, cancel = context.WithTimeout(ctx, *csiTimeout)
defer cancel()
supportsCreateVolumeGroupSnapshot, err := supportsGroupControllerCreateVolumeGroupSnapshot(tctx, csiConn)
Expand Down Expand Up @@ -266,7 +277,7 @@ func main() {
*groupSnapshotNameUUIDLength,
*extraCreateMetadata,
workqueue.NewItemExponentialFailureRateLimiter(*retryIntervalStart, *retryIntervalMax),
*enableVolumeGroupSnapshots,
utilfeature.DefaultFeatureGate.Enabled(features.VolumeGroupSnapshot),
snapshotContentfactory.Groupsnapshot().V1alpha1().VolumeGroupSnapshotContents(),
snapshotContentfactory.Groupsnapshot().V1alpha1().VolumeGroupSnapshotClasses(),
workqueue.NewItemExponentialFailureRateLimiter(*retryIntervalStart, *retryIntervalMax),
Expand Down
16 changes: 14 additions & 2 deletions cmd/snapshot-controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"net/http"
"os"
"os/signal"
"strings"
"sync"
"time"

Expand All @@ -43,12 +44,15 @@ import (

"github.com/kubernetes-csi/csi-lib-utils/leaderelection"
controller "github.com/kubernetes-csi/external-snapshotter/v8/pkg/common-controller"
"github.com/kubernetes-csi/external-snapshotter/v8/pkg/features"
"github.com/kubernetes-csi/external-snapshotter/v8/pkg/metrics"

clientset "github.com/kubernetes-csi/external-snapshotter/client/v8/clientset/versioned"
snapshotscheme "github.com/kubernetes-csi/external-snapshotter/client/v8/clientset/versioned/scheme"
informers "github.com/kubernetes-csi/external-snapshotter/client/v8/informers/externalversions"
utilfeature "k8s.io/apiserver/pkg/util/feature"
coreinformers "k8s.io/client-go/informers"
utilflag "k8s.io/component-base/cli/flag"
)

// Command line flags
Expand Down Expand Up @@ -76,6 +80,7 @@ var (
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.")

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

var version = "unknown"
Expand Down Expand Up @@ -147,10 +152,17 @@ func ensureCustomResourceDefinitionsExist(client *clientset.Clientset, enableVol
}

func main() {
flag.Var(utilflag.NewMapStringBool(&featureGates), "feature-gates", "Comma-seprated list of key=value pairs that describe feature gates for alpha/experimental features. "+
"Options are:\n"+strings.Join(utilfeature.DefaultFeatureGate.KnownFeatures(), "\n"))

klog.InitFlags(nil)
flag.Set("logtostderr", "true")
flag.Parse()

if err := utilfeature.DefaultMutableFeatureGate.SetFromMap(featureGates); err != nil {
klog.Fatal("Error while parsing feature gates: ", err)
}

if *showVersion {
fmt.Println(os.Args[0], version)
os.Exit(0)
Expand Down Expand Up @@ -228,10 +240,10 @@ func main() {
workqueue.NewItemExponentialFailureRateLimiter(*retryIntervalStart, *retryIntervalMax),
*enableDistributedSnapshotting,
*preventVolumeModeConversion,
*enableVolumeGroupSnapshots,
utilfeature.DefaultFeatureGate.Enabled(features.VolumeGroupSnapshot),
)

if err := ensureCustomResourceDefinitionsExist(snapClient, *enableVolumeGroupSnapshots); err != nil {
if err := ensureCustomResourceDefinitionsExist(snapClient, utilfeature.DefaultFeatureGate.Enabled(features.VolumeGroupSnapshot)); err != nil {
klog.Errorf("Exiting due to failure to ensure CRDs exist during startup: %+v", err)
os.Exit(1)
}
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ require (
google.golang.org/protobuf v1.35.1
k8s.io/api v0.31.0
k8s.io/apimachinery v0.31.0
k8s.io/apiserver v0.31.0
k8s.io/client-go v0.31.0
k8s.io/component-base v0.31.0
k8s.io/component-helpers v0.31.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ k8s.io/api v0.31.0 h1:b9LiSjR2ym/SzTOlfMHm1tr7/21aD7fSkqgD/CVJBCo=
k8s.io/api v0.31.0/go.mod h1:0YiFF+JfFxMM6+1hQei8FY8M7s1Mth+z/q7eF1aJkTE=
k8s.io/apimachinery v0.31.0 h1:m9jOiSr3FoSSL5WO9bjm1n6B9KROYYgNZOb4tyZ1lBc=
k8s.io/apimachinery v0.31.0/go.mod h1:rsPdaZJfTfLsNJSQzNHQvYoTmxhoOEofxtOsF3rtsMo=
k8s.io/apiserver v0.31.0 h1:p+2dgJjy+bk+B1Csz+mc2wl5gHwvNkC9QJV+w55LVrY=
k8s.io/apiserver v0.31.0/go.mod h1:KI9ox5Yu902iBnnyMmy7ajonhKnkeZYJhTZ/YI+WEMk=
k8s.io/client-go v0.31.0 h1:QqEJzNjbN2Yv1H79SsS+SWnXkBgVu4Pj3CJQgbx0gI8=
k8s.io/client-go v0.31.0/go.mod h1:Y9wvC76g4fLjmU0BA+rV+h2cncoadjvjjkkIGoTLcGU=
k8s.io/component-base v0.31.0 h1:/KIzGM5EvPNQcYgwq5NwoQBaOlVFrghoVGr8lG6vNRs=
Expand Down
37 changes: 37 additions & 0 deletions pkg/features/features.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
Copyright 2024 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package features

import (
"k8s.io/apiserver/pkg/util/feature"
"k8s.io/component-base/featuregate"
)

const (
// Enable usage of volume group snapshot
VolumeGroupSnapshot featuregate.Feature = "CSIVolumeGroupSnapshot"
)

func init() {
feature.DefaultMutableFeatureGate.Add(defaultKubernetesFeatureGates)
}

// defaultKubernetesFeatureGates consists of all known feature keys specific to external-snapshotter.
// To add a new feature, define a key for it above and add it here.
var defaultKubernetesFeatureGates = map[featuregate.Feature]featuregate.FeatureSpec{
VolumeGroupSnapshot: {Default: false, PreRelease: featuregate.Beta},
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d916fc4

Please sign in to comment.