Generate event for condition change and support unknown status.

This commit is contained in:
Lantao Liu
2018-06-21 15:29:53 -07:00
parent 8f286a4415
commit ee103dd4ac
8 changed files with 100 additions and 19 deletions
+9 -3
View File
@@ -37,11 +37,17 @@ func ConvertToAPICondition(condition types.Condition) api.NodeCondition {
}
// ConvertToAPIConditionStatus converts the internal node condition status to api.ConditionStatus.
func ConvertToAPIConditionStatus(status bool) api.ConditionStatus {
if status {
func ConvertToAPIConditionStatus(status types.ConditionStatus) api.ConditionStatus {
switch status {
case types.True:
return api.ConditionTrue
case types.False:
return api.ConditionFalse
case types.Unknown:
return api.ConditionUnknown
default:
panic("unknown condition status")
}
return api.ConditionFalse
}
// ConvertToAPIEventType converts the internal severity to event type.
+1 -1
View File
@@ -30,7 +30,7 @@ func TestConvertToAPICondition(t *testing.T) {
now := time.Now()
condition := types.Condition{
Type: "TestCondition",
Status: true,
Status: types.True,
Transition: now,
Reason: "test reason",
Message: "test message",
+33
View File
@@ -0,0 +1,33 @@
/*
Copyright 2017 The Kubernetes Authors All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package util
import (
"fmt"
"time"
"k8s.io/node-problem-detector/pkg/types"
)
// GenerateConditionChangeEvent generates an event for condition change.
func GenerateConditionChangeEvent(t string, status types.ConditionStatus, reason string, timestamp time.Time) types.Event {
return types.Event{
Severity: types.Info,
Timestamp: timestamp,
Reason: reason,
Message: fmt.Sprintf("Node condition %s is now: %s, reason: %s", t, status, reason),
}
}