@@ -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