ports.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. Copyright 2019 The Kubernetes Authors.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. /*
  14. This soak tests places a specified number of pods on each node and then
  15. repeatedly sends queries to a service running on these pods via
  16. a serivce
  17. */
  18. package endpoints
  19. import (
  20. v1 "k8s.io/api/core/v1"
  21. "k8s.io/apimachinery/pkg/types"
  22. )
  23. // PortsByPodUID is a map that maps pod UID to container ports.
  24. type PortsByPodUID map[types.UID][]int
  25. // GetContainerPortsByPodUID returns a PortsByPodUID map on the given endpoints.
  26. func GetContainerPortsByPodUID(ep *v1.Endpoints) PortsByPodUID {
  27. m := PortsByPodUID{}
  28. for _, ss := range ep.Subsets {
  29. for _, port := range ss.Ports {
  30. for _, addr := range ss.Addresses {
  31. containerPort := port.Port
  32. if _, ok := m[addr.TargetRef.UID]; !ok {
  33. m[addr.TargetRef.UID] = make([]int, 0)
  34. }
  35. m[addr.TargetRef.UID] = append(m[addr.TargetRef.UID], int(containerPort))
  36. }
  37. }
  38. }
  39. return m
  40. }