Skip to content

Commit a9bc3ce

Browse files
committed
Separate attacher flags into attacher only flags and global shared flags
1 parent d87f235 commit a9bc3ce

File tree

2 files changed

+58
-19
lines changed

2 files changed

+58
-19
lines changed

cmd/csi-attacher/config/flags.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package config
2+
3+
import (
4+
"flag"
5+
"time"
6+
)
7+
8+
type AttacherConfiguration struct {
9+
MaxEntries int
10+
ReconcileSync time.Duration
11+
MaxGRPCLogLength int
12+
WorkerThreads int
13+
DefaultFSType string
14+
Timeout time.Duration
15+
RetryIntervalStart time.Duration
16+
RetryIntervalMax time.Duration
17+
}
18+
19+
func registerAttacherFlags(flags *flag.FlagSet, configuration *AttacherConfiguration, prefix string) {
20+
flag.IntVar(&configuration.MaxEntries, prefix+"max-entries", 0, "Max entries per each page in volume lister call, 0 means no limit.")
21+
flag.DurationVar(&configuration.ReconcileSync, prefix+"reconcile-sync", 1*time.Minute, "Resync interval of the VolumeAttachment reconciler.")
22+
flag.IntVar(&configuration.MaxGRPCLogLength, prefix+"max-grpc-log-length", -1, "The maximum amount of characters logged for every grpc responses. Defaults to no limit")
23+
flags.IntVar(&configuration.WorkerThreads, prefix+"worker-threads", 10, "Number of worker threads per sidecar")
24+
flags.StringVar(&configuration.DefaultFSType, prefix+"default-fstype", "", "The default filesystem type of the volume to use.")
25+
flags.DurationVar(&configuration.Timeout, prefix+"timeout", 15*time.Second, "Timeout for waiting for attaching or detaching the volume.")
26+
flags.DurationVar(&configuration.RetryIntervalStart, prefix+"retry-interval-start", time.Second, "Initial retry interval of failed create volume or deletion. It doubles with each failure, up to retry-interval-max.")
27+
flags.DurationVar(&configuration.RetryIntervalMax, prefix+"retry-interval-max", 5*time.Minute, "Maximum retry interval of failed create volume or deletion.")
28+
}
29+
30+
// RegisterAttacherFlags registers attacher only flags.
31+
func RegisterAttacherFlags(flags *flag.FlagSet, configuration *AttacherConfiguration) {
32+
registerAttacherFlags(flags, configuration, "")
33+
}
34+
35+
// RegisterAttacherFlagsWithPrefix registers attacher only flags with the prefix attacher-.
36+
func RegisterAttacherFlagsWithPrefix(flags *flag.FlagSet, configuration *AttacherConfiguration) {
37+
registerAttacherFlags(flags, configuration, "attacher-")
38+
}

cmd/csi-attacher/main.go

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import (
4646
"github.com/kubernetes-csi/csi-lib-utils/metrics"
4747
"github.com/kubernetes-csi/csi-lib-utils/rpc"
4848
"github.com/kubernetes-csi/csi-lib-utils/standardflags"
49+
"github.com/kubernetes-csi/external-attacher/cmd/csi-attacher/config"
4950
"github.com/kubernetes-csi/external-attacher/pkg/attacher"
5051
"github.com/kubernetes-csi/external-attacher/pkg/controller"
5152
"google.golang.org/grpc"
@@ -59,49 +60,49 @@ const (
5960

6061
// Command line flags
6162
var (
62-
kubeconfig = flag.String("kubeconfig", "", "Absolute path to the kubeconfig file. Required only when running out of cluster.")
63-
resync = flag.Duration("resync", 10*time.Minute, "Resync interval of the controller.")
64-
csiAddress = flag.String("csi-address", "/run/csi/socket", "Address of the CSI driver socket.")
65-
showVersion = flag.Bool("version", false, "Show version.")
66-
timeout = flag.Duration("timeout", 15*time.Second, "Timeout for waiting for attaching or detaching the volume.")
67-
workerThreads = flag.Uint("worker-threads", 10, "Number of attacher worker threads")
68-
maxEntries = flag.Int("max-entries", 0, "Max entries per each page in volume lister call, 0 means no limit.")
69-
70-
retryIntervalStart = flag.Duration("retry-interval-start", time.Second, "Initial retry interval of failed create volume or deletion. It doubles with each failure, up to retry-interval-max.")
71-
retryIntervalMax = flag.Duration("retry-interval-max", 5*time.Minute, "Maximum retry interval of failed create volume or deletion.")
63+
kubeconfig = flag.String("kubeconfig", "", "Absolute path to the kubeconfig file. Required only when running out of cluster.")
64+
resync = flag.Duration("resync", 10*time.Minute, "Resync interval of the controller.")
65+
csiAddress = flag.String("csi-address", "/run/csi/socket", "Address of the CSI driver socket.")
66+
showVersion = flag.Bool("version", false, "Show version.")
7267

7368
enableLeaderElection = flag.Bool("leader-election", false, "Enable leader election.")
7469
leaderElectionNamespace = flag.String("leader-election-namespace", "", "Namespace where the leader election resource lives. Defaults to the pod namespace if not set.")
7570
leaderElectionLeaseDuration = flag.Duration("leader-election-lease-duration", 15*time.Second, "Duration, in seconds, that non-leader candidates will wait to force acquire leadership. Defaults to 15 seconds.")
7671
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.")
7772
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.")
7873

79-
defaultFSType = flag.String("default-fstype", "", "The default filesystem type of the volume to publish. Defaults to empty string")
80-
81-
reconcileSync = flag.Duration("reconcile-sync", 1*time.Minute, "Resync interval of the VolumeAttachment reconciler.")
82-
8374
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.")
8475
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.")
8576
metricsPath = flag.String("metrics-path", "/metrics", "The HTTP path where prometheus metrics will be exposed. Default is `/metrics`.")
8677

8778
kubeAPIQPS = flag.Float64("kube-api-qps", 5, "QPS to use while communicating with the kubernetes apiserver. Defaults to 5.0.")
8879
kubeAPIBurst = flag.Int("kube-api-burst", 10, "Burst to use while communicating with the kubernetes apiserver. Defaults to 10.")
89-
90-
maxGRPCLogLength = flag.Int("max-grpc-log-length", -1, "The maximum amount of characters logged for every grpc responses. Defaults to no limit")
9180
)
9281

93-
var (
94-
version = "unknown"
95-
)
82+
var version = "unknown"
83+
84+
var attacherConfiguration = config.AttacherConfiguration{}
9685

9786
func main() {
9887
fg := featuregate.NewFeatureGate()
9988
logsapi.AddFeatureGates(fg)
10089
c := logsapi.NewLoggingConfiguration()
10190
logsapi.AddGoFlags(c, flag.CommandLine)
91+
config.RegisterAttacherFlags(flag.CommandLine, &attacherConfiguration)
10292
logs.InitLogs()
10393
standardflags.AddAutomaxprocs(klog.Infof)
10494
flag.Parse()
95+
96+
// Make AttacherConfiguration values visible as local variables.
97+
defaultFSType := &attacherConfiguration.DefaultFSType
98+
workerThreads := &attacherConfiguration.WorkerThreads
99+
timeout := &attacherConfiguration.Timeout
100+
reconcileSync := &attacherConfiguration.ReconcileSync
101+
maxGRPCLogLength := &attacherConfiguration.MaxGRPCLogLength
102+
maxEntries := &attacherConfiguration.MaxEntries
103+
retryIntervalStart := &attacherConfiguration.RetryIntervalStart
104+
retryIntervalMax := &attacherConfiguration.RetryIntervalMax
105+
105106
logger := klog.Background()
106107
if err := logsapi.ValidateAndApply(c, fg); err != nil {
107108
logger.Error(err, "LoggingConfiguration is invalid")

0 commit comments

Comments
 (0)