Skip to content

Commit

Permalink
Consider all HTTPProxy routes when listing services
Browse files Browse the repository at this point in the history
Signed-off-by: Mario Bezerra <mario.bezerra@incognia.com>
  • Loading branch information
mvgmb committed May 16, 2023
1 parent 169bbaf commit b1fca59
Showing 1 changed file with 10 additions and 25 deletions.
35 changes: 10 additions & 25 deletions pkg/plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,8 @@ func (r *RpcPlugin) SetWeight(
slog.Debug("the services name", slog.String("stable", stableSvcName), slog.String("canary", canarySvcName))

// TODO: filter by condition(s)
services := utils.Must1(getServiceList(httpProxy.Spec.Routes))
canarySvc := utils.Must1(getService(canarySvcName, services))
stableSvc := utils.Must1(getService(stableSvcName, services))
canarySvc := utils.Must1(getService(canarySvcName, &httpProxy))
stableSvc := utils.Must1(getService(stableSvcName, &httpProxy))

slog.Debug("old weight", slog.Int64("canary", canarySvc.Weight), slog.Int64("stable", stableSvc.Weight))

Expand All @@ -115,30 +114,16 @@ func (r *RpcPlugin) SetWeight(
return
}

func getService(name string, services []contourv1.Service) (*contourv1.Service, error) {
var selected *contourv1.Service
for i := 0; i < len(services); i++ {

svc := &services[i]
if svc.Name == name {
selected = svc
break
}
}
if selected == nil {
return nil, fmt.Errorf("the service: %s is not found in HTTPProxy", name)
}
return selected, nil
}

func getServiceList(routes []contourv1.Route) ([]contourv1.Service, error) {
for _, r := range routes {
if r.Services == nil {
continue
func getService(name string, httpProxy *contourv1.HTTPProxy) (*contourv1.Service, error) {
for _, r := range httpProxy.Spec.Routes {
for i := range r.Services {
s := &r.Services[i]
if s.Name == name {
return s, nil
}
}
return r.Services, nil
}
return nil, errors.New("the services are not found in HTTPProxy")
return nil, fmt.Errorf("the service: %s is not found in HTTPProxy", name)
}

func (r *RpcPlugin) SetHeaderRoute(rollout *v1alpha1.Rollout, headerRouting *v1alpha1.SetHeaderRoute) pluginTypes.RpcError {
Expand Down

0 comments on commit b1fca59

Please sign in to comment.