Skip to content

Commit

Permalink
Merge pull request #1274 from MetisMachine/aws-new
Browse files Browse the repository at this point in the history
AWS: Inclue zone in volume ID
  • Loading branch information
skriss committed Mar 12, 2019
2 parents 394548a + 89ca257 commit b286c65
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelogs/unreleased/1274-tsturzl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
AWS EBS Volume IDs now contain AZ
9 changes: 8 additions & 1 deletion pkg/cloudprovider/aws/block_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package aws

import (
"fmt"
"os"
"regexp"
"strings"
Expand Down Expand Up @@ -282,7 +283,13 @@ func (b *blockStore) SetVolumeID(unstructuredPV runtime.Unstructured, volumeID s
return nil, errors.New("spec.awsElasticBlockStore not found")
}

pv.Spec.AWSElasticBlockStore.VolumeID = volumeID
pvFailureDomainZone := pv.Labels["failure-domain.beta.kubernetes.io/zone"]

if len(pvFailureDomainZone) > 0 {
pv.Spec.AWSElasticBlockStore.VolumeID = fmt.Sprintf("aws://%s/%s", pvFailureDomainZone, volumeID)
} else {
pv.Spec.AWSElasticBlockStore.VolumeID = volumeID
}

res, err := runtime.DefaultUnstructuredConverter.ToUnstructured(pv)
if err != nil {
Expand Down
37 changes: 37 additions & 0 deletions pkg/cloudprovider/aws/block_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,44 @@ func TestSetVolumeID(t *testing.T) {
pv.Object["spec"] = map[string]interface{}{
"awsElasticBlockStore": aws,
}

labels := map[string]interface{}{
"failure-domain.beta.kubernetes.io/zone": "us-east-1a",
}

pv.Object["metadata"] = map[string]interface{}{
"labels": labels,
}

updatedPV, err = b.SetVolumeID(pv, "vol-updated")

require.NoError(t, err)

res := new(v1.PersistentVolume)
require.NoError(t, runtime.DefaultUnstructuredConverter.FromUnstructured(updatedPV.UnstructuredContent(), res))
require.NotNil(t, res.Spec.AWSElasticBlockStore)
assert.Equal(t, "aws://us-east-1a/vol-updated", res.Spec.AWSElasticBlockStore.VolumeID)
}

func TestSetVolumeIDNoZone(t *testing.T) {
b := &blockStore{}

pv := &unstructured.Unstructured{
Object: map[string]interface{}{},
}

// missing spec.awsElasticBlockStore -> error
updatedPV, err := b.SetVolumeID(pv, "vol-updated")
require.Error(t, err)

// happy path
aws := map[string]interface{}{}
pv.Object["spec"] = map[string]interface{}{
"awsElasticBlockStore": aws,
}

updatedPV, err = b.SetVolumeID(pv, "vol-updated")

require.NoError(t, err)

res := new(v1.PersistentVolume)
Expand Down

0 comments on commit b286c65

Please sign in to comment.