Add Table to meta.k8s.io/v1alpha1

Table is a generic tabular output that can be returned by servers to
enable clients to display data simply.
This commit is contained in:
Clayton Coleman 2017-05-14 19:17:11 -04:00
parent 2413fe15ee
commit c299a8049c
No known key found for this signature in database
GPG Key ID: 3D16906B4F1C5CB3
9 changed files with 330 additions and 0 deletions

View File

@ -67,6 +67,7 @@ func New() *Generator {
`+k8s.io/apimachinery/pkg/runtime/schema`,
`+k8s.io/apimachinery/pkg/runtime`,
`k8s.io/apimachinery/pkg/apis/meta/v1`,
`k8s.io/apimachinery/pkg/apis/meta/v1alpha1`,
`k8s.io/apiserver/pkg/apis/example/v1`,
`k8s.io/kube-aggregator/pkg/apis/apiregistration/v1alpha1`,
`k8s.io/kubernetes/pkg/api/v1`,

View File

@ -38,6 +38,7 @@ openapi_library(
vendor_targets = [
"k8s.io/apimachinery/pkg/api/resource",
"k8s.io/apimachinery/pkg/apis/meta/v1",
"k8s.io/apimachinery/pkg/apis/meta/v1alpha1",
"k8s.io/apimachinery/pkg/runtime",
"k8s.io/apimachinery/pkg/util/intstr",
"k8s.io/apimachinery/pkg/version",

View File

@ -29,6 +29,7 @@ go_library(
tags = ["automanaged"],
deps = [
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1alpha1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/conversion:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/fields:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/labels:go_default_library",

View File

@ -18,6 +18,7 @@ package internalversion
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
metav1alpha1 "k8s.io/apimachinery/pkg/apis/meta/v1alpha1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/runtime/serializer"
@ -69,6 +70,12 @@ func addToGroupVersion(scheme *runtime.Scheme, groupVersion schema.GroupVersion)
&metav1.ExportOptions{},
&metav1.DeleteOptions{},
)
scheme.AddKnownTypes(SchemeGroupVersion,
&metav1alpha1.Table{},
)
scheme.AddKnownTypes(metav1alpha1.SchemeGroupVersion,
&metav1alpha1.Table{},
)
// Allow delete options to be decoded across all version in this scheme (we may want to be more clever than this)
scheme.AddUnversionedTypes(SchemeGroupVersion, &metav1.DeleteOptions{})
metav1.AddToGroupVersion(scheme, metav1.SchemeGroupVersion)

View File

@ -0,0 +1,27 @@
package(default_visibility = ["//visibility:public"])
licenses(["notice"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
)
go_library(
name = "go_default_library",
srcs = [
"doc.go",
"generated.pb.go",
"register.go",
"types.go",
"zz_generated.deepcopy.go",
],
tags = ["automanaged"],
deps = [
"//vendor/github.com/gogo/protobuf/proto:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/conversion:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
],
)

View File

@ -0,0 +1,22 @@
/*
Copyright 2017 The Kubernetes 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
http://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.
*/
// +k8s:deepcopy-gen=package
// +k8s:openapi-gen=true
// +k8s:defaulter-gen=TypeMeta
// +groupName=meta.k8s.io
package v1alpha1

View File

@ -0,0 +1,50 @@
/*
Copyright 2017 The Kubernetes 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
http://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.
*/
package v1alpha1
import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
)
// GroupName is the group name for this API.
const GroupName = "meta.k8s.io"
// SchemeGroupVersion is group version used to register these objects
var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1alpha1"}
// Kind takes an unqualified kind and returns a Group qualified GroupKind
func Kind(kind string) schema.GroupKind {
return SchemeGroupVersion.WithKind(kind).GroupKind()
}
// scheme is the registry for the common types that adhere to the meta v1alpha1 API spec.
var scheme = runtime.NewScheme()
// ParameterCodec knows about query parameters used with the meta v1alpha1 API spec.
var ParameterCodec = runtime.NewParameterCodec(scheme)
func init() {
scheme.AddKnownTypes(SchemeGroupVersion,
&Table{},
&TableOptions{},
&PartialObjectMetadata{},
)
// register manually. This usually goes through the SchemeBuilder, which we cannot use here.
//scheme.AddGeneratedDeepCopyFuncs(GetGeneratedDeepCopyFuncs()...)
}

View File

@ -0,0 +1,100 @@
/*
Copyright 2017 The Kubernetes 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
http://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.
*/
// package v1alpha1 is alpha objects from meta that will be introduced.
package v1alpha1
import (
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
)
// Table is a tabular representation of a set of API resources. The server transforms the
// object into a set of preferred columns for quickly reviewing the objects.
// +protobuf=false
type Table struct {
v1.TypeMeta `json:",inline"`
// Standard list metadata.
// More info: http://releases.k8s.io/HEAD/docs/devel/api-conventions.md#types-kinds
// +optional
v1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
// columnDefinitions describes each column in the returned items array. The number of cells per row
// will always match the number of column definitions.
ColumnDefinitions []TableColumnDefinitions `json:"columnDefinitions"`
// rows is the list of items in the table.
Rows []TableRow `json:"rows"`
}
// TableColumnDefinitions contains information about a column returned in the Table.
// +protobuf=false
type TableColumnDefinitions struct {
// name is a human readable name for the column.
Name string `json:"name"`
// type is an OpenAPI type definition for this column.
// See https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#data-types for more.
Type string `json:"type"`
// format is an optional OpenAPI type definition for this column.
// See https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#data-types for more.
Format string `json:"format"`
// description is a human readable description of this column.
Description string `json:"description"`
}
// TableRow is an individual row in a table.
// +protobuf=false
type TableRow struct {
// cells will be as wide as headers and may contain strings, numbers, booleans, simple maps, or lists, or
// null. See the type field of the column definition for a more detailed description.
Cells []interface{} `json:"cells"`
// This field contains the requested additional information about each object based on the includeObject
// policy when requesting the Table. If "None", this field is empty, if "Object" this will be the
// default serialization of the object for the current API version, and if "Metadata" (the default) will
// contain the object metadata. Check the returned kind and apiVersion of the object before parsing.
Object runtime.RawExtension `json:"object"`
}
// IncludeObjectPolicy controls which portion of the object is returned with a Table.
type IncludeObjectPolicy string
const (
// IncludeNone returns no object.
IncludeNone IncludeObjectPolicy = "None"
// IncludeMetadata serializes the object containing only its metadata field.
IncludeMetadata IncludeObjectPolicy = "Metadata"
// IncludeObject contains the full object.
IncludeObject IncludeObjectPolicy = "Object"
)
// TableOptions are used when a Table is requested by the caller.
type TableOptions struct {
v1.TypeMeta `json:",inline"`
// includeObject decides whether to include each object along with its columnar information.
// Specifying "None" will return no object, specifying "Object" will return the full object contents, and
// specifying "Metadata" (the default) will return the object's metadata in the PartialObjectMetadata kind
// in version v1alpha1 of the meta.k8s.io API group.
IncludeObject IncludeObjectPolicy `json:"includeObject,omitempty" protobuf:"bytes,1,opt,name=includeObject"`
}
// PartialObjectMetadata is a generic representation of any object with ObjectMeta. It allows clients
// to get access to a particular ObjectMeta schema without knowing the details of the version.
type PartialObjectMetadata struct {
v1.TypeMeta `json:",inline"`
// Standard object's metadata.
// More info: http://releases.k8s.io/HEAD/docs/devel/api-conventions.md#metadata
// +optional
v1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
}

View File

@ -0,0 +1,121 @@
// +build !ignore_autogenerated
/*
Copyright 2017 The Kubernetes 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
http://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.
*/
// This file was autogenerated by deepcopy-gen. Do not edit it manually!
package v1alpha1
import (
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
conversion "k8s.io/apimachinery/pkg/conversion"
runtime "k8s.io/apimachinery/pkg/runtime"
reflect "reflect"
)
// GetGeneratedDeepCopyFuncs returns the generated funcs, since we aren't registering them.
func GetGeneratedDeepCopyFuncs() []conversion.GeneratedDeepCopyFunc {
return []conversion.GeneratedDeepCopyFunc{
{Fn: DeepCopy_v1alpha1_PartialObjectMetadata, InType: reflect.TypeOf(&PartialObjectMetadata{})},
{Fn: DeepCopy_v1alpha1_Table, InType: reflect.TypeOf(&Table{})},
{Fn: DeepCopy_v1alpha1_TableColumnDefinitions, InType: reflect.TypeOf(&TableColumnDefinitions{})},
{Fn: DeepCopy_v1alpha1_TableOptions, InType: reflect.TypeOf(&TableOptions{})},
{Fn: DeepCopy_v1alpha1_TableRow, InType: reflect.TypeOf(&TableRow{})},
}
}
func DeepCopy_v1alpha1_PartialObjectMetadata(in interface{}, out interface{}, c *conversion.Cloner) error {
{
in := in.(*PartialObjectMetadata)
out := out.(*PartialObjectMetadata)
*out = *in
if newVal, err := c.DeepCopy(&in.ObjectMeta); err != nil {
return err
} else {
out.ObjectMeta = *newVal.(*v1.ObjectMeta)
}
return nil
}
}
func DeepCopy_v1alpha1_Table(in interface{}, out interface{}, c *conversion.Cloner) error {
{
in := in.(*Table)
out := out.(*Table)
*out = *in
if in.ColumnDefinitions != nil {
in, out := &in.ColumnDefinitions, &out.ColumnDefinitions
*out = make([]TableColumnDefinitions, len(*in))
copy(*out, *in)
}
if in.Rows != nil {
in, out := &in.Rows, &out.Rows
*out = make([]TableRow, len(*in))
for i := range *in {
if newVal, err := c.DeepCopy(&(*in)[i]); err != nil {
return err
} else {
(*out)[i] = *newVal.(*TableRow)
}
}
}
return nil
}
}
func DeepCopy_v1alpha1_TableColumnDefinitions(in interface{}, out interface{}, c *conversion.Cloner) error {
{
in := in.(*TableColumnDefinitions)
out := out.(*TableColumnDefinitions)
*out = *in
return nil
}
}
func DeepCopy_v1alpha1_TableOptions(in interface{}, out interface{}, c *conversion.Cloner) error {
{
in := in.(*TableOptions)
out := out.(*TableOptions)
*out = *in
return nil
}
}
func DeepCopy_v1alpha1_TableRow(in interface{}, out interface{}, c *conversion.Cloner) error {
{
in := in.(*TableRow)
out := out.(*TableRow)
*out = *in
if in.Cells != nil {
in, out := &in.Cells, &out.Cells
*out = make([]interface{}, len(*in))
for i := range *in {
if newVal, err := c.DeepCopy(&(*in)[i]); err != nil {
return err
} else {
(*out)[i] = *newVal.(*interface{})
}
}
}
if newVal, err := c.DeepCopy(&in.Object); err != nil {
return err
} else {
out.Object = *newVal.(*runtime.RawExtension)
}
return nil
}
}