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
bbc88591
Commit
bbc88591
authored
May 04, 2017
by
Ian Chakeres
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor volume operation log and error messages
parent
1235365a
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
159 additions
and
1 deletion
+159
-1
operation_executor.go
pkg/volume/util/operationexecutor/operation_executor.go
+159
-1
operation_generator.go
pkg/volume/util/operationexecutor/operation_generator.go
+0
-0
No files found.
pkg/volume/util/operationexecutor/operation_executor.go
View file @
bbc88591
...
...
@@ -21,6 +21,7 @@ limitations under the License.
package
operationexecutor
import
(
"fmt"
"strings"
"time"
...
...
@@ -167,6 +168,47 @@ type ActualStateOfWorldAttacherUpdater interface {
AddVolumeToReportAsAttached
(
volumeName
v1
.
UniqueVolumeName
,
nodeName
types
.
NodeName
)
}
// VolumeLogger defines a set of operations for generating volume-related logging and error msgs
type
VolumeLogger
interface
{
// Creates a detailed msg that can be used in logs
// The msg format follows the pattern "<prefixMsg> <volume details> <suffixMsg>",
// where each implementation provides the volume details
GenerateMsgDetailed
(
prefixMsg
,
suffixMsg
string
)
(
detailedMsg
string
)
// Creates a detailed error that can be used in logs.
// The msg format follows the pattern "<prefixMsg> <volume details>: <err> ",
GenerateErrorDetailed
(
prefixMsg
string
,
err
error
)
(
detailedErr
error
)
// Creates a simple msg that is user friendly and a detailed msg that can be used in logs
// The msg format follows the pattern "<prefixMsg> <volume details> <suffixMsg>",
// where each implementation provides the volume details
GenerateMsg
(
prefixMsg
,
suffixMsg
string
)
(
simpleMsg
,
detailedMsg
string
)
// Creates a simple error that is user friendly and a detailed error that can be used in logs.
// The msg format follows the pattern "<prefixMsg> <volume details>: <err> ",
GenerateError
(
prefixMsg
string
,
err
error
)
(
simpleErr
,
detailedErr
error
)
}
// Generates an error string with the format ": <err>" if err exists
func
errSuffix
(
err
error
)
string
{
errStr
:=
""
if
err
!=
nil
{
errStr
=
fmt
.
Sprintf
(
": %v"
,
err
)
}
return
errStr
}
// Generate a detailed error msg for logs
func
generateVolumeMsgDetailed
(
prefixMsg
,
suffixMsg
,
volumeName
,
details
string
)
(
detailedMsg
string
)
{
return
fmt
.
Sprintf
(
"%v for volume %q %v %v"
,
prefixMsg
,
volumeName
,
details
,
suffixMsg
)
}
// Generate a simplified error msg for events and a detailed error msg for logs
func
generateVolumeMsg
(
prefixMsg
,
suffixMsg
,
volumeName
,
details
string
)
(
simpleMsg
,
detailedMsg
string
)
{
simpleMsg
=
fmt
.
Sprintf
(
"%v for volume %q %v"
,
prefixMsg
,
volumeName
,
suffixMsg
)
return
simpleMsg
,
generateVolumeMsgDetailed
(
prefixMsg
,
suffixMsg
,
volumeName
,
details
)
}
// VolumeToAttach represents a volume that should be attached to a node.
type
VolumeToAttach
struct
{
// VolumeName is the unique identifier for the volume that should be
...
...
@@ -188,6 +230,37 @@ type VolumeToAttach struct {
ScheduledPods
[]
*
v1
.
Pod
}
// GenerateMsgDetailed returns detailed msgs for volumes to attach
func
(
volume
*
VolumeToAttach
)
GenerateMsgDetailed
(
prefixMsg
,
suffixMsg
string
)
(
detailedMsg
string
)
{
detailedStr
:=
fmt
.
Sprintf
(
"(UniqueName: %q) from node %q"
,
volume
.
VolumeName
,
volume
.
NodeName
)
volumeSpecName
:=
"nil"
if
volume
.
VolumeSpec
!=
nil
{
volumeSpecName
=
volume
.
VolumeSpec
.
Name
()
}
return
generateVolumeMsgDetailed
(
prefixMsg
,
suffixMsg
,
volumeSpecName
,
detailedStr
)
}
// GenerateMsg returns simple and detailed msgs for volumes to attach
func
(
volume
*
VolumeToAttach
)
GenerateMsg
(
prefixMsg
,
suffixMsg
string
)
(
simpleMsg
,
detailedMsg
string
)
{
detailedStr
:=
fmt
.
Sprintf
(
"(UniqueName: %q) from node %q"
,
volume
.
VolumeName
,
volume
.
NodeName
)
volumeSpecName
:=
"nil"
if
volume
.
VolumeSpec
!=
nil
{
volumeSpecName
=
volume
.
VolumeSpec
.
Name
()
}
return
generateVolumeMsg
(
prefixMsg
,
suffixMsg
,
volumeSpecName
,
detailedStr
)
}
// GenerateErrorDetailed returns detailed errors for volumes to attach
func
(
volume
*
VolumeToAttach
)
GenerateErrorDetailed
(
prefixMsg
string
,
err
error
)
(
detailedErr
error
)
{
return
fmt
.
Errorf
(
volume
.
GenerateMsgDetailed
(
prefixMsg
,
errSuffix
(
err
)))
}
// GenerateError returns simple and detailed errors for volumes to attach
func
(
volume
*
VolumeToAttach
)
GenerateError
(
prefixMsg
string
,
err
error
)
(
simpleErr
,
detailedErr
error
)
{
simpleMsg
,
detailedMsg
:=
volume
.
GenerateMsg
(
prefixMsg
,
errSuffix
(
err
))
return
fmt
.
Errorf
(
simpleMsg
),
fmt
.
Errorf
(
detailedMsg
)
}
// VolumeToMount represents a volume that should be attached to this node and
// mounted to the PodName.
type
VolumeToMount
struct
{
...
...
@@ -228,6 +301,37 @@ type VolumeToMount struct {
ReportedInUse
bool
}
// GenerateMsgDetailed returns detailed msgs for volumes to mount
func
(
volume
*
VolumeToMount
)
GenerateMsgDetailed
(
prefixMsg
,
suffixMsg
string
)
(
detailedMsg
string
)
{
detailedStr
:=
fmt
.
Sprintf
(
"(UniqueName: %q) pod %q (UID: %q)"
,
volume
.
VolumeName
,
volume
.
Pod
.
Name
,
volume
.
Pod
.
UID
)
volumeSpecName
:=
"nil"
if
volume
.
VolumeSpec
!=
nil
{
volumeSpecName
=
volume
.
VolumeSpec
.
Name
()
}
return
generateVolumeMsgDetailed
(
prefixMsg
,
suffixMsg
,
volumeSpecName
,
detailedStr
)
}
// GenerateMsg returns simple and detailed msgs for volumes to mount
func
(
volume
*
VolumeToMount
)
GenerateMsg
(
prefixMsg
,
suffixMsg
string
)
(
simpleMsg
,
detailedMsg
string
)
{
detailedStr
:=
fmt
.
Sprintf
(
"(UniqueName: %q) pod %q (UID: %q)"
,
volume
.
VolumeName
,
volume
.
Pod
.
Name
,
volume
.
Pod
.
UID
)
volumeSpecName
:=
"nil"
if
volume
.
VolumeSpec
!=
nil
{
volumeSpecName
=
volume
.
VolumeSpec
.
Name
()
}
return
generateVolumeMsg
(
prefixMsg
,
suffixMsg
,
volumeSpecName
,
detailedStr
)
}
// GenerateErrorDetailed returns detailed errors for volumes to mount
func
(
volume
*
VolumeToMount
)
GenerateErrorDetailed
(
prefixMsg
string
,
err
error
)
(
detailedErr
error
)
{
return
fmt
.
Errorf
(
volume
.
GenerateMsgDetailed
(
prefixMsg
,
errSuffix
(
err
)))
}
// GenerateError returns simple and detailed errors for volumes to mount
func
(
volume
*
VolumeToMount
)
GenerateError
(
prefixMsg
string
,
err
error
)
(
simpleErr
,
detailedErr
error
)
{
simpleMsg
,
detailedMsg
:=
volume
.
GenerateMsg
(
prefixMsg
,
errSuffix
(
err
))
return
fmt
.
Errorf
(
simpleMsg
),
fmt
.
Errorf
(
detailedMsg
)
}
// AttachedVolume represents a volume that is attached to a node.
type
AttachedVolume
struct
{
// VolumeName is the unique identifier for the volume that is attached.
...
...
@@ -249,6 +353,37 @@ type AttachedVolume struct {
DevicePath
string
}
// GenerateMsgDetailed returns detailed msgs for attached volumes
func
(
volume
*
AttachedVolume
)
GenerateMsgDetailed
(
prefixMsg
,
suffixMsg
string
)
(
detailedMsg
string
)
{
detailedStr
:=
fmt
.
Sprintf
(
"(UniqueName: %q) on node %q"
,
volume
.
VolumeName
,
volume
.
NodeName
)
volumeSpecName
:=
"nil"
if
volume
.
VolumeSpec
!=
nil
{
volumeSpecName
=
volume
.
VolumeSpec
.
Name
()
}
return
generateVolumeMsgDetailed
(
prefixMsg
,
suffixMsg
,
volumeSpecName
,
detailedStr
)
}
// GenerateMsg returns simple and detailed msgs for attached volumes
func
(
volume
*
AttachedVolume
)
GenerateMsg
(
prefixMsg
,
suffixMsg
string
)
(
simpleMsg
,
detailedMsg
string
)
{
detailedStr
:=
fmt
.
Sprintf
(
"(UniqueName: %q) on node %q"
,
volume
.
VolumeName
,
volume
.
NodeName
)
volumeSpecName
:=
"nil"
if
volume
.
VolumeSpec
!=
nil
{
volumeSpecName
=
volume
.
VolumeSpec
.
Name
()
}
return
generateVolumeMsg
(
prefixMsg
,
suffixMsg
,
volumeSpecName
,
detailedStr
)
}
// GenerateErrorDetailed returns detailed errors for attached volumes
func
(
volume
*
AttachedVolume
)
GenerateErrorDetailed
(
prefixMsg
string
,
err
error
)
(
detailedErr
error
)
{
return
fmt
.
Errorf
(
volume
.
GenerateMsgDetailed
(
prefixMsg
,
errSuffix
(
err
)))
}
// GenerateError returns simple and detailed errors for attached volumes
func
(
volume
*
AttachedVolume
)
GenerateError
(
prefixMsg
string
,
err
error
)
(
simpleErr
,
detailedErr
error
)
{
simpleMsg
,
detailedMsg
:=
volume
.
GenerateMsg
(
prefixMsg
,
errSuffix
(
err
))
return
fmt
.
Errorf
(
simpleMsg
),
fmt
.
Errorf
(
detailedMsg
)
}
// MountedVolume represents a volume that has successfully been mounted to a pod.
type
MountedVolume
struct
{
// PodName is the unique identifier of the pod mounted to.
...
...
@@ -353,6 +488,29 @@ type MountedVolume struct {
VolumeGidValue
string
}
// GenerateMsgDetailed returns detailed msgs for mounted volumes
func
(
volume
*
MountedVolume
)
GenerateMsgDetailed
(
prefixMsg
,
suffixMsg
string
)
(
detailedMsg
string
)
{
detailedStr
:=
fmt
.
Sprintf
(
"(UniqueName: %q) pod %q (UID: %q)"
,
volume
.
VolumeName
,
volume
.
PodName
,
volume
.
PodUID
)
return
generateVolumeMsgDetailed
(
prefixMsg
,
suffixMsg
,
volume
.
OuterVolumeSpecName
,
detailedStr
)
}
// GenerateMsg returns simple and detailed msgs for mounted volumes
func
(
volume
*
MountedVolume
)
GenerateMsg
(
prefixMsg
,
suffixMsg
string
)
(
simpleMsg
,
detailedMsg
string
)
{
detailedStr
:=
fmt
.
Sprintf
(
"(UniqueName: %q) pod %q (UID: %q)"
,
volume
.
VolumeName
,
volume
.
PodName
,
volume
.
PodUID
)
return
generateVolumeMsg
(
prefixMsg
,
suffixMsg
,
volume
.
OuterVolumeSpecName
,
detailedStr
)
}
// GenerateErrorDetailed returns simple and detailed errors for mounted volumes
func
(
volume
*
MountedVolume
)
GenerateErrorDetailed
(
prefixMsg
string
,
err
error
)
(
detailedErr
error
)
{
return
fmt
.
Errorf
(
volume
.
GenerateMsgDetailed
(
prefixMsg
,
errSuffix
(
err
)))
}
// GenerateError returns simple and detailed errors for mounted volumes
func
(
volume
*
MountedVolume
)
GenerateError
(
prefixMsg
string
,
err
error
)
(
simpleErr
,
detailedErr
error
)
{
simpleMsg
,
detailedMsg
:=
volume
.
GenerateMsg
(
prefixMsg
,
errSuffix
(
err
))
return
fmt
.
Errorf
(
simpleMsg
),
fmt
.
Errorf
(
detailedMsg
)
}
type
operationExecutor
struct
{
// pendingOperations keeps track of pending attach and detach operations so
// multiple operations are not started on the same volume
...
...
@@ -463,7 +621,7 @@ func (oe *operationExecutor) VerifyVolumesAreAttached(
volumeSpecMapByPlugin
[
pluginName
],
actualStateOfWorld
)
if
err
!=
nil
{
glog
.
Errorf
(
"BulkVerifyVolumes.GenerateBulkVolumeVerifyFunc
error bulk verifying volumes for plugin %q with %v"
,
pluginName
,
err
)
glog
.
Errorf
(
"BulkVerifyVolumes.GenerateBulkVolumeVerifyFunc error bulk verifying volumes for plugin %q with %v"
,
pluginName
,
err
)
}
// Ugly hack to ensure - we don't do parallel bulk polling of same volume plugin
uniquePluginName
:=
v1
.
UniqueVolumeName
(
pluginName
)
...
...
pkg/volume/util/operationexecutor/operation_generator.go
View file @
bbc88591
This diff is collapsed.
Click to expand it.
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