mirror of
https://github.com/kubernetes/node-problem-detector.git
synced 2026-08-28 01:47:20 +00:00
Generate event for condition change and support unknown status.
This commit is contained in:
+9
-3
@@ -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.
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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),
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user