mirror of
https://github.com/kubernetes/node-problem-detector.git
synced 2026-08-23 22:26:27 +00:00
@@ -21,13 +21,14 @@ import (
|
||||
"io/ioutil"
|
||||
"time"
|
||||
|
||||
"github.com/golang/glog"
|
||||
|
||||
"k8s.io/node-problem-detector/pkg/systemlogmonitor/logwatchers"
|
||||
watchertypes "k8s.io/node-problem-detector/pkg/systemlogmonitor/logwatchers/types"
|
||||
logtypes "k8s.io/node-problem-detector/pkg/systemlogmonitor/types"
|
||||
systemlogtypes "k8s.io/node-problem-detector/pkg/systemlogmonitor/types"
|
||||
"k8s.io/node-problem-detector/pkg/types"
|
||||
|
||||
"github.com/golang/glog"
|
||||
"k8s.io/node-problem-detector/pkg/util"
|
||||
"k8s.io/node-problem-detector/pkg/util/tomb"
|
||||
)
|
||||
|
||||
@@ -138,11 +139,17 @@ func (l *logMonitor) generateStatus(logs []*logtypes.Log, rule systemlogtypes.Ru
|
||||
// Update transition timestamp and message when the condition
|
||||
// changes. Condition is considered to be changed only when
|
||||
// status or reason changes.
|
||||
if !condition.Status || condition.Reason != rule.Reason {
|
||||
if condition.Status == types.False || condition.Reason != rule.Reason {
|
||||
condition.Transition = timestamp
|
||||
condition.Message = message
|
||||
events = append(events, util.GenerateConditionChangeEvent(
|
||||
condition.Type,
|
||||
types.True,
|
||||
rule.Reason,
|
||||
timestamp,
|
||||
))
|
||||
}
|
||||
condition.Status = true
|
||||
condition.Status = types.True
|
||||
condition.Reason = rule.Reason
|
||||
break
|
||||
}
|
||||
@@ -172,8 +179,7 @@ func initialConditions(defaults []types.Condition) []types.Condition {
|
||||
conditions := make([]types.Condition, len(defaults))
|
||||
copy(conditions, defaults)
|
||||
for i := range conditions {
|
||||
// TODO(random-liu): Validate default conditions
|
||||
conditions[i].Status = false
|
||||
conditions[i].Status = types.False
|
||||
conditions[i].Transition = time.Now()
|
||||
}
|
||||
return conditions
|
||||
|
||||
@@ -28,6 +28,7 @@ import (
|
||||
watchertest "k8s.io/node-problem-detector/pkg/systemlogmonitor/logwatchers/testing"
|
||||
logtypes "k8s.io/node-problem-detector/pkg/systemlogmonitor/types"
|
||||
"k8s.io/node-problem-detector/pkg/types"
|
||||
"k8s.io/node-problem-detector/pkg/util"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -40,13 +41,13 @@ func TestGenerateStatus(t *testing.T) {
|
||||
initConditions := []types.Condition{
|
||||
{
|
||||
Type: testConditionA,
|
||||
Status: true,
|
||||
Status: types.True,
|
||||
Transition: time.Unix(500, 500),
|
||||
Reason: "initial reason",
|
||||
},
|
||||
{
|
||||
Type: testConditionB,
|
||||
Status: false,
|
||||
Status: types.False,
|
||||
Transition: time.Unix(500, 500),
|
||||
},
|
||||
}
|
||||
@@ -73,10 +74,16 @@ func TestGenerateStatus(t *testing.T) {
|
||||
},
|
||||
expected: types.Status{
|
||||
Source: testSource,
|
||||
Events: []types.Event{util.GenerateConditionChangeEvent(
|
||||
testConditionA,
|
||||
types.True,
|
||||
"test reason",
|
||||
time.Unix(1000, 1000),
|
||||
)},
|
||||
Conditions: []types.Condition{
|
||||
{
|
||||
Type: testConditionA,
|
||||
Status: true,
|
||||
Status: types.True,
|
||||
Transition: time.Unix(1000, 1000),
|
||||
Reason: "test reason",
|
||||
Message: "test message 1\ntest message 2",
|
||||
@@ -97,7 +104,7 @@ func TestGenerateStatus(t *testing.T) {
|
||||
Conditions: []types.Condition{
|
||||
{
|
||||
Type: testConditionA,
|
||||
Status: true,
|
||||
Status: types.True,
|
||||
Transition: time.Unix(500, 500),
|
||||
Reason: "initial reason",
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user