-
Notifications
You must be signed in to change notification settings - Fork 238
/
om.go
85 lines (72 loc) · 1.94 KB
/
om.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package om
import (
"os"
"strconv"
"strings"
"time"
log "github.com/sirupsen/logrus"
)
const (
// SysLog log file
SysLog = "/var/log/messages"
// IssueBlockReference tag
IssueBlockReference = "ISSUE_BLOCK_REFERENCE"
// MessageFileLines tag
MessageFileLines = "MESSAGE_FILE_LINES"
)
var (
// GlobalConfigVar var
GlobalConfigVar GlobalConfig
)
// GlobalConfig save global values for om
type GlobalConfig struct {
MessageFileTailLines int
IssueBlockReference bool
}
// StorageOM storage Operation and Maintenance
func StorageOM() {
GlobalConfigSet()
for {
// fix block volume reference not removed issue;
// error message: The device %q is still referenced from other Pods;
if GlobalConfigVar.IssueBlockReference {
CheckMessageFileIssue()
}
// loop interval time
time.Sleep(time.Duration(time.Second * 10))
}
}
// CheckMessageFileIssue check/fix issues from message file
func CheckMessageFileIssue() {
// got the last few lines of message file
lines := ReadFileLinesFromHost(SysLog)
// loop in lines
for _, line := range lines {
// Fix Block Volume Reference Issue;
if GlobalConfigVar.IssueBlockReference && strings.Contains(line, "is still referenced from other Pods") {
if FixReferenceMountIssue(line) {
}
}
}
}
// GlobalConfigSet set Global Config
func GlobalConfigSet() {
GlobalConfigVar.MessageFileTailLines = 20
messageFileLine := os.Getenv(MessageFileLines)
if messageFileLine != "" {
lineNum, err := strconv.Atoi(messageFileLine)
if err != nil {
log.Errorf("OM GlobalConfigSet: MessageFileLines error format: %s", messageFileLine)
} else {
GlobalConfigVar.MessageFileTailLines = lineNum
if GlobalConfigVar.MessageFileTailLines > 500 {
log.Warnf("OM GlobalConfigSet: MessageFileLines too large: %s", messageFileLine)
}
}
}
GlobalConfigVar.IssueBlockReference = false
blockRef := os.Getenv(IssueBlockReference)
if blockRef == "true" {
GlobalConfigVar.IssueBlockReference = true
}
}