Skip to content

Commit d059156

Browse files
fix: handle the signal removeManagedRoutes before creating config map (#37)
* fix: handle the signal removeManagedRoutes before creating config map Signed-off-by: Philipp Plotnikov <[email protected]> * refactor: rename CreateConfigMap func to GetOrCreateConfigMap Signed-off-by: Philipp Plotnikov <[email protected]> * refactor: update config on removeHTTPManagedRoutes only it needs Signed-off-by: Philipp Plotnikov <[email protected]> --------- Signed-off-by: Philipp Plotnikov <[email protected]>
1 parent 59f8145 commit d059156

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

internal/utils/common.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func CreateFormatter(logFormat string) log.Formatter {
5252
return formatType
5353
}
5454

55-
func CreateConfigMap(name string, options CreateConfigMapOptions) (*v1.ConfigMap, error) {
55+
func GetOrCreateConfigMap(name string, options CreateConfigMapOptions) (*v1.ConfigMap, error) {
5656
clientset := options.Clientset
5757
ctx := options.Ctx
5858
configMap, err := clientset.Get(ctx, name, metav1.GetOptions{})

pkg/plugin/httproute.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func (r *RpcPlugin) setHTTPHeaderRoute(rollout *v1alpha1.Rollout, headerRouting
8484
httpRouteClient = gatewayV1beta1.HTTPRoutes(gatewayAPIConfig.Namespace)
8585
clientset = r.Clientset.CoreV1().ConfigMaps(gatewayAPIConfig.Namespace)
8686
}
87-
configMap, err := utils.CreateConfigMap(gatewayAPIConfig.ConfigMap, utils.CreateConfigMapOptions{
87+
configMap, err := utils.GetOrCreateConfigMap(gatewayAPIConfig.ConfigMap, utils.CreateConfigMapOptions{
8888
Clientset: clientset,
8989
Ctx: ctx,
9090
})
@@ -259,7 +259,10 @@ func (r *RpcPlugin) removeHTTPManagedRoutes(managedRouteNameList []v1alpha1.Mang
259259
httpRouteClient = gatewayV1beta1.HTTPRoutes(gatewayAPIConfig.Namespace)
260260
clientset = r.Clientset.CoreV1().ConfigMaps(gatewayAPIConfig.Namespace)
261261
}
262-
configMap, err := clientset.Get(ctx, gatewayAPIConfig.ConfigMap, metav1.GetOptions{})
262+
configMap, err := utils.GetOrCreateConfigMap(gatewayAPIConfig.ConfigMap, utils.CreateConfigMapOptions{
263+
Clientset: clientset,
264+
Ctx: ctx,
265+
})
263266
if err != nil {
264267
return pluginTypes.RpcError{
265268
ErrorString: err.Error(),
@@ -278,20 +281,25 @@ func (r *RpcPlugin) removeHTTPManagedRoutes(managedRouteNameList []v1alpha1.Mang
278281
}
279282
}
280283
httpRouteRuleList := HTTPRouteRuleList(httpRoute.Spec.Rules)
284+
isHTTPRouteRuleListChanged := false
281285
for _, managedRoute := range managedRouteNameList {
282286
managedRouteName := managedRoute.Name
283287
_, isOk := managedRouteMap[managedRouteName]
284288
if !isOk {
285289
r.LogCtx.Logger.Info(fmt.Sprintf("%s is not in httpHeaderManagedRouteMap", managedRouteName))
286290
continue
287291
}
292+
isHTTPRouteRuleListChanged = true
288293
httpRouteRuleList, err = removeManagedRouteEntry(managedRouteMap, httpRouteRuleList, managedRouteName)
289294
if err != nil {
290295
return pluginTypes.RpcError{
291296
ErrorString: err.Error(),
292297
}
293298
}
294299
}
300+
if !isHTTPRouteRuleListChanged {
301+
return pluginTypes.RpcError{}
302+
}
295303
oldHTTPRuleList := httpRoute.Spec.Rules
296304
httpRoute.Spec.Rules = httpRouteRuleList
297305
oldConfigMapData := make(map[string]int)

0 commit comments

Comments
 (0)