mirror of https://github.com/k3s-io/k3s
Unit tests for Azure service session affinity
parent
7f49a2ccfc
commit
79273adb52
|
@ -293,6 +293,89 @@ func TestReconcileLoadBalancerMultipleServices(t *testing.T) {
|
||||||
validateLoadBalancer(t, updatedLoadBalancer, svc1, svc2)
|
validateLoadBalancer(t, updatedLoadBalancer, svc1, svc2)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func findLBRuleForPort(lbRules []network.LoadBalancingRule, port int32) (network.LoadBalancingRule, error) {
|
||||||
|
for _, lbRule := range lbRules {
|
||||||
|
if *lbRule.FrontendPort == port {
|
||||||
|
return lbRule, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return network.LoadBalancingRule{}, fmt.Errorf("Expected LB rule with port %d but none found", port)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestServiceDefaultsToNoSessionPersistence(t *testing.T) {
|
||||||
|
az := getTestCloud()
|
||||||
|
svc := getTestService("service-sa-omitted", v1.ProtocolTCP, 7170)
|
||||||
|
configProperties := getTestPublicFipConfigurationProperties()
|
||||||
|
lb := getTestLoadBalancer()
|
||||||
|
nodes := []*v1.Node{}
|
||||||
|
|
||||||
|
lb, _, err := az.reconcileLoadBalancer(lb, &configProperties, testClusterName, &svc, nodes)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Unexpected error reconciling svc1: %q", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
validateLoadBalancer(t, lb, svc)
|
||||||
|
|
||||||
|
lbRule, err := findLBRuleForPort(*lb.LoadBalancingRules, 7170)
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if lbRule.LoadDistribution != network.Default {
|
||||||
|
t.Errorf("Expected LB rule to have default load distribution but was %s", lbRule.LoadDistribution)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestServiceRespectsNoSessionAffinity(t *testing.T) {
|
||||||
|
az := getTestCloud()
|
||||||
|
svc := getTestService("service-sa-none", v1.ProtocolTCP, 7170)
|
||||||
|
svc.Spec.SessionAffinity = v1.ServiceAffinityNone
|
||||||
|
configProperties := getTestPublicFipConfigurationProperties()
|
||||||
|
lb := getTestLoadBalancer()
|
||||||
|
nodes := []*v1.Node{}
|
||||||
|
|
||||||
|
lb, _, err := az.reconcileLoadBalancer(lb, &configProperties, testClusterName, &svc, nodes)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Unexpected error reconciling svc1: %q", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
validateLoadBalancer(t, lb, svc)
|
||||||
|
|
||||||
|
lbRule, err := findLBRuleForPort(*lb.LoadBalancingRules, 7170)
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if lbRule.LoadDistribution != network.Default {
|
||||||
|
t.Errorf("Expected LB rule to have default load distribution but was %s", lbRule.LoadDistribution)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestServiceRespectsClientIPSessionAffinity(t *testing.T) {
|
||||||
|
az := getTestCloud()
|
||||||
|
svc := getTestService("service-sa-clientip", v1.ProtocolTCP, 7170)
|
||||||
|
svc.Spec.SessionAffinity = v1.ServiceAffinityClientIP
|
||||||
|
configProperties := getTestPublicFipConfigurationProperties()
|
||||||
|
lb := getTestLoadBalancer()
|
||||||
|
nodes := []*v1.Node{}
|
||||||
|
|
||||||
|
lb, _, err := az.reconcileLoadBalancer(lb, &configProperties, testClusterName, &svc, nodes)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Unexpected error reconciling svc1: %q", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
validateLoadBalancer(t, lb, svc)
|
||||||
|
|
||||||
|
lbRule, err := findLBRuleForPort(*lb.LoadBalancingRules, 7170)
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if lbRule.LoadDistribution != network.SourceIP {
|
||||||
|
t.Errorf("Expected LB rule to have SourceIP load distribution but was %s", lbRule.LoadDistribution)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestReconcileSecurityGroupNewServiceAddsPort(t *testing.T) {
|
func TestReconcileSecurityGroupNewServiceAddsPort(t *testing.T) {
|
||||||
az := getTestCloud()
|
az := getTestCloud()
|
||||||
svc1 := getTestService("serviceea", v1.ProtocolTCP, 80)
|
svc1 := getTestService("serviceea", v1.ProtocolTCP, 80)
|
||||||
|
|
Loading…
Reference in New Issue