Skip to content

Commit

Permalink
Merge pull request #715 from humblec/anno
Browse files Browse the repository at this point in the history
Short declaration, variable declaration allignment and few other cleanups
  • Loading branch information
k8s-ci-robot authored Mar 25, 2022
2 parents 32c27a5 + 4047919 commit 46bdb0a
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 30 deletions.
1 change: 0 additions & 1 deletion cmd/csi-provisioner/csi-provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -600,5 +600,4 @@ func main() {
klog.Fatalf("failed to initialize leader election: %v", err)
}
}

}
2 changes: 1 addition & 1 deletion pkg/capacity/topology/nodes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ func TestNodeTopology(t *testing.T) {
name: node1,
driverKeys: map[string][]string{
// This node reports keys in reverse order, which must not make a difference.
driverName: []string{networkStorageKeys[2], networkStorageKeys[1], networkStorageKeys[0]},
driverName: {networkStorageKeys[2], networkStorageKeys[1], networkStorageKeys[0]},
},
labels: networkStorageLabels,
},
Expand Down
24 changes: 10 additions & 14 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ import (
snapclientset "github.com/kubernetes-csi/external-snapshotter/client/v4/clientset/versioned"
)

//secretParamsMap provides a mapping of current as well as deprecated secret keys
// secretParamsMap provides a mapping of current as well as deprecated secret keys
type secretParamsMap struct {
name string
deprecatedSecretNameKey string
Expand Down Expand Up @@ -255,16 +255,16 @@ type csiProvisioner struct {
controllerPublishReadOnly bool
}

var _ controller.Provisioner = &csiProvisioner{}
var _ controller.BlockProvisioner = &csiProvisioner{}
var _ controller.Qualifier = &csiProvisioner{}

var (
// Each provisioner have a identify string to distinguish with others. This
// identify string will be added in PV annotations under this key.
provisionerIDKey = "storage.kubernetes.io/csiProvisionerIdentity"
_ controller.Provisioner = &csiProvisioner{}
_ controller.BlockProvisioner = &csiProvisioner{}
_ controller.Qualifier = &csiProvisioner{}
)

// Each provisioner have a identify string to distinguish with others. This
// identify string will be added in PV annotations under this key.
var provisionerIDKey = "storage.kubernetes.io/csiProvisionerIdentity"

func Connect(address string, metricsManager metrics.CSIMetricsManager) (*grpc.ClientConn, error) {
return connection.Connect(address, metricsManager, connection.OnConnectionLoss(connection.ExitOnConnectionLoss()))
}
Expand Down Expand Up @@ -430,7 +430,6 @@ func makeVolumeName(prefix, pvcUID string, volumeNameUUIDLength int) (string, er
}
// Else we remove all dashes from UUID and truncate to volumeNameUUIDLength
return fmt.Sprintf("%s-%s", prefix, strings.Replace(string(pvcUID), "-", "", -1)[0:volumeNameUUIDLength]), nil

}

func getAccessTypeBlock() *csi.VolumeCapability_Block {
Expand Down Expand Up @@ -713,7 +712,6 @@ func (p *csiProvisioner) Provision(ctx context.Context, options controller.Provi
provisioner,
p.driverName),
}

}

// The same check already ran in ShouldProvision, but perhaps
Expand Down Expand Up @@ -742,7 +740,6 @@ func (p *csiProvisioner) Provision(ctx context.Context, options controller.Provi
createCtx, cancel := context.WithTimeout(createCtx, p.timeout)
defer cancel()
rep, err := p.csiClient.CreateVolume(createCtx, req)

if err != nil {
// Giving up after an error and telling the pod scheduler to retry with a different node
// only makes sense if:
Expand Down Expand Up @@ -779,7 +776,7 @@ func (p *csiProvisioner) Provision(ctx context.Context, options controller.Provi
}
respCap := rep.GetVolume().GetCapacityBytes()

//According to CSI spec CreateVolume should be able to return capacity = 0, which means it is unknown. for example NFS/FTP
// According to CSI spec CreateVolume should be able to return capacity = 0, which means it is unknown. for example NFS/FTP
if respCap == 0 {
respCap = volSizeBytes
klog.V(3).Infof("csiClient response volume with size 0, which is not supported by apiServer, will use claim size:%d", respCap)
Expand Down Expand Up @@ -1049,7 +1046,6 @@ func (p *csiProvisioner) getSnapshotSource(ctx context.Context, claim *v1.Persis
}

snapContentObj, err := p.snapshotClient.SnapshotV1().VolumeSnapshotContents().Get(ctx, *snapshotObj.Status.BoundVolumeSnapshotContentName, metav1.GetOptions{})

if err != nil {
klog.Warningf("error getting snapshotcontent %s for snapshot %s/%s from api server: %s", *snapshotObj.Status.BoundVolumeSnapshotContentName, snapshotObj.Namespace, snapshotObj.Name, err)
return nil, fmt.Errorf(snapshotNotBound, claim.Spec.DataSource.Name)
Expand Down Expand Up @@ -1265,7 +1261,7 @@ func (p *csiProvisioner) ShouldProvision(ctx context.Context, claim *v1.Persiste
return true
}

//TODO use a unique volume handle from and to Id
// TODO use a unique volume handle from and to Id
func (p *csiProvisioner) volumeIdToHandle(id string) string {
return id
}
Expand Down
25 changes: 11 additions & 14 deletions pkg/controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,6 @@ func TestBytesToQuantity(t *testing.T) {
t.Errorf("test: %s, expected: %v, got: %v", test.testName, test.quantString, q.String())
}
}

}

func TestCreateDriverReturnsInvalidCapacityDuringProvision(t *testing.T) {
Expand Down Expand Up @@ -578,8 +577,8 @@ func fakeClaim(name, namespace, claimUID string, capacity int64, boundToVolume s
// leave it undefined/nil to maintaint the current defaults for test cases
}
return &claim

}

func TestGetSecretReference(t *testing.T) {
testcases := map[string]struct {
secretParams secretParamsMap
Expand Down Expand Up @@ -2283,6 +2282,7 @@ func newSnapshot(name, className, boundToContent, snapshotUID, claimName string,

return &snapshot
}

func runFSTypeProvisionTest(t *testing.T, k string, tc provisioningFSTypeTestcase, requestedBytes int64, provisionDriverName, supportsMigrationFromInTreePluginName string) {
t.Logf("Running test: %v", k)
myDefaultfsType := "ext4"
Expand Down Expand Up @@ -2610,13 +2610,13 @@ func newContent(name, className, snapshotHandle, volumeUID, volumeName, boundToS

// TestProvisionFromSnapshot tests create volume from snapshot
func TestProvisionFromSnapshot(t *testing.T) {
var apiGrp = "snapshot.storage.k8s.io"
var unsupportedAPIGrp = "unsupported.group.io"
apiGrp := "snapshot.storage.k8s.io"
unsupportedAPIGrp := "unsupported.group.io"
var requestedBytes int64 = 1000
var snapName = "test-snapshot"
var snapClassName = "test-snapclass"
var timeNow = time.Now().UnixNano()
var metaTimeNowUnix = &metav1.Time{
snapName := "test-snapshot"
snapClassName := "test-snapclass"
timeNow := time.Now().UnixNano()
metaTimeNowUnix := &metav1.Time{
Time: time.Unix(0, timeNow),
}
deletePolicy := v1.PersistentVolumeReclaimDelete
Expand Down Expand Up @@ -3594,7 +3594,6 @@ func TestProvisionWithTopologyDisabled(t *testing.T) {
},
},
})

if err != nil {
t.Fatalf("got error from Provision call: %v", err)
}
Expand Down Expand Up @@ -4491,7 +4490,7 @@ func TestProvisionFromPVC(t *testing.T) {

func TestProvisionWithMigration(t *testing.T) {
var requestBytes int64 = 100000
var inTreePluginName = "in-tree-plugin"
inTreePluginName := "in-tree-plugin"

deletePolicy := v1.PersistentVolumeReclaimDelete
testcases := []struct {
Expand All @@ -4508,7 +4507,7 @@ func TestProvisionWithMigration(t *testing.T) {
expectTranslation: true,
},
{
name: "provision with migration on with GA annStorageProvisioner annontation",
name: "provision with migration on with GA annStorageProvisioner annotation",
scProvisioner: inTreePluginName,
annotation: map[string]string{annStorageProvisioner: driverName},
expectTranslation: true,
Expand All @@ -4520,7 +4519,7 @@ func TestProvisionWithMigration(t *testing.T) {
expectTranslation: false,
},
{
name: "provision without migration for native CSI with GA annStorageProvisioner annontation",
name: "provision without migration for native CSI with GA annStorageProvisioner annotation",
scProvisioner: driverName,
annotation: map[string]string{annStorageProvisioner: driverName},
expectTranslation: false,
Expand Down Expand Up @@ -4661,7 +4660,6 @@ func TestProvisionWithMigration(t *testing.T) {
}
}
})

}
}

Expand Down Expand Up @@ -4782,7 +4780,6 @@ func TestDeleteMigration(t *testing.T) {
t.Errorf("Got error: %v, expected none", err)
}
})

}
}

Expand Down

0 comments on commit 46bdb0a

Please sign in to comment.