AWS zone on volume IDs
Signed-off-by: Travis Sturzl<travis@metismachine.com>pull/1274/head
parent
394548afcd
commit
89ca2571f3
|
@ -0,0 +1 @@
|
||||||
|
AWS EBS Volume IDs now contain AZ
|
|
@ -17,6 +17,7 @@ limitations under the License.
|
||||||
package aws
|
package aws
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -282,7 +283,13 @@ func (b *blockStore) SetVolumeID(unstructuredPV runtime.Unstructured, volumeID s
|
||||||
return nil, errors.New("spec.awsElasticBlockStore not found")
|
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)
|
res, err := runtime.DefaultUnstructuredConverter.ToUnstructured(pv)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -85,7 +85,44 @@ func TestSetVolumeID(t *testing.T) {
|
||||||
pv.Object["spec"] = map[string]interface{}{
|
pv.Object["spec"] = map[string]interface{}{
|
||||||
"awsElasticBlockStore": aws,
|
"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")
|
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)
|
require.NoError(t, err)
|
||||||
|
|
||||||
res := new(v1.PersistentVolume)
|
res := new(v1.PersistentVolume)
|
||||||
|
|
Loading…
Reference in New Issue