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
9326e845
Commit
9326e845
authored
Jan 26, 2018
by
edisonxiang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support GetLabelsForVolume In OpenStack
parent
d352fc6f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
12 deletions
+45
-12
BUILD
pkg/cloudprovider/providers/openstack/BUILD
+1
-0
openstack_volumes.go
pkg/cloudprovider/providers/openstack/openstack_volumes.go
+44
-12
No files found.
pkg/cloudprovider/providers/openstack/BUILD
View file @
9326e845
...
@@ -24,6 +24,7 @@ go_library(
...
@@ -24,6 +24,7 @@ go_library(
"//pkg/apis/core/v1/helper:go_default_library",
"//pkg/apis/core/v1/helper:go_default_library",
"//pkg/cloudprovider:go_default_library",
"//pkg/cloudprovider:go_default_library",
"//pkg/controller:go_default_library",
"//pkg/controller:go_default_library",
"//pkg/kubelet/apis:go_default_library",
"//pkg/util/mount:go_default_library",
"//pkg/util/mount:go_default_library",
"//pkg/volume:go_default_library",
"//pkg/volume:go_default_library",
"//pkg/volume/util:go_default_library",
"//pkg/volume/util:go_default_library",
...
...
pkg/cloudprovider/providers/openstack/openstack_volumes.go
View file @
9326e845
...
@@ -25,8 +25,11 @@ import (
...
@@ -25,8 +25,11 @@ import (
"strings"
"strings"
"time"
"time"
"k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
"k8s.io/apimachinery/pkg/api/resource"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/types"
"k8s.io/kubernetes/pkg/cloudprovider"
kubeletapis
"k8s.io/kubernetes/pkg/kubelet/apis"
k8s_volume
"k8s.io/kubernetes/pkg/volume"
k8s_volume
"k8s.io/kubernetes/pkg/volume"
volumeutil
"k8s.io/kubernetes/pkg/volume/util"
volumeutil
"k8s.io/kubernetes/pkg/volume/util"
...
@@ -71,6 +74,8 @@ type Volume struct {
...
@@ -71,6 +74,8 @@ type Volume struct {
AttachedServerId
string
AttachedServerId
string
// Device file path
// Device file path
AttachedDevice
string
AttachedDevice
string
// AvailabilityZone is which availability zone the volume is in
AvailabilityZone
string
// Unique identifier for the volume.
// Unique identifier for the volume.
ID
string
ID
string
// Human-readable display name for the volume.
// Human-readable display name for the volume.
...
@@ -89,6 +94,9 @@ type VolumeCreateOpts struct {
...
@@ -89,6 +94,9 @@ type VolumeCreateOpts struct {
Metadata
map
[
string
]
string
Metadata
map
[
string
]
string
}
}
// implements PVLabeler.
var
_
cloudprovider
.
PVLabeler
=
(
*
OpenStack
)(
nil
)
const
(
const
(
VolumeAvailableStatus
=
"available"
VolumeAvailableStatus
=
"available"
VolumeInUseStatus
=
"in-use"
VolumeInUseStatus
=
"in-use"
...
@@ -171,10 +179,11 @@ func (volumes *VolumesV1) getVolume(volumeID string) (Volume, error) {
...
@@ -171,10 +179,11 @@ func (volumes *VolumesV1) getVolume(volumeID string) (Volume, error) {
}
}
volume
:=
Volume
{
volume
:=
Volume
{
ID
:
volumeV1
.
ID
,
AvailabilityZone
:
volumeV1
.
AvailabilityZone
,
Name
:
volumeV1
.
Name
,
ID
:
volumeV1
.
ID
,
Status
:
volumeV1
.
Status
,
Name
:
volumeV1
.
Name
,
Size
:
volumeV1
.
Size
,
Status
:
volumeV1
.
Status
,
Size
:
volumeV1
.
Size
,
}
}
if
len
(
volumeV1
.
Attachments
)
>
0
&&
volumeV1
.
Attachments
[
0
][
"server_id"
]
!=
nil
{
if
len
(
volumeV1
.
Attachments
)
>
0
&&
volumeV1
.
Attachments
[
0
][
"server_id"
]
!=
nil
{
...
@@ -195,10 +204,11 @@ func (volumes *VolumesV2) getVolume(volumeID string) (Volume, error) {
...
@@ -195,10 +204,11 @@ func (volumes *VolumesV2) getVolume(volumeID string) (Volume, error) {
}
}
volume
:=
Volume
{
volume
:=
Volume
{
ID
:
volumeV2
.
ID
,
AvailabilityZone
:
volumeV2
.
AvailabilityZone
,
Name
:
volumeV2
.
Name
,
ID
:
volumeV2
.
ID
,
Status
:
volumeV2
.
Status
,
Name
:
volumeV2
.
Name
,
Size
:
volumeV2
.
Size
,
Status
:
volumeV2
.
Status
,
Size
:
volumeV2
.
Size
,
}
}
if
len
(
volumeV2
.
Attachments
)
>
0
{
if
len
(
volumeV2
.
Attachments
)
>
0
{
...
@@ -219,10 +229,10 @@ func (volumes *VolumesV3) getVolume(volumeID string) (Volume, error) {
...
@@ -219,10 +229,10 @@ func (volumes *VolumesV3) getVolume(volumeID string) (Volume, error) {
}
}
volume
:=
Volume
{
volume
:=
Volume
{
ID
:
volumeV3
.
ID
,
AvailabilityZone
:
volumeV3
.
AvailabilityZone
,
Name
:
volumeV3
.
Name
,
ID
:
volumeV3
.
ID
,
Status
:
volumeV3
.
Status
,
Name
:
volumeV3
.
Name
,
S
ize
:
volumeV3
.
Size
,
S
tatus
:
volumeV3
.
Status
,
}
}
if
len
(
volumeV3
.
Attachments
)
>
0
{
if
len
(
volumeV3
.
Attachments
)
>
0
{
...
@@ -680,6 +690,28 @@ func (os *OpenStack) ShouldTrustDevicePath() bool {
...
@@ -680,6 +690,28 @@ func (os *OpenStack) ShouldTrustDevicePath() bool {
return
os
.
bsOpts
.
TrustDevicePath
return
os
.
bsOpts
.
TrustDevicePath
}
}
// GetLabelsForVolume implements PVLabeler.GetLabelsForVolume
func
(
os
*
OpenStack
)
GetLabelsForVolume
(
pv
*
v1
.
PersistentVolume
)
(
map
[
string
]
string
,
error
)
{
// Ignore any volumes that are being provisioned
if
pv
.
Spec
.
Cinder
.
VolumeID
==
k8s_volume
.
ProvisionedVolumeName
{
return
nil
,
nil
}
// Get Volume
volume
,
err
:=
os
.
getVolume
(
pv
.
Spec
.
Cinder
.
VolumeID
)
if
err
!=
nil
{
return
nil
,
err
}
// Contruct Volume Labels
labels
:=
make
(
map
[
string
]
string
)
labels
[
kubeletapis
.
LabelZoneFailureDomain
]
=
volume
.
AvailabilityZone
labels
[
kubeletapis
.
LabelZoneRegion
]
=
os
.
region
glog
.
V
(
4
)
.
Infof
(
"The Volume %s has labels %v"
,
pv
.
Spec
.
Cinder
.
VolumeID
,
labels
)
return
labels
,
nil
}
// recordOpenstackOperationMetric records openstack operation metrics
// recordOpenstackOperationMetric records openstack operation metrics
func
recordOpenstackOperationMetric
(
operation
string
,
timeTaken
float64
,
err
error
)
{
func
recordOpenstackOperationMetric
(
operation
string
,
timeTaken
float64
,
err
error
)
{
if
err
!=
nil
{
if
err
!=
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