Skip to content

Commit

Permalink
fix: handle the signal removeManagedRoutes before creating config map (
Browse files Browse the repository at this point in the history
…#37)

* fix: handle the signal removeManagedRoutes before creating config map

Signed-off-by: Philipp Plotnikov <philipp.plotnikov@icloud.com>

* refactor: rename CreateConfigMap func to GetOrCreateConfigMap

Signed-off-by: Philipp Plotnikov <philipp.plotnikov@icloud.com>

* refactor: update config on removeHTTPManagedRoutes only it needs

Signed-off-by: Philipp Plotnikov <philipp.plotnikov@icloud.com>

---------

Signed-off-by: Philipp Plotnikov <philipp.plotnikov@icloud.com>
  • Loading branch information
Philipp-Plotnikov authored Feb 19, 2024
1 parent 59f8145 commit d059156
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion internal/utils/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func CreateFormatter(logFormat string) log.Formatter {
return formatType
}

func CreateConfigMap(name string, options CreateConfigMapOptions) (*v1.ConfigMap, error) {
func GetOrCreateConfigMap(name string, options CreateConfigMapOptions) (*v1.ConfigMap, error) {
clientset := options.Clientset
ctx := options.Ctx
configMap, err := clientset.Get(ctx, name, metav1.GetOptions{})
Expand Down
12 changes: 10 additions & 2 deletions pkg/plugin/httproute.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (r *RpcPlugin) setHTTPHeaderRoute(rollout *v1alpha1.Rollout, headerRouting
httpRouteClient = gatewayV1beta1.HTTPRoutes(gatewayAPIConfig.Namespace)
clientset = r.Clientset.CoreV1().ConfigMaps(gatewayAPIConfig.Namespace)
}
configMap, err := utils.CreateConfigMap(gatewayAPIConfig.ConfigMap, utils.CreateConfigMapOptions{
configMap, err := utils.GetOrCreateConfigMap(gatewayAPIConfig.ConfigMap, utils.CreateConfigMapOptions{
Clientset: clientset,
Ctx: ctx,
})
Expand Down Expand Up @@ -259,7 +259,10 @@ func (r *RpcPlugin) removeHTTPManagedRoutes(managedRouteNameList []v1alpha1.Mang
httpRouteClient = gatewayV1beta1.HTTPRoutes(gatewayAPIConfig.Namespace)
clientset = r.Clientset.CoreV1().ConfigMaps(gatewayAPIConfig.Namespace)
}
configMap, err := clientset.Get(ctx, gatewayAPIConfig.ConfigMap, metav1.GetOptions{})
configMap, err := utils.GetOrCreateConfigMap(gatewayAPIConfig.ConfigMap, utils.CreateConfigMapOptions{
Clientset: clientset,
Ctx: ctx,
})
if err != nil {
return pluginTypes.RpcError{
ErrorString: err.Error(),
Expand All @@ -278,20 +281,25 @@ func (r *RpcPlugin) removeHTTPManagedRoutes(managedRouteNameList []v1alpha1.Mang
}
}
httpRouteRuleList := HTTPRouteRuleList(httpRoute.Spec.Rules)
isHTTPRouteRuleListChanged := false
for _, managedRoute := range managedRouteNameList {
managedRouteName := managedRoute.Name
_, isOk := managedRouteMap[managedRouteName]
if !isOk {
r.LogCtx.Logger.Info(fmt.Sprintf("%s is not in httpHeaderManagedRouteMap", managedRouteName))
continue
}
isHTTPRouteRuleListChanged = true
httpRouteRuleList, err = removeManagedRouteEntry(managedRouteMap, httpRouteRuleList, managedRouteName)
if err != nil {
return pluginTypes.RpcError{
ErrorString: err.Error(),
}
}
}
if !isHTTPRouteRuleListChanged {
return pluginTypes.RpcError{}
}
oldHTTPRuleList := httpRoute.Spec.Rules
httpRoute.Spec.Rules = httpRouteRuleList
oldConfigMapData := make(map[string]int)
Expand Down

0 comments on commit d059156

Please sign in to comment.