knative.dev/pkg@v0.0.0-20260602142205-ac97e43f6622/apis/condition_types.go (about) 1 /* 2 Copyright 2019 The Knative Authors 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package apis 18 19 import ( 20 corev1 "k8s.io/api/core/v1" 21 ) 22 23 // Conditions is the schema for the conditions portion of the payload 24 type Conditions []Condition 25 26 // ConditionType is a camel-cased condition type. 27 type ConditionType string 28 29 const ( 30 // ConditionReady specifies that the resource is ready. 31 // For long-running resources. 32 ConditionReady ConditionType = "Ready" 33 // ConditionSucceeded specifies that the resource has finished. 34 // For resource which run to completion. 35 ConditionSucceeded ConditionType = "Succeeded" 36 ) 37 38 // ConditionSeverity expresses the severity of a Condition Type failing. 39 type ConditionSeverity string 40 41 const ( 42 // ConditionSeverityError specifies that a failure of a condition type 43 // should be viewed as an error. As "Error" is the default for conditions 44 // we use the empty string (coupled with omitempty) to avoid confusion in 45 // the case where the condition is in state "True" (aka nothing is wrong). 46 ConditionSeverityError ConditionSeverity = "" 47 // ConditionSeverityWarning specifies that a failure of a condition type 48 // should be viewed as a warning, but that things could still work. 49 ConditionSeverityWarning ConditionSeverity = "Warning" 50 // ConditionSeverityInfo specifies that a failure of a condition type 51 // should be viewed as purely informational, and that things could still work. 52 ConditionSeverityInfo ConditionSeverity = "Info" 53 ) 54 55 // Condition defines a readiness condition for a Knative resource. 56 // See: https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#typical-status-properties 57 // +k8s:deepcopy-gen=true 58 type Condition struct { 59 // Type of condition. 60 // +required 61 Type ConditionType `json:"type" description:"type of status condition"` 62 63 // Status of the condition, one of True, False, Unknown. 64 // +required 65 Status corev1.ConditionStatus `json:"status" description:"status of the condition, one of True, False, Unknown"` 66 67 // Severity with which to treat failures of this type of condition. 68 // When this is not specified, it defaults to Error. 69 // +optional 70 Severity ConditionSeverity `json:"severity,omitempty" description:"how to interpret failures of this condition, one of Error, Warning, Info"` 71 72 // LastTransitionTime is the last time the condition transitioned from one status to another. 73 // We use VolatileTime in place of metav1.Time to exclude this from creating equality.Semantic 74 // differences (all other things held constant). 75 // +optional 76 LastTransitionTime VolatileTime `json:"lastTransitionTime,omitempty" description:"last time the condition transit from one status to another"` 77 78 // The reason for the condition's last transition. 79 // +optional 80 Reason string `json:"reason,omitempty" description:"one-word CamelCase reason for the condition's last transition"` 81 82 // A human readable message indicating details about the transition. 83 // +optional 84 Message string `json:"message,omitempty" description:"human-readable message indicating details about last transition"` 85 } 86 87 // IsTrue is true if the condition is True 88 func (c *Condition) IsTrue() bool { 89 if c == nil { 90 return false 91 } 92 return c.Status == corev1.ConditionTrue 93 } 94 95 // IsFalse is true if the condition is False 96 func (c *Condition) IsFalse() bool { 97 if c == nil { 98 return false 99 } 100 return c.Status == corev1.ConditionFalse 101 } 102 103 // IsUnknown is true if the condition is Unknown 104 func (c *Condition) IsUnknown() bool { 105 if c == nil { 106 return true 107 } 108 return c.Status == corev1.ConditionUnknown 109 } 110 111 // GetReason returns a nil save string of Reason 112 func (c *Condition) GetReason() string { 113 if c == nil { 114 return "" 115 } 116 return c.Reason 117 } 118 119 // GetMessage returns a nil save string of Message 120 func (c *Condition) GetMessage() string { 121 if c == nil { 122 return "" 123 } 124 return c.Message 125 }