Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Remove unused PodInfo utility functions #2144

Merged
merged 1 commit into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
18 changes: 0 additions & 18 deletions pkg/watcher/fake.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,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 +39,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 +58,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)
}
29 changes: 0 additions & 29 deletions pkg/watcher/fake_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,8 @@ import (

"github.com/stretchr/testify/assert"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

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.

Loading