Skip to content

Commit 9cc9eb2

Browse files
committed
MAISTRA-2518 add conditions to federation status
Signed-off-by: rcernich <rcernich@redhat.com>
1 parent 3d5819d commit 9cc9eb2

11 files changed

Lines changed: 276 additions & 0 deletions

docs/crd/federation.maistra.io_ExportedServiceSet_v1.adoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ maistra.io/api/federation/v1
6060
|===
6161
| Name | Description | Type
6262

63+
| conditions
64+
| Represents the latest available observations of a federation's current state.
65+
| []Condition
66+
6367
| exportedServices
6468
| Exports provides details about the services exported by this mesh.
6569
| []PeerServiceMapping

docs/crd/federation.maistra.io_ImportedServiceSet_v1.adoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ maistra.io/api/federation/v1
6868
|===
6969
| Name | Description | Type
7070

71+
| conditions
72+
| Represents the latest available observations of a federation's current state.
73+
| []Condition
74+
7175
| importedServices
7276
| Imports provides details about the services imported by this mesh.
7377
| []PeerServiceMapping

docs/crd/federation.maistra.io_ServiceMeshPeer_v1.adoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ ServiceMeshPeerStatus provides information related to the other mesh.
7272
|===
7373
| Name | Description | Type
7474

75+
| conditions
76+
| Represents the latest available observations of a federation's current state.
77+
| []Condition
78+
7579
| discoveryStatus
7680
| DiscoveryStatus represents the discovery status of each pilot/istiod pod in the mesh.
7781
| link:federation.maistra.io_ServiceMeshPeer_ServiceMeshPeerDiscoveryStatus_v1.adoc[ServiceMeshPeerDiscoveryStatus]

federation/v1/exportedserviceset_types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ type ExportedServiceRule struct {
6868
}
6969

7070
type ExportedServiceSetStatus struct {
71+
StatusConditions `json:",inline"`
7172
// Exports provides details about the services exported by this mesh.
7273
// +required
7374
// +listType=map

federation/v1/importedserviceset_types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ type ImportedServiceLocality struct {
9898
}
9999

100100
type ImportedServiceSetStatus struct {
101+
StatusConditions `json:",inline"`
101102
// Imports provides details about the services imported by this mesh.
102103
// +required
103104
// +listType=map

federation/v1/servicemeshpeer_types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ type ServiceMeshPeerRemote struct {
120120

121121
// ServiceMeshPeerStatus provides information related to the other mesh.
122122
type ServiceMeshPeerStatus struct {
123+
StatusConditions `json:",inline"`
123124
// DiscoveryStatus represents the discovery status of each pilot/istiod pod
124125
// in the mesh.
125126
// +optional

federation/v1/statusconditions.go

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
// Copyright Red Hat, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package v1
16+
17+
import (
18+
"time"
19+
20+
corev1 "k8s.io/api/core/v1"
21+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
22+
)
23+
24+
type StatusConditions struct {
25+
// Represents the latest available observations of a federation's current state.
26+
// +optional
27+
// +patchMergeKey=type
28+
// +patchStrategy=merge
29+
Conditions []Condition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type" protobuf:"bytes,10,rep,name=conditions"`
30+
}
31+
32+
type ConditionType string
33+
34+
const (
35+
// Connected indicates that one or more instances of istiod are currently
36+
// connected to the remote mesh.
37+
ConnectedServiceMeshPeerCondition ConditionType = "Connected"
38+
// Degraded indicates that one or more instances of istiod are currently
39+
// not connected to the remote mesh.
40+
DegradedServiceMeshPeerCondition ConditionType = "Degraded"
41+
// Serving indicates that one or more instances of istiod is currently
42+
// serving discovery information to a remote mesh.
43+
ServingServiceMeshPeerCondition ConditionType = "Degraded"
44+
// Ready indicates that all instances of istiod are connected to the remote
45+
// mesh.
46+
ReadyServiceMeshPeerCondition ConditionType = "Ready"
47+
// Exporting indicates that the mesh is exporting services to the remote
48+
// mesh.
49+
ExportingExportedServiceSetCondition ConditionType = "Exporting"
50+
// Importing indicates that the mesh is importing services from the remote
51+
// mesh.
52+
ImportingImportedServiceSetCondition ConditionType = "Importing"
53+
)
54+
55+
const (
56+
ConnectedConditionReason = "Connected"
57+
NotConnectedConditionReason = "NotConnected"
58+
DegradedConditionReason = "Degraded"
59+
NotDegradedConditionReason = "NotDegraded"
60+
ServingConditionReason = "Serving"
61+
NotServingConditionReason = "NotServing"
62+
ReadyConditionReason = "Ready"
63+
NotReadyConditionReason = "NotReady"
64+
ExportingConditionReason = "Exporting"
65+
NoRulesMatchedConditionReason = "NoRulesMatched"
66+
NoRulesDefinedConditionReason = "NoRulesDefined"
67+
ImportingConditionReason = "Importing"
68+
NoExportedServicesConditionReason = "NoExportedServices"
69+
)
70+
71+
// Condition describes the state of a federation at a certain point.
72+
type Condition struct {
73+
// Type of federation condition.
74+
Type ConditionType `json:"type" protobuf:"bytes,1,opt,name=type,casttype=ConditionType"`
75+
// Status of the condition, one of True, False, Unknown.
76+
Status corev1.ConditionStatus `json:"status" protobuf:"bytes,2,opt,name=status,casttype=k8s.io/api/core/v1.ConditionStatus"`
77+
// Last time the condition transitioned from one status to another.
78+
// +optional
79+
LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty" protobuf:"bytes,3,opt,name=lastTransitionTime"`
80+
// The reason for the condition's last transition.
81+
// +optional
82+
Reason string `json:"reason,omitempty" protobuf:"bytes,4,opt,name=reason"`
83+
// A human readable message indicating details about the transition.
84+
// +optional
85+
Message string `json:"message,omitempty" protobuf:"bytes,5,opt,name=message"`
86+
}
87+
88+
// GetCondition removes a condition for the list of conditions
89+
func (s *StatusConditions) GetCondition(conditionType ConditionType) Condition {
90+
if s == nil {
91+
return Condition{Type: conditionType, Status: corev1.ConditionUnknown}
92+
}
93+
for i := range s.Conditions {
94+
if s.Conditions[i].Type == conditionType {
95+
return s.Conditions[i]
96+
}
97+
}
98+
return Condition{Type: conditionType, Status: corev1.ConditionUnknown}
99+
}
100+
101+
// SetCondition sets a specific condition in the list of conditions
102+
func (s *StatusConditions) SetCondition(condition Condition) *StatusConditions {
103+
if s == nil {
104+
return nil
105+
}
106+
// These only get serialized out to the second. This can break update
107+
// skipping, as the time in the resource returned from the client may not
108+
// match the time in our cached status during a reconcile. We truncate here
109+
// to save any problems down the line.
110+
now := metav1.NewTime(time.Now().Truncate(time.Second))
111+
for i, prevCondition := range s.Conditions {
112+
if prevCondition.Type == condition.Type {
113+
if prevCondition.Status != condition.Status {
114+
condition.LastTransitionTime = now
115+
} else {
116+
condition.LastTransitionTime = prevCondition.LastTransitionTime
117+
}
118+
s.Conditions[i] = condition
119+
return s
120+
}
121+
}
122+
123+
// If the condition does not exist,
124+
// initialize the lastTransitionTime
125+
condition.LastTransitionTime = now
126+
s.Conditions = append(s.Conditions, condition)
127+
return s
128+
}
129+
130+
// RemoveCondition removes a condition for the list of conditions
131+
func (s *StatusConditions) RemoveCondition(conditionType ConditionType) *StatusConditions {
132+
if s == nil {
133+
return nil
134+
}
135+
for i := range s.Conditions {
136+
if s.Conditions[i].Type == conditionType {
137+
s.Conditions = append(s.Conditions[:i], s.Conditions[i+1:]...)
138+
return s
139+
}
140+
}
141+
return s
142+
}

federation/v1/zz_generated.deepcopy.go

Lines changed: 41 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

manifests/federation.maistra.io_exportedservicesets.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,32 @@ spec:
116116
type: object
117117
status:
118118
properties:
119+
conditions:
120+
description: Represents the latest available observations of a federation's current state.
121+
items:
122+
description: Condition describes the state of a federation at a certain point.
123+
properties:
124+
lastTransitionTime:
125+
description: Last time the condition transitioned from one status to another.
126+
format: date-time
127+
type: string
128+
message:
129+
description: A human readable message indicating details about the transition.
130+
type: string
131+
reason:
132+
description: The reason for the condition's last transition.
133+
type: string
134+
status:
135+
description: Status of the condition, one of True, False, Unknown.
136+
type: string
137+
type:
138+
description: Type of federation condition.
139+
type: string
140+
required:
141+
- status
142+
- type
143+
type: object
144+
type: array
119145
exportedServices:
120146
description: Exports provides details about the services exported by this mesh.
121147
items:

manifests/federation.maistra.io_importedservicesets.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,32 @@ spec:
8484
type: object
8585
status:
8686
properties:
87+
conditions:
88+
description: Represents the latest available observations of a federation's current state.
89+
items:
90+
description: Condition describes the state of a federation at a certain point.
91+
properties:
92+
lastTransitionTime:
93+
description: Last time the condition transitioned from one status to another.
94+
format: date-time
95+
type: string
96+
message:
97+
description: A human readable message indicating details about the transition.
98+
type: string
99+
reason:
100+
description: The reason for the condition's last transition.
101+
type: string
102+
status:
103+
description: Status of the condition, one of True, False, Unknown.
104+
type: string
105+
type:
106+
description: Type of federation condition.
107+
type: string
108+
required:
109+
- status
110+
- type
111+
type: object
112+
type: array
87113
importedServices:
88114
description: Imports provides details about the services imported by this mesh.
89115
items:

0 commit comments

Comments
 (0)