From 31cbbf546c110017326abc04304ecf35a7918033 Mon Sep 17 00:00:00 2001 From: yue9944882 <291271447@qq.com> Date: Tue, 27 Aug 2019 19:12:16 +0800 Subject: [PATCH 1/3] remove {book,pencil} from student subresource as examples --- .../pkg/apis/miskatonic/book_student_rest.go | 88 ------------------- .../apis/miskatonic/pencil_student_rest.go | 69 --------------- .../apis/miskatonic/v1beta1/student_types.go | 2 - 3 files changed, 159 deletions(-) delete mode 100644 example/basic/pkg/apis/miskatonic/book_student_rest.go delete mode 100644 example/basic/pkg/apis/miskatonic/pencil_student_rest.go diff --git a/example/basic/pkg/apis/miskatonic/book_student_rest.go b/example/basic/pkg/apis/miskatonic/book_student_rest.go deleted file mode 100644 index 29c3d1efce..0000000000 --- a/example/basic/pkg/apis/miskatonic/book_student_rest.go +++ /dev/null @@ -1,88 +0,0 @@ -/* -Copyright YEAR 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 miskatonic - -import ( - "context" - "sigs.k8s.io/apiserver-builder-alpha/pkg/builders" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apiserver/pkg/registry/generic" - "k8s.io/apiserver/pkg/registry/rest" -) - -// LogREST implements GetterWithOptions -var _ = rest.GetterWithOptions(&StudentBookREST{}) - -// +k8s:deepcopy-gen=false -type StudentBookREST struct { - StreamingHandler func(book *StudentBook) (streamer runtime.Object) -} - -// New creates a new Pod log options object -func (r *StudentBookREST) New() runtime.Object { - // TODO - return a resource that represents a log - return &StudentBook{} -} - -// LogREST implements StorageMetadata -func (r *StudentBookREST) ProducesMIMETypes(verb string) []string { - // Since the default list does not include "plain/text", we need to - // explicitly override ProducesMIMETypes, so that it gets added to - // the "produces" section for pods/{name}/log - return []string{ - "text/plain", - } -} - -// LogREST implements StorageMetadata, return string as the generating object -func (r *StudentBookREST) ProducesObject(verb string) interface{} { - return "" -} - -func (r *StudentBookREST) Get(ctx context.Context, name string, opts runtime.Object) (runtime.Object, error) { - return r.StreamingHandler(opts.(*StudentBook)), nil -} - -// NewGetOptions creates a new options object -func (r *StudentBookREST) NewGetOptions() (runtime.Object, bool, string) { - return &StudentBook{}, false, "" -} - -// OverrideMetricsVerb override the GET verb to CONNECT for pod log resource -func (r *StudentBookREST) OverrideMetricsVerb(oldVerb string) (newVerb string) { - newVerb = oldVerb - - if oldVerb == "GET" { - newVerb = "CONNECT" - } - - return -} - -// Custom REST storage that delegates to the generated standard Registry -func NewStudentBookREST(getter generic.RESTOptionsGetter) rest.Storage { - builders.ParameterScheme.AddKnownTypes(SchemeGroupVersion, &StudentBook{}) - return &StudentBookREST{ - StreamingHandler: func(book *StudentBook) runtime.Object { - return &Student{ - Spec: StudentSpec{ - ID: 3, - }, - } - }, - } -} diff --git a/example/basic/pkg/apis/miskatonic/pencil_student_rest.go b/example/basic/pkg/apis/miskatonic/pencil_student_rest.go deleted file mode 100644 index ee3aa97d34..0000000000 --- a/example/basic/pkg/apis/miskatonic/pencil_student_rest.go +++ /dev/null @@ -1,69 +0,0 @@ -/* -Copyright YEAR 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 miskatonic - -import ( - "context" - "fmt" - "net/http" - - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apiserver/pkg/registry/generic" - "k8s.io/apiserver/pkg/registry/rest" -) - -var _ rest.Connecter = &StudentPencilREST{} - -// +k8s:deepcopy-gen=false -type StudentPencilREST struct { - HTTPHandlerGetter func(pencil *StudentPencil) http.Handler -} - -// New creates a new podAttachOptions object. -func (r *StudentPencilREST) New() runtime.Object { - return &StudentPencil{} -} - -// Connect returns a handler for the pod exec proxy -func (r *StudentPencilREST) Connect(ctx context.Context, name string, opts runtime.Object, responder rest.Responder) (http.Handler, error) { - pencil, ok := opts.(*StudentPencil) - if !ok { - return nil, fmt.Errorf("Invalid options object: %#v", opts) - } - return r.HTTPHandlerGetter(pencil), nil -} - -// NewConnectOptions returns the versioned object that represents exec parameters -func (r *StudentPencilREST) NewConnectOptions() (runtime.Object, bool, string) { - return &StudentPencil{}, false, "" -} - -// ConnectMethods returns the methods supported by exec -func (r *StudentPencilREST) ConnectMethods() []string { - return []string{"GET", "POST"} -} - -// Custom REST storage that delegates to the generated standard Registry -func NewStudentPencilREST(getter generic.RESTOptionsGetter) rest.Storage { - return &StudentPencilREST{ - HTTPHandlerGetter: func(pencil *StudentPencil) http.Handler { - return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - w.Write([]byte(`all is well`)) - }) - }, - } -} diff --git a/example/basic/pkg/apis/miskatonic/v1beta1/student_types.go b/example/basic/pkg/apis/miskatonic/v1beta1/student_types.go index 2ea36f9a35..7f030d8ab5 100644 --- a/example/basic/pkg/apis/miskatonic/v1beta1/student_types.go +++ b/example/basic/pkg/apis/miskatonic/v1beta1/student_types.go @@ -29,8 +29,6 @@ import ( // +k8s:openapi-gen=true // +resource:path=students,rest=StudentREST // +subresource:request=StudentComputer,path=computer,kind=StudentComputer,rest=StudentComputerREST -// +subresource:request=StudentBook,path=book,kind=StudentBook,rest=StudentBookREST -// +subresource:request=StudentPencil,path=pencil,kind=StudentPencil,rest=StudentPencilREST type Student struct { metav1.TypeMeta `json:",inline"` metav1.ObjectMeta `json:"metadata,omitempty"` From 15611c942c1334c0f42d7c5788363de41a3348be Mon Sep 17 00:00:00 2001 From: yue9944882 <291271447@qq.com> Date: Tue, 27 Aug 2019 19:20:53 +0800 Subject: [PATCH 2/3] add examples to README headlines --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index 485e7a7df0..3456a6b122 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,13 @@ same capabilities when building from scratch. - Easily add new resources and subresources - Provides sane defaults for most values, but can be overridden +## Examples + +- [BasicExample](https://sigs.k8s.io/apiserver-builder-alpha/example/basic): Various simple resource examples. +- [KineExample](https://sigs.k8s.io/apiserver-builder-alpha/example/kine): Plumbs aggregated apiserver over SQL-storages including sqlite, mysql, etc.. +- [PodLogsExample](https://sigs.k8s.io/apiserver-builder-alpha/example/podlogs): Serves `pod/logs` in aggregation layer to offload kube-apiserver connections. +- [PodExecExample](https://sigs.k8s.io/apiserver-builder-alpha/example/podexec): Serves `pod/exec` in aggregation layer to offload kube-apiserver connections. + ## Guides **Note:** The guides are presented roughly in the order of recommended progression. From 348d44d4ec22ee0c501539dfaca6bd7829566b2f Mon Sep 17 00:00:00 2001 From: yue9944882 <291271447@qq.com> Date: Tue, 27 Aug 2019 20:10:42 +0800 Subject: [PATCH 3/3] completely remove student subresources --- .../miskatonic/v1beta1/book_student_types.go | 31 ----------------- .../v1beta1/pencil_student_types.go | 33 ------------------- 2 files changed, 64 deletions(-) delete mode 100644 example/basic/pkg/apis/miskatonic/v1beta1/book_student_types.go delete mode 100644 example/basic/pkg/apis/miskatonic/v1beta1/pencil_student_types.go diff --git a/example/basic/pkg/apis/miskatonic/v1beta1/book_student_types.go b/example/basic/pkg/apis/miskatonic/v1beta1/book_student_types.go deleted file mode 100644 index ef2c6abeef..0000000000 --- a/example/basic/pkg/apis/miskatonic/v1beta1/book_student_types.go +++ /dev/null @@ -1,31 +0,0 @@ -/* -Copyright YEAR 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 v1beta1 - -import ( - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" -) - -// +genclient -// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object - -// +subresource-request -type StudentBook struct { - metav1.TypeMeta `json:",inline"` - metav1.ObjectMeta `json:"metadata,omitempty"` - Price int `json:"price"` -} diff --git a/example/basic/pkg/apis/miskatonic/v1beta1/pencil_student_types.go b/example/basic/pkg/apis/miskatonic/v1beta1/pencil_student_types.go deleted file mode 100644 index cd5639f9ae..0000000000 --- a/example/basic/pkg/apis/miskatonic/v1beta1/pencil_student_types.go +++ /dev/null @@ -1,33 +0,0 @@ - -/* -Copyright YEAR 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 v1beta1 - -import ( - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" -) - -// +genclient -// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object - -// +subresource-request -type StudentPencil struct { - metav1.TypeMeta `json:",inline"` - metav1.ObjectMeta `json:"metadata,omitempty"` -}