mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 11:21:47 +00:00
Merge pull request #72007 from anfernee/session-affinity-2
Logs [pod,node] pairs for sessionAffinity test
This commit is contained in:
commit
680ee44f05
@ -25,7 +25,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"k8s.io/api/core/v1"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
policyv1beta1 "k8s.io/api/policy/v1beta1"
|
||||
"k8s.io/apimachinery/pkg/api/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
@ -109,6 +109,14 @@ type ServiceTestJig struct {
|
||||
Labels map[string]string
|
||||
}
|
||||
|
||||
// PodNode is a pod-node pair indicating which node a given pod is running on
|
||||
type PodNode struct {
|
||||
// Pod represents pod name
|
||||
Pod string
|
||||
// Node represents node name
|
||||
Node string
|
||||
}
|
||||
|
||||
// NewServiceTestJig allocates and inits a new ServiceTestJig.
|
||||
func NewServiceTestJig(client clientset.Interface, name string) *ServiceTestJig {
|
||||
j := &ServiceTestJig{}
|
||||
@ -348,6 +356,25 @@ func PickNodeIP(c clientset.Interface) string {
|
||||
return ip
|
||||
}
|
||||
|
||||
// PodNodePairs return PodNode pairs for all pods in a namespace
|
||||
func PodNodePairs(c clientset.Interface, ns string) ([]PodNode, error) {
|
||||
var result []PodNode
|
||||
|
||||
podList, err := c.CoreV1().Pods(ns).List(metav1.ListOptions{})
|
||||
if err != nil {
|
||||
return result, err
|
||||
}
|
||||
|
||||
for _, pod := range podList.Items {
|
||||
result = append(result, PodNode{
|
||||
Pod: pod.Name,
|
||||
Node: pod.Spec.NodeName,
|
||||
})
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// GetEndpointNodes returns a map of nodenames:external-ip on which the
|
||||
// endpoints of the given Service are running.
|
||||
func (j *ServiceTestJig) GetEndpointNodes(svc *v1.Service) map[string][]string {
|
||||
|
@ -27,7 +27,7 @@ import (
|
||||
|
||||
compute "google.golang.org/api/compute/v1"
|
||||
|
||||
"k8s.io/api/core/v1"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/labels"
|
||||
"k8s.io/apimachinery/pkg/util/intstr"
|
||||
@ -2111,6 +2111,8 @@ func execAffinityTestForLBService(f *framework.Framework, cs clientset.Interface
|
||||
svc = jig.WaitForLoadBalancerOrFail(ns, serviceName, framework.LoadBalancerCreateTimeoutDefault)
|
||||
jig.SanityCheckService(svc, v1.ServiceTypeLoadBalancer)
|
||||
defer func() {
|
||||
podNodePairs, err := framework.PodNodePairs(cs, ns)
|
||||
framework.Logf("[pod,node] pairs: %+v; err: %v", podNodePairs, err)
|
||||
framework.StopServeHostnameService(cs, ns, serviceName)
|
||||
lb := cloudprovider.DefaultLoadBalancerName(svc)
|
||||
framework.Logf("cleaning load balancer resource for %s", lb)
|
||||
|
Loading…
Reference in New Issue
Block a user