diff --git a/pkg/volume/metrics_cached.go b/pkg/volume/metrics_cached.go index 35923de5f3..cec488dd0f 100644 --- a/pkg/volume/metrics_cached.go +++ b/pkg/volume/metrics_cached.go @@ -23,7 +23,8 @@ import ( 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 { wrapped MetricsProvider resultError error @@ -31,13 +32,15 @@ type cachedMetrics struct { 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 { 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 -// Runs GetMetrics Once and caches the result. Will not cache result if there is an error. func (md *cachedMetrics) GetMetrics() (*Metrics, error) { md.once.cache(func() error { md.resultMetrics, md.resultError = md.wrapped.GetMetrics() @@ -46,13 +49,15 @@ func (md *cachedMetrics) GetMetrics() (*Metrics, error) { 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 { m sync.Mutex 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) { if atomic.LoadUint32(&o.done) == 1 { return diff --git a/pkg/volume/metrics_du.go b/pkg/volume/metrics_du.go index 1c59c2bf6b..843cfd65df 100644 --- a/pkg/volume/metrics_du.go +++ b/pkg/volume/metrics_du.go @@ -26,8 +26,9 @@ import ( var _ MetricsProvider = &metricsDu{} -// metricsDu represents a MetricsProvider that calculates the used and available -// Volume space by executing the "du" command and gathering filesystem info for the Volume path. +// metricsDu represents a MetricsProvider that calculates the used and +// available Volume space by executing the "du" command and gathering +// filesystem info for the Volume path. type metricsDu struct { // the directory path the volume is mounted to. path string @@ -38,9 +39,9 @@ func NewMetricsDu(path string) MetricsProvider { return &metricsDu{path} } -// See MetricsProvider.GetMetrics // GetMetrics calculates the volume usage and device free space by executing "du" // and gathering filesystem info for the Volume path. +// See MetricsProvider.GetMetrics func (md *metricsDu) GetMetrics() (*Metrics, error) { metrics := &Metrics{} if md.path == "" { @@ -70,7 +71,8 @@ func (md *metricsDu) runDu(metrics *Metrics) error { 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 { available, capacity, _, err := util.FsInfo(md.path) if err != nil { diff --git a/pkg/volume/metrics_nil.go b/pkg/volume/metrics_nil.go index c7fffdb88a..1c6626c17a 100644 --- a/pkg/volume/metrics_nil.go +++ b/pkg/volume/metrics_nil.go @@ -21,11 +21,12 @@ import "errors" var _ MetricsProvider = &MetricsNil{} // 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{} -// See MetricsProvider.GetMetrics // GetMetrics returns an empty Metrics and an error. +// See MetricsProvider.GetMetrics func (*MetricsNil) GetMetrics() (*Metrics, error) { return &Metrics{}, errors.New("metrics are not supported for MetricsNil Volumes") } diff --git a/pkg/volume/util.go b/pkg/volume/util.go index c4a532fa16..0b20a4be73 100644 --- a/pkg/volume/util.go +++ b/pkg/volume/util.go @@ -39,8 +39,8 @@ import ( // attempted before returning. // // 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 -// old pod instead of starting a new one. +// function assumes it's an older instance of the recycler pod and watches +// this old pod instead of starting a new one. // // pod - the pod designed by a volume plugin to recycle the volume. pod.Name // will be overwritten with unique name based on PV.Name. @@ -49,7 +49,8 @@ func RecycleVolumeByWatchingPodUntilCompletion(pvName string, pod *api.Pod, kube 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 { glog.V(5).Infof("creating recycler pod for volume %s\n", pod.Name) @@ -93,7 +94,7 @@ func internalRecycleVolumeByWatchingPodUntilCompletion(pvName string, pod *api.P } // 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 { CreatePod(pod *api.Pod) (*api.Pod, error) GetPod(name, namespace string) (*api.Pod, 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 -// to close the reflector backing the watch. The caller is responsible for derring a close on the channel to -// stop the reflector. +// to close the reflector backing the watch. The caller is responsible for +// derring a close on the channel to stop the reflector. func (c *realRecyclerClient) WatchPod(name, namespace string, stopChannel chan struct{}) func() *api.Pod { fieldSelector, _ := fields.ParseSelector("metadata.name=" + name) @@ -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. -// The calculation and return value is either the minimumTimeout or the timeoutIncrement per Gi of storage size, whichever is greater. +// CalculateTimeoutForVolume calculates time for a Recycler pod to complete a +// 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 { giQty := resource.MustParse("1Gi") pvQty := pv.Spec.Capacity[api.ResourceStorage] @@ -170,11 +173,10 @@ func RoundUpSize(volumeSizeBytes int64, allocationUnitBytes int64) int64 { return (volumeSizeBytes + allocationUnitBytes - 1) / allocationUnitBytes } -// GenerateVolumeName returns a PV name with clusterName prefix. -// The function should be used to generate a name of GCE PD or Cinder volume. -// It basically adds "-dynamic-" before the PV name, -// making sure the resulting string fits given length and cuts "dynamic" -// if not. +// GenerateVolumeName returns a PV name with clusterName prefix. The function +// should be used to generate a name of GCE PD or Cinder volume. It basically +// adds "-dynamic-" before the PV name, making sure the resulting +// string fits given length and cuts "dynamic" if not. func GenerateVolumeName(clusterName, pvName string, maxLength int) string { prefix := clusterName + "-dynamic" pvLen := len(pvName)