Skip to content

Commit 2586013

Browse files
authored
Merge pull request #714 from xing-yang/backport_690
Backport 690: replace serviceAccountName key, rbac and cleanup in the code
2 parents 1e95975 + 523d298 commit 2586013

File tree

19 files changed

+69
-67
lines changed

19 files changed

+69
-67
lines changed

cmd/snapshot-controller/main.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,7 @@ var (
7373
preventVolumeModeConversion = flag.Bool("prevent-volume-mode-conversion", false, "Prevents an unauthorised user from modifying the volume mode when creating a PVC from an existing VolumeSnapshot.")
7474
)
7575

76-
var (
77-
version = "unknown"
78-
)
76+
var version = "unknown"
7977

8078
// Checks that the VolumeSnapshot v1 CRDs exist.
8179
func ensureCustomResourceDefinitionsExist(client *clientset.Clientset) error {

deploy/kubernetes/csi-snapshotter/rbac-external-provisioner.yaml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ roleRef:
6868
apiGroup: rbac.authorization.k8s.io
6969

7070
---
71-
# Provisioner must be able to work with endpoints and leases in current namespace
71+
# Provisioner must be able to work with leases in current namespace
7272
# if (and only if) leadership election is enabled
7373
kind: Role
7474
apiVersion: rbac.authorization.k8s.io/v1
@@ -77,9 +77,6 @@ metadata:
7777
namespace: default
7878
name: external-provisioner-cfg
7979
rules:
80-
- apiGroups: [""]
81-
resources: ["endpoints"]
82-
verbs: ["get", "watch", "list", "delete", "update", "create"]
8380
- apiGroups: ["coordination.k8s.io"]
8481
resources: ["leases"]
8582
verbs: ["get", "watch", "list", "delete", "update", "create"]

deploy/kubernetes/csi-snapshotter/setup-csi-snapshotter.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ spec:
6969
labels:
7070
app: csi-snapshotter
7171
spec:
72-
serviceAccount: csi-snapshotter
72+
serviceAccountName: csi-snapshotter
7373
containers:
7474
- name: csi-provisioner
7575
image: k8s.gcr.io/sig-storage/csi-provisioner:v3.0.0

deploy/kubernetes/snapshot-controller/setup-snapshot-controller.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ spec:
3030
labels:
3131
app: snapshot-controller
3232
spec:
33-
serviceAccount: snapshot-controller
33+
serviceAccountName: snapshot-controller
3434
containers:
3535
- name: snapshot-controller
3636
image: gcr.io/k8s-staging-sig-storage/snapshot-controller:v5.0.1

pkg/common-controller/framework_test.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,18 @@ type controllerTest struct {
112112

113113
type testCall func(ctrl *csiSnapshotCommonController, reactor *snapshotReactor, test controllerTest) error
114114

115-
const testNamespace = "default"
116-
const mockDriverName = "csi-mock-plugin"
115+
const (
116+
testNamespace = "default"
117+
mockDriverName = "csi-mock-plugin"
118+
)
117119

118-
var errVersionConflict = errors.New("VersionError")
119-
var nocontents []*crdv1.VolumeSnapshotContent
120-
var nosnapshots []*crdv1.VolumeSnapshot
121-
var noevents = []string{}
122-
var noerrors = []reactorError{}
120+
var (
121+
errVersionConflict = errors.New("VersionError")
122+
nocontents []*crdv1.VolumeSnapshotContent
123+
nosnapshots []*crdv1.VolumeSnapshot
124+
noevents = []string{}
125+
noerrors = []reactorError{}
126+
)
123127

124128
// snapshotReactor is a core.Reactor that simulates etcd and API server. It
125129
// stores:
@@ -921,6 +925,7 @@ func withSnapshotContentInvalidLabel(contents []*crdv1.VolumeSnapshotContent) []
921925
}
922926
return contents
923927
}
928+
924929
func withContentAnnotations(contents []*crdv1.VolumeSnapshotContent, annotations map[string]string) []*crdv1.VolumeSnapshotContent {
925930
for i := range contents {
926931
if contents[i].ObjectMeta.Annotations == nil {
@@ -1200,7 +1205,6 @@ func testSyncSnapshot(ctrl *csiSnapshotCommonController, reactor *snapshotReacto
12001205

12011206
func testSyncSnapshotError(ctrl *csiSnapshotCommonController, reactor *snapshotReactor, test controllerTest) error {
12021207
err := ctrl.syncSnapshot(test.initialSnapshots[0])
1203-
12041208
if err != nil {
12051209
return nil
12061210
}
@@ -1303,7 +1307,6 @@ var (
13031307
// controller waits for the operation lock. Controller is then resumed and we
13041308
// check how it behaves.
13051309
func wrapTestWithInjectedOperation(toWrap testCall, injectBeforeOperation func(ctrl *csiSnapshotCommonController, reactor *snapshotReactor)) testCall {
1306-
13071310
return func(ctrl *csiSnapshotCommonController, reactor *snapshotReactor, test controllerTest) error {
13081311
// Inject a hook before async operation starts
13091312
klog.V(4).Infof("reactor:injecting call")

pkg/common-controller/snapshot_controller.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,10 @@ import (
7777
// bi-directional binding is complete and readyToUse becomes true. Error field
7878
// in the snapshot status will be updated accordingly when failure occurs.
7979

80-
const snapshotKind = "VolumeSnapshot"
81-
const snapshotAPIGroup = crdv1.GroupName
80+
const (
81+
snapshotKind = "VolumeSnapshot"
82+
snapshotAPIGroup = crdv1.GroupName
83+
)
8284

8385
const controllerUpdateFailMsg = "snapshot controller failed to update"
8486

@@ -829,7 +831,6 @@ func (ctrl *csiSnapshotCommonController) updateSnapshotErrorStatusWithEvent(snap
829831

830832
// addContentFinalizer adds a Finalizer for VolumeSnapshotContent.
831833
func (ctrl *csiSnapshotCommonController) addContentFinalizer(content *crdv1.VolumeSnapshotContent) error {
832-
833834
var patches []utils.PatchOp
834835
if len(content.Finalizers) > 0 {
835836
// Add to the end of the finalizers if we have any other finalizers
@@ -838,7 +839,6 @@ func (ctrl *csiSnapshotCommonController) addContentFinalizer(content *crdv1.Volu
838839
Path: "/metadata/finalizers/-",
839840
Value: utils.VolumeSnapshotContentFinalizer,
840841
})
841-
842842
} else {
843843
// Replace finalizers with new array if there are no other finalizers
844844
patches = append(patches, utils.PatchOp{

pkg/common-controller/snapshot_controller_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ func TestControllerCacheParsingError(t *testing.T) {
111111
}
112112

113113
func TestGetManagedByNode(t *testing.T) {
114-
115114
// Test that a matching node is found
116115

117116
node1 := &v1.Node{

pkg/common-controller/snapshot_create_test.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,22 @@ import (
2626
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2727
)
2828

29-
var timeNow = time.Now()
30-
var timeNowStamp = timeNow.UnixNano()
31-
var False = false
32-
var True = true
29+
var (
30+
timeNow = time.Now()
31+
timeNowStamp = timeNow.UnixNano()
32+
False = false
33+
True = true
34+
)
3335

3436
var metaTimeNowUnix = &metav1.Time{
3537
Time: timeNow,
3638
}
3739

38-
var defaultSize int64 = 1000
39-
var deletePolicy = crdv1.VolumeSnapshotContentDelete
40-
var retainPolicy = crdv1.VolumeSnapshotContentRetain
40+
var (
41+
defaultSize int64 = 1000
42+
deletePolicy = crdv1.VolumeSnapshotContentDelete
43+
retainPolicy = crdv1.VolumeSnapshotContentRetain
44+
)
4145

4246
// Test single call to SyncSnapshot, expecting create snapshot to happen.
4347
// 1. Fill in the controller with initial data

pkg/common-controller/snapshot_delete_test.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ var class3Parameters = map[string]string{
4040
}
4141

4242
var class4Parameters = map[string]string{
43-
//utils.SnapshotterSecretNameKey: "emptysecret",
44-
//utils.SnapshotterSecretNamespaceKey: "default",
43+
// utils.SnapshotterSecretNameKey: "emptysecret",
44+
// utils.SnapshotterSecretNamespaceKey: "default",
4545
}
4646

4747
var class5Parameters = map[string]string{
@@ -51,8 +51,10 @@ var class5Parameters = map[string]string{
5151

5252
var timeNowMetav1 = metav1.Now()
5353

54-
var content31 = "content3-1"
55-
var claim31 = "claim3-1"
54+
var (
55+
content31 = "content3-1"
56+
claim31 = "claim3-1"
57+
)
5658

5759
var snapshotClasses = []*crdv1.VolumeSnapshotClass{
5860
{

pkg/common-controller/snapshot_finalizer_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import (
2626
// Test single call to ensurePVCFinalizer, checkandRemovePVCFinalizer, addSnapshotFinalizer, removeSnapshotFinalizer
2727
// expecting finalizers to be added or removed
2828
func TestSnapshotFinalizer(t *testing.T) {
29-
3029
tests := []controllerTest{
3130
{
3231
name: "1-1 - successful add PVC finalizer",

0 commit comments

Comments
 (0)