Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introducing a cluster-scoped resource in the wardle.k8s.io group. #48444

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func Install(groupFactoryRegistry announced.APIGroupFactoryRegistry, registry *r
if err := announced.NewGroupMetaFactory(
&announced.GroupMetaFactoryArgs{
GroupName: wardle.GroupName,
RootScopedKinds: sets.NewString("APIService"),
RootScopedKinds: sets.NewString("Fischer", "FischerList"),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like APIService was unnecessary.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like APIService was unnecessary.

Yeah, bad copy/paste

VersionPreferenceOrder: []string{v1alpha1.SchemeGroupVersion.Version},
ImportPrefix: "k8s.io/sample-apiserver/pkg/apis/wardle",
AddInternalObjectsToScheme: wardle.AddToScheme,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ func addKnownTypes(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(SchemeGroupVersion,
&Flunder{},
&FlunderList{},
&Fischer{},
&FischerList{},
)
return nil
}
23 changes: 23 additions & 0 deletions staging/src/k8s.io/sample-apiserver/pkg/apis/wardle/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,26 @@ type Flunder struct {
Spec FlunderSpec
Status FlunderStatus
}

// +genclient=true
// +nonNamespaced=true

type Fischer struct {
metav1.TypeMeta
metav1.ObjectMeta

// DisallowedFlunders holds a list of Flunder.Names that are disallowed.
DisallowedFlunders []string
}

// +genclient=true
// +nonNamespaced=true

// FischerList is a list of Fischer objects.
type FischerList struct {
metav1.TypeMeta
metav1.ListMeta

// Items is a list of Fischers
Items []Fischer
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ func addKnownTypes(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(SchemeGroupVersion,
&Flunder{},
&FlunderList{},
&Fischer{},
&FischerList{},
)
metav1.AddToGroupVersion(scheme, SchemeGroupVersion)
return nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,25 @@ type Flunder struct {
Spec FlunderSpec `json:"spec,omitempty" protobuf:"bytes,2,opt,name=spec"`
Status FlunderStatus `json:"status,omitempty" protobuf:"bytes,3,opt,name=status"`
}

// +genclient=true
// +nonNamespaced=true

type Fischer struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`

// DisallowedFlunders holds a list of Flunder.Names that are disallowed.
DisallowedFlunders []string `json:"disallowedFlunders,omitempty" protobuf:"bytes,2,rep,name=disallowedFlunders"`
}

// +genclient=true
// +nonNamespaced=true

// FischerList is a list of Fischer objects.
type FischerList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`

Items []Fischer `json:"items" protobuf:"bytes,2,rep,name=items"`
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ func init() {
// Public to allow building arbitrary schemes.
func RegisterConversions(scheme *runtime.Scheme) error {
return scheme.AddGeneratedConversionFuncs(
Convert_v1alpha1_Fischer_To_wardle_Fischer,
Convert_wardle_Fischer_To_v1alpha1_Fischer,
Convert_v1alpha1_FischerList_To_wardle_FischerList,
Convert_wardle_FischerList_To_v1alpha1_FischerList,
Convert_v1alpha1_Flunder_To_wardle_Flunder,
Convert_wardle_Flunder_To_v1alpha1_Flunder,
Convert_v1alpha1_FlunderList_To_wardle_FlunderList,
Expand All @@ -46,6 +50,54 @@ func RegisterConversions(scheme *runtime.Scheme) error {
)
}

func autoConvert_v1alpha1_Fischer_To_wardle_Fischer(in *Fischer, out *wardle.Fischer, s conversion.Scope) error {
out.ObjectMeta = in.ObjectMeta
out.DisallowedFlunders = *(*[]string)(unsafe.Pointer(&in.DisallowedFlunders))
return nil
}

// Convert_v1alpha1_Fischer_To_wardle_Fischer is an autogenerated conversion function.
func Convert_v1alpha1_Fischer_To_wardle_Fischer(in *Fischer, out *wardle.Fischer, s conversion.Scope) error {
return autoConvert_v1alpha1_Fischer_To_wardle_Fischer(in, out, s)
}

func autoConvert_wardle_Fischer_To_v1alpha1_Fischer(in *wardle.Fischer, out *Fischer, s conversion.Scope) error {
out.ObjectMeta = in.ObjectMeta
out.DisallowedFlunders = *(*[]string)(unsafe.Pointer(&in.DisallowedFlunders))
return nil
}

// Convert_wardle_Fischer_To_v1alpha1_Fischer is an autogenerated conversion function.
func Convert_wardle_Fischer_To_v1alpha1_Fischer(in *wardle.Fischer, out *Fischer, s conversion.Scope) error {
return autoConvert_wardle_Fischer_To_v1alpha1_Fischer(in, out, s)
}

func autoConvert_v1alpha1_FischerList_To_wardle_FischerList(in *FischerList, out *wardle.FischerList, s conversion.Scope) error {
out.ListMeta = in.ListMeta
out.Items = *(*[]wardle.Fischer)(unsafe.Pointer(&in.Items))
return nil
}

// Convert_v1alpha1_FischerList_To_wardle_FischerList is an autogenerated conversion function.
func Convert_v1alpha1_FischerList_To_wardle_FischerList(in *FischerList, out *wardle.FischerList, s conversion.Scope) error {
return autoConvert_v1alpha1_FischerList_To_wardle_FischerList(in, out, s)
}

func autoConvert_wardle_FischerList_To_v1alpha1_FischerList(in *wardle.FischerList, out *FischerList, s conversion.Scope) error {
out.ListMeta = in.ListMeta
if in.Items == nil {
out.Items = make([]Fischer, 0)
} else {
out.Items = *(*[]Fischer)(unsafe.Pointer(&in.Items))
}
return nil
}

// Convert_wardle_FischerList_To_v1alpha1_FischerList is an autogenerated conversion function.
func Convert_wardle_FischerList_To_v1alpha1_FischerList(in *wardle.FischerList, out *FischerList, s conversion.Scope) error {
return autoConvert_wardle_FischerList_To_v1alpha1_FischerList(in, out, s)
}

func autoConvert_v1alpha1_Flunder_To_wardle_Flunder(in *Flunder, out *wardle.Flunder, s conversion.Scope) error {
out.ObjectMeta = in.ObjectMeta
if err := Convert_v1alpha1_FlunderSpec_To_wardle_FlunderSpec(&in.Spec, &out.Spec, s); err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,56 @@ func init() {
// to allow building arbitrary schemes.
func RegisterDeepCopies(scheme *runtime.Scheme) error {
return scheme.AddGeneratedDeepCopyFuncs(
conversion.GeneratedDeepCopyFunc{Fn: DeepCopy_v1alpha1_Fischer, InType: reflect.TypeOf(&Fischer{})},
conversion.GeneratedDeepCopyFunc{Fn: DeepCopy_v1alpha1_FischerList, InType: reflect.TypeOf(&FischerList{})},
conversion.GeneratedDeepCopyFunc{Fn: DeepCopy_v1alpha1_Flunder, InType: reflect.TypeOf(&Flunder{})},
conversion.GeneratedDeepCopyFunc{Fn: DeepCopy_v1alpha1_FlunderList, InType: reflect.TypeOf(&FlunderList{})},
conversion.GeneratedDeepCopyFunc{Fn: DeepCopy_v1alpha1_FlunderSpec, InType: reflect.TypeOf(&FlunderSpec{})},
conversion.GeneratedDeepCopyFunc{Fn: DeepCopy_v1alpha1_FlunderStatus, InType: reflect.TypeOf(&FlunderStatus{})},
)
}

// DeepCopy_v1alpha1_Fischer is an autogenerated deepcopy function.
func DeepCopy_v1alpha1_Fischer(in interface{}, out interface{}, c *conversion.Cloner) error {
{
in := in.(*Fischer)
out := out.(*Fischer)
*out = *in
if newVal, err := c.DeepCopy(&in.ObjectMeta); err != nil {
return err
} else {
out.ObjectMeta = *newVal.(*v1.ObjectMeta)
}
if in.DisallowedFlunders != nil {
in, out := &in.DisallowedFlunders, &out.DisallowedFlunders
*out = make([]string, len(*in))
copy(*out, *in)
}
return nil
}
}

// DeepCopy_v1alpha1_FischerList is an autogenerated deepcopy function.
func DeepCopy_v1alpha1_FischerList(in interface{}, out interface{}, c *conversion.Cloner) error {
{
in := in.(*FischerList)
out := out.(*FischerList)
*out = *in
if in.Items != nil {
in, out := &in.Items, &out.Items
*out = make([]Fischer, len(*in))
for i := range *in {
if newVal, err := c.DeepCopy(&(*in)[i]); err != nil {
return err
} else {
(*out)[i] = *newVal.(*Fischer)
}
}
}
return nil
}
}

// DeepCopy_v1alpha1_Flunder is an autogenerated deepcopy function.
func DeepCopy_v1alpha1_Flunder(in interface{}, out interface{}, c *conversion.Cloner) error {
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,56 @@ func init() {
// to allow building arbitrary schemes.
func RegisterDeepCopies(scheme *runtime.Scheme) error {
return scheme.AddGeneratedDeepCopyFuncs(
conversion.GeneratedDeepCopyFunc{Fn: DeepCopy_wardle_Fischer, InType: reflect.TypeOf(&Fischer{})},
conversion.GeneratedDeepCopyFunc{Fn: DeepCopy_wardle_FischerList, InType: reflect.TypeOf(&FischerList{})},
conversion.GeneratedDeepCopyFunc{Fn: DeepCopy_wardle_Flunder, InType: reflect.TypeOf(&Flunder{})},
conversion.GeneratedDeepCopyFunc{Fn: DeepCopy_wardle_FlunderList, InType: reflect.TypeOf(&FlunderList{})},
conversion.GeneratedDeepCopyFunc{Fn: DeepCopy_wardle_FlunderSpec, InType: reflect.TypeOf(&FlunderSpec{})},
conversion.GeneratedDeepCopyFunc{Fn: DeepCopy_wardle_FlunderStatus, InType: reflect.TypeOf(&FlunderStatus{})},
)
}

// DeepCopy_wardle_Fischer is an autogenerated deepcopy function.
func DeepCopy_wardle_Fischer(in interface{}, out interface{}, c *conversion.Cloner) error {
{
in := in.(*Fischer)
out := out.(*Fischer)
*out = *in
if newVal, err := c.DeepCopy(&in.ObjectMeta); err != nil {
return err
} else {
out.ObjectMeta = *newVal.(*v1.ObjectMeta)
}
if in.DisallowedFlunders != nil {
in, out := &in.DisallowedFlunders, &out.DisallowedFlunders
*out = make([]string, len(*in))
copy(*out, *in)
}
return nil
}
}

// DeepCopy_wardle_FischerList is an autogenerated deepcopy function.
func DeepCopy_wardle_FischerList(in interface{}, out interface{}, c *conversion.Cloner) error {
{
in := in.(*FischerList)
out := out.(*FischerList)
*out = *in
if in.Items != nil {
in, out := &in.Items, &out.Items
*out = make([]Fischer, len(*in))
for i := range *in {
if newVal, err := c.DeepCopy(&(*in)[i]); err != nil {
return err
} else {
(*out)[i] = *newVal.(*Fischer)
}
}
}
return nil
}
}

// DeepCopy_wardle_Flunder is an autogenerated deepcopy function.
func DeepCopy_wardle_Flunder(in interface{}, out interface{}, c *conversion.Cloner) error {
{
Expand Down
3 changes: 2 additions & 1 deletion staging/src/k8s.io/sample-apiserver/pkg/apiserver/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ go_library(
"//vendor/k8s.io/sample-apiserver/pkg/apis/wardle:go_default_library",
"//vendor/k8s.io/sample-apiserver/pkg/apis/wardle/install:go_default_library",
"//vendor/k8s.io/sample-apiserver/pkg/apis/wardle/v1alpha1:go_default_library",
"//vendor/k8s.io/sample-apiserver/pkg/registry/wardle:go_default_library",
"//vendor/k8s.io/sample-apiserver/pkg/registry/wardle/fischer:go_default_library",
"//vendor/k8s.io/sample-apiserver/pkg/registry/wardle/flunder:go_default_library",
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ import (
"k8s.io/sample-apiserver/pkg/apis/wardle"
"k8s.io/sample-apiserver/pkg/apis/wardle/install"
"k8s.io/sample-apiserver/pkg/apis/wardle/v1alpha1"
wardlestorage "k8s.io/sample-apiserver/pkg/registry/wardle"
fischerstorage "k8s.io/sample-apiserver/pkg/registry/wardle/fischer"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I broke up wardle pkg into two(per resource).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I broke up wardle pkg into two(per resource).

good call.

flunderstorage "k8s.io/sample-apiserver/pkg/registry/wardle/flunder"
)

var (
Expand Down Expand Up @@ -102,7 +103,8 @@ func (c completedConfig) New() (*WardleServer, error) {
apiGroupInfo := genericapiserver.NewDefaultAPIGroupInfo(wardle.GroupName, registry, Scheme, metav1.ParameterCodec, Codecs)
apiGroupInfo.GroupMeta.GroupVersion = v1alpha1.SchemeGroupVersion
v1alpha1storage := map[string]rest.Storage{}
v1alpha1storage["flunders"] = wardlestorage.NewREST(Scheme, c.GenericConfig.RESTOptionsGetter)
v1alpha1storage["flunders"] = flunderstorage.RESTInPeace(Scheme, c.GenericConfig.RESTOptionsGetter)
v1alpha1storage["fischers"] = fischerstorage.RESTInPeace(Scheme, c.GenericConfig.RESTOptionsGetter)
apiGroupInfo.VersionedResourcesStorageMap["v1alpha1"] = v1alpha1storage

if err := s.GenericAPIServer.InstallAPIGroup(&apiGroupInfo); err != nil {
Expand Down
15 changes: 15 additions & 0 deletions staging/src/k8s.io/sample-apiserver/pkg/registry/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package(default_visibility = ["//visibility:public"])

licenses(["notice"])

load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
)

go_library(
name = "go_default_library",
srcs = ["registry.go"],
tags = ["automanaged"],
deps = ["//vendor/k8s.io/apiserver/pkg/registry/generic/registry:go_default_library"],
)
24 changes: 24 additions & 0 deletions staging/src/k8s.io/sample-apiserver/pkg/registry/registry.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
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 registry

import genericregistry "k8s.io/apiserver/pkg/registry/generic/registry"

// rest implements a RESTStorage for API services against etcd
type REST struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the spot I expected RESTInPeace(rest.StandardStorage, error) rest.StandardStorage to be here. Then each individual registry still has a NewREST(scheme *runtime.Scheme, optsGetter generic.RESTOptionsGetter) *registry.REST) which can be wrapped.

*genericregistry.Store
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ go_library(
"//vendor/k8s.io/apiserver/pkg/storage:go_default_library",
"//vendor/k8s.io/apiserver/pkg/storage/names:go_default_library",
"//vendor/k8s.io/sample-apiserver/pkg/apis/wardle:go_default_library",
"//vendor/k8s.io/sample-apiserver/pkg/registry:go_default_library",
],
)
Original file line number Diff line number Diff line change
@@ -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 fischer

import (
"fmt"

"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apiserver/pkg/registry/generic"
genericregistry "k8s.io/apiserver/pkg/registry/generic/registry"
"k8s.io/sample-apiserver/pkg/apis/wardle"
"k8s.io/sample-apiserver/pkg/registry"
)

// RESTInPeace returns a RESTStorage object that will work against API services.
func RESTInPeace(scheme *runtime.Scheme, optsGetter generic.RESTOptionsGetter) *registry.REST {
strategy := NewStrategy(scheme)

store := &genericregistry.Store{
Copier: scheme,
NewFunc: func() runtime.Object { return &wardle.Fischer{} },
NewListFunc: func() runtime.Object { return &wardle.FischerList{} },
PredicateFunc: MatchFischer,
QualifiedResource: wardle.Resource("fischers"),

CreateStrategy: strategy,
UpdateStrategy: strategy,
DeleteStrategy: strategy,
}
options := &generic.StoreOptions{RESTOptions: optsGetter, AttrFunc: GetAttrs}
if err := store.CompleteWithOptions(options); err != nil {
err = fmt.Errorf("Unable to create REST storage for fischer resource due to %v. Committing suicide.", err)
panic(err)
}
return &registry.REST{store}
}