func (t *Switcher) TrafficWeights(ctx context.Context, stackset, namespace string) ([]StackTrafficWeight, error) {
	stacks, err := t.getStacks(ctx, stackset, namespace)
	if err != nil {
		return nil, err
	}
	return normalizeWeights(stacks), nil
}
TrafficWeights returns a list of stacks with their current traffic weight.
package traffic
import (
	"context"
	"encoding/json"
	"fmt"
	zv1 "github.com/zalando-incubator/stackset-controller/pkg/apis/zalando.org/v1"
	"github.com/zalando-incubator/stackset-controller/pkg/clientset"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	"k8s.io/apimachinery/pkg/labels"
	"k8s.io/apimachinery/pkg/types"
)
const (
	stacksetHeritageLabelKey           = "stackset"
	StackTrafficWeightsAnnotationKey   = "zalando.org/stack-traffic-weights"
	DefaultBackendWeightsAnnotationKey = "zalando.org/backend-weights"
)
type Switcher struct {
	client                      clientset.Interface
	backendWeightsAnnotationKey string
}
func NewSwitcher(client clientset.Interface, backendWeightsAnnotationKey string) *Switcher {
	return &Switcher{
		client:                      client,
		backendWeightsAnnotationKey: backendWeightsAnnotationKey,
	}
}
func (t *Switcher) Switch(ctx context.Context, stackset, stack, namespace string, weight float64) ([]StackTrafficWeight, error) {
	stacks, err := t.getStacks(ctx, stackset, namespace)
	if err != nil {
		return nil, err
	}
	normalized := normalizeWeights(stacks)
	newWeights, err := setWeightForStacks(normalized, stack, weight)
	if err != nil {
		return nil, err
	}
	changeNeeded := false
	stackWeights := make(map[string]float64, len(newWeights))
	for i, stack := range newWeights {
		if stack.Weight != stacks[i].Weight {
			changeNeeded = true
		}
		stackWeights[stack.Name] = stack.Weight
	}
	if changeNeeded {
		stackWeightsData, err := json.Marshal(&stackWeights)
		if err != nil {
			return nil, err
		}
		annotation := map[string]map[string]map[string]string{
			"metadata": map[string]map[string]string{
				"annotations": map[string]string{
					StackTrafficWeightsAnnotationKey: string(stackWeightsData),
				},
			},
		}
		annotationData, err := json.Marshal(&annotation)
		if err != nil {
			return nil, err
		}
		_, err = t.client.NetworkingV1().Ingresses(namespace).Patch(ctx, stackset, types.StrategicMergePatchType, annotationData, metav1.PatchOptions{})
		if err != nil {
			return nil, err
		}
	}
	return newWeights, nil
}
type StackTrafficWeight struct {
	Name         string
	Weight       float64
	ActualWeight float64
}