Skip to content

Commit d067bf3

Browse files
authored
Merge pull request #151 from ferryproxy/fix/status
Fix status
2 parents 1870ee0 + e30a001 commit d067bf3

File tree

2 files changed

+59
-17
lines changed

2 files changed

+59
-17
lines changed

pkg/conditions/conditions.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,12 @@ func (c *ConditionsManager) Ready(name string, conditionTypes ...string) (bool,
107107
}
108108

109109
notReadyReasons := []string{}
110+
netSetReasons := []string{}
110111

111112
for _, conditionType := range conditionTypes {
112113
cond := meta.FindStatusCondition(conds, conditionType)
113114
if cond == nil {
114-
notReadyReasons = append(notReadyReasons, conditionType+"NotSet")
115+
netSetReasons = append(netSetReasons, conditionType+"NotSet")
115116
continue
116117
}
117118
if cond.Status == metav1.ConditionTrue {
@@ -125,8 +126,13 @@ func (c *ConditionsManager) Ready(name string, conditionTypes ...string) (bool,
125126
notReadyReasons = append(notReadyReasons, cond.Reason+string(cond.Status))
126127
}
127128

128-
if len(notReadyReasons) == 0 {
129-
return true, ""
129+
if len(notReadyReasons) != 0 {
130+
return false, strings.Join(notReadyReasons, ",")
130131
}
131-
return false, strings.Join(notReadyReasons, ",")
132+
133+
if len(netSetReasons) != 0 {
134+
return false, strings.Join(netSetReasons, ",")
135+
}
136+
137+
return true, ""
132138
}

pkg/controllers/route/route_controller.go

Lines changed: 49 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,10 @@ func (c *RouteController) Run(ctx context.Context) error {
112112
func (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

325361
func groupRoutes(rules []*trafficv1alpha2.Route) map[clusterPair][]*trafficv1alpha2.Route {

0 commit comments

Comments
 (0)