Skip to content

Commit ab65e2a

Browse files
committed
Add make target for formatting
1 parent a06ee26 commit ab65e2a

File tree

5 files changed

+22
-20
lines changed

5 files changed

+22
-20
lines changed

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@ PLUGIN_FULL_NAME := ${AUTHOR}/${PLUGIN_NAME}
55
ROOTFS_CONTAINER := ${PLUGIN_NAME}-rootfs
66
ROOTFS_IMAGE := ${AUTHOR}/${ROOTFS_CONTAINER}
77

8+
all: format build
9+
10+
format:
11+
go fmt ./...
812

913
build:
1014
GOOS=linux GOARCH=amd64 go build -o "$(PLUGIN_NAME)"
1115

12-
1316
rootfs-image:
1417
docker build -t $(ROOTFS_IMAGE) .
1518

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,11 @@ https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=bc
77
```
88
chown -1:-1
99
10+
```
11+
12+
## Development
13+
Go 1.11
14+
```bash
15+
go mod vendor
16+
go mod tidy
1017
```

driver/driver.go

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,11 @@ import (
1515
v "github.com/docker/go-plugins-helpers/volume"
1616
)
1717

18-
1918
type Config struct {
20-
StateDir string
21-
DataDir string
22-
MountDir string
23-
DefaultSize string
19+
StateDir string
20+
DataDir string
21+
MountDir string
22+
DefaultSize string
2423
}
2524

2625
type Driver struct {
@@ -37,9 +36,9 @@ func NewDriver(cfg Config) (d Driver, err error) {
3736
}
3837

3938
m, err := manager.New(manager.Config{
40-
StateDir: cfg.StateDir,
41-
DataDir: cfg.DataDir,
42-
MountDir: cfg.MountDir,
39+
StateDir: cfg.StateDir,
40+
DataDir: cfg.DataDir,
41+
MountDir: cfg.MountDir,
4342
})
4443
if err != nil {
4544
err = errors.Wrapf(err,
@@ -215,7 +214,7 @@ func (d Driver) Get(req *v.GetRequest) (*v.GetResponse, error) {
215214
CreatedAt: fmt.Sprintf(vol.CreatedAt.Format(time.RFC3339)),
216215
Mountpoint: vol.MountPointPath,
217216
Status: map[string]interface{}{
218-
"size-max": strconv.FormatUint(vol.MaxSizeInBytes, 10),
217+
"size-max": strconv.FormatUint(vol.MaxSizeInBytes, 10),
219218
"size-current": strconv.FormatUint(vol.CurrentSizeInBytes, 10),
220219
},
221220
}
@@ -298,7 +297,7 @@ func (d Driver) Mount(req *v.MountRequest) (*v.MountResponse, error) {
298297
return resp, nil
299298
}
300299

301-
func (d Driver) Unmount(req *v.UnmountRequest) (error) {
300+
func (d Driver) Unmount(req *v.UnmountRequest) error {
302301
var logger = d.logger.With().
303302
Str("log-id", shortid.MustGenerate()).
304303
Str("method", "unmount").
@@ -318,11 +317,10 @@ func (d Driver) Unmount(req *v.UnmountRequest) (error) {
318317
return err
319318
}
320319

321-
func (d Driver) Capabilities() (resp *v.CapabilitiesResponse) {
322-
resp = &v.CapabilitiesResponse{
320+
func (d Driver) Capabilities() *v.CapabilitiesResponse {
321+
return &v.CapabilitiesResponse{
323322
Capabilities: v.Capability{
324323
Scope: "local",
325324
},
326325
}
327-
return
328326
}

driver/utils.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"github.com/docker/go-units"
88
)
99

10-
1110
func FromHumanSize(size string) (bytesInt int64, err error) {
1211
if strings.Contains(strings.ToLower(size), "i") {
1312
bytesInt, err = units.RAMInBytes(size)

manager/manager.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,6 @@ func (m Manager) Create(name string, sizeInBytes int64, sparse bool, uid, gid in
170170
return errors.Wrapf(err,
171171
"Error creating volume '%s' - data dir does not exist: '%s'",
172172
name, m.dataDir)
173-
174173
}
175174

176175
// create data file
@@ -184,9 +183,7 @@ func (m Manager) Create(name string, sizeInBytes int64, sparse bool, uid, gid in
184183
name, dataFilePath)
185184
}
186185

187-
fmt.Println(fmt.Sprintf("--- %v", sparse))
188186
if sparse {
189-
fmt.Println(fmt.Sprintf("--- Creating as sparse"))
190187
err = dataFileInfo.Truncate(sizeInBytes)
191188
if err != nil {
192189
_ = os.Remove(dataFilePath) // attempt to cleanup
@@ -195,13 +192,11 @@ func (m Manager) Create(name string, sizeInBytes int64, sparse bool, uid, gid in
195192
name, sizeInBytes)
196193
}
197194
} else {
198-
fmt.Println(fmt.Sprintf("--- Creating as fallocate"))
199195
// Try using fallocate - super fast if data dir is on ext4 or xfs
200196
errBytes, err := exec.Command("fallocate", "-l", fmt.Sprint(sizeInBytes), dataFilePath).CombinedOutput()
201197

202198
// fallocate failed - either not enough space or unsupported FS
203199
if err != nil {
204-
fmt.Println(fmt.Sprintf("--- fallocate failed"))
205200
errStr := strings.TrimSpace(string(errBytes[:]))
206201

207202
// If there is not enough space then we just error out

0 commit comments

Comments
 (0)