Skip to content

Commit ec07c90

Browse files
committed
Use common flags for external snapshotter
1 parent 6f35782 commit ec07c90

File tree

2 files changed

+13
-23
lines changed

2 files changed

+13
-23
lines changed

cmd/csi-snapshotter/main.go

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import (
4242
"k8s.io/client-go/util/workqueue"
4343
klog "k8s.io/klog/v2"
4444

45+
libconfig "github.com/kubernetes-csi/csi-lib-utils/config"
4546
"github.com/container-storage-interface/spec/lib/go/csi"
4647
"github.com/kubernetes-csi/csi-lib-utils/connection"
4748
"github.com/kubernetes-csi/csi-lib-utils/leaderelection"
@@ -74,12 +75,9 @@ const (
7475

7576
// Command line flags
7677
var (
77-
kubeconfig = flag.String("kubeconfig", "", "Absolute path to the kubeconfig file. Required only when running out of cluster.")
78-
csiAddress = flag.String("csi-address", "/run/csi/socket", "Address of the CSI driver socket.")
7978
resyncPeriod = flag.Duration("resync-period", 15*time.Minute, "Resync interval of the controller. Default is 15 minutes")
8079
snapshotNamePrefix = flag.String("snapshot-name-prefix", "snapshot", "Prefix to apply to the name of a created snapshot")
8180
snapshotNameUUIDLength = flag.Int("snapshot-name-uuid-length", -1, "Length in characters for the generated uuid of a created snapshot. Defaults behavior is to NOT truncate.")
82-
showVersion = flag.Bool("version", false, "Show version.")
8381
threads = flag.Int("worker-threads", 10, "Number of worker threads.")
8482
csiTimeout = flag.Duration("timeout", defaultCSITimeout, "The timeout for any RPCs to the CSI driver. Default is 1 minute.")
8583
extraCreateMetadata = flag.Bool("extra-create-metadata", false, "If set, add snapshot metadata to plugin snapshot requests as parameters.")
@@ -90,12 +88,6 @@ var (
9088
leaderElectionRenewDeadline = flag.Duration("leader-election-renew-deadline", 10*time.Second, "Duration, in seconds, that the acting leader will retry refreshing leadership before giving up. Defaults to 10 seconds.")
9189
leaderElectionRetryPeriod = flag.Duration("leader-election-retry-period", 5*time.Second, "Duration, in seconds, the LeaderElector clients should wait between tries of actions. Defaults to 5 seconds.")
9290

93-
kubeAPIQPS = flag.Float64("kube-api-qps", 5, "QPS to use while communicating with the kubernetes apiserver. Defaults to 5.0.")
94-
kubeAPIBurst = flag.Int("kube-api-burst", 10, "Burst to use while communicating with the kubernetes apiserver. Defaults to 10.")
95-
96-
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.")
97-
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.")
98-
metricsPath = flag.String("metrics-path", "/metrics", "The HTTP path where prometheus metrics will be exposed. Default is `/metrics`.")
9991
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.")
10092
retryIntervalMax = flag.Duration("retry-interval-max", 5*time.Minute, "Maximum retry interval of failed volume snapshot creation or deletion. Default is 5 minutes.")
10193
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.")
@@ -119,6 +111,7 @@ func main() {
119111
logsapi.AddGoFlags(c, flag.CommandLine)
120112
logs.InitLogs()
121113
standardflags.AddAutomaxprocs(klog.Infof)
114+
standardflags.RegisterCommonFlags(flag.CommandLine)
122115
flag.Parse()
123116
if err := logsapi.ValidateAndApply(c, fg); err != nil {
124117
klog.ErrorS(err, "LoggingConfiguration is invalid")
@@ -129,7 +122,7 @@ func main() {
129122
klog.Fatal("Error while parsing feature gates: ", err)
130123
}
131124

132-
if *showVersion {
125+
if standardflags.Configuration.ShowVersion {
133126
fmt.Println(os.Args[0], version)
134127
os.Exit(0)
135128
}
@@ -142,15 +135,12 @@ func main() {
142135
}
143136

144137
// Create the client config. Use kubeconfig if given, otherwise assume in-cluster.
145-
config, err := buildConfig(*kubeconfig)
138+
config, err := libconfig.BuildConfig(standardflags.Configuration.KubeConfig, standardflags.Configuration)
146139
if err != nil {
147140
klog.Error(err.Error())
148141
os.Exit(1)
149142
}
150143

151-
config.QPS = (float32)(*kubeAPIQPS)
152-
config.Burst = *kubeAPIBurst
153-
154144
coreConfig := rest.CopyConfig(config)
155145
coreConfig.ContentType = runtime.ContentTypeProtobuf
156146
kubeClient, err := kubernetes.NewForConfig(coreConfig)
@@ -184,21 +174,21 @@ func main() {
184174
// Add Snapshot types to the default Kubernetes so events can be logged for them
185175
snapshotscheme.AddToScheme(scheme.Scheme)
186176

187-
if *metricsAddress != "" && *httpEndpoint != "" {
177+
if standardflags.Configuration.MetricsAddress != "" && standardflags.Configuration.HttpEndpoint != "" {
188178
klog.Error("only one of `--metrics-address` and `--http-endpoint` can be set.")
189179
os.Exit(1)
190180
}
191-
addr := *metricsAddress
181+
addr := standardflags.Configuration.MetricsAddress
192182
if addr == "" {
193-
addr = *httpEndpoint
183+
addr = standardflags.Configuration.HttpEndpoint
194184
}
195185

196186
// Connect to CSI.
197187
metricsManager := metrics.NewCSIMetricsManager("" /* driverName */)
198188
ctx := context.Background()
199189
csiConn, err := connection.Connect(
200190
ctx,
201-
*csiAddress,
191+
standardflags.Configuration.CSIAddress,
202192
metricsManager,
203193
connection.OnConnectionLoss(connection.ExitOnConnectionLoss()))
204194
if err != nil {
@@ -226,13 +216,13 @@ func main() {
226216
// Prepare http endpoint for metrics + leader election healthz
227217
mux := http.NewServeMux()
228218
if addr != "" {
229-
metricsManager.RegisterToServer(mux, *metricsPath)
219+
metricsManager.RegisterToServer(mux, standardflags.Configuration.MetricsPath)
230220
metricsManager.SetDriverName(driverName)
231221
go func() {
232222
klog.Infof("ServeMux listening at %q", addr)
233223
err := http.ListenAndServe(addr, mux)
234224
if err != nil {
235-
klog.Fatalf("Failed to start HTTP server at specified address (%q) and metrics path (%q): %s", addr, *metricsPath, err)
225+
klog.Fatalf("Failed to start HTTP server at specified address (%q) and metrics path (%q): %s", addr, standardflags.Configuration.MetricsPath, err)
236226
}
237227
}()
238228
}
@@ -261,7 +251,7 @@ func main() {
261251
os.Exit(1)
262252
}
263253

264-
klog.V(2).Infof("Start NewCSISnapshotSideCarController with snapshotter [%s] kubeconfig [%s] csiTimeout [%+v] csiAddress [%s] resyncPeriod [%+v] snapshotNamePrefix [%s] snapshotNameUUIDLength [%d]", driverName, *kubeconfig, *csiTimeout, *csiAddress, *resyncPeriod, *snapshotNamePrefix, snapshotNameUUIDLength)
254+
klog.V(2).Infof("Start NewCSISnapshotSideCarController with snapshotter [%s] kubeconfig [%s] csiTimeout [%+v] csiAddress [%s] resyncPeriod [%+v] snapshotNamePrefix [%s] snapshotNameUUIDLength [%d]", driverName, standardflags.Configuration.KubeConfig, *csiTimeout, standardflags.Configuration.CSIAddress, *resyncPeriod, *snapshotNamePrefix, snapshotNameUUIDLength)
265255

266256
snapShotter := snapshotter.NewSnapshotter(csiConn)
267257
var groupSnapshotter group_snapshotter.GroupSnapshotter
@@ -365,7 +355,7 @@ func main() {
365355
klog.Fatalf("failed to create leaderelection client: %v", err)
366356
}
367357
le := leaderelection.NewLeaderElection(leClientset, lockName, run)
368-
if *httpEndpoint != "" {
358+
if standardflags.Configuration.HttpEndpoint != "" {
369359
le.PrepareHealthCheck(mux, leaderelection.DefaultHealthCheckTimeout)
370360
}
371361

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/kubernetes-csi/external-snapshotter/v8
22

3-
go 1.24.6
3+
go 1.24.11
44

55
require (
66
github.com/container-storage-interface/spec v1.12.0

0 commit comments

Comments
 (0)