forked from joeholley/supergloo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
trafficshifting.go
40 lines (35 loc) · 1.02 KB
/
trafficshifting.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package surveyutils
import (
"context"
"fmt"
"github.com/solo-io/gloo/pkg/cliutil"
gloov1 "github.com/solo-io/gloo/projects/gloo/pkg/api/v1"
"github.com/solo-io/supergloo/cli/pkg/options"
v1 "github.com/solo-io/supergloo/pkg/api/v1"
)
func SurveyTrafficShiftingSpec(ctx context.Context, in *options.CreateRoutingRule) error {
ts := v1.TrafficShifting{
Destinations: &gloov1.MultiDestination{
Destinations: []*gloov1.WeightedDestination{},
},
}
fmt.Println("select the upstreams to which you wish to direct traffic")
ups, err := SurveyUpstreams(ctx)
if err != nil {
return err
}
for _, us := range ups {
var weight uint32
if err := cliutil.GetUint32Input(fmt.Sprintf("choose a weight for %v", us), &weight); err != nil {
return err
}
ts.Destinations.Destinations = append(ts.Destinations.Destinations, &gloov1.WeightedDestination{
Destination: &gloov1.Destination{
Upstream: us,
},
Weight: weight,
})
}
in.RoutingRuleSpec.TrafficShifting = options.TrafficShiftingValue(ts)
return nil
}