Skip to content

Commit

Permalink
Merge pull request #99 from sttts/sttts-query-api-table
Browse files Browse the repository at this point in the history
WIP: apis/query: add table row responses
  • Loading branch information
phisco authored Jul 19, 2024
2 parents 53875fc + fdefa8d commit 79c0820
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 0 deletions.
26 changes: 26 additions & 0 deletions apis/query/v1alpha1/query_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,9 @@ type QueryObjects struct {
// +kubebuilder:pruning:PreserveUnknownFields
Object *common.JSON `json:"object,omitempty"`

// table specifies whether to return the object in a table format.
Table *QueryTable `json:"table,omitempty"`

// relations specifies which relations to query and what to return.
// Relation names are predefined strings relative to the release of
// Spaces.
Expand All @@ -247,6 +250,29 @@ type QueryObjects struct {
Relations map[string]QueryRelation `json:"relations,omitempty"`
}

// QueryGrouping specifies how to group the returned objects into multiple
// tables.
type QueryGrouping string

const (
// ByGVKsAndColumns specifies to group by GVKs and column definitions. I.e.
// rows of different GVKs or with different column definitions are grouped
// into different tables.
ByGVKsAndColumns QueryGrouping = "ByGVKsAndColumn"
)

// QueryTable specifies how to return objects in a table or multiple tables
// (in case of grouping).
type QueryTable struct {
// grouping specifies how to group the returned objects into multiple
// tables where every table can have different sets of columns.
Grouping QueryGrouping `json:"grouping,omitempty"`

// noHeaders specifies whether to return the headers of the table in the
// first row.
NoHeaders bool `json:"noHeaders,omitempty"`
}

// A QueryRelation specifies how to return objects in a relation.
type QueryRelation struct {
QueryNestedResources `json:",inline"`
Expand Down
18 changes: 18 additions & 0 deletions apis/query/v1alpha1/queryresponse_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,16 @@ type QueryResponseObjects struct {
Cursor *QueryResponseCursor `json:"cursor,omitempty"`

// objects is the list of objects returned by the query.
//
// Objects is mutual exclusive with Tables.
Objects []QueryResponseObject `json:"objects,omitempty"`

// tables is the list of tables returned by the query. Objects are grouped
// as specified in the query. Hence, potentially multiple tables are returned.
//
// Objects is mutual exclusive with Tables.
Tables []QueryResponseTable `json:"tables,omitempty"`

// count is the total number of objects that match the query.
Count *int `json:"count,omitempty"`

Expand All @@ -48,6 +56,16 @@ type QueryResponseObjects struct {
Incomplete bool `json:"incomplete,omitempty"`
}

// QueryResponseTable is a table representation of a set of API resources.
type QueryResponseTable struct {
// groupVersionKind is the group, version, and kind of the objects in the table.
GroupVersionKind metav1.GroupVersionKind `json:"groupVersionKind"`
// columns is the list of columns in the table.
Columns []metav1.TableColumnDefinition `json:"columns"`
// rows is the list of rows in the table.
Rows []metav1.TableRow `json:"rows"`
}

// QueryResponseCursor is the cursor to the next page of results.
type QueryResponseCursor struct {
// cursor is the cursor to the next page of results. If empty, there are no more,
Expand Down
56 changes: 56 additions & 0 deletions apis/query/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 79c0820

Please sign in to comment.