Skip to content

Commit

Permalink
Merge pull request #121 from vaskoz/goreportcard
Browse files Browse the repository at this point in the history
Goreportcard fixes
  • Loading branch information
fatih authored and jcodybaker committed Apr 26, 2019
1 parent 9e9f3f5 commit 0f31ec8
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 33 deletions.
48 changes: 24 additions & 24 deletions driver/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ import (
)

const (
_ = iota
KB = 1 << (10 * iota)
MB
GB
TB
_ = iota
kiB = 1 << (10 * iota)
miB
giB
tiB
)

const (
Expand All @@ -46,15 +46,15 @@ const (

// minimumVolumeSizeInBytes is used to validate that the user is not trying
// to create a volume that is smaller than what we support
minimumVolumeSizeInBytes int64 = 1 * GB
minimumVolumeSizeInBytes int64 = 1 * giB

// maximumVolumeSizeInBytes is used to validate that the user is not trying
// to create a volume that is larger than what we support
maximumVolumeSizeInBytes int64 = 16 * TB
maximumVolumeSizeInBytes int64 = 16 * tiB

// defaultVolumeSizeInBytes is used when the user did not provide a size or
// the size they provided did not satisfy our requirements
defaultVolumeSizeInBytes int64 = 16 * GB
defaultVolumeSizeInBytes int64 = 16 * giB

// createdByDO is used to tag volumes that are created by this CSI plugin
createdByDO = "Created by DigitalOcean CSI driver"
Expand Down Expand Up @@ -110,7 +110,7 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)

ll := d.log.WithFields(logrus.Fields{
"volume_name": volumeName,
"storage_size_giga_bytes": size / GB,
"storage_size_giga_bytes": size / giB,
"method": "create_volume",
"volume_capabilities": req.VolumeCapabilities,
})
Expand All @@ -132,15 +132,15 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
}
vol := volumes[0]

if vol.SizeGigaBytes*GB != size {
if vol.SizeGigaBytes*giB != size {
return nil, status.Error(codes.AlreadyExists, fmt.Sprintf("invalid option requested size: %d", size))
}

ll.Info("volume already created")
return &csi.CreateVolumeResponse{
Volume: &csi.Volume{
Id: vol.ID,
CapacityBytes: vol.SizeGigaBytes * GB,
CapacityBytes: vol.SizeGigaBytes * giB,
},
}, nil
}
Expand All @@ -149,7 +149,7 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
Region: d.region,
Name: volumeName,
Description: createdByDO,
SizeGigaBytes: size / GB,
SizeGigaBytes: size / giB,
}

if d.doTag != "" {
Expand Down Expand Up @@ -541,7 +541,7 @@ func (d *Driver) ListVolumes(ctx context.Context, req *csi.ListVolumesRequest) (
entries = append(entries, &csi.ListVolumesResponse_Entry{
Volume: &csi.Volume{
Id: vol.ID,
CapacityBytes: vol.SizeGigaBytes * GB,
CapacityBytes: vol.SizeGigaBytes * giB,
},
})
}
Expand Down Expand Up @@ -675,7 +675,7 @@ func (d *Driver) CreateSnapshot(ctx context.Context, req *csi.CreateSnapshotRequ
}, nil
}

// DeleteSnapshost will be called by the CO to delete a snapshot.
// DeleteSnapshot will be called by the CO to delete a snapshot.
func (d *Driver) DeleteSnapshot(ctx context.Context, req *csi.DeleteSnapshotRequest) (*csi.DeleteSnapshotResponse, error) {
ll := d.log.WithFields(logrus.Fields{
"req_snapshot_id": req.GetSnapshotId(),
Expand Down Expand Up @@ -859,17 +859,17 @@ func formatBytes(inputBytes int64) string {
unit := ""

switch {
case inputBytes >= TB:
output = output / TB
case inputBytes >= tiB:
output = output / tiB
unit = "Ti"
case inputBytes >= GB:
output = output / GB
case inputBytes >= giB:
output = output / giB
unit = "Gi"
case inputBytes >= MB:
output = output / MB
case inputBytes >= miB:
output = output / miB
unit = "Mi"
case inputBytes >= KB:
output = output / KB
case inputBytes >= kiB:
output = output / kiB
unit = "Ki"
case inputBytes == 0:
return "0"
Expand Down Expand Up @@ -912,7 +912,7 @@ func (d *Driver) waitAction(ctx context.Context, volumeId string, actionId int)
continue
}
case <-ctx.Done():
return fmt.Errorf("timeout occured waiting for storage action of volume: %q", volumeId)
return fmt.Errorf("timeout occurred waiting for storage action of volume: %q", volumeId)
}
}
}
Expand Down Expand Up @@ -964,7 +964,7 @@ func toCSISnapshot(snap *godo.Snapshot) (*csi.Snapshot, error) {
return &csi.Snapshot{
Id: snap.ID,
SourceVolumeId: snap.ResourceID,
SizeBytes: int64(snap.SizeGigaBytes) * GB,
SizeBytes: int64(snap.SizeGigaBytes) * giB,
CreatedAt: createdAt.UTC().UnixNano(),
Status: &csi.SnapshotStatus{
Type: csi.SnapshotStatus_READY,
Expand Down
16 changes: 8 additions & 8 deletions driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,13 @@ func (d *Driver) Run() error {
// CSI plugins talk only over UNIX sockets currently
if u.Scheme != "unix" {
return fmt.Errorf("currently only unix domain sockets are supported, have: %s", u.Scheme)
} else {
// remove the socket if it's already there. This can happen if we
// deploy a new version and the socket was created from the old running
// plugin.
d.log.WithField("socket", addr).Info("removing socket")
if err := os.Remove(addr); err != nil && !os.IsNotExist(err) {
return fmt.Errorf("failed to remove unix domain socket file %s, error: %s", addr, err)
}
}
// remove the socket if it's already there. This can happen if we
// deploy a new version and the socket was created from the old running
// plugin.
d.log.WithField("socket", addr).Info("removing socket")
if err := os.Remove(addr); err != nil && !os.IsNotExist(err) {
return fmt.Errorf("failed to remove unix domain socket file %s, error: %s", addr, err)
}

listener, err := net.Listen(u.Scheme, addr)
Expand Down Expand Up @@ -199,6 +198,7 @@ func (d *Driver) Stop() {
// When building any packages that import version, pass the build/install cmd
// ldflags like so:
// go build -ldflags "-X github.com/digitalocean/csi-digitalocean/driver.version=0.0.1"

// GetVersion returns the current release version, as inserted at build time.
func GetVersion() string {
return version
Expand Down
2 changes: 1 addition & 1 deletion driver/driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func TestDriverSuite(t *testing.T) {
volumes := make(map[string]*godo.Volume, 0)
snapshots := make(map[string]*godo.Snapshot, 0)
droplets := map[int]*godo.Droplet{
nodeID: &godo.Droplet{
nodeID: {
ID: nodeID,
},
}
Expand Down
3 changes: 3 additions & 0 deletions test/kubernetes/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,9 @@ func setup() error {
Name: namespace,
},
})
if err != nil {
return err
}

snapClient, err = snapclientset.NewForConfig(config)
if err != nil {
Expand Down

0 comments on commit 0f31ec8

Please sign in to comment.