Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider all HTTPProxy route services #16

Merged
merged 3 commits into from
Jul 17, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))
izturn marked this conversation as resolved.
Show resolved Hide resolved
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