Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

feat: enables container filter to be configured at multiple places #3455

Merged
merged 8 commits into from
Dec 14, 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
13 changes: 11 additions & 2 deletions internal/agent/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,17 @@ func (c *Client) FindContainer(ctx context.Context, containerID string) (docker.
}, nil
}

func (c *Client) ListContainers(ctx context.Context) ([]docker.Container, error) {
response, err := c.client.ListContainers(ctx, &pb.ListContainersRequest{})
func (c *Client) ListContainers(ctx context.Context, filter docker.ContainerFilter) ([]docker.Container, error) {
in := &pb.ListContainersRequest{}

if filter != nil {
in.Filter = make(map[string]*pb.RepeatedString)
for k, v := range filter {
in.Filter[k] = &pb.RepeatedString{Values: v}
}
}

response, err := c.client.ListContainers(ctx, in)
if err != nil {
return nil, err
}
Expand Down
10 changes: 5 additions & 5 deletions internal/agent/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ func (m *MockedClient) ContainerEvents(ctx context.Context, events chan<- docker
return args.Error(0)
}

func (m *MockedClient) ListContainers(ctx context.Context) ([]docker.Container, error) {
args := m.Called(ctx)
func (m *MockedClient) ListContainers(ctx context.Context, filter docker.ContainerFilter) ([]docker.Container, error) {
args := m.Called(ctx, filter)
return args.Get(0).([]docker.Container), args.Error(1)
}

Expand Down Expand Up @@ -92,7 +92,7 @@ func init() {
}

client = &MockedClient{}
client.On("ListContainers", mock.Anything).Return([]docker.Container{
client.On("ListContainers", mock.Anything, mock.Anything).Return([]docker.Container{
{
ID: "123456",
Name: "test",
Expand Down Expand Up @@ -127,7 +127,7 @@ func init() {
Stats: utils.NewRingBuffer[docker.ContainerStat](300),
}, nil)

server, _ := NewServer(client, certs, "test")
server, _ := NewServer(client, certs, "test", docker.ContainerFilter{})

go server.Serve(lis)
}
Expand Down Expand Up @@ -167,7 +167,7 @@ func TestListContainers(t *testing.T) {
t.Fatal(err)
}

containers, _ := rpc.ListContainers(context.Background())
containers, _ := rpc.ListContainers(context.Background(), docker.ContainerFilter{})

assert.Equal(t, containers, []docker.Container{
{
Expand Down
Loading
Loading