Skip to content

Commit 516bd6a

Browse files
claudioloradamjensenbot
authored andcommitted
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 think 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 b2ac20b commit 516bd6a

File tree

5 files changed

+131
-18
lines changed

5 files changed

+131
-18
lines changed

apis/core/v1beta1/foreigncluster_types.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,11 @@ 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"
103+
NetworkGatewayPresenceCondition ConditionType = "NetworkGatewayPresence"
101104
// NetworkGatewayServerStatusCondition shows the network gateway server status.
102105
NetworkGatewayServerStatusCondition ConditionType = "NetworkGatewayServerStatus"
103106
// NetworkGatewayClientStatusCondition shows the network gateway client status.
@@ -139,7 +142,7 @@ const (
139142
// Condition contains details about state of a.
140143
type Condition struct {
141144
// Type of the condition.
142-
// +kubebuilder:validation:Enum="APIServerStatus";"NetworkConnectionStatus";"NetworkGatewayServerStatus";"NetworkGatewayClientStatus";"AuthIdentityControlPlaneStatus";"AuthTenantStatus";"OffloadingVirtualNodeStatus";"OffloadingNodeStatus"
145+
// +kubebuilder:validation:Enum="APIServerStatus";"NetworkConnectionStatus";"NetworkGatewayServerStatus";"NetworkGatewayClientStatus";"NetworkGatewayPresence";"NetworkConfigurationStatus";"AuthIdentityControlPlaneStatus";"AuthTenantStatus";"OffloadingVirtualNodeStatus";"OffloadingNodeStatus"
143146
//
144147
//nolint:lll // ignore long lines given by Kubebuilder marker annotations
145148
Type ConditionType `json:"type"`

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ spec:
107107
- NetworkConnectionStatus
108108
- NetworkGatewayServerStatus
109109
- NetworkGatewayClientStatus
110+
- NetworkGatewayPresence
111+
- NetworkConfigurationStatus
110112
- AuthIdentityControlPlaneStatus
111113
- AuthTenantStatus
112114
- OffloadingVirtualNodeStatus
@@ -170,6 +172,8 @@ spec:
170172
- NetworkConnectionStatus
171173
- NetworkGatewayServerStatus
172174
- NetworkGatewayClientStatus
175+
- NetworkGatewayPresence
176+
- NetworkConfigurationStatus
173177
- AuthIdentityControlPlaneStatus
174178
- AuthTenantStatus
175179
- OffloadingVirtualNodeStatus
@@ -231,6 +235,8 @@ spec:
231235
- NetworkConnectionStatus
232236
- NetworkGatewayServerStatus
233237
- NetworkGatewayClientStatus
238+
- NetworkGatewayPresence
239+
- NetworkConfigurationStatus
234240
- AuthIdentityControlPlaneStatus
235241
- AuthTenantStatus
236242
- OffloadingVirtualNodeStatus
@@ -292,6 +298,8 @@ spec:
292298
- NetworkConnectionStatus
293299
- NetworkGatewayServerStatus
294300
- NetworkGatewayClientStatus
301+
- NetworkGatewayPresence
302+
- NetworkConfigurationStatus
295303
- AuthIdentityControlPlaneStatus
296304
- AuthTenantStatus
297305
- OffloadingVirtualNodeStatus

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

Lines changed: 15 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,18 @@ 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+
gatewayPresentReason = "GatewayPresence"
43+
gatewayPresentMessage = "There is a gateway connecting to the foreign cluster"
44+
45+
networkConfigurationPresenceReason = "NetworkConfigurationPresence"
46+
networkConfigurationPresenceMessage = "The network configuration of the peer cluster is present"
47+
48+
networkConfigurationMissingReason = "NetworkConfigurationMissing"
49+
networkConfigurationMissingMessage = "The network configuration for the connection with the foreign cluster is missing"
50+
3651
tenantReadyReason = "TenantReady"
3752
tenantReadyMessage = "The tenant has been successfully configured"
3853

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: 103 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ import (
3535
"github.com/liqotech/liqo/pkg/utils/pod"
3636
)
3737

38+
type statusException struct {
39+
liqov1beta1.ConditionStatusType
40+
Reason string
41+
Message string
42+
}
43+
3844
func (r *ForeignClusterReconciler) clearStatusExceptConditions(foreignCluster *liqov1beta1.ForeignCluster) {
3945
foreignCluster.Status = liqov1beta1.ForeignClusterStatus{
4046
Role: liqov1beta1.UnknownRole,
@@ -56,20 +62,20 @@ func (r *ForeignClusterReconciler) clearStatusExceptConditions(foreignCluster *l
5662
}
5763
}
5864

59-
func (r *ForeignClusterReconciler) handleNetworkingModuleStatus(ctx context.Context,
60-
fc *liqov1beta1.ForeignCluster, moduleEnabled bool) error {
61-
if !moduleEnabled {
62-
clearModule(&fc.Status.Modules.Networking)
63-
return nil
64-
}
65-
65+
func (r *ForeignClusterReconciler) handleConnectionStatus(ctx context.Context,
66+
fc *liqov1beta1.ForeignCluster, statusExceptions map[liqov1beta1.ConditionType]statusException) error {
6667
clusterID := fc.Spec.ClusterID
6768

6869
connection, err := getters.GetConnectionByClusterID(ctx, r.Client, string(clusterID))
6970
switch {
7071
case errors.IsNotFound(err):
7172
klog.V(6).Infof("Connection resource not found for ForeignCluster %q", clusterID)
7273
fcutils.DeleteModuleCondition(&fc.Status.Modules.Networking, liqov1beta1.NetworkConnectionStatusCondition)
74+
statusExceptions[liqov1beta1.NetworkConnectionStatusCondition] = statusException{
75+
ConditionStatusType: liqov1beta1.ConditionStatusNotReady,
76+
Reason: connectionMissingReason,
77+
Message: connectionMissingMessage,
78+
}
7379
case err != nil:
7480
klog.Errorf("an error occurred while getting the Connection resource for the ForeignCluster %q: %s", clusterID, err)
7581
return err
@@ -90,15 +96,38 @@ func (r *ForeignClusterReconciler) handleNetworkingModuleStatus(ctx context.Cont
9096
connectionErrorReason, connectionErrorMessage)
9197
}
9298
}
99+
return nil
100+
}
101+
102+
func (r *ForeignClusterReconciler) handleGatewaysStatus(ctx context.Context,
103+
fc *liqov1beta1.ForeignCluster, statusExceptions map[liqov1beta1.ConditionType]statusException) error {
104+
clusterID := fc.Spec.ClusterID
105+
106+
gwServer, errServer := getters.GetGatewayServerByClusterID(ctx, r.Client, clusterID)
107+
gwClient, errClient := getters.GetGatewayClientByClusterID(ctx, r.Client, clusterID)
108+
109+
if errors.IsNotFound(errServer) && errors.IsNotFound(errClient) {
110+
klog.V(6).Infof("Both GatewayServer and GatewayClient resources not found for ForeignCluster %q", clusterID)
111+
statusExceptions[liqov1beta1.NetworkGatewayPresenceCondition] = statusException{
112+
ConditionStatusType: liqov1beta1.ConditionStatusNotReady,
113+
Reason: gatewayMissingReason,
114+
Message: gatewayMissingMessage,
115+
}
116+
} else {
117+
statusExceptions[liqov1beta1.NetworkGatewayPresenceCondition] = statusException{
118+
ConditionStatusType: liqov1beta1.ConditionStatusReady,
119+
Reason: gatewayPresentReason,
120+
Message: gatewayPresentMessage,
121+
}
122+
}
93123

94-
gwServer, err := getters.GetGatewayServerByClusterID(ctx, r.Client, clusterID)
95124
switch {
96-
case errors.IsNotFound(err):
125+
case errors.IsNotFound(errServer):
97126
klog.V(6).Infof("GatewayServer resource not found for ForeignCluster %q", clusterID)
98127
fcutils.DeleteModuleCondition(&fc.Status.Modules.Networking, liqov1beta1.NetworkGatewayServerStatusCondition)
99-
case err != nil:
100-
klog.Errorf("an error occurred while getting the GatewayServer resource for the ForeignCluster %q: %s", clusterID, err)
101-
return err
128+
case errServer != nil:
129+
klog.Errorf("an error occurred while getting the GatewayServer resource for the ForeignCluster %q: %s", clusterID, errServer)
130+
return errServer
102131
default:
103132
fcutils.EnableModuleNetworking(fc)
104133
gwDeployment := &appsv1.Deployment{
@@ -127,14 +156,13 @@ func (r *ForeignClusterReconciler) handleNetworkingModuleStatus(ctx context.Cont
127156
}
128157
}
129158

130-
gwClient, err := getters.GetGatewayClientByClusterID(ctx, r.Client, clusterID)
131159
switch {
132-
case errors.IsNotFound(err):
160+
case errors.IsNotFound(errClient):
133161
klog.V(6).Infof("GatewayClient resource not found for ForeignCluster %q", clusterID)
134162
fcutils.DeleteModuleCondition(&fc.Status.Modules.Networking, liqov1beta1.NetworkGatewayClientStatusCondition)
135-
case err != nil:
136-
klog.Errorf("an error occurred while getting the GatewayClient resource for the ForeignCluster %q: %s", clusterID, err)
137-
return err
163+
case errClient != nil:
164+
klog.Errorf("an error occurred while getting the GatewayClient resource for the ForeignCluster %q: %s", clusterID, errClient)
165+
return errClient
138166
default:
139167
fcutils.EnableModuleNetworking(fc)
140168
gwDeployment := &appsv1.Deployment{
@@ -166,6 +194,64 @@ func (r *ForeignClusterReconciler) handleNetworkingModuleStatus(ctx context.Cont
166194
return nil
167195
}
168196

197+
func (r *ForeignClusterReconciler) handleNetworkConfigurationStatus(ctx context.Context,
198+
fc *liqov1beta1.ForeignCluster, statusExceptions map[liqov1beta1.ConditionType]statusException) error {
199+
clusterID := fc.Spec.ClusterID
200+
_, err := getters.GetConfigurationByClusterID(ctx, r.Client, clusterID)
201+
switch {
202+
case errors.IsNotFound(err):
203+
klog.V(6).Infof("Configuration resource not found for ForeignCluster %q", clusterID)
204+
fcutils.DeleteModuleCondition(&fc.Status.Modules.Networking, liqov1beta1.NetworkConfigurationStatusCondition)
205+
statusExceptions[liqov1beta1.NetworkConfigurationStatusCondition] = statusException{
206+
ConditionStatusType: liqov1beta1.ConditionStatusNotReady,
207+
Reason: networkConfigurationMissingReason,
208+
Message: networkConfigurationMissingMessage,
209+
}
210+
case err != nil:
211+
klog.Errorf("an error occurred while getting the Configuration resource for the ForeignCluster %q: %s", clusterID, err)
212+
return err
213+
default:
214+
fcutils.EnableModuleNetworking(fc)
215+
fcutils.EnsureModuleCondition(&fc.Status.Modules.Networking,
216+
liqov1beta1.NetworkConfigurationStatusCondition, liqov1beta1.ConditionStatusReady,
217+
networkConfigurationPresenceReason, networkConfigurationPresenceMessage)
218+
}
219+
return nil
220+
}
221+
222+
func (r *ForeignClusterReconciler) handleNetworkingModuleStatus(ctx context.Context,
223+
fc *liqov1beta1.ForeignCluster, moduleEnabled bool) error {
224+
if !moduleEnabled {
225+
clearModule(&fc.Status.Modules.Networking)
226+
return nil
227+
}
228+
229+
statusExceptions := map[liqov1beta1.ConditionType]statusException{}
230+
231+
if err := r.handleNetworkConfigurationStatus(ctx, fc, statusExceptions); err != nil {
232+
return err
233+
}
234+
235+
if err := r.handleGatewaysStatus(ctx, fc, statusExceptions); err != nil {
236+
return err
237+
}
238+
239+
if err := r.handleConnectionStatus(ctx, fc, statusExceptions); err != nil {
240+
return err
241+
}
242+
243+
// Write the exception in the status if the module is enabled
244+
if fc.Status.Modules.Networking.Enabled {
245+
for condition, condDescription := range statusExceptions {
246+
fcutils.EnsureModuleCondition(&fc.Status.Modules.Networking,
247+
condition, condDescription.ConditionStatusType,
248+
condDescription.Reason, condDescription.Message)
249+
}
250+
}
251+
252+
return nil
253+
}
254+
169255
func (r *ForeignClusterReconciler) handleAuthenticationModuleStatus(ctx context.Context,
170256
fc *liqov1beta1.ForeignCluster, moduleEnabled bool, consumer, provider *bool) error {
171257
if !moduleEnabled {

0 commit comments

Comments
 (0)