Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
coverage.txt
.idea/
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ vendor-tidy:
vendor:
go mod vendor

lint:
(mkdir -p tools && cd tools && GO111MODULE=off && go get -v golang.org/x/lint/golint)
$(GOPATH)/bin/golint:
GO111MODULE=off go get -u golang.org/x/lint/golint
lint: $(GOPATH)/bin/golint
for file in $$(find . -name '*.go' | grep -v vendor | \
grep -v '\.pb\.go' | \
grep -v '\.pb\.gw\.go' | \
Expand Down
51 changes: 37 additions & 14 deletions aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,19 +322,21 @@ func (s *awsOps) InspectInstanceGroupForInstance(instanceID string) (*cloudops.I
return nil, &cloudops.ErrNoInstanceGroup{}
}

func (s *awsOps) ApplyTags(volumeID string, labels map[string]string) error {
func (s *awsOps) ApplyTags(volumeID string, labels map[string]string, options map[string]string) error {
req := &ec2.CreateTagsInput{
Resources: []*string{&volumeID},
Tags: s.tags(labels),
DryRun: dryRun(options),
}
_, err := s.ec2.CreateTags(req)
return err
}

func (s *awsOps) RemoveTags(volumeID string, labels map[string]string) error {
func (s *awsOps) RemoveTags(volumeID string, labels map[string]string, options map[string]string) error {
req := &ec2.DeleteTagsInput{
Resources: []*string{&volumeID},
Tags: s.tags(labels),
DryRun: dryRun(options),
}
_, err := s.ec2.DeleteTags(req)
return err
Expand Down Expand Up @@ -660,15 +662,15 @@ func (s *awsOps) FreeDevices(

func (s *awsOps) rollbackCreate(id string, createErr error) error {
logrus.Warnf("Rollback create volume %v, Error %v", id, createErr)
err := s.Delete(id)
err := s.Delete(id, nil)
if err != nil {
logrus.Warnf("Rollback failed volume %v, Error %v", id, err)
}
return createErr
}

func (s *awsOps) refreshVol(id *string) (*ec2.Volume, error) {
vols, err := s.Inspect([]*string{id})
vols, err := s.Inspect([]*string{id}, nil)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -707,8 +709,11 @@ func (s *awsOps) GetDeviceID(vol interface{}) (string, error) {
}
}

func (s *awsOps) Inspect(volumeIds []*string) ([]interface{}, error) {
req := &ec2.DescribeVolumesInput{VolumeIds: volumeIds}
func (s *awsOps) Inspect(volumeIds []*string, options map[string]string) ([]interface{}, error) {
req := &ec2.DescribeVolumesInput{
VolumeIds: volumeIds,
DryRun: dryRun(options),
}
resp, err := s.ec2.DescribeVolumes(req)
if err != nil {
return nil, err
Expand Down Expand Up @@ -739,6 +744,7 @@ func (s *awsOps) Enumerate(
volumeIds []*string,
labels map[string]string,
setIdentifier string,

) (map[string][]interface{}, error) {
sets := make(map[string][]interface{})

Expand Down Expand Up @@ -778,6 +784,7 @@ func (s *awsOps) Enumerate(
func (s *awsOps) Create(
v interface{},
labels map[string]string,
options map[string]string,
) (interface{}, error) {
vol, ok := v.(*ec2.Volume)
if !ok {
Expand All @@ -797,6 +804,7 @@ func (s *awsOps) Create(
VolumeType: vol.VolumeType,
SnapshotId: vol.SnapshotId,
Throughput: vol.Throughput,
DryRun: dryRun(options),
}

if len(s.outpostARN) > 0 {
Expand Down Expand Up @@ -846,11 +854,14 @@ func (s *awsOps) Create(
}

func (s *awsOps) DeleteFrom(id, _ string) error {
return s.Delete(id)
return s.Delete(id, nil)
}

func (s *awsOps) Delete(id string) error {
req := &ec2.DeleteVolumeInput{VolumeId: &id}
func (s *awsOps) Delete(id string, options map[string]string) error {
req := &ec2.DeleteVolumeInput{
VolumeId: &id,
DryRun: dryRun(options),
}
_, err := s.ec2.DeleteVolume(req)
return err
}
Expand Down Expand Up @@ -879,6 +890,7 @@ func (s *awsOps) Attach(volumeID string, options map[string]string) (string, err
Device: &device,
InstanceId: &s.instance,
VolumeId: &volumeID,
DryRun: dryRun(options),
}
if _, err := s.ec2.AttachVolume(req); err != nil {
if strings.Contains(err.Error(), "is already in use") {
Expand All @@ -904,20 +916,21 @@ func (s *awsOps) Attach(volumeID string, options map[string]string) (string, err
return "", fmt.Errorf("failed to attach any of the free devices. Attempted: %v", devices)
}

func (s *awsOps) Detach(volumeID string) error {
return s.detachInternal(volumeID, s.instance)
func (s *awsOps) Detach(volumeID string, options map[string]string) error {
return s.detachInternal(volumeID, s.instance, options)
}

func (s *awsOps) DetachFrom(volumeID, instanceName string) error {
return s.detachInternal(volumeID, instanceName)
return s.detachInternal(volumeID, instanceName, nil)
}

func (s *awsOps) detachInternal(volumeID, instanceName string) error {
func (s *awsOps) detachInternal(volumeID, instanceName string, options map[string]string) error {
force := false
req := &ec2.DetachVolumeInput{
InstanceId: &instanceName,
VolumeId: &volumeID,
Force: &force,
DryRun: dryRun(options),
}
if _, err := s.ec2.DetachVolume(req); err != nil {
return err
Expand All @@ -932,6 +945,7 @@ func (s *awsOps) detachInternal(volumeID, instanceName string) error {
func (s *awsOps) Expand(
volumeID string,
newSizeInGiB uint64,
options map[string]string,
) (uint64, error) {
vol, err := s.refreshVol(&volumeID)
if err != nil {
Expand All @@ -948,6 +962,7 @@ func (s *awsOps) Expand(
request := &ec2.ModifyVolumeInput{
VolumeId: vol.VolumeId,
Size: &newSizeInGiBInt64,
DryRun: dryRun(options),
}
output, err := s.ec2.ModifyVolume(request)
if err != nil {
Expand Down Expand Up @@ -995,16 +1010,19 @@ func (s *awsOps) Expand(
func (s *awsOps) Snapshot(
volumeID string,
readonly bool,
options map[string]string,
) (interface{}, error) {
request := &ec2.CreateSnapshotInput{
VolumeId: &volumeID,
DryRun: dryRun(options),
}
return s.ec2.CreateSnapshot(request)
}

func (s *awsOps) SnapshotDelete(snapID string) error {
func (s *awsOps) SnapshotDelete(snapID string, options map[string]string) error {
request := &ec2.DeleteSnapshotInput{
SnapshotId: &snapID,
DryRun: dryRun(options),
}

_, err := s.ec2.DeleteSnapshot(request)
Expand Down Expand Up @@ -1201,3 +1219,8 @@ func reverse(a []string) []string {

return reversed
}

func dryRun(options map[string]string) *bool {
_, ok := options[cloudops.DryRunOption]
return &ok
}
22 changes: 12 additions & 10 deletions azure/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ func (a *azureOps) SetInstanceGroupSize(instanceGroupID string,

instanceGroupSize := int32(count)
agentPoolProperties := containerservice.ManagedClusterAgentPoolProfileProperties{
Count: &instanceGroupSize,
Count: &instanceGroupSize,
OsType: containerservice.Linux,
}

Expand All @@ -368,6 +368,7 @@ func (a *azureOps) SetInstanceGroupSize(instanceGroupID string,
func (a *azureOps) Create(
template interface{},
labels map[string]string,
options map[string]string,
) (interface{}, error) {
d, ok := template.(*compute.Disk)
if !ok {
Expand Down Expand Up @@ -494,7 +495,7 @@ func (a *azureOps) handleAttachError(err error) error {
// but did not succeed. We need to explicitly remove it to proceed.
matches := attachFailureMessageRegex.FindStringSubmatch(re.ServiceError.Message)
if len(matches) == 2 {
detachErr := a.Detach(matches[1])
detachErr := a.Detach(matches[1], nil)
if detachErr != nil {
logrus.Warnf("Failed to detach disk %v: %v", matches[1], detachErr)
}
Expand All @@ -504,7 +505,7 @@ func (a *azureOps) handleAttachError(err error) error {
return err
}

func (a *azureOps) Detach(diskName string) error {
func (a *azureOps) Detach(diskName string, options map[string]string) error {
return a.detachInternal(diskName, a.instance)
}

Expand Down Expand Up @@ -559,7 +560,7 @@ func (a *azureOps) detachInternal(diskName, instance string) error {
return a.waitForDetach(diskName, instance)
}

func (a *azureOps) Delete(diskName string) error {
func (a *azureOps) Delete(diskName string, options map[string]string) error {
ctx := context.Background()
future, err := a.disksClient.Delete(ctx, a.resourceGroupName, diskName)
if err != nil {
Expand All @@ -576,12 +577,13 @@ func (a *azureOps) Delete(diskName string) error {
}

func (a *azureOps) DeleteFrom(diskName, _ string) error {
return a.Delete(diskName)
return a.Delete(diskName, nil)
}

func (a *azureOps) Expand(
diskName string,
newSizeInGiB uint64,
options map[string]string,
) (uint64, error) {
disk, err := a.disksClient.Get(
context.Background(),
Expand Down Expand Up @@ -644,7 +646,7 @@ func (a *azureOps) FreeDevices(
}
}

func (a *azureOps) Inspect(diskNames []*string) ([]interface{}, error) {
func (a *azureOps) Inspect(diskNames []*string, options map[string]string) ([]interface{}, error) {
var disks []interface{}

for _, diskName := range diskNames {
Expand Down Expand Up @@ -823,7 +825,7 @@ func (a *azureOps) devicePath(diskName string) (string, error) {
)
}

func (a *azureOps) Snapshot(diskName string, readonly bool) (interface{}, error) {
func (a *azureOps) Snapshot(diskName string, readonly bool, options map[string]string) (interface{}, error) {
if !readonly {
return nil, fmt.Errorf("read-write snapshots are not supported in Azure")
}
Expand Down Expand Up @@ -861,7 +863,7 @@ func (a *azureOps) Snapshot(diskName string, readonly bool) (interface{}, error)
return &snap, err
}

func (a *azureOps) SnapshotDelete(snapName string) error {
func (a *azureOps) SnapshotDelete(snapName string, options map[string]string) error {
ctx := context.Background()
future, err := a.snapshotsClient.Delete(ctx, a.resourceGroupName, snapName)
if err != nil {
Expand All @@ -877,7 +879,7 @@ func (a *azureOps) SnapshotDelete(snapName string) error {
return err
}

func (a *azureOps) ApplyTags(diskName string, labels map[string]string) error {
func (a *azureOps) ApplyTags(diskName string, labels map[string]string, options map[string]string) error {
if len(labels) == 0 {
return nil
}
Expand Down Expand Up @@ -921,7 +923,7 @@ func (a *azureOps) ApplyTags(diskName string, labels map[string]string) error {
return err
}

func (a *azureOps) RemoveTags(diskName string, labels map[string]string) error {
func (a *azureOps) RemoveTags(diskName string, labels map[string]string, options map[string]string) error {
if len(labels) == 0 {
return nil
}
Expand Down
Loading