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
8d5052ed
Unverified
Commit
8d5052ed
authored
May 29, 2019
by
Kubernetes Prow Robot
Committed by
GitHub
May 29, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #78330 from andyzhangx/csi-translation-azuredisk
Add support for Azure Disk to csi-translation-lib
parents
eb2b5d37
6f2902e0
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
278 additions
and
4 deletions
+278
-4
kube_features.go
pkg/features/kube_features.go
+7
-0
azure_dd.go
pkg/volume/azure_dd/azure_dd.go
+4
-1
BUILD
staging/src/k8s.io/csi-translation-lib/plugins/BUILD
+2
-0
azure_disk.go
staging/src/k8s.io/csi-translation-lib/plugins/azure_disk.go
+168
-0
azure_disk_test.go
...src/k8s.io/csi-translation-lib/plugins/azure_disk_test.go
+93
-0
translate.go
staging/src/k8s.io/csi-translation-lib/translate.go
+4
-3
No files found.
pkg/features/kube_features.go
View file @
8d5052ed
...
...
@@ -417,6 +417,12 @@ const (
// Enables the AWS EBS in-tree driver to AWS EBS CSI Driver migration feature.
CSIMigrationAWS
featuregate
.
Feature
=
"CSIMigrationAWS"
// owner: @andyzhangx
// alpha: v1.15
//
// Enables the Azure Disk in-tree driver to Azure Disk Driver migration feature.
CSIMigrationAzureDisk
featuregate
.
Feature
=
"CSIMigrationAzureDisk"
// owner: @RobertKrawitz
// beta: v1.15
//
...
...
@@ -496,6 +502,7 @@ var defaultKubernetesFeatureGates = map[featuregate.Feature]featuregate.FeatureS
CSIMigration
:
{
Default
:
false
,
PreRelease
:
featuregate
.
Alpha
},
CSIMigrationGCE
:
{
Default
:
false
,
PreRelease
:
featuregate
.
Alpha
},
CSIMigrationAWS
:
{
Default
:
false
,
PreRelease
:
featuregate
.
Alpha
},
CSIMigrationAzureDisk
:
{
Default
:
false
,
PreRelease
:
featuregate
.
Alpha
},
RunAsGroup
:
{
Default
:
true
,
PreRelease
:
featuregate
.
Beta
},
CSIMigrationOpenStack
:
{
Default
:
false
,
PreRelease
:
featuregate
.
Alpha
},
VolumeSubpath
:
{
Default
:
true
,
PreRelease
:
featuregate
.
GA
},
...
...
pkg/volume/azure_dd/azure_dd.go
View file @
8d5052ed
...
...
@@ -29,6 +29,8 @@ import (
"k8s.io/apimachinery/pkg/api/resource"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/sets"
utilfeature
"k8s.io/apiserver/pkg/util/feature"
"k8s.io/kubernetes/pkg/features"
"k8s.io/kubernetes/pkg/volume"
"k8s.io/kubernetes/pkg/volume/util"
"k8s.io/legacy-cloud-providers/azure"
...
...
@@ -119,7 +121,8 @@ func (plugin *azureDataDiskPlugin) CanSupport(spec *volume.Spec) bool {
}
func
(
plugin
*
azureDataDiskPlugin
)
IsMigratedToCSI
()
bool
{
return
false
return
utilfeature
.
DefaultFeatureGate
.
Enabled
(
features
.
CSIMigration
)
&&
utilfeature
.
DefaultFeatureGate
.
Enabled
(
features
.
CSIMigrationAzureDisk
)
}
func
(
plugin
*
azureDataDiskPlugin
)
RequiresRemount
()
bool
{
...
...
staging/src/k8s.io/csi-translation-lib/plugins/BUILD
View file @
8d5052ed
...
...
@@ -4,6 +4,7 @@ go_library(
name = "go_default_library",
srcs = [
"aws_ebs.go",
"azure_disk.go",
"gce_pd.go",
"in_tree_volume.go",
"openstack_cinder.go",
...
...
@@ -37,6 +38,7 @@ go_test(
name = "go_default_test",
srcs = [
"aws_ebs_test.go",
"azure_disk_test.go",
"gce_pd_test.go",
],
embed = [":go_default_library"],
...
...
staging/src/k8s.io/csi-translation-lib/plugins/azure_disk.go
0 → 100644
View file @
8d5052ed
/*
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
(
"fmt"
"regexp"
"strings"
"k8s.io/api/core/v1"
storage
"k8s.io/api/storage/v1"
)
const
(
// AzureDiskDriverName is the name of the CSI driver for Azure Disk
AzureDiskDriverName
=
"disk.csi.azure.com"
// AzureDiskInTreePluginName is the name of the intree plugin for Azure Disk
AzureDiskInTreePluginName
=
"kubernetes.io/azure-disk"
// Parameter names defined in azure disk CSI driver, refer to
// https://github.com/kubernetes-sigs/azuredisk-csi-driver/blob/master/docs/driver-parameters.md
azureDiskCachingMode
=
"cachingMode"
azureDiskFSType
=
"fsType"
)
var
(
managedDiskPathRE
=
regexp
.
MustCompile
(
`.*/subscriptions/(?:.*)/resourceGroups/(?:.*)/providers/Microsoft.Compute/disks/(.+)`
)
unmanagedDiskPathRE
=
regexp
.
MustCompile
(
`http(?:.*)://(?:.*)/vhds/(.+)`
)
)
var
_
InTreePlugin
=
&
azureDiskCSITranslator
{}
// azureDiskCSITranslator handles translation of PV spec from In-tree
// Azure Disk to CSI Azure Disk and vice versa
type
azureDiskCSITranslator
struct
{}
// NewAzureDiskCSITranslator returns a new instance of azureDiskTranslator
func
NewAzureDiskCSITranslator
()
InTreePlugin
{
return
&
azureDiskCSITranslator
{}
}
// TranslateInTreeStorageClassParametersToCSI translates InTree Azure Disk storage class parameters to CSI storage class
func
(
t
*
azureDiskCSITranslator
)
TranslateInTreeStorageClassToCSI
(
sc
*
storage
.
StorageClass
)
(
*
storage
.
StorageClass
,
error
)
{
return
sc
,
nil
}
// TranslateInTreePVToCSI takes a PV with AzureDisk set from in-tree
// and converts the AzureDisk source to a CSIPersistentVolumeSource
func
(
t
*
azureDiskCSITranslator
)
TranslateInTreePVToCSI
(
pv
*
v1
.
PersistentVolume
)
(
*
v1
.
PersistentVolume
,
error
)
{
if
pv
==
nil
||
pv
.
Spec
.
AzureDisk
==
nil
{
return
nil
,
fmt
.
Errorf
(
"pv is nil or Azure Disk source not defined on pv"
)
}
azureSource
:=
pv
.
Spec
.
PersistentVolumeSource
.
AzureDisk
// refer to https://github.com/kubernetes-sigs/azuredisk-csi-driver/blob/master/docs/driver-parameters.md
csiSource
:=
&
v1
.
CSIPersistentVolumeSource
{
Driver
:
AzureDiskDriverName
,
VolumeHandle
:
azureSource
.
DataDiskURI
,
ReadOnly
:
*
azureSource
.
ReadOnly
,
FSType
:
*
azureSource
.
FSType
,
VolumeAttributes
:
map
[
string
]
string
{},
}
if
*
azureSource
.
CachingMode
!=
""
{
csiSource
.
VolumeAttributes
[
azureDiskCachingMode
]
=
string
(
*
azureSource
.
CachingMode
)
}
if
*
azureSource
.
FSType
!=
""
{
csiSource
.
VolumeAttributes
[
azureDiskFSType
]
=
*
azureSource
.
FSType
}
pv
.
Spec
.
PersistentVolumeSource
.
AzureDisk
=
nil
pv
.
Spec
.
PersistentVolumeSource
.
CSI
=
csiSource
pv
.
Spec
.
AccessModes
=
backwardCompatibleAccessModes
(
pv
.
Spec
.
AccessModes
)
return
pv
,
nil
}
// TranslateCSIPVToInTree takes a PV with CSIPersistentVolumeSource set and
// translates the Azure Disk CSI source to a AzureDisk source.
func
(
t
*
azureDiskCSITranslator
)
TranslateCSIPVToInTree
(
pv
*
v1
.
PersistentVolume
)
(
*
v1
.
PersistentVolume
,
error
)
{
if
pv
==
nil
||
pv
.
Spec
.
CSI
==
nil
{
return
nil
,
fmt
.
Errorf
(
"pv is nil or CSI source not defined on pv"
)
}
csiSource
:=
pv
.
Spec
.
CSI
diskURI
:=
csiSource
.
VolumeHandle
diskName
,
err
:=
getDiskName
(
diskURI
)
if
err
!=
nil
{
return
nil
,
err
}
// refer to https://github.com/kubernetes-sigs/azuredisk-csi-driver/blob/master/docs/driver-parameters.md
azureSource
:=
&
v1
.
AzureDiskVolumeSource
{
DiskName
:
diskName
,
DataDiskURI
:
diskURI
,
FSType
:
&
csiSource
.
FSType
,
ReadOnly
:
&
csiSource
.
ReadOnly
,
}
if
csiSource
.
VolumeAttributes
!=
nil
{
if
cachingMode
,
ok
:=
csiSource
.
VolumeAttributes
[
azureDiskCachingMode
];
ok
{
mode
:=
v1
.
AzureDataDiskCachingMode
(
cachingMode
)
azureSource
.
CachingMode
=
&
mode
}
if
fsType
,
ok
:=
csiSource
.
VolumeAttributes
[
azureDiskFSType
];
ok
&&
fsType
!=
""
{
azureSource
.
FSType
=
&
fsType
}
}
pv
.
Spec
.
CSI
=
nil
pv
.
Spec
.
AzureDisk
=
azureSource
return
pv
,
nil
}
// CanSupport tests whether the plugin supports a given volume
// specification from the API. The spec pointer should be considered
// const.
func
(
t
*
azureDiskCSITranslator
)
CanSupport
(
pv
*
v1
.
PersistentVolume
)
bool
{
return
pv
!=
nil
&&
pv
.
Spec
.
AzureDisk
!=
nil
}
// GetInTreePluginName returns the name of the intree plugin driver
func
(
t
*
azureDiskCSITranslator
)
GetInTreePluginName
()
string
{
return
AzureDiskInTreePluginName
}
// GetCSIPluginName returns the name of the CSI plugin
func
(
t
*
azureDiskCSITranslator
)
GetCSIPluginName
()
string
{
return
AzureDiskDriverName
}
func
isManagedDisk
(
diskURI
string
)
bool
{
if
len
(
diskURI
)
>
4
&&
strings
.
ToLower
(
diskURI
[
:
4
])
==
"http"
{
return
false
}
return
true
}
func
getDiskName
(
diskURI
string
)
(
string
,
error
)
{
diskPathRE
:=
managedDiskPathRE
if
!
isManagedDisk
(
diskURI
)
{
diskPathRE
=
unmanagedDiskPathRE
}
matches
:=
diskPathRE
.
FindStringSubmatch
(
diskURI
)
if
len
(
matches
)
!=
2
{
return
""
,
fmt
.
Errorf
(
"could not get disk name from %s, correct format: %s"
,
diskURI
,
diskPathRE
)
}
return
matches
[
1
],
nil
}
staging/src/k8s.io/csi-translation-lib/plugins/azure_disk_test.go
0 → 100644
View file @
8d5052ed
/*
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
(
"fmt"
"reflect"
"testing"
)
func
TestIsManagedDisk
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
options
string
expected
bool
}{
{
options
:
"testurl/subscriptions/12/resourceGroups/23/providers/Microsoft.Compute/disks/name"
,
expected
:
true
,
},
{
options
:
"test.com"
,
expected
:
true
,
},
{
options
:
"HTTP://test.com"
,
expected
:
false
,
},
{
options
:
"http://test.com/vhds/name"
,
expected
:
false
,
},
}
for
_
,
test
:=
range
tests
{
result
:=
isManagedDisk
(
test
.
options
)
if
!
reflect
.
DeepEqual
(
result
,
test
.
expected
)
{
t
.
Errorf
(
"input: %q, isManagedDisk result: %t, expected: %t"
,
test
.
options
,
result
,
test
.
expected
)
}
}
}
func
TestGetDiskName
(
t
*
testing
.
T
)
{
mDiskPathRE
:=
managedDiskPathRE
uDiskPathRE
:=
unmanagedDiskPathRE
tests
:=
[]
struct
{
options
string
expected1
string
expected2
error
}{
{
options
:
"testurl/subscriptions/12/resourceGroups/23/providers/Microsoft.Compute/disks/name"
,
expected1
:
"name"
,
expected2
:
nil
,
},
{
options
:
"testurl/subscriptions/23/providers/Microsoft.Compute/disks/name"
,
expected1
:
""
,
expected2
:
fmt
.
Errorf
(
"could not get disk name from testurl/subscriptions/23/providers/Microsoft.Compute/disks/name, correct format: %s"
,
mDiskPathRE
),
},
{
options
:
"http://test.com/vhds/name"
,
expected1
:
"name"
,
expected2
:
nil
,
},
{
options
:
"http://test.io/name"
,
expected1
:
""
,
expected2
:
fmt
.
Errorf
(
"could not get disk name from http://test.io/name, correct format: %s"
,
uDiskPathRE
),
},
}
for
_
,
test
:=
range
tests
{
result1
,
result2
:=
getDiskName
(
test
.
options
)
if
!
reflect
.
DeepEqual
(
result1
,
test
.
expected1
)
||
!
reflect
.
DeepEqual
(
result2
,
test
.
expected2
)
{
t
.
Errorf
(
"input: %q, getDiskName result1: %q, expected1: %q, result2: %q, expected2: %q"
,
test
.
options
,
result1
,
test
.
expected1
,
result2
,
test
.
expected2
)
}
}
}
staging/src/k8s.io/csi-translation-lib/translate.go
View file @
8d5052ed
...
...
@@ -27,9 +27,10 @@ import (
var
(
inTreePlugins
=
map
[
string
]
plugins
.
InTreePlugin
{
plugins
.
GCEPDDriverName
:
plugins
.
NewGCEPersistentDiskCSITranslator
(),
plugins
.
AWSEBSDriverName
:
plugins
.
NewAWSElasticBlockStoreCSITranslator
(),
plugins
.
CinderDriverName
:
plugins
.
NewOpenStackCinderCSITranslator
(),
plugins
.
GCEPDDriverName
:
plugins
.
NewGCEPersistentDiskCSITranslator
(),
plugins
.
AWSEBSDriverName
:
plugins
.
NewAWSElasticBlockStoreCSITranslator
(),
plugins
.
CinderDriverName
:
plugins
.
NewOpenStackCinderCSITranslator
(),
plugins
.
AzureDiskDriverName
:
plugins
.
NewAzureDiskCSITranslator
(),
}
)
...
...
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