mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 12:43:23 +00:00
Merge pull request #75073 from grayluck/esipp
Allow session affinity a period of time to setup for new services.
This commit is contained in:
commit
968d833617
@ -1453,6 +1453,7 @@ type affinityTracker struct {
|
|||||||
// Record the response going to a given host.
|
// Record the response going to a given host.
|
||||||
func (at *affinityTracker) recordHost(host string) {
|
func (at *affinityTracker) recordHost(host string) {
|
||||||
at.hostTrace = append(at.hostTrace, host)
|
at.hostTrace = append(at.hostTrace, host)
|
||||||
|
Logf("Received response from host: %s", host)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check that we got a constant count requests going to the same host.
|
// Check that we got a constant count requests going to the same host.
|
||||||
@ -1480,13 +1481,11 @@ func checkAffinityFailed(tracker affinityTracker, err string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CheckAffinity function tests whether the service affinity works as expected.
|
// CheckAffinity function tests whether the service affinity works as expected.
|
||||||
// If affinity is expected and transitionState is true, the test will
|
// If affinity is expected, the test will return true once affinityConfirmCount
|
||||||
// return true once affinityConfirmCount number of same response observed in a
|
// number of same response observed in a row. If affinity is not expected, the
|
||||||
// row. If affinity is not expected, the test will keep observe until different
|
// test will keep observe until different responses observed. The function will
|
||||||
// responses observed. The function will return false only when no expected
|
// return false only in case of unexpected errors.
|
||||||
// responses observed before timeout. If transitionState is false, the test will
|
func CheckAffinity(jig *ServiceTestJig, execPod *v1.Pod, targetIp string, targetPort int, shouldHold bool) bool {
|
||||||
// fail once different host is given if shouldHold is true.
|
|
||||||
func CheckAffinity(jig *ServiceTestJig, execPod *v1.Pod, targetIp string, targetPort int, shouldHold, transitionState bool) bool {
|
|
||||||
targetIpPort := net.JoinHostPort(targetIp, strconv.Itoa(targetPort))
|
targetIpPort := net.JoinHostPort(targetIp, strconv.Itoa(targetPort))
|
||||||
cmd := fmt.Sprintf(`wget -qO- http://%s/ -T 2`, targetIpPort)
|
cmd := fmt.Sprintf(`wget -qO- http://%s/ -T 2`, targetIpPort)
|
||||||
timeout := ServiceTestTimeout
|
timeout := ServiceTestTimeout
|
||||||
@ -1510,13 +1509,8 @@ func CheckAffinity(jig *ServiceTestJig, execPod *v1.Pod, targetIp string, target
|
|||||||
if !shouldHold && !affinityHolds {
|
if !shouldHold && !affinityHolds {
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
if shouldHold {
|
if shouldHold && trackerFulfilled && affinityHolds {
|
||||||
if !transitionState && !affinityHolds {
|
return true, nil
|
||||||
return true, fmt.Errorf("Affinity should hold but didn't.")
|
|
||||||
}
|
|
||||||
if trackerFulfilled && affinityHolds {
|
|
||||||
return true, nil
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return false, nil
|
return false, nil
|
||||||
}); pollErr != nil {
|
}); pollErr != nil {
|
||||||
|
@ -2200,17 +2200,17 @@ func execAffinityTestForNonLBService(f *framework.Framework, cs clientset.Interf
|
|||||||
Expect(err).NotTo(HaveOccurred(), "failed to fetch pod: %s in namespace: %s", execPodName, ns)
|
Expect(err).NotTo(HaveOccurred(), "failed to fetch pod: %s in namespace: %s", execPodName, ns)
|
||||||
|
|
||||||
if !isTransitionTest {
|
if !isTransitionTest {
|
||||||
Expect(framework.CheckAffinity(jig, execPod, svcIp, servicePort, true, false)).To(BeTrue())
|
Expect(framework.CheckAffinity(jig, execPod, svcIp, servicePort, true)).To(BeTrue())
|
||||||
}
|
}
|
||||||
if isTransitionTest {
|
if isTransitionTest {
|
||||||
svc = jig.UpdateServiceOrFail(svc.Namespace, svc.Name, func(svc *v1.Service) {
|
svc = jig.UpdateServiceOrFail(svc.Namespace, svc.Name, func(svc *v1.Service) {
|
||||||
svc.Spec.SessionAffinity = v1.ServiceAffinityNone
|
svc.Spec.SessionAffinity = v1.ServiceAffinityNone
|
||||||
})
|
})
|
||||||
Expect(framework.CheckAffinity(jig, execPod, svcIp, servicePort, false, true)).To(BeTrue())
|
Expect(framework.CheckAffinity(jig, execPod, svcIp, servicePort, false)).To(BeTrue())
|
||||||
svc = jig.UpdateServiceOrFail(svc.Namespace, svc.Name, func(svc *v1.Service) {
|
svc = jig.UpdateServiceOrFail(svc.Namespace, svc.Name, func(svc *v1.Service) {
|
||||||
svc.Spec.SessionAffinity = v1.ServiceAffinityClientIP
|
svc.Spec.SessionAffinity = v1.ServiceAffinityClientIP
|
||||||
})
|
})
|
||||||
Expect(framework.CheckAffinity(jig, execPod, svcIp, servicePort, true, true)).To(BeTrue())
|
Expect(framework.CheckAffinity(jig, execPod, svcIp, servicePort, true)).To(BeTrue())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2240,16 +2240,16 @@ func execAffinityTestForLBService(f *framework.Framework, cs clientset.Interface
|
|||||||
port := int(svc.Spec.Ports[0].Port)
|
port := int(svc.Spec.Ports[0].Port)
|
||||||
|
|
||||||
if !isTransitionTest {
|
if !isTransitionTest {
|
||||||
Expect(framework.CheckAffinity(jig, nil, ingressIP, port, true, false)).To(BeTrue())
|
Expect(framework.CheckAffinity(jig, nil, ingressIP, port, true)).To(BeTrue())
|
||||||
}
|
}
|
||||||
if isTransitionTest {
|
if isTransitionTest {
|
||||||
svc = jig.UpdateServiceOrFail(svc.Namespace, svc.Name, func(svc *v1.Service) {
|
svc = jig.UpdateServiceOrFail(svc.Namespace, svc.Name, func(svc *v1.Service) {
|
||||||
svc.Spec.SessionAffinity = v1.ServiceAffinityNone
|
svc.Spec.SessionAffinity = v1.ServiceAffinityNone
|
||||||
})
|
})
|
||||||
Expect(framework.CheckAffinity(jig, nil, ingressIP, port, false, true)).To(BeTrue())
|
Expect(framework.CheckAffinity(jig, nil, ingressIP, port, false)).To(BeTrue())
|
||||||
svc = jig.UpdateServiceOrFail(svc.Namespace, svc.Name, func(svc *v1.Service) {
|
svc = jig.UpdateServiceOrFail(svc.Namespace, svc.Name, func(svc *v1.Service) {
|
||||||
svc.Spec.SessionAffinity = v1.ServiceAffinityClientIP
|
svc.Spec.SessionAffinity = v1.ServiceAffinityClientIP
|
||||||
})
|
})
|
||||||
Expect(framework.CheckAffinity(jig, nil, ingressIP, port, true, true)).To(BeTrue())
|
Expect(framework.CheckAffinity(jig, nil, ingressIP, port, true)).To(BeTrue())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user