diff --git a/efs/Makefile b/efs/Makefile index f24838cc..e440de54 100644 --- a/efs/Makefile +++ b/efs/Makefile @@ -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 diff --git a/efs/cmd/efs-provisioner/efs-provisioner.go b/efs/cmd/efs-provisioner/efs-provisioner.go index d10885b6..bde8363c 100644 --- a/efs/cmd/efs-provisioner/efs-provisioner.go +++ b/efs/cmd/efs-provisioner/efs-provisioner.go @@ -43,7 +43,7 @@ import ( const ( provisionerNameKey = "PROVISIONER_NAME" - fileSystemIdKey = "FILE_SYSTEM_ID" + fileSystemIDKey = "FILE_SYSTEM_ID" awsRegionKey = "AWS_REGION" resyncPeriod = 15 * time.Second @@ -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 { @@ -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) @@ -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) { @@ -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 diff --git a/efs/pkg/gidallocator/allocator.go b/efs/pkg/gidallocator/allocator.go index 5cdfdbcf..ba4449f6 100644 --- a/efs/pkg/gidallocator/allocator.go +++ b/efs/pkg/gidallocator/allocator.go @@ -42,12 +42,15 @@ 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, @@ -55,6 +58,8 @@ func New(client kubernetes.Interface) Allocator { } } +// 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) @@ -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 { diff --git a/efs/pkg/util/util.go b/efs/pkg/util/util.go index 54ab940f..ece21bda 100644 --- a/efs/pkg/util/util.go +++ b/efs/pkg/util/util.go @@ -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") diff --git a/lib/verify.sh b/lib/verify.sh index ba43960d..a4e41b26 100755 --- a/lib/verify.sh +++ b/lib/verify.sh @@ -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 diff --git a/nfs/Makefile b/nfs/Makefile index 81b93247..5979789d 100644 --- a/nfs/Makefile +++ b/nfs/Makefile @@ -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