mirror of
https://github.com/apple/container.git
synced 2026-09-23 16:15:37 +00:00
APIServer: Add support for filtering to list rpc (#1175)
This is not intended to be used to support `--filter` or similar on the CLIs list yet, it's solely to clean up our rather awkward use of `ContainerClient.list()` today in the CLI. The list RPC simply returns all of the containers we have created. Because of this, for a LOT of our commands we filter to what we need client side, which feels like a waste.. This change introduces a filter struct that we can provide an array of container IDs, labels, and the status of the containers to filter the `list()` output from. This additionally, because it was killing (pun not intended) me and I was already having to change this area for the `list()` additions, changes container kill slightly to return an error if you try and kill a container that doesn't exist.
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
// Copyright © 2026 Apple Inc. and the container project authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
import Foundation
|
||||
|
||||
/// Filters for listing containers.
|
||||
public struct ContainerListFilters: Sendable, Codable {
|
||||
/// Filter by container IDs. If non-empty, only containers with matching IDs are returned.
|
||||
public var ids: [String]
|
||||
/// Filter by container status.
|
||||
public var status: RuntimeStatus?
|
||||
/// Filter by labels. All specified labels must match.
|
||||
public var labels: [String: String]
|
||||
|
||||
/// No filters applied. Will return all containers.
|
||||
public static let all = ContainerListFilters()
|
||||
|
||||
public init(
|
||||
ids: [String] = [],
|
||||
status: RuntimeStatus? = nil,
|
||||
labels: [String: String] = [:]
|
||||
) {
|
||||
self.ids = ids
|
||||
self.status = status
|
||||
self.labels = labels
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user