Skip to content

Commit

Permalink
Remove unused utility func
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-gshe committed Feb 26, 2024
1 parent 034b4d9 commit 0b6c8ef
Show file tree
Hide file tree
Showing 5 changed files with 0 additions and 186 deletions.
9 changes: 0 additions & 9 deletions pkg/observer/observertesthelper/observer_test_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import (
"github.com/cilium/tetragon/pkg/cilium"
"github.com/cilium/tetragon/pkg/exporter"
tetragonGrpc "github.com/cilium/tetragon/pkg/grpc"
"github.com/cilium/tetragon/pkg/k8s/apis/cilium.io/v1alpha1"
"github.com/cilium/tetragon/pkg/logger"
"github.com/cilium/tetragon/pkg/option"
"github.com/cilium/tetragon/pkg/process"
Expand Down Expand Up @@ -565,14 +564,6 @@ func (f *fakeK8sWatcher) FindContainer(containerID string) (*corev1.Pod, *corev1
return &pod, &container, true
}

func (f *fakeK8sWatcher) FindServiceByIP(ip string) ([]*corev1.Service, error) {
return nil, fmt.Errorf("service with IP %s not found", ip)
}

func (f *fakeK8sWatcher) FindPodInfoByIP(ip string) ([]*v1alpha1.PodInfo, error) {
return nil, fmt.Errorf("PodInfo with IP %s not found", ip)
}

// Used to wait for a process to start, we do a lookup on PROCFS because this
// may be called before obs is created.
func WaitForProcess(process string) error {
Expand Down
19 changes: 0 additions & 19 deletions pkg/watcher/fake.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ package watcher

import (
"fmt"

"github.com/cilium/tetragon/pkg/k8s/apis/cilium.io/v1alpha1"
corev1 "k8s.io/api/core/v1"
)

Expand Down Expand Up @@ -40,19 +38,6 @@ func (watcher *FakeK8sWatcher) FindPod(podID string) (*corev1.Pod, error) {
return nil, fmt.Errorf("podID %s not found (in %d pods)", podID, len(watcher.pods))
}

func (watcher *FakeK8sWatcher) FindServiceByIP(ip string) ([]*corev1.Service, error) {
for i := range watcher.services {
if service, ok := watcher.services[i].(*corev1.Service); ok {
for _, serviceIP := range service.Spec.ClusterIPs {
if serviceIP == ip {
return []*corev1.Service{service}, nil
}
}
}
}
return nil, fmt.Errorf("service with IP %s not found", ip)
}

// AddPod adds a pod to the fake k8s watcher. This is intended for testing.
func (watcher *FakeK8sWatcher) AddPod(pod *corev1.Pod) {
watcher.pods = append(watcher.pods, pod)
Expand All @@ -72,7 +57,3 @@ func (watcher *FakeK8sWatcher) AddService(service *corev1.Service) {
func (watcher *FakeK8sWatcher) ClearAllServices() {
watcher.services = nil
}

func (watcher *FakeK8sWatcher) FindPodInfoByIP(ip string) ([]*v1alpha1.PodInfo, error) {
return nil, fmt.Errorf("PodInfo with IP %q not found", ip)
}
28 changes: 0 additions & 28 deletions pkg/watcher/fake_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,6 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

Check failure on line 11 in pkg/watcher/fake_test.go

View workflow job for this annotation

GitHub Actions / golangci-lint

"k8s.io/apimachinery/pkg/apis/meta/v1" imported as metav1 and not used (typecheck)

Check failure on line 11 in pkg/watcher/fake_test.go

View workflow job for this annotation

GitHub Actions / analyze

"k8s.io/apimachinery/pkg/apis/meta/v1" imported as metav1 and not used
)

func TestFakeK8sWatcher_FindServiceByIP(t *testing.T) {
services := []interface{}{
&corev1.Service{
ObjectMeta: metav1.ObjectMeta{Name: "svc-1"},
Spec: corev1.ServiceSpec{ClusterIPs: []string{"1.1.1.1"}},
},
&corev1.Service{
ObjectMeta: metav1.ObjectMeta{Name: "svc-2"},
Spec: corev1.ServiceSpec{ClusterIPs: []string{"2.2.2.2", "3.3.3.3"}},
},
}
fakeWatcher := NewFakeK8sWatcherWithPodsAndServices(nil, services)
res, err := fakeWatcher.FindServiceByIP("1.1.1.1")
assert.NoError(t, err)
assert.Len(t, res, 1)
assert.Equal(t, res[0].Name, "svc-1")
res, err = fakeWatcher.FindServiceByIP("2.2.2.2")
assert.NoError(t, err)
assert.Len(t, res, 1)
assert.Equal(t, res[0].Name, "svc-2")
res, err = fakeWatcher.FindServiceByIP("3.3.3.3")
assert.NoError(t, err)
assert.Len(t, res, 1)
assert.Equal(t, res[0].Name, "svc-2")
_, err = fakeWatcher.FindServiceByIP("4.4.4.4")
assert.Error(t, err)
}

func TestFakeK8sWatcher_AddService(t *testing.T) {
services := []interface{}{
&corev1.Service{},
Expand Down
44 changes: 0 additions & 44 deletions pkg/watcher/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,6 @@ type K8sResourceWatcher interface {

// Find a pod given the podID
FindPod(podID string) (*corev1.Pod, error)

// FindServiceByIP finds a service given the IP address.
FindServiceByIP(ip string) ([]*corev1.Service, error)

// FindPodInfoByIP finds a service given the IP address.
FindPodInfoByIP(ip string) ([]*v1alpha1.PodInfo, error)
}

// K8sWatcher maintains a local cache of k8s resources.
Expand Down Expand Up @@ -282,41 +276,3 @@ func findContainer(containerID string, pods []interface{}) (*corev1.Pod, *corev1
}
return nil, nil, false
}

func (watcher *K8sWatcher) FindServiceByIP(ip string) ([]*corev1.Service, error) {
objs, err := watcher.serviceInformer.GetIndexer().ByIndex(serviceIPsIdx, ip)
if err != nil {
return nil, fmt.Errorf("watcher returned: %w", err)
}
if len(objs) == 0 {
return nil, fmt.Errorf("service with IP %s not found", ip)
}
var services []*corev1.Service
for _, obj := range objs {
service, ok := obj.(*corev1.Service)
if !ok {
return nil, fmt.Errorf("unexpected type %t", objs[0])
}
services = append(services, service)
}
return services, nil
}

func (watcher *K8sWatcher) FindPodInfoByIP(ip string) ([]*v1alpha1.PodInfo, error) {
objs, err := watcher.podInfoInformer.GetIndexer().ByIndex(podInfoIPsIdx, ip)
if err != nil {
return nil, fmt.Errorf("pod info watcher returned: %w", err)
}
if len(objs) == 0 {
return nil, fmt.Errorf("PodInfo with IP %s not found", ip)
}
var podInfo []*v1alpha1.PodInfo
for _, obj := range objs {
service, ok := obj.(*v1alpha1.PodInfo)
if !ok {
return nil, fmt.Errorf("unexpected type %t", objs[0])
}
podInfo = append(podInfo, service)
}
return podInfo, nil
}
86 changes: 0 additions & 86 deletions pkg/watcher/watcher_test.go

This file was deleted.

0 comments on commit 0b6c8ef

Please sign in to comment.