-
Notifications
You must be signed in to change notification settings - Fork 984
/
inference_service_status.go
221 lines (198 loc) · 9.15 KB
/
inference_service_status.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
/*
Copyright 2020 kubeflow.org.
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 v1beta1
import (
"k8s.io/api/core/v1"
"knative.dev/pkg/apis"
duckv1 "knative.dev/pkg/apis/duck/v1"
knservingv1 "knative.dev/serving/pkg/apis/serving/v1"
)
// InferenceServiceStatus defines the observed state of InferenceService
type InferenceServiceStatus struct {
// Conditions for the InferenceService <br/>
// - PredictorReady: predictor readiness condition; <br/>
// - TransformerReady: transformer readiness condition; <br/>
// - ExplainerReady: explainer readiness condition; <br/>
// - RoutesReady: aggregated routing condition; <br/>
// - Ready: aggregated condition; <br/>
duckv1.Status `json:",inline"`
// Addressable endpoint for the InferenceService
// +optional
Address *duckv1.Addressable `json:"address,omitempty"`
// URL holds the url that will distribute traffic over the provided traffic targets.
// It generally has the form http[s]://{route-name}.{route-namespace}.{cluster-level-suffix}
// +optional
URL *apis.URL `json:"url,omitempty"`
// Statuses for the components of the InferenceService
Components map[ComponentType]ComponentStatusSpec `json:"components,omitempty"`
}
// ComponentStatusSpec describes the state of the component
type ComponentStatusSpec struct {
// Latest revision name that is in ready state
// +optional
LatestReadyRevision string `json:"latestReadyRevision,omitempty"`
// Latest revision name that is created
// +optional
LatestCreatedRevision string `json:"latestCreatedRevision,omitempty"`
// Previous revision name that is rolled out with 100 percent traffic
// +optional
PreviousRolledoutRevision string `json:"previousRolledoutRevision,omitempty"`
// Latest revision name that is rolled out with 100 percent traffic
// +optional
LatestRolledoutRevision string `json:"latestRolledoutRevision,omitempty"`
// Traffic holds the configured traffic distribution for latest ready revision and previous rolled out revision.
// +optional
Traffic []knservingv1.TrafficTarget `json:"traffic,omitempty"`
// URL holds the url that will distribute traffic over the provided traffic targets.
// It generally has the form http[s]://{route-name}.{route-namespace}.{cluster-level-suffix}
// +optional
URL *apis.URL `json:"url,omitempty"`
// Addressable endpoint for the InferenceService
// +optional
Address *duckv1.Addressable `json:"address,omitempty"`
}
// ComponentType contains the different types of components of the service
type ComponentType string
// ComponentType Enum
const (
PredictorComponent ComponentType = "predictor"
ExplainerComponent ComponentType = "explainer"
TransformerComponent ComponentType = "transformer"
)
// ConditionType represents a Service condition value
const (
// PredictorRoutesReady is set when network configuration has completed.
PredictorRouteReady apis.ConditionType = "PredictorRouteReady"
// TransformerRoutesReady is set when network configuration has completed.
TransformerRouteReady apis.ConditionType = "TransformerRouteReady"
// ExplainerRoutesReady is set when network configuration has completed.
ExplainerRoutesReady apis.ConditionType = "ExplainerRoutesReady"
// PredictorConfigurationReady is set when predictor pods are ready.
PredictorConfigurationReady apis.ConditionType = "PredictorConfigurationReady"
// TransformerConfigurationeReady is set when transformer pods are ready.
TransformerConfigurationeReady apis.ConditionType = "TransformerConfigurationeReady"
// ExplainerConfigurationReady is set when explainer pods are ready.
ExplainerConfigurationReady apis.ConditionType = "ExplainerConfigurationReady"
// PredictorReady is set when predictor has reported readiness.
PredictorReady apis.ConditionType = "PredictorReady"
// TransformerReady is set when transformer has reported readiness.
TransformerReady apis.ConditionType = "TransformerReady"
// ExplainerReady is set when explainer has reported readiness.
ExplainerReady apis.ConditionType = "ExplainerReady"
// Ingress is created
IngressReady apis.ConditionType = "IngressReady"
)
var conditionsMap = map[ComponentType]apis.ConditionType{
PredictorComponent: PredictorReady,
ExplainerComponent: ExplainerReady,
TransformerComponent: TransformerReady,
}
var routeConditionsMap = map[ComponentType]apis.ConditionType{
PredictorComponent: PredictorRouteReady,
ExplainerComponent: ExplainerRoutesReady,
TransformerComponent: TransformerRouteReady,
}
var configurationConditionsMap = map[ComponentType]apis.ConditionType{
PredictorComponent: PredictorConfigurationReady,
ExplainerComponent: ExplainerConfigurationReady,
TransformerComponent: TransformerConfigurationeReady,
}
// InferenceService Ready condition is depending on predictor and route readiness condition
var conditionSet = apis.NewLivingConditionSet(
PredictorReady,
IngressReady,
)
var _ apis.ConditionsAccessor = (*InferenceServiceStatus)(nil)
func (ss *InferenceServiceStatus) InitializeConditions() {
conditionSet.Manage(ss).InitializeConditions()
}
// IsReady returns if the service is ready to serve the requested configuration.
func (ss *InferenceServiceStatus) IsReady() bool {
return conditionSet.Manage(ss).IsHappy()
}
// GetCondition returns the condition by name.
func (ss *InferenceServiceStatus) GetCondition(t apis.ConditionType) *apis.Condition {
return conditionSet.Manage(ss).GetCondition(t)
}
// IsConditionReady returns the readiness for a given condition
func (ss *InferenceServiceStatus) IsConditionReady(t apis.ConditionType) bool {
return conditionSet.Manage(ss).GetCondition(t) != nil && conditionSet.Manage(ss).GetCondition(t).Status == v1.ConditionTrue
}
func (ss *InferenceServiceStatus) PropagateStatus(component ComponentType, serviceStatus *knservingv1.ServiceStatus) {
if len(ss.Components) == 0 {
ss.Components = make(map[ComponentType]ComponentStatusSpec)
}
statusSpec, ok := ss.Components[component]
if !ok {
ss.Components[component] = ComponentStatusSpec{}
}
statusSpec.LatestCreatedRevision = serviceStatus.LatestCreatedRevisionName
for _, traffic := range serviceStatus.Traffic {
if traffic.RevisionName == serviceStatus.LatestReadyRevisionName && traffic.LatestRevision != nil &&
*traffic.LatestRevision {
if statusSpec.LatestRolledoutRevision != serviceStatus.LatestReadyRevisionName {
if traffic.Percent != nil && *traffic.Percent == 100 {
// track the last revision that's rolled out
statusSpec.PreviousRolledoutRevision = statusSpec.LatestRolledoutRevision
statusSpec.LatestRolledoutRevision = serviceStatus.LatestReadyRevisionName
}
} else {
// This is to handle case when the latest ready revision is rolled out with 100% and then rolled back
// so here we need to rollback the LatestRolledoutRevision to PreviousRolledoutRevision
if serviceStatus.LatestReadyRevisionName == serviceStatus.LatestCreatedRevisionName {
if traffic.Percent != nil && *traffic.Percent < 100 {
statusSpec.LatestRolledoutRevision = statusSpec.PreviousRolledoutRevision
}
}
}
}
}
if serviceStatus.LatestReadyRevisionName != statusSpec.LatestReadyRevision {
statusSpec.LatestReadyRevision = serviceStatus.LatestReadyRevisionName
}
// propagate overall service condition
serviceCondition := serviceStatus.GetCondition(knservingv1.ServiceConditionReady)
if serviceCondition != nil && serviceCondition.Status == v1.ConditionTrue {
if serviceStatus.Address != nil {
statusSpec.Address = serviceStatus.Address
}
if serviceStatus.URL != nil {
statusSpec.URL = serviceStatus.URL
}
}
// propagate ready condition for each component
readyCondition := conditionsMap[component]
ss.SetCondition(readyCondition, serviceCondition)
// propagate route condition for each component
routeCondition := serviceStatus.GetCondition("ConfigurationsReady")
routeConditionType := routeConditionsMap[component]
ss.SetCondition(routeConditionType, routeCondition)
// propagate configuration condition for each component
configurationCondition := serviceStatus.GetCondition("RoutesReady")
configurationConditionType := configurationConditionsMap[component]
// propagate traffic status for each component
statusSpec.Traffic = serviceStatus.Traffic
ss.SetCondition(configurationConditionType, configurationCondition)
ss.Components[component] = statusSpec
}
func (ss *InferenceServiceStatus) SetCondition(conditionType apis.ConditionType, condition *apis.Condition) {
switch {
case condition == nil:
case condition.Status == v1.ConditionUnknown:
conditionSet.Manage(ss).MarkUnknown(conditionType, condition.Reason, condition.Message)
case condition.Status == v1.ConditionTrue:
conditionSet.Manage(ss).MarkTrue(conditionType)
case condition.Status == v1.ConditionFalse:
conditionSet.Manage(ss).MarkFalse(conditionType, condition.Reason, condition.Message)
}
}