@@ -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+
3844func (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+
169255func (r * ForeignClusterReconciler ) handleAuthenticationModuleStatus (ctx context.Context ,
170256 fc * liqov1beta1.ForeignCluster , moduleEnabled bool , consumer , provider * bool ) error {
171257 if ! moduleEnabled {
0 commit comments