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
29c5d6c7
Commit
29c5d6c7
authored
Jun 09, 2016
by
k8s-merge-robot
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #26848 from pmorie/wrap-volumes
Automatic merge from submit-queue Wrap more comments in pkg/volume Wrap some more comments in `pkg/volume`
parents
a5cd171c
6415c2d2
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
34 additions
and
24 deletions
+34
-24
metrics_cached.go
pkg/volume/metrics_cached.go
+10
-5
metrics_du.go
pkg/volume/metrics_du.go
+6
-4
metrics_nil.go
pkg/volume/metrics_nil.go
+3
-2
util.go
pkg/volume/util.go
+15
-13
No files found.
pkg/volume/metrics_cached.go
View file @
29c5d6c7
...
@@ -23,7 +23,8 @@ import (
...
@@ -23,7 +23,8 @@ import (
var
_
MetricsProvider
=
&
cachedMetrics
{}
var
_
MetricsProvider
=
&
cachedMetrics
{}
// cachedMetrics represents a MetricsProvider that wraps another provider and caches the result.
// cachedMetrics represents a MetricsProvider that wraps another provider and
// caches the result.
type
cachedMetrics
struct
{
type
cachedMetrics
struct
{
wrapped
MetricsProvider
wrapped
MetricsProvider
resultError
error
resultError
error
...
@@ -31,13 +32,15 @@ type cachedMetrics struct {
...
@@ -31,13 +32,15 @@ type cachedMetrics struct {
once
cacheOnce
once
cacheOnce
}
}
// NewCachedMetrics creates a new cachedMetrics wrapping another MetricsProvider and caching the results.
// NewCachedMetrics creates a new cachedMetrics wrapping another
// MetricsProvider and caching the results.
func
NewCachedMetrics
(
provider
MetricsProvider
)
MetricsProvider
{
func
NewCachedMetrics
(
provider
MetricsProvider
)
MetricsProvider
{
return
&
cachedMetrics
{
wrapped
:
provider
}
return
&
cachedMetrics
{
wrapped
:
provider
}
}
}
// GetMetrics runs the wrapped metrics provider's GetMetrics methd once and
// caches the result. Will not cache result if there is an error.
// See MetricsProvider.GetMetrics
// See MetricsProvider.GetMetrics
// Runs GetMetrics Once and caches the result. Will not cache result if there is an error.
func
(
md
*
cachedMetrics
)
GetMetrics
()
(
*
Metrics
,
error
)
{
func
(
md
*
cachedMetrics
)
GetMetrics
()
(
*
Metrics
,
error
)
{
md
.
once
.
cache
(
func
()
error
{
md
.
once
.
cache
(
func
()
error
{
md
.
resultMetrics
,
md
.
resultError
=
md
.
wrapped
.
GetMetrics
()
md
.
resultMetrics
,
md
.
resultError
=
md
.
wrapped
.
GetMetrics
()
...
@@ -46,13 +49,15 @@ func (md *cachedMetrics) GetMetrics() (*Metrics, error) {
...
@@ -46,13 +49,15 @@ func (md *cachedMetrics) GetMetrics() (*Metrics, error) {
return
md
.
resultMetrics
,
md
.
resultError
return
md
.
resultMetrics
,
md
.
resultError
}
}
// Copied from sync.Once but we don't want to cache the results if there is an error
// Copied from sync.Once but we don't want to cache the results if there is an
// error
type
cacheOnce
struct
{
type
cacheOnce
struct
{
m
sync
.
Mutex
m
sync
.
Mutex
done
uint32
done
uint32
}
}
// Copied from sync.Once but we don't want to cache the results if there is an error
// Copied from sync.Once but we don't want to cache the results if there is an
// error
func
(
o
*
cacheOnce
)
cache
(
f
func
()
error
)
{
func
(
o
*
cacheOnce
)
cache
(
f
func
()
error
)
{
if
atomic
.
LoadUint32
(
&
o
.
done
)
==
1
{
if
atomic
.
LoadUint32
(
&
o
.
done
)
==
1
{
return
return
...
...
pkg/volume/metrics_du.go
View file @
29c5d6c7
...
@@ -26,8 +26,9 @@ import (
...
@@ -26,8 +26,9 @@ import (
var
_
MetricsProvider
=
&
metricsDu
{}
var
_
MetricsProvider
=
&
metricsDu
{}
// metricsDu represents a MetricsProvider that calculates the used and available
// metricsDu represents a MetricsProvider that calculates the used and
// Volume space by executing the "du" command and gathering filesystem info for the Volume path.
// available Volume space by executing the "du" command and gathering
// filesystem info for the Volume path.
type
metricsDu
struct
{
type
metricsDu
struct
{
// the directory path the volume is mounted to.
// the directory path the volume is mounted to.
path
string
path
string
...
@@ -38,9 +39,9 @@ func NewMetricsDu(path string) MetricsProvider {
...
@@ -38,9 +39,9 @@ func NewMetricsDu(path string) MetricsProvider {
return
&
metricsDu
{
path
}
return
&
metricsDu
{
path
}
}
}
// See MetricsProvider.GetMetrics
// GetMetrics calculates the volume usage and device free space by executing "du"
// GetMetrics calculates the volume usage and device free space by executing "du"
// and gathering filesystem info for the Volume path.
// and gathering filesystem info for the Volume path.
// See MetricsProvider.GetMetrics
func
(
md
*
metricsDu
)
GetMetrics
()
(
*
Metrics
,
error
)
{
func
(
md
*
metricsDu
)
GetMetrics
()
(
*
Metrics
,
error
)
{
metrics
:=
&
Metrics
{}
metrics
:=
&
Metrics
{}
if
md
.
path
==
""
{
if
md
.
path
==
""
{
...
@@ -70,7 +71,8 @@ func (md *metricsDu) runDu(metrics *Metrics) error {
...
@@ -70,7 +71,8 @@ func (md *metricsDu) runDu(metrics *Metrics) error {
return
nil
return
nil
}
}
// getFsInfo writes metrics.Capacity and metrics.Available from the filesystem info
// getFsInfo writes metrics.Capacity and metrics.Available from the filesystem
// info
func
(
md
*
metricsDu
)
getFsInfo
(
metrics
*
Metrics
)
error
{
func
(
md
*
metricsDu
)
getFsInfo
(
metrics
*
Metrics
)
error
{
available
,
capacity
,
_
,
err
:=
util
.
FsInfo
(
md
.
path
)
available
,
capacity
,
_
,
err
:=
util
.
FsInfo
(
md
.
path
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
pkg/volume/metrics_nil.go
View file @
29c5d6c7
...
@@ -21,11 +21,12 @@ import "errors"
...
@@ -21,11 +21,12 @@ import "errors"
var
_
MetricsProvider
=
&
MetricsNil
{}
var
_
MetricsProvider
=
&
MetricsNil
{}
// MetricsNil represents a MetricsProvider that does not support returning
// MetricsNil represents a MetricsProvider that does not support returning
// Metrics. It serves as a placeholder for Volumes that do not yet support metrics.
// Metrics. It serves as a placeholder for Volumes that do not yet support
// metrics.
type
MetricsNil
struct
{}
type
MetricsNil
struct
{}
// See MetricsProvider.GetMetrics
// GetMetrics returns an empty Metrics and an error.
// GetMetrics returns an empty Metrics and an error.
// See MetricsProvider.GetMetrics
func
(
*
MetricsNil
)
GetMetrics
()
(
*
Metrics
,
error
)
{
func
(
*
MetricsNil
)
GetMetrics
()
(
*
Metrics
,
error
)
{
return
&
Metrics
{},
errors
.
New
(
"metrics are not supported for MetricsNil Volumes"
)
return
&
Metrics
{},
errors
.
New
(
"metrics are not supported for MetricsNil Volumes"
)
}
}
pkg/volume/util.go
View file @
29c5d6c7
...
@@ -39,8 +39,8 @@ import (
...
@@ -39,8 +39,8 @@ import (
// attempted before returning.
// attempted before returning.
//
//
// In case there is a pod with the same namespace+name already running, this
// In case there is a pod with the same namespace+name already running, this
// function assumes it's an older instance of the recycler pod and watches
this
// function assumes it's an older instance of the recycler pod and watches
// old pod instead of starting a new one.
//
this
old pod instead of starting a new one.
//
//
// pod - the pod designed by a volume plugin to recycle the volume. pod.Name
// pod - the pod designed by a volume plugin to recycle the volume. pod.Name
// will be overwritten with unique name based on PV.Name.
// will be overwritten with unique name based on PV.Name.
...
@@ -49,7 +49,8 @@ func RecycleVolumeByWatchingPodUntilCompletion(pvName string, pod *api.Pod, kube
...
@@ -49,7 +49,8 @@ func RecycleVolumeByWatchingPodUntilCompletion(pvName string, pod *api.Pod, kube
return
internalRecycleVolumeByWatchingPodUntilCompletion
(
pvName
,
pod
,
newRecyclerClient
(
kubeClient
))
return
internalRecycleVolumeByWatchingPodUntilCompletion
(
pvName
,
pod
,
newRecyclerClient
(
kubeClient
))
}
}
// same as above func comments, except 'recyclerClient' is a narrower pod API interface to ease testing
// same as above func comments, except 'recyclerClient' is a narrower pod API
// interface to ease testing
func
internalRecycleVolumeByWatchingPodUntilCompletion
(
pvName
string
,
pod
*
api
.
Pod
,
recyclerClient
recyclerClient
)
error
{
func
internalRecycleVolumeByWatchingPodUntilCompletion
(
pvName
string
,
pod
*
api
.
Pod
,
recyclerClient
recyclerClient
)
error
{
glog
.
V
(
5
)
.
Infof
(
"creating recycler pod for volume %s
\n
"
,
pod
.
Name
)
glog
.
V
(
5
)
.
Infof
(
"creating recycler pod for volume %s
\n
"
,
pod
.
Name
)
...
@@ -93,7 +94,7 @@ func internalRecycleVolumeByWatchingPodUntilCompletion(pvName string, pod *api.P
...
@@ -93,7 +94,7 @@ func internalRecycleVolumeByWatchingPodUntilCompletion(pvName string, pod *api.P
}
}
// recyclerClient abstracts access to a Pod by providing a narrower interface.
// recyclerClient abstracts access to a Pod by providing a narrower interface.
//
this makes it easier to mock a client for testing
//
This makes it easier to mock a client for testing.
type
recyclerClient
interface
{
type
recyclerClient
interface
{
CreatePod
(
pod
*
api
.
Pod
)
(
*
api
.
Pod
,
error
)
CreatePod
(
pod
*
api
.
Pod
)
(
*
api
.
Pod
,
error
)
GetPod
(
name
,
namespace
string
)
(
*
api
.
Pod
,
error
)
GetPod
(
name
,
namespace
string
)
(
*
api
.
Pod
,
error
)
...
@@ -122,8 +123,8 @@ func (c *realRecyclerClient) DeletePod(name, namespace string) error {
...
@@ -122,8 +123,8 @@ func (c *realRecyclerClient) DeletePod(name, namespace string) error {
}
}
// WatchPod returns a ListWatch for watching a pod. The stopChannel is used
// WatchPod returns a ListWatch for watching a pod. The stopChannel is used
// to close the reflector backing the watch. The caller is responsible for
derring a close on the channel to
// to close the reflector backing the watch. The caller is responsible for
// stop the reflector.
//
derring a close on the channel to
stop the reflector.
func
(
c
*
realRecyclerClient
)
WatchPod
(
name
,
namespace
string
,
stopChannel
chan
struct
{})
func
()
*
api
.
Pod
{
func
(
c
*
realRecyclerClient
)
WatchPod
(
name
,
namespace
string
,
stopChannel
chan
struct
{})
func
()
*
api
.
Pod
{
fieldSelector
,
_
:=
fields
.
ParseSelector
(
"metadata.name="
+
name
)
fieldSelector
,
_
:=
fields
.
ParseSelector
(
"metadata.name="
+
name
)
...
@@ -146,8 +147,10 @@ func (c *realRecyclerClient) WatchPod(name, namespace string, stopChannel chan s
...
@@ -146,8 +147,10 @@ func (c *realRecyclerClient) WatchPod(name, namespace string, stopChannel chan s
}
}
}
}
// CalculateTimeoutForVolume calculates time for a Recycler pod to complete a recycle operation.
// CalculateTimeoutForVolume calculates time for a Recycler pod to complete a
// The calculation and return value is either the minimumTimeout or the timeoutIncrement per Gi of storage size, whichever is greater.
// recycle operation. The calculation and return value is either the
// minimumTimeout or the timeoutIncrement per Gi of storage size, whichever is
// greater.
func
CalculateTimeoutForVolume
(
minimumTimeout
,
timeoutIncrement
int
,
pv
*
api
.
PersistentVolume
)
int64
{
func
CalculateTimeoutForVolume
(
minimumTimeout
,
timeoutIncrement
int
,
pv
*
api
.
PersistentVolume
)
int64
{
giQty
:=
resource
.
MustParse
(
"1Gi"
)
giQty
:=
resource
.
MustParse
(
"1Gi"
)
pvQty
:=
pv
.
Spec
.
Capacity
[
api
.
ResourceStorage
]
pvQty
:=
pv
.
Spec
.
Capacity
[
api
.
ResourceStorage
]
...
@@ -170,11 +173,10 @@ func RoundUpSize(volumeSizeBytes int64, allocationUnitBytes int64) int64 {
...
@@ -170,11 +173,10 @@ func RoundUpSize(volumeSizeBytes int64, allocationUnitBytes int64) int64 {
return
(
volumeSizeBytes
+
allocationUnitBytes
-
1
)
/
allocationUnitBytes
return
(
volumeSizeBytes
+
allocationUnitBytes
-
1
)
/
allocationUnitBytes
}
}
// GenerateVolumeName returns a PV name with clusterName prefix.
// GenerateVolumeName returns a PV name with clusterName prefix. The function
// The function should be used to generate a name of GCE PD or Cinder volume.
// should be used to generate a name of GCE PD or Cinder volume. It basically
// It basically adds "<clusterName>-dynamic-" before the PV name,
// adds "<clusterName>-dynamic-" before the PV name, making sure the resulting
// making sure the resulting string fits given length and cuts "dynamic"
// string fits given length and cuts "dynamic" if not.
// if not.
func
GenerateVolumeName
(
clusterName
,
pvName
string
,
maxLength
int
)
string
{
func
GenerateVolumeName
(
clusterName
,
pvName
string
,
maxLength
int
)
string
{
prefix
:=
clusterName
+
"-dynamic"
prefix
:=
clusterName
+
"-dynamic"
pvLen
:=
len
(
pvName
)
pvLen
:=
len
(
pvName
)
...
...
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