/
condition.go
73 lines (61 loc) · 2 KB
/
condition.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
// Copyright 2022 VMware, Inc.
// SPDX-License-Identifier: Apache-2.0
package v1alpha1
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// ConditionType is a camel-cased condition type.
type ConditionType string
// ConditionStatus is the status of condition.
type ConditionStatus string
const (
// ConditionStatusTrue represents the condition status is True.
ConditionStatusTrue ConditionStatus = "True"
// ConditionStatusFalse represents the condition status is False.
ConditionStatusFalse ConditionStatus = "False"
// ConditionStatusUnknown represents the condition status is Unknown.
ConditionStatusUnknown ConditionStatus = "Unknown"
)
// Conditions is the schema for collected conditions.
type Conditions []Condition
// Condition is the schema for condition.
type Condition struct {
// Type of condition.
// +kubebuilder:validation:Required
Type ConditionType `json:"type"`
// Status of condition, one of True, False, Unknown
// +kubebuilder:validation:Required
Status ConditionStatus `json:"status"`
// LastTransitionTime is the last time the condition transitioned from one
// status to another.
// +kubebuilder:validation:Optional
LastTransitionTime *metav1.Time `json:"lastTransitionTime,omitempty"`
// Reason is the reason for condition's last transition.
// +kubebuilder:validation:Optional
Reason string `json:"reason,omitempty"`
// Message is a human readable message indicating details about the
// transition.
// +kubebuilder:validation:Optional
Message string `json:"message,omitempty"`
}
// IsTrue checks if the condition status is True.
func (c *Condition) IsTrue() bool {
if c == nil {
return false
}
return c.Status == ConditionStatusTrue
}
// IsFalse checks if the condition status if False.
func (c *Condition) IsFalse() bool {
if c == nil {
return false
}
return c.Status == ConditionStatusFalse
}
// IsUnknown checks if the condition status is Unknown.
func (c *Condition) IsUnknown() bool {
if c == nil {
return false
}
return c.Status == ConditionStatusUnknown
}