Skip to content

Commit ba28e0e

Browse files
authored
Merge pull request kubernetes#77136 from smarterclayton/add_v1_table_partial
Add meta/v1 Table and PartialObjectMetadata objects
2 parents a949abc + f95f1db commit ba28e0e

File tree

10 files changed

+809
-0
lines changed

10 files changed

+809
-0
lines changed

staging/src/k8s.io/apiextensions-apiserver/pkg/generated/openapi/zz_generated.openapi.go

Lines changed: 327 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

staging/src/k8s.io/apimachinery/pkg/apis/meta/internalversion/register.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,12 @@ func addToGroupVersion(scheme *runtime.Scheme, groupVersion schema.GroupVersion)
9595
&metav1beta1.PartialObjectMetadata{},
9696
&metav1beta1.PartialObjectMetadataList{},
9797
)
98+
scheme.AddKnownTypes(metav1.SchemeGroupVersion,
99+
&metav1.Table{},
100+
&metav1.TableOptions{},
101+
&metav1.PartialObjectMetadata{},
102+
&metav1.PartialObjectMetadataList{},
103+
)
98104
// Allow delete options to be decoded across all version in this scheme (we may want to be more clever than this)
99105
scheme.AddUnversionedTypes(SchemeGroupVersion,
100106
&metav1.DeleteOptions{},

staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ go_library(
3838
srcs = [
3939
"controller_ref.go",
4040
"conversion.go",
41+
"deepcopy.go",
4142
"doc.go",
4243
"duration.go",
4344
"generated.pb.go",

staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/conversion.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ func AddConversionFuncs(scheme *runtime.Scheme) error {
7777
Convert_Slice_string_To_Slice_int32,
7878

7979
Convert_Slice_string_To_v1_DeletionPropagation,
80+
81+
Convert_Slice_string_To_v1_IncludeObjectPolicy,
8082
)
8183
}
8284

@@ -317,3 +319,11 @@ func Convert_Slice_string_To_v1_DeletionPropagation(input *[]string, out *Deleti
317319
}
318320
return nil
319321
}
322+
323+
// Convert_Slice_string_To_v1_IncludeObjectPolicy allows converting a URL query parameter value
324+
func Convert_Slice_string_To_v1_IncludeObjectPolicy(input *[]string, out *IncludeObjectPolicy, s conversion.Scope) error {
325+
if len(*input) > 0 {
326+
*out = IncludeObjectPolicy((*input)[0])
327+
}
328+
return nil
329+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
Copyright 2019 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1
18+
19+
import (
20+
"k8s.io/apimachinery/pkg/runtime"
21+
)
22+
23+
func (in *TableRow) DeepCopy() *TableRow {
24+
if in == nil {
25+
return nil
26+
}
27+
28+
out := new(TableRow)
29+
30+
if in.Cells != nil {
31+
out.Cells = make([]interface{}, len(in.Cells))
32+
for i := range in.Cells {
33+
out.Cells[i] = runtime.DeepCopyJSONValue(in.Cells[i])
34+
}
35+
}
36+
37+
if in.Conditions != nil {
38+
out.Conditions = make([]TableRowCondition, len(in.Conditions))
39+
for i := range in.Conditions {
40+
in.Conditions[i].DeepCopyInto(&out.Conditions[i])
41+
}
42+
}
43+
44+
in.Object.DeepCopyInto(&out.Object)
45+
return out
46+
}

staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/register.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,13 @@ func init() {
9494
&PatchOptions{},
9595
)
9696

97+
scheme.AddKnownTypes(SchemeGroupVersion,
98+
&Table{},
99+
&TableOptions{},
100+
&PartialObjectMetadata{},
101+
&PartialObjectMetadataList{},
102+
)
103+
97104
// register manually. This usually goes through the SchemeBuilder, which we cannot use here.
98105
utilruntime.Must(RegisterDefaults(scheme))
99106
}

staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/types.go

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,3 +1142,164 @@ type Fields struct {
11421142
// The exact format is defined in k8s.io/apiserver/pkg/endpoints/handlers/fieldmanager/internal
11431143
Map map[string]Fields `json:",inline" protobuf:"bytes,1,rep,name=map"`
11441144
}
1145+
1146+
// TODO: Table does not generate to protobuf because of the interface{} - fix protobuf
1147+
// generation to support a meta type that can accept any valid JSON. This can be introduced
1148+
// in a v1 because clients a) receive an error if they try to access proto today, and b)
1149+
// once introduced they would be able to gracefully switch over to using it.
1150+
1151+
// Table is a tabular representation of a set of API resources. The server transforms the
1152+
// object into a set of preferred columns for quickly reviewing the objects.
1153+
// +protobuf=false
1154+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
1155+
type Table struct {
1156+
TypeMeta `json:",inline"`
1157+
// Standard list metadata.
1158+
// More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds
1159+
// +optional
1160+
ListMeta `json:"metadata,omitempty"`
1161+
1162+
// columnDefinitions describes each column in the returned items array. The number of cells per row
1163+
// will always match the number of column definitions.
1164+
ColumnDefinitions []TableColumnDefinition `json:"columnDefinitions"`
1165+
// rows is the list of items in the table.
1166+
Rows []TableRow `json:"rows"`
1167+
}
1168+
1169+
// TableColumnDefinition contains information about a column returned in the Table.
1170+
// +protobuf=false
1171+
type TableColumnDefinition struct {
1172+
// name is a human readable name for the column.
1173+
Name string `json:"name"`
1174+
// type is an OpenAPI type definition for this column, such as number, integer, string, or
1175+
// array.
1176+
// See https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#data-types for more.
1177+
Type string `json:"type"`
1178+
// format is an optional OpenAPI type modifier for this column. A format modifies the type and
1179+
// imposes additional rules, like date or time formatting for a string. The 'name' format is applied
1180+
// to the primary identifier column which has type 'string' to assist in clients identifying column
1181+
// is the resource name.
1182+
// See https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#data-types for more.
1183+
Format string `json:"format"`
1184+
// description is a human readable description of this column.
1185+
Description string `json:"description"`
1186+
// priority is an integer defining the relative importance of this column compared to others. Lower
1187+
// numbers are considered higher priority. Columns that may be omitted in limited space scenarios
1188+
// should be given a higher priority.
1189+
Priority int32 `json:"priority"`
1190+
}
1191+
1192+
// TableRow is an individual row in a table.
1193+
// +protobuf=false
1194+
type TableRow struct {
1195+
// cells will be as wide as the column definitions array and may contain strings, numbers (float64 or
1196+
// int64), booleans, simple maps, lists, or null. See the type field of the column definition for a
1197+
// more detailed description.
1198+
Cells []interface{} `json:"cells"`
1199+
// conditions describe additional status of a row that are relevant for a human user. These conditions
1200+
// apply to the row, not to the object, and will be specific to table output. The only defined
1201+
// condition type is 'Completed', for a row that indicates a resource that has run to completion and
1202+
// can be given less visual priority.
1203+
// +optional
1204+
Conditions []TableRowCondition `json:"conditions,omitempty"`
1205+
// This field contains the requested additional information about each object based on the includeObject
1206+
// policy when requesting the Table. If "None", this field is empty, if "Object" this will be the
1207+
// default serialization of the object for the current API version, and if "Metadata" (the default) will
1208+
// contain the object metadata. Check the returned kind and apiVersion of the object before parsing.
1209+
// The media type of the object will always match the enclosing list - if this as a JSON table, these
1210+
// will be JSON encoded objects.
1211+
// +optional
1212+
Object runtime.RawExtension `json:"object,omitempty"`
1213+
}
1214+
1215+
// TableRowCondition allows a row to be marked with additional information.
1216+
// +protobuf=false
1217+
type TableRowCondition struct {
1218+
// Type of row condition. The only defined value is 'Completed' indicating that the
1219+
// object this row represents has reached a completed state and may be given less visual
1220+
// priority than other rows. Clients are not required to honor any conditions but should
1221+
// be consistent where possible about handling the conditions.
1222+
Type RowConditionType `json:"type"`
1223+
// Status of the condition, one of True, False, Unknown.
1224+
Status ConditionStatus `json:"status"`
1225+
// (brief) machine readable reason for the condition's last transition.
1226+
// +optional
1227+
Reason string `json:"reason,omitempty"`
1228+
// Human readable message indicating details about last transition.
1229+
// +optional
1230+
Message string `json:"message,omitempty"`
1231+
}
1232+
1233+
type RowConditionType string
1234+
1235+
// These are valid conditions of a row. This list is not exhaustive and new conditions may be
1236+
// included by other resources.
1237+
const (
1238+
// RowCompleted means the underlying resource has reached completion and may be given less
1239+
// visual priority than other resources.
1240+
RowCompleted RowConditionType = "Completed"
1241+
)
1242+
1243+
type ConditionStatus string
1244+
1245+
// These are valid condition statuses. "ConditionTrue" means a resource is in the condition.
1246+
// "ConditionFalse" means a resource is not in the condition. "ConditionUnknown" means kubernetes
1247+
// can't decide if a resource is in the condition or not. In the future, we could add other
1248+
// intermediate conditions, e.g. ConditionDegraded.
1249+
const (
1250+
ConditionTrue ConditionStatus = "True"
1251+
ConditionFalse ConditionStatus = "False"
1252+
ConditionUnknown ConditionStatus = "Unknown"
1253+
)
1254+
1255+
// IncludeObjectPolicy controls which portion of the object is returned with a Table.
1256+
type IncludeObjectPolicy string
1257+
1258+
const (
1259+
// IncludeNone returns no object.
1260+
IncludeNone IncludeObjectPolicy = "None"
1261+
// IncludeMetadata serializes the object containing only its metadata field.
1262+
IncludeMetadata IncludeObjectPolicy = "Metadata"
1263+
// IncludeObject contains the full object.
1264+
IncludeObject IncludeObjectPolicy = "Object"
1265+
)
1266+
1267+
// TableOptions are used when a Table is requested by the caller.
1268+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
1269+
type TableOptions struct {
1270+
TypeMeta `json:",inline"`
1271+
1272+
// NoHeaders is only exposed for internal callers. It is not included in our OpenAPI definitions
1273+
// and may be removed as a field in a future release.
1274+
NoHeaders bool `json:"-"`
1275+
1276+
// includeObject decides whether to include each object along with its columnar information.
1277+
// Specifying "None" will return no object, specifying "Object" will return the full object contents, and
1278+
// specifying "Metadata" (the default) will return the object's metadata in the PartialObjectMetadata kind
1279+
// in version v1beta1 of the meta.k8s.io API group.
1280+
IncludeObject IncludeObjectPolicy `json:"includeObject,omitempty" protobuf:"bytes,1,opt,name=includeObject,casttype=IncludeObjectPolicy"`
1281+
}
1282+
1283+
// PartialObjectMetadata is a generic representation of any object with ObjectMeta. It allows clients
1284+
// to get access to a particular ObjectMeta schema without knowing the details of the version.
1285+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
1286+
type PartialObjectMetadata struct {
1287+
TypeMeta `json:",inline"`
1288+
// Standard object's metadata.
1289+
// More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata
1290+
// +optional
1291+
ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
1292+
}
1293+
1294+
// PartialObjectMetadataList contains a list of objects containing only their metadata
1295+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
1296+
type PartialObjectMetadataList struct {
1297+
TypeMeta `json:",inline"`
1298+
// Standard list metadata.
1299+
// More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds
1300+
// +optional
1301+
ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
1302+
1303+
// items contains each of the included items.
1304+
Items []*PartialObjectMetadata `json:"items" protobuf:"bytes,2,rep,name=items"`
1305+
}

staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/types_swagger_doc_generated.go

Lines changed: 75 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/validation/validation.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,3 +158,14 @@ func ValidateDryRun(fldPath *field.Path, dryRun []string) field.ErrorList {
158158
}
159159

160160
const UninitializedStatusUpdateErrorMsg string = `must not update status when the object is uninitialized`
161+
162+
// ValidateTableOptions returns any invalid flags on TableOptions.
163+
func ValidateTableOptions(opts *metav1.TableOptions) field.ErrorList {
164+
var allErrs field.ErrorList
165+
switch opts.IncludeObject {
166+
case metav1.IncludeMetadata, metav1.IncludeNone, metav1.IncludeObject, "":
167+
default:
168+
allErrs = append(allErrs, field.Invalid(field.NewPath("includeObject"), opts.IncludeObject, "must be 'Metadata', 'Object', 'None', or empty"))
169+
}
170+
return allErrs
171+
}

0 commit comments

Comments
 (0)