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
87c58833
Commit
87c58833
authored
Jul 23, 2018
by
Pengfei Ni
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement GetLabelsForVolume for AzureDisk
parent
28b6fb5f
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
63 additions
and
0 deletions
+63
-0
azure.go
pkg/cloudprovider/providers/azure/azure.go
+3
-0
azure_managedDiskController.go
...udprovider/providers/azure/azure_managedDiskController.go
+60
-0
No files found.
pkg/cloudprovider/providers/azure/azure.go
View file @
87c58833
...
@@ -59,6 +59,9 @@ var (
...
@@ -59,6 +59,9 @@ var (
defaultExcludeMasterFromStandardLB
=
true
defaultExcludeMasterFromStandardLB
=
true
)
)
// Azure implements PVLabeler.
var
_
cloudprovider
.
PVLabeler
=
(
*
Cloud
)(
nil
)
// Config holds the configuration parsed from the --cloud-config flag
// Config holds the configuration parsed from the --cloud-config flag
// All fields are required unless otherwise specified
// All fields are required unless otherwise specified
type
Config
struct
{
type
Config
struct
{
...
...
pkg/cloudprovider/providers/azure/azure_managedDiskController.go
View file @
87c58833
...
@@ -17,16 +17,21 @@ limitations under the License.
...
@@ -17,16 +17,21 @@ limitations under the License.
package
azure
package
azure
import
(
import
(
"context"
"fmt"
"fmt"
"path"
"path"
"strconv"
"strings"
"strings"
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2018-04-01/compute"
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2018-04-01/compute"
"github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2017-10-01/storage"
"github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2017-10-01/storage"
"github.com/golang/glog"
"github.com/golang/glog"
"k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
"k8s.io/apimachinery/pkg/api/resource"
kwait
"k8s.io/apimachinery/pkg/util/wait"
kwait
"k8s.io/apimachinery/pkg/util/wait"
kubeletapis
"k8s.io/kubernetes/pkg/kubelet/apis"
"k8s.io/kubernetes/pkg/volume"
"k8s.io/kubernetes/pkg/volume/util"
"k8s.io/kubernetes/pkg/volume/util"
)
)
...
@@ -201,3 +206,58 @@ func getResourceGroupFromDiskURI(diskURI string) (string, error) {
...
@@ -201,3 +206,58 @@ func getResourceGroupFromDiskURI(diskURI string) (string, error) {
}
}
return
fields
[
4
],
nil
return
fields
[
4
],
nil
}
}
// GetLabelsForVolume implements PVLabeler.GetLabelsForVolume
func
(
c
*
Cloud
)
GetLabelsForVolume
(
ctx
context
.
Context
,
pv
*
v1
.
PersistentVolume
)
(
map
[
string
]
string
,
error
)
{
// Ignore if not AzureDisk.
if
pv
.
Spec
.
AzureDisk
==
nil
{
return
nil
,
nil
}
// Ignore any volumes that are being provisioned
if
pv
.
Spec
.
AzureDisk
.
DiskName
==
volume
.
ProvisionedVolumeName
{
return
nil
,
nil
}
return
c
.
GetAzureDiskLabels
(
pv
.
Spec
.
AzureDisk
.
DataDiskURI
)
}
// GetAzureDiskLabels gets availability zone labels for Azuredisk.
func
(
c
*
Cloud
)
GetAzureDiskLabels
(
diskURI
string
)
(
map
[
string
]
string
,
error
)
{
// Get disk's resource group.
diskName
:=
path
.
Base
(
diskURI
)
resourceGroup
,
err
:=
getResourceGroupFromDiskURI
(
diskURI
)
if
err
!=
nil
{
glog
.
Errorf
(
"Failed to get resource group for AzureDisk %q: %v"
,
diskName
,
err
)
return
nil
,
err
}
// Get information of the disk.
ctx
,
cancel
:=
getContextWithCancel
()
defer
cancel
()
disk
,
err
:=
c
.
DisksClient
.
Get
(
ctx
,
resourceGroup
,
diskName
)
if
err
!=
nil
{
glog
.
Errorf
(
"Failed to get information for AzureDisk %q: %v"
,
diskName
,
err
)
return
nil
,
err
}
// Check whether availability zone is specified.
if
disk
.
Zones
==
nil
||
len
(
*
disk
.
Zones
)
==
0
{
glog
.
V
(
4
)
.
Infof
(
"Azure disk %q is not zoned"
,
diskName
)
return
nil
,
nil
}
zones
:=
*
disk
.
Zones
zoneID
,
err
:=
strconv
.
Atoi
(
zones
[
0
])
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"failed to parse zone %v for AzureDisk %v: %v"
,
zones
,
diskName
,
err
)
}
zone
:=
c
.
makeZone
(
zoneID
)
glog
.
V
(
4
)
.
Infof
(
"Get zone %q for Azure disk %q"
,
zone
,
diskName
)
labels
:=
map
[
string
]
string
{
kubeletapis
.
LabelZoneRegion
:
c
.
Location
,
kubeletapis
.
LabelZoneFailureDomain
:
zone
,
}
return
labels
,
nil
}
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