Skip to content

Commit

Permalink
feat(NSC.utils): add getPodListForService & getServiceForServiceInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
aauren committed Apr 27, 2024
1 parent b270750 commit a633849
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions pkg/controllers/proxy/utils.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package proxy

import (
"context"
"errors"
"fmt"
"hash/fnv"
Expand All @@ -17,6 +18,8 @@ import (
"github.com/vishvananda/netlink"
"github.com/vishvananda/netns"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/klog/v2"
netutils "k8s.io/utils/net"
)
Expand Down Expand Up @@ -327,6 +330,24 @@ func (nsc *NetworkServicesController) getPodObjectForEndpointIP(endpointIP strin
return nil, errors.New("Failed to find pod with ip " + endpointIP)
}

func (nsc *NetworkServicesController) getServiceForServiceInfo(svcIn *serviceInfo) (*v1.Service, error) {
svc, err := nsc.client.CoreV1().Services(svcIn.namespace).Get(context.Background(), svcIn.name, metav1.GetOptions{})
if err != nil {
return nil, err
}
return svc, err
}

func (nsc *NetworkServicesController) getPodListForService(svc *v1.Service) (*v1.PodList, error) {
lbSet := labels.Set(svc.Spec.Selector)
listOpts := metav1.ListOptions{LabelSelector: lbSet.AsSelector().String()}
pods, err := nsc.client.CoreV1().Pods(svc.Namespace).List(context.Background(), listOpts)
if err != nil {
return nil, err
}
return pods, err
}

// 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 a633849

Please sign in to comment.