Skip to content

Commit

Permalink
fact: nsc.getPodObjectForEndpoint -> nsc.getPodObjectForEndpointIP
Browse files Browse the repository at this point in the history
  • Loading branch information
aauren committed Apr 27, 2024
1 parent 567c891 commit b270750
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion pkg/controllers/proxy/network_service_graceful.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (nsc *NetworkServicesController) addToGracefulQueue(req *gracefulRequest) {
}
if !alreadyExists {
// try to get get Termination grace period from the pod, if unsuccesfull use the default timeout
podObj, err := nsc.getPodObjectForEndpoint(req.ipvsDst.Address.String())
podObj, err := nsc.getPodObjectForEndpointIP(req.ipvsDst.Address.String())
if err != nil {
klog.V(1).Infof("Failed to find endpoint with ip: %s err: %s",
req.ipvsDst.Address.String(), err.Error())
Expand Down
12 changes: 0 additions & 12 deletions pkg/controllers/proxy/network_services_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -893,18 +893,6 @@ func hasActiveEndpoints(endpoints []endpointSliceInfo) bool {
return false
}

func (nsc *NetworkServicesController) getPodObjectForEndpoint(endpointIP string) (*v1.Pod, error) {
for _, obj := range nsc.podLister.List() {
pod := obj.(*v1.Pod)
for _, ip := range pod.Status.PodIPs {
if strings.Compare(ip.IP, endpointIP) == 0 {
return pod, nil
}
}
}
return nil, errors.New("Failed to find pod with ip " + endpointIP)
}

func (nsc *NetworkServicesController) buildServicesInfo() serviceInfoMap {
serviceMap := make(serviceInfoMap)
for _, obj := range nsc.svcLister.List() {
Expand Down
15 changes: 14 additions & 1 deletion pkg/controllers/proxy/utils.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package proxy

import (
"errors"
"fmt"
"hash/fnv"
"net"
Expand Down Expand Up @@ -197,7 +198,7 @@ func convertSysCallProtoToSvcProto(sysProtocol uint16) string {
// namespace, it doesn't really matter which container we choose here, if this function gets used for something
// else in the future, this might have to be re-evaluated)
func (nsc *NetworkServicesController) findContainerRuntimeReferences(endpointIP string) (string, string, error) {
podObj, err := nsc.getPodObjectForEndpoint(endpointIP)
podObj, err := nsc.getPodObjectForEndpointIP(endpointIP)
if err != nil {
return "", "", fmt.Errorf("failed to find endpoint with ip: %s. so skipping preparing endpoint for DSR",
endpointIP)
Expand Down Expand Up @@ -314,6 +315,18 @@ func (nsc *NetworkServicesController) getPrimaryAndCIDRsByFamily(ipFamily v1.IPF
return primaryIP, cidrs
}

func (nsc *NetworkServicesController) getPodObjectForEndpointIP(endpointIP string) (*v1.Pod, error) {
for _, obj := range nsc.podLister.List() {
pod := obj.(*v1.Pod)
for _, ip := range pod.Status.PodIPs {
if strings.Compare(ip.IP, endpointIP) == 0 {
return pod, nil
}
}
}
return nil, errors.New("Failed to find pod with ip " + endpointIP)
}

// GetAllClusterIPs returns all of the cluster IPs on a service separated into IPv4 and IPv6 lists
func getAllClusterIPs(svc *serviceInfo) map[v1.IPFamily][]net.IP {
// We use maps here so that we can de-duplicate repeat IP addresses
Expand Down

0 comments on commit b270750

Please sign in to comment.