@@ -112,7 +112,10 @@ func (c *RouteController) Run(ctx context.Context) error {
112112func (c * RouteController ) UpdateRouteCondition (name string , conditions []metav1.Condition ) {
113113 c .mut .Lock ()
114114 defer c .mut .Unlock ()
115+ c .updateRouteCondition (name , conditions )
116+ }
115117
118+ func (c * RouteController ) updateRouteCondition (name string , conditions []metav1.Condition ) {
116119 var retErr error
117120 defer func () {
118121 if retErr != nil {
@@ -164,10 +167,10 @@ func (c *RouteController) UpdateRouteCondition(name string, conditions []metav1.
164167 if c .conditionsManager .IsTrue (name , trafficv1alpha2 .PathReachableCondition ) {
165168 status .Way = cond .Message
166169 } else {
167- status .Way = " <unreachable>"
170+ status .Way = fp . Spec . Export . HubName + ", <unreachable>," + fp . Spec . Import . HubName
168171 }
169172 } else {
170- status .Way = " <unknown>"
173+ status .Way = fp . Spec . Export . HubName + ", <unknown>," + fp . Spec . Import . HubName
171174 }
172175
173176 data , err := json .Marshal (map [string ]interface {}{
@@ -261,9 +264,28 @@ func (c *RouteController) Sync(ctx context.Context) {
261264 for _ , key := range updated {
262265 logger := logger .WithValues ("export" , key .Export , "import" , key .Import )
263266 logger .Info ("Update mapping controller" )
264- mc , err := c .startMappingController (ctx , key )
267+ mc , failedConds , err := c .startMappingController (ctx , key )
265268 if err != nil {
266269 logger .Error (err , "start mapping controller" )
270+ routes := newerRoutes [key ]
271+ conds := []metav1.Condition {
272+ {
273+ Type : trafficv1alpha2 .RouteSyncedCondition ,
274+ Status : metav1 .ConditionFalse ,
275+ Reason : "Unsynced" ,
276+ Message : err .Error (),
277+ },
278+ }
279+ for _ , route := range routes {
280+ c .updateRouteCondition (route .Name , conds )
281+ }
282+ continue
283+ }
284+ if len (failedConds ) != 0 {
285+ routes := newerRoutes [key ]
286+ for _ , route := range routes {
287+ c .updateRouteCondition (route .Name , failedConds )
288+ }
267289 continue
268290 }
269291
@@ -286,20 +308,34 @@ func (c *RouteController) getMappingController(key clusterPair) *MappingControll
286308 return c .cacheMappingController [key ]
287309}
288310
289- func (c * RouteController ) startMappingController (ctx context.Context , key clusterPair ) (* MappingController , error ) {
311+ func (c * RouteController ) startMappingController (ctx context.Context , key clusterPair ) (* MappingController , []metav1. Condition , error ) {
290312 mc := c .cacheMappingController [key ]
291313 if mc != nil {
292- return mc , nil
314+ return mc , nil , nil
315+ }
316+
317+ conds := []metav1.Condition {}
318+
319+ exportHub := c .hubInterface .GetHub (key .Export )
320+ if exportHub == nil {
321+ conds = append (conds , metav1.Condition {
322+ Type : trafficv1alpha2 .ExportHubReadyCondition ,
323+ Status : metav1 .ConditionFalse ,
324+ Reason : "ExportHubNotExist" ,
325+ })
293326 }
294327
295- exportCluster := c .hubInterface .GetHub (key .Export )
296- if exportCluster == nil {
297- return nil , fmt .Errorf ("not found cluster information %q" , key .Export )
328+ importHub := c .hubInterface .GetHub (key .Import )
329+ if importHub == nil {
330+ conds = append (conds , metav1.Condition {
331+ Type : trafficv1alpha2 .ImportHubReadyCondition ,
332+ Status : metav1 .ConditionFalse ,
333+ Reason : "ImportHubNotExist" ,
334+ })
298335 }
299336
300- importCluster := c .hubInterface .GetHub (key .Import )
301- if importCluster == nil {
302- return nil , fmt .Errorf ("not found cluster information %q" , key .Import )
337+ if len (conds ) != 0 {
338+ return nil , conds , nil
303339 }
304340
305341 mc = NewMappingController (MappingControllerConfig {
@@ -315,11 +351,11 @@ func (c *RouteController) startMappingController(ctx context.Context, key cluste
315351
316352 err := mc .Start (ctx )
317353 if err != nil {
318- return nil , err
354+ return nil , nil , err
319355 }
320356
321357 c .cacheMappingController [key ] = mc
322- return mc , nil
358+ return mc , nil , nil
323359}
324360
325361func groupRoutes (rules []* trafficv1alpha2.Route ) map [clusterPair ][]* trafficv1alpha2.Route {
0 commit comments