Skip to content

Commit 10749dd

Browse files
committed
fix: network status in ForeignCluster resource
This patch fixes the network status in the ForeignCluster resource. Previously, when the connection or the configuration were missing no conditions were shown, so who looked at the ForeignCluster status could thing that everything is correctly configured. Moreover, this patch makes the status check more robust, collecting all the errors first and only once we are sure that the module is enabled (there is at least a network resource present), it writes the errors in the status.
1 parent 8351b13 commit 10749dd

File tree

5 files changed

+87
-19
lines changed

5 files changed

+87
-19
lines changed

apis/core/v1beta1/foreigncluster_types.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ const (
9696
APIServerStatusCondition ConditionType = "APIServerStatus"
9797

9898
// NETWORKING
99+
// NetworkConfigurationStatusCondition tells whether the network configuration of the peer cluster is present.
100+
NetworkConfigurationStatusCondition ConditionType = "NetworkConfigurationStatus"
99101
// NetworkConnectionStatusCondition shows the network connection status.
100102
NetworkConnectionStatusCondition ConditionType = "NetworkConnectionStatus"
101103
// NetworkGatewayServerStatusCondition shows the network gateway server status.
@@ -139,7 +141,7 @@ const (
139141
// Condition contains details about state of a.
140142
type Condition struct {
141143
// Type of the condition.
142-
// +kubebuilder:validation:Enum="APIServerStatus";"NetworkConnectionStatus";"NetworkGatewayServerStatus";"NetworkGatewayClientStatus";"AuthIdentityControlPlaneStatus";"AuthTenantStatus";"OffloadingVirtualNodeStatus";"OffloadingNodeStatus"
144+
// +kubebuilder:validation:Enum="APIServerStatus";"NetworkConnectionStatus";"NetworkGatewayServerStatus";"NetworkGatewayClientStatus";"NetworkConfigurationStatus";"AuthIdentityControlPlaneStatus";"AuthTenantStatus";"OffloadingVirtualNodeStatus";"OffloadingNodeStatus"
143145
//
144146
//nolint:lll // ignore long lines given by Kubebuilder marker annotations
145147
Type ConditionType `json:"type"`

deployments/liqo/charts/liqo-crds/crds/core.liqo.io_foreignclusters.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ spec:
107107
- NetworkConnectionStatus
108108
- NetworkGatewayServerStatus
109109
- NetworkGatewayClientStatus
110+
- NetworkConfigurationStatus
110111
- AuthIdentityControlPlaneStatus
111112
- AuthTenantStatus
112113
- OffloadingVirtualNodeStatus
@@ -170,6 +171,7 @@ spec:
170171
- NetworkConnectionStatus
171172
- NetworkGatewayServerStatus
172173
- NetworkGatewayClientStatus
174+
- NetworkConfigurationStatus
173175
- AuthIdentityControlPlaneStatus
174176
- AuthTenantStatus
175177
- OffloadingVirtualNodeStatus
@@ -231,6 +233,7 @@ spec:
231233
- NetworkConnectionStatus
232234
- NetworkGatewayServerStatus
233235
- NetworkGatewayClientStatus
236+
- NetworkConfigurationStatus
234237
- AuthIdentityControlPlaneStatus
235238
- AuthTenantStatus
236239
- OffloadingVirtualNodeStatus
@@ -292,6 +295,7 @@ spec:
292295
- NetworkConnectionStatus
293296
- NetworkGatewayServerStatus
294297
- NetworkGatewayClientStatus
298+
- NetworkConfigurationStatus
295299
- AuthIdentityControlPlaneStatus
296300
- AuthTenantStatus
297301
- OffloadingVirtualNodeStatus

pkg/liqo-controller-manager/core/foreigncluster-controller/conditions.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ const (
2424
connectionErrorReason = "ConnectionError"
2525
connectionErrorMessage = "The network connection with the foreign cluster is in error"
2626

27+
connectionMissingReason = "ConnectionMissing"
28+
connectionMissingMessage = "There is no network connection with the foreign cluster"
29+
2730
gatewaysReadyReason = "GatewaysReady"
2831
gatewaysReadyMessage = "All gateway replicas are ready"
2932

@@ -33,6 +36,15 @@ const (
3336
gatewaysNotReadyReason = "GatewaysNotReady"
3437
gatewaysNotReadyMessage = "All gateway replicas are not ready"
3538

39+
gatewayMissingReason = "GatewayMissing"
40+
gatewayMissingMessage = "The gateway resource connecting to the foreign cluster is missing"
41+
42+
networkConfigurationStatusReason = "NetworkConfigurationPresence"
43+
networkConfigurationStatusMessage = "The network configuration of the peer cluster is present"
44+
45+
networkConfigurationMissingReason = "NetworkConfigurationMissing"
46+
networkConfigurationMissingMessage = "The network configuration for the connection with the foreign cluster is missing"
47+
3648
tenantReadyReason = "TenantReady"
3749
tenantReadyMessage = "The tenant has been successfully configured"
3850

pkg/liqo-controller-manager/core/foreigncluster-controller/foreigncluster_controller.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ func (r *ForeignClusterReconciler) SetupWithManager(mgr ctrl.Manager, workers in
170170

171171
return ctrl.NewControllerManagedBy(mgr).Named(consts.CtrlForeignCluster).
172172
For(&liqov1beta1.ForeignCluster{}, builder.WithPredicates(foreignClusterPredicate)).
173+
Watches(&networkingv1beta1.Configuration{}, handler.EnqueueRequestsFromMapFunc(r.foreignclusterEnqueuer)).
173174
Watches(&networkingv1beta1.Connection{}, handler.EnqueueRequestsFromMapFunc(r.foreignclusterEnqueuer)).
174175
Watches(&networkingv1beta1.GatewayServer{}, handler.EnqueueRequestsFromMapFunc(r.foreignclusterEnqueuer)).
175176
Watches(&networkingv1beta1.GatewayClient{}, handler.EnqueueRequestsFromMapFunc(r.foreignclusterEnqueuer)).

pkg/liqo-controller-manager/core/foreigncluster-controller/status.go

Lines changed: 67 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -63,38 +63,43 @@ func (r *ForeignClusterReconciler) handleNetworkingModuleStatus(ctx context.Cont
6363
}
6464

6565
clusterID := fc.Spec.ClusterID
66+
type StatusException struct {
67+
liqov1beta1.ConditionStatusType
68+
Reason string
69+
Message string
70+
}
71+
statusExceptions := map[liqov1beta1.ConditionType]StatusException{}
6672

67-
connection, err := getters.GetConnectionByClusterID(ctx, r.Client, string(clusterID))
73+
_, err := getters.GetConfigurationByClusterID(ctx, r.Client, clusterID)
6874
switch {
6975
case errors.IsNotFound(err):
70-
klog.V(6).Infof("Connection resource not found for ForeignCluster %q", clusterID)
71-
fcutils.DeleteModuleCondition(&fc.Status.Modules.Networking, liqov1beta1.NetworkConnectionStatusCondition)
76+
klog.V(6).Infof("Configuration resource not found for ForeignCluster %q", clusterID)
77+
fcutils.DeleteModuleCondition(&fc.Status.Modules.Networking, liqov1beta1.NetworkConfigurationStatusCondition)
78+
statusExceptions[liqov1beta1.NetworkConfigurationStatusCondition] = StatusException{
79+
ConditionStatusType: liqov1beta1.ConditionStatusNotReady,
80+
Reason: networkConfigurationMissingReason,
81+
Message: networkConfigurationMissingMessage,
82+
}
7283
case err != nil:
73-
klog.Errorf("an error occurred while getting the Connection resource for the ForeignCluster %q: %s", clusterID, err)
84+
klog.Errorf("an error occurred while getting the Configuration resource for the ForeignCluster %q: %s", clusterID, err)
7485
return err
7586
default:
7687
fcutils.EnableModuleNetworking(fc)
77-
switch connection.Status.Value {
78-
case networkingv1beta1.Connected:
79-
fcutils.EnsureModuleCondition(&fc.Status.Modules.Networking,
80-
liqov1beta1.NetworkConnectionStatusCondition, liqov1beta1.ConditionStatusEstablished,
81-
connectionEstablishedReason, connectionEstablishedMessage)
82-
case networkingv1beta1.Connecting:
83-
fcutils.EnsureModuleCondition(&fc.Status.Modules.Networking,
84-
liqov1beta1.NetworkConnectionStatusCondition, liqov1beta1.ConditionStatusPending,
85-
connectionPendingReason, connectionPendingMessage)
86-
default:
87-
fcutils.EnsureModuleCondition(&fc.Status.Modules.Networking,
88-
liqov1beta1.NetworkConnectionStatusCondition, liqov1beta1.ConditionStatusError,
89-
connectionErrorReason, connectionErrorMessage)
90-
}
88+
fcutils.EnsureModuleCondition(&fc.Status.Modules.Networking,
89+
liqov1beta1.NetworkConfigurationStatusCondition, liqov1beta1.ConditionStatusReady,
90+
networkConfigurationStatusReason, networkConfigurationStatusMessage)
9191
}
9292

9393
gwServer, err := getters.GetGatewayServerByClusterID(ctx, r.Client, clusterID)
9494
switch {
9595
case errors.IsNotFound(err):
9696
klog.V(6).Infof("GatewayServer resource not found for ForeignCluster %q", clusterID)
9797
fcutils.DeleteModuleCondition(&fc.Status.Modules.Networking, liqov1beta1.NetworkGatewayServerStatusCondition)
98+
statusExceptions[liqov1beta1.NetworkGatewayServerStatusCondition] = StatusException{
99+
ConditionStatusType: liqov1beta1.ConditionStatusNotReady,
100+
Reason: gatewayMissingReason,
101+
Message: gatewayMissingMessage,
102+
}
98103
case err != nil:
99104
klog.Errorf("an error occurred while getting the GatewayServer resource for the ForeignCluster %q: %s", clusterID, err)
100105
return err
@@ -126,15 +131,50 @@ func (r *ForeignClusterReconciler) handleNetworkingModuleStatus(ctx context.Cont
126131
}
127132
}
128133

134+
connection, err := getters.GetConnectionByClusterID(ctx, r.Client, string(clusterID))
135+
switch {
136+
case errors.IsNotFound(err):
137+
klog.V(6).Infof("Connection resource not found for ForeignCluster %q", clusterID)
138+
fcutils.DeleteModuleCondition(&fc.Status.Modules.Networking, liqov1beta1.NetworkConnectionStatusCondition)
139+
statusExceptions[liqov1beta1.NetworkConnectionStatusCondition] = StatusException{
140+
ConditionStatusType: liqov1beta1.ConditionStatusNotReady,
141+
Reason: connectionMissingReason,
142+
Message: connectionMissingMessage,
143+
}
144+
case err != nil:
145+
klog.Errorf("an error occurred while getting the Connection resource for the ForeignCluster %q: %s", clusterID, err)
146+
return err
147+
default:
148+
fcutils.EnableModuleNetworking(fc)
149+
switch connection.Status.Value {
150+
case networkingv1beta1.Connected:
151+
fcutils.EnsureModuleCondition(&fc.Status.Modules.Networking,
152+
liqov1beta1.NetworkConnectionStatusCondition, liqov1beta1.ConditionStatusEstablished,
153+
connectionEstablishedReason, connectionEstablishedMessage)
154+
case networkingv1beta1.Connecting:
155+
fcutils.EnsureModuleCondition(&fc.Status.Modules.Networking,
156+
liqov1beta1.NetworkConnectionStatusCondition, liqov1beta1.ConditionStatusPending,
157+
connectionPendingReason, connectionPendingMessage)
158+
default:
159+
fcutils.EnsureModuleCondition(&fc.Status.Modules.Networking,
160+
liqov1beta1.NetworkConnectionStatusCondition, liqov1beta1.ConditionStatusError,
161+
connectionErrorReason, connectionErrorMessage)
162+
}
163+
}
164+
129165
gwClient, err := getters.GetGatewayClientByClusterID(ctx, r.Client, clusterID)
130166
switch {
131167
case errors.IsNotFound(err):
132168
klog.V(6).Infof("GatewayClient resource not found for ForeignCluster %q", clusterID)
133169
fcutils.DeleteModuleCondition(&fc.Status.Modules.Networking, liqov1beta1.NetworkGatewayClientStatusCondition)
170+
// Do not write any exception, as if both gateways are missing we write a single condition telling that a gateway is missing.
171+
// If instead, only the gateway client is missing, then this cluster acts as server.
134172
case err != nil:
135173
klog.Errorf("an error occurred while getting the GatewayClient resource for the ForeignCluster %q: %s", clusterID, err)
136174
return err
137175
default:
176+
// Delete the exceptions with the Gateway, if any, if this cluster has the gateway client
177+
delete(statusExceptions, liqov1beta1.NetworkGatewayServerStatusCondition)
138178
fcutils.EnableModuleNetworking(fc)
139179
gwDeployment := &appsv1.Deployment{
140180
ObjectMeta: metav1.ObjectMeta{
@@ -162,6 +202,15 @@ func (r *ForeignClusterReconciler) handleNetworkingModuleStatus(ctx context.Cont
162202
}
163203
}
164204

205+
// Write the exception in the status if the module is enabled
206+
if fc.Status.Modules.Networking.Enabled {
207+
for condition, condDescription := range statusExceptions {
208+
fcutils.EnsureModuleCondition(&fc.Status.Modules.Networking,
209+
condition, condDescription.ConditionStatusType,
210+
condDescription.Reason, condDescription.Message)
211+
}
212+
}
213+
165214
return nil
166215
}
167216

0 commit comments

Comments
 (0)