Skip to content

Commit c745c0f

Browse files
authored
Merge pull request kubernetes-csi#173 from jsafrane/remove-deprecated-flags
2.0 prep: Remove deprecated flags
2 parents f622643 + b35db9d commit c745c0f

File tree

31 files changed

+49
-2289
lines changed

31 files changed

+49
-2289
lines changed

Gopkg.lock

+1-22
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

-10
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,6 @@ Note that the external-attacher does not scale with more replicas. Only one exte
6666
* `--retry-interval-max`: The exponential backoff maximum value. See [CSI error and timeout handling](#csi-error-and-timeout-handling) for details. 5 minutes is used by default.
6767

6868
#### Other recognized arguments
69-
70-
* `--dummy`: Runs the external-attacher in dummy mode, i.e. without any CSI driver. All volumes are immediately reported as attached / detached as controller-manager requires. This option can be used for debugging of other CSI components such as Kubernetes Attach / Detach controller.
71-
7269
* `--kubeconfig <path>`: Path to Kubernetes client configuration that the external-attacher uses to connect to Kubernetes API server. When omitted, default token provided by Kubernetes will be used. This option is useful only when the external-attacher does not run as a Kubernetes pod, e.g. for debugging.
7370

7471
* `--resync <duration>`: Internal resync interval when the external-attacher re-evaluates all existing `VolumeAttachment` instances and tries to fulfill them, i.e. attach / detach corresponding volumes. It does not affect re-tries of failed CSI calls! It should be used only when there is a bug in Kubernetes watch logic.
@@ -77,13 +74,6 @@ Note that the external-attacher does not scale with more replicas. Only one exte
7774

7875
* All glog / klog arguments are supported, such as `-v <log level>` or `-alsologtostderr`.
7976

80-
#### Deprecated arguments
81-
* `--connection-timeout <duration>`: This option was used to limit establishing connection to CSI driver. Currently, the option does not have any effect and the external-attacher tries to connect to CSI driver socket indefinitely. It is recommended to run ReadinessProbe on the driver to ensure that the driver comes up in reasonable time.
82-
83-
* `--leader-election-type`: This option was used to choose which leader election resource type to use. Currently, the option defaults to `configmaps`, but will be removed in the future to only support `leases` based leader election.
84-
85-
* `--leader-election-identity <id>`: This option is deprecated and has no effect since external-attacher will now use the pod hostname as the leader election identity
86-
8777
### CSI error and timeout handling
8878
The external-attacher invokes all gRPC calls to CSI driver with timeout provided by `--timeout` command line argument (15 seconds by default).
8979

cmd/csi-attacher/main.go

+47-82
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,10 @@ import (
2828
"k8s.io/client-go/rest"
2929
"k8s.io/client-go/tools/clientcmd"
3030
"k8s.io/client-go/util/workqueue"
31-
csiinformers "k8s.io/csi-api/pkg/client/informers/externalversions"
3231
"k8s.io/klog"
3332

3433
"github.com/container-storage-interface/spec/lib/go/csi"
3534
"github.com/kubernetes-csi/csi-lib-utils/connection"
36-
"github.com/kubernetes-csi/csi-lib-utils/deprecatedflags"
3735
"github.com/kubernetes-csi/csi-lib-utils/leaderelection"
3836
"github.com/kubernetes-csi/csi-lib-utils/rpc"
3937
"github.com/kubernetes-csi/external-attacher/pkg/attacher"
@@ -48,30 +46,23 @@ const (
4846
// Default timeout of short CSI calls like GetPluginInfo
4947
csiTimeout = time.Second
5048

51-
// Name of CSI plugin for dummy operation
52-
dummyAttacherName = "csi/dummy"
53-
5449
leaderElectionTypeLeases = "leases"
5550
leaderElectionTypeConfigMaps = "configmaps"
5651
)
5752

5853
// Command line flags
5954
var (
60-
kubeconfig = flag.String("kubeconfig", "", "Absolute path to the kubeconfig file. Required only when running out of cluster.")
61-
resync = flag.Duration("resync", 10*time.Minute, "Resync interval of the controller.")
62-
connectionTimeout = flag.Duration("connection-timeout", 0, "This option is deprecated.")
63-
csiAddress = flag.String("csi-address", "/run/csi/socket", "Address of the CSI driver socket.")
64-
dummy = flag.Bool("dummy", false, "Run in dummy mode, i.e. not connecting to CSI driver and marking everything as attached. Expected CSI driver name is \"csi/dummy\".")
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.")
55+
kubeconfig = flag.String("kubeconfig", "", "Absolute path to the kubeconfig file. Required only when running out of cluster.")
56+
resync = flag.Duration("resync", 10*time.Minute, "Resync interval of the controller.")
57+
csiAddress = flag.String("csi-address", "/run/csi/socket", "Address of the CSI driver socket.")
58+
showVersion = flag.Bool("version", false, "Show version.")
59+
timeout = flag.Duration("timeout", 15*time.Second, "Timeout for waiting for attaching or detaching the volume.")
6760

6861
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.")
6962
retryIntervalMax = flag.Duration("retry-interval-max", 5*time.Minute, "Maximum retry interval of failed create volume or deletion.")
7063

7164
enableLeaderElection = flag.Bool("leader-election", false, "Enable leader election.")
72-
leaderElectionType = flag.String("leader-election-type", leaderElectionTypeConfigMaps, "the type of leader election, options are 'configmaps' (default) or 'leases' (recommended). The 'configmaps' option is deprecated in favor of 'leases'.")
7365
leaderElectionNamespace = flag.String("leader-election-namespace", "", "Namespace where the leader election resource lives. Defaults to the pod namespace if not set.")
74-
_ = deprecatedflags.Add("leader-election-identity")
7566
)
7667

7768
var (
@@ -94,10 +85,6 @@ func main() {
9485
}
9586
klog.Infof("Version: %s", version)
9687

97-
if *connectionTimeout != 0 {
98-
klog.Warningf("Warning: option -connection-timeout is deprecated and has no effect")
99-
}
100-
10188
// Create the client config. Use kubeconfig if given, otherwise assume in-cluster.
10289
config, err := buildConfig(*kubeconfig)
10390
if err != nil {
@@ -112,65 +99,56 @@ func main() {
11299
}
113100

114101
factory := informers.NewSharedInformerFactory(clientset, *resync)
115-
var csiFactory csiinformers.SharedInformerFactory
116102
var handler controller.Handler
103+
// Connect to CSI.
104+
csiConn, err := connection.Connect(*csiAddress)
105+
if err != nil {
106+
klog.Error(err.Error())
107+
os.Exit(1)
108+
}
117109

118-
var csiAttacher string
119-
if *dummy {
120-
// Do not connect to any CSI, mark everything as attached.
121-
handler = controller.NewTrivialHandler(clientset)
122-
csiAttacher = dummyAttacherName
123-
} else {
124-
// Connect to CSI.
125-
csiConn, err := connection.Connect(*csiAddress)
126-
if err != nil {
127-
klog.Error(err.Error())
128-
os.Exit(1)
129-
}
130-
131-
err = rpc.ProbeForever(csiConn, *timeout)
132-
if err != nil {
133-
klog.Error(err.Error())
134-
os.Exit(1)
135-
}
110+
err = rpc.ProbeForever(csiConn, *timeout)
111+
if err != nil {
112+
klog.Error(err.Error())
113+
os.Exit(1)
114+
}
136115

137-
// Find driver name.
138-
ctx, cancel := context.WithTimeout(context.Background(), csiTimeout)
139-
defer cancel()
140-
csiAttacher, err = rpc.GetDriverName(ctx, csiConn)
141-
if err != nil {
142-
klog.Error(err.Error())
143-
os.Exit(1)
144-
}
145-
klog.V(2).Infof("CSI driver name: %q", csiAttacher)
116+
// Find driver name.
117+
ctx, cancel := context.WithTimeout(context.Background(), csiTimeout)
118+
defer cancel()
119+
csiAttacher, err := rpc.GetDriverName(ctx, csiConn)
120+
if err != nil {
121+
klog.Error(err.Error())
122+
os.Exit(1)
123+
}
124+
klog.V(2).Infof("CSI driver name: %q", csiAttacher)
146125

147-
supportsService, err := supportsPluginControllerService(ctx, csiConn)
126+
supportsService, err := supportsPluginControllerService(ctx, csiConn)
127+
if err != nil {
128+
klog.Error(err.Error())
129+
os.Exit(1)
130+
}
131+
if !supportsService {
132+
handler = controller.NewTrivialHandler(clientset)
133+
klog.V(2).Infof("CSI driver does not support Plugin Controller Service, using trivial handler")
134+
} else {
135+
// Find out if the driver supports attach/detach.
136+
supportsAttach, supportsReadOnly, err := supportsControllerPublish(ctx, csiConn)
148137
if err != nil {
149138
klog.Error(err.Error())
150139
os.Exit(1)
151140
}
152-
if !supportsService {
153-
handler = controller.NewTrivialHandler(clientset)
154-
klog.V(2).Infof("CSI driver does not support Plugin Controller Service, using trivial handler")
141+
if supportsAttach {
142+
pvLister := factory.Core().V1().PersistentVolumes().Lister()
143+
nodeLister := factory.Core().V1().Nodes().Lister()
144+
vaLister := factory.Storage().V1beta1().VolumeAttachments().Lister()
145+
csiNodeLister := factory.Storage().V1beta1().CSINodes().Lister()
146+
attacher := attacher.NewAttacher(csiConn)
147+
handler = controller.NewCSIHandler(clientset, csiAttacher, attacher, pvLister, nodeLister, csiNodeLister, vaLister, timeout, supportsReadOnly)
148+
klog.V(2).Infof("CSI driver supports ControllerPublishUnpublish, using real CSI handler")
155149
} else {
156-
// Find out if the driver supports attach/detach.
157-
supportsAttach, supportsReadOnly, err := supportsControllerPublish(ctx, csiConn)
158-
if err != nil {
159-
klog.Error(err.Error())
160-
os.Exit(1)
161-
}
162-
if supportsAttach {
163-
pvLister := factory.Core().V1().PersistentVolumes().Lister()
164-
nodeLister := factory.Core().V1().Nodes().Lister()
165-
vaLister := factory.Storage().V1beta1().VolumeAttachments().Lister()
166-
csiNodeLister := factory.Storage().V1beta1().CSINodes().Lister()
167-
attacher := attacher.NewAttacher(csiConn)
168-
handler = controller.NewCSIHandler(clientset, csiAttacher, attacher, pvLister, nodeLister, csiNodeLister, vaLister, timeout, supportsReadOnly)
169-
klog.V(2).Infof("CSI driver supports ControllerPublishUnpublish, using real CSI handler")
170-
} else {
171-
handler = controller.NewTrivialHandler(clientset)
172-
klog.V(2).Infof("CSI driver does not support ControllerPublishUnpublish, using trivial handler")
173-
}
150+
handler = controller.NewTrivialHandler(clientset)
151+
klog.V(2).Infof("CSI driver does not support ControllerPublishUnpublish, using trivial handler")
174152
}
175153
}
176154

@@ -187,28 +165,15 @@ func main() {
187165
run := func(ctx context.Context) {
188166
stopCh := ctx.Done()
189167
factory.Start(stopCh)
190-
if csiFactory != nil {
191-
csiFactory.Start(stopCh)
192-
}
193168
ctrl.Run(threads, stopCh)
194169
}
195170

196171
if !*enableLeaderElection {
197172
run(context.TODO())
198173
} else {
199-
var le leaderElection
200-
201174
// Name of config map with leader election lock
202175
lockName := "external-attacher-leader-" + csiAttacher
203-
if *leaderElectionType == leaderElectionTypeConfigMaps {
204-
klog.Warningf("The '%s' leader election type is deprecated and will be removed in a future release. Use '--leader-election-type=%s' instead.", leaderElectionTypeConfigMaps, leaderElectionTypeLeases)
205-
le = leaderelection.NewLeaderElectionWithConfigMaps(clientset, lockName, run)
206-
} else if *leaderElectionType == leaderElectionTypeLeases {
207-
le = leaderelection.NewLeaderElection(clientset, lockName, run)
208-
} else {
209-
klog.Errorf("--leader-election-type must be either '%s' or '%s'", leaderElectionTypeConfigMaps, leaderElectionTypeLeases)
210-
os.Exit(1)
211-
}
176+
le := leaderelection.NewLeaderElection(clientset, lockName, run)
212177

213178
if *leaderElectionNamespace != "" {
214179
le.WithNamespace(*leaderElectionNamespace)

deploy/kubernetes/deployment.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ spec:
3838
- "--v=5"
3939
- "--csi-address=$(ADDRESS)"
4040
- "--leader-election"
41-
- "--leader-election-type=leases"
4241
env:
4342
- name: MY_NAME
4443
valueFrom:

deploy/kubernetes/rbac.yaml

-5
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,6 @@ metadata:
6767
namespace: default
6868
name: external-attacher-cfg
6969
rules:
70-
# access to configmaps is only supported for backwards compatibility reasons
71-
# and can be removed once you are uses Leases (--leader-election-type=leases)
72-
- apiGroups: [""]
73-
resources: ["configmaps"]
74-
verbs: ["get", "watch", "list", "delete", "update", "create"]
7570
- apiGroups: ["coordination.k8s.io"]
7671
resources: ["leases"]
7772
verbs: ["get", "watch", "list", "delete", "update", "create"]

doc/development.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Trivial handler will be used for CSI drivers that don't support `ControllerPubli
1818

1919
### Real attacher
2020

21-
"Real" attacher talks to CSI over socket (`/run/csi/socket` by default, configurable by `-csi-address`). The attacher tries to connect for `-connection-timeout` (1 minute by default), allowing CSI driver to start and create its server socket a bit later.
21+
"Real" attacher talks to CSI over socket (`/run/csi/socket` by default, configurable by `-csi-address`).
2222

2323
The attacher then:
2424

vendor/github.com/kubernetes-csi/csi-lib-utils/deprecatedflags/deprecatedflags.go

-57
This file was deleted.

0 commit comments

Comments
 (0)