Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
28c2a531
Unverified
Commit
28c2a531
authored
Mar 05, 2019
by
Kubernetes Prow Robot
Committed by
GitHub
Mar 05, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #74858 from leakingtapan/ebs-id
Add CSI migration logic for EBS Volume ID format
parents
596a48dd
001d9c69
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
133 additions
and
41 deletions
+133
-41
BUILD
pkg/cloudprovider/providers/aws/BUILD
+1
-0
volumes.go
pkg/cloudprovider/providers/aws/volumes.go
+3
-39
BUILD
staging/src/k8s.io/csi-translation-lib/plugins/BUILD
+7
-1
aws_ebs.go
staging/src/k8s.io/csi-translation-lib/plugins/aws_ebs.go
+56
-1
aws_ebs_test.go
...ng/src/k8s.io/csi-translation-lib/plugins/aws_ebs_test.go
+66
-0
No files found.
pkg/cloudprovider/providers/aws/BUILD
View file @
28c2a531
...
@@ -45,6 +45,7 @@ go_library(
...
@@ -45,6 +45,7 @@ go_library(
"//staging/src/k8s.io/cloud-provider/volume:go_default_library",
"//staging/src/k8s.io/cloud-provider/volume:go_default_library",
"//staging/src/k8s.io/cloud-provider/volume/errors:go_default_library",
"//staging/src/k8s.io/cloud-provider/volume/errors:go_default_library",
"//staging/src/k8s.io/cloud-provider/volume/helpers:go_default_library",
"//staging/src/k8s.io/cloud-provider/volume/helpers:go_default_library",
"//staging/src/k8s.io/csi-translation-lib/plugins:go_default_library",
"//vendor/github.com/aws/aws-sdk-go/aws:go_default_library",
"//vendor/github.com/aws/aws-sdk-go/aws:go_default_library",
"//vendor/github.com/aws/aws-sdk-go/aws/awserr:go_default_library",
"//vendor/github.com/aws/aws-sdk-go/aws/awserr:go_default_library",
"//vendor/github.com/aws/aws-sdk-go/aws/credentials:go_default_library",
"//vendor/github.com/aws/aws-sdk-go/aws/credentials:go_default_library",
...
...
pkg/cloudprovider/providers/aws/volumes.go
View file @
28c2a531
...
@@ -18,20 +18,15 @@ package aws
...
@@ -18,20 +18,15 @@ package aws
import
(
import
(
"fmt"
"fmt"
"net/url"
"regexp"
"strings"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/aws/aws-sdk-go/service/ec2"
csimigration
"k8s.io/csi-translation-lib/plugins"
"k8s.io/klog"
"k8s.io/klog"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/types"
)
)
// awsVolumeRegMatch represents Regex Match for AWS volume.
var
awsVolumeRegMatch
=
regexp
.
MustCompile
(
"^vol-[^/]*$"
)
// EBSVolumeID represents the ID of the volume in the AWS API, e.g.
// EBSVolumeID represents the ID of the volume in the AWS API, e.g.
// vol-12345678 The "traditional" format is "vol-12345678" A new longer format
// vol-12345678 The "traditional" format is "vol-12345678" A new longer format
// is also being introduced: "vol-12345678abcdef01" We should not assume
// is also being introduced: "vol-12345678abcdef01" We should not assume
...
@@ -62,41 +57,10 @@ type diskInfo struct {
...
@@ -62,41 +57,10 @@ type diskInfo struct {
// MapToAWSVolumeID extracts the EBSVolumeID from the KubernetesVolumeID
// MapToAWSVolumeID extracts the EBSVolumeID from the KubernetesVolumeID
func
(
name
KubernetesVolumeID
)
MapToAWSVolumeID
()
(
EBSVolumeID
,
error
)
{
func
(
name
KubernetesVolumeID
)
MapToAWSVolumeID
()
(
EBSVolumeID
,
error
)
{
// name looks like aws://availability-zone/awsVolumeId
awsID
,
err
:=
csimigration
.
KubernetesVolumeIDToEBSVolumeID
(
string
(
name
))
// The original idea of the URL-style name was to put the AZ into the
// host, so we could find the AZ immediately from the name without
// querying the API. But it turns out we don't actually need it for
// multi-AZ clusters, as we put the AZ into the labels on the PV instead.
// However, if in future we want to support multi-AZ cluster
// volume-awareness without using PersistentVolumes, we likely will
// want the AZ in the host.
s
:=
string
(
name
)
if
!
strings
.
HasPrefix
(
s
,
"aws://"
)
{
// Assume a bare aws volume id (vol-1234...)
// Build a URL with an empty host (AZ)
s
=
"aws://"
+
""
+
"/"
+
s
}
url
,
err
:=
url
.
Parse
(
s
)
if
err
!=
nil
{
if
err
!=
nil
{
// TODO: Maybe we should pass a URL into the Volume functions
return
""
,
err
return
""
,
fmt
.
Errorf
(
"Invalid disk name (%s): %v"
,
name
,
err
)
}
}
if
url
.
Scheme
!=
"aws"
{
return
""
,
fmt
.
Errorf
(
"Invalid scheme for AWS volume (%s)"
,
name
)
}
awsID
:=
url
.
Path
awsID
=
strings
.
Trim
(
awsID
,
"/"
)
// We sanity check the resulting volume; the two known formats are
// vol-12345678 and vol-12345678abcdef01
if
!
awsVolumeRegMatch
.
MatchString
(
awsID
)
{
return
""
,
fmt
.
Errorf
(
"Invalid format for AWS volume (%s)"
,
name
)
}
return
EBSVolumeID
(
awsID
),
nil
return
EBSVolumeID
(
awsID
),
nil
}
}
...
...
staging/src/k8s.io/csi-translation-lib/plugins/BUILD
View file @
28c2a531
load("@io_bazel_rules_go//go:def.bzl", "go_library")
load("@io_bazel_rules_go//go:def.bzl", "go_library"
, "go_test"
)
go_library(
go_library(
name = "go_default_library",
name = "go_default_library",
...
@@ -31,3 +31,9 @@ filegroup(
...
@@ -31,3 +31,9 @@ filegroup(
tags = ["automanaged"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
visibility = ["//visibility:public"],
)
)
go_test(
name = "go_default_test",
srcs = ["aws_ebs_test.go"],
embed = [":go_default_library"],
)
staging/src/k8s.io/csi-translation-lib/plugins/aws_ebs.go
View file @
28c2a531
...
@@ -18,7 +18,10 @@ package plugins
...
@@ -18,7 +18,10 @@ package plugins
import
(
import
(
"fmt"
"fmt"
"net/url"
"regexp"
"strconv"
"strconv"
"strings"
"k8s.io/api/core/v1"
"k8s.io/api/core/v1"
)
)
...
@@ -54,9 +57,14 @@ func (t *awsElasticBlockStoreCSITranslator) TranslateInTreePVToCSI(pv *v1.Persis
...
@@ -54,9 +57,14 @@ func (t *awsElasticBlockStoreCSITranslator) TranslateInTreePVToCSI(pv *v1.Persis
ebsSource
:=
pv
.
Spec
.
AWSElasticBlockStore
ebsSource
:=
pv
.
Spec
.
AWSElasticBlockStore
volumeHandle
,
err
:=
KubernetesVolumeIDToEBSVolumeID
(
ebsSource
.
VolumeID
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"failed to translate Kubernetes ID to EBS Volume ID %v"
,
err
)
}
csiSource
:=
&
v1
.
CSIPersistentVolumeSource
{
csiSource
:=
&
v1
.
CSIPersistentVolumeSource
{
Driver
:
AWSEBSDriverName
,
Driver
:
AWSEBSDriverName
,
VolumeHandle
:
ebsSource
.
VolumeID
,
VolumeHandle
:
volumeHandle
,
ReadOnly
:
ebsSource
.
ReadOnly
,
ReadOnly
:
ebsSource
.
ReadOnly
,
FSType
:
ebsSource
.
FSType
,
FSType
:
ebsSource
.
FSType
,
VolumeAttributes
:
map
[
string
]
string
{
VolumeAttributes
:
map
[
string
]
string
{
...
@@ -113,3 +121,50 @@ func (t *awsElasticBlockStoreCSITranslator) GetInTreePluginName() string {
...
@@ -113,3 +121,50 @@ func (t *awsElasticBlockStoreCSITranslator) GetInTreePluginName() string {
func
(
t
*
awsElasticBlockStoreCSITranslator
)
GetCSIPluginName
()
string
{
func
(
t
*
awsElasticBlockStoreCSITranslator
)
GetCSIPluginName
()
string
{
return
AWSEBSDriverName
return
AWSEBSDriverName
}
}
// awsVolumeRegMatch represents Regex Match for AWS volume.
var
awsVolumeRegMatch
=
regexp
.
MustCompile
(
"^vol-[^/]*$"
)
// KubernetesVolumeIDToEBSVolumeID translates Kubernetes volume ID to EBS volume ID
// KubernetsVolumeID forms:
// * aws://<zone>/<awsVolumeId>
// * aws:///<awsVolumeId>
// * <awsVolumeId>
// EBS Volume ID form:
// * vol-<alphanumberic>
// This translation shouldn't be needed and should be fixed in long run
// See https://github.com/kubernetes/kubernetes/issues/73730
func
KubernetesVolumeIDToEBSVolumeID
(
kubernetesID
string
)
(
string
,
error
)
{
// name looks like aws://availability-zone/awsVolumeId
// The original idea of the URL-style name was to put the AZ into the
// host, so we could find the AZ immediately from the name without
// querying the API. But it turns out we don't actually need it for
// multi-AZ clusters, as we put the AZ into the labels on the PV instead.
// However, if in future we want to support multi-AZ cluster
// volume-awareness without using PersistentVolumes, we likely will
// want the AZ in the host.
if
!
strings
.
HasPrefix
(
kubernetesID
,
"aws://"
)
{
// Assume a bare aws volume id (vol-1234...)
return
kubernetesID
,
nil
}
url
,
err
:=
url
.
Parse
(
kubernetesID
)
if
err
!=
nil
{
// TODO: Maybe we should pass a URL into the Volume functions
return
""
,
fmt
.
Errorf
(
"Invalid disk name (%s): %v"
,
kubernetesID
,
err
)
}
if
url
.
Scheme
!=
"aws"
{
return
""
,
fmt
.
Errorf
(
"Invalid scheme for AWS volume (%s)"
,
kubernetesID
)
}
awsID
:=
url
.
Path
awsID
=
strings
.
Trim
(
awsID
,
"/"
)
// We sanity check the resulting volume; the two known formats are
// vol-12345678 and vol-12345678abcdef01
if
!
awsVolumeRegMatch
.
MatchString
(
awsID
)
{
return
""
,
fmt
.
Errorf
(
"Invalid format for AWS volume (%s)"
,
kubernetesID
)
}
return
awsID
,
nil
}
staging/src/k8s.io/csi-translation-lib/plugins/aws_ebs_test.go
0 → 100644
View file @
28c2a531
/*
Copyright 2019 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package
plugins
import
(
"testing"
)
func
TestKubernetesVolumeIDToEBSVolumeID
(
t
*
testing
.
T
)
{
testCases
:=
[]
struct
{
name
string
kubernetesID
string
ebsVolumeID
string
expErr
bool
}{
{
name
:
"Normal ID format"
,
kubernetesID
:
"vol-02399794d890f9375"
,
ebsVolumeID
:
"vol-02399794d890f9375"
,
},
{
name
:
"aws:///{volumeId} format"
,
kubernetesID
:
"aws:///vol-02399794d890f9375"
,
ebsVolumeID
:
"vol-02399794d890f9375"
,
},
{
name
:
"aws://{zone}/{volumeId} format"
,
kubernetesID
:
"aws://us-west-2a/vol-02399794d890f9375"
,
ebsVolumeID
:
"vol-02399794d890f9375"
,
},
{
name
:
"fails on invalid volume ID"
,
kubernetesID
:
"aws://us-west-2a/02399794d890f9375"
,
expErr
:
true
,
},
}
for
_
,
tc
:=
range
testCases
{
t
.
Run
(
tc
.
name
,
func
(
t
*
testing
.
T
)
{
actual
,
err
:=
KubernetesVolumeIDToEBSVolumeID
(
tc
.
kubernetesID
)
if
err
!=
nil
{
if
!
tc
.
expErr
{
t
.
Errorf
(
"KubernetesVolumeIDToEBSVolumeID failed %v"
,
err
)
}
}
else
{
if
actual
!=
tc
.
ebsVolumeID
{
t
.
Errorf
(
"Wrong EBS Volume ID. actual: %s expected: %s"
,
actual
,
tc
.
ebsVolumeID
)
}
}
})
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment