github.com/solo-io/service-mesh-hub@v0.9.2/test/data/traffic_policies.go (about)

     1  package data
     2  
     3  import (
     4  	"github.com/solo-io/service-mesh-hub/pkg/api/networking.smh.solo.io/v1alpha2"
     5  	v1 "github.com/solo-io/skv2/pkg/api/core.skv2.solo.io/v1"
     6  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
     7  )
     8  
     9  // shifts traffic to a subset in the local cluster
    10  func LocalTrafficShiftPolicy(
    11  	name, namespace string,
    12  	destinationService *v1.ClusterObjectRef,
    13  	subset map[string]string,
    14  	port uint32) *v1alpha2.TrafficPolicy {
    15  	return &v1alpha2.TrafficPolicy{
    16  		ObjectMeta: metav1.ObjectMeta{
    17  			Name:      name,
    18  			Namespace: namespace,
    19  		},
    20  		TypeMeta: metav1.TypeMeta{
    21  			Kind:       "TrafficPolicy",
    22  			APIVersion: v1alpha2.SchemeGroupVersion.String(),
    23  		},
    24  		Spec: v1alpha2.TrafficPolicySpec{
    25  			SourceSelector: nil,
    26  			DestinationSelector: []*v1alpha2.TrafficTargetSelector{{
    27  				KubeServiceRefs: &v1alpha2.TrafficTargetSelector_KubeServiceRefs{
    28  					Services: []*v1.ClusterObjectRef{destinationService},
    29  				},
    30  			}},
    31  			TrafficShift: &v1alpha2.TrafficPolicySpec_MultiDestination{
    32  				Destinations: []*v1alpha2.TrafficPolicySpec_MultiDestination_WeightedDestination{{
    33  					DestinationType: &v1alpha2.TrafficPolicySpec_MultiDestination_WeightedDestination_KubeService{
    34  						KubeService: &v1alpha2.TrafficPolicySpec_MultiDestination_WeightedDestination_KubeDestination{
    35  							Namespace:   destinationService.GetNamespace(),
    36  							Name:        destinationService.GetName(),
    37  							ClusterName: destinationService.GetClusterName(),
    38  							Subset:      subset,
    39  							Port:        port,
    40  						},
    41  					},
    42  				}},
    43  			},
    44  		},
    45  	}
    46  }
    47  
    48  // shifts traffic to a subset in the remote cluster
    49  func RemoteTrafficShiftPolicy(
    50  	name, namespace string,
    51  	destinationService *v1.ClusterObjectRef,
    52  	subsetCluster string,
    53  	subset map[string]string,
    54  	port uint32) *v1alpha2.TrafficPolicy {
    55  	return &v1alpha2.TrafficPolicy{
    56  		ObjectMeta: metav1.ObjectMeta{
    57  			Name:      name,
    58  			Namespace: namespace,
    59  		},
    60  		TypeMeta: metav1.TypeMeta{
    61  			Kind:       "TrafficPolicy",
    62  			APIVersion: v1alpha2.SchemeGroupVersion.String(),
    63  		},
    64  		Spec: v1alpha2.TrafficPolicySpec{
    65  			SourceSelector: nil,
    66  			DestinationSelector: []*v1alpha2.TrafficTargetSelector{{
    67  				KubeServiceRefs: &v1alpha2.TrafficTargetSelector_KubeServiceRefs{
    68  					Services: []*v1.ClusterObjectRef{destinationService},
    69  				},
    70  			}},
    71  			TrafficShift: &v1alpha2.TrafficPolicySpec_MultiDestination{
    72  				Destinations: []*v1alpha2.TrafficPolicySpec_MultiDestination_WeightedDestination{{
    73  					DestinationType: &v1alpha2.TrafficPolicySpec_MultiDestination_WeightedDestination_KubeService{
    74  						KubeService: &v1alpha2.TrafficPolicySpec_MultiDestination_WeightedDestination_KubeDestination{
    75  							Namespace:   destinationService.GetNamespace(),
    76  							Name:        destinationService.GetName(),
    77  							ClusterName: subsetCluster,
    78  							Subset:      subset,
    79  							Port:        port,
    80  						},
    81  					},
    82  				}},
    83  			},
    84  		},
    85  	}
    86  }