From b5a883c6bbc813030ae31c2f480c36654019d7bd Mon Sep 17 00:00:00 2001 From: Karol Szwaj Date: Fri, 28 Mar 2025 16:48:23 +0100 Subject: [PATCH 1/8] introduce v1alpha2 crd with apiresourceschema Signed-off-by: Karol Szwaj On-behalf-of: @SAP karol.szwaj@sap.com --- .../crd/kube-bind.io_apiresourceschemas.yaml | 50 ++++ .../v1alpha2/apiresourceschema_types.go | 50 ++++ sdk/apis/kubebind/v1alpha2/doc.go | 23 ++ sdk/apis/kubebind/v1alpha2/register.go | 54 +++++ .../v1alpha2/zz_generated.deepcopy.go | 119 ++++++++++ sdk/client/clientset/versioned/clientset.go | 13 ++ .../versioned/fake/clientset_generated.go | 7 + .../clientset/versioned/fake/register.go | 2 + .../clientset/versioned/scheme/register.go | 2 + .../kubebind/v1alpha2/apiresourceschema.go | 70 ++++++ .../versioned/typed/kubebind/v1alpha2/doc.go | 20 ++ .../typed/kubebind/v1alpha2/fake/doc.go | 20 ++ .../v1alpha2/fake/fake_apiresourceschema.go | 148 ++++++++++++ .../v1alpha2/fake/fake_kubebind_client.go | 41 ++++ .../kubebind/v1alpha2/generated_expansion.go | 21 ++ .../kubebind/v1alpha2/kubebind_client.go | 108 +++++++++ .../informers/externalversions/generic.go | 5 + .../externalversions/kubebind/interface.go | 8 + .../kubebind/v1alpha2/apiresourceschema.go | 91 ++++++++ .../kubebind/v1alpha2/interface.go | 45 ++++ .../kubebind/v1alpha2/apiresourceschema.go | 71 ++++++ .../kubebind/v1alpha2/expansion_generated.go | 27 +++ .../clientset/versioned/cluster/clientset.go | 12 + .../versioned/cluster/fake/clientset.go | 13 ++ .../versioned/cluster/scheme/register.go | 2 + .../kubebind/v1alpha2/apiresourceschema.go | 86 +++++++ .../v1alpha2/fake/apiresourceschema.go | 213 ++++++++++++++++++ .../kubebind/v1alpha2/fake/kubebind_client.go | 65 ++++++ .../kubebind/v1alpha2/kubebind_client.go | 90 ++++++++ sdk/kcp/informers/externalversions/generic.go | 8 + .../externalversions/kubebind/interface.go | 15 ++ .../kubebind/v1alpha2/apiresourceschema.go | 182 +++++++++++++++ .../kubebind/v1alpha2/interface.go | 67 ++++++ .../kubebind/v1alpha2/apiresourceschema.go | 196 ++++++++++++++++ .../v1alpha2/apiresourceschema_expansion.go | 31 +++ 35 files changed, 1975 insertions(+) create mode 100644 deploy/crd/kube-bind.io_apiresourceschemas.yaml create mode 100644 sdk/apis/kubebind/v1alpha2/apiresourceschema_types.go create mode 100644 sdk/apis/kubebind/v1alpha2/doc.go create mode 100644 sdk/apis/kubebind/v1alpha2/register.go create mode 100644 sdk/apis/kubebind/v1alpha2/zz_generated.deepcopy.go create mode 100644 sdk/client/clientset/versioned/typed/kubebind/v1alpha2/apiresourceschema.go create mode 100644 sdk/client/clientset/versioned/typed/kubebind/v1alpha2/doc.go create mode 100644 sdk/client/clientset/versioned/typed/kubebind/v1alpha2/fake/doc.go create mode 100644 sdk/client/clientset/versioned/typed/kubebind/v1alpha2/fake/fake_apiresourceschema.go create mode 100644 sdk/client/clientset/versioned/typed/kubebind/v1alpha2/fake/fake_kubebind_client.go create mode 100644 sdk/client/clientset/versioned/typed/kubebind/v1alpha2/generated_expansion.go create mode 100644 sdk/client/clientset/versioned/typed/kubebind/v1alpha2/kubebind_client.go create mode 100644 sdk/client/informers/externalversions/kubebind/v1alpha2/apiresourceschema.go create mode 100644 sdk/client/informers/externalversions/kubebind/v1alpha2/interface.go create mode 100644 sdk/client/listers/kubebind/v1alpha2/apiresourceschema.go create mode 100644 sdk/client/listers/kubebind/v1alpha2/expansion_generated.go create mode 100644 sdk/kcp/clientset/versioned/cluster/typed/kubebind/v1alpha2/apiresourceschema.go create mode 100644 sdk/kcp/clientset/versioned/cluster/typed/kubebind/v1alpha2/fake/apiresourceschema.go create mode 100644 sdk/kcp/clientset/versioned/cluster/typed/kubebind/v1alpha2/fake/kubebind_client.go create mode 100644 sdk/kcp/clientset/versioned/cluster/typed/kubebind/v1alpha2/kubebind_client.go create mode 100644 sdk/kcp/informers/externalversions/kubebind/v1alpha2/apiresourceschema.go create mode 100644 sdk/kcp/informers/externalversions/kubebind/v1alpha2/interface.go create mode 100644 sdk/kcp/listers/kubebind/v1alpha2/apiresourceschema.go create mode 100644 sdk/kcp/listers/kubebind/v1alpha2/apiresourceschema_expansion.go diff --git a/deploy/crd/kube-bind.io_apiresourceschemas.yaml b/deploy/crd/kube-bind.io_apiresourceschemas.yaml new file mode 100644 index 000000000..9ed2e219c --- /dev/null +++ b/deploy/crd/kube-bind.io_apiresourceschemas.yaml @@ -0,0 +1,50 @@ +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: v0.16.5 + name: apiresourceschemas.kube-bind.io +spec: + group: kube-bind.io + names: + kind: APIResourceSchema + listKind: APIResourceSchemaList + plural: apiresourceschemas + singular: apiresourceschema + scope: Namespaced + versions: + - name: v1alpha2 + schema: + openAPIV3Schema: + description: APIResourceSchema + properties: + apiVersion: + description: |- + APIVersion defines the versioned schema of this representation of an object. + Servers should convert recognized schemas to the latest internal value, and + may reject unrecognized values. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources + type: string + kind: + description: |- + Kind is a string value representing the REST resource this object represents. + Servers may infer this from the endpoint the client submits requests to. + Cannot be updated. + In CamelCase. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds + type: string + metadata: + type: object + spec: + description: |- + spec specifies how an API service from a service provider should be bound in the + local consumer cluster. + type: object + status: + description: status contains reconciliation information for a service + binding. + type: object + type: object + served: true + storage: true diff --git a/sdk/apis/kubebind/v1alpha2/apiresourceschema_types.go b/sdk/apis/kubebind/v1alpha2/apiresourceschema_types.go new file mode 100644 index 000000000..006f03835 --- /dev/null +++ b/sdk/apis/kubebind/v1alpha2/apiresourceschema_types.go @@ -0,0 +1,50 @@ +/* +Copyright 2025 The Kube Bind 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 v1alpha2 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +// APIResourceSchema +// +crd +// +genclient +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object +type APIResourceSchema struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + + Spec APIResourceSchemaSpec `json:"spec"` + + Status APIResourceSchemaStatus `json:"status,omitempty"` +} + +type APIResourceSchemaSpec struct { +} + +type APIResourceSchemaStatus struct { +} + +// APIResourceSchemaList is a list of APIResourceSchemas. +// +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object +type APIResourceSchemaList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata"` + + Items []APIResourceSchema `json:"items"` +} diff --git a/sdk/apis/kubebind/v1alpha2/doc.go b/sdk/apis/kubebind/v1alpha2/doc.go new file mode 100644 index 000000000..1bb359de3 --- /dev/null +++ b/sdk/apis/kubebind/v1alpha2/doc.go @@ -0,0 +1,23 @@ +/* +Copyright 2025 The Kube Bind 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 v1alpha2 defines the v1alpha1 version of the Kube Bind API +// +// +groupName=kube-bind.io +// +groupGoName=KubeBind +// +k8s:deepcopy-gen=package,register +// +kubebuilder:validation:Optional +package v1alpha2 diff --git a/sdk/apis/kubebind/v1alpha2/register.go b/sdk/apis/kubebind/v1alpha2/register.go new file mode 100644 index 000000000..72700a89e --- /dev/null +++ b/sdk/apis/kubebind/v1alpha2/register.go @@ -0,0 +1,54 @@ +/* +Copyright 2025 The Kube Bind 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 v1alpha2 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/schema" +) + +var ( + SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes) + AddToScheme = SchemeBuilder.AddToScheme +) + +const ( + // GroupName is the group name used in this package + GroupName = "kube-bind.io" + + // GroupVersion is the group version used in this package + GroupVersion = "v1alpha2" +) + +// SchemeGroupVersion is group version used to register these objects +var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: GroupVersion} + +// Resource takes an unqualified resource and returns a Group qualified GroupResource +func Resource(resource string) schema.GroupResource { + return SchemeGroupVersion.WithResource(resource).GroupResource() +} + +// Adds the list of known types to api.Scheme. +func addKnownTypes(scheme *runtime.Scheme) error { + scheme.AddKnownTypes(SchemeGroupVersion, + &APIResourceSchema{}, + ) + + metav1.AddToGroupVersion(scheme, SchemeGroupVersion) + return nil +} diff --git a/sdk/apis/kubebind/v1alpha2/zz_generated.deepcopy.go b/sdk/apis/kubebind/v1alpha2/zz_generated.deepcopy.go new file mode 100644 index 000000000..69c0e5e2a --- /dev/null +++ b/sdk/apis/kubebind/v1alpha2/zz_generated.deepcopy.go @@ -0,0 +1,119 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The Kube Bind 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. +*/ + +// Code generated by deepcopy-gen. DO NOT EDIT. + +package v1alpha2 + +import ( + runtime "k8s.io/apimachinery/pkg/runtime" +) + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *APIResourceSchema) DeepCopyInto(out *APIResourceSchema) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + out.Spec = in.Spec + out.Status = in.Status + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new APIResourceSchema. +func (in *APIResourceSchema) DeepCopy() *APIResourceSchema { + if in == nil { + return nil + } + out := new(APIResourceSchema) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *APIResourceSchema) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *APIResourceSchemaList) DeepCopyInto(out *APIResourceSchemaList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]APIResourceSchema, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new APIResourceSchemaList. +func (in *APIResourceSchemaList) DeepCopy() *APIResourceSchemaList { + if in == nil { + return nil + } + out := new(APIResourceSchemaList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *APIResourceSchemaList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *APIResourceSchemaSpec) DeepCopyInto(out *APIResourceSchemaSpec) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new APIResourceSchemaSpec. +func (in *APIResourceSchemaSpec) DeepCopy() *APIResourceSchemaSpec { + if in == nil { + return nil + } + out := new(APIResourceSchemaSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *APIResourceSchemaStatus) DeepCopyInto(out *APIResourceSchemaStatus) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new APIResourceSchemaStatus. +func (in *APIResourceSchemaStatus) DeepCopy() *APIResourceSchemaStatus { + if in == nil { + return nil + } + out := new(APIResourceSchemaStatus) + in.DeepCopyInto(out) + return out +} diff --git a/sdk/client/clientset/versioned/clientset.go b/sdk/client/clientset/versioned/clientset.go index 7ddfa947e..cceba1e28 100644 --- a/sdk/client/clientset/versioned/clientset.go +++ b/sdk/client/clientset/versioned/clientset.go @@ -27,17 +27,20 @@ import ( flowcontrol "k8s.io/client-go/util/flowcontrol" kubebindv1alpha1 "github.com/kube-bind/kube-bind/sdk/client/clientset/versioned/typed/kubebind/v1alpha1" + kubebindv1alpha2 "github.com/kube-bind/kube-bind/sdk/client/clientset/versioned/typed/kubebind/v1alpha2" ) type Interface interface { Discovery() discovery.DiscoveryInterface KubeBindV1alpha1() kubebindv1alpha1.KubeBindV1alpha1Interface + KubeBindV1alpha2() kubebindv1alpha2.KubeBindV1alpha2Interface } // Clientset contains the clients for groups. type Clientset struct { *discovery.DiscoveryClient kubeBindV1alpha1 *kubebindv1alpha1.KubeBindV1alpha1Client + kubeBindV1alpha2 *kubebindv1alpha2.KubeBindV1alpha2Client } // KubeBindV1alpha1 retrieves the KubeBindV1alpha1Client @@ -45,6 +48,11 @@ func (c *Clientset) KubeBindV1alpha1() kubebindv1alpha1.KubeBindV1alpha1Interfac return c.kubeBindV1alpha1 } +// KubeBindV1alpha2 retrieves the KubeBindV1alpha2Client +func (c *Clientset) KubeBindV1alpha2() kubebindv1alpha2.KubeBindV1alpha2Interface { + return c.kubeBindV1alpha2 +} + // Discovery retrieves the DiscoveryClient func (c *Clientset) Discovery() discovery.DiscoveryInterface { if c == nil { @@ -93,6 +101,10 @@ func NewForConfigAndClient(c *rest.Config, httpClient *http.Client) (*Clientset, if err != nil { return nil, err } + cs.kubeBindV1alpha2, err = kubebindv1alpha2.NewForConfigAndClient(&configShallowCopy, httpClient) + if err != nil { + return nil, err + } cs.DiscoveryClient, err = discovery.NewDiscoveryClientForConfigAndClient(&configShallowCopy, httpClient) if err != nil { @@ -115,6 +127,7 @@ func NewForConfigOrDie(c *rest.Config) *Clientset { func New(c rest.Interface) *Clientset { var cs Clientset cs.kubeBindV1alpha1 = kubebindv1alpha1.New(c) + cs.kubeBindV1alpha2 = kubebindv1alpha2.New(c) cs.DiscoveryClient = discovery.NewDiscoveryClient(c) return &cs diff --git a/sdk/client/clientset/versioned/fake/clientset_generated.go b/sdk/client/clientset/versioned/fake/clientset_generated.go index 4bd9384d5..8d15d2197 100644 --- a/sdk/client/clientset/versioned/fake/clientset_generated.go +++ b/sdk/client/clientset/versioned/fake/clientset_generated.go @@ -28,6 +28,8 @@ import ( clientset "github.com/kube-bind/kube-bind/sdk/client/clientset/versioned" kubebindv1alpha1 "github.com/kube-bind/kube-bind/sdk/client/clientset/versioned/typed/kubebind/v1alpha1" fakekubebindv1alpha1 "github.com/kube-bind/kube-bind/sdk/client/clientset/versioned/typed/kubebind/v1alpha1/fake" + kubebindv1alpha2 "github.com/kube-bind/kube-bind/sdk/client/clientset/versioned/typed/kubebind/v1alpha2" + fakekubebindv1alpha2 "github.com/kube-bind/kube-bind/sdk/client/clientset/versioned/typed/kubebind/v1alpha2/fake" ) // NewSimpleClientset returns a clientset that will respond with the provided objects. @@ -88,3 +90,8 @@ var ( func (c *Clientset) KubeBindV1alpha1() kubebindv1alpha1.KubeBindV1alpha1Interface { return &fakekubebindv1alpha1.FakeKubeBindV1alpha1{Fake: &c.Fake} } + +// KubeBindV1alpha2 retrieves the KubeBindV1alpha2Client +func (c *Clientset) KubeBindV1alpha2() kubebindv1alpha2.KubeBindV1alpha2Interface { + return &fakekubebindv1alpha2.FakeKubeBindV1alpha2{Fake: &c.Fake} +} diff --git a/sdk/client/clientset/versioned/fake/register.go b/sdk/client/clientset/versioned/fake/register.go index 0eb19ef74..f361cafbd 100644 --- a/sdk/client/clientset/versioned/fake/register.go +++ b/sdk/client/clientset/versioned/fake/register.go @@ -26,6 +26,7 @@ import ( utilruntime "k8s.io/apimachinery/pkg/util/runtime" kubebindv1alpha1 "github.com/kube-bind/kube-bind/sdk/apis/kubebind/v1alpha1" + kubebindv1alpha2 "github.com/kube-bind/kube-bind/sdk/apis/kubebind/v1alpha2" ) var scheme = runtime.NewScheme() @@ -33,6 +34,7 @@ var codecs = serializer.NewCodecFactory(scheme) var localSchemeBuilder = runtime.SchemeBuilder{ kubebindv1alpha1.AddToScheme, + kubebindv1alpha2.AddToScheme, } // AddToScheme adds all types of this clientset into the given scheme. This allows composition diff --git a/sdk/client/clientset/versioned/scheme/register.go b/sdk/client/clientset/versioned/scheme/register.go index 7f424d295..20fd57527 100644 --- a/sdk/client/clientset/versioned/scheme/register.go +++ b/sdk/client/clientset/versioned/scheme/register.go @@ -26,6 +26,7 @@ import ( utilruntime "k8s.io/apimachinery/pkg/util/runtime" kubebindv1alpha1 "github.com/kube-bind/kube-bind/sdk/apis/kubebind/v1alpha1" + kubebindv1alpha2 "github.com/kube-bind/kube-bind/sdk/apis/kubebind/v1alpha2" ) var Scheme = runtime.NewScheme() @@ -33,6 +34,7 @@ var Codecs = serializer.NewCodecFactory(Scheme) var ParameterCodec = runtime.NewParameterCodec(Scheme) var localSchemeBuilder = runtime.SchemeBuilder{ kubebindv1alpha1.AddToScheme, + kubebindv1alpha2.AddToScheme, } // AddToScheme adds all types of this clientset into the given scheme. This allows composition diff --git a/sdk/client/clientset/versioned/typed/kubebind/v1alpha2/apiresourceschema.go b/sdk/client/clientset/versioned/typed/kubebind/v1alpha2/apiresourceschema.go new file mode 100644 index 000000000..2d3ef0e55 --- /dev/null +++ b/sdk/client/clientset/versioned/typed/kubebind/v1alpha2/apiresourceschema.go @@ -0,0 +1,70 @@ +/* +Copyright The Kube Bind 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. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +package v1alpha2 + +import ( + "context" + + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + gentype "k8s.io/client-go/gentype" + + v1alpha2 "github.com/kube-bind/kube-bind/sdk/apis/kubebind/v1alpha2" + scheme "github.com/kube-bind/kube-bind/sdk/client/clientset/versioned/scheme" +) + +// APIResourceSchemasGetter has a method to return a APIResourceSchemaInterface. +// A group's client should implement this interface. +type APIResourceSchemasGetter interface { + APIResourceSchemas(namespace string) APIResourceSchemaInterface +} + +// APIResourceSchemaInterface has methods to work with APIResourceSchema resources. +type APIResourceSchemaInterface interface { + Create(ctx context.Context, aPIResourceSchema *v1alpha2.APIResourceSchema, opts v1.CreateOptions) (*v1alpha2.APIResourceSchema, error) + Update(ctx context.Context, aPIResourceSchema *v1alpha2.APIResourceSchema, opts v1.UpdateOptions) (*v1alpha2.APIResourceSchema, error) + // Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). + UpdateStatus(ctx context.Context, aPIResourceSchema *v1alpha2.APIResourceSchema, opts v1.UpdateOptions) (*v1alpha2.APIResourceSchema, error) + Delete(ctx context.Context, name string, opts v1.DeleteOptions) error + DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error + Get(ctx context.Context, name string, opts v1.GetOptions) (*v1alpha2.APIResourceSchema, error) + List(ctx context.Context, opts v1.ListOptions) (*v1alpha2.APIResourceSchemaList, error) + Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) + Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha2.APIResourceSchema, err error) + APIResourceSchemaExpansion +} + +// aPIResourceSchemas implements APIResourceSchemaInterface +type aPIResourceSchemas struct { + *gentype.ClientWithList[*v1alpha2.APIResourceSchema, *v1alpha2.APIResourceSchemaList] +} + +// newAPIResourceSchemas returns a APIResourceSchemas +func newAPIResourceSchemas(c *KubeBindV1alpha2Client, namespace string) *aPIResourceSchemas { + return &aPIResourceSchemas{ + gentype.NewClientWithList[*v1alpha2.APIResourceSchema, *v1alpha2.APIResourceSchemaList]( + "apiresourceschemas", + c.RESTClient(), + scheme.ParameterCodec, + namespace, + func() *v1alpha2.APIResourceSchema { return &v1alpha2.APIResourceSchema{} }, + func() *v1alpha2.APIResourceSchemaList { return &v1alpha2.APIResourceSchemaList{} }), + } +} diff --git a/sdk/client/clientset/versioned/typed/kubebind/v1alpha2/doc.go b/sdk/client/clientset/versioned/typed/kubebind/v1alpha2/doc.go new file mode 100644 index 000000000..5c1216263 --- /dev/null +++ b/sdk/client/clientset/versioned/typed/kubebind/v1alpha2/doc.go @@ -0,0 +1,20 @@ +/* +Copyright The Kube Bind 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. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +// This package has the automatically generated typed clients. +package v1alpha2 diff --git a/sdk/client/clientset/versioned/typed/kubebind/v1alpha2/fake/doc.go b/sdk/client/clientset/versioned/typed/kubebind/v1alpha2/fake/doc.go new file mode 100644 index 000000000..a0ee34800 --- /dev/null +++ b/sdk/client/clientset/versioned/typed/kubebind/v1alpha2/fake/doc.go @@ -0,0 +1,20 @@ +/* +Copyright The Kube Bind 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. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +// Package fake has the automatically generated clients. +package fake diff --git a/sdk/client/clientset/versioned/typed/kubebind/v1alpha2/fake/fake_apiresourceschema.go b/sdk/client/clientset/versioned/typed/kubebind/v1alpha2/fake/fake_apiresourceschema.go new file mode 100644 index 000000000..066f2a2c7 --- /dev/null +++ b/sdk/client/clientset/versioned/typed/kubebind/v1alpha2/fake/fake_apiresourceschema.go @@ -0,0 +1,148 @@ +/* +Copyright The Kube Bind 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. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +package fake + +import ( + "context" + + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + labels "k8s.io/apimachinery/pkg/labels" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + testing "k8s.io/client-go/testing" + + v1alpha2 "github.com/kube-bind/kube-bind/sdk/apis/kubebind/v1alpha2" +) + +// FakeAPIResourceSchemas implements APIResourceSchemaInterface +type FakeAPIResourceSchemas struct { + Fake *FakeKubeBindV1alpha2 + ns string +} + +var apiresourceschemasResource = v1alpha2.SchemeGroupVersion.WithResource("apiresourceschemas") + +var apiresourceschemasKind = v1alpha2.SchemeGroupVersion.WithKind("APIResourceSchema") + +// Get takes name of the aPIResourceSchema, and returns the corresponding aPIResourceSchema object, and an error if there is any. +func (c *FakeAPIResourceSchemas) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha2.APIResourceSchema, err error) { + emptyResult := &v1alpha2.APIResourceSchema{} + obj, err := c.Fake. + Invokes(testing.NewGetActionWithOptions(apiresourceschemasResource, c.ns, name, options), emptyResult) + + if obj == nil { + return emptyResult, err + } + return obj.(*v1alpha2.APIResourceSchema), err +} + +// List takes label and field selectors, and returns the list of APIResourceSchemas that match those selectors. +func (c *FakeAPIResourceSchemas) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha2.APIResourceSchemaList, err error) { + emptyResult := &v1alpha2.APIResourceSchemaList{} + obj, err := c.Fake. + Invokes(testing.NewListActionWithOptions(apiresourceschemasResource, apiresourceschemasKind, c.ns, opts), emptyResult) + + if obj == nil { + return emptyResult, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &v1alpha2.APIResourceSchemaList{ListMeta: obj.(*v1alpha2.APIResourceSchemaList).ListMeta} + for _, item := range obj.(*v1alpha2.APIResourceSchemaList).Items { + if label.Matches(labels.Set(item.Labels)) { + list.Items = append(list.Items, item) + } + } + return list, err +} + +// Watch returns a watch.Interface that watches the requested aPIResourceSchemas. +func (c *FakeAPIResourceSchemas) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { + return c.Fake. + InvokesWatch(testing.NewWatchActionWithOptions(apiresourceschemasResource, c.ns, opts)) + +} + +// Create takes the representation of a aPIResourceSchema and creates it. Returns the server's representation of the aPIResourceSchema, and an error, if there is any. +func (c *FakeAPIResourceSchemas) Create(ctx context.Context, aPIResourceSchema *v1alpha2.APIResourceSchema, opts v1.CreateOptions) (result *v1alpha2.APIResourceSchema, err error) { + emptyResult := &v1alpha2.APIResourceSchema{} + obj, err := c.Fake. + Invokes(testing.NewCreateActionWithOptions(apiresourceschemasResource, c.ns, aPIResourceSchema, opts), emptyResult) + + if obj == nil { + return emptyResult, err + } + return obj.(*v1alpha2.APIResourceSchema), err +} + +// Update takes the representation of a aPIResourceSchema and updates it. Returns the server's representation of the aPIResourceSchema, and an error, if there is any. +func (c *FakeAPIResourceSchemas) Update(ctx context.Context, aPIResourceSchema *v1alpha2.APIResourceSchema, opts v1.UpdateOptions) (result *v1alpha2.APIResourceSchema, err error) { + emptyResult := &v1alpha2.APIResourceSchema{} + obj, err := c.Fake. + Invokes(testing.NewUpdateActionWithOptions(apiresourceschemasResource, c.ns, aPIResourceSchema, opts), emptyResult) + + if obj == nil { + return emptyResult, err + } + return obj.(*v1alpha2.APIResourceSchema), err +} + +// UpdateStatus was generated because the type contains a Status member. +// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). +func (c *FakeAPIResourceSchemas) UpdateStatus(ctx context.Context, aPIResourceSchema *v1alpha2.APIResourceSchema, opts v1.UpdateOptions) (result *v1alpha2.APIResourceSchema, err error) { + emptyResult := &v1alpha2.APIResourceSchema{} + obj, err := c.Fake. + Invokes(testing.NewUpdateSubresourceActionWithOptions(apiresourceschemasResource, "status", c.ns, aPIResourceSchema, opts), emptyResult) + + if obj == nil { + return emptyResult, err + } + return obj.(*v1alpha2.APIResourceSchema), err +} + +// Delete takes name of the aPIResourceSchema and deletes it. Returns an error if one occurs. +func (c *FakeAPIResourceSchemas) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { + _, err := c.Fake. + Invokes(testing.NewDeleteActionWithOptions(apiresourceschemasResource, c.ns, name, opts), &v1alpha2.APIResourceSchema{}) + + return err +} + +// DeleteCollection deletes a collection of objects. +func (c *FakeAPIResourceSchemas) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { + action := testing.NewDeleteCollectionActionWithOptions(apiresourceschemasResource, c.ns, opts, listOpts) + + _, err := c.Fake.Invokes(action, &v1alpha2.APIResourceSchemaList{}) + return err +} + +// Patch applies the patch and returns the patched aPIResourceSchema. +func (c *FakeAPIResourceSchemas) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha2.APIResourceSchema, err error) { + emptyResult := &v1alpha2.APIResourceSchema{} + obj, err := c.Fake. + Invokes(testing.NewPatchSubresourceActionWithOptions(apiresourceschemasResource, c.ns, name, pt, data, opts, subresources...), emptyResult) + + if obj == nil { + return emptyResult, err + } + return obj.(*v1alpha2.APIResourceSchema), err +} diff --git a/sdk/client/clientset/versioned/typed/kubebind/v1alpha2/fake/fake_kubebind_client.go b/sdk/client/clientset/versioned/typed/kubebind/v1alpha2/fake/fake_kubebind_client.go new file mode 100644 index 000000000..429226072 --- /dev/null +++ b/sdk/client/clientset/versioned/typed/kubebind/v1alpha2/fake/fake_kubebind_client.go @@ -0,0 +1,41 @@ +/* +Copyright The Kube Bind 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. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +package fake + +import ( + rest "k8s.io/client-go/rest" + testing "k8s.io/client-go/testing" + + v1alpha2 "github.com/kube-bind/kube-bind/sdk/client/clientset/versioned/typed/kubebind/v1alpha2" +) + +type FakeKubeBindV1alpha2 struct { + *testing.Fake +} + +func (c *FakeKubeBindV1alpha2) APIResourceSchemas(namespace string) v1alpha2.APIResourceSchemaInterface { + return &FakeAPIResourceSchemas{c, namespace} +} + +// RESTClient returns a RESTClient that is used to communicate +// with API server by this client implementation. +func (c *FakeKubeBindV1alpha2) RESTClient() rest.Interface { + var ret *rest.RESTClient + return ret +} diff --git a/sdk/client/clientset/versioned/typed/kubebind/v1alpha2/generated_expansion.go b/sdk/client/clientset/versioned/typed/kubebind/v1alpha2/generated_expansion.go new file mode 100644 index 000000000..4e3067937 --- /dev/null +++ b/sdk/client/clientset/versioned/typed/kubebind/v1alpha2/generated_expansion.go @@ -0,0 +1,21 @@ +/* +Copyright The Kube Bind 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. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +package v1alpha2 + +type APIResourceSchemaExpansion interface{} diff --git a/sdk/client/clientset/versioned/typed/kubebind/v1alpha2/kubebind_client.go b/sdk/client/clientset/versioned/typed/kubebind/v1alpha2/kubebind_client.go new file mode 100644 index 000000000..1f77db9cc --- /dev/null +++ b/sdk/client/clientset/versioned/typed/kubebind/v1alpha2/kubebind_client.go @@ -0,0 +1,108 @@ +/* +Copyright The Kube Bind 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. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +package v1alpha2 + +import ( + "net/http" + + rest "k8s.io/client-go/rest" + + v1alpha2 "github.com/kube-bind/kube-bind/sdk/apis/kubebind/v1alpha2" + "github.com/kube-bind/kube-bind/sdk/client/clientset/versioned/scheme" +) + +type KubeBindV1alpha2Interface interface { + RESTClient() rest.Interface + APIResourceSchemasGetter +} + +// KubeBindV1alpha2Client is used to interact with features provided by the kube-bind.io group. +type KubeBindV1alpha2Client struct { + restClient rest.Interface +} + +func (c *KubeBindV1alpha2Client) APIResourceSchemas(namespace string) APIResourceSchemaInterface { + return newAPIResourceSchemas(c, namespace) +} + +// NewForConfig creates a new KubeBindV1alpha2Client for the given config. +// NewForConfig is equivalent to NewForConfigAndClient(c, httpClient), +// where httpClient was generated with rest.HTTPClientFor(c). +func NewForConfig(c *rest.Config) (*KubeBindV1alpha2Client, error) { + config := *c + if err := setConfigDefaults(&config); err != nil { + return nil, err + } + httpClient, err := rest.HTTPClientFor(&config) + if err != nil { + return nil, err + } + return NewForConfigAndClient(&config, httpClient) +} + +// NewForConfigAndClient creates a new KubeBindV1alpha2Client for the given config and http client. +// Note the http client provided takes precedence over the configured transport values. +func NewForConfigAndClient(c *rest.Config, h *http.Client) (*KubeBindV1alpha2Client, error) { + config := *c + if err := setConfigDefaults(&config); err != nil { + return nil, err + } + client, err := rest.RESTClientForConfigAndClient(&config, h) + if err != nil { + return nil, err + } + return &KubeBindV1alpha2Client{client}, nil +} + +// NewForConfigOrDie creates a new KubeBindV1alpha2Client for the given config and +// panics if there is an error in the config. +func NewForConfigOrDie(c *rest.Config) *KubeBindV1alpha2Client { + client, err := NewForConfig(c) + if err != nil { + panic(err) + } + return client +} + +// New creates a new KubeBindV1alpha2Client for the given RESTClient. +func New(c rest.Interface) *KubeBindV1alpha2Client { + return &KubeBindV1alpha2Client{c} +} + +func setConfigDefaults(config *rest.Config) error { + gv := v1alpha2.SchemeGroupVersion + config.GroupVersion = &gv + config.APIPath = "/apis" + config.NegotiatedSerializer = scheme.Codecs.WithoutConversion() + + if config.UserAgent == "" { + config.UserAgent = rest.DefaultKubernetesUserAgent() + } + + return nil +} + +// RESTClient returns a RESTClient that is used to communicate +// with API server by this client implementation. +func (c *KubeBindV1alpha2Client) RESTClient() rest.Interface { + if c == nil { + return nil + } + return c.restClient +} diff --git a/sdk/client/informers/externalversions/generic.go b/sdk/client/informers/externalversions/generic.go index 6c2da7da1..f61e26520 100644 --- a/sdk/client/informers/externalversions/generic.go +++ b/sdk/client/informers/externalversions/generic.go @@ -25,6 +25,7 @@ import ( cache "k8s.io/client-go/tools/cache" v1alpha1 "github.com/kube-bind/kube-bind/sdk/apis/kubebind/v1alpha1" + v1alpha2 "github.com/kube-bind/kube-bind/sdk/apis/kubebind/v1alpha2" ) // GenericInformer is type of SharedIndexInformer which will locate and delegate to other @@ -65,6 +66,10 @@ func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource case v1alpha1.SchemeGroupVersion.WithResource("clusterbindings"): return &genericInformer{resource: resource.GroupResource(), informer: f.KubeBind().V1alpha1().ClusterBindings().Informer()}, nil + // Group=kube-bind.io, Version=v1alpha2 + case v1alpha2.SchemeGroupVersion.WithResource("apiresourceschemas"): + return &genericInformer{resource: resource.GroupResource(), informer: f.KubeBind().V1alpha2().APIResourceSchemas().Informer()}, nil + } return nil, fmt.Errorf("no informer found for %v", resource) diff --git a/sdk/client/informers/externalversions/kubebind/interface.go b/sdk/client/informers/externalversions/kubebind/interface.go index eb6257351..2a3f534d3 100644 --- a/sdk/client/informers/externalversions/kubebind/interface.go +++ b/sdk/client/informers/externalversions/kubebind/interface.go @@ -21,12 +21,15 @@ package kubebind import ( internalinterfaces "github.com/kube-bind/kube-bind/sdk/client/informers/externalversions/internalinterfaces" v1alpha1 "github.com/kube-bind/kube-bind/sdk/client/informers/externalversions/kubebind/v1alpha1" + v1alpha2 "github.com/kube-bind/kube-bind/sdk/client/informers/externalversions/kubebind/v1alpha2" ) // Interface provides access to each of this group's versions. type Interface interface { // V1alpha1 provides access to shared informers for resources in V1alpha1. V1alpha1() v1alpha1.Interface + // V1alpha2 provides access to shared informers for resources in V1alpha2. + V1alpha2() v1alpha2.Interface } type group struct { @@ -44,3 +47,8 @@ func New(f internalinterfaces.SharedInformerFactory, namespace string, tweakList func (g *group) V1alpha1() v1alpha1.Interface { return v1alpha1.New(g.factory, g.namespace, g.tweakListOptions) } + +// V1alpha2 returns a new v1alpha2.Interface. +func (g *group) V1alpha2() v1alpha2.Interface { + return v1alpha2.New(g.factory, g.namespace, g.tweakListOptions) +} diff --git a/sdk/client/informers/externalversions/kubebind/v1alpha2/apiresourceschema.go b/sdk/client/informers/externalversions/kubebind/v1alpha2/apiresourceschema.go new file mode 100644 index 000000000..dd8e23ef0 --- /dev/null +++ b/sdk/client/informers/externalversions/kubebind/v1alpha2/apiresourceschema.go @@ -0,0 +1,91 @@ +/* +Copyright The Kube Bind 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. +*/ + +// Code generated by informer-gen. DO NOT EDIT. + +package v1alpha2 + +import ( + "context" + time "time" + + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + watch "k8s.io/apimachinery/pkg/watch" + cache "k8s.io/client-go/tools/cache" + + kubebindv1alpha2 "github.com/kube-bind/kube-bind/sdk/apis/kubebind/v1alpha2" + versioned "github.com/kube-bind/kube-bind/sdk/client/clientset/versioned" + internalinterfaces "github.com/kube-bind/kube-bind/sdk/client/informers/externalversions/internalinterfaces" + v1alpha2 "github.com/kube-bind/kube-bind/sdk/client/listers/kubebind/v1alpha2" +) + +// APIResourceSchemaInformer provides access to a shared informer and lister for +// APIResourceSchemas. +type APIResourceSchemaInformer interface { + Informer() cache.SharedIndexInformer + Lister() v1alpha2.APIResourceSchemaLister +} + +type aPIResourceSchemaInformer struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc + namespace string +} + +// NewAPIResourceSchemaInformer constructs a new informer for APIResourceSchema type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewAPIResourceSchemaInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return NewFilteredAPIResourceSchemaInformer(client, namespace, resyncPeriod, indexers, nil) +} + +// NewFilteredAPIResourceSchemaInformer constructs a new informer for APIResourceSchema type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewFilteredAPIResourceSchemaInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { + return cache.NewSharedIndexInformer( + &cache.ListWatch{ + ListFunc: func(options v1.ListOptions) (runtime.Object, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.KubeBindV1alpha2().APIResourceSchemas(namespace).List(context.TODO(), options) + }, + WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.KubeBindV1alpha2().APIResourceSchemas(namespace).Watch(context.TODO(), options) + }, + }, + &kubebindv1alpha2.APIResourceSchema{}, + resyncPeriod, + indexers, + ) +} + +func (f *aPIResourceSchemaInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewFilteredAPIResourceSchemaInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) +} + +func (f *aPIResourceSchemaInformer) Informer() cache.SharedIndexInformer { + return f.factory.InformerFor(&kubebindv1alpha2.APIResourceSchema{}, f.defaultInformer) +} + +func (f *aPIResourceSchemaInformer) Lister() v1alpha2.APIResourceSchemaLister { + return v1alpha2.NewAPIResourceSchemaLister(f.Informer().GetIndexer()) +} diff --git a/sdk/client/informers/externalversions/kubebind/v1alpha2/interface.go b/sdk/client/informers/externalversions/kubebind/v1alpha2/interface.go new file mode 100644 index 000000000..caee10c7f --- /dev/null +++ b/sdk/client/informers/externalversions/kubebind/v1alpha2/interface.go @@ -0,0 +1,45 @@ +/* +Copyright The Kube Bind 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. +*/ + +// Code generated by informer-gen. DO NOT EDIT. + +package v1alpha2 + +import ( + internalinterfaces "github.com/kube-bind/kube-bind/sdk/client/informers/externalversions/internalinterfaces" +) + +// Interface provides access to all the informers in this group version. +type Interface interface { + // APIResourceSchemas returns a APIResourceSchemaInformer. + APIResourceSchemas() APIResourceSchemaInformer +} + +type version struct { + factory internalinterfaces.SharedInformerFactory + namespace string + tweakListOptions internalinterfaces.TweakListOptionsFunc +} + +// New returns a new Interface. +func New(f internalinterfaces.SharedInformerFactory, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) Interface { + return &version{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} +} + +// APIResourceSchemas returns a APIResourceSchemaInformer. +func (v *version) APIResourceSchemas() APIResourceSchemaInformer { + return &aPIResourceSchemaInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} +} diff --git a/sdk/client/listers/kubebind/v1alpha2/apiresourceschema.go b/sdk/client/listers/kubebind/v1alpha2/apiresourceschema.go new file mode 100644 index 000000000..f3cdcdac1 --- /dev/null +++ b/sdk/client/listers/kubebind/v1alpha2/apiresourceschema.go @@ -0,0 +1,71 @@ +/* +Copyright The Kube Bind 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. +*/ + +// Code generated by lister-gen. DO NOT EDIT. + +package v1alpha2 + +import ( + "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/listers" + "k8s.io/client-go/tools/cache" + + v1alpha2 "github.com/kube-bind/kube-bind/sdk/apis/kubebind/v1alpha2" +) + +// APIResourceSchemaLister helps list APIResourceSchemas. +// All objects returned here must be treated as read-only. +type APIResourceSchemaLister interface { + // List lists all APIResourceSchemas in the indexer. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*v1alpha2.APIResourceSchema, err error) + // APIResourceSchemas returns an object that can list and get APIResourceSchemas. + APIResourceSchemas(namespace string) APIResourceSchemaNamespaceLister + APIResourceSchemaListerExpansion +} + +// aPIResourceSchemaLister implements the APIResourceSchemaLister interface. +type aPIResourceSchemaLister struct { + listers.ResourceIndexer[*v1alpha2.APIResourceSchema] +} + +// NewAPIResourceSchemaLister returns a new APIResourceSchemaLister. +func NewAPIResourceSchemaLister(indexer cache.Indexer) APIResourceSchemaLister { + return &aPIResourceSchemaLister{listers.New[*v1alpha2.APIResourceSchema](indexer, v1alpha2.Resource("apiresourceschema"))} +} + +// APIResourceSchemas returns an object that can list and get APIResourceSchemas. +func (s *aPIResourceSchemaLister) APIResourceSchemas(namespace string) APIResourceSchemaNamespaceLister { + return aPIResourceSchemaNamespaceLister{listers.NewNamespaced[*v1alpha2.APIResourceSchema](s.ResourceIndexer, namespace)} +} + +// APIResourceSchemaNamespaceLister helps list and get APIResourceSchemas. +// All objects returned here must be treated as read-only. +type APIResourceSchemaNamespaceLister interface { + // List lists all APIResourceSchemas in the indexer for a given namespace. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*v1alpha2.APIResourceSchema, err error) + // Get retrieves the APIResourceSchema from the indexer for a given namespace and name. + // Objects returned here must be treated as read-only. + Get(name string) (*v1alpha2.APIResourceSchema, error) + APIResourceSchemaNamespaceListerExpansion +} + +// aPIResourceSchemaNamespaceLister implements the APIResourceSchemaNamespaceLister +// interface. +type aPIResourceSchemaNamespaceLister struct { + listers.ResourceIndexer[*v1alpha2.APIResourceSchema] +} diff --git a/sdk/client/listers/kubebind/v1alpha2/expansion_generated.go b/sdk/client/listers/kubebind/v1alpha2/expansion_generated.go new file mode 100644 index 000000000..f2287acf0 --- /dev/null +++ b/sdk/client/listers/kubebind/v1alpha2/expansion_generated.go @@ -0,0 +1,27 @@ +/* +Copyright The Kube Bind 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. +*/ + +// Code generated by lister-gen. DO NOT EDIT. + +package v1alpha2 + +// APIResourceSchemaListerExpansion allows custom methods to be added to +// APIResourceSchemaLister. +type APIResourceSchemaListerExpansion interface{} + +// APIResourceSchemaNamespaceListerExpansion allows custom methods to be added to +// APIResourceSchemaNamespaceLister. +type APIResourceSchemaNamespaceListerExpansion interface{} diff --git a/sdk/kcp/clientset/versioned/cluster/clientset.go b/sdk/kcp/clientset/versioned/cluster/clientset.go index 2b3e8aec6..b647bc8e2 100644 --- a/sdk/kcp/clientset/versioned/cluster/clientset.go +++ b/sdk/kcp/clientset/versioned/cluster/clientset.go @@ -34,12 +34,14 @@ import ( client "github.com/kube-bind/kube-bind/sdk/kcp/clientset/versioned" kubebindv1alpha1 "github.com/kube-bind/kube-bind/sdk/kcp/clientset/versioned/cluster/typed/kubebind/v1alpha1" + kubebindv1alpha2 "github.com/kube-bind/kube-bind/sdk/kcp/clientset/versioned/cluster/typed/kubebind/v1alpha2" ) type ClusterInterface interface { Cluster(logicalcluster.Path) client.Interface Discovery() discovery.DiscoveryInterface KubeBindV1alpha1() kubebindv1alpha1.KubeBindV1alpha1ClusterInterface + KubeBindV1alpha2() kubebindv1alpha2.KubeBindV1alpha2ClusterInterface } // ClusterClientset contains the clients for groups. @@ -47,6 +49,7 @@ type ClusterClientset struct { *discovery.DiscoveryClient clientCache kcpclient.Cache[*client.Clientset] kubebindV1alpha1 *kubebindv1alpha1.KubeBindV1alpha1ClusterClient + kubebindV1alpha2 *kubebindv1alpha2.KubeBindV1alpha2ClusterClient } // Discovery retrieves the DiscoveryClient @@ -62,6 +65,11 @@ func (c *ClusterClientset) KubeBindV1alpha1() kubebindv1alpha1.KubeBindV1alpha1C return c.kubebindV1alpha1 } +// KubeBindV1alpha2 retrieves the KubeBindV1alpha2ClusterClient. +func (c *ClusterClientset) KubeBindV1alpha2() kubebindv1alpha2.KubeBindV1alpha2ClusterInterface { + return c.kubebindV1alpha2 +} + // Cluster scopes this clientset to one cluster. func (c *ClusterClientset) Cluster(clusterPath logicalcluster.Path) client.Interface { if clusterPath == logicalcluster.Wildcard { @@ -118,6 +126,10 @@ func NewForConfigAndClient(c *rest.Config, httpClient *http.Client) (*ClusterCli if err != nil { return nil, err } + cs.kubebindV1alpha2, err = kubebindv1alpha2.NewForConfigAndClient(&configShallowCopy, httpClient) + if err != nil { + return nil, err + } cs.DiscoveryClient, err = discovery.NewDiscoveryClientForConfigAndClient(&configShallowCopy, httpClient) if err != nil { diff --git a/sdk/kcp/clientset/versioned/cluster/fake/clientset.go b/sdk/kcp/clientset/versioned/cluster/fake/clientset.go index 515b705e6..171ca39a2 100644 --- a/sdk/kcp/clientset/versioned/cluster/fake/clientset.go +++ b/sdk/kcp/clientset/versioned/cluster/fake/clientset.go @@ -33,8 +33,11 @@ import ( kcpclient "github.com/kube-bind/kube-bind/sdk/kcp/clientset/versioned/cluster" kcpkubebindv1alpha1 "github.com/kube-bind/kube-bind/sdk/kcp/clientset/versioned/cluster/typed/kubebind/v1alpha1" fakekubebindv1alpha1 "github.com/kube-bind/kube-bind/sdk/kcp/clientset/versioned/cluster/typed/kubebind/v1alpha1/fake" + kcpkubebindv1alpha2 "github.com/kube-bind/kube-bind/sdk/kcp/clientset/versioned/cluster/typed/kubebind/v1alpha2" + fakekubebindv1alpha2 "github.com/kube-bind/kube-bind/sdk/kcp/clientset/versioned/cluster/typed/kubebind/v1alpha2/fake" clientscheme "github.com/kube-bind/kube-bind/sdk/kcp/clientset/versioned/scheme" kubebindv1alpha1 "github.com/kube-bind/kube-bind/sdk/kcp/clientset/versioned/typed/kubebind/v1alpha1" + kubebindv1alpha2 "github.com/kube-bind/kube-bind/sdk/kcp/clientset/versioned/typed/kubebind/v1alpha2" ) // NewSimpleClientset returns a clientset that will respond with the provided objects. @@ -76,6 +79,11 @@ func (c *ClusterClientset) KubeBindV1alpha1() kcpkubebindv1alpha1.KubeBindV1alph return &fakekubebindv1alpha1.KubeBindV1alpha1ClusterClient{Fake: c.Fake} } +// KubeBindV1alpha2 retrieves the KubeBindV1alpha2ClusterClient. +func (c *ClusterClientset) KubeBindV1alpha2() kcpkubebindv1alpha2.KubeBindV1alpha2ClusterInterface { + return &fakekubebindv1alpha2.KubeBindV1alpha2ClusterClient{Fake: c.Fake} +} + // Cluster scopes this clientset to one cluster. func (c *ClusterClientset) Cluster(clusterPath logicalcluster.Path) client.Interface { if clusterPath == logicalcluster.Wildcard { @@ -112,3 +120,8 @@ func (c *Clientset) Tracker() kcptesting.ScopedObjectTracker { func (c *Clientset) KubeBindV1alpha1() kubebindv1alpha1.KubeBindV1alpha1Interface { return &fakekubebindv1alpha1.KubeBindV1alpha1Client{Fake: c.Fake, ClusterPath: c.clusterPath} } + +// KubeBindV1alpha2 retrieves the KubeBindV1alpha2Client. +func (c *Clientset) KubeBindV1alpha2() kubebindv1alpha2.KubeBindV1alpha2Interface { + return &fakekubebindv1alpha2.KubeBindV1alpha2Client{Fake: c.Fake, ClusterPath: c.clusterPath} +} diff --git a/sdk/kcp/clientset/versioned/cluster/scheme/register.go b/sdk/kcp/clientset/versioned/cluster/scheme/register.go index 245fefb54..2b46e2bb8 100644 --- a/sdk/kcp/clientset/versioned/cluster/scheme/register.go +++ b/sdk/kcp/clientset/versioned/cluster/scheme/register.go @@ -29,6 +29,7 @@ import ( utilruntime "k8s.io/apimachinery/pkg/util/runtime" kubebindv1alpha1 "github.com/kube-bind/kube-bind/sdk/apis/kubebind/v1alpha1" + kubebindv1alpha2 "github.com/kube-bind/kube-bind/sdk/apis/kubebind/v1alpha2" ) var Scheme = runtime.NewScheme() @@ -36,6 +37,7 @@ var Codecs = serializer.NewCodecFactory(Scheme) var ParameterCodec = runtime.NewParameterCodec(Scheme) var localSchemeBuilder = runtime.SchemeBuilder{ kubebindv1alpha1.AddToScheme, + kubebindv1alpha2.AddToScheme, } // AddToScheme adds all types of this clientset into the given scheme. This allows composition diff --git a/sdk/kcp/clientset/versioned/cluster/typed/kubebind/v1alpha2/apiresourceschema.go b/sdk/kcp/clientset/versioned/cluster/typed/kubebind/v1alpha2/apiresourceschema.go new file mode 100644 index 000000000..3672294f8 --- /dev/null +++ b/sdk/kcp/clientset/versioned/cluster/typed/kubebind/v1alpha2/apiresourceschema.go @@ -0,0 +1,86 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The Kube Bind 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. +*/ + +// Code generated by kcp code-generator. DO NOT EDIT. + +package v1alpha2 + +import ( + "context" + + kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" + "github.com/kcp-dev/logicalcluster/v3" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/watch" + + kubebindv1alpha2 "github.com/kube-bind/kube-bind/sdk/apis/kubebind/v1alpha2" + kubebindv1alpha2client "github.com/kube-bind/kube-bind/sdk/kcp/clientset/versioned/typed/kubebind/v1alpha2" +) + +// APIResourceSchemasClusterGetter has a method to return a APIResourceSchemaClusterInterface. +// A group's cluster client should implement this interface. +type APIResourceSchemasClusterGetter interface { + APIResourceSchemas() APIResourceSchemaClusterInterface +} + +// APIResourceSchemaClusterInterface can operate on APIResourceSchemas across all clusters, +// or scope down to one cluster and return a APIResourceSchemasNamespacer. +type APIResourceSchemaClusterInterface interface { + Cluster(logicalcluster.Path) APIResourceSchemasNamespacer + List(ctx context.Context, opts metav1.ListOptions) (*kubebindv1alpha2.APIResourceSchemaList, error) + Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) +} + +type aPIResourceSchemasClusterInterface struct { + clientCache kcpclient.Cache[*kubebindv1alpha2client.KubeBindV1alpha2Client] +} + +// Cluster scopes the client down to a particular cluster. +func (c *aPIResourceSchemasClusterInterface) Cluster(clusterPath logicalcluster.Path) APIResourceSchemasNamespacer { + if clusterPath == logicalcluster.Wildcard { + panic("A specific cluster must be provided when scoping, not the wildcard.") + } + + return &aPIResourceSchemasNamespacer{clientCache: c.clientCache, clusterPath: clusterPath} +} + +// List returns the entire collection of all APIResourceSchemas across all clusters. +func (c *aPIResourceSchemasClusterInterface) List(ctx context.Context, opts metav1.ListOptions) (*kubebindv1alpha2.APIResourceSchemaList, error) { + return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).APIResourceSchemas(metav1.NamespaceAll).List(ctx, opts) +} + +// Watch begins to watch all APIResourceSchemas across all clusters. +func (c *aPIResourceSchemasClusterInterface) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { + return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).APIResourceSchemas(metav1.NamespaceAll).Watch(ctx, opts) +} + +// APIResourceSchemasNamespacer can scope to objects within a namespace, returning a kubebindv1alpha2client.APIResourceSchemaInterface. +type APIResourceSchemasNamespacer interface { + Namespace(string) kubebindv1alpha2client.APIResourceSchemaInterface +} + +type aPIResourceSchemasNamespacer struct { + clientCache kcpclient.Cache[*kubebindv1alpha2client.KubeBindV1alpha2Client] + clusterPath logicalcluster.Path +} + +func (n *aPIResourceSchemasNamespacer) Namespace(namespace string) kubebindv1alpha2client.APIResourceSchemaInterface { + return n.clientCache.ClusterOrDie(n.clusterPath).APIResourceSchemas(namespace) +} diff --git a/sdk/kcp/clientset/versioned/cluster/typed/kubebind/v1alpha2/fake/apiresourceschema.go b/sdk/kcp/clientset/versioned/cluster/typed/kubebind/v1alpha2/fake/apiresourceschema.go new file mode 100644 index 000000000..7bc22b869 --- /dev/null +++ b/sdk/kcp/clientset/versioned/cluster/typed/kubebind/v1alpha2/fake/apiresourceschema.go @@ -0,0 +1,213 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The Kube Bind 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. +*/ + +// Code generated by kcp code-generator. DO NOT EDIT. + +package fake + +import ( + "context" + "encoding/json" + "fmt" + + "github.com/kcp-dev/logicalcluster/v3" + + kcptesting "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/labels" + "k8s.io/apimachinery/pkg/runtime/schema" + "k8s.io/apimachinery/pkg/types" + "k8s.io/apimachinery/pkg/watch" + "k8s.io/client-go/testing" + + kubebindv1alpha2 "github.com/kube-bind/kube-bind/sdk/apis/kubebind/v1alpha2" + applyconfigurationskubebindv1alpha2 "github.com/kube-bind/kube-bind/sdk/kcp/applyconfiguration/kubebind/v1alpha2" + kcpkubebindv1alpha2 "github.com/kube-bind/kube-bind/sdk/kcp/clientset/versioned/cluster/typed/kubebind/v1alpha2" + kubebindv1alpha2client "github.com/kube-bind/kube-bind/sdk/kcp/clientset/versioned/typed/kubebind/v1alpha2" +) + +var aPIResourceSchemasResource = schema.GroupVersionResource{Group: "kube-bind.io", Version: "v1alpha2", Resource: "apiresourceschemas"} +var aPIResourceSchemasKind = schema.GroupVersionKind{Group: "kube-bind.io", Version: "v1alpha2", Kind: "APIResourceSchema"} + +type aPIResourceSchemasClusterClient struct { + *kcptesting.Fake +} + +// Cluster scopes the client down to a particular cluster. +func (c *aPIResourceSchemasClusterClient) Cluster(clusterPath logicalcluster.Path) kcpkubebindv1alpha2.APIResourceSchemasNamespacer { + if clusterPath == logicalcluster.Wildcard { + panic("A specific cluster must be provided when scoping, not the wildcard.") + } + + return &aPIResourceSchemasNamespacer{Fake: c.Fake, ClusterPath: clusterPath} +} + +// List takes label and field selectors, and returns the list of APIResourceSchemas that match those selectors across all clusters. +func (c *aPIResourceSchemasClusterClient) List(ctx context.Context, opts metav1.ListOptions) (*kubebindv1alpha2.APIResourceSchemaList, error) { + obj, err := c.Fake.Invokes(kcptesting.NewListAction(aPIResourceSchemasResource, aPIResourceSchemasKind, logicalcluster.Wildcard, metav1.NamespaceAll, opts), &kubebindv1alpha2.APIResourceSchemaList{}) + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &kubebindv1alpha2.APIResourceSchemaList{ListMeta: obj.(*kubebindv1alpha2.APIResourceSchemaList).ListMeta} + for _, item := range obj.(*kubebindv1alpha2.APIResourceSchemaList).Items { + if label.Matches(labels.Set(item.Labels)) { + list.Items = append(list.Items, item) + } + } + return list, err +} + +// Watch returns a watch.Interface that watches the requested APIResourceSchemas across all clusters. +func (c *aPIResourceSchemasClusterClient) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { + return c.Fake.InvokesWatch(kcptesting.NewWatchAction(aPIResourceSchemasResource, logicalcluster.Wildcard, metav1.NamespaceAll, opts)) +} + +type aPIResourceSchemasNamespacer struct { + *kcptesting.Fake + ClusterPath logicalcluster.Path +} + +func (n *aPIResourceSchemasNamespacer) Namespace(namespace string) kubebindv1alpha2client.APIResourceSchemaInterface { + return &aPIResourceSchemasClient{Fake: n.Fake, ClusterPath: n.ClusterPath, Namespace: namespace} +} + +type aPIResourceSchemasClient struct { + *kcptesting.Fake + ClusterPath logicalcluster.Path + Namespace string +} + +func (c *aPIResourceSchemasClient) Create(ctx context.Context, aPIResourceSchema *kubebindv1alpha2.APIResourceSchema, opts metav1.CreateOptions) (*kubebindv1alpha2.APIResourceSchema, error) { + obj, err := c.Fake.Invokes(kcptesting.NewCreateAction(aPIResourceSchemasResource, c.ClusterPath, c.Namespace, aPIResourceSchema), &kubebindv1alpha2.APIResourceSchema{}) + if obj == nil { + return nil, err + } + return obj.(*kubebindv1alpha2.APIResourceSchema), err +} + +func (c *aPIResourceSchemasClient) Update(ctx context.Context, aPIResourceSchema *kubebindv1alpha2.APIResourceSchema, opts metav1.UpdateOptions) (*kubebindv1alpha2.APIResourceSchema, error) { + obj, err := c.Fake.Invokes(kcptesting.NewUpdateAction(aPIResourceSchemasResource, c.ClusterPath, c.Namespace, aPIResourceSchema), &kubebindv1alpha2.APIResourceSchema{}) + if obj == nil { + return nil, err + } + return obj.(*kubebindv1alpha2.APIResourceSchema), err +} + +func (c *aPIResourceSchemasClient) UpdateStatus(ctx context.Context, aPIResourceSchema *kubebindv1alpha2.APIResourceSchema, opts metav1.UpdateOptions) (*kubebindv1alpha2.APIResourceSchema, error) { + obj, err := c.Fake.Invokes(kcptesting.NewUpdateSubresourceAction(aPIResourceSchemasResource, c.ClusterPath, "status", c.Namespace, aPIResourceSchema), &kubebindv1alpha2.APIResourceSchema{}) + if obj == nil { + return nil, err + } + return obj.(*kubebindv1alpha2.APIResourceSchema), err +} + +func (c *aPIResourceSchemasClient) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { + _, err := c.Fake.Invokes(kcptesting.NewDeleteActionWithOptions(aPIResourceSchemasResource, c.ClusterPath, c.Namespace, name, opts), &kubebindv1alpha2.APIResourceSchema{}) + return err +} + +func (c *aPIResourceSchemasClient) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { + action := kcptesting.NewDeleteCollectionAction(aPIResourceSchemasResource, c.ClusterPath, c.Namespace, listOpts) + + _, err := c.Fake.Invokes(action, &kubebindv1alpha2.APIResourceSchemaList{}) + return err +} + +func (c *aPIResourceSchemasClient) Get(ctx context.Context, name string, options metav1.GetOptions) (*kubebindv1alpha2.APIResourceSchema, error) { + obj, err := c.Fake.Invokes(kcptesting.NewGetAction(aPIResourceSchemasResource, c.ClusterPath, c.Namespace, name), &kubebindv1alpha2.APIResourceSchema{}) + if obj == nil { + return nil, err + } + return obj.(*kubebindv1alpha2.APIResourceSchema), err +} + +// List takes label and field selectors, and returns the list of APIResourceSchemas that match those selectors. +func (c *aPIResourceSchemasClient) List(ctx context.Context, opts metav1.ListOptions) (*kubebindv1alpha2.APIResourceSchemaList, error) { + obj, err := c.Fake.Invokes(kcptesting.NewListAction(aPIResourceSchemasResource, aPIResourceSchemasKind, c.ClusterPath, c.Namespace, opts), &kubebindv1alpha2.APIResourceSchemaList{}) + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &kubebindv1alpha2.APIResourceSchemaList{ListMeta: obj.(*kubebindv1alpha2.APIResourceSchemaList).ListMeta} + for _, item := range obj.(*kubebindv1alpha2.APIResourceSchemaList).Items { + if label.Matches(labels.Set(item.Labels)) { + list.Items = append(list.Items, item) + } + } + return list, err +} + +func (c *aPIResourceSchemasClient) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { + return c.Fake.InvokesWatch(kcptesting.NewWatchAction(aPIResourceSchemasResource, c.ClusterPath, c.Namespace, opts)) +} + +func (c *aPIResourceSchemasClient) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (*kubebindv1alpha2.APIResourceSchema, error) { + obj, err := c.Fake.Invokes(kcptesting.NewPatchSubresourceAction(aPIResourceSchemasResource, c.ClusterPath, c.Namespace, name, pt, data, subresources...), &kubebindv1alpha2.APIResourceSchema{}) + if obj == nil { + return nil, err + } + return obj.(*kubebindv1alpha2.APIResourceSchema), err +} + +func (c *aPIResourceSchemasClient) Apply(ctx context.Context, applyConfiguration *applyconfigurationskubebindv1alpha2.APIResourceSchemaApplyConfiguration, opts metav1.ApplyOptions) (*kubebindv1alpha2.APIResourceSchema, error) { + if applyConfiguration == nil { + return nil, fmt.Errorf("applyConfiguration provided to Apply must not be nil") + } + data, err := json.Marshal(applyConfiguration) + if err != nil { + return nil, err + } + name := applyConfiguration.Name + if name == nil { + return nil, fmt.Errorf("applyConfiguration.Name must be provided to Apply") + } + obj, err := c.Fake.Invokes(kcptesting.NewPatchSubresourceAction(aPIResourceSchemasResource, c.ClusterPath, c.Namespace, *name, types.ApplyPatchType, data), &kubebindv1alpha2.APIResourceSchema{}) + if obj == nil { + return nil, err + } + return obj.(*kubebindv1alpha2.APIResourceSchema), err +} + +func (c *aPIResourceSchemasClient) ApplyStatus(ctx context.Context, applyConfiguration *applyconfigurationskubebindv1alpha2.APIResourceSchemaApplyConfiguration, opts metav1.ApplyOptions) (*kubebindv1alpha2.APIResourceSchema, error) { + if applyConfiguration == nil { + return nil, fmt.Errorf("applyConfiguration provided to Apply must not be nil") + } + data, err := json.Marshal(applyConfiguration) + if err != nil { + return nil, err + } + name := applyConfiguration.Name + if name == nil { + return nil, fmt.Errorf("applyConfiguration.Name must be provided to Apply") + } + obj, err := c.Fake.Invokes(kcptesting.NewPatchSubresourceAction(aPIResourceSchemasResource, c.ClusterPath, c.Namespace, *name, types.ApplyPatchType, data, "status"), &kubebindv1alpha2.APIResourceSchema{}) + if obj == nil { + return nil, err + } + return obj.(*kubebindv1alpha2.APIResourceSchema), err +} diff --git a/sdk/kcp/clientset/versioned/cluster/typed/kubebind/v1alpha2/fake/kubebind_client.go b/sdk/kcp/clientset/versioned/cluster/typed/kubebind/v1alpha2/fake/kubebind_client.go new file mode 100644 index 000000000..3131126b7 --- /dev/null +++ b/sdk/kcp/clientset/versioned/cluster/typed/kubebind/v1alpha2/fake/kubebind_client.go @@ -0,0 +1,65 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The Kube Bind 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. +*/ + +// Code generated by kcp code-generator. DO NOT EDIT. + +package fake + +import ( + "github.com/kcp-dev/logicalcluster/v3" + + kcptesting "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing" + "k8s.io/client-go/rest" + + kcpkubebindv1alpha2 "github.com/kube-bind/kube-bind/sdk/kcp/clientset/versioned/cluster/typed/kubebind/v1alpha2" + kubebindv1alpha2 "github.com/kube-bind/kube-bind/sdk/kcp/clientset/versioned/typed/kubebind/v1alpha2" +) + +var _ kcpkubebindv1alpha2.KubeBindV1alpha2ClusterInterface = (*KubeBindV1alpha2ClusterClient)(nil) + +type KubeBindV1alpha2ClusterClient struct { + *kcptesting.Fake +} + +func (c *KubeBindV1alpha2ClusterClient) Cluster(clusterPath logicalcluster.Path) kubebindv1alpha2.KubeBindV1alpha2Interface { + if clusterPath == logicalcluster.Wildcard { + panic("A specific cluster must be provided when scoping, not the wildcard.") + } + return &KubeBindV1alpha2Client{Fake: c.Fake, ClusterPath: clusterPath} +} + +func (c *KubeBindV1alpha2ClusterClient) APIResourceSchemas() kcpkubebindv1alpha2.APIResourceSchemaClusterInterface { + return &aPIResourceSchemasClusterClient{Fake: c.Fake} +} + +var _ kubebindv1alpha2.KubeBindV1alpha2Interface = (*KubeBindV1alpha2Client)(nil) + +type KubeBindV1alpha2Client struct { + *kcptesting.Fake + ClusterPath logicalcluster.Path +} + +func (c *KubeBindV1alpha2Client) RESTClient() rest.Interface { + var ret *rest.RESTClient + return ret +} + +func (c *KubeBindV1alpha2Client) APIResourceSchemas(namespace string) kubebindv1alpha2.APIResourceSchemaInterface { + return &aPIResourceSchemasClient{Fake: c.Fake, ClusterPath: c.ClusterPath, Namespace: namespace} +} diff --git a/sdk/kcp/clientset/versioned/cluster/typed/kubebind/v1alpha2/kubebind_client.go b/sdk/kcp/clientset/versioned/cluster/typed/kubebind/v1alpha2/kubebind_client.go new file mode 100644 index 000000000..82300fa55 --- /dev/null +++ b/sdk/kcp/clientset/versioned/cluster/typed/kubebind/v1alpha2/kubebind_client.go @@ -0,0 +1,90 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The Kube Bind 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. +*/ + +// Code generated by kcp code-generator. DO NOT EDIT. + +package v1alpha2 + +import ( + "net/http" + + kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" + "github.com/kcp-dev/logicalcluster/v3" + + "k8s.io/client-go/rest" + + kubebindv1alpha2 "github.com/kube-bind/kube-bind/sdk/kcp/clientset/versioned/typed/kubebind/v1alpha2" +) + +type KubeBindV1alpha2ClusterInterface interface { + KubeBindV1alpha2ClusterScoper + APIResourceSchemasClusterGetter +} + +type KubeBindV1alpha2ClusterScoper interface { + Cluster(logicalcluster.Path) kubebindv1alpha2.KubeBindV1alpha2Interface +} + +type KubeBindV1alpha2ClusterClient struct { + clientCache kcpclient.Cache[*kubebindv1alpha2.KubeBindV1alpha2Client] +} + +func (c *KubeBindV1alpha2ClusterClient) Cluster(clusterPath logicalcluster.Path) kubebindv1alpha2.KubeBindV1alpha2Interface { + if clusterPath == logicalcluster.Wildcard { + panic("A specific cluster must be provided when scoping, not the wildcard.") + } + return c.clientCache.ClusterOrDie(clusterPath) +} + +func (c *KubeBindV1alpha2ClusterClient) APIResourceSchemas() APIResourceSchemaClusterInterface { + return &aPIResourceSchemasClusterInterface{clientCache: c.clientCache} +} + +// NewForConfig creates a new KubeBindV1alpha2ClusterClient for the given config. +// NewForConfig is equivalent to NewForConfigAndClient(c, httpClient), +// where httpClient was generated with rest.HTTPClientFor(c). +func NewForConfig(c *rest.Config) (*KubeBindV1alpha2ClusterClient, error) { + client, err := rest.HTTPClientFor(c) + if err != nil { + return nil, err + } + return NewForConfigAndClient(c, client) +} + +// NewForConfigAndClient creates a new KubeBindV1alpha2ClusterClient for the given config and http client. +// Note the http client provided takes precedence over the configured transport values. +func NewForConfigAndClient(c *rest.Config, h *http.Client) (*KubeBindV1alpha2ClusterClient, error) { + cache := kcpclient.NewCache(c, h, &kcpclient.Constructor[*kubebindv1alpha2.KubeBindV1alpha2Client]{ + NewForConfigAndClient: kubebindv1alpha2.NewForConfigAndClient, + }) + if _, err := cache.Cluster(logicalcluster.Name("root").Path()); err != nil { + return nil, err + } + return &KubeBindV1alpha2ClusterClient{clientCache: cache}, nil +} + +// NewForConfigOrDie creates a new KubeBindV1alpha2ClusterClient for the given config and +// panics if there is an error in the config. +func NewForConfigOrDie(c *rest.Config) *KubeBindV1alpha2ClusterClient { + client, err := NewForConfig(c) + if err != nil { + panic(err) + } + return client +} diff --git a/sdk/kcp/informers/externalversions/generic.go b/sdk/kcp/informers/externalversions/generic.go index 80ffdd5c6..2c960fdce 100644 --- a/sdk/kcp/informers/externalversions/generic.go +++ b/sdk/kcp/informers/externalversions/generic.go @@ -31,6 +31,7 @@ import ( "k8s.io/client-go/tools/cache" kubebindv1alpha1 "github.com/kube-bind/kube-bind/sdk/apis/kubebind/v1alpha1" + kubebindv1alpha2 "github.com/kube-bind/kube-bind/sdk/apis/kubebind/v1alpha2" ) type GenericClusterInformer interface { @@ -97,6 +98,9 @@ func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource return &genericClusterInformer{resource: resource.GroupResource(), informer: f.KubeBind().V1alpha1().APIServiceNamespaces().Informer()}, nil case kubebindv1alpha1.SchemeGroupVersion.WithResource("clusterbindings"): return &genericClusterInformer{resource: resource.GroupResource(), informer: f.KubeBind().V1alpha1().ClusterBindings().Informer()}, nil + // Group=kube-bind.io, Version=V1alpha2 + case kubebindv1alpha2.SchemeGroupVersion.WithResource("apiresourceschemas"): + return &genericClusterInformer{resource: resource.GroupResource(), informer: f.KubeBind().V1alpha2().APIResourceSchemas().Informer()}, nil } return nil, fmt.Errorf("no informer found for %v", resource) @@ -122,6 +126,10 @@ func (f *sharedScopedInformerFactory) ForResource(resource schema.GroupVersionRe case kubebindv1alpha1.SchemeGroupVersion.WithResource("clusterbindings"): informer := f.KubeBind().V1alpha1().ClusterBindings().Informer() return &genericInformer{lister: cache.NewGenericLister(informer.GetIndexer(), resource.GroupResource()), informer: informer}, nil + // Group=kube-bind.io, Version=V1alpha2 + case kubebindv1alpha2.SchemeGroupVersion.WithResource("apiresourceschemas"): + informer := f.KubeBind().V1alpha2().APIResourceSchemas().Informer() + return &genericInformer{lister: cache.NewGenericLister(informer.GetIndexer(), resource.GroupResource()), informer: informer}, nil } return nil, fmt.Errorf("no informer found for %v", resource) diff --git a/sdk/kcp/informers/externalversions/kubebind/interface.go b/sdk/kcp/informers/externalversions/kubebind/interface.go index 7f42e6ea7..ce45aed66 100644 --- a/sdk/kcp/informers/externalversions/kubebind/interface.go +++ b/sdk/kcp/informers/externalversions/kubebind/interface.go @@ -24,11 +24,14 @@ package kubebind import ( "github.com/kube-bind/kube-bind/sdk/kcp/informers/externalversions/internalinterfaces" "github.com/kube-bind/kube-bind/sdk/kcp/informers/externalversions/kubebind/v1alpha1" + "github.com/kube-bind/kube-bind/sdk/kcp/informers/externalversions/kubebind/v1alpha2" ) type ClusterInterface interface { // V1alpha1 provides access to the shared informers in V1alpha1. V1alpha1() v1alpha1.ClusterInterface + // V1alpha2 provides access to the shared informers in V1alpha2. + V1alpha2() v1alpha2.ClusterInterface } type group struct { @@ -46,9 +49,16 @@ func (g *group) V1alpha1() v1alpha1.ClusterInterface { return v1alpha1.New(g.factory, g.tweakListOptions) } +// V1alpha2 returns a new v1alpha2.ClusterInterface. +func (g *group) V1alpha2() v1alpha2.ClusterInterface { + return v1alpha2.New(g.factory, g.tweakListOptions) +} + type Interface interface { // V1alpha1 provides access to the shared informers in V1alpha1. V1alpha1() v1alpha1.Interface + // V1alpha2 provides access to the shared informers in V1alpha2. + V1alpha2() v1alpha2.Interface } type scopedGroup struct { @@ -66,3 +76,8 @@ func NewScoped(f internalinterfaces.SharedScopedInformerFactory, namespace strin func (g *scopedGroup) V1alpha1() v1alpha1.Interface { return v1alpha1.NewScoped(g.factory, g.namespace, g.tweakListOptions) } + +// V1alpha2 returns a new v1alpha2.ClusterInterface. +func (g *scopedGroup) V1alpha2() v1alpha2.Interface { + return v1alpha2.NewScoped(g.factory, g.namespace, g.tweakListOptions) +} diff --git a/sdk/kcp/informers/externalversions/kubebind/v1alpha2/apiresourceschema.go b/sdk/kcp/informers/externalversions/kubebind/v1alpha2/apiresourceschema.go new file mode 100644 index 000000000..a01baaf3b --- /dev/null +++ b/sdk/kcp/informers/externalversions/kubebind/v1alpha2/apiresourceschema.go @@ -0,0 +1,182 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The Kube Bind 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. +*/ + +// Code generated by kcp code-generator. DO NOT EDIT. + +package v1alpha2 + +import ( + "context" + "time" + + kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" + kcpinformers "github.com/kcp-dev/apimachinery/v2/third_party/informers" + "github.com/kcp-dev/logicalcluster/v3" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/watch" + "k8s.io/client-go/tools/cache" + + kubebindv1alpha2 "github.com/kube-bind/kube-bind/sdk/apis/kubebind/v1alpha2" + scopedclientset "github.com/kube-bind/kube-bind/sdk/kcp/clientset/versioned" + clientset "github.com/kube-bind/kube-bind/sdk/kcp/clientset/versioned/cluster" + "github.com/kube-bind/kube-bind/sdk/kcp/informers/externalversions/internalinterfaces" + kubebindv1alpha2listers "github.com/kube-bind/kube-bind/sdk/kcp/listers/kubebind/v1alpha2" +) + +// APIResourceSchemaClusterInformer provides access to a shared informer and lister for +// APIResourceSchemas. +type APIResourceSchemaClusterInformer interface { + Cluster(logicalcluster.Name) APIResourceSchemaInformer + Informer() kcpcache.ScopeableSharedIndexInformer + Lister() kubebindv1alpha2listers.APIResourceSchemaClusterLister +} + +type aPIResourceSchemaClusterInformer struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc +} + +// NewAPIResourceSchemaClusterInformer constructs a new informer for APIResourceSchema type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewAPIResourceSchemaClusterInformer(client clientset.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers) kcpcache.ScopeableSharedIndexInformer { + return NewFilteredAPIResourceSchemaClusterInformer(client, resyncPeriod, indexers, nil) +} + +// NewFilteredAPIResourceSchemaClusterInformer constructs a new informer for APIResourceSchema type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewFilteredAPIResourceSchemaClusterInformer(client clientset.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) kcpcache.ScopeableSharedIndexInformer { + return kcpinformers.NewSharedIndexInformer( + &cache.ListWatch{ + ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.KubeBindV1alpha2().APIResourceSchemas().List(context.TODO(), options) + }, + WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.KubeBindV1alpha2().APIResourceSchemas().Watch(context.TODO(), options) + }, + }, + &kubebindv1alpha2.APIResourceSchema{}, + resyncPeriod, + indexers, + ) +} + +func (f *aPIResourceSchemaClusterInformer) defaultInformer(client clientset.ClusterInterface, resyncPeriod time.Duration) kcpcache.ScopeableSharedIndexInformer { + return NewFilteredAPIResourceSchemaClusterInformer(client, resyncPeriod, cache.Indexers{ + kcpcache.ClusterIndexName: kcpcache.ClusterIndexFunc, + kcpcache.ClusterAndNamespaceIndexName: kcpcache.ClusterAndNamespaceIndexFunc}, + f.tweakListOptions, + ) +} + +func (f *aPIResourceSchemaClusterInformer) Informer() kcpcache.ScopeableSharedIndexInformer { + return f.factory.InformerFor(&kubebindv1alpha2.APIResourceSchema{}, f.defaultInformer) +} + +func (f *aPIResourceSchemaClusterInformer) Lister() kubebindv1alpha2listers.APIResourceSchemaClusterLister { + return kubebindv1alpha2listers.NewAPIResourceSchemaClusterLister(f.Informer().GetIndexer()) +} + +// APIResourceSchemaInformer provides access to a shared informer and lister for +// APIResourceSchemas. +type APIResourceSchemaInformer interface { + Informer() cache.SharedIndexInformer + Lister() kubebindv1alpha2listers.APIResourceSchemaLister +} + +func (f *aPIResourceSchemaClusterInformer) Cluster(clusterName logicalcluster.Name) APIResourceSchemaInformer { + return &aPIResourceSchemaInformer{ + informer: f.Informer().Cluster(clusterName), + lister: f.Lister().Cluster(clusterName), + } +} + +type aPIResourceSchemaInformer struct { + informer cache.SharedIndexInformer + lister kubebindv1alpha2listers.APIResourceSchemaLister +} + +func (f *aPIResourceSchemaInformer) Informer() cache.SharedIndexInformer { + return f.informer +} + +func (f *aPIResourceSchemaInformer) Lister() kubebindv1alpha2listers.APIResourceSchemaLister { + return f.lister +} + +type aPIResourceSchemaScopedInformer struct { + factory internalinterfaces.SharedScopedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc + namespace string +} + +func (f *aPIResourceSchemaScopedInformer) Informer() cache.SharedIndexInformer { + return f.factory.InformerFor(&kubebindv1alpha2.APIResourceSchema{}, f.defaultInformer) +} + +func (f *aPIResourceSchemaScopedInformer) Lister() kubebindv1alpha2listers.APIResourceSchemaLister { + return kubebindv1alpha2listers.NewAPIResourceSchemaLister(f.Informer().GetIndexer()) +} + +// NewAPIResourceSchemaInformer constructs a new informer for APIResourceSchema type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewAPIResourceSchemaInformer(client scopedclientset.Interface, resyncPeriod time.Duration, namespace string, indexers cache.Indexers) cache.SharedIndexInformer { + return NewFilteredAPIResourceSchemaInformer(client, resyncPeriod, namespace, indexers, nil) +} + +// NewFilteredAPIResourceSchemaInformer constructs a new informer for APIResourceSchema type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewFilteredAPIResourceSchemaInformer(client scopedclientset.Interface, resyncPeriod time.Duration, namespace string, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { + return cache.NewSharedIndexInformer( + &cache.ListWatch{ + ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.KubeBindV1alpha2().APIResourceSchemas(namespace).List(context.TODO(), options) + }, + WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.KubeBindV1alpha2().APIResourceSchemas(namespace).Watch(context.TODO(), options) + }, + }, + &kubebindv1alpha2.APIResourceSchema{}, + resyncPeriod, + indexers, + ) +} + +func (f *aPIResourceSchemaScopedInformer) defaultInformer(client scopedclientset.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewFilteredAPIResourceSchemaInformer(client, resyncPeriod, f.namespace, cache.Indexers{ + cache.NamespaceIndex: cache.MetaNamespaceIndexFunc, + }, f.tweakListOptions) +} diff --git a/sdk/kcp/informers/externalversions/kubebind/v1alpha2/interface.go b/sdk/kcp/informers/externalversions/kubebind/v1alpha2/interface.go new file mode 100644 index 000000000..b48ba3bb2 --- /dev/null +++ b/sdk/kcp/informers/externalversions/kubebind/v1alpha2/interface.go @@ -0,0 +1,67 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The Kube Bind 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. +*/ + +// Code generated by kcp code-generator. DO NOT EDIT. + +package v1alpha2 + +import ( + "github.com/kube-bind/kube-bind/sdk/kcp/informers/externalversions/internalinterfaces" +) + +type ClusterInterface interface { + // APIResourceSchemas returns a APIResourceSchemaClusterInformer + APIResourceSchemas() APIResourceSchemaClusterInformer +} + +type version struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc +} + +// New returns a new ClusterInterface. +func New(f internalinterfaces.SharedInformerFactory, tweakListOptions internalinterfaces.TweakListOptionsFunc) ClusterInterface { + return &version{factory: f, tweakListOptions: tweakListOptions} +} + +// APIResourceSchemas returns a APIResourceSchemaClusterInformer +func (v *version) APIResourceSchemas() APIResourceSchemaClusterInformer { + return &aPIResourceSchemaClusterInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} +} + +type Interface interface { + // APIResourceSchemas returns a APIResourceSchemaInformer + APIResourceSchemas() APIResourceSchemaInformer +} + +type scopedVersion struct { + factory internalinterfaces.SharedScopedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc + namespace string +} + +// New returns a new ClusterInterface. +func NewScoped(f internalinterfaces.SharedScopedInformerFactory, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) Interface { + return &scopedVersion{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} +} + +// APIResourceSchemas returns a APIResourceSchemaInformer +func (v *scopedVersion) APIResourceSchemas() APIResourceSchemaInformer { + return &aPIResourceSchemaScopedInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} +} diff --git a/sdk/kcp/listers/kubebind/v1alpha2/apiresourceschema.go b/sdk/kcp/listers/kubebind/v1alpha2/apiresourceschema.go new file mode 100644 index 000000000..5498fd446 --- /dev/null +++ b/sdk/kcp/listers/kubebind/v1alpha2/apiresourceschema.go @@ -0,0 +1,196 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The Kube Bind 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. +*/ + +// Code generated by kcp code-generator. DO NOT EDIT. + +package v1alpha2 + +import ( + kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" + "github.com/kcp-dev/logicalcluster/v3" + + "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/tools/cache" + + kubebindv1alpha2 "github.com/kube-bind/kube-bind/sdk/apis/kubebind/v1alpha2" +) + +// APIResourceSchemaClusterLister can list APIResourceSchemas across all workspaces, or scope down to a APIResourceSchemaLister for one workspace. +// All objects returned here must be treated as read-only. +type APIResourceSchemaClusterLister interface { + // List lists all APIResourceSchemas in the indexer. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*kubebindv1alpha2.APIResourceSchema, err error) + // Cluster returns a lister that can list and get APIResourceSchemas in one workspace. + Cluster(clusterName logicalcluster.Name) APIResourceSchemaLister + APIResourceSchemaClusterListerExpansion +} + +type aPIResourceSchemaClusterLister struct { + indexer cache.Indexer +} + +// NewAPIResourceSchemaClusterLister returns a new APIResourceSchemaClusterLister. +// We assume that the indexer: +// - is fed by a cross-workspace LIST+WATCH +// - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function +// - has the kcpcache.ClusterIndex as an index +// - has the kcpcache.ClusterAndNamespaceIndex as an index +func NewAPIResourceSchemaClusterLister(indexer cache.Indexer) *aPIResourceSchemaClusterLister { + return &aPIResourceSchemaClusterLister{indexer: indexer} +} + +// List lists all APIResourceSchemas in the indexer across all workspaces. +func (s *aPIResourceSchemaClusterLister) List(selector labels.Selector) (ret []*kubebindv1alpha2.APIResourceSchema, err error) { + err = cache.ListAll(s.indexer, selector, func(m interface{}) { + ret = append(ret, m.(*kubebindv1alpha2.APIResourceSchema)) + }) + return ret, err +} + +// Cluster scopes the lister to one workspace, allowing users to list and get APIResourceSchemas. +func (s *aPIResourceSchemaClusterLister) Cluster(clusterName logicalcluster.Name) APIResourceSchemaLister { + return &aPIResourceSchemaLister{indexer: s.indexer, clusterName: clusterName} +} + +// APIResourceSchemaLister can list APIResourceSchemas across all namespaces, or scope down to a APIResourceSchemaNamespaceLister for one namespace. +// All objects returned here must be treated as read-only. +type APIResourceSchemaLister interface { + // List lists all APIResourceSchemas in the workspace. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*kubebindv1alpha2.APIResourceSchema, err error) + // APIResourceSchemas returns a lister that can list and get APIResourceSchemas in one workspace and namespace. + APIResourceSchemas(namespace string) APIResourceSchemaNamespaceLister + APIResourceSchemaListerExpansion +} + +// aPIResourceSchemaLister can list all APIResourceSchemas inside a workspace or scope down to a APIResourceSchemaLister for one namespace. +type aPIResourceSchemaLister struct { + indexer cache.Indexer + clusterName logicalcluster.Name +} + +// List lists all APIResourceSchemas in the indexer for a workspace. +func (s *aPIResourceSchemaLister) List(selector labels.Selector) (ret []*kubebindv1alpha2.APIResourceSchema, err error) { + err = kcpcache.ListAllByCluster(s.indexer, s.clusterName, selector, func(i interface{}) { + ret = append(ret, i.(*kubebindv1alpha2.APIResourceSchema)) + }) + return ret, err +} + +// APIResourceSchemas returns an object that can list and get APIResourceSchemas in one namespace. +func (s *aPIResourceSchemaLister) APIResourceSchemas(namespace string) APIResourceSchemaNamespaceLister { + return &aPIResourceSchemaNamespaceLister{indexer: s.indexer, clusterName: s.clusterName, namespace: namespace} +} + +// aPIResourceSchemaNamespaceLister helps list and get APIResourceSchemas. +// All objects returned here must be treated as read-only. +type APIResourceSchemaNamespaceLister interface { + // List lists all APIResourceSchemas in the workspace and namespace. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*kubebindv1alpha2.APIResourceSchema, err error) + // Get retrieves the APIResourceSchema from the indexer for a given workspace, namespace and name. + // Objects returned here must be treated as read-only. + Get(name string) (*kubebindv1alpha2.APIResourceSchema, error) + APIResourceSchemaNamespaceListerExpansion +} + +// aPIResourceSchemaNamespaceLister helps list and get APIResourceSchemas. +// All objects returned here must be treated as read-only. +type aPIResourceSchemaNamespaceLister struct { + indexer cache.Indexer + clusterName logicalcluster.Name + namespace string +} + +// List lists all APIResourceSchemas in the indexer for a given workspace and namespace. +func (s *aPIResourceSchemaNamespaceLister) List(selector labels.Selector) (ret []*kubebindv1alpha2.APIResourceSchema, err error) { + err = kcpcache.ListAllByClusterAndNamespace(s.indexer, s.clusterName, s.namespace, selector, func(i interface{}) { + ret = append(ret, i.(*kubebindv1alpha2.APIResourceSchema)) + }) + return ret, err +} + +// Get retrieves the APIResourceSchema from the indexer for a given workspace, namespace and name. +func (s *aPIResourceSchemaNamespaceLister) Get(name string) (*kubebindv1alpha2.APIResourceSchema, error) { + key := kcpcache.ToClusterAwareKey(s.clusterName.String(), s.namespace, name) + obj, exists, err := s.indexer.GetByKey(key) + if err != nil { + return nil, err + } + if !exists { + return nil, errors.NewNotFound(kubebindv1alpha2.Resource("apiresourceschemas"), name) + } + return obj.(*kubebindv1alpha2.APIResourceSchema), nil +} + +// NewAPIResourceSchemaLister returns a new APIResourceSchemaLister. +// We assume that the indexer: +// - is fed by a workspace-scoped LIST+WATCH +// - uses cache.MetaNamespaceKeyFunc as the key function +// - has the cache.NamespaceIndex as an index +func NewAPIResourceSchemaLister(indexer cache.Indexer) *aPIResourceSchemaScopedLister { + return &aPIResourceSchemaScopedLister{indexer: indexer} +} + +// aPIResourceSchemaScopedLister can list all APIResourceSchemas inside a workspace or scope down to a APIResourceSchemaLister for one namespace. +type aPIResourceSchemaScopedLister struct { + indexer cache.Indexer +} + +// List lists all APIResourceSchemas in the indexer for a workspace. +func (s *aPIResourceSchemaScopedLister) List(selector labels.Selector) (ret []*kubebindv1alpha2.APIResourceSchema, err error) { + err = cache.ListAll(s.indexer, selector, func(i interface{}) { + ret = append(ret, i.(*kubebindv1alpha2.APIResourceSchema)) + }) + return ret, err +} + +// APIResourceSchemas returns an object that can list and get APIResourceSchemas in one namespace. +func (s *aPIResourceSchemaScopedLister) APIResourceSchemas(namespace string) APIResourceSchemaNamespaceLister { + return &aPIResourceSchemaScopedNamespaceLister{indexer: s.indexer, namespace: namespace} +} + +// aPIResourceSchemaScopedNamespaceLister helps list and get APIResourceSchemas. +type aPIResourceSchemaScopedNamespaceLister struct { + indexer cache.Indexer + namespace string +} + +// List lists all APIResourceSchemas in the indexer for a given workspace and namespace. +func (s *aPIResourceSchemaScopedNamespaceLister) List(selector labels.Selector) (ret []*kubebindv1alpha2.APIResourceSchema, err error) { + err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(i interface{}) { + ret = append(ret, i.(*kubebindv1alpha2.APIResourceSchema)) + }) + return ret, err +} + +// Get retrieves the APIResourceSchema from the indexer for a given workspace, namespace and name. +func (s *aPIResourceSchemaScopedNamespaceLister) Get(name string) (*kubebindv1alpha2.APIResourceSchema, error) { + key := s.namespace + "/" + name + obj, exists, err := s.indexer.GetByKey(key) + if err != nil { + return nil, err + } + if !exists { + return nil, errors.NewNotFound(kubebindv1alpha2.Resource("apiresourceschemas"), name) + } + return obj.(*kubebindv1alpha2.APIResourceSchema), nil +} diff --git a/sdk/kcp/listers/kubebind/v1alpha2/apiresourceschema_expansion.go b/sdk/kcp/listers/kubebind/v1alpha2/apiresourceschema_expansion.go new file mode 100644 index 000000000..f656c23de --- /dev/null +++ b/sdk/kcp/listers/kubebind/v1alpha2/apiresourceschema_expansion.go @@ -0,0 +1,31 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The Kube Bind 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. +*/ + +// Code generated by kcp code-generator. DO NOT EDIT. + +package v1alpha2 + +// APIResourceSchemaClusterListerExpansion allows custom methods to be added to APIResourceSchemaClusterLister. +type APIResourceSchemaClusterListerExpansion interface{} + +// APIResourceSchemaListerExpansion allows custom methods to be added to APIResourceSchemaLister. +type APIResourceSchemaListerExpansion interface{} + +// APIResourceSchemaNamespaceListerExpansion allows custom methods to be added to APIResourceSchemaNamespaceLister. +type APIResourceSchemaNamespaceListerExpansion interface{} From 8df80696242cc630ed8c6ab4ba87294b74d364a9 Mon Sep 17 00:00:00 2001 From: Karol Szwaj Date: Tue, 15 Apr 2025 16:44:32 +0200 Subject: [PATCH 2/8] update APIResourceSchemaSpec and initialize CLI tool for object creation Signed-off-by: Karol Szwaj On-behalf-of: @SAP karol.szwaj@sap.com --- .../cmd/crd2apiresourceschema.go | 50 +++ cli/cmd/crd2apiresourceschema/main.go | 37 ++ cli/pkg/crd2apiresourceschema/cmd/cmd.go | 61 ++++ .../plugin/crd2apiresourceschema.go | 67 ++++ deploy/crd/kube-bind.io_apiconversions.yaml | 124 +++++++ .../crd/kube-bind.io_apiresourceschemas.yaml | 325 +++++++++++++++++- .../v1alpha2/apiresourceschema_types.go | 317 ++++++++++++++++- .../v1alpha2/zz_generated.deepcopy.go | 247 ++++++++++++- .../typed/kubebind/v1alpha2/apiconversion.go | 68 ++++ .../kubebind/v1alpha2/apiresourceschema.go | 2 - .../v1alpha2/fake/fake_apiconversion.go | 127 +++++++ .../v1alpha2/fake/fake_apiresourceschema.go | 13 - .../v1alpha2/fake/fake_kubebind_client.go | 4 + .../kubebind/v1alpha2/generated_expansion.go | 2 + .../kubebind/v1alpha2/kubebind_client.go | 5 + .../informers/externalversions/generic.go | 2 + .../kubebind/v1alpha2/apiconversion.go | 90 +++++ .../kubebind/v1alpha2/interface.go | 7 + .../kubebind/v1alpha2/apiconversion.go | 49 +++ .../kubebind/v1alpha2/expansion_generated.go | 4 + .../typed/kubebind/v1alpha2/apiconversion.go | 72 ++++ .../kubebind/v1alpha2/fake/apiconversion.go | 202 +++++++++++ .../kubebind/v1alpha2/fake/kubebind_client.go | 8 + .../kubebind/v1alpha2/kubebind_client.go | 5 + sdk/kcp/informers/externalversions/generic.go | 5 + .../kubebind/v1alpha2/apiconversion.go | 179 ++++++++++ .../kubebind/v1alpha2/interface.go | 14 + .../kubebind/v1alpha2/apiconversion.go | 143 ++++++++ .../v1alpha2/apiconversion_expansion.go | 28 ++ 29 files changed, 2226 insertions(+), 31 deletions(-) create mode 100644 cli/cmd/crd2apiresourceschema/cmd/crd2apiresourceschema.go create mode 100644 cli/cmd/crd2apiresourceschema/main.go create mode 100644 cli/pkg/crd2apiresourceschema/cmd/cmd.go create mode 100644 cli/pkg/crd2apiresourceschema/plugin/crd2apiresourceschema.go create mode 100644 deploy/crd/kube-bind.io_apiconversions.yaml create mode 100644 sdk/client/clientset/versioned/typed/kubebind/v1alpha2/apiconversion.go create mode 100644 sdk/client/clientset/versioned/typed/kubebind/v1alpha2/fake/fake_apiconversion.go create mode 100644 sdk/client/informers/externalversions/kubebind/v1alpha2/apiconversion.go create mode 100644 sdk/client/listers/kubebind/v1alpha2/apiconversion.go create mode 100644 sdk/kcp/clientset/versioned/cluster/typed/kubebind/v1alpha2/apiconversion.go create mode 100644 sdk/kcp/clientset/versioned/cluster/typed/kubebind/v1alpha2/fake/apiconversion.go create mode 100644 sdk/kcp/informers/externalversions/kubebind/v1alpha2/apiconversion.go create mode 100644 sdk/kcp/listers/kubebind/v1alpha2/apiconversion.go create mode 100644 sdk/kcp/listers/kubebind/v1alpha2/apiconversion_expansion.go diff --git a/cli/cmd/crd2apiresourceschema/cmd/crd2apiresourceschema.go b/cli/cmd/crd2apiresourceschema/cmd/crd2apiresourceschema.go new file mode 100644 index 000000000..9870f7251 --- /dev/null +++ b/cli/cmd/crd2apiresourceschema/cmd/crd2apiresourceschema.go @@ -0,0 +1,50 @@ +/* +Copyright 2025 The Kube Bind 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 cmd + +import ( + goflags "flag" + "fmt" + "os" + + "github.com/spf13/cobra" + + crd2apiresourceschemacmd "github.com/kube-bind/kube-bind/cli/pkg/crd2apiresourceschema/cmd" + "k8s.io/cli-runtime/pkg/genericclioptions" + "k8s.io/component-base/version" + "k8s.io/klog/v2" +) + +func CRD2APIResourceSchemaCmd() *cobra.Command { + rootCmd, err := crd2apiresourceschemacmd.New(genericclioptions.IOStreams{In: os.Stdin, Out: os.Stdout, ErrOut: os.Stderr}) + if err != nil { + fmt.Fprintf(os.Stderr, "error: %v", err) + os.Exit(1) + } + // setup klog + fs := goflags.NewFlagSet("klog", goflags.PanicOnError) + klog.InitFlags(fs) + rootCmd.PersistentFlags().AddGoFlagSet(fs) + + if v := version.Get().String(); len(v) == 0 { + rootCmd.Version = "" + } else { + rootCmd.Version = v + } + + return rootCmd +} diff --git a/cli/cmd/crd2apiresourceschema/main.go b/cli/cmd/crd2apiresourceschema/main.go new file mode 100644 index 000000000..f4c7207e3 --- /dev/null +++ b/cli/cmd/crd2apiresourceschema/main.go @@ -0,0 +1,37 @@ +/* +Copyright 2025 The Kube Bind 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 main + +import ( + "fmt" + "os" + + "github.com/spf13/pflag" + + cmd "github.com/kube-bind/kube-bind/cli/cmd/crd2apiresourceschema/cmd" +) + +func main() { + flags := pflag.NewFlagSet("crd2apiresourceschema", pflag.ExitOnError) + pflag.CommandLine = flags + + command := cmd.CRD2APIResourceSchemaCmd() + if err := command.Execute(); err != nil { + fmt.Fprintf(os.Stderr, "error: %v\n", err) + os.Exit(1) + } +} diff --git a/cli/pkg/crd2apiresourceschema/cmd/cmd.go b/cli/pkg/crd2apiresourceschema/cmd/cmd.go new file mode 100644 index 000000000..acad31265 --- /dev/null +++ b/cli/pkg/crd2apiresourceschema/cmd/cmd.go @@ -0,0 +1,61 @@ +/* +Copyright 2025 The Kube Bind 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 cmd + +import ( + "fmt" + + "github.com/spf13/cobra" + + "k8s.io/cli-runtime/pkg/genericclioptions" + _ "k8s.io/client-go/plugin/pkg/client/auth/exec" + _ "k8s.io/client-go/plugin/pkg/client/auth/oidc" + logsv1 "k8s.io/component-base/logs/api/v1" + + "github.com/kube-bind/kube-bind/cli/pkg/crd2apiresourceschema/plugin" +) + +var ( + CRD2APIResourceSchemaUses = `` +) + +func New(streams genericclioptions.IOStreams) (*cobra.Command, error) { + opts := plugin.NewCRD2APIResourceSchemaOptions(streams) + cmd := &cobra.Command{ + Use: "crd2apiresourceschema", + Short: "Create APIResourceSchema from provided CRD in the cluster.", + Example: fmt.Sprintf(CRD2APIResourceSchemaUses, "crd2apiresourceschema"), + SilenceUsage: true, + RunE: func(cmd *cobra.Command, args []string) error { + if err := logsv1.ValidateAndApply(opts.Logs, nil); err != nil { + return err + } + + if len(args) > 1 { + return cmd.Help() + } + if err := opts.Complete(args); err != nil { + return err + } + + return opts.Run(cmd.Context()) + }, + } + opts.AddCmdFlags(cmd) + + return cmd, nil +} diff --git a/cli/pkg/crd2apiresourceschema/plugin/crd2apiresourceschema.go b/cli/pkg/crd2apiresourceschema/plugin/crd2apiresourceschema.go new file mode 100644 index 000000000..0bbb2e319 --- /dev/null +++ b/cli/pkg/crd2apiresourceschema/plugin/crd2apiresourceschema.go @@ -0,0 +1,67 @@ +/* +Copyright 2025 The Kube Bind 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 plugin + +import ( + "context" + + "github.com/spf13/cobra" + + "k8s.io/cli-runtime/pkg/genericclioptions" + "k8s.io/component-base/logs" + logsv1 "k8s.io/component-base/logs/api/v1" + + "github.com/kube-bind/kube-bind/cli/pkg/kubectl/base" +) + +// CRD2APIResourceSchemaOptions are the options for the kubectl-bind-apiservice command. +type CRD2APIResourceSchemaOptions struct { + Options *base.Options + Logs *logs.Options + Print *genericclioptions.PrintFlags +} + +// NewCRD2APIResourceSchemaOptions returns new BindAPIServiceOptions. +func NewCRD2APIResourceSchemaOptions(streams genericclioptions.IOStreams) *CRD2APIResourceSchemaOptions { + return &CRD2APIResourceSchemaOptions{ + Options: base.NewOptions(streams), + Logs: logs.NewOptions(), + Print: genericclioptions.NewPrintFlags("kubectl-bind-apiservice"), + } +} + +// AddCmdFlags binds fields to cmd's flagset. +func (b *CRD2APIResourceSchemaOptions) AddCmdFlags(cmd *cobra.Command) { + b.Options.BindFlags(cmd) + logsv1.AddFlags(b.Logs, cmd.Flags()) + b.Print.AddFlags(cmd) +} + +// Complete ensures all fields are initialized. +func (b *CRD2APIResourceSchemaOptions) Complete(args []string) error { + if err := b.Options.Complete(); err != nil { + return err + } + + return nil +} + +// Run starts the binding process. +func (b *CRD2APIResourceSchemaOptions) Run(ctx context.Context) error { + + return nil +} diff --git a/deploy/crd/kube-bind.io_apiconversions.yaml b/deploy/crd/kube-bind.io_apiconversions.yaml new file mode 100644 index 000000000..5101a551d --- /dev/null +++ b/deploy/crd/kube-bind.io_apiconversions.yaml @@ -0,0 +1,124 @@ +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: v0.16.5 + name: apiconversions.kube-bind.io +spec: + group: kube-bind.io + names: + categories: + - kcp + kind: APIConversion + listKind: APIConversionList + plural: apiconversions + singular: apiconversion + scope: Cluster + versions: + - additionalPrinterColumns: + - jsonPath: .metadata.creationTimestamp + name: Age + type: date + name: v1alpha2 + schema: + openAPIV3Schema: + description: |- + APIConversion contains rules to convert between different API versions in an APIResourceSchema. The name must match + the name of the APIResourceSchema for the conversions to take effect. + properties: + apiVersion: + description: |- + APIVersion defines the versioned schema of this representation of an object. + Servers should convert recognized schemas to the latest internal value, and + may reject unrecognized values. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources + type: string + kind: + description: |- + Kind is a string value representing the REST resource this object represents. + Servers may infer this from the endpoint the client submits requests to. + Cannot be updated. + In CamelCase. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds + type: string + metadata: + type: object + spec: + description: Spec holds the desired state. + properties: + conversions: + description: conversions specify rules to convert between different + API versions in an APIResourceSchema. + items: + description: |- + APIVersionConversion contains rules to convert between two specific API versions in an + APIResourceSchema. Additionally, to avoid data loss when round-tripping from a version that + contains a new field to one that doesn't and back again, you can specify a list of fields to + preserve (these are stored in annotations). + properties: + from: + description: from is the source version. + minLength: 1 + pattern: ^v[1-9][0-9]*([a-z]+[1-9][0-9]*)?$ + type: string + preserve: + description: |- + preserve contains a list of JSONPath expressions to fields to preserve in the originating version + of the object, relative to its root, such as '.spec.name.first'. + items: + type: string + type: array + rules: + description: rules contains field-specific conversion expressions. + items: + description: APIConversionRule specifies how to convert a + single field. + properties: + destination: + description: |- + destination is a JSONPath expression to the field in the target version of the object, relative to + its root, such as '.spec.name.first'. + minLength: 1 + type: string + field: + description: |- + field is a JSONPath expression to the field in the originating version of the object, relative to its root, such + as '.spec.name.first'. + minLength: 1 + type: string + transformation: + description: |- + transformation is an optional CEL expression used to execute user-specified rules to transform the + originating field -- identified by 'self' -- to the destination field. + type: string + required: + - destination + - field + type: object + type: array + x-kubernetes-list-map-keys: + - destination + x-kubernetes-list-type: map + to: + description: to is the target version. + minLength: 1 + pattern: ^v[1-9][0-9]*([a-z]+[1-9][0-9]*)?$ + type: string + required: + - from + - rules + - to + type: object + type: array + x-kubernetes-list-map-keys: + - from + - to + x-kubernetes-list-type: map + required: + - conversions + type: object + type: object + served: true + storage: true + subresources: {} diff --git a/deploy/crd/kube-bind.io_apiresourceschemas.yaml b/deploy/crd/kube-bind.io_apiresourceschemas.yaml index 9ed2e219c..ce56f2d8a 100644 --- a/deploy/crd/kube-bind.io_apiresourceschemas.yaml +++ b/deploy/crd/kube-bind.io_apiresourceschemas.yaml @@ -37,13 +37,324 @@ spec: metadata: type: object spec: - description: |- - spec specifies how an API service from a service provider should be bound in the - local consumer cluster. - type: object - status: - description: status contains reconciliation information for a service - binding. + properties: + conversion: + description: conversion defines conversion settings for the defined + custom resource. + properties: + strategy: + description: |- + strategy specifies how custom resources are converted between versions. Allowed values are: + - `"None"`: The converter only change the apiVersion and would not touch any other field in the custom resource. + - `"Webhook"`: API Server will call to an external webhook to do the conversion. Additional information + is needed for this option. This requires spec.preserveUnknownFields to be false, and spec.conversion.webhook to be set. + enum: + - None + - Webhook + type: string + webhook: + description: webhook describes how to call the conversion webhook. + Required when `strategy` is set to `"Webhook"`. + properties: + clientConfig: + description: clientConfig is the instructions for how to call + the webhook if strategy is `Webhook`. + properties: + caBundle: + description: |- + caBundle is a PEM encoded CA bundle which will be used to validate the webhook's server certificate. + If unspecified, system trust roots on the apiserver are used. + format: byte + type: string + url: + description: |- + url gives the location of the webhook, in standard URL form + (`scheme://host:port/path`). + + Please note that using `localhost` or `127.0.0.1` as a `host` is + risky unless you take great care to run this webhook on all hosts + which run an apiserver which might need to make calls to this + webhook. Such installs are likely to be non-portable, i.e., not easy + to turn up in a new cluster. + + The scheme must be "https"; the URL must begin with "https://". + + A path is optional, and if present may be any string permissible in + a URL. You may use the path to pass an arbitrary string to the + webhook, for example, a cluster identifier. + + Attempting to use a user or basic auth e.g. "user:password@" is not + allowed. Fragments ("#...") and query parameters ("?...") are not + allowed, either. + + Note: kcp does not support provided service names like Kubernetes does. + format: uri + type: string + type: object + conversionReviewVersions: + description: |- + conversionReviewVersions is an ordered list of preferred `ConversionReview` + versions the Webhook expects. The API server will use the first version in + the list which it supports. If none of the versions specified in this list + are supported by API server, conversion will fail for the custom resource. + If a persisted Webhook configuration specifies allowed versions and does not + include any versions known to the API Server, calls to the webhook will fail. + items: + type: string + type: array + x-kubernetes-list-type: atomic + type: object + type: object + x-kubernetes-validations: + - message: Webhook must be specified if strategy=Webhook + rule: (self.strategy == 'None' && !has(self.webhook)) || (self.strategy + == 'Webhook' && has(self.webhook)) + group: + description: "group is the API group of the defined custom resource. + Empty string means the\ncore API group. \tThe resources are served + under `/apis//...` or `/api` for the core group." + type: string + informerScope: + allOf: + - enum: + - Cluster + - Namespaced + - enum: + - Cluster + - Namespaced + description: |- + InformerScope indicates whether the defined custom resource is cluster- or namespace-scoped. + Allowed values are `Cluster` and `Namespaced`. + type: string + nameValidation: + default: DNS1123Subdomain + description: |- + nameValidation can be used to configure name validation for bound APIs. + Allowed values are `DNS1123Subdomain` and `PathSegmentName`. + - DNS1123Subdomain: a lowercase RFC 1123 subdomain must consist of lower case + alphanumeric characters, '-' or '.', and must start and end with an alphanumeric character. + Regex used is '[a-z0-9]([-a-z0-9]*[a-z0-9])?(\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*' + - PathSegmentName: validates the name can be safely encoded as a path segment. + The name may not be '.' or '..' and the name may not contain '/' or '%'. + + Defaults to `DNS1123Subdomain`, matching the behaviour of CRDs. + enum: + - DNS1123Subdomain + - PathSegmentName + type: string + names: + description: names specify the resource and kind names for the custom + resource. + properties: + categories: + description: |- + categories is a list of grouped resources this custom resource belongs to (e.g. 'all'). + This is published in API discovery documents, and used by clients to support invocations like + `kubectl get all`. + items: + type: string + type: array + x-kubernetes-list-type: atomic + kind: + description: |- + kind is the serialized kind of the resource. It is normally CamelCase and singular. + Custom resource instances will use this value as the `kind` attribute in API calls. + type: string + listKind: + description: listKind is the serialized kind of the list for this + resource. Defaults to "`kind`List". + type: string + plural: + description: |- + plural is the plural name of the resource to serve. + The custom resources are served under `/apis///.../`. + Must match the name of the CustomResourceDefinition (in the form `.`). + Must be all lowercase. + type: string + shortNames: + description: |- + shortNames are short names for the resource, exposed in API discovery documents, + and used by clients to support invocations like `kubectl get `. + It must be all lowercase. + items: + type: string + type: array + x-kubernetes-list-type: atomic + singular: + description: singular is the singular name of the resource. It + must be all lowercase. Defaults to lowercased `kind`. + type: string + required: + - kind + - plural + type: object + scope: + description: |- + scope indicates whether the defined custom resource is cluster- or namespace-scoped. + Allowed values are `Cluster` and `Namespaced`. + enum: + - Cluster + - Namespaced + type: string + versions: + description: |- + versions is the API version of the defined custom resource. + + Note: the OpenAPI v3 schemas must be equal for all versions until CEL + version migration is supported. + items: + description: APIResourceVersion describes one API version of a resource. + properties: + additionalPrinterColumns: + description: |- + additionalPrinterColumns specifies additional columns returned in Table output. + See https://kubernetes.io/docs/reference/using-api/api-concepts/#receiving-resources-as-tables for details. + If no columns are specified, a single column displaying the age of the custom resource is used. + items: + description: CustomResourceColumnDefinition specifies a column + for server side printing. + properties: + description: + description: description is a human readable description + of this column. + type: string + format: + description: |- + format is an optional OpenAPI type definition for this column. The 'name' format is applied + to the primary identifier column to assist in clients identifying column is the resource name. + See https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#data-types for details. + type: string + jsonPath: + description: |- + jsonPath is a simple JSON path (i.e. with array notation) which is evaluated against + each custom resource to produce the value for this column. + type: string + name: + description: name is a human readable name for the column. + type: string + priority: + description: |- + priority is an integer defining the relative importance of this column compared to others. Lower + numbers are considered higher priority. Columns that may be omitted in limited space scenarios + should be given a priority greater than 0. + format: int32 + type: integer + type: + description: |- + 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 details. + type: string + required: + - jsonPath + - name + - type + type: object + type: array + x-kubernetes-list-map-keys: + - name + x-kubernetes-list-type: map + deprecated: + description: |- + deprecated indicates this version of the custom resource API is deprecated. + When set to true, API requests to this version receive a warning header in the server response. + Defaults to false. + type: boolean + deprecationWarning: + description: |- + deprecationWarning overrides the default warning returned to API clients. + May only be set when `deprecated` is true. + The default warning indicates this version is deprecated and recommends use + of the newest served version of equal or greater stability, if one exists. + type: string + name: + description: |- + name is the version name, e.g. “v1”, “v2beta1”, etc. + The custom resources are served under this version at `/apis///...` if `served` is true. + minLength: 1 + pattern: ^v[1-9][0-9]*([a-z]+[1-9][0-9]*)?$ + type: string + schema: + description: |- + schema describes the structural schema used for validation, pruning, and defaulting + of this version of the custom resource. + type: object + x-kubernetes-map-type: atomic + x-kubernetes-preserve-unknown-fields: true + served: + default: true + description: served is a flag enabling/disabling this version + from being served via REST APIs + type: boolean + storage: + description: |- + storage indicates this version should be used when persisting custom resources to storage. + There must be exactly one version with storage=true. + type: boolean + subresources: + description: subresources specify what subresources this version + of the defined custom resource have. + properties: + scale: + description: scale indicates the custom resource should + serve a `/scale` subresource that returns an `autoscaling/v1` + Scale object. + properties: + labelSelectorPath: + description: |- + labelSelectorPath defines the JSON path inside of a custom resource that corresponds to Scale `status.selector`. + Only JSON paths without the array notation are allowed. + Must be a JSON Path under `.status` or `.spec`. + Must be set to work with HorizontalPodAutoscaler. + The field pointed by this JSON path must be a string field (not a complex selector struct) + which contains a serialized label selector in string form. + More info: https://kubernetes.io/docs/tasks/access-kubernetes-api/custom-resources/custom-resource-definitions#scale-subresource + If there is no value under the given path in the custom resource, the `status.selector` value in the `/scale` + subresource will default to the empty string. + type: string + specReplicasPath: + description: |- + specReplicasPath defines the JSON path inside of a custom resource that corresponds to Scale `spec.replicas`. + Only JSON paths without the array notation are allowed. + Must be a JSON Path under `.spec`. + If there is no value under the given path in the custom resource, the `/scale` subresource will return an error on GET. + type: string + statusReplicasPath: + description: |- + statusReplicasPath defines the JSON path inside of a custom resource that corresponds to Scale `status.replicas`. + Only JSON paths without the array notation are allowed. + Must be a JSON Path under `.status`. + If there is no value under the given path in the custom resource, the `status.replicas` value in the `/scale` subresource + will default to 0. + type: string + required: + - specReplicasPath + - statusReplicasPath + type: object + status: + description: |- + status indicates the custom resource should serve a `/status` subresource. + When enabled: + 1. requests to the custom resource primary endpoint ignore changes to the `status` stanza of the object. + 2. requests to the custom resource `/status` subresource ignore changes to anything other than the `status` stanza of the object. + type: object + type: object + required: + - name + - schema + - served + - storage + type: object + minItems: 1 + type: array + x-kubernetes-list-map-keys: + - name + x-kubernetes-list-type: map + required: + - group + - informerScope + - names + - scope + - versions type: object type: object served: true diff --git a/sdk/apis/kubebind/v1alpha2/apiresourceschema_types.go b/sdk/apis/kubebind/v1alpha2/apiresourceschema_types.go index 006f03835..fba7c16c8 100644 --- a/sdk/apis/kubebind/v1alpha2/apiresourceschema_types.go +++ b/sdk/apis/kubebind/v1alpha2/apiresourceschema_types.go @@ -17,7 +17,21 @@ limitations under the License. package v1alpha2 import ( + "encoding/json" + + apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" +) + +// InformerScope is the scope of the Api. +// +// +kubebuilder:validation:Enum=Cluster;Namespaced +type InformerScope string + +const ( + ClusterScope InformerScope = "Cluster" + NamespacedScope InformerScope = "Namespaced" ) // APIResourceSchema @@ -29,14 +43,186 @@ type APIResourceSchema struct { metav1.ObjectMeta `json:"metadata,omitempty"` Spec APIResourceSchemaSpec `json:"spec"` - - Status APIResourceSchemaStatus `json:"status,omitempty"` } type APIResourceSchemaSpec struct { + // InformerScope indicates whether the informer for defined custom resource is cluster- or namespace-scoped. + // Allowed values are `Cluster` and `Namespaced`. + // + // +required + // +kubebuilder:validation:Enum=Cluster;Namespaced + InformerScope InformerScope `json:"informerScope"` + + APIResourceSchemaCRDSpec `json:",inline"` +} + +type APIResourceSchemaCRDSpec struct { + // group is the API group of the defined custom resource. Empty string means the + // core API group. The resources are served under `/apis//...` or `/api` for the core group. + // + // +required + Group string `json:"group"` + + // names specify the resource and kind names for the custom resource. + // + // +required + Names apiextensionsv1.CustomResourceDefinitionNames `json:"names"` + // scope indicates whether the defined custom resource is cluster- or namespace-scoped. + // Allowed values are `Cluster` and `Namespaced`. + // + // +required + // +kubebuilder:validation:Enum=Cluster;Namespaced + Scope apiextensionsv1.ResourceScope `json:"scope"` + + // versions is the API version of the defined custom resource. + // + // Note: the OpenAPI v3 schemas must be equal for all versions until CEL + // version migration is supported. + // + // +required + // +listType=map + // +listMapKey=name + // +kubebuilder:validation:MinItems=1 + Versions []APIResourceVersion `json:"versions"` + + // nameValidation can be used to configure name validation for bound APIs. + // Allowed values are `DNS1123Subdomain` and `PathSegmentName`. + // - DNS1123Subdomain: a lowercase RFC 1123 subdomain must consist of lower case + // alphanumeric characters, '-' or '.', and must start and end with an alphanumeric character. + // Regex used is '[a-z0-9]([-a-z0-9]*[a-z0-9])?(\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*' + // - PathSegmentName: validates the name can be safely encoded as a path segment. + // The name may not be '.' or '..' and the name may not contain '/' or '%'. + // + // Defaults to `DNS1123Subdomain`, matching the behaviour of CRDs. + // + // +optional + // +kubebuilder:validation:Enum=DNS1123Subdomain;PathSegmentName + // +kubebuilder:default=DNS1123Subdomain + NameValidation string `json:"nameValidation,omitempty"` + + // conversion defines conversion settings for the defined custom resource. + // +optional + Conversion *CustomResourceConversion `json:"conversion,omitempty"` +} + +// APIResourceVersion describes one API version of a resource. +type APIResourceVersion struct { + // name is the version name, e.g. “v1”, “v2beta1”, etc. + // The custom resources are served under this version at `/apis///...` if `served` is true. + // + // +required + // +kubebuilder:validation:MinLength=1 + // +kubebuilder:validation:Pattern=^v[1-9][0-9]*([a-z]+[1-9][0-9]*)?$ + Name string `json:"name"` + // served is a flag enabling/disabling this version from being served via REST APIs + // + // +required + // +kubebuilder:default=true + Served bool `json:"served"` + // storage indicates this version should be used when persisting custom resources to storage. + // There must be exactly one version with storage=true. + // + // +required + Storage bool `json:"storage"` + + //nolint:gocritic + // deprecated indicates this version of the custom resource API is deprecated. + // When set to true, API requests to this version receive a warning header in the server response. + // Defaults to false. + // + // +optional + Deprecated bool `json:"deprecated,omitempty"` + // deprecationWarning overrides the default warning returned to API clients. + // May only be set when `deprecated` is true. + // The default warning indicates this version is deprecated and recommends use + // of the newest served version of equal or greater stability, if one exists. + // + // +optional + DeprecationWarning *string `json:"deprecationWarning,omitempty"` + // schema describes the structural schema used for validation, pruning, and defaulting + // of this version of the custom resource. + // + // +required + // +kubebuilder:pruning:PreserveUnknownFields + // +structType=atomic + Schema runtime.RawExtension `json:"schema"` + // subresources specify what subresources this version of the defined custom resource have. + // + // +optional + Subresources apiextensionsv1.CustomResourceSubresources `json:"subresources,omitempty"` + // additionalPrinterColumns specifies additional columns returned in Table output. + // See https://kubernetes.io/docs/reference/using-api/api-concepts/#receiving-resources-as-tables for details. + // If no columns are specified, a single column displaying the age of the custom resource is used. + // + // +optional + // +listType=map + // +listMapKey=name + AdditionalPrinterColumns []apiextensionsv1.CustomResourceColumnDefinition `json:"additionalPrinterColumns,omitempty"` +} + +// CustomResourceConversion describes how to convert different versions of a CR. +// +kubebuilder:validation:XValidation:message="Webhook must be specified if strategy=Webhook",rule="(self.strategy == 'None' && !has(self.webhook)) || (self.strategy == 'Webhook' && has(self.webhook))" +type CustomResourceConversion struct { + // strategy specifies how custom resources are converted between versions. Allowed values are: + // - `"None"`: The converter only change the apiVersion and would not touch any other field in the custom resource. + // - `"Webhook"`: API Server will call to an external webhook to do the conversion. Additional information + // is needed for this option. This requires spec.preserveUnknownFields to be false, and spec.conversion.webhook to be set. + // +kubebuilder:validation:Enum=None;Webhook + Strategy ConversionStrategyType `json:"strategy"` + + // webhook describes how to call the conversion webhook. Required when `strategy` is set to `"Webhook"`. + // +optional + Webhook *WebhookConversion `json:"webhook,omitempty"` +} + +// ConversionStrategyType describes different conversion types. +type ConversionStrategyType string + +// WebhookConversion describes how to call a conversion webhook +type WebhookConversion struct { + // clientConfig is the instructions for how to call the webhook if strategy is `Webhook`. + // +optional + ClientConfig *WebhookClientConfig `json:"clientConfig,omitempty"` + + // conversionReviewVersions is an ordered list of preferred `ConversionReview` + // versions the Webhook expects. The API server will use the first version in + // the list which it supports. If none of the versions specified in this list + // are supported by API server, conversion will fail for the custom resource. + // If a persisted Webhook configuration specifies allowed versions and does not + // include any versions known to the API Server, calls to the webhook will fail. + // +listType=atomic + ConversionReviewVersions []string `json:"conversionReviewVersions"` } -type APIResourceSchemaStatus struct { +// WebhookClientConfig contains the information to make a TLS connection with the webhook. +type WebhookClientConfig struct { + // url gives the location of the webhook, in standard URL form + // (`scheme://host:port/path`). + // + // Please note that using `localhost` or `127.0.0.1` as a `host` is + // risky unless you take great care to run this webhook on all hosts + // which run an apiserver which might need to make calls to this + // webhook. Such installs are likely to be non-portable, i.e., not easy + // to turn up in a new cluster. + // + // The scheme must be "https"; the URL must begin with "https://". + // + // A path is optional, and if present may be any string permissible in + // a URL. You may use the path to pass an arbitrary string to the + // webhook, for example, a cluster identifier. + // + // Attempting to use a user or basic auth e.g. "user:password@" is not + // allowed. Fragments ("#...") and query parameters ("?...") are not + // allowed, either. + // + // Note: kcp does not support provided service names like Kubernetes does. + // +kubebuilder:validation:Format=uri + URL string `json:"url,omitempty"` + + // caBundle is a PEM encoded CA bundle which will be used to validate the webhook's server certificate. + // If unspecified, system trust roots on the apiserver are used. + // +optional + CABundle []byte `json:"caBundle,omitempty"` } // APIResourceSchemaList is a list of APIResourceSchemas. @@ -48,3 +234,128 @@ type APIResourceSchemaList struct { Items []APIResourceSchema `json:"items"` } + +func (v *APIResourceVersion) GetSchema() (*apiextensionsv1.JSONSchemaProps, error) { + if v.Schema.Raw == nil { + return nil, nil + } + var schema apiextensionsv1.JSONSchemaProps + if err := json.Unmarshal(v.Schema.Raw, &schema); err != nil { + return nil, err + } + return &schema, nil +} + +func (v *APIResourceVersion) SetSchema(schema *apiextensionsv1.JSONSchemaProps) error { + if schema == nil { + v.Schema.Raw = nil + return nil + } + raw, err := json.Marshal(schema) + if err != nil { + return err + } + v.Schema.Raw = raw + return nil +} + +const ( + // VersionPreservationAnnotationKeyPrefix is the prefix for the annotation key used to preserve fields from an API + // version that would otherwise be lost during round-tripping to a different API version. An example key and value + // might look like this: preserve.conversion.apis.kcp.io/v2: {"spec.someNewField": "someValue"}. + VersionPreservationAnnotationKeyPrefix = "preserve.conversion.apis.kcp.io/" +) + +// +crd +// +genclient +// +genclient:nonNamespaced +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object +// +kubebuilder:resource:scope=Cluster,categories=kcp +// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp" + +// APIConversion contains rules to convert between different API versions in an APIResourceSchema. The name must match +// the name of the APIResourceSchema for the conversions to take effect. +type APIConversion struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata"` + + // Spec holds the desired state. + Spec APIConversionSpec `json:"spec"` +} + +// APIConversionSpec contains rules to convert between different API versions in an APIResourceSchema. +type APIConversionSpec struct { + // conversions specify rules to convert between different API versions in an APIResourceSchema. + // + // +required + // +listType=map + // +listMapKey=from + // +listMapKey=to + Conversions []APIVersionConversion `json:"conversions"` +} + +// APIVersionConversion contains rules to convert between two specific API versions in an +// APIResourceSchema. Additionally, to avoid data loss when round-tripping from a version that +// contains a new field to one that doesn't and back again, you can specify a list of fields to +// preserve (these are stored in annotations). +type APIVersionConversion struct { + // from is the source version. + // + // +required + // +kubebuilder:validation:MinLength=1 + // +kubebuilder:validation:Pattern=^v[1-9][0-9]*([a-z]+[1-9][0-9]*)?$ + From string `json:"from"` + + // to is the target version. + // + // +required + // +kubebuilder:validation:MinLength=1 + // +kubebuilder:validation:Pattern=^v[1-9][0-9]*([a-z]+[1-9][0-9]*)?$ + To string `json:"to"` + + // rules contains field-specific conversion expressions. + // + // +required + // +listType=map + // +listMapKey=destination + Rules []APIConversionRule `json:"rules"` + + // preserve contains a list of JSONPath expressions to fields to preserve in the originating version + // of the object, relative to its root, such as '.spec.name.first'. + // + // +optional + Preserve []string `json:"preserve,omitempty"` +} + +// APIConversionRule specifies how to convert a single field. +type APIConversionRule struct { + // field is a JSONPath expression to the field in the originating version of the object, relative to its root, such + // as '.spec.name.first'. + // + // +required + // +kubebuilder:validation:MinLength=1 + Field string `json:"field"` + + // destination is a JSONPath expression to the field in the target version of the object, relative to + // its root, such as '.spec.name.first'. + // + // +required + // +kubebuilder:validation:MinLength=1 + Destination string `json:"destination"` + + // transformation is an optional CEL expression used to execute user-specified rules to transform the + // originating field -- identified by 'self' -- to the destination field. + // + // +optional + Transformation string `json:"transformation,omitempty"` +} + +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// APIConversionList is a list of APIConversion resources. +type APIConversionList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata"` + + Items []APIConversion `json:"items"` +} diff --git a/sdk/apis/kubebind/v1alpha2/zz_generated.deepcopy.go b/sdk/apis/kubebind/v1alpha2/zz_generated.deepcopy.go index 69c0e5e2a..92db79220 100644 --- a/sdk/apis/kubebind/v1alpha2/zz_generated.deepcopy.go +++ b/sdk/apis/kubebind/v1alpha2/zz_generated.deepcopy.go @@ -22,16 +22,115 @@ limitations under the License. package v1alpha2 import ( + v1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" runtime "k8s.io/apimachinery/pkg/runtime" ) +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *APIConversion) DeepCopyInto(out *APIConversion) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new APIConversion. +func (in *APIConversion) DeepCopy() *APIConversion { + if in == nil { + return nil + } + out := new(APIConversion) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *APIConversion) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *APIConversionList) DeepCopyInto(out *APIConversionList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]APIConversion, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new APIConversionList. +func (in *APIConversionList) DeepCopy() *APIConversionList { + if in == nil { + return nil + } + out := new(APIConversionList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *APIConversionList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *APIConversionRule) DeepCopyInto(out *APIConversionRule) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new APIConversionRule. +func (in *APIConversionRule) DeepCopy() *APIConversionRule { + if in == nil { + return nil + } + out := new(APIConversionRule) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *APIConversionSpec) DeepCopyInto(out *APIConversionSpec) { + *out = *in + if in.Conversions != nil { + in, out := &in.Conversions, &out.Conversions + *out = make([]APIVersionConversion, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new APIConversionSpec. +func (in *APIConversionSpec) DeepCopy() *APIConversionSpec { + if in == nil { + return nil + } + out := new(APIConversionSpec) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *APIResourceSchema) DeepCopyInto(out *APIResourceSchema) { *out = *in out.TypeMeta = in.TypeMeta in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - out.Spec = in.Spec - out.Status = in.Status + in.Spec.DeepCopyInto(&out.Spec) return } @@ -53,6 +152,35 @@ func (in *APIResourceSchema) DeepCopyObject() runtime.Object { return nil } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *APIResourceSchemaCRDSpec) DeepCopyInto(out *APIResourceSchemaCRDSpec) { + *out = *in + in.Names.DeepCopyInto(&out.Names) + if in.Versions != nil { + in, out := &in.Versions, &out.Versions + *out = make([]APIResourceVersion, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + if in.Conversion != nil { + in, out := &in.Conversion, &out.Conversion + *out = new(CustomResourceConversion) + (*in).DeepCopyInto(*out) + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new APIResourceSchemaCRDSpec. +func (in *APIResourceSchemaCRDSpec) DeepCopy() *APIResourceSchemaCRDSpec { + if in == nil { + return nil + } + out := new(APIResourceSchemaCRDSpec) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *APIResourceSchemaList) DeepCopyInto(out *APIResourceSchemaList) { *out = *in @@ -89,6 +217,7 @@ func (in *APIResourceSchemaList) DeepCopyObject() runtime.Object { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *APIResourceSchemaSpec) DeepCopyInto(out *APIResourceSchemaSpec) { *out = *in + in.APIResourceSchemaCRDSpec.DeepCopyInto(&out.APIResourceSchemaCRDSpec) return } @@ -103,17 +232,123 @@ func (in *APIResourceSchemaSpec) DeepCopy() *APIResourceSchemaSpec { } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *APIResourceSchemaStatus) DeepCopyInto(out *APIResourceSchemaStatus) { +func (in *APIResourceVersion) DeepCopyInto(out *APIResourceVersion) { + *out = *in + if in.DeprecationWarning != nil { + in, out := &in.DeprecationWarning, &out.DeprecationWarning + *out = new(string) + **out = **in + } + in.Schema.DeepCopyInto(&out.Schema) + in.Subresources.DeepCopyInto(&out.Subresources) + if in.AdditionalPrinterColumns != nil { + in, out := &in.AdditionalPrinterColumns, &out.AdditionalPrinterColumns + *out = make([]v1.CustomResourceColumnDefinition, len(*in)) + copy(*out, *in) + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new APIResourceVersion. +func (in *APIResourceVersion) DeepCopy() *APIResourceVersion { + if in == nil { + return nil + } + out := new(APIResourceVersion) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *APIVersionConversion) DeepCopyInto(out *APIVersionConversion) { + *out = *in + if in.Rules != nil { + in, out := &in.Rules, &out.Rules + *out = make([]APIConversionRule, len(*in)) + copy(*out, *in) + } + if in.Preserve != nil { + in, out := &in.Preserve, &out.Preserve + *out = make([]string, len(*in)) + copy(*out, *in) + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new APIVersionConversion. +func (in *APIVersionConversion) DeepCopy() *APIVersionConversion { + if in == nil { + return nil + } + out := new(APIVersionConversion) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *CustomResourceConversion) DeepCopyInto(out *CustomResourceConversion) { *out = *in + if in.Webhook != nil { + in, out := &in.Webhook, &out.Webhook + *out = new(WebhookConversion) + (*in).DeepCopyInto(*out) + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CustomResourceConversion. +func (in *CustomResourceConversion) DeepCopy() *CustomResourceConversion { + if in == nil { + return nil + } + out := new(CustomResourceConversion) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *WebhookClientConfig) DeepCopyInto(out *WebhookClientConfig) { + *out = *in + if in.CABundle != nil { + in, out := &in.CABundle, &out.CABundle + *out = make([]byte, len(*in)) + copy(*out, *in) + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new WebhookClientConfig. +func (in *WebhookClientConfig) DeepCopy() *WebhookClientConfig { + if in == nil { + return nil + } + out := new(WebhookClientConfig) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *WebhookConversion) DeepCopyInto(out *WebhookConversion) { + *out = *in + if in.ClientConfig != nil { + in, out := &in.ClientConfig, &out.ClientConfig + *out = new(WebhookClientConfig) + (*in).DeepCopyInto(*out) + } + if in.ConversionReviewVersions != nil { + in, out := &in.ConversionReviewVersions, &out.ConversionReviewVersions + *out = make([]string, len(*in)) + copy(*out, *in) + } return } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new APIResourceSchemaStatus. -func (in *APIResourceSchemaStatus) DeepCopy() *APIResourceSchemaStatus { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new WebhookConversion. +func (in *WebhookConversion) DeepCopy() *WebhookConversion { if in == nil { return nil } - out := new(APIResourceSchemaStatus) + out := new(WebhookConversion) in.DeepCopyInto(out) return out } diff --git a/sdk/client/clientset/versioned/typed/kubebind/v1alpha2/apiconversion.go b/sdk/client/clientset/versioned/typed/kubebind/v1alpha2/apiconversion.go new file mode 100644 index 000000000..2b1ab71a4 --- /dev/null +++ b/sdk/client/clientset/versioned/typed/kubebind/v1alpha2/apiconversion.go @@ -0,0 +1,68 @@ +/* +Copyright The Kube Bind 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. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +package v1alpha2 + +import ( + "context" + + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + gentype "k8s.io/client-go/gentype" + + v1alpha2 "github.com/kube-bind/kube-bind/sdk/apis/kubebind/v1alpha2" + scheme "github.com/kube-bind/kube-bind/sdk/client/clientset/versioned/scheme" +) + +// APIConversionsGetter has a method to return a APIConversionInterface. +// A group's client should implement this interface. +type APIConversionsGetter interface { + APIConversions() APIConversionInterface +} + +// APIConversionInterface has methods to work with APIConversion resources. +type APIConversionInterface interface { + Create(ctx context.Context, aPIConversion *v1alpha2.APIConversion, opts v1.CreateOptions) (*v1alpha2.APIConversion, error) + Update(ctx context.Context, aPIConversion *v1alpha2.APIConversion, opts v1.UpdateOptions) (*v1alpha2.APIConversion, error) + Delete(ctx context.Context, name string, opts v1.DeleteOptions) error + DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error + Get(ctx context.Context, name string, opts v1.GetOptions) (*v1alpha2.APIConversion, error) + List(ctx context.Context, opts v1.ListOptions) (*v1alpha2.APIConversionList, error) + Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) + Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha2.APIConversion, err error) + APIConversionExpansion +} + +// aPIConversions implements APIConversionInterface +type aPIConversions struct { + *gentype.ClientWithList[*v1alpha2.APIConversion, *v1alpha2.APIConversionList] +} + +// newAPIConversions returns a APIConversions +func newAPIConversions(c *KubeBindV1alpha2Client) *aPIConversions { + return &aPIConversions{ + gentype.NewClientWithList[*v1alpha2.APIConversion, *v1alpha2.APIConversionList]( + "apiconversions", + c.RESTClient(), + scheme.ParameterCodec, + "", + func() *v1alpha2.APIConversion { return &v1alpha2.APIConversion{} }, + func() *v1alpha2.APIConversionList { return &v1alpha2.APIConversionList{} }), + } +} diff --git a/sdk/client/clientset/versioned/typed/kubebind/v1alpha2/apiresourceschema.go b/sdk/client/clientset/versioned/typed/kubebind/v1alpha2/apiresourceschema.go index 2d3ef0e55..501a6a2d4 100644 --- a/sdk/client/clientset/versioned/typed/kubebind/v1alpha2/apiresourceschema.go +++ b/sdk/client/clientset/versioned/typed/kubebind/v1alpha2/apiresourceschema.go @@ -40,8 +40,6 @@ type APIResourceSchemasGetter interface { type APIResourceSchemaInterface interface { Create(ctx context.Context, aPIResourceSchema *v1alpha2.APIResourceSchema, opts v1.CreateOptions) (*v1alpha2.APIResourceSchema, error) Update(ctx context.Context, aPIResourceSchema *v1alpha2.APIResourceSchema, opts v1.UpdateOptions) (*v1alpha2.APIResourceSchema, error) - // Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). - UpdateStatus(ctx context.Context, aPIResourceSchema *v1alpha2.APIResourceSchema, opts v1.UpdateOptions) (*v1alpha2.APIResourceSchema, error) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error Get(ctx context.Context, name string, opts v1.GetOptions) (*v1alpha2.APIResourceSchema, error) diff --git a/sdk/client/clientset/versioned/typed/kubebind/v1alpha2/fake/fake_apiconversion.go b/sdk/client/clientset/versioned/typed/kubebind/v1alpha2/fake/fake_apiconversion.go new file mode 100644 index 000000000..c607f9ac6 --- /dev/null +++ b/sdk/client/clientset/versioned/typed/kubebind/v1alpha2/fake/fake_apiconversion.go @@ -0,0 +1,127 @@ +/* +Copyright The Kube Bind 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. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +package fake + +import ( + "context" + + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + labels "k8s.io/apimachinery/pkg/labels" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + testing "k8s.io/client-go/testing" + + v1alpha2 "github.com/kube-bind/kube-bind/sdk/apis/kubebind/v1alpha2" +) + +// FakeAPIConversions implements APIConversionInterface +type FakeAPIConversions struct { + Fake *FakeKubeBindV1alpha2 +} + +var apiconversionsResource = v1alpha2.SchemeGroupVersion.WithResource("apiconversions") + +var apiconversionsKind = v1alpha2.SchemeGroupVersion.WithKind("APIConversion") + +// Get takes name of the aPIConversion, and returns the corresponding aPIConversion object, and an error if there is any. +func (c *FakeAPIConversions) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha2.APIConversion, err error) { + emptyResult := &v1alpha2.APIConversion{} + obj, err := c.Fake. + Invokes(testing.NewRootGetActionWithOptions(apiconversionsResource, name, options), emptyResult) + if obj == nil { + return emptyResult, err + } + return obj.(*v1alpha2.APIConversion), err +} + +// List takes label and field selectors, and returns the list of APIConversions that match those selectors. +func (c *FakeAPIConversions) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha2.APIConversionList, err error) { + emptyResult := &v1alpha2.APIConversionList{} + obj, err := c.Fake. + Invokes(testing.NewRootListActionWithOptions(apiconversionsResource, apiconversionsKind, opts), emptyResult) + if obj == nil { + return emptyResult, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &v1alpha2.APIConversionList{ListMeta: obj.(*v1alpha2.APIConversionList).ListMeta} + for _, item := range obj.(*v1alpha2.APIConversionList).Items { + if label.Matches(labels.Set(item.Labels)) { + list.Items = append(list.Items, item) + } + } + return list, err +} + +// Watch returns a watch.Interface that watches the requested aPIConversions. +func (c *FakeAPIConversions) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { + return c.Fake. + InvokesWatch(testing.NewRootWatchActionWithOptions(apiconversionsResource, opts)) +} + +// Create takes the representation of a aPIConversion and creates it. Returns the server's representation of the aPIConversion, and an error, if there is any. +func (c *FakeAPIConversions) Create(ctx context.Context, aPIConversion *v1alpha2.APIConversion, opts v1.CreateOptions) (result *v1alpha2.APIConversion, err error) { + emptyResult := &v1alpha2.APIConversion{} + obj, err := c.Fake. + Invokes(testing.NewRootCreateActionWithOptions(apiconversionsResource, aPIConversion, opts), emptyResult) + if obj == nil { + return emptyResult, err + } + return obj.(*v1alpha2.APIConversion), err +} + +// Update takes the representation of a aPIConversion and updates it. Returns the server's representation of the aPIConversion, and an error, if there is any. +func (c *FakeAPIConversions) Update(ctx context.Context, aPIConversion *v1alpha2.APIConversion, opts v1.UpdateOptions) (result *v1alpha2.APIConversion, err error) { + emptyResult := &v1alpha2.APIConversion{} + obj, err := c.Fake. + Invokes(testing.NewRootUpdateActionWithOptions(apiconversionsResource, aPIConversion, opts), emptyResult) + if obj == nil { + return emptyResult, err + } + return obj.(*v1alpha2.APIConversion), err +} + +// Delete takes name of the aPIConversion and deletes it. Returns an error if one occurs. +func (c *FakeAPIConversions) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { + _, err := c.Fake. + Invokes(testing.NewRootDeleteActionWithOptions(apiconversionsResource, name, opts), &v1alpha2.APIConversion{}) + return err +} + +// DeleteCollection deletes a collection of objects. +func (c *FakeAPIConversions) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { + action := testing.NewRootDeleteCollectionActionWithOptions(apiconversionsResource, opts, listOpts) + + _, err := c.Fake.Invokes(action, &v1alpha2.APIConversionList{}) + return err +} + +// Patch applies the patch and returns the patched aPIConversion. +func (c *FakeAPIConversions) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha2.APIConversion, err error) { + emptyResult := &v1alpha2.APIConversion{} + obj, err := c.Fake. + Invokes(testing.NewRootPatchSubresourceActionWithOptions(apiconversionsResource, name, pt, data, opts, subresources...), emptyResult) + if obj == nil { + return emptyResult, err + } + return obj.(*v1alpha2.APIConversion), err +} diff --git a/sdk/client/clientset/versioned/typed/kubebind/v1alpha2/fake/fake_apiresourceschema.go b/sdk/client/clientset/versioned/typed/kubebind/v1alpha2/fake/fake_apiresourceschema.go index 066f2a2c7..6ba06ccb8 100644 --- a/sdk/client/clientset/versioned/typed/kubebind/v1alpha2/fake/fake_apiresourceschema.go +++ b/sdk/client/clientset/versioned/typed/kubebind/v1alpha2/fake/fake_apiresourceschema.go @@ -106,19 +106,6 @@ func (c *FakeAPIResourceSchemas) Update(ctx context.Context, aPIResourceSchema * return obj.(*v1alpha2.APIResourceSchema), err } -// UpdateStatus was generated because the type contains a Status member. -// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). -func (c *FakeAPIResourceSchemas) UpdateStatus(ctx context.Context, aPIResourceSchema *v1alpha2.APIResourceSchema, opts v1.UpdateOptions) (result *v1alpha2.APIResourceSchema, err error) { - emptyResult := &v1alpha2.APIResourceSchema{} - obj, err := c.Fake. - Invokes(testing.NewUpdateSubresourceActionWithOptions(apiresourceschemasResource, "status", c.ns, aPIResourceSchema, opts), emptyResult) - - if obj == nil { - return emptyResult, err - } - return obj.(*v1alpha2.APIResourceSchema), err -} - // Delete takes name of the aPIResourceSchema and deletes it. Returns an error if one occurs. func (c *FakeAPIResourceSchemas) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { _, err := c.Fake. diff --git a/sdk/client/clientset/versioned/typed/kubebind/v1alpha2/fake/fake_kubebind_client.go b/sdk/client/clientset/versioned/typed/kubebind/v1alpha2/fake/fake_kubebind_client.go index 429226072..c10e367b2 100644 --- a/sdk/client/clientset/versioned/typed/kubebind/v1alpha2/fake/fake_kubebind_client.go +++ b/sdk/client/clientset/versioned/typed/kubebind/v1alpha2/fake/fake_kubebind_client.go @@ -29,6 +29,10 @@ type FakeKubeBindV1alpha2 struct { *testing.Fake } +func (c *FakeKubeBindV1alpha2) APIConversions() v1alpha2.APIConversionInterface { + return &FakeAPIConversions{c} +} + func (c *FakeKubeBindV1alpha2) APIResourceSchemas(namespace string) v1alpha2.APIResourceSchemaInterface { return &FakeAPIResourceSchemas{c, namespace} } diff --git a/sdk/client/clientset/versioned/typed/kubebind/v1alpha2/generated_expansion.go b/sdk/client/clientset/versioned/typed/kubebind/v1alpha2/generated_expansion.go index 4e3067937..a4998e4ff 100644 --- a/sdk/client/clientset/versioned/typed/kubebind/v1alpha2/generated_expansion.go +++ b/sdk/client/clientset/versioned/typed/kubebind/v1alpha2/generated_expansion.go @@ -18,4 +18,6 @@ limitations under the License. package v1alpha2 +type APIConversionExpansion interface{} + type APIResourceSchemaExpansion interface{} diff --git a/sdk/client/clientset/versioned/typed/kubebind/v1alpha2/kubebind_client.go b/sdk/client/clientset/versioned/typed/kubebind/v1alpha2/kubebind_client.go index 1f77db9cc..3287784bb 100644 --- a/sdk/client/clientset/versioned/typed/kubebind/v1alpha2/kubebind_client.go +++ b/sdk/client/clientset/versioned/typed/kubebind/v1alpha2/kubebind_client.go @@ -29,6 +29,7 @@ import ( type KubeBindV1alpha2Interface interface { RESTClient() rest.Interface + APIConversionsGetter APIResourceSchemasGetter } @@ -37,6 +38,10 @@ type KubeBindV1alpha2Client struct { restClient rest.Interface } +func (c *KubeBindV1alpha2Client) APIConversions() APIConversionInterface { + return newAPIConversions(c) +} + func (c *KubeBindV1alpha2Client) APIResourceSchemas(namespace string) APIResourceSchemaInterface { return newAPIResourceSchemas(c, namespace) } diff --git a/sdk/client/informers/externalversions/generic.go b/sdk/client/informers/externalversions/generic.go index f61e26520..b61c2dd1a 100644 --- a/sdk/client/informers/externalversions/generic.go +++ b/sdk/client/informers/externalversions/generic.go @@ -67,6 +67,8 @@ func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource return &genericInformer{resource: resource.GroupResource(), informer: f.KubeBind().V1alpha1().ClusterBindings().Informer()}, nil // Group=kube-bind.io, Version=v1alpha2 + case v1alpha2.SchemeGroupVersion.WithResource("apiconversions"): + return &genericInformer{resource: resource.GroupResource(), informer: f.KubeBind().V1alpha2().APIConversions().Informer()}, nil case v1alpha2.SchemeGroupVersion.WithResource("apiresourceschemas"): return &genericInformer{resource: resource.GroupResource(), informer: f.KubeBind().V1alpha2().APIResourceSchemas().Informer()}, nil diff --git a/sdk/client/informers/externalversions/kubebind/v1alpha2/apiconversion.go b/sdk/client/informers/externalversions/kubebind/v1alpha2/apiconversion.go new file mode 100644 index 000000000..b76d09ae9 --- /dev/null +++ b/sdk/client/informers/externalversions/kubebind/v1alpha2/apiconversion.go @@ -0,0 +1,90 @@ +/* +Copyright The Kube Bind 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. +*/ + +// Code generated by informer-gen. DO NOT EDIT. + +package v1alpha2 + +import ( + "context" + time "time" + + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + watch "k8s.io/apimachinery/pkg/watch" + cache "k8s.io/client-go/tools/cache" + + kubebindv1alpha2 "github.com/kube-bind/kube-bind/sdk/apis/kubebind/v1alpha2" + versioned "github.com/kube-bind/kube-bind/sdk/client/clientset/versioned" + internalinterfaces "github.com/kube-bind/kube-bind/sdk/client/informers/externalversions/internalinterfaces" + v1alpha2 "github.com/kube-bind/kube-bind/sdk/client/listers/kubebind/v1alpha2" +) + +// APIConversionInformer provides access to a shared informer and lister for +// APIConversions. +type APIConversionInformer interface { + Informer() cache.SharedIndexInformer + Lister() v1alpha2.APIConversionLister +} + +type aPIConversionInformer struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc +} + +// NewAPIConversionInformer constructs a new informer for APIConversion type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewAPIConversionInformer(client versioned.Interface, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return NewFilteredAPIConversionInformer(client, resyncPeriod, indexers, nil) +} + +// NewFilteredAPIConversionInformer constructs a new informer for APIConversion type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewFilteredAPIConversionInformer(client versioned.Interface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { + return cache.NewSharedIndexInformer( + &cache.ListWatch{ + ListFunc: func(options v1.ListOptions) (runtime.Object, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.KubeBindV1alpha2().APIConversions().List(context.TODO(), options) + }, + WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.KubeBindV1alpha2().APIConversions().Watch(context.TODO(), options) + }, + }, + &kubebindv1alpha2.APIConversion{}, + resyncPeriod, + indexers, + ) +} + +func (f *aPIConversionInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewFilteredAPIConversionInformer(client, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) +} + +func (f *aPIConversionInformer) Informer() cache.SharedIndexInformer { + return f.factory.InformerFor(&kubebindv1alpha2.APIConversion{}, f.defaultInformer) +} + +func (f *aPIConversionInformer) Lister() v1alpha2.APIConversionLister { + return v1alpha2.NewAPIConversionLister(f.Informer().GetIndexer()) +} diff --git a/sdk/client/informers/externalversions/kubebind/v1alpha2/interface.go b/sdk/client/informers/externalversions/kubebind/v1alpha2/interface.go index caee10c7f..3e8973598 100644 --- a/sdk/client/informers/externalversions/kubebind/v1alpha2/interface.go +++ b/sdk/client/informers/externalversions/kubebind/v1alpha2/interface.go @@ -24,6 +24,8 @@ import ( // Interface provides access to all the informers in this group version. type Interface interface { + // APIConversions returns a APIConversionInformer. + APIConversions() APIConversionInformer // APIResourceSchemas returns a APIResourceSchemaInformer. APIResourceSchemas() APIResourceSchemaInformer } @@ -39,6 +41,11 @@ func New(f internalinterfaces.SharedInformerFactory, namespace string, tweakList return &version{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} } +// APIConversions returns a APIConversionInformer. +func (v *version) APIConversions() APIConversionInformer { + return &aPIConversionInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} +} + // APIResourceSchemas returns a APIResourceSchemaInformer. func (v *version) APIResourceSchemas() APIResourceSchemaInformer { return &aPIResourceSchemaInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} diff --git a/sdk/client/listers/kubebind/v1alpha2/apiconversion.go b/sdk/client/listers/kubebind/v1alpha2/apiconversion.go new file mode 100644 index 000000000..0cd13df2f --- /dev/null +++ b/sdk/client/listers/kubebind/v1alpha2/apiconversion.go @@ -0,0 +1,49 @@ +/* +Copyright The Kube Bind 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. +*/ + +// Code generated by lister-gen. DO NOT EDIT. + +package v1alpha2 + +import ( + "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/listers" + "k8s.io/client-go/tools/cache" + + v1alpha2 "github.com/kube-bind/kube-bind/sdk/apis/kubebind/v1alpha2" +) + +// APIConversionLister helps list APIConversions. +// All objects returned here must be treated as read-only. +type APIConversionLister interface { + // List lists all APIConversions in the indexer. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*v1alpha2.APIConversion, err error) + // Get retrieves the APIConversion from the index for a given name. + // Objects returned here must be treated as read-only. + Get(name string) (*v1alpha2.APIConversion, error) + APIConversionListerExpansion +} + +// aPIConversionLister implements the APIConversionLister interface. +type aPIConversionLister struct { + listers.ResourceIndexer[*v1alpha2.APIConversion] +} + +// NewAPIConversionLister returns a new APIConversionLister. +func NewAPIConversionLister(indexer cache.Indexer) APIConversionLister { + return &aPIConversionLister{listers.New[*v1alpha2.APIConversion](indexer, v1alpha2.Resource("apiconversion"))} +} diff --git a/sdk/client/listers/kubebind/v1alpha2/expansion_generated.go b/sdk/client/listers/kubebind/v1alpha2/expansion_generated.go index f2287acf0..ebb03cb66 100644 --- a/sdk/client/listers/kubebind/v1alpha2/expansion_generated.go +++ b/sdk/client/listers/kubebind/v1alpha2/expansion_generated.go @@ -18,6 +18,10 @@ limitations under the License. package v1alpha2 +// APIConversionListerExpansion allows custom methods to be added to +// APIConversionLister. +type APIConversionListerExpansion interface{} + // APIResourceSchemaListerExpansion allows custom methods to be added to // APIResourceSchemaLister. type APIResourceSchemaListerExpansion interface{} diff --git a/sdk/kcp/clientset/versioned/cluster/typed/kubebind/v1alpha2/apiconversion.go b/sdk/kcp/clientset/versioned/cluster/typed/kubebind/v1alpha2/apiconversion.go new file mode 100644 index 000000000..3146c0cfe --- /dev/null +++ b/sdk/kcp/clientset/versioned/cluster/typed/kubebind/v1alpha2/apiconversion.go @@ -0,0 +1,72 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The Kube Bind 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. +*/ + +// Code generated by kcp code-generator. DO NOT EDIT. + +package v1alpha2 + +import ( + "context" + + kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" + "github.com/kcp-dev/logicalcluster/v3" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/watch" + + kubebindv1alpha2 "github.com/kube-bind/kube-bind/sdk/apis/kubebind/v1alpha2" + kubebindv1alpha2client "github.com/kube-bind/kube-bind/sdk/kcp/clientset/versioned/typed/kubebind/v1alpha2" +) + +// APIConversionsClusterGetter has a method to return a APIConversionClusterInterface. +// A group's cluster client should implement this interface. +type APIConversionsClusterGetter interface { + APIConversions() APIConversionClusterInterface +} + +// APIConversionClusterInterface can operate on APIConversions across all clusters, +// or scope down to one cluster and return a kubebindv1alpha2client.APIConversionInterface. +type APIConversionClusterInterface interface { + Cluster(logicalcluster.Path) kubebindv1alpha2client.APIConversionInterface + List(ctx context.Context, opts metav1.ListOptions) (*kubebindv1alpha2.APIConversionList, error) + Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) +} + +type aPIConversionsClusterInterface struct { + clientCache kcpclient.Cache[*kubebindv1alpha2client.KubeBindV1alpha2Client] +} + +// Cluster scopes the client down to a particular cluster. +func (c *aPIConversionsClusterInterface) Cluster(clusterPath logicalcluster.Path) kubebindv1alpha2client.APIConversionInterface { + if clusterPath == logicalcluster.Wildcard { + panic("A specific cluster must be provided when scoping, not the wildcard.") + } + + return c.clientCache.ClusterOrDie(clusterPath).APIConversions() +} + +// List returns the entire collection of all APIConversions across all clusters. +func (c *aPIConversionsClusterInterface) List(ctx context.Context, opts metav1.ListOptions) (*kubebindv1alpha2.APIConversionList, error) { + return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).APIConversions().List(ctx, opts) +} + +// Watch begins to watch all APIConversions across all clusters. +func (c *aPIConversionsClusterInterface) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { + return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).APIConversions().Watch(ctx, opts) +} diff --git a/sdk/kcp/clientset/versioned/cluster/typed/kubebind/v1alpha2/fake/apiconversion.go b/sdk/kcp/clientset/versioned/cluster/typed/kubebind/v1alpha2/fake/apiconversion.go new file mode 100644 index 000000000..882b9478a --- /dev/null +++ b/sdk/kcp/clientset/versioned/cluster/typed/kubebind/v1alpha2/fake/apiconversion.go @@ -0,0 +1,202 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The Kube Bind 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. +*/ + +// Code generated by kcp code-generator. DO NOT EDIT. + +package fake + +import ( + "context" + "encoding/json" + "fmt" + + "github.com/kcp-dev/logicalcluster/v3" + + kcptesting "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/labels" + "k8s.io/apimachinery/pkg/runtime/schema" + "k8s.io/apimachinery/pkg/types" + "k8s.io/apimachinery/pkg/watch" + "k8s.io/client-go/testing" + + kubebindv1alpha2 "github.com/kube-bind/kube-bind/sdk/apis/kubebind/v1alpha2" + applyconfigurationskubebindv1alpha2 "github.com/kube-bind/kube-bind/sdk/kcp/applyconfiguration/kubebind/v1alpha2" + kubebindv1alpha2client "github.com/kube-bind/kube-bind/sdk/kcp/clientset/versioned/typed/kubebind/v1alpha2" +) + +var aPIConversionsResource = schema.GroupVersionResource{Group: "kube-bind.io", Version: "v1alpha2", Resource: "apiconversions"} +var aPIConversionsKind = schema.GroupVersionKind{Group: "kube-bind.io", Version: "v1alpha2", Kind: "APIConversion"} + +type aPIConversionsClusterClient struct { + *kcptesting.Fake +} + +// Cluster scopes the client down to a particular cluster. +func (c *aPIConversionsClusterClient) Cluster(clusterPath logicalcluster.Path) kubebindv1alpha2client.APIConversionInterface { + if clusterPath == logicalcluster.Wildcard { + panic("A specific cluster must be provided when scoping, not the wildcard.") + } + + return &aPIConversionsClient{Fake: c.Fake, ClusterPath: clusterPath} +} + +// List takes label and field selectors, and returns the list of APIConversions that match those selectors across all clusters. +func (c *aPIConversionsClusterClient) List(ctx context.Context, opts metav1.ListOptions) (*kubebindv1alpha2.APIConversionList, error) { + obj, err := c.Fake.Invokes(kcptesting.NewRootListAction(aPIConversionsResource, aPIConversionsKind, logicalcluster.Wildcard, opts), &kubebindv1alpha2.APIConversionList{}) + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &kubebindv1alpha2.APIConversionList{ListMeta: obj.(*kubebindv1alpha2.APIConversionList).ListMeta} + for _, item := range obj.(*kubebindv1alpha2.APIConversionList).Items { + if label.Matches(labels.Set(item.Labels)) { + list.Items = append(list.Items, item) + } + } + return list, err +} + +// Watch returns a watch.Interface that watches the requested APIConversions across all clusters. +func (c *aPIConversionsClusterClient) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { + return c.Fake.InvokesWatch(kcptesting.NewRootWatchAction(aPIConversionsResource, logicalcluster.Wildcard, opts)) +} + +type aPIConversionsClient struct { + *kcptesting.Fake + ClusterPath logicalcluster.Path +} + +func (c *aPIConversionsClient) Create(ctx context.Context, aPIConversion *kubebindv1alpha2.APIConversion, opts metav1.CreateOptions) (*kubebindv1alpha2.APIConversion, error) { + obj, err := c.Fake.Invokes(kcptesting.NewRootCreateAction(aPIConversionsResource, c.ClusterPath, aPIConversion), &kubebindv1alpha2.APIConversion{}) + if obj == nil { + return nil, err + } + return obj.(*kubebindv1alpha2.APIConversion), err +} + +func (c *aPIConversionsClient) Update(ctx context.Context, aPIConversion *kubebindv1alpha2.APIConversion, opts metav1.UpdateOptions) (*kubebindv1alpha2.APIConversion, error) { + obj, err := c.Fake.Invokes(kcptesting.NewRootUpdateAction(aPIConversionsResource, c.ClusterPath, aPIConversion), &kubebindv1alpha2.APIConversion{}) + if obj == nil { + return nil, err + } + return obj.(*kubebindv1alpha2.APIConversion), err +} + +func (c *aPIConversionsClient) UpdateStatus(ctx context.Context, aPIConversion *kubebindv1alpha2.APIConversion, opts metav1.UpdateOptions) (*kubebindv1alpha2.APIConversion, error) { + obj, err := c.Fake.Invokes(kcptesting.NewRootUpdateSubresourceAction(aPIConversionsResource, c.ClusterPath, "status", aPIConversion), &kubebindv1alpha2.APIConversion{}) + if obj == nil { + return nil, err + } + return obj.(*kubebindv1alpha2.APIConversion), err +} + +func (c *aPIConversionsClient) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { + _, err := c.Fake.Invokes(kcptesting.NewRootDeleteActionWithOptions(aPIConversionsResource, c.ClusterPath, name, opts), &kubebindv1alpha2.APIConversion{}) + return err +} + +func (c *aPIConversionsClient) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { + action := kcptesting.NewRootDeleteCollectionAction(aPIConversionsResource, c.ClusterPath, listOpts) + + _, err := c.Fake.Invokes(action, &kubebindv1alpha2.APIConversionList{}) + return err +} + +func (c *aPIConversionsClient) Get(ctx context.Context, name string, options metav1.GetOptions) (*kubebindv1alpha2.APIConversion, error) { + obj, err := c.Fake.Invokes(kcptesting.NewRootGetAction(aPIConversionsResource, c.ClusterPath, name), &kubebindv1alpha2.APIConversion{}) + if obj == nil { + return nil, err + } + return obj.(*kubebindv1alpha2.APIConversion), err +} + +// List takes label and field selectors, and returns the list of APIConversions that match those selectors. +func (c *aPIConversionsClient) List(ctx context.Context, opts metav1.ListOptions) (*kubebindv1alpha2.APIConversionList, error) { + obj, err := c.Fake.Invokes(kcptesting.NewRootListAction(aPIConversionsResource, aPIConversionsKind, c.ClusterPath, opts), &kubebindv1alpha2.APIConversionList{}) + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &kubebindv1alpha2.APIConversionList{ListMeta: obj.(*kubebindv1alpha2.APIConversionList).ListMeta} + for _, item := range obj.(*kubebindv1alpha2.APIConversionList).Items { + if label.Matches(labels.Set(item.Labels)) { + list.Items = append(list.Items, item) + } + } + return list, err +} + +func (c *aPIConversionsClient) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { + return c.Fake.InvokesWatch(kcptesting.NewRootWatchAction(aPIConversionsResource, c.ClusterPath, opts)) +} + +func (c *aPIConversionsClient) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (*kubebindv1alpha2.APIConversion, error) { + obj, err := c.Fake.Invokes(kcptesting.NewRootPatchSubresourceAction(aPIConversionsResource, c.ClusterPath, name, pt, data, subresources...), &kubebindv1alpha2.APIConversion{}) + if obj == nil { + return nil, err + } + return obj.(*kubebindv1alpha2.APIConversion), err +} + +func (c *aPIConversionsClient) Apply(ctx context.Context, applyConfiguration *applyconfigurationskubebindv1alpha2.APIConversionApplyConfiguration, opts metav1.ApplyOptions) (*kubebindv1alpha2.APIConversion, error) { + if applyConfiguration == nil { + return nil, fmt.Errorf("applyConfiguration provided to Apply must not be nil") + } + data, err := json.Marshal(applyConfiguration) + if err != nil { + return nil, err + } + name := applyConfiguration.Name + if name == nil { + return nil, fmt.Errorf("applyConfiguration.Name must be provided to Apply") + } + obj, err := c.Fake.Invokes(kcptesting.NewRootPatchSubresourceAction(aPIConversionsResource, c.ClusterPath, *name, types.ApplyPatchType, data), &kubebindv1alpha2.APIConversion{}) + if obj == nil { + return nil, err + } + return obj.(*kubebindv1alpha2.APIConversion), err +} + +func (c *aPIConversionsClient) ApplyStatus(ctx context.Context, applyConfiguration *applyconfigurationskubebindv1alpha2.APIConversionApplyConfiguration, opts metav1.ApplyOptions) (*kubebindv1alpha2.APIConversion, error) { + if applyConfiguration == nil { + return nil, fmt.Errorf("applyConfiguration provided to Apply must not be nil") + } + data, err := json.Marshal(applyConfiguration) + if err != nil { + return nil, err + } + name := applyConfiguration.Name + if name == nil { + return nil, fmt.Errorf("applyConfiguration.Name must be provided to Apply") + } + obj, err := c.Fake.Invokes(kcptesting.NewRootPatchSubresourceAction(aPIConversionsResource, c.ClusterPath, *name, types.ApplyPatchType, data, "status"), &kubebindv1alpha2.APIConversion{}) + if obj == nil { + return nil, err + } + return obj.(*kubebindv1alpha2.APIConversion), err +} diff --git a/sdk/kcp/clientset/versioned/cluster/typed/kubebind/v1alpha2/fake/kubebind_client.go b/sdk/kcp/clientset/versioned/cluster/typed/kubebind/v1alpha2/fake/kubebind_client.go index 3131126b7..821bd0eda 100644 --- a/sdk/kcp/clientset/versioned/cluster/typed/kubebind/v1alpha2/fake/kubebind_client.go +++ b/sdk/kcp/clientset/versioned/cluster/typed/kubebind/v1alpha2/fake/kubebind_client.go @@ -48,6 +48,10 @@ func (c *KubeBindV1alpha2ClusterClient) APIResourceSchemas() kcpkubebindv1alpha2 return &aPIResourceSchemasClusterClient{Fake: c.Fake} } +func (c *KubeBindV1alpha2ClusterClient) APIConversions() kcpkubebindv1alpha2.APIConversionClusterInterface { + return &aPIConversionsClusterClient{Fake: c.Fake} +} + var _ kubebindv1alpha2.KubeBindV1alpha2Interface = (*KubeBindV1alpha2Client)(nil) type KubeBindV1alpha2Client struct { @@ -63,3 +67,7 @@ func (c *KubeBindV1alpha2Client) RESTClient() rest.Interface { func (c *KubeBindV1alpha2Client) APIResourceSchemas(namespace string) kubebindv1alpha2.APIResourceSchemaInterface { return &aPIResourceSchemasClient{Fake: c.Fake, ClusterPath: c.ClusterPath, Namespace: namespace} } + +func (c *KubeBindV1alpha2Client) APIConversions() kubebindv1alpha2.APIConversionInterface { + return &aPIConversionsClient{Fake: c.Fake, ClusterPath: c.ClusterPath} +} diff --git a/sdk/kcp/clientset/versioned/cluster/typed/kubebind/v1alpha2/kubebind_client.go b/sdk/kcp/clientset/versioned/cluster/typed/kubebind/v1alpha2/kubebind_client.go index 82300fa55..75cd181d7 100644 --- a/sdk/kcp/clientset/versioned/cluster/typed/kubebind/v1alpha2/kubebind_client.go +++ b/sdk/kcp/clientset/versioned/cluster/typed/kubebind/v1alpha2/kubebind_client.go @@ -35,6 +35,7 @@ import ( type KubeBindV1alpha2ClusterInterface interface { KubeBindV1alpha2ClusterScoper APIResourceSchemasClusterGetter + APIConversionsClusterGetter } type KubeBindV1alpha2ClusterScoper interface { @@ -56,6 +57,10 @@ func (c *KubeBindV1alpha2ClusterClient) APIResourceSchemas() APIResourceSchemaCl return &aPIResourceSchemasClusterInterface{clientCache: c.clientCache} } +func (c *KubeBindV1alpha2ClusterClient) APIConversions() APIConversionClusterInterface { + return &aPIConversionsClusterInterface{clientCache: c.clientCache} +} + // NewForConfig creates a new KubeBindV1alpha2ClusterClient for the given config. // NewForConfig is equivalent to NewForConfigAndClient(c, httpClient), // where httpClient was generated with rest.HTTPClientFor(c). diff --git a/sdk/kcp/informers/externalversions/generic.go b/sdk/kcp/informers/externalversions/generic.go index 2c960fdce..72a7c0ee4 100644 --- a/sdk/kcp/informers/externalversions/generic.go +++ b/sdk/kcp/informers/externalversions/generic.go @@ -101,6 +101,8 @@ func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource // Group=kube-bind.io, Version=V1alpha2 case kubebindv1alpha2.SchemeGroupVersion.WithResource("apiresourceschemas"): return &genericClusterInformer{resource: resource.GroupResource(), informer: f.KubeBind().V1alpha2().APIResourceSchemas().Informer()}, nil + case kubebindv1alpha2.SchemeGroupVersion.WithResource("apiconversions"): + return &genericClusterInformer{resource: resource.GroupResource(), informer: f.KubeBind().V1alpha2().APIConversions().Informer()}, nil } return nil, fmt.Errorf("no informer found for %v", resource) @@ -130,6 +132,9 @@ func (f *sharedScopedInformerFactory) ForResource(resource schema.GroupVersionRe case kubebindv1alpha2.SchemeGroupVersion.WithResource("apiresourceschemas"): informer := f.KubeBind().V1alpha2().APIResourceSchemas().Informer() return &genericInformer{lister: cache.NewGenericLister(informer.GetIndexer(), resource.GroupResource()), informer: informer}, nil + case kubebindv1alpha2.SchemeGroupVersion.WithResource("apiconversions"): + informer := f.KubeBind().V1alpha2().APIConversions().Informer() + return &genericInformer{lister: cache.NewGenericLister(informer.GetIndexer(), resource.GroupResource()), informer: informer}, nil } return nil, fmt.Errorf("no informer found for %v", resource) diff --git a/sdk/kcp/informers/externalversions/kubebind/v1alpha2/apiconversion.go b/sdk/kcp/informers/externalversions/kubebind/v1alpha2/apiconversion.go new file mode 100644 index 000000000..7a0a3fbb9 --- /dev/null +++ b/sdk/kcp/informers/externalversions/kubebind/v1alpha2/apiconversion.go @@ -0,0 +1,179 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The Kube Bind 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. +*/ + +// Code generated by kcp code-generator. DO NOT EDIT. + +package v1alpha2 + +import ( + "context" + "time" + + kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" + kcpinformers "github.com/kcp-dev/apimachinery/v2/third_party/informers" + "github.com/kcp-dev/logicalcluster/v3" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/watch" + "k8s.io/client-go/tools/cache" + + kubebindv1alpha2 "github.com/kube-bind/kube-bind/sdk/apis/kubebind/v1alpha2" + scopedclientset "github.com/kube-bind/kube-bind/sdk/kcp/clientset/versioned" + clientset "github.com/kube-bind/kube-bind/sdk/kcp/clientset/versioned/cluster" + "github.com/kube-bind/kube-bind/sdk/kcp/informers/externalversions/internalinterfaces" + kubebindv1alpha2listers "github.com/kube-bind/kube-bind/sdk/kcp/listers/kubebind/v1alpha2" +) + +// APIConversionClusterInformer provides access to a shared informer and lister for +// APIConversions. +type APIConversionClusterInformer interface { + Cluster(logicalcluster.Name) APIConversionInformer + Informer() kcpcache.ScopeableSharedIndexInformer + Lister() kubebindv1alpha2listers.APIConversionClusterLister +} + +type aPIConversionClusterInformer struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc +} + +// NewAPIConversionClusterInformer constructs a new informer for APIConversion type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewAPIConversionClusterInformer(client clientset.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers) kcpcache.ScopeableSharedIndexInformer { + return NewFilteredAPIConversionClusterInformer(client, resyncPeriod, indexers, nil) +} + +// NewFilteredAPIConversionClusterInformer constructs a new informer for APIConversion type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewFilteredAPIConversionClusterInformer(client clientset.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) kcpcache.ScopeableSharedIndexInformer { + return kcpinformers.NewSharedIndexInformer( + &cache.ListWatch{ + ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.KubeBindV1alpha2().APIConversions().List(context.TODO(), options) + }, + WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.KubeBindV1alpha2().APIConversions().Watch(context.TODO(), options) + }, + }, + &kubebindv1alpha2.APIConversion{}, + resyncPeriod, + indexers, + ) +} + +func (f *aPIConversionClusterInformer) defaultInformer(client clientset.ClusterInterface, resyncPeriod time.Duration) kcpcache.ScopeableSharedIndexInformer { + return NewFilteredAPIConversionClusterInformer(client, resyncPeriod, cache.Indexers{ + kcpcache.ClusterIndexName: kcpcache.ClusterIndexFunc, + }, + f.tweakListOptions, + ) +} + +func (f *aPIConversionClusterInformer) Informer() kcpcache.ScopeableSharedIndexInformer { + return f.factory.InformerFor(&kubebindv1alpha2.APIConversion{}, f.defaultInformer) +} + +func (f *aPIConversionClusterInformer) Lister() kubebindv1alpha2listers.APIConversionClusterLister { + return kubebindv1alpha2listers.NewAPIConversionClusterLister(f.Informer().GetIndexer()) +} + +// APIConversionInformer provides access to a shared informer and lister for +// APIConversions. +type APIConversionInformer interface { + Informer() cache.SharedIndexInformer + Lister() kubebindv1alpha2listers.APIConversionLister +} + +func (f *aPIConversionClusterInformer) Cluster(clusterName logicalcluster.Name) APIConversionInformer { + return &aPIConversionInformer{ + informer: f.Informer().Cluster(clusterName), + lister: f.Lister().Cluster(clusterName), + } +} + +type aPIConversionInformer struct { + informer cache.SharedIndexInformer + lister kubebindv1alpha2listers.APIConversionLister +} + +func (f *aPIConversionInformer) Informer() cache.SharedIndexInformer { + return f.informer +} + +func (f *aPIConversionInformer) Lister() kubebindv1alpha2listers.APIConversionLister { + return f.lister +} + +type aPIConversionScopedInformer struct { + factory internalinterfaces.SharedScopedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc +} + +func (f *aPIConversionScopedInformer) Informer() cache.SharedIndexInformer { + return f.factory.InformerFor(&kubebindv1alpha2.APIConversion{}, f.defaultInformer) +} + +func (f *aPIConversionScopedInformer) Lister() kubebindv1alpha2listers.APIConversionLister { + return kubebindv1alpha2listers.NewAPIConversionLister(f.Informer().GetIndexer()) +} + +// NewAPIConversionInformer constructs a new informer for APIConversion type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewAPIConversionInformer(client scopedclientset.Interface, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return NewFilteredAPIConversionInformer(client, resyncPeriod, indexers, nil) +} + +// NewFilteredAPIConversionInformer constructs a new informer for APIConversion type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewFilteredAPIConversionInformer(client scopedclientset.Interface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { + return cache.NewSharedIndexInformer( + &cache.ListWatch{ + ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.KubeBindV1alpha2().APIConversions().List(context.TODO(), options) + }, + WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.KubeBindV1alpha2().APIConversions().Watch(context.TODO(), options) + }, + }, + &kubebindv1alpha2.APIConversion{}, + resyncPeriod, + indexers, + ) +} + +func (f *aPIConversionScopedInformer) defaultInformer(client scopedclientset.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewFilteredAPIConversionInformer(client, resyncPeriod, cache.Indexers{}, f.tweakListOptions) +} diff --git a/sdk/kcp/informers/externalversions/kubebind/v1alpha2/interface.go b/sdk/kcp/informers/externalversions/kubebind/v1alpha2/interface.go index b48ba3bb2..4c255269e 100644 --- a/sdk/kcp/informers/externalversions/kubebind/v1alpha2/interface.go +++ b/sdk/kcp/informers/externalversions/kubebind/v1alpha2/interface.go @@ -28,6 +28,8 @@ import ( type ClusterInterface interface { // APIResourceSchemas returns a APIResourceSchemaClusterInformer APIResourceSchemas() APIResourceSchemaClusterInformer + // APIConversions returns a APIConversionClusterInformer + APIConversions() APIConversionClusterInformer } type version struct { @@ -45,9 +47,16 @@ func (v *version) APIResourceSchemas() APIResourceSchemaClusterInformer { return &aPIResourceSchemaClusterInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} } +// APIConversions returns a APIConversionClusterInformer +func (v *version) APIConversions() APIConversionClusterInformer { + return &aPIConversionClusterInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} +} + type Interface interface { // APIResourceSchemas returns a APIResourceSchemaInformer APIResourceSchemas() APIResourceSchemaInformer + // APIConversions returns a APIConversionInformer + APIConversions() APIConversionInformer } type scopedVersion struct { @@ -65,3 +74,8 @@ func NewScoped(f internalinterfaces.SharedScopedInformerFactory, namespace strin func (v *scopedVersion) APIResourceSchemas() APIResourceSchemaInformer { return &aPIResourceSchemaScopedInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} } + +// APIConversions returns a APIConversionInformer +func (v *scopedVersion) APIConversions() APIConversionInformer { + return &aPIConversionScopedInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} +} diff --git a/sdk/kcp/listers/kubebind/v1alpha2/apiconversion.go b/sdk/kcp/listers/kubebind/v1alpha2/apiconversion.go new file mode 100644 index 000000000..b6738b8dd --- /dev/null +++ b/sdk/kcp/listers/kubebind/v1alpha2/apiconversion.go @@ -0,0 +1,143 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The Kube Bind 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. +*/ + +// Code generated by kcp code-generator. DO NOT EDIT. + +package v1alpha2 + +import ( + kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" + "github.com/kcp-dev/logicalcluster/v3" + + "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/tools/cache" + + kubebindv1alpha2 "github.com/kube-bind/kube-bind/sdk/apis/kubebind/v1alpha2" +) + +// APIConversionClusterLister can list APIConversions across all workspaces, or scope down to a APIConversionLister for one workspace. +// All objects returned here must be treated as read-only. +type APIConversionClusterLister interface { + // List lists all APIConversions in the indexer. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*kubebindv1alpha2.APIConversion, err error) + // Cluster returns a lister that can list and get APIConversions in one workspace. + Cluster(clusterName logicalcluster.Name) APIConversionLister + APIConversionClusterListerExpansion +} + +type aPIConversionClusterLister struct { + indexer cache.Indexer +} + +// NewAPIConversionClusterLister returns a new APIConversionClusterLister. +// We assume that the indexer: +// - is fed by a cross-workspace LIST+WATCH +// - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function +// - has the kcpcache.ClusterIndex as an index +func NewAPIConversionClusterLister(indexer cache.Indexer) *aPIConversionClusterLister { + return &aPIConversionClusterLister{indexer: indexer} +} + +// List lists all APIConversions in the indexer across all workspaces. +func (s *aPIConversionClusterLister) List(selector labels.Selector) (ret []*kubebindv1alpha2.APIConversion, err error) { + err = cache.ListAll(s.indexer, selector, func(m interface{}) { + ret = append(ret, m.(*kubebindv1alpha2.APIConversion)) + }) + return ret, err +} + +// Cluster scopes the lister to one workspace, allowing users to list and get APIConversions. +func (s *aPIConversionClusterLister) Cluster(clusterName logicalcluster.Name) APIConversionLister { + return &aPIConversionLister{indexer: s.indexer, clusterName: clusterName} +} + +// APIConversionLister can list all APIConversions, or get one in particular. +// All objects returned here must be treated as read-only. +type APIConversionLister interface { + // List lists all APIConversions in the workspace. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*kubebindv1alpha2.APIConversion, err error) + // Get retrieves the APIConversion from the indexer for a given workspace and name. + // Objects returned here must be treated as read-only. + Get(name string) (*kubebindv1alpha2.APIConversion, error) + APIConversionListerExpansion +} + +// aPIConversionLister can list all APIConversions inside a workspace. +type aPIConversionLister struct { + indexer cache.Indexer + clusterName logicalcluster.Name +} + +// List lists all APIConversions in the indexer for a workspace. +func (s *aPIConversionLister) List(selector labels.Selector) (ret []*kubebindv1alpha2.APIConversion, err error) { + err = kcpcache.ListAllByCluster(s.indexer, s.clusterName, selector, func(i interface{}) { + ret = append(ret, i.(*kubebindv1alpha2.APIConversion)) + }) + return ret, err +} + +// Get retrieves the APIConversion from the indexer for a given workspace and name. +func (s *aPIConversionLister) Get(name string) (*kubebindv1alpha2.APIConversion, error) { + key := kcpcache.ToClusterAwareKey(s.clusterName.String(), "", name) + obj, exists, err := s.indexer.GetByKey(key) + if err != nil { + return nil, err + } + if !exists { + return nil, errors.NewNotFound(kubebindv1alpha2.Resource("apiconversions"), name) + } + return obj.(*kubebindv1alpha2.APIConversion), nil +} + +// NewAPIConversionLister returns a new APIConversionLister. +// We assume that the indexer: +// - is fed by a workspace-scoped LIST+WATCH +// - uses cache.MetaNamespaceKeyFunc as the key function +func NewAPIConversionLister(indexer cache.Indexer) *aPIConversionScopedLister { + return &aPIConversionScopedLister{indexer: indexer} +} + +// aPIConversionScopedLister can list all APIConversions inside a workspace. +type aPIConversionScopedLister struct { + indexer cache.Indexer +} + +// List lists all APIConversions in the indexer for a workspace. +func (s *aPIConversionScopedLister) List(selector labels.Selector) (ret []*kubebindv1alpha2.APIConversion, err error) { + err = cache.ListAll(s.indexer, selector, func(i interface{}) { + ret = append(ret, i.(*kubebindv1alpha2.APIConversion)) + }) + return ret, err +} + +// Get retrieves the APIConversion from the indexer for a given workspace and name. +func (s *aPIConversionScopedLister) Get(name string) (*kubebindv1alpha2.APIConversion, error) { + key := name + obj, exists, err := s.indexer.GetByKey(key) + if err != nil { + return nil, err + } + if !exists { + return nil, errors.NewNotFound(kubebindv1alpha2.Resource("apiconversions"), name) + } + return obj.(*kubebindv1alpha2.APIConversion), nil +} diff --git a/sdk/kcp/listers/kubebind/v1alpha2/apiconversion_expansion.go b/sdk/kcp/listers/kubebind/v1alpha2/apiconversion_expansion.go new file mode 100644 index 000000000..9ab53f362 --- /dev/null +++ b/sdk/kcp/listers/kubebind/v1alpha2/apiconversion_expansion.go @@ -0,0 +1,28 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The Kube Bind 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. +*/ + +// Code generated by kcp code-generator. DO NOT EDIT. + +package v1alpha2 + +// APIConversionClusterListerExpansion allows custom methods to be added to APIConversionClusterLister. +type APIConversionClusterListerExpansion interface{} + +// APIConversionListerExpansion allows custom methods to be added to APIConversionLister. +type APIConversionListerExpansion interface{} From ce37ca51dc9850609fb236bfc314b682d5ba8030 Mon Sep 17 00:00:00 2001 From: Karol Szwaj Date: Tue, 15 Apr 2025 16:47:13 +0200 Subject: [PATCH 3/8] make imports Signed-off-by: Karol Szwaj On-behalf-of: @SAP karol.szwaj@sap.com --- cli/cmd/crd2apiresourceschema/cmd/crd2apiresourceschema.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cli/cmd/crd2apiresourceschema/cmd/crd2apiresourceschema.go b/cli/cmd/crd2apiresourceschema/cmd/crd2apiresourceschema.go index 9870f7251..37d494f07 100644 --- a/cli/cmd/crd2apiresourceschema/cmd/crd2apiresourceschema.go +++ b/cli/cmd/crd2apiresourceschema/cmd/crd2apiresourceschema.go @@ -23,10 +23,11 @@ import ( "github.com/spf13/cobra" - crd2apiresourceschemacmd "github.com/kube-bind/kube-bind/cli/pkg/crd2apiresourceschema/cmd" "k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/component-base/version" "k8s.io/klog/v2" + + crd2apiresourceschemacmd "github.com/kube-bind/kube-bind/cli/pkg/crd2apiresourceschema/cmd" ) func CRD2APIResourceSchemaCmd() *cobra.Command { From 32415be8addbbff1ba19f54c143d74f9cc802a4a Mon Sep 17 00:00:00 2001 From: Karol Szwaj Date: Tue, 22 Apr 2025 15:33:07 +0200 Subject: [PATCH 4/8] update crd2apiresourceschema CLI Signed-off-by: Karol Szwaj On-behalf-of: @SAP karol.szwaj@sap.com --- cli/pkg/crd2apiresourceschema/cmd/cmd.go | 14 +- .../plugin/crd2apiresourceschema.go | 148 ++++++++++++- .../crd/kube-bind.io_apiresourceschemas.yaml | 31 +-- .../v1alpha2/apiresourceschema_types.go | 122 +---------- sdk/apis/kubebind/v1alpha2/doc.go | 2 +- .../v1alpha2/zz_generated.deepcopy.go | 130 +---------- .../typed/kubebind/v1alpha2/apiconversion.go | 68 ------ .../kubebind/v1alpha2/apiresourceschema.go | 6 +- .../v1alpha2/fake/fake_apiconversion.go | 127 ----------- .../v1alpha2/fake/fake_apiresourceschema.go | 24 +-- .../v1alpha2/fake/fake_kubebind_client.go | 8 +- .../kubebind/v1alpha2/generated_expansion.go | 2 - .../kubebind/v1alpha2/kubebind_client.go | 9 +- .../informers/externalversions/generic.go | 2 - .../kubebind/v1alpha2/apiconversion.go | 90 -------- .../kubebind/v1alpha2/apiresourceschema.go | 13 +- .../kubebind/v1alpha2/interface.go | 9 +- .../kubebind/v1alpha2/apiconversion.go | 49 ----- .../kubebind/v1alpha2/apiresourceschema.go | 28 +-- .../kubebind/v1alpha2/expansion_generated.go | 8 - .../typed/kubebind/v1alpha2/apiconversion.go | 72 ------- .../kubebind/v1alpha2/apiresourceschema.go | 26 +-- .../kubebind/v1alpha2/fake/apiconversion.go | 202 ------------------ .../v1alpha2/fake/apiresourceschema.go | 41 ++-- .../kubebind/v1alpha2/fake/kubebind_client.go | 12 +- .../kubebind/v1alpha2/kubebind_client.go | 5 - sdk/kcp/informers/externalversions/generic.go | 5 - .../kubebind/v1alpha2/apiconversion.go | 179 ---------------- .../kubebind/v1alpha2/apiresourceschema.go | 19 +- .../kubebind/v1alpha2/interface.go | 16 +- .../kubebind/v1alpha2/apiconversion.go | 143 ------------- .../kubebind/v1alpha2/apiresourceschema.go | 77 ++----- 32 files changed, 240 insertions(+), 1447 deletions(-) delete mode 100644 sdk/client/clientset/versioned/typed/kubebind/v1alpha2/apiconversion.go delete mode 100644 sdk/client/clientset/versioned/typed/kubebind/v1alpha2/fake/fake_apiconversion.go delete mode 100644 sdk/client/informers/externalversions/kubebind/v1alpha2/apiconversion.go delete mode 100644 sdk/client/listers/kubebind/v1alpha2/apiconversion.go delete mode 100644 sdk/kcp/clientset/versioned/cluster/typed/kubebind/v1alpha2/apiconversion.go delete mode 100644 sdk/kcp/clientset/versioned/cluster/typed/kubebind/v1alpha2/fake/apiconversion.go delete mode 100644 sdk/kcp/informers/externalversions/kubebind/v1alpha2/apiconversion.go delete mode 100644 sdk/kcp/listers/kubebind/v1alpha2/apiconversion.go diff --git a/cli/pkg/crd2apiresourceschema/cmd/cmd.go b/cli/pkg/crd2apiresourceschema/cmd/cmd.go index acad31265..77e5fdb26 100644 --- a/cli/pkg/crd2apiresourceschema/cmd/cmd.go +++ b/cli/pkg/crd2apiresourceschema/cmd/cmd.go @@ -17,8 +17,6 @@ limitations under the License. package cmd import ( - "fmt" - "github.com/spf13/cobra" "k8s.io/cli-runtime/pkg/genericclioptions" @@ -30,15 +28,21 @@ import ( ) var ( - CRD2APIResourceSchemaUses = `` + CRD2APIResourceSchemaUses = ` +# Generate and create APIResourceSchema objects for all CRDs in the cluster +crd2apiresourceschema --kubeconfig ~/.kube/config + +# Generate and create APIResourceSchema objects for all CRDs in the cluster, specifying a different kubeconfig +crd2apiresourceschema --kubeconfig /path/to/your/kubeconfig +` ) func New(streams genericclioptions.IOStreams) (*cobra.Command, error) { opts := plugin.NewCRD2APIResourceSchemaOptions(streams) cmd := &cobra.Command{ Use: "crd2apiresourceschema", - Short: "Create APIResourceSchema from provided CRD in the cluster.", - Example: fmt.Sprintf(CRD2APIResourceSchemaUses, "crd2apiresourceschema"), + Short: "Create APIResourceSchema from provided CRDs in the cluster.", + Example: CRD2APIResourceSchemaUses, SilenceUsage: true, RunE: func(cmd *cobra.Command, args []string) error { if err := logsv1.ValidateAndApply(opts.Logs, nil); err != nil { diff --git a/cli/pkg/crd2apiresourceschema/plugin/crd2apiresourceschema.go b/cli/pkg/crd2apiresourceschema/plugin/crd2apiresourceschema.go index 0bbb2e319..f554e166c 100644 --- a/cli/pkg/crd2apiresourceschema/plugin/crd2apiresourceschema.go +++ b/cli/pkg/crd2apiresourceschema/plugin/crd2apiresourceschema.go @@ -18,40 +18,44 @@ package plugin import ( "context" + "encoding/json" + "fmt" "github.com/spf13/cobra" + apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" + "k8s.io/apimachinery/pkg/runtime" "k8s.io/cli-runtime/pkg/genericclioptions" + "k8s.io/client-go/dynamic" "k8s.io/component-base/logs" logsv1 "k8s.io/component-base/logs/api/v1" "github.com/kube-bind/kube-bind/cli/pkg/kubectl/base" + kubebindv1alpha2 "github.com/kube-bind/kube-bind/sdk/apis/kubebind/v1alpha2" ) -// CRD2APIResourceSchemaOptions are the options for the kubectl-bind-apiservice command. type CRD2APIResourceSchemaOptions struct { Options *base.Options Logs *logs.Options Print *genericclioptions.PrintFlags } -// NewCRD2APIResourceSchemaOptions returns new BindAPIServiceOptions. func NewCRD2APIResourceSchemaOptions(streams genericclioptions.IOStreams) *CRD2APIResourceSchemaOptions { return &CRD2APIResourceSchemaOptions{ Options: base.NewOptions(streams), Logs: logs.NewOptions(), - Print: genericclioptions.NewPrintFlags("kubectl-bind-apiservice"), + Print: genericclioptions.NewPrintFlags("crd2apiresourceschema"), } } -// AddCmdFlags binds fields to cmd's flagset. func (b *CRD2APIResourceSchemaOptions) AddCmdFlags(cmd *cobra.Command) { b.Options.BindFlags(cmd) logsv1.AddFlags(b.Logs, cmd.Flags()) b.Print.AddFlags(cmd) } -// Complete ensures all fields are initialized. func (b *CRD2APIResourceSchemaOptions) Complete(args []string) error { if err := b.Options.Complete(); err != nil { return err @@ -60,8 +64,140 @@ func (b *CRD2APIResourceSchemaOptions) Complete(args []string) error { return nil } -// Run starts the binding process. +// Run starts the process of converting CRDs to APIResourceSchema objects. func (b *CRD2APIResourceSchemaOptions) Run(ctx context.Context) error { + config, err := b.Options.ClientConfig.ClientConfig() + if err != nil { + return err + } + client, err := dynamic.NewForConfig(config) + if err != nil { + return fmt.Errorf("failed to create dynamic client: %w", err) + } + + apiResourceSchemaGVR := kubebindv1alpha2.SchemeGroupVersion.WithResource("apiresourceschemas") + crdGVR := apiextensionsv1.SchemeGroupVersion.WithResource("customresourcedefinitions") + crdList, err := client.Resource(crdGVR).List(ctx, metav1.ListOptions{}) + if err != nil { + return fmt.Errorf("failed to list CRDs: %w", err) + } + + for _, crd := range crdList.Items { + crdObj := &apiextensionsv1.CustomResourceDefinition{} + if err := runtime.DefaultUnstructuredConverter.FromUnstructured(crd.UnstructuredContent(), crdObj); err != nil { + return fmt.Errorf("failed to convert CRD: %w", err) + } + + if crdObj.Spec.Group == "kube-bind.io" { + fmt.Fprintf(b.Options.ErrOut, "Skipping CRD %s: belongs to group kube-bind.io\n", crdObj.Name) + continue + } + + apiResourceSchema, err := convertCRDToAPIResourceSchema(crdObj, "apiresourceschema") + if err != nil { + fmt.Fprintf(b.Options.ErrOut, "Failed to convert CRD %s to APIResourceSchema: %v\n", crdObj.Name, err) + } + + if apiResourceSchema == nil { + fmt.Fprintf(b.Options.ErrOut, "Skipping CRD %s: no schema found\n", crdObj.Name) + continue + } + + unstructuredObj, err := runtime.DefaultUnstructuredConverter.ToUnstructured(apiResourceSchema) + if err != nil { + return fmt.Errorf("failed to convert APIResourceSchema to unstructured: %w", err) + } + unstructuredResource := &unstructured.Unstructured{Object: unstructuredObj} + + _, err = client.Resource(apiResourceSchemaGVR).Create(ctx, unstructuredResource, metav1.CreateOptions{}) + if err != nil { + fmt.Fprintf(b.Options.ErrOut, "Failed to create APIResourceSchema for CRD %s: %v\n", crdObj.Name, err) + continue + } + + fmt.Fprintf(b.Options.Out, "Successfully created APIResourceSchema for CRD %s\n", crdObj.Name) + } return nil } + +func convertCRDToAPIResourceSchema(crd *apiextensionsv1.CustomResourceDefinition, prefix string) (*kubebindv1alpha2.APIResourceSchema, error) { + name := prefix + "." + crd.Name + + informerScope := kubebindv1alpha2.ClusterScope + if crd.Spec.Scope == apiextensionsv1.NamespaceScoped { + informerScope = kubebindv1alpha2.NamespacedScope + } + + apiResourceSchema := &kubebindv1alpha2.APIResourceSchema{ + TypeMeta: metav1.TypeMeta{ + APIVersion: kubebindv1alpha2.SchemeGroupVersion.String(), + Kind: "APIResourceSchema", + }, + ObjectMeta: metav1.ObjectMeta{ + Name: name, + }, + Spec: kubebindv1alpha2.APIResourceSchemaSpec{ + InformerScope: informerScope, + APIResourceSchemaCRDSpec: kubebindv1alpha2.APIResourceSchemaCRDSpec{ + Group: crd.Spec.Group, + Names: crd.Spec.Names, + Scope: crd.Spec.Scope, + }, + }, + } + + if len(crd.Spec.Versions) > 1 && crd.Spec.Conversion == nil { + return nil, fmt.Errorf("multiple versions specified but no conversion strategy") + } + + if crd.Spec.Conversion != nil { + crConversion := &kubebindv1alpha2.CustomResourceConversion{ + Strategy: kubebindv1alpha2.ConversionStrategyType(crd.Spec.Conversion.Strategy), + } + + if crd.Spec.Conversion.Strategy == "Webhook" { + crConversion.Webhook = &kubebindv1alpha2.WebhookConversion{ + ConversionReviewVersions: crd.Spec.Conversion.Webhook.ConversionReviewVersions, + } + + if crd.Spec.Conversion.Webhook.ClientConfig != nil { + crConversion.Webhook.ClientConfig = &kubebindv1alpha2.WebhookClientConfig{ + URL: crd.Spec.Conversion.Webhook.ClientConfig.URL, + CABundle: crd.Spec.Conversion.Webhook.ClientConfig.CABundle, + } + } + } + + apiResourceSchema.Spec.Conversion = crConversion + } + + for i := range crd.Spec.Versions { + crdVersion := crd.Spec.Versions[i] + + apiResourceVersion := kubebindv1alpha2.APIResourceVersion{ + Name: crdVersion.Name, + Served: crdVersion.Served, + Storage: crdVersion.Storage, + Deprecated: crdVersion.Deprecated, + DeprecationWarning: crdVersion.DeprecationWarning, + AdditionalPrinterColumns: crdVersion.AdditionalPrinterColumns, + } + + if crdVersion.Schema != nil && crdVersion.Schema.OpenAPIV3Schema != nil { + rawSchema, err := json.Marshal(crdVersion.Schema.OpenAPIV3Schema) + if err != nil { + return nil, fmt.Errorf("error converting schema for version %q: %w", crdVersion.Name, err) + } + apiResourceVersion.Schema = runtime.RawExtension{Raw: rawSchema} + } + + if crdVersion.Subresources != nil { + apiResourceVersion.Subresources = *crdVersion.Subresources + } + + apiResourceSchema.Spec.Versions = append(apiResourceSchema.Spec.Versions, apiResourceVersion) + } + + return apiResourceSchema, nil +} diff --git a/deploy/crd/kube-bind.io_apiresourceschemas.yaml b/deploy/crd/kube-bind.io_apiresourceschemas.yaml index ce56f2d8a..53760a054 100644 --- a/deploy/crd/kube-bind.io_apiresourceschemas.yaml +++ b/deploy/crd/kube-bind.io_apiresourceschemas.yaml @@ -8,13 +8,19 @@ metadata: spec: group: kube-bind.io names: + categories: + - kcp kind: APIResourceSchema listKind: APIResourceSchemaList plural: apiresourceschemas singular: apiresourceschema - scope: Namespaced + scope: Cluster versions: - - name: v1alpha2 + - additionalPrinterColumns: + - jsonPath: .metadata.creationTimestamp + name: Age + type: date + name: v1alpha2 schema: openAPIV3Schema: description: APIResourceSchema @@ -86,8 +92,6 @@ spec: Attempting to use a user or basic auth e.g. "user:password@" is not allowed. Fragments ("#...") and query parameters ("?...") are not allowed, either. - - Note: kcp does not support provided service names like Kubernetes does. format: uri type: string type: object @@ -123,25 +127,9 @@ spec: - Cluster - Namespaced description: |- - InformerScope indicates whether the defined custom resource is cluster- or namespace-scoped. + InformerScope indicates whether the informer for defined custom resource is cluster- or namespace-scoped. Allowed values are `Cluster` and `Namespaced`. type: string - nameValidation: - default: DNS1123Subdomain - description: |- - nameValidation can be used to configure name validation for bound APIs. - Allowed values are `DNS1123Subdomain` and `PathSegmentName`. - - DNS1123Subdomain: a lowercase RFC 1123 subdomain must consist of lower case - alphanumeric characters, '-' or '.', and must start and end with an alphanumeric character. - Regex used is '[a-z0-9]([-a-z0-9]*[a-z0-9])?(\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*' - - PathSegmentName: validates the name can be safely encoded as a path segment. - The name may not be '.' or '..' and the name may not contain '/' or '%'. - - Defaults to `DNS1123Subdomain`, matching the behaviour of CRDs. - enum: - - DNS1123Subdomain - - PathSegmentName - type: string names: description: names specify the resource and kind names for the custom resource. @@ -359,3 +347,4 @@ spec: type: object served: true storage: true + subresources: {} diff --git a/sdk/apis/kubebind/v1alpha2/apiresourceschema_types.go b/sdk/apis/kubebind/v1alpha2/apiresourceschema_types.go index fba7c16c8..f202cea1e 100644 --- a/sdk/apis/kubebind/v1alpha2/apiresourceschema_types.go +++ b/sdk/apis/kubebind/v1alpha2/apiresourceschema_types.go @@ -37,7 +37,10 @@ const ( // APIResourceSchema // +crd // +genclient +// +genclient:nonNamespaced // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object +// +kubebuilder:resource:scope=Cluster,categories=kcp +// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp" type APIResourceSchema struct { metav1.TypeMeta `json:",inline"` metav1.ObjectMeta `json:"metadata,omitempty"` @@ -85,21 +88,6 @@ type APIResourceSchemaCRDSpec struct { // +kubebuilder:validation:MinItems=1 Versions []APIResourceVersion `json:"versions"` - // nameValidation can be used to configure name validation for bound APIs. - // Allowed values are `DNS1123Subdomain` and `PathSegmentName`. - // - DNS1123Subdomain: a lowercase RFC 1123 subdomain must consist of lower case - // alphanumeric characters, '-' or '.', and must start and end with an alphanumeric character. - // Regex used is '[a-z0-9]([-a-z0-9]*[a-z0-9])?(\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*' - // - PathSegmentName: validates the name can be safely encoded as a path segment. - // The name may not be '.' or '..' and the name may not contain '/' or '%'. - // - // Defaults to `DNS1123Subdomain`, matching the behaviour of CRDs. - // - // +optional - // +kubebuilder:validation:Enum=DNS1123Subdomain;PathSegmentName - // +kubebuilder:default=DNS1123Subdomain - NameValidation string `json:"nameValidation,omitempty"` - // conversion defines conversion settings for the defined custom resource. // +optional Conversion *CustomResourceConversion `json:"conversion,omitempty"` @@ -215,9 +203,8 @@ type WebhookClientConfig struct { // allowed. Fragments ("#...") and query parameters ("?...") are not // allowed, either. // - // Note: kcp does not support provided service names like Kubernetes does. // +kubebuilder:validation:Format=uri - URL string `json:"url,omitempty"` + URL *string `json:"url,omitempty"` // caBundle is a PEM encoded CA bundle which will be used to validate the webhook's server certificate. // If unspecified, system trust roots on the apiserver are used. @@ -258,104 +245,3 @@ func (v *APIResourceVersion) SetSchema(schema *apiextensionsv1.JSONSchemaProps) v.Schema.Raw = raw return nil } - -const ( - // VersionPreservationAnnotationKeyPrefix is the prefix for the annotation key used to preserve fields from an API - // version that would otherwise be lost during round-tripping to a different API version. An example key and value - // might look like this: preserve.conversion.apis.kcp.io/v2: {"spec.someNewField": "someValue"}. - VersionPreservationAnnotationKeyPrefix = "preserve.conversion.apis.kcp.io/" -) - -// +crd -// +genclient -// +genclient:nonNamespaced -// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object -// +kubebuilder:resource:scope=Cluster,categories=kcp -// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp" - -// APIConversion contains rules to convert between different API versions in an APIResourceSchema. The name must match -// the name of the APIResourceSchema for the conversions to take effect. -type APIConversion struct { - metav1.TypeMeta `json:",inline"` - metav1.ObjectMeta `json:"metadata"` - - // Spec holds the desired state. - Spec APIConversionSpec `json:"spec"` -} - -// APIConversionSpec contains rules to convert between different API versions in an APIResourceSchema. -type APIConversionSpec struct { - // conversions specify rules to convert between different API versions in an APIResourceSchema. - // - // +required - // +listType=map - // +listMapKey=from - // +listMapKey=to - Conversions []APIVersionConversion `json:"conversions"` -} - -// APIVersionConversion contains rules to convert between two specific API versions in an -// APIResourceSchema. Additionally, to avoid data loss when round-tripping from a version that -// contains a new field to one that doesn't and back again, you can specify a list of fields to -// preserve (these are stored in annotations). -type APIVersionConversion struct { - // from is the source version. - // - // +required - // +kubebuilder:validation:MinLength=1 - // +kubebuilder:validation:Pattern=^v[1-9][0-9]*([a-z]+[1-9][0-9]*)?$ - From string `json:"from"` - - // to is the target version. - // - // +required - // +kubebuilder:validation:MinLength=1 - // +kubebuilder:validation:Pattern=^v[1-9][0-9]*([a-z]+[1-9][0-9]*)?$ - To string `json:"to"` - - // rules contains field-specific conversion expressions. - // - // +required - // +listType=map - // +listMapKey=destination - Rules []APIConversionRule `json:"rules"` - - // preserve contains a list of JSONPath expressions to fields to preserve in the originating version - // of the object, relative to its root, such as '.spec.name.first'. - // - // +optional - Preserve []string `json:"preserve,omitempty"` -} - -// APIConversionRule specifies how to convert a single field. -type APIConversionRule struct { - // field is a JSONPath expression to the field in the originating version of the object, relative to its root, such - // as '.spec.name.first'. - // - // +required - // +kubebuilder:validation:MinLength=1 - Field string `json:"field"` - - // destination is a JSONPath expression to the field in the target version of the object, relative to - // its root, such as '.spec.name.first'. - // - // +required - // +kubebuilder:validation:MinLength=1 - Destination string `json:"destination"` - - // transformation is an optional CEL expression used to execute user-specified rules to transform the - // originating field -- identified by 'self' -- to the destination field. - // - // +optional - Transformation string `json:"transformation,omitempty"` -} - -// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object - -// APIConversionList is a list of APIConversion resources. -type APIConversionList struct { - metav1.TypeMeta `json:",inline"` - metav1.ListMeta `json:"metadata"` - - Items []APIConversion `json:"items"` -} diff --git a/sdk/apis/kubebind/v1alpha2/doc.go b/sdk/apis/kubebind/v1alpha2/doc.go index 1bb359de3..35aca2a27 100644 --- a/sdk/apis/kubebind/v1alpha2/doc.go +++ b/sdk/apis/kubebind/v1alpha2/doc.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Package v1alpha2 defines the v1alpha1 version of the Kube Bind API +// Package v1alpha2 defines the v1alpha2 version of the Kube Bind API // // +groupName=kube-bind.io // +groupGoName=KubeBind diff --git a/sdk/apis/kubebind/v1alpha2/zz_generated.deepcopy.go b/sdk/apis/kubebind/v1alpha2/zz_generated.deepcopy.go index 92db79220..0fa206039 100644 --- a/sdk/apis/kubebind/v1alpha2/zz_generated.deepcopy.go +++ b/sdk/apis/kubebind/v1alpha2/zz_generated.deepcopy.go @@ -26,105 +26,6 @@ import ( runtime "k8s.io/apimachinery/pkg/runtime" ) -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *APIConversion) DeepCopyInto(out *APIConversion) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - in.Spec.DeepCopyInto(&out.Spec) - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new APIConversion. -func (in *APIConversion) DeepCopy() *APIConversion { - if in == nil { - return nil - } - out := new(APIConversion) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *APIConversion) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *APIConversionList) DeepCopyInto(out *APIConversionList) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ListMeta.DeepCopyInto(&out.ListMeta) - if in.Items != nil { - in, out := &in.Items, &out.Items - *out = make([]APIConversion, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new APIConversionList. -func (in *APIConversionList) DeepCopy() *APIConversionList { - if in == nil { - return nil - } - out := new(APIConversionList) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *APIConversionList) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *APIConversionRule) DeepCopyInto(out *APIConversionRule) { - *out = *in - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new APIConversionRule. -func (in *APIConversionRule) DeepCopy() *APIConversionRule { - if in == nil { - return nil - } - out := new(APIConversionRule) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *APIConversionSpec) DeepCopyInto(out *APIConversionSpec) { - *out = *in - if in.Conversions != nil { - in, out := &in.Conversions, &out.Conversions - *out = make([]APIVersionConversion, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new APIConversionSpec. -func (in *APIConversionSpec) DeepCopy() *APIConversionSpec { - if in == nil { - return nil - } - out := new(APIConversionSpec) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *APIResourceSchema) DeepCopyInto(out *APIResourceSchema) { *out = *in @@ -259,32 +160,6 @@ func (in *APIResourceVersion) DeepCopy() *APIResourceVersion { return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *APIVersionConversion) DeepCopyInto(out *APIVersionConversion) { - *out = *in - if in.Rules != nil { - in, out := &in.Rules, &out.Rules - *out = make([]APIConversionRule, len(*in)) - copy(*out, *in) - } - if in.Preserve != nil { - in, out := &in.Preserve, &out.Preserve - *out = make([]string, len(*in)) - copy(*out, *in) - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new APIVersionConversion. -func (in *APIVersionConversion) DeepCopy() *APIVersionConversion { - if in == nil { - return nil - } - out := new(APIVersionConversion) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *CustomResourceConversion) DeepCopyInto(out *CustomResourceConversion) { *out = *in @@ -309,6 +184,11 @@ func (in *CustomResourceConversion) DeepCopy() *CustomResourceConversion { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *WebhookClientConfig) DeepCopyInto(out *WebhookClientConfig) { *out = *in + if in.URL != nil { + in, out := &in.URL, &out.URL + *out = new(string) + **out = **in + } if in.CABundle != nil { in, out := &in.CABundle, &out.CABundle *out = make([]byte, len(*in)) diff --git a/sdk/client/clientset/versioned/typed/kubebind/v1alpha2/apiconversion.go b/sdk/client/clientset/versioned/typed/kubebind/v1alpha2/apiconversion.go deleted file mode 100644 index 2b1ab71a4..000000000 --- a/sdk/client/clientset/versioned/typed/kubebind/v1alpha2/apiconversion.go +++ /dev/null @@ -1,68 +0,0 @@ -/* -Copyright The Kube Bind 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. -*/ - -// Code generated by client-gen. DO NOT EDIT. - -package v1alpha2 - -import ( - "context" - - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - types "k8s.io/apimachinery/pkg/types" - watch "k8s.io/apimachinery/pkg/watch" - gentype "k8s.io/client-go/gentype" - - v1alpha2 "github.com/kube-bind/kube-bind/sdk/apis/kubebind/v1alpha2" - scheme "github.com/kube-bind/kube-bind/sdk/client/clientset/versioned/scheme" -) - -// APIConversionsGetter has a method to return a APIConversionInterface. -// A group's client should implement this interface. -type APIConversionsGetter interface { - APIConversions() APIConversionInterface -} - -// APIConversionInterface has methods to work with APIConversion resources. -type APIConversionInterface interface { - Create(ctx context.Context, aPIConversion *v1alpha2.APIConversion, opts v1.CreateOptions) (*v1alpha2.APIConversion, error) - Update(ctx context.Context, aPIConversion *v1alpha2.APIConversion, opts v1.UpdateOptions) (*v1alpha2.APIConversion, error) - Delete(ctx context.Context, name string, opts v1.DeleteOptions) error - DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error - Get(ctx context.Context, name string, opts v1.GetOptions) (*v1alpha2.APIConversion, error) - List(ctx context.Context, opts v1.ListOptions) (*v1alpha2.APIConversionList, error) - Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) - Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha2.APIConversion, err error) - APIConversionExpansion -} - -// aPIConversions implements APIConversionInterface -type aPIConversions struct { - *gentype.ClientWithList[*v1alpha2.APIConversion, *v1alpha2.APIConversionList] -} - -// newAPIConversions returns a APIConversions -func newAPIConversions(c *KubeBindV1alpha2Client) *aPIConversions { - return &aPIConversions{ - gentype.NewClientWithList[*v1alpha2.APIConversion, *v1alpha2.APIConversionList]( - "apiconversions", - c.RESTClient(), - scheme.ParameterCodec, - "", - func() *v1alpha2.APIConversion { return &v1alpha2.APIConversion{} }, - func() *v1alpha2.APIConversionList { return &v1alpha2.APIConversionList{} }), - } -} diff --git a/sdk/client/clientset/versioned/typed/kubebind/v1alpha2/apiresourceschema.go b/sdk/client/clientset/versioned/typed/kubebind/v1alpha2/apiresourceschema.go index 501a6a2d4..f5d39689d 100644 --- a/sdk/client/clientset/versioned/typed/kubebind/v1alpha2/apiresourceschema.go +++ b/sdk/client/clientset/versioned/typed/kubebind/v1alpha2/apiresourceschema.go @@ -33,7 +33,7 @@ import ( // APIResourceSchemasGetter has a method to return a APIResourceSchemaInterface. // A group's client should implement this interface. type APIResourceSchemasGetter interface { - APIResourceSchemas(namespace string) APIResourceSchemaInterface + APIResourceSchemas() APIResourceSchemaInterface } // APIResourceSchemaInterface has methods to work with APIResourceSchema resources. @@ -55,13 +55,13 @@ type aPIResourceSchemas struct { } // newAPIResourceSchemas returns a APIResourceSchemas -func newAPIResourceSchemas(c *KubeBindV1alpha2Client, namespace string) *aPIResourceSchemas { +func newAPIResourceSchemas(c *KubeBindV1alpha2Client) *aPIResourceSchemas { return &aPIResourceSchemas{ gentype.NewClientWithList[*v1alpha2.APIResourceSchema, *v1alpha2.APIResourceSchemaList]( "apiresourceschemas", c.RESTClient(), scheme.ParameterCodec, - namespace, + "", func() *v1alpha2.APIResourceSchema { return &v1alpha2.APIResourceSchema{} }, func() *v1alpha2.APIResourceSchemaList { return &v1alpha2.APIResourceSchemaList{} }), } diff --git a/sdk/client/clientset/versioned/typed/kubebind/v1alpha2/fake/fake_apiconversion.go b/sdk/client/clientset/versioned/typed/kubebind/v1alpha2/fake/fake_apiconversion.go deleted file mode 100644 index c607f9ac6..000000000 --- a/sdk/client/clientset/versioned/typed/kubebind/v1alpha2/fake/fake_apiconversion.go +++ /dev/null @@ -1,127 +0,0 @@ -/* -Copyright The Kube Bind 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. -*/ - -// Code generated by client-gen. DO NOT EDIT. - -package fake - -import ( - "context" - - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - labels "k8s.io/apimachinery/pkg/labels" - types "k8s.io/apimachinery/pkg/types" - watch "k8s.io/apimachinery/pkg/watch" - testing "k8s.io/client-go/testing" - - v1alpha2 "github.com/kube-bind/kube-bind/sdk/apis/kubebind/v1alpha2" -) - -// FakeAPIConversions implements APIConversionInterface -type FakeAPIConversions struct { - Fake *FakeKubeBindV1alpha2 -} - -var apiconversionsResource = v1alpha2.SchemeGroupVersion.WithResource("apiconversions") - -var apiconversionsKind = v1alpha2.SchemeGroupVersion.WithKind("APIConversion") - -// Get takes name of the aPIConversion, and returns the corresponding aPIConversion object, and an error if there is any. -func (c *FakeAPIConversions) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha2.APIConversion, err error) { - emptyResult := &v1alpha2.APIConversion{} - obj, err := c.Fake. - Invokes(testing.NewRootGetActionWithOptions(apiconversionsResource, name, options), emptyResult) - if obj == nil { - return emptyResult, err - } - return obj.(*v1alpha2.APIConversion), err -} - -// List takes label and field selectors, and returns the list of APIConversions that match those selectors. -func (c *FakeAPIConversions) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha2.APIConversionList, err error) { - emptyResult := &v1alpha2.APIConversionList{} - obj, err := c.Fake. - Invokes(testing.NewRootListActionWithOptions(apiconversionsResource, apiconversionsKind, opts), emptyResult) - if obj == nil { - return emptyResult, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &v1alpha2.APIConversionList{ListMeta: obj.(*v1alpha2.APIConversionList).ListMeta} - for _, item := range obj.(*v1alpha2.APIConversionList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } - } - return list, err -} - -// Watch returns a watch.Interface that watches the requested aPIConversions. -func (c *FakeAPIConversions) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { - return c.Fake. - InvokesWatch(testing.NewRootWatchActionWithOptions(apiconversionsResource, opts)) -} - -// Create takes the representation of a aPIConversion and creates it. Returns the server's representation of the aPIConversion, and an error, if there is any. -func (c *FakeAPIConversions) Create(ctx context.Context, aPIConversion *v1alpha2.APIConversion, opts v1.CreateOptions) (result *v1alpha2.APIConversion, err error) { - emptyResult := &v1alpha2.APIConversion{} - obj, err := c.Fake. - Invokes(testing.NewRootCreateActionWithOptions(apiconversionsResource, aPIConversion, opts), emptyResult) - if obj == nil { - return emptyResult, err - } - return obj.(*v1alpha2.APIConversion), err -} - -// Update takes the representation of a aPIConversion and updates it. Returns the server's representation of the aPIConversion, and an error, if there is any. -func (c *FakeAPIConversions) Update(ctx context.Context, aPIConversion *v1alpha2.APIConversion, opts v1.UpdateOptions) (result *v1alpha2.APIConversion, err error) { - emptyResult := &v1alpha2.APIConversion{} - obj, err := c.Fake. - Invokes(testing.NewRootUpdateActionWithOptions(apiconversionsResource, aPIConversion, opts), emptyResult) - if obj == nil { - return emptyResult, err - } - return obj.(*v1alpha2.APIConversion), err -} - -// Delete takes name of the aPIConversion and deletes it. Returns an error if one occurs. -func (c *FakeAPIConversions) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { - _, err := c.Fake. - Invokes(testing.NewRootDeleteActionWithOptions(apiconversionsResource, name, opts), &v1alpha2.APIConversion{}) - return err -} - -// DeleteCollection deletes a collection of objects. -func (c *FakeAPIConversions) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { - action := testing.NewRootDeleteCollectionActionWithOptions(apiconversionsResource, opts, listOpts) - - _, err := c.Fake.Invokes(action, &v1alpha2.APIConversionList{}) - return err -} - -// Patch applies the patch and returns the patched aPIConversion. -func (c *FakeAPIConversions) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha2.APIConversion, err error) { - emptyResult := &v1alpha2.APIConversion{} - obj, err := c.Fake. - Invokes(testing.NewRootPatchSubresourceActionWithOptions(apiconversionsResource, name, pt, data, opts, subresources...), emptyResult) - if obj == nil { - return emptyResult, err - } - return obj.(*v1alpha2.APIConversion), err -} diff --git a/sdk/client/clientset/versioned/typed/kubebind/v1alpha2/fake/fake_apiresourceschema.go b/sdk/client/clientset/versioned/typed/kubebind/v1alpha2/fake/fake_apiresourceschema.go index 6ba06ccb8..f747ed636 100644 --- a/sdk/client/clientset/versioned/typed/kubebind/v1alpha2/fake/fake_apiresourceschema.go +++ b/sdk/client/clientset/versioned/typed/kubebind/v1alpha2/fake/fake_apiresourceschema.go @@ -33,7 +33,6 @@ import ( // FakeAPIResourceSchemas implements APIResourceSchemaInterface type FakeAPIResourceSchemas struct { Fake *FakeKubeBindV1alpha2 - ns string } var apiresourceschemasResource = v1alpha2.SchemeGroupVersion.WithResource("apiresourceschemas") @@ -44,8 +43,7 @@ var apiresourceschemasKind = v1alpha2.SchemeGroupVersion.WithKind("APIResourceSc func (c *FakeAPIResourceSchemas) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha2.APIResourceSchema, err error) { emptyResult := &v1alpha2.APIResourceSchema{} obj, err := c.Fake. - Invokes(testing.NewGetActionWithOptions(apiresourceschemasResource, c.ns, name, options), emptyResult) - + Invokes(testing.NewRootGetActionWithOptions(apiresourceschemasResource, name, options), emptyResult) if obj == nil { return emptyResult, err } @@ -56,8 +54,7 @@ func (c *FakeAPIResourceSchemas) Get(ctx context.Context, name string, options v func (c *FakeAPIResourceSchemas) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha2.APIResourceSchemaList, err error) { emptyResult := &v1alpha2.APIResourceSchemaList{} obj, err := c.Fake. - Invokes(testing.NewListActionWithOptions(apiresourceschemasResource, apiresourceschemasKind, c.ns, opts), emptyResult) - + Invokes(testing.NewRootListActionWithOptions(apiresourceschemasResource, apiresourceschemasKind, opts), emptyResult) if obj == nil { return emptyResult, err } @@ -78,16 +75,14 @@ func (c *FakeAPIResourceSchemas) List(ctx context.Context, opts v1.ListOptions) // Watch returns a watch.Interface that watches the requested aPIResourceSchemas. func (c *FakeAPIResourceSchemas) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { return c.Fake. - InvokesWatch(testing.NewWatchActionWithOptions(apiresourceschemasResource, c.ns, opts)) - + InvokesWatch(testing.NewRootWatchActionWithOptions(apiresourceschemasResource, opts)) } // Create takes the representation of a aPIResourceSchema and creates it. Returns the server's representation of the aPIResourceSchema, and an error, if there is any. func (c *FakeAPIResourceSchemas) Create(ctx context.Context, aPIResourceSchema *v1alpha2.APIResourceSchema, opts v1.CreateOptions) (result *v1alpha2.APIResourceSchema, err error) { emptyResult := &v1alpha2.APIResourceSchema{} obj, err := c.Fake. - Invokes(testing.NewCreateActionWithOptions(apiresourceschemasResource, c.ns, aPIResourceSchema, opts), emptyResult) - + Invokes(testing.NewRootCreateActionWithOptions(apiresourceschemasResource, aPIResourceSchema, opts), emptyResult) if obj == nil { return emptyResult, err } @@ -98,8 +93,7 @@ func (c *FakeAPIResourceSchemas) Create(ctx context.Context, aPIResourceSchema * func (c *FakeAPIResourceSchemas) Update(ctx context.Context, aPIResourceSchema *v1alpha2.APIResourceSchema, opts v1.UpdateOptions) (result *v1alpha2.APIResourceSchema, err error) { emptyResult := &v1alpha2.APIResourceSchema{} obj, err := c.Fake. - Invokes(testing.NewUpdateActionWithOptions(apiresourceschemasResource, c.ns, aPIResourceSchema, opts), emptyResult) - + Invokes(testing.NewRootUpdateActionWithOptions(apiresourceschemasResource, aPIResourceSchema, opts), emptyResult) if obj == nil { return emptyResult, err } @@ -109,14 +103,13 @@ func (c *FakeAPIResourceSchemas) Update(ctx context.Context, aPIResourceSchema * // Delete takes name of the aPIResourceSchema and deletes it. Returns an error if one occurs. func (c *FakeAPIResourceSchemas) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { _, err := c.Fake. - Invokes(testing.NewDeleteActionWithOptions(apiresourceschemasResource, c.ns, name, opts), &v1alpha2.APIResourceSchema{}) - + Invokes(testing.NewRootDeleteActionWithOptions(apiresourceschemasResource, name, opts), &v1alpha2.APIResourceSchema{}) return err } // DeleteCollection deletes a collection of objects. func (c *FakeAPIResourceSchemas) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { - action := testing.NewDeleteCollectionActionWithOptions(apiresourceschemasResource, c.ns, opts, listOpts) + action := testing.NewRootDeleteCollectionActionWithOptions(apiresourceschemasResource, opts, listOpts) _, err := c.Fake.Invokes(action, &v1alpha2.APIResourceSchemaList{}) return err @@ -126,8 +119,7 @@ func (c *FakeAPIResourceSchemas) DeleteCollection(ctx context.Context, opts v1.D func (c *FakeAPIResourceSchemas) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha2.APIResourceSchema, err error) { emptyResult := &v1alpha2.APIResourceSchema{} obj, err := c.Fake. - Invokes(testing.NewPatchSubresourceActionWithOptions(apiresourceschemasResource, c.ns, name, pt, data, opts, subresources...), emptyResult) - + Invokes(testing.NewRootPatchSubresourceActionWithOptions(apiresourceschemasResource, name, pt, data, opts, subresources...), emptyResult) if obj == nil { return emptyResult, err } diff --git a/sdk/client/clientset/versioned/typed/kubebind/v1alpha2/fake/fake_kubebind_client.go b/sdk/client/clientset/versioned/typed/kubebind/v1alpha2/fake/fake_kubebind_client.go index c10e367b2..c2dddcabd 100644 --- a/sdk/client/clientset/versioned/typed/kubebind/v1alpha2/fake/fake_kubebind_client.go +++ b/sdk/client/clientset/versioned/typed/kubebind/v1alpha2/fake/fake_kubebind_client.go @@ -29,12 +29,8 @@ type FakeKubeBindV1alpha2 struct { *testing.Fake } -func (c *FakeKubeBindV1alpha2) APIConversions() v1alpha2.APIConversionInterface { - return &FakeAPIConversions{c} -} - -func (c *FakeKubeBindV1alpha2) APIResourceSchemas(namespace string) v1alpha2.APIResourceSchemaInterface { - return &FakeAPIResourceSchemas{c, namespace} +func (c *FakeKubeBindV1alpha2) APIResourceSchemas() v1alpha2.APIResourceSchemaInterface { + return &FakeAPIResourceSchemas{c} } // RESTClient returns a RESTClient that is used to communicate diff --git a/sdk/client/clientset/versioned/typed/kubebind/v1alpha2/generated_expansion.go b/sdk/client/clientset/versioned/typed/kubebind/v1alpha2/generated_expansion.go index a4998e4ff..4e3067937 100644 --- a/sdk/client/clientset/versioned/typed/kubebind/v1alpha2/generated_expansion.go +++ b/sdk/client/clientset/versioned/typed/kubebind/v1alpha2/generated_expansion.go @@ -18,6 +18,4 @@ limitations under the License. package v1alpha2 -type APIConversionExpansion interface{} - type APIResourceSchemaExpansion interface{} diff --git a/sdk/client/clientset/versioned/typed/kubebind/v1alpha2/kubebind_client.go b/sdk/client/clientset/versioned/typed/kubebind/v1alpha2/kubebind_client.go index 3287784bb..62ed02b04 100644 --- a/sdk/client/clientset/versioned/typed/kubebind/v1alpha2/kubebind_client.go +++ b/sdk/client/clientset/versioned/typed/kubebind/v1alpha2/kubebind_client.go @@ -29,7 +29,6 @@ import ( type KubeBindV1alpha2Interface interface { RESTClient() rest.Interface - APIConversionsGetter APIResourceSchemasGetter } @@ -38,12 +37,8 @@ type KubeBindV1alpha2Client struct { restClient rest.Interface } -func (c *KubeBindV1alpha2Client) APIConversions() APIConversionInterface { - return newAPIConversions(c) -} - -func (c *KubeBindV1alpha2Client) APIResourceSchemas(namespace string) APIResourceSchemaInterface { - return newAPIResourceSchemas(c, namespace) +func (c *KubeBindV1alpha2Client) APIResourceSchemas() APIResourceSchemaInterface { + return newAPIResourceSchemas(c) } // NewForConfig creates a new KubeBindV1alpha2Client for the given config. diff --git a/sdk/client/informers/externalversions/generic.go b/sdk/client/informers/externalversions/generic.go index b61c2dd1a..f61e26520 100644 --- a/sdk/client/informers/externalversions/generic.go +++ b/sdk/client/informers/externalversions/generic.go @@ -67,8 +67,6 @@ func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource return &genericInformer{resource: resource.GroupResource(), informer: f.KubeBind().V1alpha1().ClusterBindings().Informer()}, nil // Group=kube-bind.io, Version=v1alpha2 - case v1alpha2.SchemeGroupVersion.WithResource("apiconversions"): - return &genericInformer{resource: resource.GroupResource(), informer: f.KubeBind().V1alpha2().APIConversions().Informer()}, nil case v1alpha2.SchemeGroupVersion.WithResource("apiresourceschemas"): return &genericInformer{resource: resource.GroupResource(), informer: f.KubeBind().V1alpha2().APIResourceSchemas().Informer()}, nil diff --git a/sdk/client/informers/externalversions/kubebind/v1alpha2/apiconversion.go b/sdk/client/informers/externalversions/kubebind/v1alpha2/apiconversion.go deleted file mode 100644 index b76d09ae9..000000000 --- a/sdk/client/informers/externalversions/kubebind/v1alpha2/apiconversion.go +++ /dev/null @@ -1,90 +0,0 @@ -/* -Copyright The Kube Bind 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. -*/ - -// Code generated by informer-gen. DO NOT EDIT. - -package v1alpha2 - -import ( - "context" - time "time" - - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - runtime "k8s.io/apimachinery/pkg/runtime" - watch "k8s.io/apimachinery/pkg/watch" - cache "k8s.io/client-go/tools/cache" - - kubebindv1alpha2 "github.com/kube-bind/kube-bind/sdk/apis/kubebind/v1alpha2" - versioned "github.com/kube-bind/kube-bind/sdk/client/clientset/versioned" - internalinterfaces "github.com/kube-bind/kube-bind/sdk/client/informers/externalversions/internalinterfaces" - v1alpha2 "github.com/kube-bind/kube-bind/sdk/client/listers/kubebind/v1alpha2" -) - -// APIConversionInformer provides access to a shared informer and lister for -// APIConversions. -type APIConversionInformer interface { - Informer() cache.SharedIndexInformer - Lister() v1alpha2.APIConversionLister -} - -type aPIConversionInformer struct { - factory internalinterfaces.SharedInformerFactory - tweakListOptions internalinterfaces.TweakListOptionsFunc -} - -// NewAPIConversionInformer constructs a new informer for APIConversion type. -// Always prefer using an informer factory to get a shared informer instead of getting an independent -// one. This reduces memory footprint and number of connections to the server. -func NewAPIConversionInformer(client versioned.Interface, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { - return NewFilteredAPIConversionInformer(client, resyncPeriod, indexers, nil) -} - -// NewFilteredAPIConversionInformer constructs a new informer for APIConversion type. -// Always prefer using an informer factory to get a shared informer instead of getting an independent -// one. This reduces memory footprint and number of connections to the server. -func NewFilteredAPIConversionInformer(client versioned.Interface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { - return cache.NewSharedIndexInformer( - &cache.ListWatch{ - ListFunc: func(options v1.ListOptions) (runtime.Object, error) { - if tweakListOptions != nil { - tweakListOptions(&options) - } - return client.KubeBindV1alpha2().APIConversions().List(context.TODO(), options) - }, - WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { - if tweakListOptions != nil { - tweakListOptions(&options) - } - return client.KubeBindV1alpha2().APIConversions().Watch(context.TODO(), options) - }, - }, - &kubebindv1alpha2.APIConversion{}, - resyncPeriod, - indexers, - ) -} - -func (f *aPIConversionInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { - return NewFilteredAPIConversionInformer(client, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) -} - -func (f *aPIConversionInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&kubebindv1alpha2.APIConversion{}, f.defaultInformer) -} - -func (f *aPIConversionInformer) Lister() v1alpha2.APIConversionLister { - return v1alpha2.NewAPIConversionLister(f.Informer().GetIndexer()) -} diff --git a/sdk/client/informers/externalversions/kubebind/v1alpha2/apiresourceschema.go b/sdk/client/informers/externalversions/kubebind/v1alpha2/apiresourceschema.go index dd8e23ef0..48a248c3d 100644 --- a/sdk/client/informers/externalversions/kubebind/v1alpha2/apiresourceschema.go +++ b/sdk/client/informers/externalversions/kubebind/v1alpha2/apiresourceschema.go @@ -43,33 +43,32 @@ type APIResourceSchemaInformer interface { type aPIResourceSchemaInformer struct { factory internalinterfaces.SharedInformerFactory tweakListOptions internalinterfaces.TweakListOptionsFunc - namespace string } // NewAPIResourceSchemaInformer constructs a new informer for APIResourceSchema type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server. -func NewAPIResourceSchemaInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { - return NewFilteredAPIResourceSchemaInformer(client, namespace, resyncPeriod, indexers, nil) +func NewAPIResourceSchemaInformer(client versioned.Interface, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return NewFilteredAPIResourceSchemaInformer(client, resyncPeriod, indexers, nil) } // NewFilteredAPIResourceSchemaInformer constructs a new informer for APIResourceSchema type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server. -func NewFilteredAPIResourceSchemaInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { +func NewFilteredAPIResourceSchemaInformer(client versioned.Interface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { return cache.NewSharedIndexInformer( &cache.ListWatch{ ListFunc: func(options v1.ListOptions) (runtime.Object, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.KubeBindV1alpha2().APIResourceSchemas(namespace).List(context.TODO(), options) + return client.KubeBindV1alpha2().APIResourceSchemas().List(context.TODO(), options) }, WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.KubeBindV1alpha2().APIResourceSchemas(namespace).Watch(context.TODO(), options) + return client.KubeBindV1alpha2().APIResourceSchemas().Watch(context.TODO(), options) }, }, &kubebindv1alpha2.APIResourceSchema{}, @@ -79,7 +78,7 @@ func NewFilteredAPIResourceSchemaInformer(client versioned.Interface, namespace } func (f *aPIResourceSchemaInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { - return NewFilteredAPIResourceSchemaInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) + return NewFilteredAPIResourceSchemaInformer(client, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) } func (f *aPIResourceSchemaInformer) Informer() cache.SharedIndexInformer { diff --git a/sdk/client/informers/externalversions/kubebind/v1alpha2/interface.go b/sdk/client/informers/externalversions/kubebind/v1alpha2/interface.go index 3e8973598..52b0011e7 100644 --- a/sdk/client/informers/externalversions/kubebind/v1alpha2/interface.go +++ b/sdk/client/informers/externalversions/kubebind/v1alpha2/interface.go @@ -24,8 +24,6 @@ import ( // Interface provides access to all the informers in this group version. type Interface interface { - // APIConversions returns a APIConversionInformer. - APIConversions() APIConversionInformer // APIResourceSchemas returns a APIResourceSchemaInformer. APIResourceSchemas() APIResourceSchemaInformer } @@ -41,12 +39,7 @@ func New(f internalinterfaces.SharedInformerFactory, namespace string, tweakList return &version{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} } -// APIConversions returns a APIConversionInformer. -func (v *version) APIConversions() APIConversionInformer { - return &aPIConversionInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} -} - // APIResourceSchemas returns a APIResourceSchemaInformer. func (v *version) APIResourceSchemas() APIResourceSchemaInformer { - return &aPIResourceSchemaInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} + return &aPIResourceSchemaInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} } diff --git a/sdk/client/listers/kubebind/v1alpha2/apiconversion.go b/sdk/client/listers/kubebind/v1alpha2/apiconversion.go deleted file mode 100644 index 0cd13df2f..000000000 --- a/sdk/client/listers/kubebind/v1alpha2/apiconversion.go +++ /dev/null @@ -1,49 +0,0 @@ -/* -Copyright The Kube Bind 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. -*/ - -// Code generated by lister-gen. DO NOT EDIT. - -package v1alpha2 - -import ( - "k8s.io/apimachinery/pkg/labels" - "k8s.io/client-go/listers" - "k8s.io/client-go/tools/cache" - - v1alpha2 "github.com/kube-bind/kube-bind/sdk/apis/kubebind/v1alpha2" -) - -// APIConversionLister helps list APIConversions. -// All objects returned here must be treated as read-only. -type APIConversionLister interface { - // List lists all APIConversions in the indexer. - // Objects returned here must be treated as read-only. - List(selector labels.Selector) (ret []*v1alpha2.APIConversion, err error) - // Get retrieves the APIConversion from the index for a given name. - // Objects returned here must be treated as read-only. - Get(name string) (*v1alpha2.APIConversion, error) - APIConversionListerExpansion -} - -// aPIConversionLister implements the APIConversionLister interface. -type aPIConversionLister struct { - listers.ResourceIndexer[*v1alpha2.APIConversion] -} - -// NewAPIConversionLister returns a new APIConversionLister. -func NewAPIConversionLister(indexer cache.Indexer) APIConversionLister { - return &aPIConversionLister{listers.New[*v1alpha2.APIConversion](indexer, v1alpha2.Resource("apiconversion"))} -} diff --git a/sdk/client/listers/kubebind/v1alpha2/apiresourceschema.go b/sdk/client/listers/kubebind/v1alpha2/apiresourceschema.go index f3cdcdac1..f85a54dd9 100644 --- a/sdk/client/listers/kubebind/v1alpha2/apiresourceschema.go +++ b/sdk/client/listers/kubebind/v1alpha2/apiresourceschema.go @@ -32,8 +32,9 @@ type APIResourceSchemaLister interface { // List lists all APIResourceSchemas in the indexer. // Objects returned here must be treated as read-only. List(selector labels.Selector) (ret []*v1alpha2.APIResourceSchema, err error) - // APIResourceSchemas returns an object that can list and get APIResourceSchemas. - APIResourceSchemas(namespace string) APIResourceSchemaNamespaceLister + // Get retrieves the APIResourceSchema from the index for a given name. + // Objects returned here must be treated as read-only. + Get(name string) (*v1alpha2.APIResourceSchema, error) APIResourceSchemaListerExpansion } @@ -46,26 +47,3 @@ type aPIResourceSchemaLister struct { func NewAPIResourceSchemaLister(indexer cache.Indexer) APIResourceSchemaLister { return &aPIResourceSchemaLister{listers.New[*v1alpha2.APIResourceSchema](indexer, v1alpha2.Resource("apiresourceschema"))} } - -// APIResourceSchemas returns an object that can list and get APIResourceSchemas. -func (s *aPIResourceSchemaLister) APIResourceSchemas(namespace string) APIResourceSchemaNamespaceLister { - return aPIResourceSchemaNamespaceLister{listers.NewNamespaced[*v1alpha2.APIResourceSchema](s.ResourceIndexer, namespace)} -} - -// APIResourceSchemaNamespaceLister helps list and get APIResourceSchemas. -// All objects returned here must be treated as read-only. -type APIResourceSchemaNamespaceLister interface { - // List lists all APIResourceSchemas in the indexer for a given namespace. - // Objects returned here must be treated as read-only. - List(selector labels.Selector) (ret []*v1alpha2.APIResourceSchema, err error) - // Get retrieves the APIResourceSchema from the indexer for a given namespace and name. - // Objects returned here must be treated as read-only. - Get(name string) (*v1alpha2.APIResourceSchema, error) - APIResourceSchemaNamespaceListerExpansion -} - -// aPIResourceSchemaNamespaceLister implements the APIResourceSchemaNamespaceLister -// interface. -type aPIResourceSchemaNamespaceLister struct { - listers.ResourceIndexer[*v1alpha2.APIResourceSchema] -} diff --git a/sdk/client/listers/kubebind/v1alpha2/expansion_generated.go b/sdk/client/listers/kubebind/v1alpha2/expansion_generated.go index ebb03cb66..e9a67bc79 100644 --- a/sdk/client/listers/kubebind/v1alpha2/expansion_generated.go +++ b/sdk/client/listers/kubebind/v1alpha2/expansion_generated.go @@ -18,14 +18,6 @@ limitations under the License. package v1alpha2 -// APIConversionListerExpansion allows custom methods to be added to -// APIConversionLister. -type APIConversionListerExpansion interface{} - // APIResourceSchemaListerExpansion allows custom methods to be added to // APIResourceSchemaLister. type APIResourceSchemaListerExpansion interface{} - -// APIResourceSchemaNamespaceListerExpansion allows custom methods to be added to -// APIResourceSchemaNamespaceLister. -type APIResourceSchemaNamespaceListerExpansion interface{} diff --git a/sdk/kcp/clientset/versioned/cluster/typed/kubebind/v1alpha2/apiconversion.go b/sdk/kcp/clientset/versioned/cluster/typed/kubebind/v1alpha2/apiconversion.go deleted file mode 100644 index 3146c0cfe..000000000 --- a/sdk/kcp/clientset/versioned/cluster/typed/kubebind/v1alpha2/apiconversion.go +++ /dev/null @@ -1,72 +0,0 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - -/* -Copyright The Kube Bind 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. -*/ - -// Code generated by kcp code-generator. DO NOT EDIT. - -package v1alpha2 - -import ( - "context" - - kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" - "github.com/kcp-dev/logicalcluster/v3" - - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/watch" - - kubebindv1alpha2 "github.com/kube-bind/kube-bind/sdk/apis/kubebind/v1alpha2" - kubebindv1alpha2client "github.com/kube-bind/kube-bind/sdk/kcp/clientset/versioned/typed/kubebind/v1alpha2" -) - -// APIConversionsClusterGetter has a method to return a APIConversionClusterInterface. -// A group's cluster client should implement this interface. -type APIConversionsClusterGetter interface { - APIConversions() APIConversionClusterInterface -} - -// APIConversionClusterInterface can operate on APIConversions across all clusters, -// or scope down to one cluster and return a kubebindv1alpha2client.APIConversionInterface. -type APIConversionClusterInterface interface { - Cluster(logicalcluster.Path) kubebindv1alpha2client.APIConversionInterface - List(ctx context.Context, opts metav1.ListOptions) (*kubebindv1alpha2.APIConversionList, error) - Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) -} - -type aPIConversionsClusterInterface struct { - clientCache kcpclient.Cache[*kubebindv1alpha2client.KubeBindV1alpha2Client] -} - -// Cluster scopes the client down to a particular cluster. -func (c *aPIConversionsClusterInterface) Cluster(clusterPath logicalcluster.Path) kubebindv1alpha2client.APIConversionInterface { - if clusterPath == logicalcluster.Wildcard { - panic("A specific cluster must be provided when scoping, not the wildcard.") - } - - return c.clientCache.ClusterOrDie(clusterPath).APIConversions() -} - -// List returns the entire collection of all APIConversions across all clusters. -func (c *aPIConversionsClusterInterface) List(ctx context.Context, opts metav1.ListOptions) (*kubebindv1alpha2.APIConversionList, error) { - return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).APIConversions().List(ctx, opts) -} - -// Watch begins to watch all APIConversions across all clusters. -func (c *aPIConversionsClusterInterface) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).APIConversions().Watch(ctx, opts) -} diff --git a/sdk/kcp/clientset/versioned/cluster/typed/kubebind/v1alpha2/apiresourceschema.go b/sdk/kcp/clientset/versioned/cluster/typed/kubebind/v1alpha2/apiresourceschema.go index 3672294f8..953c45950 100644 --- a/sdk/kcp/clientset/versioned/cluster/typed/kubebind/v1alpha2/apiresourceschema.go +++ b/sdk/kcp/clientset/versioned/cluster/typed/kubebind/v1alpha2/apiresourceschema.go @@ -41,9 +41,9 @@ type APIResourceSchemasClusterGetter interface { } // APIResourceSchemaClusterInterface can operate on APIResourceSchemas across all clusters, -// or scope down to one cluster and return a APIResourceSchemasNamespacer. +// or scope down to one cluster and return a kubebindv1alpha2client.APIResourceSchemaInterface. type APIResourceSchemaClusterInterface interface { - Cluster(logicalcluster.Path) APIResourceSchemasNamespacer + Cluster(logicalcluster.Path) kubebindv1alpha2client.APIResourceSchemaInterface List(ctx context.Context, opts metav1.ListOptions) (*kubebindv1alpha2.APIResourceSchemaList, error) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) } @@ -53,34 +53,20 @@ type aPIResourceSchemasClusterInterface struct { } // Cluster scopes the client down to a particular cluster. -func (c *aPIResourceSchemasClusterInterface) Cluster(clusterPath logicalcluster.Path) APIResourceSchemasNamespacer { +func (c *aPIResourceSchemasClusterInterface) Cluster(clusterPath logicalcluster.Path) kubebindv1alpha2client.APIResourceSchemaInterface { if clusterPath == logicalcluster.Wildcard { panic("A specific cluster must be provided when scoping, not the wildcard.") } - return &aPIResourceSchemasNamespacer{clientCache: c.clientCache, clusterPath: clusterPath} + return c.clientCache.ClusterOrDie(clusterPath).APIResourceSchemas() } // List returns the entire collection of all APIResourceSchemas across all clusters. func (c *aPIResourceSchemasClusterInterface) List(ctx context.Context, opts metav1.ListOptions) (*kubebindv1alpha2.APIResourceSchemaList, error) { - return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).APIResourceSchemas(metav1.NamespaceAll).List(ctx, opts) + return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).APIResourceSchemas().List(ctx, opts) } // Watch begins to watch all APIResourceSchemas across all clusters. func (c *aPIResourceSchemasClusterInterface) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).APIResourceSchemas(metav1.NamespaceAll).Watch(ctx, opts) -} - -// APIResourceSchemasNamespacer can scope to objects within a namespace, returning a kubebindv1alpha2client.APIResourceSchemaInterface. -type APIResourceSchemasNamespacer interface { - Namespace(string) kubebindv1alpha2client.APIResourceSchemaInterface -} - -type aPIResourceSchemasNamespacer struct { - clientCache kcpclient.Cache[*kubebindv1alpha2client.KubeBindV1alpha2Client] - clusterPath logicalcluster.Path -} - -func (n *aPIResourceSchemasNamespacer) Namespace(namespace string) kubebindv1alpha2client.APIResourceSchemaInterface { - return n.clientCache.ClusterOrDie(n.clusterPath).APIResourceSchemas(namespace) + return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).APIResourceSchemas().Watch(ctx, opts) } diff --git a/sdk/kcp/clientset/versioned/cluster/typed/kubebind/v1alpha2/fake/apiconversion.go b/sdk/kcp/clientset/versioned/cluster/typed/kubebind/v1alpha2/fake/apiconversion.go deleted file mode 100644 index 882b9478a..000000000 --- a/sdk/kcp/clientset/versioned/cluster/typed/kubebind/v1alpha2/fake/apiconversion.go +++ /dev/null @@ -1,202 +0,0 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - -/* -Copyright The Kube Bind 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. -*/ - -// Code generated by kcp code-generator. DO NOT EDIT. - -package fake - -import ( - "context" - "encoding/json" - "fmt" - - "github.com/kcp-dev/logicalcluster/v3" - - kcptesting "github.com/kcp-dev/client-go/third_party/k8s.io/client-go/testing" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/types" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/testing" - - kubebindv1alpha2 "github.com/kube-bind/kube-bind/sdk/apis/kubebind/v1alpha2" - applyconfigurationskubebindv1alpha2 "github.com/kube-bind/kube-bind/sdk/kcp/applyconfiguration/kubebind/v1alpha2" - kubebindv1alpha2client "github.com/kube-bind/kube-bind/sdk/kcp/clientset/versioned/typed/kubebind/v1alpha2" -) - -var aPIConversionsResource = schema.GroupVersionResource{Group: "kube-bind.io", Version: "v1alpha2", Resource: "apiconversions"} -var aPIConversionsKind = schema.GroupVersionKind{Group: "kube-bind.io", Version: "v1alpha2", Kind: "APIConversion"} - -type aPIConversionsClusterClient struct { - *kcptesting.Fake -} - -// Cluster scopes the client down to a particular cluster. -func (c *aPIConversionsClusterClient) Cluster(clusterPath logicalcluster.Path) kubebindv1alpha2client.APIConversionInterface { - if clusterPath == logicalcluster.Wildcard { - panic("A specific cluster must be provided when scoping, not the wildcard.") - } - - return &aPIConversionsClient{Fake: c.Fake, ClusterPath: clusterPath} -} - -// List takes label and field selectors, and returns the list of APIConversions that match those selectors across all clusters. -func (c *aPIConversionsClusterClient) List(ctx context.Context, opts metav1.ListOptions) (*kubebindv1alpha2.APIConversionList, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootListAction(aPIConversionsResource, aPIConversionsKind, logicalcluster.Wildcard, opts), &kubebindv1alpha2.APIConversionList{}) - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &kubebindv1alpha2.APIConversionList{ListMeta: obj.(*kubebindv1alpha2.APIConversionList).ListMeta} - for _, item := range obj.(*kubebindv1alpha2.APIConversionList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } - } - return list, err -} - -// Watch returns a watch.Interface that watches the requested APIConversions across all clusters. -func (c *aPIConversionsClusterClient) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - return c.Fake.InvokesWatch(kcptesting.NewRootWatchAction(aPIConversionsResource, logicalcluster.Wildcard, opts)) -} - -type aPIConversionsClient struct { - *kcptesting.Fake - ClusterPath logicalcluster.Path -} - -func (c *aPIConversionsClient) Create(ctx context.Context, aPIConversion *kubebindv1alpha2.APIConversion, opts metav1.CreateOptions) (*kubebindv1alpha2.APIConversion, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootCreateAction(aPIConversionsResource, c.ClusterPath, aPIConversion), &kubebindv1alpha2.APIConversion{}) - if obj == nil { - return nil, err - } - return obj.(*kubebindv1alpha2.APIConversion), err -} - -func (c *aPIConversionsClient) Update(ctx context.Context, aPIConversion *kubebindv1alpha2.APIConversion, opts metav1.UpdateOptions) (*kubebindv1alpha2.APIConversion, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootUpdateAction(aPIConversionsResource, c.ClusterPath, aPIConversion), &kubebindv1alpha2.APIConversion{}) - if obj == nil { - return nil, err - } - return obj.(*kubebindv1alpha2.APIConversion), err -} - -func (c *aPIConversionsClient) UpdateStatus(ctx context.Context, aPIConversion *kubebindv1alpha2.APIConversion, opts metav1.UpdateOptions) (*kubebindv1alpha2.APIConversion, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootUpdateSubresourceAction(aPIConversionsResource, c.ClusterPath, "status", aPIConversion), &kubebindv1alpha2.APIConversion{}) - if obj == nil { - return nil, err - } - return obj.(*kubebindv1alpha2.APIConversion), err -} - -func (c *aPIConversionsClient) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { - _, err := c.Fake.Invokes(kcptesting.NewRootDeleteActionWithOptions(aPIConversionsResource, c.ClusterPath, name, opts), &kubebindv1alpha2.APIConversion{}) - return err -} - -func (c *aPIConversionsClient) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { - action := kcptesting.NewRootDeleteCollectionAction(aPIConversionsResource, c.ClusterPath, listOpts) - - _, err := c.Fake.Invokes(action, &kubebindv1alpha2.APIConversionList{}) - return err -} - -func (c *aPIConversionsClient) Get(ctx context.Context, name string, options metav1.GetOptions) (*kubebindv1alpha2.APIConversion, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootGetAction(aPIConversionsResource, c.ClusterPath, name), &kubebindv1alpha2.APIConversion{}) - if obj == nil { - return nil, err - } - return obj.(*kubebindv1alpha2.APIConversion), err -} - -// List takes label and field selectors, and returns the list of APIConversions that match those selectors. -func (c *aPIConversionsClient) List(ctx context.Context, opts metav1.ListOptions) (*kubebindv1alpha2.APIConversionList, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootListAction(aPIConversionsResource, aPIConversionsKind, c.ClusterPath, opts), &kubebindv1alpha2.APIConversionList{}) - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &kubebindv1alpha2.APIConversionList{ListMeta: obj.(*kubebindv1alpha2.APIConversionList).ListMeta} - for _, item := range obj.(*kubebindv1alpha2.APIConversionList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } - } - return list, err -} - -func (c *aPIConversionsClient) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - return c.Fake.InvokesWatch(kcptesting.NewRootWatchAction(aPIConversionsResource, c.ClusterPath, opts)) -} - -func (c *aPIConversionsClient) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (*kubebindv1alpha2.APIConversion, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootPatchSubresourceAction(aPIConversionsResource, c.ClusterPath, name, pt, data, subresources...), &kubebindv1alpha2.APIConversion{}) - if obj == nil { - return nil, err - } - return obj.(*kubebindv1alpha2.APIConversion), err -} - -func (c *aPIConversionsClient) Apply(ctx context.Context, applyConfiguration *applyconfigurationskubebindv1alpha2.APIConversionApplyConfiguration, opts metav1.ApplyOptions) (*kubebindv1alpha2.APIConversion, error) { - if applyConfiguration == nil { - return nil, fmt.Errorf("applyConfiguration provided to Apply must not be nil") - } - data, err := json.Marshal(applyConfiguration) - if err != nil { - return nil, err - } - name := applyConfiguration.Name - if name == nil { - return nil, fmt.Errorf("applyConfiguration.Name must be provided to Apply") - } - obj, err := c.Fake.Invokes(kcptesting.NewRootPatchSubresourceAction(aPIConversionsResource, c.ClusterPath, *name, types.ApplyPatchType, data), &kubebindv1alpha2.APIConversion{}) - if obj == nil { - return nil, err - } - return obj.(*kubebindv1alpha2.APIConversion), err -} - -func (c *aPIConversionsClient) ApplyStatus(ctx context.Context, applyConfiguration *applyconfigurationskubebindv1alpha2.APIConversionApplyConfiguration, opts metav1.ApplyOptions) (*kubebindv1alpha2.APIConversion, error) { - if applyConfiguration == nil { - return nil, fmt.Errorf("applyConfiguration provided to Apply must not be nil") - } - data, err := json.Marshal(applyConfiguration) - if err != nil { - return nil, err - } - name := applyConfiguration.Name - if name == nil { - return nil, fmt.Errorf("applyConfiguration.Name must be provided to Apply") - } - obj, err := c.Fake.Invokes(kcptesting.NewRootPatchSubresourceAction(aPIConversionsResource, c.ClusterPath, *name, types.ApplyPatchType, data, "status"), &kubebindv1alpha2.APIConversion{}) - if obj == nil { - return nil, err - } - return obj.(*kubebindv1alpha2.APIConversion), err -} diff --git a/sdk/kcp/clientset/versioned/cluster/typed/kubebind/v1alpha2/fake/apiresourceschema.go b/sdk/kcp/clientset/versioned/cluster/typed/kubebind/v1alpha2/fake/apiresourceschema.go index 7bc22b869..726235f59 100644 --- a/sdk/kcp/clientset/versioned/cluster/typed/kubebind/v1alpha2/fake/apiresourceschema.go +++ b/sdk/kcp/clientset/versioned/cluster/typed/kubebind/v1alpha2/fake/apiresourceschema.go @@ -38,7 +38,6 @@ import ( kubebindv1alpha2 "github.com/kube-bind/kube-bind/sdk/apis/kubebind/v1alpha2" applyconfigurationskubebindv1alpha2 "github.com/kube-bind/kube-bind/sdk/kcp/applyconfiguration/kubebind/v1alpha2" - kcpkubebindv1alpha2 "github.com/kube-bind/kube-bind/sdk/kcp/clientset/versioned/cluster/typed/kubebind/v1alpha2" kubebindv1alpha2client "github.com/kube-bind/kube-bind/sdk/kcp/clientset/versioned/typed/kubebind/v1alpha2" ) @@ -50,17 +49,17 @@ type aPIResourceSchemasClusterClient struct { } // Cluster scopes the client down to a particular cluster. -func (c *aPIResourceSchemasClusterClient) Cluster(clusterPath logicalcluster.Path) kcpkubebindv1alpha2.APIResourceSchemasNamespacer { +func (c *aPIResourceSchemasClusterClient) Cluster(clusterPath logicalcluster.Path) kubebindv1alpha2client.APIResourceSchemaInterface { if clusterPath == logicalcluster.Wildcard { panic("A specific cluster must be provided when scoping, not the wildcard.") } - return &aPIResourceSchemasNamespacer{Fake: c.Fake, ClusterPath: clusterPath} + return &aPIResourceSchemasClient{Fake: c.Fake, ClusterPath: clusterPath} } // List takes label and field selectors, and returns the list of APIResourceSchemas that match those selectors across all clusters. func (c *aPIResourceSchemasClusterClient) List(ctx context.Context, opts metav1.ListOptions) (*kubebindv1alpha2.APIResourceSchemaList, error) { - obj, err := c.Fake.Invokes(kcptesting.NewListAction(aPIResourceSchemasResource, aPIResourceSchemasKind, logicalcluster.Wildcard, metav1.NamespaceAll, opts), &kubebindv1alpha2.APIResourceSchemaList{}) + obj, err := c.Fake.Invokes(kcptesting.NewRootListAction(aPIResourceSchemasResource, aPIResourceSchemasKind, logicalcluster.Wildcard, opts), &kubebindv1alpha2.APIResourceSchemaList{}) if obj == nil { return nil, err } @@ -80,26 +79,16 @@ func (c *aPIResourceSchemasClusterClient) List(ctx context.Context, opts metav1. // Watch returns a watch.Interface that watches the requested APIResourceSchemas across all clusters. func (c *aPIResourceSchemasClusterClient) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - return c.Fake.InvokesWatch(kcptesting.NewWatchAction(aPIResourceSchemasResource, logicalcluster.Wildcard, metav1.NamespaceAll, opts)) -} - -type aPIResourceSchemasNamespacer struct { - *kcptesting.Fake - ClusterPath logicalcluster.Path -} - -func (n *aPIResourceSchemasNamespacer) Namespace(namespace string) kubebindv1alpha2client.APIResourceSchemaInterface { - return &aPIResourceSchemasClient{Fake: n.Fake, ClusterPath: n.ClusterPath, Namespace: namespace} + return c.Fake.InvokesWatch(kcptesting.NewRootWatchAction(aPIResourceSchemasResource, logicalcluster.Wildcard, opts)) } type aPIResourceSchemasClient struct { *kcptesting.Fake ClusterPath logicalcluster.Path - Namespace string } func (c *aPIResourceSchemasClient) Create(ctx context.Context, aPIResourceSchema *kubebindv1alpha2.APIResourceSchema, opts metav1.CreateOptions) (*kubebindv1alpha2.APIResourceSchema, error) { - obj, err := c.Fake.Invokes(kcptesting.NewCreateAction(aPIResourceSchemasResource, c.ClusterPath, c.Namespace, aPIResourceSchema), &kubebindv1alpha2.APIResourceSchema{}) + obj, err := c.Fake.Invokes(kcptesting.NewRootCreateAction(aPIResourceSchemasResource, c.ClusterPath, aPIResourceSchema), &kubebindv1alpha2.APIResourceSchema{}) if obj == nil { return nil, err } @@ -107,7 +96,7 @@ func (c *aPIResourceSchemasClient) Create(ctx context.Context, aPIResourceSchema } func (c *aPIResourceSchemasClient) Update(ctx context.Context, aPIResourceSchema *kubebindv1alpha2.APIResourceSchema, opts metav1.UpdateOptions) (*kubebindv1alpha2.APIResourceSchema, error) { - obj, err := c.Fake.Invokes(kcptesting.NewUpdateAction(aPIResourceSchemasResource, c.ClusterPath, c.Namespace, aPIResourceSchema), &kubebindv1alpha2.APIResourceSchema{}) + obj, err := c.Fake.Invokes(kcptesting.NewRootUpdateAction(aPIResourceSchemasResource, c.ClusterPath, aPIResourceSchema), &kubebindv1alpha2.APIResourceSchema{}) if obj == nil { return nil, err } @@ -115,7 +104,7 @@ func (c *aPIResourceSchemasClient) Update(ctx context.Context, aPIResourceSchema } func (c *aPIResourceSchemasClient) UpdateStatus(ctx context.Context, aPIResourceSchema *kubebindv1alpha2.APIResourceSchema, opts metav1.UpdateOptions) (*kubebindv1alpha2.APIResourceSchema, error) { - obj, err := c.Fake.Invokes(kcptesting.NewUpdateSubresourceAction(aPIResourceSchemasResource, c.ClusterPath, "status", c.Namespace, aPIResourceSchema), &kubebindv1alpha2.APIResourceSchema{}) + obj, err := c.Fake.Invokes(kcptesting.NewRootUpdateSubresourceAction(aPIResourceSchemasResource, c.ClusterPath, "status", aPIResourceSchema), &kubebindv1alpha2.APIResourceSchema{}) if obj == nil { return nil, err } @@ -123,19 +112,19 @@ func (c *aPIResourceSchemasClient) UpdateStatus(ctx context.Context, aPIResource } func (c *aPIResourceSchemasClient) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { - _, err := c.Fake.Invokes(kcptesting.NewDeleteActionWithOptions(aPIResourceSchemasResource, c.ClusterPath, c.Namespace, name, opts), &kubebindv1alpha2.APIResourceSchema{}) + _, err := c.Fake.Invokes(kcptesting.NewRootDeleteActionWithOptions(aPIResourceSchemasResource, c.ClusterPath, name, opts), &kubebindv1alpha2.APIResourceSchema{}) return err } func (c *aPIResourceSchemasClient) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { - action := kcptesting.NewDeleteCollectionAction(aPIResourceSchemasResource, c.ClusterPath, c.Namespace, listOpts) + action := kcptesting.NewRootDeleteCollectionAction(aPIResourceSchemasResource, c.ClusterPath, listOpts) _, err := c.Fake.Invokes(action, &kubebindv1alpha2.APIResourceSchemaList{}) return err } func (c *aPIResourceSchemasClient) Get(ctx context.Context, name string, options metav1.GetOptions) (*kubebindv1alpha2.APIResourceSchema, error) { - obj, err := c.Fake.Invokes(kcptesting.NewGetAction(aPIResourceSchemasResource, c.ClusterPath, c.Namespace, name), &kubebindv1alpha2.APIResourceSchema{}) + obj, err := c.Fake.Invokes(kcptesting.NewRootGetAction(aPIResourceSchemasResource, c.ClusterPath, name), &kubebindv1alpha2.APIResourceSchema{}) if obj == nil { return nil, err } @@ -144,7 +133,7 @@ func (c *aPIResourceSchemasClient) Get(ctx context.Context, name string, options // List takes label and field selectors, and returns the list of APIResourceSchemas that match those selectors. func (c *aPIResourceSchemasClient) List(ctx context.Context, opts metav1.ListOptions) (*kubebindv1alpha2.APIResourceSchemaList, error) { - obj, err := c.Fake.Invokes(kcptesting.NewListAction(aPIResourceSchemasResource, aPIResourceSchemasKind, c.ClusterPath, c.Namespace, opts), &kubebindv1alpha2.APIResourceSchemaList{}) + obj, err := c.Fake.Invokes(kcptesting.NewRootListAction(aPIResourceSchemasResource, aPIResourceSchemasKind, c.ClusterPath, opts), &kubebindv1alpha2.APIResourceSchemaList{}) if obj == nil { return nil, err } @@ -163,11 +152,11 @@ func (c *aPIResourceSchemasClient) List(ctx context.Context, opts metav1.ListOpt } func (c *aPIResourceSchemasClient) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - return c.Fake.InvokesWatch(kcptesting.NewWatchAction(aPIResourceSchemasResource, c.ClusterPath, c.Namespace, opts)) + return c.Fake.InvokesWatch(kcptesting.NewRootWatchAction(aPIResourceSchemasResource, c.ClusterPath, opts)) } func (c *aPIResourceSchemasClient) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (*kubebindv1alpha2.APIResourceSchema, error) { - obj, err := c.Fake.Invokes(kcptesting.NewPatchSubresourceAction(aPIResourceSchemasResource, c.ClusterPath, c.Namespace, name, pt, data, subresources...), &kubebindv1alpha2.APIResourceSchema{}) + obj, err := c.Fake.Invokes(kcptesting.NewRootPatchSubresourceAction(aPIResourceSchemasResource, c.ClusterPath, name, pt, data, subresources...), &kubebindv1alpha2.APIResourceSchema{}) if obj == nil { return nil, err } @@ -186,7 +175,7 @@ func (c *aPIResourceSchemasClient) Apply(ctx context.Context, applyConfiguration if name == nil { return nil, fmt.Errorf("applyConfiguration.Name must be provided to Apply") } - obj, err := c.Fake.Invokes(kcptesting.NewPatchSubresourceAction(aPIResourceSchemasResource, c.ClusterPath, c.Namespace, *name, types.ApplyPatchType, data), &kubebindv1alpha2.APIResourceSchema{}) + obj, err := c.Fake.Invokes(kcptesting.NewRootPatchSubresourceAction(aPIResourceSchemasResource, c.ClusterPath, *name, types.ApplyPatchType, data), &kubebindv1alpha2.APIResourceSchema{}) if obj == nil { return nil, err } @@ -205,7 +194,7 @@ func (c *aPIResourceSchemasClient) ApplyStatus(ctx context.Context, applyConfigu if name == nil { return nil, fmt.Errorf("applyConfiguration.Name must be provided to Apply") } - obj, err := c.Fake.Invokes(kcptesting.NewPatchSubresourceAction(aPIResourceSchemasResource, c.ClusterPath, c.Namespace, *name, types.ApplyPatchType, data, "status"), &kubebindv1alpha2.APIResourceSchema{}) + obj, err := c.Fake.Invokes(kcptesting.NewRootPatchSubresourceAction(aPIResourceSchemasResource, c.ClusterPath, *name, types.ApplyPatchType, data, "status"), &kubebindv1alpha2.APIResourceSchema{}) if obj == nil { return nil, err } diff --git a/sdk/kcp/clientset/versioned/cluster/typed/kubebind/v1alpha2/fake/kubebind_client.go b/sdk/kcp/clientset/versioned/cluster/typed/kubebind/v1alpha2/fake/kubebind_client.go index 821bd0eda..c6aa54f2e 100644 --- a/sdk/kcp/clientset/versioned/cluster/typed/kubebind/v1alpha2/fake/kubebind_client.go +++ b/sdk/kcp/clientset/versioned/cluster/typed/kubebind/v1alpha2/fake/kubebind_client.go @@ -48,10 +48,6 @@ func (c *KubeBindV1alpha2ClusterClient) APIResourceSchemas() kcpkubebindv1alpha2 return &aPIResourceSchemasClusterClient{Fake: c.Fake} } -func (c *KubeBindV1alpha2ClusterClient) APIConversions() kcpkubebindv1alpha2.APIConversionClusterInterface { - return &aPIConversionsClusterClient{Fake: c.Fake} -} - var _ kubebindv1alpha2.KubeBindV1alpha2Interface = (*KubeBindV1alpha2Client)(nil) type KubeBindV1alpha2Client struct { @@ -64,10 +60,6 @@ func (c *KubeBindV1alpha2Client) RESTClient() rest.Interface { return ret } -func (c *KubeBindV1alpha2Client) APIResourceSchemas(namespace string) kubebindv1alpha2.APIResourceSchemaInterface { - return &aPIResourceSchemasClient{Fake: c.Fake, ClusterPath: c.ClusterPath, Namespace: namespace} -} - -func (c *KubeBindV1alpha2Client) APIConversions() kubebindv1alpha2.APIConversionInterface { - return &aPIConversionsClient{Fake: c.Fake, ClusterPath: c.ClusterPath} +func (c *KubeBindV1alpha2Client) APIResourceSchemas() kubebindv1alpha2.APIResourceSchemaInterface { + return &aPIResourceSchemasClient{Fake: c.Fake, ClusterPath: c.ClusterPath} } diff --git a/sdk/kcp/clientset/versioned/cluster/typed/kubebind/v1alpha2/kubebind_client.go b/sdk/kcp/clientset/versioned/cluster/typed/kubebind/v1alpha2/kubebind_client.go index 75cd181d7..82300fa55 100644 --- a/sdk/kcp/clientset/versioned/cluster/typed/kubebind/v1alpha2/kubebind_client.go +++ b/sdk/kcp/clientset/versioned/cluster/typed/kubebind/v1alpha2/kubebind_client.go @@ -35,7 +35,6 @@ import ( type KubeBindV1alpha2ClusterInterface interface { KubeBindV1alpha2ClusterScoper APIResourceSchemasClusterGetter - APIConversionsClusterGetter } type KubeBindV1alpha2ClusterScoper interface { @@ -57,10 +56,6 @@ func (c *KubeBindV1alpha2ClusterClient) APIResourceSchemas() APIResourceSchemaCl return &aPIResourceSchemasClusterInterface{clientCache: c.clientCache} } -func (c *KubeBindV1alpha2ClusterClient) APIConversions() APIConversionClusterInterface { - return &aPIConversionsClusterInterface{clientCache: c.clientCache} -} - // NewForConfig creates a new KubeBindV1alpha2ClusterClient for the given config. // NewForConfig is equivalent to NewForConfigAndClient(c, httpClient), // where httpClient was generated with rest.HTTPClientFor(c). diff --git a/sdk/kcp/informers/externalversions/generic.go b/sdk/kcp/informers/externalversions/generic.go index 72a7c0ee4..2c960fdce 100644 --- a/sdk/kcp/informers/externalversions/generic.go +++ b/sdk/kcp/informers/externalversions/generic.go @@ -101,8 +101,6 @@ func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource // Group=kube-bind.io, Version=V1alpha2 case kubebindv1alpha2.SchemeGroupVersion.WithResource("apiresourceschemas"): return &genericClusterInformer{resource: resource.GroupResource(), informer: f.KubeBind().V1alpha2().APIResourceSchemas().Informer()}, nil - case kubebindv1alpha2.SchemeGroupVersion.WithResource("apiconversions"): - return &genericClusterInformer{resource: resource.GroupResource(), informer: f.KubeBind().V1alpha2().APIConversions().Informer()}, nil } return nil, fmt.Errorf("no informer found for %v", resource) @@ -132,9 +130,6 @@ func (f *sharedScopedInformerFactory) ForResource(resource schema.GroupVersionRe case kubebindv1alpha2.SchemeGroupVersion.WithResource("apiresourceschemas"): informer := f.KubeBind().V1alpha2().APIResourceSchemas().Informer() return &genericInformer{lister: cache.NewGenericLister(informer.GetIndexer(), resource.GroupResource()), informer: informer}, nil - case kubebindv1alpha2.SchemeGroupVersion.WithResource("apiconversions"): - informer := f.KubeBind().V1alpha2().APIConversions().Informer() - return &genericInformer{lister: cache.NewGenericLister(informer.GetIndexer(), resource.GroupResource()), informer: informer}, nil } return nil, fmt.Errorf("no informer found for %v", resource) diff --git a/sdk/kcp/informers/externalversions/kubebind/v1alpha2/apiconversion.go b/sdk/kcp/informers/externalversions/kubebind/v1alpha2/apiconversion.go deleted file mode 100644 index 7a0a3fbb9..000000000 --- a/sdk/kcp/informers/externalversions/kubebind/v1alpha2/apiconversion.go +++ /dev/null @@ -1,179 +0,0 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - -/* -Copyright The Kube Bind 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. -*/ - -// Code generated by kcp code-generator. DO NOT EDIT. - -package v1alpha2 - -import ( - "context" - "time" - - kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" - kcpinformers "github.com/kcp-dev/apimachinery/v2/third_party/informers" - "github.com/kcp-dev/logicalcluster/v3" - - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/tools/cache" - - kubebindv1alpha2 "github.com/kube-bind/kube-bind/sdk/apis/kubebind/v1alpha2" - scopedclientset "github.com/kube-bind/kube-bind/sdk/kcp/clientset/versioned" - clientset "github.com/kube-bind/kube-bind/sdk/kcp/clientset/versioned/cluster" - "github.com/kube-bind/kube-bind/sdk/kcp/informers/externalversions/internalinterfaces" - kubebindv1alpha2listers "github.com/kube-bind/kube-bind/sdk/kcp/listers/kubebind/v1alpha2" -) - -// APIConversionClusterInformer provides access to a shared informer and lister for -// APIConversions. -type APIConversionClusterInformer interface { - Cluster(logicalcluster.Name) APIConversionInformer - Informer() kcpcache.ScopeableSharedIndexInformer - Lister() kubebindv1alpha2listers.APIConversionClusterLister -} - -type aPIConversionClusterInformer struct { - factory internalinterfaces.SharedInformerFactory - tweakListOptions internalinterfaces.TweakListOptionsFunc -} - -// NewAPIConversionClusterInformer constructs a new informer for APIConversion type. -// Always prefer using an informer factory to get a shared informer instead of getting an independent -// one. This reduces memory footprint and number of connections to the server. -func NewAPIConversionClusterInformer(client clientset.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers) kcpcache.ScopeableSharedIndexInformer { - return NewFilteredAPIConversionClusterInformer(client, resyncPeriod, indexers, nil) -} - -// NewFilteredAPIConversionClusterInformer constructs a new informer for APIConversion type. -// Always prefer using an informer factory to get a shared informer instead of getting an independent -// one. This reduces memory footprint and number of connections to the server. -func NewFilteredAPIConversionClusterInformer(client clientset.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) kcpcache.ScopeableSharedIndexInformer { - return kcpinformers.NewSharedIndexInformer( - &cache.ListWatch{ - ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { - if tweakListOptions != nil { - tweakListOptions(&options) - } - return client.KubeBindV1alpha2().APIConversions().List(context.TODO(), options) - }, - WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { - if tweakListOptions != nil { - tweakListOptions(&options) - } - return client.KubeBindV1alpha2().APIConversions().Watch(context.TODO(), options) - }, - }, - &kubebindv1alpha2.APIConversion{}, - resyncPeriod, - indexers, - ) -} - -func (f *aPIConversionClusterInformer) defaultInformer(client clientset.ClusterInterface, resyncPeriod time.Duration) kcpcache.ScopeableSharedIndexInformer { - return NewFilteredAPIConversionClusterInformer(client, resyncPeriod, cache.Indexers{ - kcpcache.ClusterIndexName: kcpcache.ClusterIndexFunc, - }, - f.tweakListOptions, - ) -} - -func (f *aPIConversionClusterInformer) Informer() kcpcache.ScopeableSharedIndexInformer { - return f.factory.InformerFor(&kubebindv1alpha2.APIConversion{}, f.defaultInformer) -} - -func (f *aPIConversionClusterInformer) Lister() kubebindv1alpha2listers.APIConversionClusterLister { - return kubebindv1alpha2listers.NewAPIConversionClusterLister(f.Informer().GetIndexer()) -} - -// APIConversionInformer provides access to a shared informer and lister for -// APIConversions. -type APIConversionInformer interface { - Informer() cache.SharedIndexInformer - Lister() kubebindv1alpha2listers.APIConversionLister -} - -func (f *aPIConversionClusterInformer) Cluster(clusterName logicalcluster.Name) APIConversionInformer { - return &aPIConversionInformer{ - informer: f.Informer().Cluster(clusterName), - lister: f.Lister().Cluster(clusterName), - } -} - -type aPIConversionInformer struct { - informer cache.SharedIndexInformer - lister kubebindv1alpha2listers.APIConversionLister -} - -func (f *aPIConversionInformer) Informer() cache.SharedIndexInformer { - return f.informer -} - -func (f *aPIConversionInformer) Lister() kubebindv1alpha2listers.APIConversionLister { - return f.lister -} - -type aPIConversionScopedInformer struct { - factory internalinterfaces.SharedScopedInformerFactory - tweakListOptions internalinterfaces.TweakListOptionsFunc -} - -func (f *aPIConversionScopedInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&kubebindv1alpha2.APIConversion{}, f.defaultInformer) -} - -func (f *aPIConversionScopedInformer) Lister() kubebindv1alpha2listers.APIConversionLister { - return kubebindv1alpha2listers.NewAPIConversionLister(f.Informer().GetIndexer()) -} - -// NewAPIConversionInformer constructs a new informer for APIConversion type. -// Always prefer using an informer factory to get a shared informer instead of getting an independent -// one. This reduces memory footprint and number of connections to the server. -func NewAPIConversionInformer(client scopedclientset.Interface, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { - return NewFilteredAPIConversionInformer(client, resyncPeriod, indexers, nil) -} - -// NewFilteredAPIConversionInformer constructs a new informer for APIConversion type. -// Always prefer using an informer factory to get a shared informer instead of getting an independent -// one. This reduces memory footprint and number of connections to the server. -func NewFilteredAPIConversionInformer(client scopedclientset.Interface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { - return cache.NewSharedIndexInformer( - &cache.ListWatch{ - ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { - if tweakListOptions != nil { - tweakListOptions(&options) - } - return client.KubeBindV1alpha2().APIConversions().List(context.TODO(), options) - }, - WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { - if tweakListOptions != nil { - tweakListOptions(&options) - } - return client.KubeBindV1alpha2().APIConversions().Watch(context.TODO(), options) - }, - }, - &kubebindv1alpha2.APIConversion{}, - resyncPeriod, - indexers, - ) -} - -func (f *aPIConversionScopedInformer) defaultInformer(client scopedclientset.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { - return NewFilteredAPIConversionInformer(client, resyncPeriod, cache.Indexers{}, f.tweakListOptions) -} diff --git a/sdk/kcp/informers/externalversions/kubebind/v1alpha2/apiresourceschema.go b/sdk/kcp/informers/externalversions/kubebind/v1alpha2/apiresourceschema.go index a01baaf3b..5713459d6 100644 --- a/sdk/kcp/informers/externalversions/kubebind/v1alpha2/apiresourceschema.go +++ b/sdk/kcp/informers/externalversions/kubebind/v1alpha2/apiresourceschema.go @@ -88,8 +88,8 @@ func NewFilteredAPIResourceSchemaClusterInformer(client clientset.ClusterInterfa func (f *aPIResourceSchemaClusterInformer) defaultInformer(client clientset.ClusterInterface, resyncPeriod time.Duration) kcpcache.ScopeableSharedIndexInformer { return NewFilteredAPIResourceSchemaClusterInformer(client, resyncPeriod, cache.Indexers{ - kcpcache.ClusterIndexName: kcpcache.ClusterIndexFunc, - kcpcache.ClusterAndNamespaceIndexName: kcpcache.ClusterAndNamespaceIndexFunc}, + kcpcache.ClusterIndexName: kcpcache.ClusterIndexFunc, + }, f.tweakListOptions, ) } @@ -132,7 +132,6 @@ func (f *aPIResourceSchemaInformer) Lister() kubebindv1alpha2listers.APIResource type aPIResourceSchemaScopedInformer struct { factory internalinterfaces.SharedScopedInformerFactory tweakListOptions internalinterfaces.TweakListOptionsFunc - namespace string } func (f *aPIResourceSchemaScopedInformer) Informer() cache.SharedIndexInformer { @@ -146,27 +145,27 @@ func (f *aPIResourceSchemaScopedInformer) Lister() kubebindv1alpha2listers.APIRe // NewAPIResourceSchemaInformer constructs a new informer for APIResourceSchema type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server. -func NewAPIResourceSchemaInformer(client scopedclientset.Interface, resyncPeriod time.Duration, namespace string, indexers cache.Indexers) cache.SharedIndexInformer { - return NewFilteredAPIResourceSchemaInformer(client, resyncPeriod, namespace, indexers, nil) +func NewAPIResourceSchemaInformer(client scopedclientset.Interface, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return NewFilteredAPIResourceSchemaInformer(client, resyncPeriod, indexers, nil) } // NewFilteredAPIResourceSchemaInformer constructs a new informer for APIResourceSchema type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server. -func NewFilteredAPIResourceSchemaInformer(client scopedclientset.Interface, resyncPeriod time.Duration, namespace string, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { +func NewFilteredAPIResourceSchemaInformer(client scopedclientset.Interface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { return cache.NewSharedIndexInformer( &cache.ListWatch{ ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.KubeBindV1alpha2().APIResourceSchemas(namespace).List(context.TODO(), options) + return client.KubeBindV1alpha2().APIResourceSchemas().List(context.TODO(), options) }, WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.KubeBindV1alpha2().APIResourceSchemas(namespace).Watch(context.TODO(), options) + return client.KubeBindV1alpha2().APIResourceSchemas().Watch(context.TODO(), options) }, }, &kubebindv1alpha2.APIResourceSchema{}, @@ -176,7 +175,5 @@ func NewFilteredAPIResourceSchemaInformer(client scopedclientset.Interface, resy } func (f *aPIResourceSchemaScopedInformer) defaultInformer(client scopedclientset.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { - return NewFilteredAPIResourceSchemaInformer(client, resyncPeriod, f.namespace, cache.Indexers{ - cache.NamespaceIndex: cache.MetaNamespaceIndexFunc, - }, f.tweakListOptions) + return NewFilteredAPIResourceSchemaInformer(client, resyncPeriod, cache.Indexers{}, f.tweakListOptions) } diff --git a/sdk/kcp/informers/externalversions/kubebind/v1alpha2/interface.go b/sdk/kcp/informers/externalversions/kubebind/v1alpha2/interface.go index 4c255269e..bd5325322 100644 --- a/sdk/kcp/informers/externalversions/kubebind/v1alpha2/interface.go +++ b/sdk/kcp/informers/externalversions/kubebind/v1alpha2/interface.go @@ -28,8 +28,6 @@ import ( type ClusterInterface interface { // APIResourceSchemas returns a APIResourceSchemaClusterInformer APIResourceSchemas() APIResourceSchemaClusterInformer - // APIConversions returns a APIConversionClusterInformer - APIConversions() APIConversionClusterInformer } type version struct { @@ -47,16 +45,9 @@ func (v *version) APIResourceSchemas() APIResourceSchemaClusterInformer { return &aPIResourceSchemaClusterInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} } -// APIConversions returns a APIConversionClusterInformer -func (v *version) APIConversions() APIConversionClusterInformer { - return &aPIConversionClusterInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} -} - type Interface interface { // APIResourceSchemas returns a APIResourceSchemaInformer APIResourceSchemas() APIResourceSchemaInformer - // APIConversions returns a APIConversionInformer - APIConversions() APIConversionInformer } type scopedVersion struct { @@ -72,10 +63,5 @@ func NewScoped(f internalinterfaces.SharedScopedInformerFactory, namespace strin // APIResourceSchemas returns a APIResourceSchemaInformer func (v *scopedVersion) APIResourceSchemas() APIResourceSchemaInformer { - return &aPIResourceSchemaScopedInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} -} - -// APIConversions returns a APIConversionInformer -func (v *scopedVersion) APIConversions() APIConversionInformer { - return &aPIConversionScopedInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} + return &aPIResourceSchemaScopedInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} } diff --git a/sdk/kcp/listers/kubebind/v1alpha2/apiconversion.go b/sdk/kcp/listers/kubebind/v1alpha2/apiconversion.go deleted file mode 100644 index b6738b8dd..000000000 --- a/sdk/kcp/listers/kubebind/v1alpha2/apiconversion.go +++ /dev/null @@ -1,143 +0,0 @@ -//go:build !ignore_autogenerated -// +build !ignore_autogenerated - -/* -Copyright The Kube Bind 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. -*/ - -// Code generated by kcp code-generator. DO NOT EDIT. - -package v1alpha2 - -import ( - kcpcache "github.com/kcp-dev/apimachinery/v2/pkg/cache" - "github.com/kcp-dev/logicalcluster/v3" - - "k8s.io/apimachinery/pkg/api/errors" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/client-go/tools/cache" - - kubebindv1alpha2 "github.com/kube-bind/kube-bind/sdk/apis/kubebind/v1alpha2" -) - -// APIConversionClusterLister can list APIConversions across all workspaces, or scope down to a APIConversionLister for one workspace. -// All objects returned here must be treated as read-only. -type APIConversionClusterLister interface { - // List lists all APIConversions in the indexer. - // Objects returned here must be treated as read-only. - List(selector labels.Selector) (ret []*kubebindv1alpha2.APIConversion, err error) - // Cluster returns a lister that can list and get APIConversions in one workspace. - Cluster(clusterName logicalcluster.Name) APIConversionLister - APIConversionClusterListerExpansion -} - -type aPIConversionClusterLister struct { - indexer cache.Indexer -} - -// NewAPIConversionClusterLister returns a new APIConversionClusterLister. -// We assume that the indexer: -// - is fed by a cross-workspace LIST+WATCH -// - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function -// - has the kcpcache.ClusterIndex as an index -func NewAPIConversionClusterLister(indexer cache.Indexer) *aPIConversionClusterLister { - return &aPIConversionClusterLister{indexer: indexer} -} - -// List lists all APIConversions in the indexer across all workspaces. -func (s *aPIConversionClusterLister) List(selector labels.Selector) (ret []*kubebindv1alpha2.APIConversion, err error) { - err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*kubebindv1alpha2.APIConversion)) - }) - return ret, err -} - -// Cluster scopes the lister to one workspace, allowing users to list and get APIConversions. -func (s *aPIConversionClusterLister) Cluster(clusterName logicalcluster.Name) APIConversionLister { - return &aPIConversionLister{indexer: s.indexer, clusterName: clusterName} -} - -// APIConversionLister can list all APIConversions, or get one in particular. -// All objects returned here must be treated as read-only. -type APIConversionLister interface { - // List lists all APIConversions in the workspace. - // Objects returned here must be treated as read-only. - List(selector labels.Selector) (ret []*kubebindv1alpha2.APIConversion, err error) - // Get retrieves the APIConversion from the indexer for a given workspace and name. - // Objects returned here must be treated as read-only. - Get(name string) (*kubebindv1alpha2.APIConversion, error) - APIConversionListerExpansion -} - -// aPIConversionLister can list all APIConversions inside a workspace. -type aPIConversionLister struct { - indexer cache.Indexer - clusterName logicalcluster.Name -} - -// List lists all APIConversions in the indexer for a workspace. -func (s *aPIConversionLister) List(selector labels.Selector) (ret []*kubebindv1alpha2.APIConversion, err error) { - err = kcpcache.ListAllByCluster(s.indexer, s.clusterName, selector, func(i interface{}) { - ret = append(ret, i.(*kubebindv1alpha2.APIConversion)) - }) - return ret, err -} - -// Get retrieves the APIConversion from the indexer for a given workspace and name. -func (s *aPIConversionLister) Get(name string) (*kubebindv1alpha2.APIConversion, error) { - key := kcpcache.ToClusterAwareKey(s.clusterName.String(), "", name) - obj, exists, err := s.indexer.GetByKey(key) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(kubebindv1alpha2.Resource("apiconversions"), name) - } - return obj.(*kubebindv1alpha2.APIConversion), nil -} - -// NewAPIConversionLister returns a new APIConversionLister. -// We assume that the indexer: -// - is fed by a workspace-scoped LIST+WATCH -// - uses cache.MetaNamespaceKeyFunc as the key function -func NewAPIConversionLister(indexer cache.Indexer) *aPIConversionScopedLister { - return &aPIConversionScopedLister{indexer: indexer} -} - -// aPIConversionScopedLister can list all APIConversions inside a workspace. -type aPIConversionScopedLister struct { - indexer cache.Indexer -} - -// List lists all APIConversions in the indexer for a workspace. -func (s *aPIConversionScopedLister) List(selector labels.Selector) (ret []*kubebindv1alpha2.APIConversion, err error) { - err = cache.ListAll(s.indexer, selector, func(i interface{}) { - ret = append(ret, i.(*kubebindv1alpha2.APIConversion)) - }) - return ret, err -} - -// Get retrieves the APIConversion from the indexer for a given workspace and name. -func (s *aPIConversionScopedLister) Get(name string) (*kubebindv1alpha2.APIConversion, error) { - key := name - obj, exists, err := s.indexer.GetByKey(key) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(kubebindv1alpha2.Resource("apiconversions"), name) - } - return obj.(*kubebindv1alpha2.APIConversion), nil -} diff --git a/sdk/kcp/listers/kubebind/v1alpha2/apiresourceschema.go b/sdk/kcp/listers/kubebind/v1alpha2/apiresourceschema.go index 5498fd446..99025a512 100644 --- a/sdk/kcp/listers/kubebind/v1alpha2/apiresourceschema.go +++ b/sdk/kcp/listers/kubebind/v1alpha2/apiresourceschema.go @@ -52,7 +52,6 @@ type aPIResourceSchemaClusterLister struct { // - is fed by a cross-workspace LIST+WATCH // - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function // - has the kcpcache.ClusterIndex as an index -// - has the kcpcache.ClusterAndNamespaceIndex as an index func NewAPIResourceSchemaClusterLister(indexer cache.Indexer) *aPIResourceSchemaClusterLister { return &aPIResourceSchemaClusterLister{indexer: indexer} } @@ -70,18 +69,19 @@ func (s *aPIResourceSchemaClusterLister) Cluster(clusterName logicalcluster.Name return &aPIResourceSchemaLister{indexer: s.indexer, clusterName: clusterName} } -// APIResourceSchemaLister can list APIResourceSchemas across all namespaces, or scope down to a APIResourceSchemaNamespaceLister for one namespace. +// APIResourceSchemaLister can list all APIResourceSchemas, or get one in particular. // All objects returned here must be treated as read-only. type APIResourceSchemaLister interface { // List lists all APIResourceSchemas in the workspace. // Objects returned here must be treated as read-only. List(selector labels.Selector) (ret []*kubebindv1alpha2.APIResourceSchema, err error) - // APIResourceSchemas returns a lister that can list and get APIResourceSchemas in one workspace and namespace. - APIResourceSchemas(namespace string) APIResourceSchemaNamespaceLister + // Get retrieves the APIResourceSchema from the indexer for a given workspace and name. + // Objects returned here must be treated as read-only. + Get(name string) (*kubebindv1alpha2.APIResourceSchema, error) APIResourceSchemaListerExpansion } -// aPIResourceSchemaLister can list all APIResourceSchemas inside a workspace or scope down to a APIResourceSchemaLister for one namespace. +// aPIResourceSchemaLister can list all APIResourceSchemas inside a workspace. type aPIResourceSchemaLister struct { indexer cache.Indexer clusterName logicalcluster.Name @@ -95,42 +95,9 @@ func (s *aPIResourceSchemaLister) List(selector labels.Selector) (ret []*kubebin return ret, err } -// APIResourceSchemas returns an object that can list and get APIResourceSchemas in one namespace. -func (s *aPIResourceSchemaLister) APIResourceSchemas(namespace string) APIResourceSchemaNamespaceLister { - return &aPIResourceSchemaNamespaceLister{indexer: s.indexer, clusterName: s.clusterName, namespace: namespace} -} - -// aPIResourceSchemaNamespaceLister helps list and get APIResourceSchemas. -// All objects returned here must be treated as read-only. -type APIResourceSchemaNamespaceLister interface { - // List lists all APIResourceSchemas in the workspace and namespace. - // Objects returned here must be treated as read-only. - List(selector labels.Selector) (ret []*kubebindv1alpha2.APIResourceSchema, err error) - // Get retrieves the APIResourceSchema from the indexer for a given workspace, namespace and name. - // Objects returned here must be treated as read-only. - Get(name string) (*kubebindv1alpha2.APIResourceSchema, error) - APIResourceSchemaNamespaceListerExpansion -} - -// aPIResourceSchemaNamespaceLister helps list and get APIResourceSchemas. -// All objects returned here must be treated as read-only. -type aPIResourceSchemaNamespaceLister struct { - indexer cache.Indexer - clusterName logicalcluster.Name - namespace string -} - -// List lists all APIResourceSchemas in the indexer for a given workspace and namespace. -func (s *aPIResourceSchemaNamespaceLister) List(selector labels.Selector) (ret []*kubebindv1alpha2.APIResourceSchema, err error) { - err = kcpcache.ListAllByClusterAndNamespace(s.indexer, s.clusterName, s.namespace, selector, func(i interface{}) { - ret = append(ret, i.(*kubebindv1alpha2.APIResourceSchema)) - }) - return ret, err -} - -// Get retrieves the APIResourceSchema from the indexer for a given workspace, namespace and name. -func (s *aPIResourceSchemaNamespaceLister) Get(name string) (*kubebindv1alpha2.APIResourceSchema, error) { - key := kcpcache.ToClusterAwareKey(s.clusterName.String(), s.namespace, name) +// Get retrieves the APIResourceSchema from the indexer for a given workspace and name. +func (s *aPIResourceSchemaLister) Get(name string) (*kubebindv1alpha2.APIResourceSchema, error) { + key := kcpcache.ToClusterAwareKey(s.clusterName.String(), "", name) obj, exists, err := s.indexer.GetByKey(key) if err != nil { return nil, err @@ -145,12 +112,11 @@ func (s *aPIResourceSchemaNamespaceLister) Get(name string) (*kubebindv1alpha2.A // We assume that the indexer: // - is fed by a workspace-scoped LIST+WATCH // - uses cache.MetaNamespaceKeyFunc as the key function -// - has the cache.NamespaceIndex as an index func NewAPIResourceSchemaLister(indexer cache.Indexer) *aPIResourceSchemaScopedLister { return &aPIResourceSchemaScopedLister{indexer: indexer} } -// aPIResourceSchemaScopedLister can list all APIResourceSchemas inside a workspace or scope down to a APIResourceSchemaLister for one namespace. +// aPIResourceSchemaScopedLister can list all APIResourceSchemas inside a workspace. type aPIResourceSchemaScopedLister struct { indexer cache.Indexer } @@ -163,28 +129,9 @@ func (s *aPIResourceSchemaScopedLister) List(selector labels.Selector) (ret []*k return ret, err } -// APIResourceSchemas returns an object that can list and get APIResourceSchemas in one namespace. -func (s *aPIResourceSchemaScopedLister) APIResourceSchemas(namespace string) APIResourceSchemaNamespaceLister { - return &aPIResourceSchemaScopedNamespaceLister{indexer: s.indexer, namespace: namespace} -} - -// aPIResourceSchemaScopedNamespaceLister helps list and get APIResourceSchemas. -type aPIResourceSchemaScopedNamespaceLister struct { - indexer cache.Indexer - namespace string -} - -// List lists all APIResourceSchemas in the indexer for a given workspace and namespace. -func (s *aPIResourceSchemaScopedNamespaceLister) List(selector labels.Selector) (ret []*kubebindv1alpha2.APIResourceSchema, err error) { - err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(i interface{}) { - ret = append(ret, i.(*kubebindv1alpha2.APIResourceSchema)) - }) - return ret, err -} - -// Get retrieves the APIResourceSchema from the indexer for a given workspace, namespace and name. -func (s *aPIResourceSchemaScopedNamespaceLister) Get(name string) (*kubebindv1alpha2.APIResourceSchema, error) { - key := s.namespace + "/" + name +// Get retrieves the APIResourceSchema from the indexer for a given workspace and name. +func (s *aPIResourceSchemaScopedLister) Get(name string) (*kubebindv1alpha2.APIResourceSchema, error) { + key := name obj, exists, err := s.indexer.GetByKey(key) if err != nil { return nil, err From 3ecf9cb24b7c71c13d1fa18250db741d7c9b8828 Mon Sep 17 00:00:00 2001 From: Karol Szwaj Date: Fri, 25 Apr 2025 13:27:02 +0200 Subject: [PATCH 5/8] Make APIResourceSchema namespaced for now Signed-off-by: Karol Szwaj On-behalf-of: @SAP karol.szwaj@sap.com --- .../crd2apiresourceschema/plugin/crd2apiresourceschema.go | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/cli/pkg/crd2apiresourceschema/plugin/crd2apiresourceschema.go b/cli/pkg/crd2apiresourceschema/plugin/crd2apiresourceschema.go index f554e166c..dabd7bb53 100644 --- a/cli/pkg/crd2apiresourceschema/plugin/crd2apiresourceschema.go +++ b/cli/pkg/crd2apiresourceschema/plugin/crd2apiresourceschema.go @@ -123,12 +123,7 @@ func (b *CRD2APIResourceSchemaOptions) Run(ctx context.Context) error { func convertCRDToAPIResourceSchema(crd *apiextensionsv1.CustomResourceDefinition, prefix string) (*kubebindv1alpha2.APIResourceSchema, error) { name := prefix + "." + crd.Name - - informerScope := kubebindv1alpha2.ClusterScope - if crd.Spec.Scope == apiextensionsv1.NamespaceScoped { - informerScope = kubebindv1alpha2.NamespacedScope - } - + informerScope := kubebindv1alpha2.NamespacedScope apiResourceSchema := &kubebindv1alpha2.APIResourceSchema{ TypeMeta: metav1.TypeMeta{ APIVersion: kubebindv1alpha2.SchemeGroupVersion.String(), From a34477dcd6460df34677f669a1220150f179fc17 Mon Sep 17 00:00:00 2001 From: Karol Szwaj Date: Tue, 29 Apr 2025 12:11:55 +0200 Subject: [PATCH 6/8] update cli to save yaml files Signed-off-by: Karol Szwaj On-behalf-of: @SAP karol.szwaj@sap.com --- cli/pkg/crd2apiresourceschema/cmd/cmd.go | 4 + .../plugin/crd2apiresourceschema.go | 97 ++++++++++++++++--- .../v1alpha2/apiresourceschema_types.go | 1 - .../kubebind/v1alpha2/apiresourceschema.go | 6 +- .../v1alpha2/fake/fake_apiresourceschema.go | 24 +++-- .../v1alpha2/fake/fake_kubebind_client.go | 4 +- .../kubebind/v1alpha2/kubebind_client.go | 4 +- .../kubebind/v1alpha2/apiresourceschema.go | 13 +-- .../kubebind/v1alpha2/interface.go | 2 +- .../kubebind/v1alpha2/apiresourceschema.go | 28 +++++- .../kubebind/v1alpha2/expansion_generated.go | 4 + .../kubebind/v1alpha2/apiresourceschema.go | 26 +++-- .../v1alpha2/fake/apiresourceschema.go | 41 +++++--- .../kubebind/v1alpha2/fake/kubebind_client.go | 4 +- .../kubebind/v1alpha2/apiresourceschema.go | 19 ++-- .../kubebind/v1alpha2/interface.go | 2 +- .../kubebind/v1alpha2/apiresourceschema.go | 77 ++++++++++++--- 17 files changed, 271 insertions(+), 85 deletions(-) diff --git a/cli/pkg/crd2apiresourceschema/cmd/cmd.go b/cli/pkg/crd2apiresourceschema/cmd/cmd.go index 77e5fdb26..d7e52a1af 100644 --- a/cli/pkg/crd2apiresourceschema/cmd/cmd.go +++ b/cli/pkg/crd2apiresourceschema/cmd/cmd.go @@ -56,6 +56,10 @@ func New(streams genericclioptions.IOStreams) (*cobra.Command, error) { return err } + if err := opts.Validate(); err != nil { + return err + } + return opts.Run(cmd.Context()) }, } diff --git a/cli/pkg/crd2apiresourceschema/plugin/crd2apiresourceschema.go b/cli/pkg/crd2apiresourceschema/plugin/crd2apiresourceschema.go index dabd7bb53..1271f05fb 100644 --- a/cli/pkg/crd2apiresourceschema/plugin/crd2apiresourceschema.go +++ b/cli/pkg/crd2apiresourceschema/plugin/crd2apiresourceschema.go @@ -19,7 +19,12 @@ package plugin import ( "context" "encoding/json" + "errors" "fmt" + "io" + "os" + "path/filepath" + "time" "github.com/spf13/cobra" @@ -27,10 +32,12 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/serializer" "k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/client-go/dynamic" "k8s.io/component-base/logs" logsv1 "k8s.io/component-base/logs/api/v1" + "k8s.io/component-base/version" "github.com/kube-bind/kube-bind/cli/pkg/kubectl/base" kubebindv1alpha2 "github.com/kube-bind/kube-bind/sdk/apis/kubebind/v1alpha2" @@ -40,6 +47,11 @@ type CRD2APIResourceSchemaOptions struct { Options *base.Options Logs *logs.Options Print *genericclioptions.PrintFlags + + // GenerateInCluster indicates whether to generate the APIResourceSchema in-cluster. + GenerateInCluster bool + // OutputDir is the directory where the APIResourceSchemas will be written. + OutputDir string } func NewCRD2APIResourceSchemaOptions(streams genericclioptions.IOStreams) *CRD2APIResourceSchemaOptions { @@ -54,14 +66,21 @@ func (b *CRD2APIResourceSchemaOptions) AddCmdFlags(cmd *cobra.Command) { b.Options.BindFlags(cmd) logsv1.AddFlags(b.Logs, cmd.Flags()) b.Print.AddFlags(cmd) + + cmd.Flags().BoolVar(&b.GenerateInCluster, "generate-in-cluster", b.GenerateInCluster, "Generate the APIResourceSchema in-cluster.") + cmd.Flags().StringVar(&b.OutputDir, "output-dir", b.OutputDir, "Directory where APIResourceSchemas will be written.") } func (b *CRD2APIResourceSchemaOptions) Complete(args []string) error { - if err := b.Options.Complete(); err != nil { - return err + return b.Options.Complete() +} + +func (b *CRD2APIResourceSchemaOptions) Validate() error { + if b.GenerateInCluster && b.OutputDir != "" { + return errors.New("output-dir and generate-in-cluster cannot be used together") } - return nil + return b.Options.Validate() } // Run starts the process of converting CRDs to APIResourceSchema objects. @@ -75,7 +94,10 @@ func (b *CRD2APIResourceSchemaOptions) Run(ctx context.Context) error { return fmt.Errorf("failed to create dynamic client: %w", err) } - apiResourceSchemaGVR := kubebindv1alpha2.SchemeGroupVersion.WithResource("apiresourceschemas") + if b.OutputDir == "" { + b.OutputDir = "." + } + crdGVR := apiextensionsv1.SchemeGroupVersion.WithResource("customresourcedefinitions") crdList, err := client.Resource(crdGVR).List(ctx, metav1.ListOptions{}) if err != nil { @@ -93,9 +115,11 @@ func (b *CRD2APIResourceSchemaOptions) Run(ctx context.Context) error { continue } - apiResourceSchema, err := convertCRDToAPIResourceSchema(crdObj, "apiresourceschema") + prefix := fmt.Sprintf("v%s-%s", time.Now().Format("060102"), string(version.Get().GitCommit)) + apiResourceSchema, err := convertCRDToAPIResourceSchema(crdObj, prefix) if err != nil { fmt.Fprintf(b.Options.ErrOut, "Failed to convert CRD %s to APIResourceSchema: %v\n", crdObj.Name, err) + continue } if apiResourceSchema == nil { @@ -103,21 +127,34 @@ func (b *CRD2APIResourceSchemaOptions) Run(ctx context.Context) error { continue } - unstructuredObj, err := runtime.DefaultUnstructuredConverter.ToUnstructured(apiResourceSchema) - if err != nil { - return fmt.Errorf("failed to convert APIResourceSchema to unstructured: %w", err) + if b.GenerateInCluster { + if err := generateAPIResourceSchemaInCluster(ctx, client, apiResourceSchema, b.Options.ErrOut, b.Options.Out); err != nil { + continue + } } - unstructuredResource := &unstructured.Unstructured{Object: unstructuredObj} - - _, err = client.Resource(apiResourceSchemaGVR).Create(ctx, unstructuredResource, metav1.CreateOptions{}) - if err != nil { - fmt.Fprintf(b.Options.ErrOut, "Failed to create APIResourceSchema for CRD %s: %v\n", crdObj.Name, err) - continue + if err := writeObjectToYAML(b.OutputDir, apiResourceSchema, b.Options.Out); err != nil { + return err } + } + + return nil +} - fmt.Fprintf(b.Options.Out, "Successfully created APIResourceSchema for CRD %s\n", crdObj.Name) +func generateAPIResourceSchemaInCluster(ctx context.Context, client dynamic.Interface, apiResourceSchema *kubebindv1alpha2.APIResourceSchema, errOut, out io.Writer) error { + apiResourceSchemaGVR := kubebindv1alpha2.SchemeGroupVersion.WithResource("apiresourceschemas") + unstructuredObj, err := runtime.DefaultUnstructuredConverter.ToUnstructured(apiResourceSchema) + if err != nil { + return fmt.Errorf("failed to convert APIResourceSchema to unstructured: %w", err) + } + unstructuredResource := &unstructured.Unstructured{Object: unstructuredObj} + + _, err = client.Resource(apiResourceSchemaGVR).Create(ctx, unstructuredResource, metav1.CreateOptions{}) + if err != nil { + fmt.Fprintf(errOut, "Failed to create APIResourceSchema for CRD %s: %v\n", apiResourceSchema.Name, err) + return err } + fmt.Fprintf(out, "Successfully created APIResourceSchema for CRD %s\n", apiResourceSchema.Name) return nil } @@ -196,3 +233,33 @@ func convertCRDToAPIResourceSchema(crd *apiextensionsv1.CustomResourceDefinition return apiResourceSchema, nil } + +func writeObjectToYAML(outputDir string, apiResourceSchema *kubebindv1alpha2.APIResourceSchema, logger io.Writer) error { + if err := os.MkdirAll(outputDir, 0755); err != nil { + return fmt.Errorf("failed to create output directory %s: %w", outputDir, err) + } + + scheme := runtime.NewScheme() + if err := kubebindv1alpha2.AddToScheme(scheme); err != nil { + return fmt.Errorf("failed to register kubebindv1alpha2 API group: %w", err) + } + + codecs := serializer.NewCodecFactory(scheme) + info, ok := runtime.SerializerInfoForMediaType(codecs.SupportedMediaTypes(), runtime.ContentTypeYAML) + if !ok { + return fmt.Errorf("unsupported media type %q", runtime.ContentTypeYAML) + } + encoder := codecs.EncoderForVersion(info.Serializer, kubebindv1alpha2.SchemeGroupVersion) + + out, err := runtime.Encode(encoder, apiResourceSchema) + if err != nil { + return fmt.Errorf("failed to encode APIResourceSchema %s: %w", apiResourceSchema.Name, err) + } + outputPath := filepath.Join(outputDir, fmt.Sprintf("%s.yaml", apiResourceSchema.Name)) + if err := os.WriteFile(outputPath, out, 0644); err != nil { + return fmt.Errorf("failed to write APIResourceSchema to file %s: %w", outputPath, err) + } + + fmt.Fprintf(logger, "Wrote APIResourceSchema %s to %s\n", apiResourceSchema.Name, outputPath) + return nil +} diff --git a/sdk/apis/kubebind/v1alpha2/apiresourceschema_types.go b/sdk/apis/kubebind/v1alpha2/apiresourceschema_types.go index f202cea1e..522dfd6fd 100644 --- a/sdk/apis/kubebind/v1alpha2/apiresourceschema_types.go +++ b/sdk/apis/kubebind/v1alpha2/apiresourceschema_types.go @@ -37,7 +37,6 @@ const ( // APIResourceSchema // +crd // +genclient -// +genclient:nonNamespaced // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object // +kubebuilder:resource:scope=Cluster,categories=kcp // +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp" diff --git a/sdk/client/clientset/versioned/typed/kubebind/v1alpha2/apiresourceschema.go b/sdk/client/clientset/versioned/typed/kubebind/v1alpha2/apiresourceschema.go index f5d39689d..501a6a2d4 100644 --- a/sdk/client/clientset/versioned/typed/kubebind/v1alpha2/apiresourceschema.go +++ b/sdk/client/clientset/versioned/typed/kubebind/v1alpha2/apiresourceschema.go @@ -33,7 +33,7 @@ import ( // APIResourceSchemasGetter has a method to return a APIResourceSchemaInterface. // A group's client should implement this interface. type APIResourceSchemasGetter interface { - APIResourceSchemas() APIResourceSchemaInterface + APIResourceSchemas(namespace string) APIResourceSchemaInterface } // APIResourceSchemaInterface has methods to work with APIResourceSchema resources. @@ -55,13 +55,13 @@ type aPIResourceSchemas struct { } // newAPIResourceSchemas returns a APIResourceSchemas -func newAPIResourceSchemas(c *KubeBindV1alpha2Client) *aPIResourceSchemas { +func newAPIResourceSchemas(c *KubeBindV1alpha2Client, namespace string) *aPIResourceSchemas { return &aPIResourceSchemas{ gentype.NewClientWithList[*v1alpha2.APIResourceSchema, *v1alpha2.APIResourceSchemaList]( "apiresourceschemas", c.RESTClient(), scheme.ParameterCodec, - "", + namespace, func() *v1alpha2.APIResourceSchema { return &v1alpha2.APIResourceSchema{} }, func() *v1alpha2.APIResourceSchemaList { return &v1alpha2.APIResourceSchemaList{} }), } diff --git a/sdk/client/clientset/versioned/typed/kubebind/v1alpha2/fake/fake_apiresourceschema.go b/sdk/client/clientset/versioned/typed/kubebind/v1alpha2/fake/fake_apiresourceschema.go index f747ed636..6ba06ccb8 100644 --- a/sdk/client/clientset/versioned/typed/kubebind/v1alpha2/fake/fake_apiresourceschema.go +++ b/sdk/client/clientset/versioned/typed/kubebind/v1alpha2/fake/fake_apiresourceschema.go @@ -33,6 +33,7 @@ import ( // FakeAPIResourceSchemas implements APIResourceSchemaInterface type FakeAPIResourceSchemas struct { Fake *FakeKubeBindV1alpha2 + ns string } var apiresourceschemasResource = v1alpha2.SchemeGroupVersion.WithResource("apiresourceschemas") @@ -43,7 +44,8 @@ var apiresourceschemasKind = v1alpha2.SchemeGroupVersion.WithKind("APIResourceSc func (c *FakeAPIResourceSchemas) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha2.APIResourceSchema, err error) { emptyResult := &v1alpha2.APIResourceSchema{} obj, err := c.Fake. - Invokes(testing.NewRootGetActionWithOptions(apiresourceschemasResource, name, options), emptyResult) + Invokes(testing.NewGetActionWithOptions(apiresourceschemasResource, c.ns, name, options), emptyResult) + if obj == nil { return emptyResult, err } @@ -54,7 +56,8 @@ func (c *FakeAPIResourceSchemas) Get(ctx context.Context, name string, options v func (c *FakeAPIResourceSchemas) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha2.APIResourceSchemaList, err error) { emptyResult := &v1alpha2.APIResourceSchemaList{} obj, err := c.Fake. - Invokes(testing.NewRootListActionWithOptions(apiresourceschemasResource, apiresourceschemasKind, opts), emptyResult) + Invokes(testing.NewListActionWithOptions(apiresourceschemasResource, apiresourceschemasKind, c.ns, opts), emptyResult) + if obj == nil { return emptyResult, err } @@ -75,14 +78,16 @@ func (c *FakeAPIResourceSchemas) List(ctx context.Context, opts v1.ListOptions) // Watch returns a watch.Interface that watches the requested aPIResourceSchemas. func (c *FakeAPIResourceSchemas) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { return c.Fake. - InvokesWatch(testing.NewRootWatchActionWithOptions(apiresourceschemasResource, opts)) + InvokesWatch(testing.NewWatchActionWithOptions(apiresourceschemasResource, c.ns, opts)) + } // Create takes the representation of a aPIResourceSchema and creates it. Returns the server's representation of the aPIResourceSchema, and an error, if there is any. func (c *FakeAPIResourceSchemas) Create(ctx context.Context, aPIResourceSchema *v1alpha2.APIResourceSchema, opts v1.CreateOptions) (result *v1alpha2.APIResourceSchema, err error) { emptyResult := &v1alpha2.APIResourceSchema{} obj, err := c.Fake. - Invokes(testing.NewRootCreateActionWithOptions(apiresourceschemasResource, aPIResourceSchema, opts), emptyResult) + Invokes(testing.NewCreateActionWithOptions(apiresourceschemasResource, c.ns, aPIResourceSchema, opts), emptyResult) + if obj == nil { return emptyResult, err } @@ -93,7 +98,8 @@ func (c *FakeAPIResourceSchemas) Create(ctx context.Context, aPIResourceSchema * func (c *FakeAPIResourceSchemas) Update(ctx context.Context, aPIResourceSchema *v1alpha2.APIResourceSchema, opts v1.UpdateOptions) (result *v1alpha2.APIResourceSchema, err error) { emptyResult := &v1alpha2.APIResourceSchema{} obj, err := c.Fake. - Invokes(testing.NewRootUpdateActionWithOptions(apiresourceschemasResource, aPIResourceSchema, opts), emptyResult) + Invokes(testing.NewUpdateActionWithOptions(apiresourceschemasResource, c.ns, aPIResourceSchema, opts), emptyResult) + if obj == nil { return emptyResult, err } @@ -103,13 +109,14 @@ func (c *FakeAPIResourceSchemas) Update(ctx context.Context, aPIResourceSchema * // Delete takes name of the aPIResourceSchema and deletes it. Returns an error if one occurs. func (c *FakeAPIResourceSchemas) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { _, err := c.Fake. - Invokes(testing.NewRootDeleteActionWithOptions(apiresourceschemasResource, name, opts), &v1alpha2.APIResourceSchema{}) + Invokes(testing.NewDeleteActionWithOptions(apiresourceschemasResource, c.ns, name, opts), &v1alpha2.APIResourceSchema{}) + return err } // DeleteCollection deletes a collection of objects. func (c *FakeAPIResourceSchemas) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { - action := testing.NewRootDeleteCollectionActionWithOptions(apiresourceschemasResource, opts, listOpts) + action := testing.NewDeleteCollectionActionWithOptions(apiresourceschemasResource, c.ns, opts, listOpts) _, err := c.Fake.Invokes(action, &v1alpha2.APIResourceSchemaList{}) return err @@ -119,7 +126,8 @@ func (c *FakeAPIResourceSchemas) DeleteCollection(ctx context.Context, opts v1.D func (c *FakeAPIResourceSchemas) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha2.APIResourceSchema, err error) { emptyResult := &v1alpha2.APIResourceSchema{} obj, err := c.Fake. - Invokes(testing.NewRootPatchSubresourceActionWithOptions(apiresourceschemasResource, name, pt, data, opts, subresources...), emptyResult) + Invokes(testing.NewPatchSubresourceActionWithOptions(apiresourceschemasResource, c.ns, name, pt, data, opts, subresources...), emptyResult) + if obj == nil { return emptyResult, err } diff --git a/sdk/client/clientset/versioned/typed/kubebind/v1alpha2/fake/fake_kubebind_client.go b/sdk/client/clientset/versioned/typed/kubebind/v1alpha2/fake/fake_kubebind_client.go index c2dddcabd..429226072 100644 --- a/sdk/client/clientset/versioned/typed/kubebind/v1alpha2/fake/fake_kubebind_client.go +++ b/sdk/client/clientset/versioned/typed/kubebind/v1alpha2/fake/fake_kubebind_client.go @@ -29,8 +29,8 @@ type FakeKubeBindV1alpha2 struct { *testing.Fake } -func (c *FakeKubeBindV1alpha2) APIResourceSchemas() v1alpha2.APIResourceSchemaInterface { - return &FakeAPIResourceSchemas{c} +func (c *FakeKubeBindV1alpha2) APIResourceSchemas(namespace string) v1alpha2.APIResourceSchemaInterface { + return &FakeAPIResourceSchemas{c, namespace} } // RESTClient returns a RESTClient that is used to communicate diff --git a/sdk/client/clientset/versioned/typed/kubebind/v1alpha2/kubebind_client.go b/sdk/client/clientset/versioned/typed/kubebind/v1alpha2/kubebind_client.go index 62ed02b04..1f77db9cc 100644 --- a/sdk/client/clientset/versioned/typed/kubebind/v1alpha2/kubebind_client.go +++ b/sdk/client/clientset/versioned/typed/kubebind/v1alpha2/kubebind_client.go @@ -37,8 +37,8 @@ type KubeBindV1alpha2Client struct { restClient rest.Interface } -func (c *KubeBindV1alpha2Client) APIResourceSchemas() APIResourceSchemaInterface { - return newAPIResourceSchemas(c) +func (c *KubeBindV1alpha2Client) APIResourceSchemas(namespace string) APIResourceSchemaInterface { + return newAPIResourceSchemas(c, namespace) } // NewForConfig creates a new KubeBindV1alpha2Client for the given config. diff --git a/sdk/client/informers/externalversions/kubebind/v1alpha2/apiresourceschema.go b/sdk/client/informers/externalversions/kubebind/v1alpha2/apiresourceschema.go index 48a248c3d..dd8e23ef0 100644 --- a/sdk/client/informers/externalversions/kubebind/v1alpha2/apiresourceschema.go +++ b/sdk/client/informers/externalversions/kubebind/v1alpha2/apiresourceschema.go @@ -43,32 +43,33 @@ type APIResourceSchemaInformer interface { type aPIResourceSchemaInformer struct { factory internalinterfaces.SharedInformerFactory tweakListOptions internalinterfaces.TweakListOptionsFunc + namespace string } // NewAPIResourceSchemaInformer constructs a new informer for APIResourceSchema type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server. -func NewAPIResourceSchemaInformer(client versioned.Interface, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { - return NewFilteredAPIResourceSchemaInformer(client, resyncPeriod, indexers, nil) +func NewAPIResourceSchemaInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return NewFilteredAPIResourceSchemaInformer(client, namespace, resyncPeriod, indexers, nil) } // NewFilteredAPIResourceSchemaInformer constructs a new informer for APIResourceSchema type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server. -func NewFilteredAPIResourceSchemaInformer(client versioned.Interface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { +func NewFilteredAPIResourceSchemaInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { return cache.NewSharedIndexInformer( &cache.ListWatch{ ListFunc: func(options v1.ListOptions) (runtime.Object, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.KubeBindV1alpha2().APIResourceSchemas().List(context.TODO(), options) + return client.KubeBindV1alpha2().APIResourceSchemas(namespace).List(context.TODO(), options) }, WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.KubeBindV1alpha2().APIResourceSchemas().Watch(context.TODO(), options) + return client.KubeBindV1alpha2().APIResourceSchemas(namespace).Watch(context.TODO(), options) }, }, &kubebindv1alpha2.APIResourceSchema{}, @@ -78,7 +79,7 @@ func NewFilteredAPIResourceSchemaInformer(client versioned.Interface, resyncPeri } func (f *aPIResourceSchemaInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { - return NewFilteredAPIResourceSchemaInformer(client, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) + return NewFilteredAPIResourceSchemaInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) } func (f *aPIResourceSchemaInformer) Informer() cache.SharedIndexInformer { diff --git a/sdk/client/informers/externalversions/kubebind/v1alpha2/interface.go b/sdk/client/informers/externalversions/kubebind/v1alpha2/interface.go index 52b0011e7..caee10c7f 100644 --- a/sdk/client/informers/externalversions/kubebind/v1alpha2/interface.go +++ b/sdk/client/informers/externalversions/kubebind/v1alpha2/interface.go @@ -41,5 +41,5 @@ func New(f internalinterfaces.SharedInformerFactory, namespace string, tweakList // APIResourceSchemas returns a APIResourceSchemaInformer. func (v *version) APIResourceSchemas() APIResourceSchemaInformer { - return &aPIResourceSchemaInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} + return &aPIResourceSchemaInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} } diff --git a/sdk/client/listers/kubebind/v1alpha2/apiresourceschema.go b/sdk/client/listers/kubebind/v1alpha2/apiresourceschema.go index f85a54dd9..f3cdcdac1 100644 --- a/sdk/client/listers/kubebind/v1alpha2/apiresourceschema.go +++ b/sdk/client/listers/kubebind/v1alpha2/apiresourceschema.go @@ -32,9 +32,8 @@ type APIResourceSchemaLister interface { // List lists all APIResourceSchemas in the indexer. // Objects returned here must be treated as read-only. List(selector labels.Selector) (ret []*v1alpha2.APIResourceSchema, err error) - // Get retrieves the APIResourceSchema from the index for a given name. - // Objects returned here must be treated as read-only. - Get(name string) (*v1alpha2.APIResourceSchema, error) + // APIResourceSchemas returns an object that can list and get APIResourceSchemas. + APIResourceSchemas(namespace string) APIResourceSchemaNamespaceLister APIResourceSchemaListerExpansion } @@ -47,3 +46,26 @@ type aPIResourceSchemaLister struct { func NewAPIResourceSchemaLister(indexer cache.Indexer) APIResourceSchemaLister { return &aPIResourceSchemaLister{listers.New[*v1alpha2.APIResourceSchema](indexer, v1alpha2.Resource("apiresourceschema"))} } + +// APIResourceSchemas returns an object that can list and get APIResourceSchemas. +func (s *aPIResourceSchemaLister) APIResourceSchemas(namespace string) APIResourceSchemaNamespaceLister { + return aPIResourceSchemaNamespaceLister{listers.NewNamespaced[*v1alpha2.APIResourceSchema](s.ResourceIndexer, namespace)} +} + +// APIResourceSchemaNamespaceLister helps list and get APIResourceSchemas. +// All objects returned here must be treated as read-only. +type APIResourceSchemaNamespaceLister interface { + // List lists all APIResourceSchemas in the indexer for a given namespace. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*v1alpha2.APIResourceSchema, err error) + // Get retrieves the APIResourceSchema from the indexer for a given namespace and name. + // Objects returned here must be treated as read-only. + Get(name string) (*v1alpha2.APIResourceSchema, error) + APIResourceSchemaNamespaceListerExpansion +} + +// aPIResourceSchemaNamespaceLister implements the APIResourceSchemaNamespaceLister +// interface. +type aPIResourceSchemaNamespaceLister struct { + listers.ResourceIndexer[*v1alpha2.APIResourceSchema] +} diff --git a/sdk/client/listers/kubebind/v1alpha2/expansion_generated.go b/sdk/client/listers/kubebind/v1alpha2/expansion_generated.go index e9a67bc79..f2287acf0 100644 --- a/sdk/client/listers/kubebind/v1alpha2/expansion_generated.go +++ b/sdk/client/listers/kubebind/v1alpha2/expansion_generated.go @@ -21,3 +21,7 @@ package v1alpha2 // APIResourceSchemaListerExpansion allows custom methods to be added to // APIResourceSchemaLister. type APIResourceSchemaListerExpansion interface{} + +// APIResourceSchemaNamespaceListerExpansion allows custom methods to be added to +// APIResourceSchemaNamespaceLister. +type APIResourceSchemaNamespaceListerExpansion interface{} diff --git a/sdk/kcp/clientset/versioned/cluster/typed/kubebind/v1alpha2/apiresourceschema.go b/sdk/kcp/clientset/versioned/cluster/typed/kubebind/v1alpha2/apiresourceschema.go index 953c45950..3672294f8 100644 --- a/sdk/kcp/clientset/versioned/cluster/typed/kubebind/v1alpha2/apiresourceschema.go +++ b/sdk/kcp/clientset/versioned/cluster/typed/kubebind/v1alpha2/apiresourceschema.go @@ -41,9 +41,9 @@ type APIResourceSchemasClusterGetter interface { } // APIResourceSchemaClusterInterface can operate on APIResourceSchemas across all clusters, -// or scope down to one cluster and return a kubebindv1alpha2client.APIResourceSchemaInterface. +// or scope down to one cluster and return a APIResourceSchemasNamespacer. type APIResourceSchemaClusterInterface interface { - Cluster(logicalcluster.Path) kubebindv1alpha2client.APIResourceSchemaInterface + Cluster(logicalcluster.Path) APIResourceSchemasNamespacer List(ctx context.Context, opts metav1.ListOptions) (*kubebindv1alpha2.APIResourceSchemaList, error) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) } @@ -53,20 +53,34 @@ type aPIResourceSchemasClusterInterface struct { } // Cluster scopes the client down to a particular cluster. -func (c *aPIResourceSchemasClusterInterface) Cluster(clusterPath logicalcluster.Path) kubebindv1alpha2client.APIResourceSchemaInterface { +func (c *aPIResourceSchemasClusterInterface) Cluster(clusterPath logicalcluster.Path) APIResourceSchemasNamespacer { if clusterPath == logicalcluster.Wildcard { panic("A specific cluster must be provided when scoping, not the wildcard.") } - return c.clientCache.ClusterOrDie(clusterPath).APIResourceSchemas() + return &aPIResourceSchemasNamespacer{clientCache: c.clientCache, clusterPath: clusterPath} } // List returns the entire collection of all APIResourceSchemas across all clusters. func (c *aPIResourceSchemasClusterInterface) List(ctx context.Context, opts metav1.ListOptions) (*kubebindv1alpha2.APIResourceSchemaList, error) { - return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).APIResourceSchemas().List(ctx, opts) + return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).APIResourceSchemas(metav1.NamespaceAll).List(ctx, opts) } // Watch begins to watch all APIResourceSchemas across all clusters. func (c *aPIResourceSchemasClusterInterface) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).APIResourceSchemas().Watch(ctx, opts) + return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).APIResourceSchemas(metav1.NamespaceAll).Watch(ctx, opts) +} + +// APIResourceSchemasNamespacer can scope to objects within a namespace, returning a kubebindv1alpha2client.APIResourceSchemaInterface. +type APIResourceSchemasNamespacer interface { + Namespace(string) kubebindv1alpha2client.APIResourceSchemaInterface +} + +type aPIResourceSchemasNamespacer struct { + clientCache kcpclient.Cache[*kubebindv1alpha2client.KubeBindV1alpha2Client] + clusterPath logicalcluster.Path +} + +func (n *aPIResourceSchemasNamespacer) Namespace(namespace string) kubebindv1alpha2client.APIResourceSchemaInterface { + return n.clientCache.ClusterOrDie(n.clusterPath).APIResourceSchemas(namespace) } diff --git a/sdk/kcp/clientset/versioned/cluster/typed/kubebind/v1alpha2/fake/apiresourceschema.go b/sdk/kcp/clientset/versioned/cluster/typed/kubebind/v1alpha2/fake/apiresourceschema.go index 726235f59..7bc22b869 100644 --- a/sdk/kcp/clientset/versioned/cluster/typed/kubebind/v1alpha2/fake/apiresourceschema.go +++ b/sdk/kcp/clientset/versioned/cluster/typed/kubebind/v1alpha2/fake/apiresourceschema.go @@ -38,6 +38,7 @@ import ( kubebindv1alpha2 "github.com/kube-bind/kube-bind/sdk/apis/kubebind/v1alpha2" applyconfigurationskubebindv1alpha2 "github.com/kube-bind/kube-bind/sdk/kcp/applyconfiguration/kubebind/v1alpha2" + kcpkubebindv1alpha2 "github.com/kube-bind/kube-bind/sdk/kcp/clientset/versioned/cluster/typed/kubebind/v1alpha2" kubebindv1alpha2client "github.com/kube-bind/kube-bind/sdk/kcp/clientset/versioned/typed/kubebind/v1alpha2" ) @@ -49,17 +50,17 @@ type aPIResourceSchemasClusterClient struct { } // Cluster scopes the client down to a particular cluster. -func (c *aPIResourceSchemasClusterClient) Cluster(clusterPath logicalcluster.Path) kubebindv1alpha2client.APIResourceSchemaInterface { +func (c *aPIResourceSchemasClusterClient) Cluster(clusterPath logicalcluster.Path) kcpkubebindv1alpha2.APIResourceSchemasNamespacer { if clusterPath == logicalcluster.Wildcard { panic("A specific cluster must be provided when scoping, not the wildcard.") } - return &aPIResourceSchemasClient{Fake: c.Fake, ClusterPath: clusterPath} + return &aPIResourceSchemasNamespacer{Fake: c.Fake, ClusterPath: clusterPath} } // List takes label and field selectors, and returns the list of APIResourceSchemas that match those selectors across all clusters. func (c *aPIResourceSchemasClusterClient) List(ctx context.Context, opts metav1.ListOptions) (*kubebindv1alpha2.APIResourceSchemaList, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootListAction(aPIResourceSchemasResource, aPIResourceSchemasKind, logicalcluster.Wildcard, opts), &kubebindv1alpha2.APIResourceSchemaList{}) + obj, err := c.Fake.Invokes(kcptesting.NewListAction(aPIResourceSchemasResource, aPIResourceSchemasKind, logicalcluster.Wildcard, metav1.NamespaceAll, opts), &kubebindv1alpha2.APIResourceSchemaList{}) if obj == nil { return nil, err } @@ -79,16 +80,26 @@ func (c *aPIResourceSchemasClusterClient) List(ctx context.Context, opts metav1. // Watch returns a watch.Interface that watches the requested APIResourceSchemas across all clusters. func (c *aPIResourceSchemasClusterClient) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - return c.Fake.InvokesWatch(kcptesting.NewRootWatchAction(aPIResourceSchemasResource, logicalcluster.Wildcard, opts)) + return c.Fake.InvokesWatch(kcptesting.NewWatchAction(aPIResourceSchemasResource, logicalcluster.Wildcard, metav1.NamespaceAll, opts)) +} + +type aPIResourceSchemasNamespacer struct { + *kcptesting.Fake + ClusterPath logicalcluster.Path +} + +func (n *aPIResourceSchemasNamespacer) Namespace(namespace string) kubebindv1alpha2client.APIResourceSchemaInterface { + return &aPIResourceSchemasClient{Fake: n.Fake, ClusterPath: n.ClusterPath, Namespace: namespace} } type aPIResourceSchemasClient struct { *kcptesting.Fake ClusterPath logicalcluster.Path + Namespace string } func (c *aPIResourceSchemasClient) Create(ctx context.Context, aPIResourceSchema *kubebindv1alpha2.APIResourceSchema, opts metav1.CreateOptions) (*kubebindv1alpha2.APIResourceSchema, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootCreateAction(aPIResourceSchemasResource, c.ClusterPath, aPIResourceSchema), &kubebindv1alpha2.APIResourceSchema{}) + obj, err := c.Fake.Invokes(kcptesting.NewCreateAction(aPIResourceSchemasResource, c.ClusterPath, c.Namespace, aPIResourceSchema), &kubebindv1alpha2.APIResourceSchema{}) if obj == nil { return nil, err } @@ -96,7 +107,7 @@ func (c *aPIResourceSchemasClient) Create(ctx context.Context, aPIResourceSchema } func (c *aPIResourceSchemasClient) Update(ctx context.Context, aPIResourceSchema *kubebindv1alpha2.APIResourceSchema, opts metav1.UpdateOptions) (*kubebindv1alpha2.APIResourceSchema, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootUpdateAction(aPIResourceSchemasResource, c.ClusterPath, aPIResourceSchema), &kubebindv1alpha2.APIResourceSchema{}) + obj, err := c.Fake.Invokes(kcptesting.NewUpdateAction(aPIResourceSchemasResource, c.ClusterPath, c.Namespace, aPIResourceSchema), &kubebindv1alpha2.APIResourceSchema{}) if obj == nil { return nil, err } @@ -104,7 +115,7 @@ func (c *aPIResourceSchemasClient) Update(ctx context.Context, aPIResourceSchema } func (c *aPIResourceSchemasClient) UpdateStatus(ctx context.Context, aPIResourceSchema *kubebindv1alpha2.APIResourceSchema, opts metav1.UpdateOptions) (*kubebindv1alpha2.APIResourceSchema, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootUpdateSubresourceAction(aPIResourceSchemasResource, c.ClusterPath, "status", aPIResourceSchema), &kubebindv1alpha2.APIResourceSchema{}) + obj, err := c.Fake.Invokes(kcptesting.NewUpdateSubresourceAction(aPIResourceSchemasResource, c.ClusterPath, "status", c.Namespace, aPIResourceSchema), &kubebindv1alpha2.APIResourceSchema{}) if obj == nil { return nil, err } @@ -112,19 +123,19 @@ func (c *aPIResourceSchemasClient) UpdateStatus(ctx context.Context, aPIResource } func (c *aPIResourceSchemasClient) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { - _, err := c.Fake.Invokes(kcptesting.NewRootDeleteActionWithOptions(aPIResourceSchemasResource, c.ClusterPath, name, opts), &kubebindv1alpha2.APIResourceSchema{}) + _, err := c.Fake.Invokes(kcptesting.NewDeleteActionWithOptions(aPIResourceSchemasResource, c.ClusterPath, c.Namespace, name, opts), &kubebindv1alpha2.APIResourceSchema{}) return err } func (c *aPIResourceSchemasClient) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { - action := kcptesting.NewRootDeleteCollectionAction(aPIResourceSchemasResource, c.ClusterPath, listOpts) + action := kcptesting.NewDeleteCollectionAction(aPIResourceSchemasResource, c.ClusterPath, c.Namespace, listOpts) _, err := c.Fake.Invokes(action, &kubebindv1alpha2.APIResourceSchemaList{}) return err } func (c *aPIResourceSchemasClient) Get(ctx context.Context, name string, options metav1.GetOptions) (*kubebindv1alpha2.APIResourceSchema, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootGetAction(aPIResourceSchemasResource, c.ClusterPath, name), &kubebindv1alpha2.APIResourceSchema{}) + obj, err := c.Fake.Invokes(kcptesting.NewGetAction(aPIResourceSchemasResource, c.ClusterPath, c.Namespace, name), &kubebindv1alpha2.APIResourceSchema{}) if obj == nil { return nil, err } @@ -133,7 +144,7 @@ func (c *aPIResourceSchemasClient) Get(ctx context.Context, name string, options // List takes label and field selectors, and returns the list of APIResourceSchemas that match those selectors. func (c *aPIResourceSchemasClient) List(ctx context.Context, opts metav1.ListOptions) (*kubebindv1alpha2.APIResourceSchemaList, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootListAction(aPIResourceSchemasResource, aPIResourceSchemasKind, c.ClusterPath, opts), &kubebindv1alpha2.APIResourceSchemaList{}) + obj, err := c.Fake.Invokes(kcptesting.NewListAction(aPIResourceSchemasResource, aPIResourceSchemasKind, c.ClusterPath, c.Namespace, opts), &kubebindv1alpha2.APIResourceSchemaList{}) if obj == nil { return nil, err } @@ -152,11 +163,11 @@ func (c *aPIResourceSchemasClient) List(ctx context.Context, opts metav1.ListOpt } func (c *aPIResourceSchemasClient) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { - return c.Fake.InvokesWatch(kcptesting.NewRootWatchAction(aPIResourceSchemasResource, c.ClusterPath, opts)) + return c.Fake.InvokesWatch(kcptesting.NewWatchAction(aPIResourceSchemasResource, c.ClusterPath, c.Namespace, opts)) } func (c *aPIResourceSchemasClient) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (*kubebindv1alpha2.APIResourceSchema, error) { - obj, err := c.Fake.Invokes(kcptesting.NewRootPatchSubresourceAction(aPIResourceSchemasResource, c.ClusterPath, name, pt, data, subresources...), &kubebindv1alpha2.APIResourceSchema{}) + obj, err := c.Fake.Invokes(kcptesting.NewPatchSubresourceAction(aPIResourceSchemasResource, c.ClusterPath, c.Namespace, name, pt, data, subresources...), &kubebindv1alpha2.APIResourceSchema{}) if obj == nil { return nil, err } @@ -175,7 +186,7 @@ func (c *aPIResourceSchemasClient) Apply(ctx context.Context, applyConfiguration if name == nil { return nil, fmt.Errorf("applyConfiguration.Name must be provided to Apply") } - obj, err := c.Fake.Invokes(kcptesting.NewRootPatchSubresourceAction(aPIResourceSchemasResource, c.ClusterPath, *name, types.ApplyPatchType, data), &kubebindv1alpha2.APIResourceSchema{}) + obj, err := c.Fake.Invokes(kcptesting.NewPatchSubresourceAction(aPIResourceSchemasResource, c.ClusterPath, c.Namespace, *name, types.ApplyPatchType, data), &kubebindv1alpha2.APIResourceSchema{}) if obj == nil { return nil, err } @@ -194,7 +205,7 @@ func (c *aPIResourceSchemasClient) ApplyStatus(ctx context.Context, applyConfigu if name == nil { return nil, fmt.Errorf("applyConfiguration.Name must be provided to Apply") } - obj, err := c.Fake.Invokes(kcptesting.NewRootPatchSubresourceAction(aPIResourceSchemasResource, c.ClusterPath, *name, types.ApplyPatchType, data, "status"), &kubebindv1alpha2.APIResourceSchema{}) + obj, err := c.Fake.Invokes(kcptesting.NewPatchSubresourceAction(aPIResourceSchemasResource, c.ClusterPath, c.Namespace, *name, types.ApplyPatchType, data, "status"), &kubebindv1alpha2.APIResourceSchema{}) if obj == nil { return nil, err } diff --git a/sdk/kcp/clientset/versioned/cluster/typed/kubebind/v1alpha2/fake/kubebind_client.go b/sdk/kcp/clientset/versioned/cluster/typed/kubebind/v1alpha2/fake/kubebind_client.go index c6aa54f2e..3131126b7 100644 --- a/sdk/kcp/clientset/versioned/cluster/typed/kubebind/v1alpha2/fake/kubebind_client.go +++ b/sdk/kcp/clientset/versioned/cluster/typed/kubebind/v1alpha2/fake/kubebind_client.go @@ -60,6 +60,6 @@ func (c *KubeBindV1alpha2Client) RESTClient() rest.Interface { return ret } -func (c *KubeBindV1alpha2Client) APIResourceSchemas() kubebindv1alpha2.APIResourceSchemaInterface { - return &aPIResourceSchemasClient{Fake: c.Fake, ClusterPath: c.ClusterPath} +func (c *KubeBindV1alpha2Client) APIResourceSchemas(namespace string) kubebindv1alpha2.APIResourceSchemaInterface { + return &aPIResourceSchemasClient{Fake: c.Fake, ClusterPath: c.ClusterPath, Namespace: namespace} } diff --git a/sdk/kcp/informers/externalversions/kubebind/v1alpha2/apiresourceschema.go b/sdk/kcp/informers/externalversions/kubebind/v1alpha2/apiresourceschema.go index 5713459d6..a01baaf3b 100644 --- a/sdk/kcp/informers/externalversions/kubebind/v1alpha2/apiresourceschema.go +++ b/sdk/kcp/informers/externalversions/kubebind/v1alpha2/apiresourceschema.go @@ -88,8 +88,8 @@ func NewFilteredAPIResourceSchemaClusterInformer(client clientset.ClusterInterfa func (f *aPIResourceSchemaClusterInformer) defaultInformer(client clientset.ClusterInterface, resyncPeriod time.Duration) kcpcache.ScopeableSharedIndexInformer { return NewFilteredAPIResourceSchemaClusterInformer(client, resyncPeriod, cache.Indexers{ - kcpcache.ClusterIndexName: kcpcache.ClusterIndexFunc, - }, + kcpcache.ClusterIndexName: kcpcache.ClusterIndexFunc, + kcpcache.ClusterAndNamespaceIndexName: kcpcache.ClusterAndNamespaceIndexFunc}, f.tweakListOptions, ) } @@ -132,6 +132,7 @@ func (f *aPIResourceSchemaInformer) Lister() kubebindv1alpha2listers.APIResource type aPIResourceSchemaScopedInformer struct { factory internalinterfaces.SharedScopedInformerFactory tweakListOptions internalinterfaces.TweakListOptionsFunc + namespace string } func (f *aPIResourceSchemaScopedInformer) Informer() cache.SharedIndexInformer { @@ -145,27 +146,27 @@ func (f *aPIResourceSchemaScopedInformer) Lister() kubebindv1alpha2listers.APIRe // NewAPIResourceSchemaInformer constructs a new informer for APIResourceSchema type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server. -func NewAPIResourceSchemaInformer(client scopedclientset.Interface, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { - return NewFilteredAPIResourceSchemaInformer(client, resyncPeriod, indexers, nil) +func NewAPIResourceSchemaInformer(client scopedclientset.Interface, resyncPeriod time.Duration, namespace string, indexers cache.Indexers) cache.SharedIndexInformer { + return NewFilteredAPIResourceSchemaInformer(client, resyncPeriod, namespace, indexers, nil) } // NewFilteredAPIResourceSchemaInformer constructs a new informer for APIResourceSchema type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server. -func NewFilteredAPIResourceSchemaInformer(client scopedclientset.Interface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { +func NewFilteredAPIResourceSchemaInformer(client scopedclientset.Interface, resyncPeriod time.Duration, namespace string, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { return cache.NewSharedIndexInformer( &cache.ListWatch{ ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.KubeBindV1alpha2().APIResourceSchemas().List(context.TODO(), options) + return client.KubeBindV1alpha2().APIResourceSchemas(namespace).List(context.TODO(), options) }, WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.KubeBindV1alpha2().APIResourceSchemas().Watch(context.TODO(), options) + return client.KubeBindV1alpha2().APIResourceSchemas(namespace).Watch(context.TODO(), options) }, }, &kubebindv1alpha2.APIResourceSchema{}, @@ -175,5 +176,7 @@ func NewFilteredAPIResourceSchemaInformer(client scopedclientset.Interface, resy } func (f *aPIResourceSchemaScopedInformer) defaultInformer(client scopedclientset.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { - return NewFilteredAPIResourceSchemaInformer(client, resyncPeriod, cache.Indexers{}, f.tweakListOptions) + return NewFilteredAPIResourceSchemaInformer(client, resyncPeriod, f.namespace, cache.Indexers{ + cache.NamespaceIndex: cache.MetaNamespaceIndexFunc, + }, f.tweakListOptions) } diff --git a/sdk/kcp/informers/externalversions/kubebind/v1alpha2/interface.go b/sdk/kcp/informers/externalversions/kubebind/v1alpha2/interface.go index bd5325322..b48ba3bb2 100644 --- a/sdk/kcp/informers/externalversions/kubebind/v1alpha2/interface.go +++ b/sdk/kcp/informers/externalversions/kubebind/v1alpha2/interface.go @@ -63,5 +63,5 @@ func NewScoped(f internalinterfaces.SharedScopedInformerFactory, namespace strin // APIResourceSchemas returns a APIResourceSchemaInformer func (v *scopedVersion) APIResourceSchemas() APIResourceSchemaInformer { - return &aPIResourceSchemaScopedInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} + return &aPIResourceSchemaScopedInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} } diff --git a/sdk/kcp/listers/kubebind/v1alpha2/apiresourceschema.go b/sdk/kcp/listers/kubebind/v1alpha2/apiresourceschema.go index 99025a512..5498fd446 100644 --- a/sdk/kcp/listers/kubebind/v1alpha2/apiresourceschema.go +++ b/sdk/kcp/listers/kubebind/v1alpha2/apiresourceschema.go @@ -52,6 +52,7 @@ type aPIResourceSchemaClusterLister struct { // - is fed by a cross-workspace LIST+WATCH // - uses kcpcache.MetaClusterNamespaceKeyFunc as the key function // - has the kcpcache.ClusterIndex as an index +// - has the kcpcache.ClusterAndNamespaceIndex as an index func NewAPIResourceSchemaClusterLister(indexer cache.Indexer) *aPIResourceSchemaClusterLister { return &aPIResourceSchemaClusterLister{indexer: indexer} } @@ -69,19 +70,18 @@ func (s *aPIResourceSchemaClusterLister) Cluster(clusterName logicalcluster.Name return &aPIResourceSchemaLister{indexer: s.indexer, clusterName: clusterName} } -// APIResourceSchemaLister can list all APIResourceSchemas, or get one in particular. +// APIResourceSchemaLister can list APIResourceSchemas across all namespaces, or scope down to a APIResourceSchemaNamespaceLister for one namespace. // All objects returned here must be treated as read-only. type APIResourceSchemaLister interface { // List lists all APIResourceSchemas in the workspace. // Objects returned here must be treated as read-only. List(selector labels.Selector) (ret []*kubebindv1alpha2.APIResourceSchema, err error) - // Get retrieves the APIResourceSchema from the indexer for a given workspace and name. - // Objects returned here must be treated as read-only. - Get(name string) (*kubebindv1alpha2.APIResourceSchema, error) + // APIResourceSchemas returns a lister that can list and get APIResourceSchemas in one workspace and namespace. + APIResourceSchemas(namespace string) APIResourceSchemaNamespaceLister APIResourceSchemaListerExpansion } -// aPIResourceSchemaLister can list all APIResourceSchemas inside a workspace. +// aPIResourceSchemaLister can list all APIResourceSchemas inside a workspace or scope down to a APIResourceSchemaLister for one namespace. type aPIResourceSchemaLister struct { indexer cache.Indexer clusterName logicalcluster.Name @@ -95,9 +95,42 @@ func (s *aPIResourceSchemaLister) List(selector labels.Selector) (ret []*kubebin return ret, err } -// Get retrieves the APIResourceSchema from the indexer for a given workspace and name. -func (s *aPIResourceSchemaLister) Get(name string) (*kubebindv1alpha2.APIResourceSchema, error) { - key := kcpcache.ToClusterAwareKey(s.clusterName.String(), "", name) +// APIResourceSchemas returns an object that can list and get APIResourceSchemas in one namespace. +func (s *aPIResourceSchemaLister) APIResourceSchemas(namespace string) APIResourceSchemaNamespaceLister { + return &aPIResourceSchemaNamespaceLister{indexer: s.indexer, clusterName: s.clusterName, namespace: namespace} +} + +// aPIResourceSchemaNamespaceLister helps list and get APIResourceSchemas. +// All objects returned here must be treated as read-only. +type APIResourceSchemaNamespaceLister interface { + // List lists all APIResourceSchemas in the workspace and namespace. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*kubebindv1alpha2.APIResourceSchema, err error) + // Get retrieves the APIResourceSchema from the indexer for a given workspace, namespace and name. + // Objects returned here must be treated as read-only. + Get(name string) (*kubebindv1alpha2.APIResourceSchema, error) + APIResourceSchemaNamespaceListerExpansion +} + +// aPIResourceSchemaNamespaceLister helps list and get APIResourceSchemas. +// All objects returned here must be treated as read-only. +type aPIResourceSchemaNamespaceLister struct { + indexer cache.Indexer + clusterName logicalcluster.Name + namespace string +} + +// List lists all APIResourceSchemas in the indexer for a given workspace and namespace. +func (s *aPIResourceSchemaNamespaceLister) List(selector labels.Selector) (ret []*kubebindv1alpha2.APIResourceSchema, err error) { + err = kcpcache.ListAllByClusterAndNamespace(s.indexer, s.clusterName, s.namespace, selector, func(i interface{}) { + ret = append(ret, i.(*kubebindv1alpha2.APIResourceSchema)) + }) + return ret, err +} + +// Get retrieves the APIResourceSchema from the indexer for a given workspace, namespace and name. +func (s *aPIResourceSchemaNamespaceLister) Get(name string) (*kubebindv1alpha2.APIResourceSchema, error) { + key := kcpcache.ToClusterAwareKey(s.clusterName.String(), s.namespace, name) obj, exists, err := s.indexer.GetByKey(key) if err != nil { return nil, err @@ -112,11 +145,12 @@ func (s *aPIResourceSchemaLister) Get(name string) (*kubebindv1alpha2.APIResourc // We assume that the indexer: // - is fed by a workspace-scoped LIST+WATCH // - uses cache.MetaNamespaceKeyFunc as the key function +// - has the cache.NamespaceIndex as an index func NewAPIResourceSchemaLister(indexer cache.Indexer) *aPIResourceSchemaScopedLister { return &aPIResourceSchemaScopedLister{indexer: indexer} } -// aPIResourceSchemaScopedLister can list all APIResourceSchemas inside a workspace. +// aPIResourceSchemaScopedLister can list all APIResourceSchemas inside a workspace or scope down to a APIResourceSchemaLister for one namespace. type aPIResourceSchemaScopedLister struct { indexer cache.Indexer } @@ -129,9 +163,28 @@ func (s *aPIResourceSchemaScopedLister) List(selector labels.Selector) (ret []*k return ret, err } -// Get retrieves the APIResourceSchema from the indexer for a given workspace and name. -func (s *aPIResourceSchemaScopedLister) Get(name string) (*kubebindv1alpha2.APIResourceSchema, error) { - key := name +// APIResourceSchemas returns an object that can list and get APIResourceSchemas in one namespace. +func (s *aPIResourceSchemaScopedLister) APIResourceSchemas(namespace string) APIResourceSchemaNamespaceLister { + return &aPIResourceSchemaScopedNamespaceLister{indexer: s.indexer, namespace: namespace} +} + +// aPIResourceSchemaScopedNamespaceLister helps list and get APIResourceSchemas. +type aPIResourceSchemaScopedNamespaceLister struct { + indexer cache.Indexer + namespace string +} + +// List lists all APIResourceSchemas in the indexer for a given workspace and namespace. +func (s *aPIResourceSchemaScopedNamespaceLister) List(selector labels.Selector) (ret []*kubebindv1alpha2.APIResourceSchema, err error) { + err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(i interface{}) { + ret = append(ret, i.(*kubebindv1alpha2.APIResourceSchema)) + }) + return ret, err +} + +// Get retrieves the APIResourceSchema from the indexer for a given workspace, namespace and name. +func (s *aPIResourceSchemaScopedNamespaceLister) Get(name string) (*kubebindv1alpha2.APIResourceSchema, error) { + key := s.namespace + "/" + name obj, exists, err := s.indexer.GetByKey(key) if err != nil { return nil, err From d2d76bf1b15d9237f41dc430046b6bb131919d1b Mon Sep 17 00:00:00 2001 From: Karol Szwaj Date: Tue, 29 Apr 2025 12:48:35 +0200 Subject: [PATCH 7/8] restore namespaced apiresourceschema On-behalf-of: @SAP karol.szwaj@sap.com --- cli/pkg/crd2apiresourceschema/cmd/cmd.go | 10 ++++++++-- deploy/crd/kube-bind.io_apiresourceschemas.yaml | 4 ++-- sdk/apis/kubebind/v1alpha2/apiresourceschema_types.go | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/cli/pkg/crd2apiresourceschema/cmd/cmd.go b/cli/pkg/crd2apiresourceschema/cmd/cmd.go index d7e52a1af..b7dccc582 100644 --- a/cli/pkg/crd2apiresourceschema/cmd/cmd.go +++ b/cli/pkg/crd2apiresourceschema/cmd/cmd.go @@ -29,11 +29,17 @@ import ( var ( CRD2APIResourceSchemaUses = ` +# Generate APIResourceSchemas from provided CRDs in the cluster and save them to YAML files in the specified output directory +crd2apiresourceschema --output-dir /output/dir + +# Generate APIResourceSchemas from provided CRDs in the cluster and save them to YAML files, specifying a different kubeconfig and output directory +crd2apiresourceschema --kubeconfig /path/to/your/kubeconfig --output-dir /path/to/output/dir + # Generate and create APIResourceSchema objects for all CRDs in the cluster -crd2apiresourceschema --kubeconfig ~/.kube/config +crd2apiresourceschema --generate-in-cluster # Generate and create APIResourceSchema objects for all CRDs in the cluster, specifying a different kubeconfig -crd2apiresourceschema --kubeconfig /path/to/your/kubeconfig +crd2apiresourceschema --kubeconfig /path/to/your/kubeconfig --generate-in-cluster ` ) diff --git a/deploy/crd/kube-bind.io_apiresourceschemas.yaml b/deploy/crd/kube-bind.io_apiresourceschemas.yaml index 53760a054..6d9eb6887 100644 --- a/deploy/crd/kube-bind.io_apiresourceschemas.yaml +++ b/deploy/crd/kube-bind.io_apiresourceschemas.yaml @@ -9,12 +9,12 @@ spec: group: kube-bind.io names: categories: - - kcp + - kube-bindings kind: APIResourceSchema listKind: APIResourceSchemaList plural: apiresourceschemas singular: apiresourceschema - scope: Cluster + scope: Namespaced versions: - additionalPrinterColumns: - jsonPath: .metadata.creationTimestamp diff --git a/sdk/apis/kubebind/v1alpha2/apiresourceschema_types.go b/sdk/apis/kubebind/v1alpha2/apiresourceschema_types.go index 522dfd6fd..812741219 100644 --- a/sdk/apis/kubebind/v1alpha2/apiresourceschema_types.go +++ b/sdk/apis/kubebind/v1alpha2/apiresourceschema_types.go @@ -38,7 +38,7 @@ const ( // +crd // +genclient // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object -// +kubebuilder:resource:scope=Cluster,categories=kcp +// +kubebuilder:resource:scope=Namespaced,categories=kube-bindings // +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp" type APIResourceSchema struct { metav1.TypeMeta `json:",inline"` From bbf9a9fabcc0a68695fb6758eb14c4676035b86e Mon Sep 17 00:00:00 2001 From: Karol Szwaj Date: Fri, 2 May 2025 14:03:01 +0200 Subject: [PATCH 8/8] Update cli/pkg/crd2apiresourceschema/plugin/crd2apiresourceschema.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- cli/pkg/crd2apiresourceschema/plugin/crd2apiresourceschema.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/pkg/crd2apiresourceschema/plugin/crd2apiresourceschema.go b/cli/pkg/crd2apiresourceschema/plugin/crd2apiresourceschema.go index 1271f05fb..16252af56 100644 --- a/cli/pkg/crd2apiresourceschema/plugin/crd2apiresourceschema.go +++ b/cli/pkg/crd2apiresourceschema/plugin/crd2apiresourceschema.go @@ -180,7 +180,7 @@ func convertCRDToAPIResourceSchema(crd *apiextensionsv1.CustomResourceDefinition } if len(crd.Spec.Versions) > 1 && crd.Spec.Conversion == nil { - return nil, fmt.Errorf("multiple versions specified but no conversion strategy") + return nil, fmt.Errorf("multiple versions specified for CRD %q but no conversion strategy", crd.Name) } if crd.Spec.Conversion != nil {