Skip to content

Commit

Permalink
MAISTRA-2518 add conditions to federation status
Browse files Browse the repository at this point in the history
Signed-off-by: rcernich <[email protected]>
  • Loading branch information
rcernich committed Aug 18, 2021
1 parent 3d5819d commit 77268cd
Show file tree
Hide file tree
Showing 11 changed files with 276 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/crd/federation.maistra.io_ExportedServiceSet_v1.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ maistra.io/api/federation/v1
|===
| Name | Description | Type

| conditions
| Represents the latest available observations of a federation's current state.
| []Condition

| exportedServices
| Exports provides details about the services exported by this mesh.
| []PeerServiceMapping
Expand Down
4 changes: 4 additions & 0 deletions docs/crd/federation.maistra.io_ImportedServiceSet_v1.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ maistra.io/api/federation/v1
|===
| Name | Description | Type

| conditions
| Represents the latest available observations of a federation's current state.
| []Condition

| importedServices
| Imports provides details about the services imported by this mesh.
| []PeerServiceMapping
Expand Down
4 changes: 4 additions & 0 deletions docs/crd/federation.maistra.io_ServiceMeshPeer_v1.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ ServiceMeshPeerStatus provides information related to the other mesh.
|===
| Name | Description | Type

| conditions
| Represents the latest available observations of a federation's current state.
| []Condition

| discoveryStatus
| DiscoveryStatus represents the discovery status of each pilot/istiod pod in the mesh.
| link:federation.maistra.io_ServiceMeshPeer_ServiceMeshPeerDiscoveryStatus_v1.adoc[ServiceMeshPeerDiscoveryStatus]
Expand Down
1 change: 1 addition & 0 deletions federation/v1/exportedserviceset_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ type ExportedServiceRule struct {
}

type ExportedServiceSetStatus struct {
StatusConditions `json:",inline"`
// Exports provides details about the services exported by this mesh.
// +required
// +listType=map
Expand Down
1 change: 1 addition & 0 deletions federation/v1/importedserviceset_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ type ImportedServiceLocality struct {
}

type ImportedServiceSetStatus struct {
StatusConditions `json:",inline"`
// Imports provides details about the services imported by this mesh.
// +required
// +listType=map
Expand Down
1 change: 1 addition & 0 deletions federation/v1/servicemeshpeer_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ type ServiceMeshPeerRemote struct {

// ServiceMeshPeerStatus provides information related to the other mesh.
type ServiceMeshPeerStatus struct {
StatusConditions `json:",inline"`
// DiscoveryStatus represents the discovery status of each pilot/istiod pod
// in the mesh.
// +optional
Expand Down
142 changes: 142 additions & 0 deletions federation/v1/statusconditions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
// Copyright Red Hat, Inc.
//
// 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 v1

import (
"time"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

type StatusConditions struct {
// Represents the latest available observations of a federation's current state.
// +optional
// +patchMergeKey=type
// +patchStrategy=merge
Conditions []Condition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type" protobuf:"bytes,10,rep,name=conditions"`
}

type ConditionType string

const (
// Connected indicates that one or more instances of istiod are currently
// connected to the remote mesh.
ConnectedServiceMeshPeerCondition ConditionType = "Connected"
// Degraded indicates that one or more instances of istiod are currently
// not connected to the remote mesh.
DegradedServiceMeshPeerCondition ConditionType = "Degraded"
// Serving indicates that one or more instances of istiod is currently
// serving discovery information to a remote mesh.
ServingServiceMeshPeerCondition ConditionType = "Degraded"
// Ready indicates that all instances of istiod are connected to the remote
// mesh.
ReadyServiceMeshPeerCondition ConditionType = "Ready"
// Exporting indicates that the mesh is exporting services to the remote
// mesh.
ExportingExportedServiceSetCondition ConditionType = "Exporting"
// Importing indicates that the mesh is importing services from the remote
// mesh.
ImportingImportedServiceSetCondition ConditionType = "Importing"
)

const (
ConnectedConditionReason = "Connected"
NotConnectedConditionReason = "NotConnected"
DegradedConditionReason = "Degraded"
NotDegradedConditionReason = "NotDegraded"
ServingConditionReason = "Serving"
NotServingConditionReason = "NotServing"
ReadyConditionReason = "Ready"
NotReadyConditionReason = "NotReady"
ExportingConditionReason = "Exporting"
NoRulesMatchedConditionReason = "NoRulesMatched"
NoRulesDefinedConditionReason = "NoRulesDefined"
ImportingConditionReason = "Importing"
NoExportedServicesConditionReason = "NoExportedServices"
)

// Condition describes the state of a federation at a certain point.
type Condition struct {
// Type of federation condition.
Type ConditionType `json:"type"`
// Status of the condition, one of True, False, Unknown.
Status corev1.ConditionStatus `json:"status"`
// Last time the condition transitioned from one status to another.
// +optional
LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty"`
// The reason for the condition's last transition.
// +optional
Reason string `json:"reason,omitempty"`
// A human readable message indicating details about the transition.
// +optional
Message string `json:"message,omitempty"`
}

// GetCondition removes a condition for the list of conditions
func (s *StatusConditions) GetCondition(conditionType ConditionType) Condition {
if s == nil {
return Condition{Type: conditionType, Status: corev1.ConditionUnknown}
}
for i := range s.Conditions {
if s.Conditions[i].Type == conditionType {
return s.Conditions[i]
}
}
return Condition{Type: conditionType, Status: corev1.ConditionUnknown}
}

// SetCondition sets a specific condition in the list of conditions
func (s *StatusConditions) SetCondition(condition Condition) *StatusConditions {
if s == nil {
return nil
}
// These only get serialized out to the second. This can break update
// skipping, as the time in the resource returned from the client may not
// match the time in our cached status during a reconcile. We truncate here
// to save any problems down the line.
now := metav1.NewTime(time.Now().Truncate(time.Second))
for i, prevCondition := range s.Conditions {
if prevCondition.Type == condition.Type {
if prevCondition.Status != condition.Status {
condition.LastTransitionTime = now
} else {
condition.LastTransitionTime = prevCondition.LastTransitionTime
}
s.Conditions[i] = condition
return s
}
}

// If the condition does not exist,
// initialize the lastTransitionTime
condition.LastTransitionTime = now
s.Conditions = append(s.Conditions, condition)
return s
}

// RemoveCondition removes a condition for the list of conditions
func (s *StatusConditions) RemoveCondition(conditionType ConditionType) *StatusConditions {
if s == nil {
return nil
}
for i := range s.Conditions {
if s.Conditions[i].Type == conditionType {
s.Conditions = append(s.Conditions[:i], s.Conditions[i+1:]...)
return s
}
}
return s
}
41 changes: 41 additions & 0 deletions federation/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions manifests/federation.maistra.io_exportedservicesets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,32 @@ spec:
type: object
status:
properties:
conditions:
description: Represents the latest available observations of a federation's current state.
items:
description: Condition describes the state of a federation at a certain point.
properties:
lastTransitionTime:
description: Last time the condition transitioned from one status to another.
format: date-time
type: string
message:
description: A human readable message indicating details about the transition.
type: string
reason:
description: The reason for the condition's last transition.
type: string
status:
description: Status of the condition, one of True, False, Unknown.
type: string
type:
description: Type of federation condition.
type: string
required:
- status
- type
type: object
type: array
exportedServices:
description: Exports provides details about the services exported by this mesh.
items:
Expand Down
26 changes: 26 additions & 0 deletions manifests/federation.maistra.io_importedservicesets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,32 @@ spec:
type: object
status:
properties:
conditions:
description: Represents the latest available observations of a federation's current state.
items:
description: Condition describes the state of a federation at a certain point.
properties:
lastTransitionTime:
description: Last time the condition transitioned from one status to another.
format: date-time
type: string
message:
description: A human readable message indicating details about the transition.
type: string
reason:
description: The reason for the condition's last transition.
type: string
status:
description: Status of the condition, one of True, False, Unknown.
type: string
type:
description: Type of federation condition.
type: string
required:
- status
- type
type: object
type: array
importedServices:
description: Imports provides details about the services imported by this mesh.
items:
Expand Down
26 changes: 26 additions & 0 deletions manifests/federation.maistra.io_servicemeshpeers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,32 @@ spec:
status:
description: ServiceMeshPeerStatus provides information related to the other mesh.
properties:
conditions:
description: Represents the latest available observations of a federation's current state.
items:
description: Condition describes the state of a federation at a certain point.
properties:
lastTransitionTime:
description: Last time the condition transitioned from one status to another.
format: date-time
type: string
message:
description: A human readable message indicating details about the transition.
type: string
reason:
description: The reason for the condition's last transition.
type: string
status:
description: Status of the condition, one of True, False, Unknown.
type: string
type:
description: Type of federation condition.
type: string
required:
- status
- type
type: object
type: array
discoveryStatus:
description: DiscoveryStatus represents the discovery status of each pilot/istiod pod in the mesh.
properties:
Expand Down

0 comments on commit 77268cd

Please sign in to comment.