Skip to content

Commit

Permalink
update installation command to use latest stable version
Browse files Browse the repository at this point in the history
  • Loading branch information
AndyXiangLi committed Apr 16, 2021
1 parent 9f4ce44 commit 79e9ff0
Show file tree
Hide file tree
Showing 17 changed files with 105 additions and 39 deletions.
2 changes: 1 addition & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package main

import (
"flag"

"github.com/kubernetes-sigs/aws-ebs-csi-driver/pkg/driver"

"k8s.io/klog"
Expand All @@ -35,6 +34,7 @@ func main() {
driver.WithMode(options.DriverMode),
driver.WithVolumeAttachLimit(options.NodeOptions.VolumeAttachLimit),
driver.WithKubernetesClusterID(options.ControllerOptions.KubernetesClusterID),
driver.WithAwsSdkDebugLog(options.ControllerOptions.AwsSdkDebugLog),
)
if err != nil {
klog.Fatalln(err)
Expand Down
3 changes: 3 additions & 0 deletions cmd/options/controller_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,13 @@ type ControllerOptions struct {
ExtraVolumeTags map[string]string
// ID of the kubernetes cluster.
KubernetesClusterID string
// flag to enable sdk debug log
AwsSdkDebugLog bool
}

func (s *ControllerOptions) AddFlags(fs *flag.FlagSet) {
fs.Var(cliflag.NewMapStringString(&s.ExtraTags), "extra-tags", "Extra tags to attach to each dynamically provisioned resource. It is a comma separated list of key value pairs like '<key1>=<value1>,<key2>=<value2>'")
fs.Var(cliflag.NewMapStringString(&s.ExtraVolumeTags), "extra-volume-tags", "DEPRECATED: Please use --extra-tags instead. Extra volume tags to attach to each dynamically provisioned volume. It is a comma separated list of key value pairs like '<key1>=<value1>,<key2>=<value2>'")
fs.StringVar(&s.KubernetesClusterID, "k8s-tag-cluster-id", "", "ID of the Kubernetes cluster used for tagging provisioned EBS volumes (optional).")
fs.BoolVar(&s.AwsSdkDebugLog, "aws-sdk-debug-log", false, "To enable the aws sdk debug log level (default to false).")
}
5 changes: 5 additions & 0 deletions cmd/options/controller_options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ func TestControllerOptions(t *testing.T) {
flag: "k8s-tag-cluster-id",
found: true,
},
{
name: "lookup aws-sdk-debug-log",
flag: "aws-sdk-debug-log",
found: true,
},
{
name: "fail for non-desired flag",
flag: "some-other-flag",
Expand Down
10 changes: 10 additions & 0 deletions cmd/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ func TestGetOptions(t *testing.T) {
extraTagKey: extraTagValue,
}

awsSdkDebugFlagName := "aws-sdk-debug-log"
awsSdkDebugFlagValue := true
VolumeAttachLimitFlagName := "volume-attach-limit"
var VolumeAttachLimit int64 = 42

Expand All @@ -58,6 +60,7 @@ func TestGetOptions(t *testing.T) {
}
if withControllerOptions {
args = append(args, "-"+extraTagsFlagName+"="+extraTagKey+"="+extraTagValue)
args = append(args, "-"+awsSdkDebugFlagName+"="+strconv.FormatBool(awsSdkDebugFlagValue))
}
if withNodeOptions {
args = append(args, "-"+VolumeAttachLimitFlagName+"="+strconv.FormatInt(VolumeAttachLimit, 10))
Expand Down Expand Up @@ -87,6 +90,13 @@ func TestGetOptions(t *testing.T) {
if !reflect.DeepEqual(options.ControllerOptions.ExtraTags, extraTags) {
t.Fatalf("expected extra tags to be %q but it is %q", extraTags, options.ControllerOptions.ExtraTags)
}
awsDebugLogFlag := flagSet.Lookup(awsSdkDebugFlagName)
if awsDebugLogFlag == nil {
t.Fatalf("expected %q flag to be added but it is not", awsSdkDebugFlagName)
}
if options.ControllerOptions.AwsSdkDebugLog != awsSdkDebugFlagValue {
t.Fatalf("expected sdk debug flag to be %v but it is %v", awsSdkDebugFlagValue, options.ControllerOptions.AwsSdkDebugLog)
}
}

if withNodeOptions {
Expand Down
5 changes: 5 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@ helm upgrade --install aws-ebs-csi-driver \
--set enableVolumeSnapshot=true \
aws-ebs-csi-driver/aws-ebs-csi-driver
```

#### Deploy driver with debug mode
To view driver debug logs, run the CSI driver with `-v=5` command line option
To enable aws sdk debug logs, run the CSI driver with `--aws-sdk-debug-log=true` command line option.

## Examples
Make sure you follow the [Prerequisites](README.md#Prerequisites) before the examples:
* [Dynamic Provisioning](../examples/kubernetes/dynamic-provisioning)
Expand Down
26 changes: 15 additions & 11 deletions pkg/cloud/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,11 @@ var _ Cloud = &cloud{}

// NewCloud returns a new instance of AWS cloud
// It panics if session is invalid
func NewCloud(region string) (Cloud, error) {
return newEC2Cloud(region)
func NewCloud(region string, awsSdkDebugLog bool) (Cloud, error) {
return newEC2Cloud(region, awsSdkDebugLog)
}

func newEC2Cloud(region string) (Cloud, error) {
func newEC2Cloud(region string, awsSdkDebugLog bool) (Cloud, error) {
awsConfig := &aws.Config{
Region: aws.String(region),
CredentialsChainVerboseErrors: aws.Bool(true),
Expand All @@ -256,6 +256,10 @@ func newEC2Cloud(region string) (Cloud, error) {
awsConfig.Endpoint = aws.String(endpoint)
}

if awsSdkDebugLog {
awsConfig.WithLogLevel(aws.LogDebugWithRequestErrors)
}

return &cloud{
region: region,
dm: dm.NewDeviceManager(),
Expand Down Expand Up @@ -310,9 +314,9 @@ func (c *cloud) CreateDisk(ctx context.Context, volumeName string, diskOptions *

zone := diskOptions.AvailabilityZone
if zone == "" {
klog.V(5).Infof("AZ is not provided. Using node AZ [%s]", zone)
var err error
zone, err = c.randomAvailabilityZone(ctx)
klog.V(5).Infof("[Debug] AZ is not provided. Using node AZ [%s]", zone)
if err != nil {
return nil, fmt.Errorf("failed to get availability zone %s", err)
}
Expand Down Expand Up @@ -370,7 +374,7 @@ func (c *cloud) CreateDisk(ctx context.Context, volumeName string, diskOptions *
if _, error := c.DeleteDisk(ctx, volumeID); error != nil {
klog.Errorf("%v failed to be deleted, this may cause volume leak", volumeID)
} else {
klog.V(5).Infof("%v is deleted because it is not in desired state within retry limit", volumeID)
klog.V(5).Infof("[Debug] %v is deleted because it is not in desired state within retry limit", volumeID)
}
return nil, fmt.Errorf("failed to get an available volume in EC2: %v", err)
}
Expand Down Expand Up @@ -419,7 +423,7 @@ func (c *cloud) AttachDisk(ctx context.Context, volumeID, nodeID string) (string
}
return "", fmt.Errorf("could not attach volume %q to node %q: %v", volumeID, nodeID, err)
}
klog.V(5).Infof("AttachVolume volume=%q instance=%q request returned %v", volumeID, nodeID, resp)
klog.V(5).Infof("[Debug] AttachVolume volume=%q instance=%q request returned %v", volumeID, nodeID, resp)

}

Expand Down Expand Up @@ -952,7 +956,7 @@ func (c *cloud) ResizeDisk(ctx context.Context, volumeID string, newSizeBytes in
// Even if existing volume size is greater than user requested size, we should ensure that there are no pending
// volume modifications objects or volume has completed previously issued modification request.
if oldSizeGiB >= newSizeGiB {
klog.V(5).Infof("Volume %q current size (%d GiB) is greater or equal to the new size (%d GiB)", volumeID, oldSizeGiB, newSizeGiB)
klog.V(5).Infof("[Debug] Volume %q current size (%d GiB) is greater or equal to the new size (%d GiB)", volumeID, oldSizeGiB, newSizeGiB)
_, err = c.waitForVolumeSize(ctx, volumeID)
if err != nil && err != VolumeNotBeingModified {
return oldSizeGiB, err
Expand All @@ -965,7 +969,7 @@ func (c *cloud) ResizeDisk(ctx context.Context, volumeID string, newSizeBytes in
Size: aws.Int64(newSizeGiB),
}

klog.Infof("expanding volume %q to size %d", volumeID, newSizeGiB)
klog.V(4).Infof("expanding volume %q to size %d", volumeID, newSizeGiB)
response, err := c.ec2.ModifyVolumeWithContext(ctx, req)
if err != nil {
return 0, fmt.Errorf("could not modify AWS volume %q: %v", volumeID, err)
Expand Down Expand Up @@ -1106,18 +1110,18 @@ func capIOPS(volumeType string, requestedCapacityGiB int64, requstedIOPSPerGB, m
if iops < minTotalIOPS {
if allowIncrease {
iops = minTotalIOPS
klog.V(5).Infof("Increased IOPS for %s %d GB volume to the min supported limit: %d", volumeType, requestedCapacityGiB, iops)
klog.V(5).Infof("[Debug] Increased IOPS for %s %d GB volume to the min supported limit: %d", volumeType, requestedCapacityGiB, iops)
} else {
return 0, fmt.Errorf("invalid combination of volume size %d GB and iopsPerGB %d: the resulting IOPS %d is too low for AWS, it must be at least %d", requestedCapacityGiB, requstedIOPSPerGB, iops, minTotalIOPS)
}
}
if iops > maxTotalIOPS {
iops = maxTotalIOPS
klog.V(5).Infof("Capped IOPS for %s %d GB volume at the max supported limit: %d", volumeType, requestedCapacityGiB, iops)
klog.V(5).Infof("[Debug] Capped IOPS for %s %d GB volume at the max supported limit: %d", volumeType, requestedCapacityGiB, iops)
}
if iops > maxIOPSPerGB*requestedCapacityGiB {
iops = maxIOPSPerGB * requestedCapacityGiB
klog.V(5).Infof("Capped IOPS for %s %d GB volume at %d IOPS/GB: %d", volumeType, requestedCapacityGiB, maxIOPSPerGB, iops)
klog.V(5).Infof("[Debug] Capped IOPS for %s %d GB volume at %d IOPS/GB: %d", volumeType, requestedCapacityGiB, maxIOPSPerGB, iops)
}
return iops, nil
}
22 changes: 22 additions & 0 deletions pkg/cloud/cloud_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,22 @@ func TestCreateDisk(t *testing.T) {
},
expErr: nil,
},
{
name: "success: normal with gp2 options",
volumeName: "vol-test-name",
diskOptions: &DiskOptions{
CapacityBytes: util.GiBToBytes(1),
VolumeType: VolumeTypeGP2,
Tags: map[string]string{VolumeNameTagKey: "vol-test"},
},
expCreateVolumeInput: &ec2.CreateVolumeInput{},
expDisk: &Disk{
VolumeID: "vol-test",
CapacityGiB: 1,
AvailabilityZone: defaultZone,
},
expErr: nil,
},
{
name: "success: normal with io2 options",
volumeName: "vol-test-name",
Expand Down Expand Up @@ -531,6 +547,12 @@ func TestAttachDisk(t *testing.T) {
nodeID: "node-1234",
expErr: fmt.Errorf(""),
},
{
name: "fail: AttachVolume returned error volumeInUse",
volumeID: "vol-test-1234",
nodeID: "node-1234",
expErr: awserr.New("VolumeInUse", "Volume is in use", nil),
},
}

for _, tc := range testCases {
Expand Down
2 changes: 1 addition & 1 deletion pkg/cloud/devicemanager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ func (d *deviceManager) release(device *Device) error {
return fmt.Errorf("release on device %q assigned to different volume: %q vs %q", device.Path, device.VolumeID, existingVolumeID)
}

klog.V(5).Infof("Releasing in-process attachment entry: %v -> volume %s", device.Path, device.VolumeID)
klog.V(5).Infof("[Debug] Releasing in-process attachment entry: %v -> volume %s", device.Path, device.VolumeID)
d.inFlight.Del(nodeID, name)

return nil
Expand Down
9 changes: 5 additions & 4 deletions pkg/driver/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,21 @@ var (
func newControllerService(driverOptions *DriverOptions) controllerService {
region := os.Getenv("AWS_REGION")
if region == "" {
klog.V(5).Infof("[Debug] Retrieving region from metadata service")
metadata, err := NewMetadataFunc()
if err != nil {
panic(err)
}
region = metadata.GetRegion()
}

cloud, err := NewCloudFunc(region)
cloudSrv, err := NewCloudFunc(region, driverOptions.awsSdkDebugLog)
if err != nil {
panic(err)
}

return controllerService{
cloud: cloud,
cloud: cloudSrv,
inFlight: internal.NewInFlight(),
driverOptions: driverOptions,
}
Expand Down Expand Up @@ -323,7 +324,7 @@ func (d *controllerService) ControllerPublishVolume(ctx context.Context, req *cs
// TODO: Check volume capability matches for ALREADY_EXISTS
return nil, status.Errorf(codes.Internal, "Could not attach volume %q to node %q: %v", volumeID, nodeID, err)
}
klog.V(5).Infof("ControllerPublishVolume: volume %s attached to node %s through device %s", volumeID, nodeID, devicePath)
klog.V(5).Infof("[Debug] ControllerPublishVolume: volume %s attached to node %s through device %s", volumeID, nodeID, devicePath)

pvInfo := map[string]string{DevicePathKey: devicePath}
return &csi.ControllerPublishVolumeResponse{PublishContext: pvInfo}, nil
Expand All @@ -347,7 +348,7 @@ func (d *controllerService) ControllerUnpublishVolume(ctx context.Context, req *
}
return nil, status.Errorf(codes.Internal, "Could not detach volume %q from node %q: %v", volumeID, nodeID, err)
}
klog.V(5).Infof("ControllerUnpublishVolume: volume %s detached from node %s", volumeID, nodeID)
klog.V(5).Infof("[Debug] ControllerUnpublishVolume: volume %s detached from node %s", volumeID, nodeID)

return &csi.ControllerUnpublishVolumeResponse{}, nil
}
Expand Down
14 changes: 7 additions & 7 deletions pkg/driver/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ func TestNewControllerService(t *testing.T) {
testErr = errors.New("test error")
testRegion = "test-region"

getNewCloudFunc = func(expectedRegion string) func(region string) (cloud.Cloud, error) {
return func(region string) (cloud.Cloud, error) {
getNewCloudFunc = func(expectedRegion string, awsSdkDebugLog bool) func(region string, awsSdkDebugLog bool) (cloud.Cloud, error) {
return func(region string, awsSdkDebugLog bool) (cloud.Cloud, error) {
if region != expectedRegion {
t.Fatalf("expected region %q but got %q", expectedRegion, region)
}
Expand All @@ -63,30 +63,30 @@ func TestNewControllerService(t *testing.T) {
testCases := []struct {
name string
region string
newCloudFunc func(string) (cloud.Cloud, error)
newCloudFunc func(string, bool) (cloud.Cloud, error)
newMetadataFuncErrors bool
expectPanic bool
}{
{
name: "AWS_REGION variable set, newCloud does not error",
region: "foo",
newCloudFunc: getNewCloudFunc("foo"),
newCloudFunc: getNewCloudFunc("foo", false),
},
{
name: "AWS_REGION variable set, newCloud errors",
region: "foo",
newCloudFunc: func(region string) (cloud.Cloud, error) {
newCloudFunc: func(region string, awsSdkDebugLog bool) (cloud.Cloud, error) {
return nil, testErr
},
expectPanic: true,
},
{
name: "AWS_REGION variable not set, newMetadata does not error",
newCloudFunc: getNewCloudFunc(testRegion),
newCloudFunc: getNewCloudFunc(testRegion, false),
},
{
name: "AWS_REGION variable not set, newMetadata errors",
newCloudFunc: getNewCloudFunc(testRegion),
newCloudFunc: getNewCloudFunc(testRegion, false),
newMetadataFuncErrors: true,
expectPanic: true,
},
Expand Down
12 changes: 9 additions & 3 deletions pkg/driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,11 @@ type DriverOptions struct {
mode Mode
volumeAttachLimit int64
kubernetesClusterID string
awsSdkDebugLog bool
}

func NewDriver(options ...func(*DriverOptions)) (*Driver, error) {
klog.Infof("Driver: %v Version: %v", DriverName, driverVersion)
klog.V(4).Infof("Driver: %v Version: %v", DriverName, driverVersion)

driverOptions := DriverOptions{
endpoint: DefaultCSIEndpoint,
Expand Down Expand Up @@ -138,12 +139,11 @@ func (d *Driver) Run() error {
return fmt.Errorf("unknown mode: %s", d.options.mode)
}

klog.Infof("Listening for connections on address: %#v", listener.Addr())
klog.V(4).Infof("Listening for connections on address: %#v", listener.Addr())
return d.srv.Serve(listener)
}

func (d *Driver) Stop() {
klog.Infof("Stopping server")
d.srv.Stop()
}

Expand Down Expand Up @@ -185,3 +185,9 @@ func WithKubernetesClusterID(clusterID string) func(*DriverOptions) {
o.kubernetesClusterID = clusterID
}
}

func WithAwsSdkDebugLog(enableSdkDebugLog bool) func(*DriverOptions) {
return func(o *DriverOptions) {
o.awsSdkDebugLog = enableSdkDebugLog
}
}
9 changes: 9 additions & 0 deletions pkg/driver/driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,12 @@ func TestWithClusterID(t *testing.T) {
t.Fatalf("expected kubernetesClusterID option got set to %s but is set to %s", id, options.kubernetesClusterID)
}
}

func TestWithAwsSdkDebugLog(t *testing.T) {
var enableSdkDebugLog bool = true
options := &DriverOptions{}
WithAwsSdkDebugLog(enableSdkDebugLog)(options)
if options.awsSdkDebugLog != enableSdkDebugLog {
t.Fatalf("expected awsSdkDebugLog option got set to %v but is set to %v", enableSdkDebugLog, options.awsSdkDebugLog)
}
}
Loading

0 comments on commit 79e9ff0

Please sign in to comment.