Skip to content

Commit

Permalink
Fix verify golint
Browse files Browse the repository at this point in the history
  • Loading branch information
wongma7 committed Mar 6, 2017
1 parent aa616c7 commit 7d1b585
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 14 deletions.
4 changes: 2 additions & 2 deletions efs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ verify:
@tput bold; echo Running gofmt:; tput sgr0
(gofmt -s -w -l `find . -type f -name "*.go" | grep -v vendor`) || exit 1
@tput bold; echo Running golint and go vet:; tput sgr0
for i in $$(find . -type f -name "*.go" | grep -v 'vendor\|framework'); do \
golint --set_exit_status $$i; \
for i in $$(find . -type f -name "*.go" | grep -v 'vendor\|minmax'); do \
golint --set_exit_status $$i || exit 1; \
go vet $$i; \
done
@tput bold; echo Running verify-boilerplate; tput sgr0
Expand Down
21 changes: 11 additions & 10 deletions efs/cmd/efs-provisioner/efs-provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import (

const (
provisionerNameKey = "PROVISIONER_NAME"
fileSystemIdKey = "FILE_SYSTEM_ID"
fileSystemIDKey = "FILE_SYSTEM_ID"
awsRegionKey = "AWS_REGION"

resyncPeriod = 15 * time.Second
Expand All @@ -63,18 +63,19 @@ type efsProvisioner struct {
allocator gidallocator.Allocator
}

// NewEFSProvisioner creates an AWS EFS volume provisioner
func NewEFSProvisioner(client kubernetes.Interface) controller.Provisioner {
fileSystemId := os.Getenv(fileSystemIdKey)
if fileSystemId == "" {
glog.Fatal("environment variable %s is not set! Please set it.", fileSystemIdKey)
fileSystemID := os.Getenv(fileSystemIDKey)
if fileSystemID == "" {
glog.Fatalf("environment variable %s is not set! Please set it.", fileSystemIDKey)
}

awsRegion := os.Getenv(awsRegionKey)
if awsRegion == "" {
glog.Fatal("environment variable %s is not set! Please set it.", awsRegionKey)
glog.Fatalf("environment variable %s is not set! Please set it.", awsRegionKey)
}

dnsName := getDNSName(fileSystemId, awsRegion)
dnsName := getDNSName(fileSystemID, awsRegion)

mountpoint, source, err := getMount(dnsName)
if err != nil {
Expand All @@ -88,7 +89,7 @@ func NewEFSProvisioner(client kubernetes.Interface) controller.Provisioner {

svc := efs.New(sess, &aws.Config{Region: aws.String(awsRegion)})
params := &efs.DescribeFileSystemsInput{
FileSystemId: aws.String(fileSystemId),
FileSystemId: aws.String(fileSystemID),
}

_, err = svc.DescribeFileSystems(params)
Expand All @@ -105,8 +106,8 @@ func NewEFSProvisioner(client kubernetes.Interface) controller.Provisioner {
}
}

func getDNSName(fileSystemId, awsRegion string) string {
return fileSystemId + ".efs." + awsRegion + ".amazonaws.com"
func getDNSName(fileSystemID, awsRegion string) string {
return fileSystemID + ".efs." + awsRegion + ".amazonaws.com"
}

func getMount(dnsName string) (string, string, error) {
Expand Down Expand Up @@ -269,7 +270,7 @@ func main() {

provisionerName := os.Getenv(provisionerNameKey)
if provisionerName == "" {
glog.Fatal("environment variable %s is not set! Please set it.", provisionerNameKey)
glog.Fatalf("environment variable %s is not set! Please set it.", provisionerNameKey)
}

// Start the provision controller which will dynamically provision efs NFS
Expand Down
7 changes: 7 additions & 0 deletions efs/pkg/gidallocator/allocator.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,24 @@ const (
absoluteGidMax = math.MaxInt32
)

// Allocator allocates GIDs to PVs. It allocates from per-SC ranges and ensures
// that no two PVs of the same SC get the same GID.
type Allocator struct {
client kubernetes.Interface
gidTable map[string]*allocator.MinMaxAllocator
gidTableLock sync.Mutex
}

// New creates a new GID Allocator
func New(client kubernetes.Interface) Allocator {
return Allocator{
client: client,
gidTable: make(map[string]*allocator.MinMaxAllocator),
}
}

// AllocateNext allocates the next available GID for the given VolumeOptions
// (claim's options for a volume it wants) from the appropriate GID table.
func (a *Allocator) AllocateNext(options controller.VolumeOptions) (int, error) {
class := util.GetClaimStorageClass(options.PVC)
gidMin, gidMax, err := parseClassParameters(options.Parameters)
Expand All @@ -75,6 +80,8 @@ func (a *Allocator) AllocateNext(options controller.VolumeOptions) (int, error)
return gid, nil
}

// Release releases the given volume's allocated GID from the appropriate GID
// table.
func (a *Allocator) Release(volume *v1.PersistentVolume) error {
class, err := util.GetClassForVolume(a.client, volume)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions efs/pkg/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ func GetClaimStorageClass(claim *v1.PersistentVolumeClaim) string {
return ""
}

// GetClassForVolume gets the volume's Storage Class
func GetClassForVolume(kubeClient kubernetes.Interface, pv *v1.PersistentVolume) (*v1beta1.StorageClass, error) {
if kubeClient == nil {
return nil, fmt.Errorf("Cannot get kube client")
Expand Down
2 changes: 1 addition & 1 deletion lib/verify.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ tput bold; echo Running gofmt:; tput sgr0
(gofmt -s -w -l `find . -type f -name "*.go" | grep -v vendor`) || exit 1
tput bold; echo Running golint and go vet:; tput sgr0
for i in $(find . -type f -name "*.go" | grep -v 'vendor\|framework\|leaderelection.go\|interface.go'); do \
golint --set_exit_status $i; \
golint --set_exit_status $i || exit 1; \
go vet $i; \
done
tput bold; echo Running verify-boilerplate; tput sgr0
Expand Down
2 changes: 1 addition & 1 deletion nfs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ verify:
(gofmt -s -w -l `find . -type f -name "*.go" | grep -v vendor`) || exit 1
@tput bold; echo Running golint and go vet:; tput sgr0
for i in $$(find . -type f -name "*.go" | grep -v 'vendor\|framework'); do \
golint --set_exit_status $$i; \
golint --set_exit_status $$i || exit 1; \
go vet $$i; \
done
@tput bold; echo Running verify-boilerplate; tput sgr0
Expand Down

0 comments on commit 7d1b585

Please sign in to comment.