diff --git a/Makefile b/Makefile index 3f1ae4682..3eebd8f9a 100644 --- a/Makefile +++ b/Makefile @@ -20,7 +20,7 @@ TOOLS_DIR=hack/tools GOBIN_DIR := $(abspath $(TOOLS_DIR)) TMPDIR := $(shell mktemp -d) -CONTROLLER_GEN_VER := v0.16.1 +CONTROLLER_GEN_VER := v0.16.5 CONTROLLER_GEN_BIN := controller-gen CONTROLLER_GEN := $(GOBIN_DIR)/$(CONTROLLER_GEN_BIN)-$(CONTROLLER_GEN_VER) export CONTROLLER_GEN diff --git a/examples/pkg/apis/exampledashed/doc.go b/examples/pkg/apis/exampledashed/doc.go new file mode 100644 index 000000000..574f2f997 --- /dev/null +++ b/examples/pkg/apis/exampledashed/doc.go @@ -0,0 +1,22 @@ +/* +Copyright 2021 The KCP 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 exampledashed + +const ( + // GroupName is the group name use in this package. + GroupName = "example-dashed.some.corp" +) diff --git a/examples/pkg/apis/exampledashed/v1/doc.go b/examples/pkg/apis/exampledashed/v1/doc.go new file mode 100644 index 000000000..6adf1cdd6 --- /dev/null +++ b/examples/pkg/apis/exampledashed/v1/doc.go @@ -0,0 +1,23 @@ +/* +Copyright 2022 The KCP 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 v1 contains API Schema definitions for the example-dashed.some.corp +// v1 API group. +// +// +k8s:deepcopy-gen=package,register +// +groupName=example-dashed.some.corp +// +groupGoName=ExampleDashed +package v1 diff --git a/examples/pkg/apis/exampledashed/v1/register.go b/examples/pkg/apis/exampledashed/v1/register.go new file mode 100644 index 000000000..fba99ff2b --- /dev/null +++ b/examples/pkg/apis/exampledashed/v1/register.go @@ -0,0 +1,55 @@ +/* +Copyright 2021 The KCP 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 v1 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/schema" + + example "acme.corp/pkg/apis/exampledashed" +) + +// SchemeGroupVersion is group version used to register these objects. +var SchemeGroupVersion = schema.GroupVersion{Group: example.GroupName, Version: "v1"} + +// Kind takes an unqualified kind and returns back a Group qualified GroupKind. +func Kind(kind string) schema.GroupKind { + return SchemeGroupVersion.WithKind(kind).GroupKind() +} + +// Resource takes an unqualified resource and returns a Group qualified GroupResource. +func Resource(resource string) schema.GroupResource { + return SchemeGroupVersion.WithResource(resource).GroupResource() +} + +var ( + SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes) + AddToScheme = SchemeBuilder.AddToScheme +) + +// Adds the list of known types to Scheme. +func addKnownTypes(scheme *runtime.Scheme) error { + scheme.AddKnownTypes(SchemeGroupVersion, + &TestType{}, + &TestTypeList{}, + &ClusterTestType{}, + &ClusterTestTypeList{}, + ) + metav1.AddToGroupVersion(scheme, SchemeGroupVersion) + return nil +} diff --git a/examples/pkg/apis/exampledashed/v1/types.go b/examples/pkg/apis/exampledashed/v1/types.go new file mode 100644 index 000000000..1f1a48209 --- /dev/null +++ b/examples/pkg/apis/exampledashed/v1/types.go @@ -0,0 +1,70 @@ +/* +Copyright 2022 The KCP 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 v1 + +import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + +// +genclient +// +genclient:noStatus +// +genclient:method=CreateField,verb=create,subresource=field,input=acme.corp/pkg/apis/example/v1.Field,result=acme.corp/pkg/apis/example/v1.Field +// +genclient:method=UpdateField,verb=update,subresource=field,input=acme.corp/pkg/apis/example/v1.Field,result=acme.corp/pkg/apis/example/v1.Field +// +genclient:method=GetField,verb=get,subresource=field,result=acme.corp/pkg/apis/example/v1.Field +// TestType is a top-level type. A client is created for it. +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object +type TestType struct { + metav1.TypeMeta `json:",inline"` + // +optional + metav1.ObjectMeta `json:"metadata,omitempty"` + // +optional + APIGroups []string `json:"apiGroups,omitempty"` +} + +// TestTypeList is a top-level list type. The client methods for lists are automatically created. +// You are not supposed to create a separated client for this one. +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object +type TestTypeList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata"` + Items []TestType `json:"items"` +} + +// +genclient +// +genclient:nonNamespaced +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object +type ClusterTestType struct { + metav1.TypeMeta `json:",inline"` + // +optional + metav1.ObjectMeta `json:"metadata,omitempty"` + // ObjectKind is the type of resource being referenced + ObjectKind string `json:"kind"` + // ObjectName is the name of resource being referenced + ObjectName string `json:"name"` + // +optional + Status ClusterTestTypeStatus `json:"status,omitempty"` +} + +type ClusterTestTypeStatus struct { + Blah string `json:"blah,omitempty"` +} + +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object +type ClusterTestTypeList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata"` + + Items []ClusterTestType `json:"items"` +} diff --git a/examples/pkg/apis/exampledashed/v1/zz_generated.deepcopy.go b/examples/pkg/apis/exampledashed/v1/zz_generated.deepcopy.go new file mode 100644 index 000000000..137615d31 --- /dev/null +++ b/examples/pkg/apis/exampledashed/v1/zz_generated.deepcopy.go @@ -0,0 +1,144 @@ +//go:build !ignore_autogenerated + +// Code generated by controller-gen. DO NOT EDIT. + +package v1 + +import ( + "k8s.io/apimachinery/pkg/runtime" +) + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ClusterTestType) DeepCopyInto(out *ClusterTestType) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + out.Status = in.Status +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterTestType. +func (in *ClusterTestType) DeepCopy() *ClusterTestType { + if in == nil { + return nil + } + out := new(ClusterTestType) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *ClusterTestType) 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 *ClusterTestTypeList) DeepCopyInto(out *ClusterTestTypeList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]ClusterTestType, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterTestTypeList. +func (in *ClusterTestTypeList) DeepCopy() *ClusterTestTypeList { + if in == nil { + return nil + } + out := new(ClusterTestTypeList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *ClusterTestTypeList) 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 *ClusterTestTypeStatus) DeepCopyInto(out *ClusterTestTypeStatus) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterTestTypeStatus. +func (in *ClusterTestTypeStatus) DeepCopy() *ClusterTestTypeStatus { + if in == nil { + return nil + } + out := new(ClusterTestTypeStatus) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *TestType) DeepCopyInto(out *TestType) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + if in.APIGroups != nil { + in, out := &in.APIGroups, &out.APIGroups + *out = make([]string, len(*in)) + copy(*out, *in) + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TestType. +func (in *TestType) DeepCopy() *TestType { + if in == nil { + return nil + } + out := new(TestType) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *TestType) 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 *TestTypeList) DeepCopyInto(out *TestTypeList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]TestType, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TestTypeList. +func (in *TestTypeList) DeepCopy() *TestTypeList { + if in == nil { + return nil + } + out := new(TestTypeList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *TestTypeList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} diff --git a/examples/pkg/generated/applyconfigurations/exampledashed/v1/clustertesttype.go b/examples/pkg/generated/applyconfigurations/exampledashed/v1/clustertesttype.go new file mode 100644 index 000000000..74c16fc78 --- /dev/null +++ b/examples/pkg/generated/applyconfigurations/exampledashed/v1/clustertesttype.go @@ -0,0 +1,233 @@ +/* +Copyright The KCP 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 applyconfiguration-gen-v0.31. DO NOT EDIT. + +package v1 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + types "k8s.io/apimachinery/pkg/types" + v1 "k8s.io/client-go/applyconfigurations/meta/v1" +) + +// ClusterTestTypeApplyConfiguration represents a declarative configuration of the ClusterTestType type for use +// with apply. +type ClusterTestTypeApplyConfiguration struct { + v1.TypeMetaApplyConfiguration `json:",inline"` + *v1.ObjectMetaApplyConfiguration `json:"metadata,omitempty"` + ObjectKind *string `json:"kind,omitempty"` + ObjectName *string `json:"name,omitempty"` + Status *ClusterTestTypeStatusApplyConfiguration `json:"status,omitempty"` +} + +// ClusterTestType constructs a declarative configuration of the ClusterTestType type for use with +// apply. +func ClusterTestType(name string) *ClusterTestTypeApplyConfiguration { + b := &ClusterTestTypeApplyConfiguration{} + b.WithName(name) + b.WithKind("ClusterTestType") + b.WithAPIVersion("example-dashed.some.corp/v1") + return b +} + +// WithKind sets the Kind field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Kind field is set to the value of the last call. +func (b *ClusterTestTypeApplyConfiguration) WithKind(value string) *ClusterTestTypeApplyConfiguration { + b.Kind = &value + return b +} + +// WithAPIVersion sets the APIVersion field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the APIVersion field is set to the value of the last call. +func (b *ClusterTestTypeApplyConfiguration) WithAPIVersion(value string) *ClusterTestTypeApplyConfiguration { + b.APIVersion = &value + return b +} + +// WithName sets the Name field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Name field is set to the value of the last call. +func (b *ClusterTestTypeApplyConfiguration) WithName(value string) *ClusterTestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.Name = &value + return b +} + +// WithGenerateName sets the GenerateName field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the GenerateName field is set to the value of the last call. +func (b *ClusterTestTypeApplyConfiguration) WithGenerateName(value string) *ClusterTestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.GenerateName = &value + return b +} + +// WithNamespace sets the Namespace field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Namespace field is set to the value of the last call. +func (b *ClusterTestTypeApplyConfiguration) WithNamespace(value string) *ClusterTestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.Namespace = &value + return b +} + +// WithUID sets the UID field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the UID field is set to the value of the last call. +func (b *ClusterTestTypeApplyConfiguration) WithUID(value types.UID) *ClusterTestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.UID = &value + return b +} + +// WithResourceVersion sets the ResourceVersion field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the ResourceVersion field is set to the value of the last call. +func (b *ClusterTestTypeApplyConfiguration) WithResourceVersion(value string) *ClusterTestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.ResourceVersion = &value + return b +} + +// WithGeneration sets the Generation field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Generation field is set to the value of the last call. +func (b *ClusterTestTypeApplyConfiguration) WithGeneration(value int64) *ClusterTestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.Generation = &value + return b +} + +// WithCreationTimestamp sets the CreationTimestamp field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the CreationTimestamp field is set to the value of the last call. +func (b *ClusterTestTypeApplyConfiguration) WithCreationTimestamp(value metav1.Time) *ClusterTestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.CreationTimestamp = &value + return b +} + +// WithDeletionTimestamp sets the DeletionTimestamp field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the DeletionTimestamp field is set to the value of the last call. +func (b *ClusterTestTypeApplyConfiguration) WithDeletionTimestamp(value metav1.Time) *ClusterTestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.DeletionTimestamp = &value + return b +} + +// WithDeletionGracePeriodSeconds sets the DeletionGracePeriodSeconds field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the DeletionGracePeriodSeconds field is set to the value of the last call. +func (b *ClusterTestTypeApplyConfiguration) WithDeletionGracePeriodSeconds(value int64) *ClusterTestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.DeletionGracePeriodSeconds = &value + return b +} + +// WithLabels puts the entries into the Labels field in the declarative configuration +// and returns the receiver, so that objects can be build by chaining "With" function invocations. +// If called multiple times, the entries provided by each call will be put on the Labels field, +// overwriting an existing map entries in Labels field with the same key. +func (b *ClusterTestTypeApplyConfiguration) WithLabels(entries map[string]string) *ClusterTestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + if b.Labels == nil && len(entries) > 0 { + b.Labels = make(map[string]string, len(entries)) + } + for k, v := range entries { + b.Labels[k] = v + } + return b +} + +// WithAnnotations puts the entries into the Annotations field in the declarative configuration +// and returns the receiver, so that objects can be build by chaining "With" function invocations. +// If called multiple times, the entries provided by each call will be put on the Annotations field, +// overwriting an existing map entries in Annotations field with the same key. +func (b *ClusterTestTypeApplyConfiguration) WithAnnotations(entries map[string]string) *ClusterTestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + if b.Annotations == nil && len(entries) > 0 { + b.Annotations = make(map[string]string, len(entries)) + } + for k, v := range entries { + b.Annotations[k] = v + } + return b +} + +// WithOwnerReferences adds the given value to the OwnerReferences field in the declarative configuration +// and returns the receiver, so that objects can be build by chaining "With" function invocations. +// If called multiple times, values provided by each call will be appended to the OwnerReferences field. +func (b *ClusterTestTypeApplyConfiguration) WithOwnerReferences(values ...*v1.OwnerReferenceApplyConfiguration) *ClusterTestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + for i := range values { + if values[i] == nil { + panic("nil value passed to WithOwnerReferences") + } + b.OwnerReferences = append(b.OwnerReferences, *values[i]) + } + return b +} + +// WithFinalizers adds the given value to the Finalizers field in the declarative configuration +// and returns the receiver, so that objects can be build by chaining "With" function invocations. +// If called multiple times, values provided by each call will be appended to the Finalizers field. +func (b *ClusterTestTypeApplyConfiguration) WithFinalizers(values ...string) *ClusterTestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + for i := range values { + b.Finalizers = append(b.Finalizers, values[i]) + } + return b +} + +func (b *ClusterTestTypeApplyConfiguration) ensureObjectMetaApplyConfigurationExists() { + if b.ObjectMetaApplyConfiguration == nil { + b.ObjectMetaApplyConfiguration = &v1.ObjectMetaApplyConfiguration{} + } +} + +// WithObjectKind sets the ObjectKind field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the ObjectKind field is set to the value of the last call. +func (b *ClusterTestTypeApplyConfiguration) WithObjectKind(value string) *ClusterTestTypeApplyConfiguration { + b.ObjectKind = &value + return b +} + +// WithObjectName sets the ObjectName field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the ObjectName field is set to the value of the last call. +func (b *ClusterTestTypeApplyConfiguration) WithObjectName(value string) *ClusterTestTypeApplyConfiguration { + b.ObjectName = &value + return b +} + +// WithStatus sets the Status field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Status field is set to the value of the last call. +func (b *ClusterTestTypeApplyConfiguration) WithStatus(value *ClusterTestTypeStatusApplyConfiguration) *ClusterTestTypeApplyConfiguration { + b.Status = value + return b +} + +// GetName retrieves the value of the Name field in the declarative configuration. +func (b *ClusterTestTypeApplyConfiguration) GetName() *string { + b.ensureObjectMetaApplyConfigurationExists() + return b.Name +} diff --git a/examples/pkg/generated/applyconfigurations/exampledashed/v1/clustertesttypestatus.go b/examples/pkg/generated/applyconfigurations/exampledashed/v1/clustertesttypestatus.go new file mode 100644 index 000000000..9c966d9ae --- /dev/null +++ b/examples/pkg/generated/applyconfigurations/exampledashed/v1/clustertesttypestatus.go @@ -0,0 +1,39 @@ +/* +Copyright The KCP 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 applyconfiguration-gen-v0.31. DO NOT EDIT. + +package v1 + +// ClusterTestTypeStatusApplyConfiguration represents a declarative configuration of the ClusterTestTypeStatus type for use +// with apply. +type ClusterTestTypeStatusApplyConfiguration struct { + Blah *string `json:"blah,omitempty"` +} + +// ClusterTestTypeStatusApplyConfiguration constructs a declarative configuration of the ClusterTestTypeStatus type for use with +// apply. +func ClusterTestTypeStatus() *ClusterTestTypeStatusApplyConfiguration { + return &ClusterTestTypeStatusApplyConfiguration{} +} + +// WithBlah sets the Blah field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Blah field is set to the value of the last call. +func (b *ClusterTestTypeStatusApplyConfiguration) WithBlah(value string) *ClusterTestTypeStatusApplyConfiguration { + b.Blah = &value + return b +} diff --git a/examples/pkg/generated/applyconfigurations/exampledashed/v1/testtype.go b/examples/pkg/generated/applyconfigurations/exampledashed/v1/testtype.go new file mode 100644 index 000000000..60fca0a04 --- /dev/null +++ b/examples/pkg/generated/applyconfigurations/exampledashed/v1/testtype.go @@ -0,0 +1,218 @@ +/* +Copyright The KCP 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 applyconfiguration-gen-v0.31. DO NOT EDIT. + +package v1 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + types "k8s.io/apimachinery/pkg/types" + v1 "k8s.io/client-go/applyconfigurations/meta/v1" +) + +// TestTypeApplyConfiguration represents a declarative configuration of the TestType type for use +// with apply. +type TestTypeApplyConfiguration struct { + v1.TypeMetaApplyConfiguration `json:",inline"` + *v1.ObjectMetaApplyConfiguration `json:"metadata,omitempty"` + APIGroups []string `json:"apiGroups,omitempty"` +} + +// TestType constructs a declarative configuration of the TestType type for use with +// apply. +func TestType(name, namespace string) *TestTypeApplyConfiguration { + b := &TestTypeApplyConfiguration{} + b.WithName(name) + b.WithNamespace(namespace) + b.WithKind("TestType") + b.WithAPIVersion("example-dashed.some.corp/v1") + return b +} + +// WithKind sets the Kind field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Kind field is set to the value of the last call. +func (b *TestTypeApplyConfiguration) WithKind(value string) *TestTypeApplyConfiguration { + b.Kind = &value + return b +} + +// WithAPIVersion sets the APIVersion field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the APIVersion field is set to the value of the last call. +func (b *TestTypeApplyConfiguration) WithAPIVersion(value string) *TestTypeApplyConfiguration { + b.APIVersion = &value + return b +} + +// WithName sets the Name field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Name field is set to the value of the last call. +func (b *TestTypeApplyConfiguration) WithName(value string) *TestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.Name = &value + return b +} + +// WithGenerateName sets the GenerateName field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the GenerateName field is set to the value of the last call. +func (b *TestTypeApplyConfiguration) WithGenerateName(value string) *TestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.GenerateName = &value + return b +} + +// WithNamespace sets the Namespace field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Namespace field is set to the value of the last call. +func (b *TestTypeApplyConfiguration) WithNamespace(value string) *TestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.Namespace = &value + return b +} + +// WithUID sets the UID field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the UID field is set to the value of the last call. +func (b *TestTypeApplyConfiguration) WithUID(value types.UID) *TestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.UID = &value + return b +} + +// WithResourceVersion sets the ResourceVersion field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the ResourceVersion field is set to the value of the last call. +func (b *TestTypeApplyConfiguration) WithResourceVersion(value string) *TestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.ResourceVersion = &value + return b +} + +// WithGeneration sets the Generation field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Generation field is set to the value of the last call. +func (b *TestTypeApplyConfiguration) WithGeneration(value int64) *TestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.Generation = &value + return b +} + +// WithCreationTimestamp sets the CreationTimestamp field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the CreationTimestamp field is set to the value of the last call. +func (b *TestTypeApplyConfiguration) WithCreationTimestamp(value metav1.Time) *TestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.CreationTimestamp = &value + return b +} + +// WithDeletionTimestamp sets the DeletionTimestamp field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the DeletionTimestamp field is set to the value of the last call. +func (b *TestTypeApplyConfiguration) WithDeletionTimestamp(value metav1.Time) *TestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.DeletionTimestamp = &value + return b +} + +// WithDeletionGracePeriodSeconds sets the DeletionGracePeriodSeconds field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the DeletionGracePeriodSeconds field is set to the value of the last call. +func (b *TestTypeApplyConfiguration) WithDeletionGracePeriodSeconds(value int64) *TestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.DeletionGracePeriodSeconds = &value + return b +} + +// WithLabels puts the entries into the Labels field in the declarative configuration +// and returns the receiver, so that objects can be build by chaining "With" function invocations. +// If called multiple times, the entries provided by each call will be put on the Labels field, +// overwriting an existing map entries in Labels field with the same key. +func (b *TestTypeApplyConfiguration) WithLabels(entries map[string]string) *TestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + if b.Labels == nil && len(entries) > 0 { + b.Labels = make(map[string]string, len(entries)) + } + for k, v := range entries { + b.Labels[k] = v + } + return b +} + +// WithAnnotations puts the entries into the Annotations field in the declarative configuration +// and returns the receiver, so that objects can be build by chaining "With" function invocations. +// If called multiple times, the entries provided by each call will be put on the Annotations field, +// overwriting an existing map entries in Annotations field with the same key. +func (b *TestTypeApplyConfiguration) WithAnnotations(entries map[string]string) *TestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + if b.Annotations == nil && len(entries) > 0 { + b.Annotations = make(map[string]string, len(entries)) + } + for k, v := range entries { + b.Annotations[k] = v + } + return b +} + +// WithOwnerReferences adds the given value to the OwnerReferences field in the declarative configuration +// and returns the receiver, so that objects can be build by chaining "With" function invocations. +// If called multiple times, values provided by each call will be appended to the OwnerReferences field. +func (b *TestTypeApplyConfiguration) WithOwnerReferences(values ...*v1.OwnerReferenceApplyConfiguration) *TestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + for i := range values { + if values[i] == nil { + panic("nil value passed to WithOwnerReferences") + } + b.OwnerReferences = append(b.OwnerReferences, *values[i]) + } + return b +} + +// WithFinalizers adds the given value to the Finalizers field in the declarative configuration +// and returns the receiver, so that objects can be build by chaining "With" function invocations. +// If called multiple times, values provided by each call will be appended to the Finalizers field. +func (b *TestTypeApplyConfiguration) WithFinalizers(values ...string) *TestTypeApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + for i := range values { + b.Finalizers = append(b.Finalizers, values[i]) + } + return b +} + +func (b *TestTypeApplyConfiguration) ensureObjectMetaApplyConfigurationExists() { + if b.ObjectMetaApplyConfiguration == nil { + b.ObjectMetaApplyConfiguration = &v1.ObjectMetaApplyConfiguration{} + } +} + +// WithAPIGroups adds the given value to the APIGroups field in the declarative configuration +// and returns the receiver, so that objects can be build by chaining "With" function invocations. +// If called multiple times, values provided by each call will be appended to the APIGroups field. +func (b *TestTypeApplyConfiguration) WithAPIGroups(values ...string) *TestTypeApplyConfiguration { + for i := range values { + b.APIGroups = append(b.APIGroups, values[i]) + } + return b +} + +// GetName retrieves the value of the Name field in the declarative configuration. +func (b *TestTypeApplyConfiguration) GetName() *string { + b.ensureObjectMetaApplyConfigurationExists() + return b.Name +} diff --git a/examples/pkg/generated/applyconfigurations/utils.go b/examples/pkg/generated/applyconfigurations/utils.go index 780dec64e..f46560dcb 100644 --- a/examples/pkg/generated/applyconfigurations/utils.go +++ b/examples/pkg/generated/applyconfigurations/utils.go @@ -28,6 +28,7 @@ import ( v1beta1 "acme.corp/pkg/apis/example/v1beta1" v2 "acme.corp/pkg/apis/example/v2" example3v1 "acme.corp/pkg/apis/example3/v1" + exampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" existinginterfacesv1 "acme.corp/pkg/apis/existinginterfaces/v1" secondexamplev1 "acme.corp/pkg/apis/secondexample/v1" examplev1 "acme.corp/pkg/generated/applyconfigurations/example/v1" @@ -35,6 +36,7 @@ import ( examplev1beta1 "acme.corp/pkg/generated/applyconfigurations/example/v1beta1" examplev2 "acme.corp/pkg/generated/applyconfigurations/example/v2" applyconfigurationsexample3v1 "acme.corp/pkg/generated/applyconfigurations/example3/v1" + applyconfigurationsexampledashedv1 "acme.corp/pkg/generated/applyconfigurations/exampledashed/v1" applyconfigurationsexistinginterfacesv1 "acme.corp/pkg/generated/applyconfigurations/existinginterfaces/v1" internal "acme.corp/pkg/generated/applyconfigurations/internal" applyconfigurationssecondexamplev1 "acme.corp/pkg/generated/applyconfigurations/secondexample/v1" @@ -78,6 +80,14 @@ func ForKind(kind schema.GroupVersionKind) interface{} { case v2.SchemeGroupVersion.WithKind("TestType"): return &examplev2.TestTypeApplyConfiguration{} + // Group=example-dashed.some.corp, Version=v1 + case exampledashedv1.SchemeGroupVersion.WithKind("ClusterTestType"): + return &applyconfigurationsexampledashedv1.ClusterTestTypeApplyConfiguration{} + case exampledashedv1.SchemeGroupVersion.WithKind("ClusterTestTypeStatus"): + return &applyconfigurationsexampledashedv1.ClusterTestTypeStatusApplyConfiguration{} + case exampledashedv1.SchemeGroupVersion.WithKind("TestType"): + return &applyconfigurationsexampledashedv1.TestTypeApplyConfiguration{} + // Group=example3.some.corp, Version=v1 case example3v1.SchemeGroupVersion.WithKind("ClusterTestType"): return &applyconfigurationsexample3v1.ClusterTestTypeApplyConfiguration{} diff --git a/examples/pkg/generated/clientset/versioned/clientset.go b/examples/pkg/generated/clientset/versioned/clientset.go index cbb2b8144..78b3f1360 100644 --- a/examples/pkg/generated/clientset/versioned/clientset.go +++ b/examples/pkg/generated/clientset/versioned/clientset.go @@ -31,6 +31,7 @@ import ( examplev1beta1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1beta1" examplev2 "acme.corp/pkg/generated/clientset/versioned/typed/example/v2" example3v1 "acme.corp/pkg/generated/clientset/versioned/typed/example3/v1" + exampledashedv1 "acme.corp/pkg/generated/clientset/versioned/typed/exampledashed/v1" existinginterfacesv1 "acme.corp/pkg/generated/clientset/versioned/typed/existinginterfaces/v1" secondexamplev1 "acme.corp/pkg/generated/clientset/versioned/typed/secondexample/v1" ) @@ -42,6 +43,7 @@ type Interface interface { ExampleV1beta1() examplev1beta1.ExampleV1beta1Interface ExampleV2() examplev2.ExampleV2Interface Example3V1() example3v1.Example3V1Interface + ExampleDashedV1() exampledashedv1.ExampleDashedV1Interface ExistinginterfacesV1() existinginterfacesv1.ExistinginterfacesV1Interface SecondexampleV1() secondexamplev1.SecondexampleV1Interface } @@ -54,6 +56,7 @@ type Clientset struct { exampleV1beta1 *examplev1beta1.ExampleV1beta1Client exampleV2 *examplev2.ExampleV2Client example3V1 *example3v1.Example3V1Client + exampleDashedV1 *exampledashedv1.ExampleDashedV1Client existinginterfacesV1 *existinginterfacesv1.ExistinginterfacesV1Client secondexampleV1 *secondexamplev1.SecondexampleV1Client } @@ -83,6 +86,11 @@ func (c *Clientset) Example3V1() example3v1.Example3V1Interface { return c.example3V1 } +// ExampleDashedV1 retrieves the ExampleDashedV1Client +func (c *Clientset) ExampleDashedV1() exampledashedv1.ExampleDashedV1Interface { + return c.exampleDashedV1 +} + // ExistinginterfacesV1 retrieves the ExistinginterfacesV1Client func (c *Clientset) ExistinginterfacesV1() existinginterfacesv1.ExistinginterfacesV1Interface { return c.existinginterfacesV1 @@ -157,6 +165,10 @@ func NewForConfigAndClient(c *rest.Config, httpClient *http.Client) (*Clientset, if err != nil { return nil, err } + cs.exampleDashedV1, err = exampledashedv1.NewForConfigAndClient(&configShallowCopy, httpClient) + if err != nil { + return nil, err + } cs.existinginterfacesV1, err = existinginterfacesv1.NewForConfigAndClient(&configShallowCopy, httpClient) if err != nil { return nil, err @@ -191,6 +203,7 @@ func New(c rest.Interface) *Clientset { cs.exampleV1beta1 = examplev1beta1.New(c) cs.exampleV2 = examplev2.New(c) cs.example3V1 = example3v1.New(c) + cs.exampleDashedV1 = exampledashedv1.New(c) cs.existinginterfacesV1 = existinginterfacesv1.New(c) cs.secondexampleV1 = secondexamplev1.New(c) diff --git a/examples/pkg/generated/clientset/versioned/fake/clientset_generated.go b/examples/pkg/generated/clientset/versioned/fake/clientset_generated.go index cc6fb5c28..3d33029f9 100644 --- a/examples/pkg/generated/clientset/versioned/fake/clientset_generated.go +++ b/examples/pkg/generated/clientset/versioned/fake/clientset_generated.go @@ -36,6 +36,8 @@ import ( fakeexamplev2 "acme.corp/pkg/generated/clientset/versioned/typed/example/v2/fake" example3v1 "acme.corp/pkg/generated/clientset/versioned/typed/example3/v1" fakeexample3v1 "acme.corp/pkg/generated/clientset/versioned/typed/example3/v1/fake" + exampledashedv1 "acme.corp/pkg/generated/clientset/versioned/typed/exampledashed/v1" + fakeexampledashedv1 "acme.corp/pkg/generated/clientset/versioned/typed/exampledashed/v1/fake" existinginterfacesv1 "acme.corp/pkg/generated/clientset/versioned/typed/existinginterfaces/v1" fakeexistinginterfacesv1 "acme.corp/pkg/generated/clientset/versioned/typed/existinginterfaces/v1/fake" secondexamplev1 "acme.corp/pkg/generated/clientset/versioned/typed/secondexample/v1" @@ -121,6 +123,11 @@ func (c *Clientset) Example3V1() example3v1.Example3V1Interface { return &fakeexample3v1.FakeExample3V1{Fake: &c.Fake} } +// ExampleDashedV1 retrieves the ExampleDashedV1Client +func (c *Clientset) ExampleDashedV1() exampledashedv1.ExampleDashedV1Interface { + return &fakeexampledashedv1.FakeExampleDashedV1{Fake: &c.Fake} +} + // ExistinginterfacesV1 retrieves the ExistinginterfacesV1Client func (c *Clientset) ExistinginterfacesV1() existinginterfacesv1.ExistinginterfacesV1Interface { return &fakeexistinginterfacesv1.FakeExistinginterfacesV1{Fake: &c.Fake} diff --git a/examples/pkg/generated/clientset/versioned/fake/register.go b/examples/pkg/generated/clientset/versioned/fake/register.go index 0b163682a..4914f6ddd 100644 --- a/examples/pkg/generated/clientset/versioned/fake/register.go +++ b/examples/pkg/generated/clientset/versioned/fake/register.go @@ -30,6 +30,7 @@ import ( examplev1beta1 "acme.corp/pkg/apis/example/v1beta1" examplev2 "acme.corp/pkg/apis/example/v2" example3v1 "acme.corp/pkg/apis/example3/v1" + exampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" existinginterfacesv1 "acme.corp/pkg/apis/existinginterfaces/v1" secondexamplev1 "acme.corp/pkg/apis/secondexample/v1" ) @@ -43,6 +44,7 @@ var localSchemeBuilder = runtime.SchemeBuilder{ examplev1beta1.AddToScheme, examplev2.AddToScheme, example3v1.AddToScheme, + exampledashedv1.AddToScheme, existinginterfacesv1.AddToScheme, secondexamplev1.AddToScheme, } diff --git a/examples/pkg/generated/clientset/versioned/scheme/register.go b/examples/pkg/generated/clientset/versioned/scheme/register.go index 4dde88efb..d22aec109 100644 --- a/examples/pkg/generated/clientset/versioned/scheme/register.go +++ b/examples/pkg/generated/clientset/versioned/scheme/register.go @@ -30,6 +30,7 @@ import ( examplev1beta1 "acme.corp/pkg/apis/example/v1beta1" examplev2 "acme.corp/pkg/apis/example/v2" example3v1 "acme.corp/pkg/apis/example3/v1" + exampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" existinginterfacesv1 "acme.corp/pkg/apis/existinginterfaces/v1" secondexamplev1 "acme.corp/pkg/apis/secondexample/v1" ) @@ -43,6 +44,7 @@ var localSchemeBuilder = runtime.SchemeBuilder{ examplev1beta1.AddToScheme, examplev2.AddToScheme, example3v1.AddToScheme, + exampledashedv1.AddToScheme, existinginterfacesv1.AddToScheme, secondexamplev1.AddToScheme, } diff --git a/examples/pkg/generated/clientset/versioned/typed/exampledashed/v1/clustertesttype.go b/examples/pkg/generated/clientset/versioned/typed/exampledashed/v1/clustertesttype.go new file mode 100644 index 000000000..34afc956f --- /dev/null +++ b/examples/pkg/generated/clientset/versioned/typed/exampledashed/v1/clustertesttype.go @@ -0,0 +1,70 @@ +/* +Copyright The KCP 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-v0.31. DO NOT EDIT. + +package v1 + +import ( + "context" + + metav1 "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" + + v1 "acme.corp/pkg/apis/exampledashed/v1" + scheme "acme.corp/pkg/generated/clientset/versioned/scheme" +) + +// ClusterTestTypesGetter has a method to return a ClusterTestTypeInterface. +// A group's client should implement this interface. +type ClusterTestTypesGetter interface { + ClusterTestTypes() ClusterTestTypeInterface +} + +// ClusterTestTypeInterface has methods to work with ClusterTestType resources. +type ClusterTestTypeInterface interface { + Create(ctx context.Context, clusterTestType *v1.ClusterTestType, opts metav1.CreateOptions) (*v1.ClusterTestType, error) + Update(ctx context.Context, clusterTestType *v1.ClusterTestType, opts metav1.UpdateOptions) (*v1.ClusterTestType, error) + // Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). + UpdateStatus(ctx context.Context, clusterTestType *v1.ClusterTestType, opts metav1.UpdateOptions) (*v1.ClusterTestType, error) + Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error + DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error + Get(ctx context.Context, name string, opts metav1.GetOptions) (*v1.ClusterTestType, error) + List(ctx context.Context, opts metav1.ListOptions) (*v1.ClusterTestTypeList, error) + Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) + Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.ClusterTestType, err error) + ClusterTestTypeExpansion +} + +// clusterTestTypes implements ClusterTestTypeInterface +type clusterTestTypes struct { + *gentype.ClientWithList[*v1.ClusterTestType, *v1.ClusterTestTypeList] +} + +// newClusterTestTypes returns a ClusterTestTypes +func newClusterTestTypes(c *ExampleDashedV1Client) *clusterTestTypes { + return &clusterTestTypes{ + gentype.NewClientWithList[*v1.ClusterTestType, *v1.ClusterTestTypeList]( + "clustertesttypes", + c.RESTClient(), + scheme.ParameterCodec, + "", + func() *v1.ClusterTestType { return &v1.ClusterTestType{} }, + func() *v1.ClusterTestTypeList { return &v1.ClusterTestTypeList{} }), + } +} diff --git a/examples/pkg/generated/clientset/versioned/typed/exampledashed/v1/doc.go b/examples/pkg/generated/clientset/versioned/typed/exampledashed/v1/doc.go new file mode 100644 index 000000000..b2e49efd1 --- /dev/null +++ b/examples/pkg/generated/clientset/versioned/typed/exampledashed/v1/doc.go @@ -0,0 +1,20 @@ +/* +Copyright The KCP 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-v0.31. DO NOT EDIT. + +// This package has the automatically generated typed clients. +package v1 diff --git a/examples/pkg/generated/clientset/versioned/typed/exampledashed/v1/exampledashed_client.go b/examples/pkg/generated/clientset/versioned/typed/exampledashed/v1/exampledashed_client.go new file mode 100644 index 000000000..080cc7d3e --- /dev/null +++ b/examples/pkg/generated/clientset/versioned/typed/exampledashed/v1/exampledashed_client.go @@ -0,0 +1,113 @@ +/* +Copyright The KCP 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-v0.31. DO NOT EDIT. + +package v1 + +import ( + "net/http" + + rest "k8s.io/client-go/rest" + + v1 "acme.corp/pkg/apis/exampledashed/v1" + "acme.corp/pkg/generated/clientset/versioned/scheme" +) + +type ExampleDashedV1Interface interface { + RESTClient() rest.Interface + ClusterTestTypesGetter + TestTypesGetter +} + +// ExampleDashedV1Client is used to interact with features provided by the example-dashed.some.corp group. +type ExampleDashedV1Client struct { + restClient rest.Interface +} + +func (c *ExampleDashedV1Client) ClusterTestTypes() ClusterTestTypeInterface { + return newClusterTestTypes(c) +} + +func (c *ExampleDashedV1Client) TestTypes(namespace string) TestTypeInterface { + return newTestTypes(c, namespace) +} + +// NewForConfig creates a new ExampleDashedV1Client for the given config. +// NewForConfig is equivalent to NewForConfigAndClient(c, httpClient), +// where httpClient was generated with rest.HTTPClientFor(c). +func NewForConfig(c *rest.Config) (*ExampleDashedV1Client, 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 ExampleDashedV1Client 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) (*ExampleDashedV1Client, 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 &ExampleDashedV1Client{client}, nil +} + +// NewForConfigOrDie creates a new ExampleDashedV1Client for the given config and +// panics if there is an error in the config. +func NewForConfigOrDie(c *rest.Config) *ExampleDashedV1Client { + client, err := NewForConfig(c) + if err != nil { + panic(err) + } + return client +} + +// New creates a new ExampleDashedV1Client for the given RESTClient. +func New(c rest.Interface) *ExampleDashedV1Client { + return &ExampleDashedV1Client{c} +} + +func setConfigDefaults(config *rest.Config) error { + gv := v1.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 *ExampleDashedV1Client) RESTClient() rest.Interface { + if c == nil { + return nil + } + return c.restClient +} diff --git a/examples/pkg/generated/clientset/versioned/typed/exampledashed/v1/fake/doc.go b/examples/pkg/generated/clientset/versioned/typed/exampledashed/v1/fake/doc.go new file mode 100644 index 000000000..43d633d75 --- /dev/null +++ b/examples/pkg/generated/clientset/versioned/typed/exampledashed/v1/fake/doc.go @@ -0,0 +1,20 @@ +/* +Copyright The KCP 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-v0.31. DO NOT EDIT. + +// Package fake has the automatically generated clients. +package fake diff --git a/examples/pkg/generated/clientset/versioned/typed/exampledashed/v1/fake/fake_clustertesttype.go b/examples/pkg/generated/clientset/versioned/typed/exampledashed/v1/fake/fake_clustertesttype.go new file mode 100644 index 000000000..88cc6b717 --- /dev/null +++ b/examples/pkg/generated/clientset/versioned/typed/exampledashed/v1/fake/fake_clustertesttype.go @@ -0,0 +1,139 @@ +/* +Copyright The KCP 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-v0.31. DO NOT EDIT. + +package fake + +import ( + "context" + + metav1 "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" + + v1 "acme.corp/pkg/apis/exampledashed/v1" +) + +// FakeClusterTestTypes implements ClusterTestTypeInterface +type FakeClusterTestTypes struct { + Fake *FakeExampleDashedV1 +} + +var clustertesttypesResource = v1.SchemeGroupVersion.WithResource("clustertesttypes") + +var clustertesttypesKind = v1.SchemeGroupVersion.WithKind("ClusterTestType") + +// Get takes name of the clusterTestType, and returns the corresponding clusterTestType object, and an error if there is any. +func (c *FakeClusterTestTypes) Get(ctx context.Context, name string, options metav1.GetOptions) (result *v1.ClusterTestType, err error) { + emptyResult := &v1.ClusterTestType{} + obj, err := c.Fake. + Invokes(testing.NewRootGetActionWithOptions(clustertesttypesResource, name, options), emptyResult) + if obj == nil { + return emptyResult, err + } + return obj.(*v1.ClusterTestType), err +} + +// List takes label and field selectors, and returns the list of ClusterTestTypes that match those selectors. +func (c *FakeClusterTestTypes) List(ctx context.Context, opts metav1.ListOptions) (result *v1.ClusterTestTypeList, err error) { + emptyResult := &v1.ClusterTestTypeList{} + obj, err := c.Fake. + Invokes(testing.NewRootListActionWithOptions(clustertesttypesResource, clustertesttypesKind, opts), emptyResult) + if obj == nil { + return emptyResult, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &v1.ClusterTestTypeList{ListMeta: obj.(*v1.ClusterTestTypeList).ListMeta} + for _, item := range obj.(*v1.ClusterTestTypeList).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 clusterTestTypes. +func (c *FakeClusterTestTypes) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { + return c.Fake. + InvokesWatch(testing.NewRootWatchActionWithOptions(clustertesttypesResource, opts)) +} + +// Create takes the representation of a clusterTestType and creates it. Returns the server's representation of the clusterTestType, and an error, if there is any. +func (c *FakeClusterTestTypes) Create(ctx context.Context, clusterTestType *v1.ClusterTestType, opts metav1.CreateOptions) (result *v1.ClusterTestType, err error) { + emptyResult := &v1.ClusterTestType{} + obj, err := c.Fake. + Invokes(testing.NewRootCreateActionWithOptions(clustertesttypesResource, clusterTestType, opts), emptyResult) + if obj == nil { + return emptyResult, err + } + return obj.(*v1.ClusterTestType), err +} + +// Update takes the representation of a clusterTestType and updates it. Returns the server's representation of the clusterTestType, and an error, if there is any. +func (c *FakeClusterTestTypes) Update(ctx context.Context, clusterTestType *v1.ClusterTestType, opts metav1.UpdateOptions) (result *v1.ClusterTestType, err error) { + emptyResult := &v1.ClusterTestType{} + obj, err := c.Fake. + Invokes(testing.NewRootUpdateActionWithOptions(clustertesttypesResource, clusterTestType, opts), emptyResult) + if obj == nil { + return emptyResult, err + } + return obj.(*v1.ClusterTestType), 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 *FakeClusterTestTypes) UpdateStatus(ctx context.Context, clusterTestType *v1.ClusterTestType, opts metav1.UpdateOptions) (result *v1.ClusterTestType, err error) { + emptyResult := &v1.ClusterTestType{} + obj, err := c.Fake. + Invokes(testing.NewRootUpdateSubresourceActionWithOptions(clustertesttypesResource, "status", clusterTestType, opts), emptyResult) + if obj == nil { + return emptyResult, err + } + return obj.(*v1.ClusterTestType), err +} + +// Delete takes name of the clusterTestType and deletes it. Returns an error if one occurs. +func (c *FakeClusterTestTypes) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { + _, err := c.Fake. + Invokes(testing.NewRootDeleteActionWithOptions(clustertesttypesResource, name, opts), &v1.ClusterTestType{}) + return err +} + +// DeleteCollection deletes a collection of objects. +func (c *FakeClusterTestTypes) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { + action := testing.NewRootDeleteCollectionActionWithOptions(clustertesttypesResource, opts, listOpts) + + _, err := c.Fake.Invokes(action, &v1.ClusterTestTypeList{}) + return err +} + +// Patch applies the patch and returns the patched clusterTestType. +func (c *FakeClusterTestTypes) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.ClusterTestType, err error) { + emptyResult := &v1.ClusterTestType{} + obj, err := c.Fake. + Invokes(testing.NewRootPatchSubresourceActionWithOptions(clustertesttypesResource, name, pt, data, opts, subresources...), emptyResult) + if obj == nil { + return emptyResult, err + } + return obj.(*v1.ClusterTestType), err +} diff --git a/examples/pkg/generated/clientset/versioned/typed/exampledashed/v1/fake/fake_exampledashed_client.go b/examples/pkg/generated/clientset/versioned/typed/exampledashed/v1/fake/fake_exampledashed_client.go new file mode 100644 index 000000000..85213f67a --- /dev/null +++ b/examples/pkg/generated/clientset/versioned/typed/exampledashed/v1/fake/fake_exampledashed_client.go @@ -0,0 +1,45 @@ +/* +Copyright The KCP 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-v0.31. DO NOT EDIT. + +package fake + +import ( + rest "k8s.io/client-go/rest" + testing "k8s.io/client-go/testing" + + v1 "acme.corp/pkg/generated/clientset/versioned/typed/exampledashed/v1" +) + +type FakeExampleDashedV1 struct { + *testing.Fake +} + +func (c *FakeExampleDashedV1) ClusterTestTypes() v1.ClusterTestTypeInterface { + return &FakeClusterTestTypes{c} +} + +func (c *FakeExampleDashedV1) TestTypes(namespace string) v1.TestTypeInterface { + return &FakeTestTypes{c, namespace} +} + +// RESTClient returns a RESTClient that is used to communicate +// with API server by this client implementation. +func (c *FakeExampleDashedV1) RESTClient() rest.Interface { + var ret *rest.RESTClient + return ret +} diff --git a/examples/pkg/generated/clientset/versioned/typed/exampledashed/v1/fake/fake_testtype.go b/examples/pkg/generated/clientset/versioned/typed/exampledashed/v1/fake/fake_testtype.go new file mode 100644 index 000000000..ecf6ac9d4 --- /dev/null +++ b/examples/pkg/generated/clientset/versioned/typed/exampledashed/v1/fake/fake_testtype.go @@ -0,0 +1,172 @@ +/* +Copyright The KCP 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-v0.31. DO NOT EDIT. + +package fake + +import ( + "context" + + metav1 "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" + + examplev1 "acme.corp/pkg/apis/example/v1" + v1 "acme.corp/pkg/apis/exampledashed/v1" +) + +// FakeTestTypes implements TestTypeInterface +type FakeTestTypes struct { + Fake *FakeExampleDashedV1 + ns string +} + +var testtypesResource = v1.SchemeGroupVersion.WithResource("testtypes") + +var testtypesKind = v1.SchemeGroupVersion.WithKind("TestType") + +// Get takes name of the testType, and returns the corresponding testType object, and an error if there is any. +func (c *FakeTestTypes) Get(ctx context.Context, name string, options metav1.GetOptions) (result *v1.TestType, err error) { + emptyResult := &v1.TestType{} + obj, err := c.Fake. + Invokes(testing.NewGetActionWithOptions(testtypesResource, c.ns, name, options), emptyResult) + + if obj == nil { + return emptyResult, err + } + return obj.(*v1.TestType), err +} + +// List takes label and field selectors, and returns the list of TestTypes that match those selectors. +func (c *FakeTestTypes) List(ctx context.Context, opts metav1.ListOptions) (result *v1.TestTypeList, err error) { + emptyResult := &v1.TestTypeList{} + obj, err := c.Fake. + Invokes(testing.NewListActionWithOptions(testtypesResource, testtypesKind, c.ns, opts), emptyResult) + + if obj == nil { + return emptyResult, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &v1.TestTypeList{ListMeta: obj.(*v1.TestTypeList).ListMeta} + for _, item := range obj.(*v1.TestTypeList).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 testTypes. +func (c *FakeTestTypes) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { + return c.Fake. + InvokesWatch(testing.NewWatchActionWithOptions(testtypesResource, c.ns, opts)) + +} + +// Create takes the representation of a testType and creates it. Returns the server's representation of the testType, and an error, if there is any. +func (c *FakeTestTypes) Create(ctx context.Context, testType *v1.TestType, opts metav1.CreateOptions) (result *v1.TestType, err error) { + emptyResult := &v1.TestType{} + obj, err := c.Fake. + Invokes(testing.NewCreateActionWithOptions(testtypesResource, c.ns, testType, opts), emptyResult) + + if obj == nil { + return emptyResult, err + } + return obj.(*v1.TestType), err +} + +// Update takes the representation of a testType and updates it. Returns the server's representation of the testType, and an error, if there is any. +func (c *FakeTestTypes) Update(ctx context.Context, testType *v1.TestType, opts metav1.UpdateOptions) (result *v1.TestType, err error) { + emptyResult := &v1.TestType{} + obj, err := c.Fake. + Invokes(testing.NewUpdateActionWithOptions(testtypesResource, c.ns, testType, opts), emptyResult) + + if obj == nil { + return emptyResult, err + } + return obj.(*v1.TestType), err +} + +// Delete takes name of the testType and deletes it. Returns an error if one occurs. +func (c *FakeTestTypes) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { + _, err := c.Fake. + Invokes(testing.NewDeleteActionWithOptions(testtypesResource, c.ns, name, opts), &v1.TestType{}) + + return err +} + +// DeleteCollection deletes a collection of objects. +func (c *FakeTestTypes) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { + action := testing.NewDeleteCollectionActionWithOptions(testtypesResource, c.ns, opts, listOpts) + + _, err := c.Fake.Invokes(action, &v1.TestTypeList{}) + return err +} + +// Patch applies the patch and returns the patched testType. +func (c *FakeTestTypes) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.TestType, err error) { + emptyResult := &v1.TestType{} + obj, err := c.Fake. + Invokes(testing.NewPatchSubresourceActionWithOptions(testtypesResource, c.ns, name, pt, data, opts, subresources...), emptyResult) + + if obj == nil { + return emptyResult, err + } + return obj.(*v1.TestType), err +} + +// CreateField takes the representation of a field and creates it. Returns the server's representation of the field, and an error, if there is any. +func (c *FakeTestTypes) CreateField(ctx context.Context, testTypeName string, field *examplev1.Field, opts metav1.CreateOptions) (result *examplev1.Field, err error) { + emptyResult := &examplev1.Field{} + obj, err := c.Fake. + Invokes(testing.NewCreateSubresourceActionWithOptions(testtypesResource, testTypeName, "field", c.ns, field, opts), emptyResult) + + if obj == nil { + return emptyResult, err + } + return obj.(*examplev1.Field), err +} + +// UpdateField takes the representation of a field and updates it. Returns the server's representation of the field, and an error, if there is any. +func (c *FakeTestTypes) UpdateField(ctx context.Context, testTypeName string, field *examplev1.Field, opts metav1.UpdateOptions) (result *examplev1.Field, err error) { + emptyResult := &examplev1.Field{} + obj, err := c.Fake. + Invokes(testing.NewUpdateSubresourceActionWithOptions(testtypesResource, "field", c.ns, field, opts), &examplev1.Field{}) + + if obj == nil { + return emptyResult, err + } + return obj.(*examplev1.Field), err +} + +// GetField takes name of the testType, and returns the corresponding field object, and an error if there is any. +func (c *FakeTestTypes) GetField(ctx context.Context, testTypeName string, options metav1.GetOptions) (result *examplev1.Field, err error) { + emptyResult := &examplev1.Field{} + obj, err := c.Fake. + Invokes(testing.NewGetSubresourceActionWithOptions(testtypesResource, c.ns, "field", testTypeName, options), emptyResult) + + if obj == nil { + return emptyResult, err + } + return obj.(*examplev1.Field), err +} diff --git a/examples/pkg/generated/clientset/versioned/typed/exampledashed/v1/generated_expansion.go b/examples/pkg/generated/clientset/versioned/typed/exampledashed/v1/generated_expansion.go new file mode 100644 index 000000000..4233cb0ef --- /dev/null +++ b/examples/pkg/generated/clientset/versioned/typed/exampledashed/v1/generated_expansion.go @@ -0,0 +1,23 @@ +/* +Copyright The KCP 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-v0.31. DO NOT EDIT. + +package v1 + +type ClusterTestTypeExpansion interface{} + +type TestTypeExpansion interface{} diff --git a/examples/pkg/generated/clientset/versioned/typed/exampledashed/v1/testtype.go b/examples/pkg/generated/clientset/versioned/typed/exampledashed/v1/testtype.go new file mode 100644 index 000000000..a044c31c8 --- /dev/null +++ b/examples/pkg/generated/clientset/versioned/typed/exampledashed/v1/testtype.go @@ -0,0 +1,117 @@ +/* +Copyright The KCP 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-v0.31. DO NOT EDIT. + +package v1 + +import ( + "context" + + metav1 "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" + + examplev1 "acme.corp/pkg/apis/example/v1" + v1 "acme.corp/pkg/apis/exampledashed/v1" + scheme "acme.corp/pkg/generated/clientset/versioned/scheme" +) + +// TestTypesGetter has a method to return a TestTypeInterface. +// A group's client should implement this interface. +type TestTypesGetter interface { + TestTypes(namespace string) TestTypeInterface +} + +// TestTypeInterface has methods to work with TestType resources. +type TestTypeInterface interface { + Create(ctx context.Context, testType *v1.TestType, opts metav1.CreateOptions) (*v1.TestType, error) + Update(ctx context.Context, testType *v1.TestType, opts metav1.UpdateOptions) (*v1.TestType, error) + Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error + DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error + Get(ctx context.Context, name string, opts metav1.GetOptions) (*v1.TestType, error) + List(ctx context.Context, opts metav1.ListOptions) (*v1.TestTypeList, error) + Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) + Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.TestType, err error) + CreateField(ctx context.Context, testTypeName string, field *examplev1.Field, opts metav1.CreateOptions) (*examplev1.Field, error) + UpdateField(ctx context.Context, testTypeName string, field *examplev1.Field, opts metav1.UpdateOptions) (*examplev1.Field, error) + GetField(ctx context.Context, testTypeName string, options metav1.GetOptions) (*examplev1.Field, error) + + TestTypeExpansion +} + +// testTypes implements TestTypeInterface +type testTypes struct { + *gentype.ClientWithList[*v1.TestType, *v1.TestTypeList] +} + +// newTestTypes returns a TestTypes +func newTestTypes(c *ExampleDashedV1Client, namespace string) *testTypes { + return &testTypes{ + gentype.NewClientWithList[*v1.TestType, *v1.TestTypeList]( + "testtypes", + c.RESTClient(), + scheme.ParameterCodec, + namespace, + func() *v1.TestType { return &v1.TestType{} }, + func() *v1.TestTypeList { return &v1.TestTypeList{} }), + } +} + +// CreateField takes the representation of a field and creates it. Returns the server's representation of the field, and an error, if there is any. +func (c *testTypes) CreateField(ctx context.Context, testTypeName string, field *examplev1.Field, opts metav1.CreateOptions) (result *examplev1.Field, err error) { + result = &examplev1.Field{} + err = c.GetClient().Post(). + Namespace(c.GetNamespace()). + Resource("testtypes"). + Name(testTypeName). + SubResource("field"). + VersionedParams(&opts, scheme.ParameterCodec). + Body(field). + Do(ctx). + Into(result) + return +} + +// UpdateField takes the top resource name and the representation of a field and updates it. Returns the server's representation of the field, and an error, if there is any. +func (c *testTypes) UpdateField(ctx context.Context, testTypeName string, field *examplev1.Field, opts metav1.UpdateOptions) (result *examplev1.Field, err error) { + result = &examplev1.Field{} + err = c.GetClient().Put(). + Namespace(c.GetNamespace()). + Resource("testtypes"). + Name(testTypeName). + SubResource("field"). + VersionedParams(&opts, scheme.ParameterCodec). + Body(field). + Do(ctx). + Into(result) + return +} + +// GetField takes name of the testType, and returns the corresponding examplev1.Field object, and an error if there is any. +func (c *testTypes) GetField(ctx context.Context, testTypeName string, options metav1.GetOptions) (result *examplev1.Field, err error) { + result = &examplev1.Field{} + err = c.GetClient().Get(). + Namespace(c.GetNamespace()). + Resource("testtypes"). + Name(testTypeName). + SubResource("field"). + VersionedParams(&options, scheme.ParameterCodec). + Do(ctx). + Into(result) + return +} diff --git a/examples/pkg/generated/informers/externalversions/exampledashed/interface.go b/examples/pkg/generated/informers/externalversions/exampledashed/interface.go new file mode 100644 index 000000000..e5277e3f6 --- /dev/null +++ b/examples/pkg/generated/informers/externalversions/exampledashed/interface.go @@ -0,0 +1,46 @@ +/* +Copyright The KCP 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-v0.31. DO NOT EDIT. + +package exampledashed + +import ( + v1 "acme.corp/pkg/generated/informers/externalversions/exampledashed/v1" + internalinterfaces "acme.corp/pkg/generated/informers/externalversions/internalinterfaces" +) + +// Interface provides access to each of this group's versions. +type Interface interface { + // V1 provides access to shared informers for resources in V1. + V1() v1.Interface +} + +type group 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 &group{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} +} + +// V1 returns a new v1.Interface. +func (g *group) V1() v1.Interface { + return v1.New(g.factory, g.namespace, g.tweakListOptions) +} diff --git a/examples/pkg/generated/informers/externalversions/exampledashed/v1/clustertesttype.go b/examples/pkg/generated/informers/externalversions/exampledashed/v1/clustertesttype.go new file mode 100644 index 000000000..fa987482c --- /dev/null +++ b/examples/pkg/generated/informers/externalversions/exampledashed/v1/clustertesttype.go @@ -0,0 +1,90 @@ +/* +Copyright The KCP 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-v0.31. DO NOT EDIT. + +package v1 + +import ( + "context" + time "time" + + metav1 "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" + + exampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" + versioned "acme.corp/pkg/generated/clientset/versioned" + internalinterfaces "acme.corp/pkg/generated/informers/externalversions/internalinterfaces" + v1 "acme.corp/pkg/generated/listers/exampledashed/v1" +) + +// ClusterTestTypeInformer provides access to a shared informer and lister for +// ClusterTestTypes. +type ClusterTestTypeInformer interface { + Informer() cache.SharedIndexInformer + Lister() v1.ClusterTestTypeLister +} + +type clusterTestTypeInformer struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc +} + +// NewClusterTestTypeInformer constructs a new informer for ClusterTestType 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 NewClusterTestTypeInformer(client versioned.Interface, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return NewFilteredClusterTestTypeInformer(client, resyncPeriod, indexers, nil) +} + +// NewFilteredClusterTestTypeInformer constructs a new informer for ClusterTestType 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 NewFilteredClusterTestTypeInformer(client versioned.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.ExampleDashedV1().ClusterTestTypes().List(context.TODO(), options) + }, + WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ExampleDashedV1().ClusterTestTypes().Watch(context.TODO(), options) + }, + }, + &exampledashedv1.ClusterTestType{}, + resyncPeriod, + indexers, + ) +} + +func (f *clusterTestTypeInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewFilteredClusterTestTypeInformer(client, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) +} + +func (f *clusterTestTypeInformer) Informer() cache.SharedIndexInformer { + return f.factory.InformerFor(&exampledashedv1.ClusterTestType{}, f.defaultInformer) +} + +func (f *clusterTestTypeInformer) Lister() v1.ClusterTestTypeLister { + return v1.NewClusterTestTypeLister(f.Informer().GetIndexer()) +} diff --git a/examples/pkg/generated/informers/externalversions/exampledashed/v1/interface.go b/examples/pkg/generated/informers/externalversions/exampledashed/v1/interface.go new file mode 100644 index 000000000..066225ba4 --- /dev/null +++ b/examples/pkg/generated/informers/externalversions/exampledashed/v1/interface.go @@ -0,0 +1,52 @@ +/* +Copyright The KCP 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-v0.31. DO NOT EDIT. + +package v1 + +import ( + internalinterfaces "acme.corp/pkg/generated/informers/externalversions/internalinterfaces" +) + +// Interface provides access to all the informers in this group version. +type Interface interface { + // ClusterTestTypes returns a ClusterTestTypeInformer. + ClusterTestTypes() ClusterTestTypeInformer + // TestTypes returns a TestTypeInformer. + TestTypes() TestTypeInformer +} + +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} +} + +// ClusterTestTypes returns a ClusterTestTypeInformer. +func (v *version) ClusterTestTypes() ClusterTestTypeInformer { + return &clusterTestTypeInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} +} + +// TestTypes returns a TestTypeInformer. +func (v *version) TestTypes() TestTypeInformer { + return &testTypeInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} +} diff --git a/examples/pkg/generated/informers/externalversions/exampledashed/v1/testtype.go b/examples/pkg/generated/informers/externalversions/exampledashed/v1/testtype.go new file mode 100644 index 000000000..6a910df8a --- /dev/null +++ b/examples/pkg/generated/informers/externalversions/exampledashed/v1/testtype.go @@ -0,0 +1,91 @@ +/* +Copyright The KCP 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-v0.31. DO NOT EDIT. + +package v1 + +import ( + "context" + time "time" + + metav1 "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" + + exampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" + versioned "acme.corp/pkg/generated/clientset/versioned" + internalinterfaces "acme.corp/pkg/generated/informers/externalversions/internalinterfaces" + v1 "acme.corp/pkg/generated/listers/exampledashed/v1" +) + +// TestTypeInformer provides access to a shared informer and lister for +// TestTypes. +type TestTypeInformer interface { + Informer() cache.SharedIndexInformer + Lister() v1.TestTypeLister +} + +type testTypeInformer struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc + namespace string +} + +// NewTestTypeInformer constructs a new informer for TestType 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 NewTestTypeInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return NewFilteredTestTypeInformer(client, namespace, resyncPeriod, indexers, nil) +} + +// NewFilteredTestTypeInformer constructs a new informer for TestType 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 NewFilteredTestTypeInformer(client versioned.Interface, namespace string, 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.ExampleDashedV1().TestTypes(namespace).List(context.TODO(), options) + }, + WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ExampleDashedV1().TestTypes(namespace).Watch(context.TODO(), options) + }, + }, + &exampledashedv1.TestType{}, + resyncPeriod, + indexers, + ) +} + +func (f *testTypeInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewFilteredTestTypeInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) +} + +func (f *testTypeInformer) Informer() cache.SharedIndexInformer { + return f.factory.InformerFor(&exampledashedv1.TestType{}, f.defaultInformer) +} + +func (f *testTypeInformer) Lister() v1.TestTypeLister { + return v1.NewTestTypeLister(f.Informer().GetIndexer()) +} diff --git a/examples/pkg/generated/informers/externalversions/factory.go b/examples/pkg/generated/informers/externalversions/factory.go index 02a666102..28af342a0 100644 --- a/examples/pkg/generated/informers/externalversions/factory.go +++ b/examples/pkg/generated/informers/externalversions/factory.go @@ -31,6 +31,7 @@ import ( versioned "acme.corp/pkg/generated/clientset/versioned" example "acme.corp/pkg/generated/informers/externalversions/example" example3 "acme.corp/pkg/generated/informers/externalversions/example3" + exampledashed "acme.corp/pkg/generated/informers/externalversions/exampledashed" existinginterfaces "acme.corp/pkg/generated/informers/externalversions/existinginterfaces" internalinterfaces "acme.corp/pkg/generated/informers/externalversions/internalinterfaces" secondexample "acme.corp/pkg/generated/informers/externalversions/secondexample" @@ -260,6 +261,7 @@ type SharedInformerFactory interface { Example() example.Interface Example3() example3.Interface + ExampleDashed() exampledashed.Interface Existinginterfaces() existinginterfaces.Interface Secondexample() secondexample.Interface } @@ -272,6 +274,10 @@ func (f *sharedInformerFactory) Example3() example3.Interface { return example3.New(f, f.namespace, f.tweakListOptions) } +func (f *sharedInformerFactory) ExampleDashed() exampledashed.Interface { + return exampledashed.New(f, f.namespace, f.tweakListOptions) +} + func (f *sharedInformerFactory) Existinginterfaces() existinginterfaces.Interface { return existinginterfaces.New(f, f.namespace, f.tweakListOptions) } diff --git a/examples/pkg/generated/informers/externalversions/generic.go b/examples/pkg/generated/informers/externalversions/generic.go index 9337b236d..792370a65 100644 --- a/examples/pkg/generated/informers/externalversions/generic.go +++ b/examples/pkg/generated/informers/externalversions/generic.go @@ -29,6 +29,7 @@ import ( v1beta1 "acme.corp/pkg/apis/example/v1beta1" v2 "acme.corp/pkg/apis/example/v2" example3v1 "acme.corp/pkg/apis/example3/v1" + exampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" existinginterfacesv1 "acme.corp/pkg/apis/existinginterfaces/v1" secondexamplev1 "acme.corp/pkg/apis/secondexample/v1" ) @@ -83,6 +84,12 @@ func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource case v2.SchemeGroupVersion.WithResource("testtypes"): return &genericInformer{resource: resource.GroupResource(), informer: f.Example().V2().TestTypes().Informer()}, nil + // Group=example-dashed.some.corp, Version=v1 + case exampledashedv1.SchemeGroupVersion.WithResource("clustertesttypes"): + return &genericInformer{resource: resource.GroupResource(), informer: f.ExampleDashed().V1().ClusterTestTypes().Informer()}, nil + case exampledashedv1.SchemeGroupVersion.WithResource("testtypes"): + return &genericInformer{resource: resource.GroupResource(), informer: f.ExampleDashed().V1().TestTypes().Informer()}, nil + // Group=example3.some.corp, Version=v1 case example3v1.SchemeGroupVersion.WithResource("clustertesttypes"): return &genericInformer{resource: resource.GroupResource(), informer: f.Example3().V1().ClusterTestTypes().Informer()}, nil diff --git a/examples/pkg/generated/listers/exampledashed/v1/clustertesttype.go b/examples/pkg/generated/listers/exampledashed/v1/clustertesttype.go new file mode 100644 index 000000000..ba313da5a --- /dev/null +++ b/examples/pkg/generated/listers/exampledashed/v1/clustertesttype.go @@ -0,0 +1,49 @@ +/* +Copyright The KCP 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-v0.31. DO NOT EDIT. + +package v1 + +import ( + "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/listers" + "k8s.io/client-go/tools/cache" + + v1 "acme.corp/pkg/apis/exampledashed/v1" +) + +// ClusterTestTypeLister helps list ClusterTestTypes. +// All objects returned here must be treated as read-only. +type ClusterTestTypeLister interface { + // List lists all ClusterTestTypes in the indexer. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*v1.ClusterTestType, err error) + // Get retrieves the ClusterTestType from the index for a given name. + // Objects returned here must be treated as read-only. + Get(name string) (*v1.ClusterTestType, error) + ClusterTestTypeListerExpansion +} + +// clusterTestTypeLister implements the ClusterTestTypeLister interface. +type clusterTestTypeLister struct { + listers.ResourceIndexer[*v1.ClusterTestType] +} + +// NewClusterTestTypeLister returns a new ClusterTestTypeLister. +func NewClusterTestTypeLister(indexer cache.Indexer) ClusterTestTypeLister { + return &clusterTestTypeLister{listers.New[*v1.ClusterTestType](indexer, v1.Resource("clustertesttype"))} +} diff --git a/examples/pkg/generated/listers/exampledashed/v1/expansion_generated.go b/examples/pkg/generated/listers/exampledashed/v1/expansion_generated.go new file mode 100644 index 000000000..35b3a43bb --- /dev/null +++ b/examples/pkg/generated/listers/exampledashed/v1/expansion_generated.go @@ -0,0 +1,31 @@ +/* +Copyright The KCP 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-v0.31. DO NOT EDIT. + +package v1 + +// ClusterTestTypeListerExpansion allows custom methods to be added to +// ClusterTestTypeLister. +type ClusterTestTypeListerExpansion interface{} + +// TestTypeListerExpansion allows custom methods to be added to +// TestTypeLister. +type TestTypeListerExpansion interface{} + +// TestTypeNamespaceListerExpansion allows custom methods to be added to +// TestTypeNamespaceLister. +type TestTypeNamespaceListerExpansion interface{} diff --git a/examples/pkg/generated/listers/exampledashed/v1/testtype.go b/examples/pkg/generated/listers/exampledashed/v1/testtype.go new file mode 100644 index 000000000..e1babab80 --- /dev/null +++ b/examples/pkg/generated/listers/exampledashed/v1/testtype.go @@ -0,0 +1,71 @@ +/* +Copyright The KCP 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-v0.31. DO NOT EDIT. + +package v1 + +import ( + "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/listers" + "k8s.io/client-go/tools/cache" + + v1 "acme.corp/pkg/apis/exampledashed/v1" +) + +// TestTypeLister helps list TestTypes. +// All objects returned here must be treated as read-only. +type TestTypeLister interface { + // List lists all TestTypes in the indexer. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*v1.TestType, err error) + // TestTypes returns an object that can list and get TestTypes. + TestTypes(namespace string) TestTypeNamespaceLister + TestTypeListerExpansion +} + +// testTypeLister implements the TestTypeLister interface. +type testTypeLister struct { + listers.ResourceIndexer[*v1.TestType] +} + +// NewTestTypeLister returns a new TestTypeLister. +func NewTestTypeLister(indexer cache.Indexer) TestTypeLister { + return &testTypeLister{listers.New[*v1.TestType](indexer, v1.Resource("testtype"))} +} + +// TestTypes returns an object that can list and get TestTypes. +func (s *testTypeLister) TestTypes(namespace string) TestTypeNamespaceLister { + return testTypeNamespaceLister{listers.NewNamespaced[*v1.TestType](s.ResourceIndexer, namespace)} +} + +// TestTypeNamespaceLister helps list and get TestTypes. +// All objects returned here must be treated as read-only. +type TestTypeNamespaceLister interface { + // List lists all TestTypes in the indexer for a given namespace. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*v1.TestType, err error) + // Get retrieves the TestType from the indexer for a given namespace and name. + // Objects returned here must be treated as read-only. + Get(name string) (*v1.TestType, error) + TestTypeNamespaceListerExpansion +} + +// testTypeNamespaceLister implements the TestTypeNamespaceLister +// interface. +type testTypeNamespaceLister struct { + listers.ResourceIndexer[*v1.TestType] +} diff --git a/examples/pkg/kcp/clients/clientset/versioned/clientset.go b/examples/pkg/kcp/clients/clientset/versioned/clientset.go index aa4ccb8f9..93c0659fd 100644 --- a/examples/pkg/kcp/clients/clientset/versioned/clientset.go +++ b/examples/pkg/kcp/clients/clientset/versioned/clientset.go @@ -38,6 +38,7 @@ import ( examplev1beta1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/example/v1beta1" examplev2 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/example/v2" example3v1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/example3/v1" + exampledashedv1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/exampledashed/v1" existinginterfacesv1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/existinginterfaces/v1" secondexamplev1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/secondexample/v1" ) @@ -45,6 +46,7 @@ import ( type ClusterInterface interface { Cluster(logicalcluster.Path) client.Interface Discovery() discovery.DiscoveryInterface + ExampleDashedV1() exampledashedv1.ExampleDashedV1ClusterInterface Example3V1() example3v1.Example3V1ClusterInterface ExampleV1() examplev1.ExampleV1ClusterInterface ExampleV1alpha1() examplev1alpha1.ExampleV1alpha1ClusterInterface @@ -58,6 +60,7 @@ type ClusterInterface interface { type ClusterClientset struct { *discovery.DiscoveryClient clientCache kcpclient.Cache[*client.Clientset] + exampledashedV1 *exampledashedv1.ExampleDashedV1ClusterClient example3V1 *example3v1.Example3V1ClusterClient exampleV1 *examplev1.ExampleV1ClusterClient exampleV1alpha1 *examplev1alpha1.ExampleV1alpha1ClusterClient @@ -75,6 +78,11 @@ func (c *ClusterClientset) Discovery() discovery.DiscoveryInterface { return c.DiscoveryClient } +// ExampleDashedV1 retrieves the ExampleDashedV1ClusterClient. +func (c *ClusterClientset) ExampleDashedV1() exampledashedv1.ExampleDashedV1ClusterInterface { + return c.exampledashedV1 +} + // Example3V1 retrieves the Example3V1ClusterClient. func (c *ClusterClientset) Example3V1() example3v1.Example3V1ClusterInterface { return c.example3V1 @@ -162,6 +170,10 @@ func NewForConfigAndClient(c *rest.Config, httpClient *http.Client) (*ClusterCli var cs ClusterClientset cs.clientCache = cache var err error + cs.exampledashedV1, err = exampledashedv1.NewForConfigAndClient(&configShallowCopy, httpClient) + if err != nil { + return nil, err + } cs.example3V1, err = example3v1.NewForConfigAndClient(&configShallowCopy, httpClient) if err != nil { return nil, err diff --git a/examples/pkg/kcp/clients/clientset/versioned/fake/clientset.go b/examples/pkg/kcp/clients/clientset/versioned/fake/clientset.go index 0ee45174b..07a6fc29d 100644 --- a/examples/pkg/kcp/clients/clientset/versioned/fake/clientset.go +++ b/examples/pkg/kcp/clients/clientset/versioned/fake/clientset.go @@ -36,6 +36,7 @@ import ( examplev1beta1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1beta1" examplev2 "acme.corp/pkg/generated/clientset/versioned/typed/example/v2" example3v1 "acme.corp/pkg/generated/clientset/versioned/typed/example3/v1" + exampledashedv1 "acme.corp/pkg/generated/clientset/versioned/typed/exampledashed/v1" existinginterfacesv1 "acme.corp/pkg/generated/clientset/versioned/typed/existinginterfaces/v1" secondexamplev1 "acme.corp/pkg/generated/clientset/versioned/typed/secondexample/v1" kcpclient "acme.corp/pkg/kcp/clients/clientset/versioned" @@ -49,6 +50,8 @@ import ( fakeexamplev2 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/example/v2/fake" kcpexample3v1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/example3/v1" fakeexample3v1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/example3/v1/fake" + kcpexampledashedv1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/exampledashed/v1" + fakeexampledashedv1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/exampledashed/v1/fake" kcpexistinginterfacesv1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/existinginterfaces/v1" fakeexistinginterfacesv1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/existinginterfaces/v1/fake" kcpsecondexamplev1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/secondexample/v1" @@ -89,6 +92,11 @@ func (c *ClusterClientset) Tracker() kcptesting.ObjectTracker { return c.tracker } +// ExampleDashedV1 retrieves the ExampleDashedV1ClusterClient. +func (c *ClusterClientset) ExampleDashedV1() kcpexampledashedv1.ExampleDashedV1ClusterInterface { + return &fakeexampledashedv1.ExampleDashedV1ClusterClient{Fake: c.Fake} +} + // Example3V1 retrieves the Example3V1ClusterClient. func (c *ClusterClientset) Example3V1() kcpexample3v1.Example3V1ClusterInterface { return &fakeexample3v1.Example3V1ClusterClient{Fake: c.Fake} @@ -156,6 +164,11 @@ func (c *Clientset) Tracker() kcptesting.ScopedObjectTracker { return c.tracker } +// ExampleDashedV1 retrieves the ExampleDashedV1Client. +func (c *Clientset) ExampleDashedV1() exampledashedv1.ExampleDashedV1Interface { + return &fakeexampledashedv1.ExampleDashedV1Client{Fake: c.Fake, ClusterPath: c.clusterPath} +} + // Example3V1 retrieves the Example3V1Client. func (c *Clientset) Example3V1() example3v1.Example3V1Interface { return &fakeexample3v1.Example3V1Client{Fake: c.Fake, ClusterPath: c.clusterPath} diff --git a/examples/pkg/kcp/clients/clientset/versioned/scheme/register.go b/examples/pkg/kcp/clients/clientset/versioned/scheme/register.go index 2a57d2e75..9761d7ec8 100644 --- a/examples/pkg/kcp/clients/clientset/versioned/scheme/register.go +++ b/examples/pkg/kcp/clients/clientset/versioned/scheme/register.go @@ -33,6 +33,7 @@ import ( examplev1beta1 "acme.corp/pkg/apis/example/v1beta1" examplev2 "acme.corp/pkg/apis/example/v2" example3v1 "acme.corp/pkg/apis/example3/v1" + exampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" existinginterfacesv1 "acme.corp/pkg/apis/existinginterfaces/v1" secondexamplev1 "acme.corp/pkg/apis/secondexample/v1" ) @@ -41,6 +42,7 @@ var Scheme = runtime.NewScheme() var Codecs = serializer.NewCodecFactory(Scheme) var ParameterCodec = runtime.NewParameterCodec(Scheme) var localSchemeBuilder = runtime.SchemeBuilder{ + exampledashedv1.AddToScheme, example3v1.AddToScheme, examplev1.AddToScheme, examplev1alpha1.AddToScheme, diff --git a/examples/pkg/kcp/clients/clientset/versioned/typed/exampledashed/v1/clustertesttype.go b/examples/pkg/kcp/clients/clientset/versioned/typed/exampledashed/v1/clustertesttype.go new file mode 100644 index 000000000..85031ddd1 --- /dev/null +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/exampledashed/v1/clustertesttype.go @@ -0,0 +1,72 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The KCP 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 v1 + +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" + + exampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" + exampledashedv1client "acme.corp/pkg/generated/clientset/versioned/typed/exampledashed/v1" +) + +// ClusterTestTypesClusterGetter has a method to return a ClusterTestTypeClusterInterface. +// A group's cluster client should implement this interface. +type ClusterTestTypesClusterGetter interface { + ClusterTestTypes() ClusterTestTypeClusterInterface +} + +// ClusterTestTypeClusterInterface can operate on ClusterTestTypes across all clusters, +// or scope down to one cluster and return a exampledashedv1client.ClusterTestTypeInterface. +type ClusterTestTypeClusterInterface interface { + Cluster(logicalcluster.Path) exampledashedv1client.ClusterTestTypeInterface + List(ctx context.Context, opts metav1.ListOptions) (*exampledashedv1.ClusterTestTypeList, error) + Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) +} + +type clusterTestTypesClusterInterface struct { + clientCache kcpclient.Cache[*exampledashedv1client.ExampleDashedV1Client] +} + +// Cluster scopes the client down to a particular cluster. +func (c *clusterTestTypesClusterInterface) Cluster(clusterPath logicalcluster.Path) exampledashedv1client.ClusterTestTypeInterface { + if clusterPath == logicalcluster.Wildcard { + panic("A specific cluster must be provided when scoping, not the wildcard.") + } + + return c.clientCache.ClusterOrDie(clusterPath).ClusterTestTypes() +} + +// List returns the entire collection of all ClusterTestTypes across all clusters. +func (c *clusterTestTypesClusterInterface) List(ctx context.Context, opts metav1.ListOptions) (*exampledashedv1.ClusterTestTypeList, error) { + return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).ClusterTestTypes().List(ctx, opts) +} + +// Watch begins to watch all ClusterTestTypes across all clusters. +func (c *clusterTestTypesClusterInterface) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { + return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).ClusterTestTypes().Watch(ctx, opts) +} diff --git a/examples/pkg/kcp/clients/clientset/versioned/typed/exampledashed/v1/exampledashed_client.go b/examples/pkg/kcp/clients/clientset/versioned/typed/exampledashed/v1/exampledashed_client.go new file mode 100644 index 000000000..6030bf227 --- /dev/null +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/exampledashed/v1/exampledashed_client.go @@ -0,0 +1,95 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The KCP 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 v1 + +import ( + "net/http" + + kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" + "github.com/kcp-dev/logicalcluster/v3" + + "k8s.io/client-go/rest" + + exampledashedv1 "acme.corp/pkg/generated/clientset/versioned/typed/exampledashed/v1" +) + +type ExampleDashedV1ClusterInterface interface { + ExampleDashedV1ClusterScoper + TestTypesClusterGetter + ClusterTestTypesClusterGetter +} + +type ExampleDashedV1ClusterScoper interface { + Cluster(logicalcluster.Path) exampledashedv1.ExampleDashedV1Interface +} + +type ExampleDashedV1ClusterClient struct { + clientCache kcpclient.Cache[*exampledashedv1.ExampleDashedV1Client] +} + +func (c *ExampleDashedV1ClusterClient) Cluster(clusterPath logicalcluster.Path) exampledashedv1.ExampleDashedV1Interface { + if clusterPath == logicalcluster.Wildcard { + panic("A specific cluster must be provided when scoping, not the wildcard.") + } + return c.clientCache.ClusterOrDie(clusterPath) +} + +func (c *ExampleDashedV1ClusterClient) TestTypes() TestTypeClusterInterface { + return &testTypesClusterInterface{clientCache: c.clientCache} +} + +func (c *ExampleDashedV1ClusterClient) ClusterTestTypes() ClusterTestTypeClusterInterface { + return &clusterTestTypesClusterInterface{clientCache: c.clientCache} +} + +// NewForConfig creates a new ExampleDashedV1ClusterClient for the given config. +// NewForConfig is equivalent to NewForConfigAndClient(c, httpClient), +// where httpClient was generated with rest.HTTPClientFor(c). +func NewForConfig(c *rest.Config) (*ExampleDashedV1ClusterClient, error) { + client, err := rest.HTTPClientFor(c) + if err != nil { + return nil, err + } + return NewForConfigAndClient(c, client) +} + +// NewForConfigAndClient creates a new ExampleDashedV1ClusterClient 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) (*ExampleDashedV1ClusterClient, error) { + cache := kcpclient.NewCache(c, h, &kcpclient.Constructor[*exampledashedv1.ExampleDashedV1Client]{ + NewForConfigAndClient: exampledashedv1.NewForConfigAndClient, + }) + if _, err := cache.Cluster(logicalcluster.Name("root").Path()); err != nil { + return nil, err + } + return &ExampleDashedV1ClusterClient{clientCache: cache}, nil +} + +// NewForConfigOrDie creates a new ExampleDashedV1ClusterClient for the given config and +// panics if there is an error in the config. +func NewForConfigOrDie(c *rest.Config) *ExampleDashedV1ClusterClient { + client, err := NewForConfig(c) + if err != nil { + panic(err) + } + return client +} diff --git a/examples/pkg/kcp/clients/clientset/versioned/typed/exampledashed/v1/fake/clustertesttype.go b/examples/pkg/kcp/clients/clientset/versioned/typed/exampledashed/v1/fake/clustertesttype.go new file mode 100644 index 000000000..58dbc19e9 --- /dev/null +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/exampledashed/v1/fake/clustertesttype.go @@ -0,0 +1,202 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The KCP 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" + + exampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" + applyconfigurationsexampledashedv1 "acme.corp/pkg/generated/applyconfigurations/exampledashed/v1" + exampledashedv1client "acme.corp/pkg/generated/clientset/versioned/typed/exampledashed/v1" +) + +var clusterTestTypesResource = schema.GroupVersionResource{Group: "example-dashed.some.corp", Version: "v1", Resource: "clustertesttypes"} +var clusterTestTypesKind = schema.GroupVersionKind{Group: "example-dashed.some.corp", Version: "v1", Kind: "ClusterTestType"} + +type clusterTestTypesClusterClient struct { + *kcptesting.Fake +} + +// Cluster scopes the client down to a particular cluster. +func (c *clusterTestTypesClusterClient) Cluster(clusterPath logicalcluster.Path) exampledashedv1client.ClusterTestTypeInterface { + if clusterPath == logicalcluster.Wildcard { + panic("A specific cluster must be provided when scoping, not the wildcard.") + } + + return &clusterTestTypesClient{Fake: c.Fake, ClusterPath: clusterPath} +} + +// List takes label and field selectors, and returns the list of ClusterTestTypes that match those selectors across all clusters. +func (c *clusterTestTypesClusterClient) List(ctx context.Context, opts metav1.ListOptions) (*exampledashedv1.ClusterTestTypeList, error) { + obj, err := c.Fake.Invokes(kcptesting.NewRootListAction(clusterTestTypesResource, clusterTestTypesKind, logicalcluster.Wildcard, opts), &exampledashedv1.ClusterTestTypeList{}) + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &exampledashedv1.ClusterTestTypeList{ListMeta: obj.(*exampledashedv1.ClusterTestTypeList).ListMeta} + for _, item := range obj.(*exampledashedv1.ClusterTestTypeList).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 ClusterTestTypes across all clusters. +func (c *clusterTestTypesClusterClient) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { + return c.Fake.InvokesWatch(kcptesting.NewRootWatchAction(clusterTestTypesResource, logicalcluster.Wildcard, opts)) +} + +type clusterTestTypesClient struct { + *kcptesting.Fake + ClusterPath logicalcluster.Path +} + +func (c *clusterTestTypesClient) Create(ctx context.Context, clusterTestType *exampledashedv1.ClusterTestType, opts metav1.CreateOptions) (*exampledashedv1.ClusterTestType, error) { + obj, err := c.Fake.Invokes(kcptesting.NewRootCreateAction(clusterTestTypesResource, c.ClusterPath, clusterTestType), &exampledashedv1.ClusterTestType{}) + if obj == nil { + return nil, err + } + return obj.(*exampledashedv1.ClusterTestType), err +} + +func (c *clusterTestTypesClient) Update(ctx context.Context, clusterTestType *exampledashedv1.ClusterTestType, opts metav1.UpdateOptions) (*exampledashedv1.ClusterTestType, error) { + obj, err := c.Fake.Invokes(kcptesting.NewRootUpdateAction(clusterTestTypesResource, c.ClusterPath, clusterTestType), &exampledashedv1.ClusterTestType{}) + if obj == nil { + return nil, err + } + return obj.(*exampledashedv1.ClusterTestType), err +} + +func (c *clusterTestTypesClient) UpdateStatus(ctx context.Context, clusterTestType *exampledashedv1.ClusterTestType, opts metav1.UpdateOptions) (*exampledashedv1.ClusterTestType, error) { + obj, err := c.Fake.Invokes(kcptesting.NewRootUpdateSubresourceAction(clusterTestTypesResource, c.ClusterPath, "status", clusterTestType), &exampledashedv1.ClusterTestType{}) + if obj == nil { + return nil, err + } + return obj.(*exampledashedv1.ClusterTestType), err +} + +func (c *clusterTestTypesClient) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { + _, err := c.Fake.Invokes(kcptesting.NewRootDeleteActionWithOptions(clusterTestTypesResource, c.ClusterPath, name, opts), &exampledashedv1.ClusterTestType{}) + return err +} + +func (c *clusterTestTypesClient) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { + action := kcptesting.NewRootDeleteCollectionAction(clusterTestTypesResource, c.ClusterPath, listOpts) + + _, err := c.Fake.Invokes(action, &exampledashedv1.ClusterTestTypeList{}) + return err +} + +func (c *clusterTestTypesClient) Get(ctx context.Context, name string, options metav1.GetOptions) (*exampledashedv1.ClusterTestType, error) { + obj, err := c.Fake.Invokes(kcptesting.NewRootGetAction(clusterTestTypesResource, c.ClusterPath, name), &exampledashedv1.ClusterTestType{}) + if obj == nil { + return nil, err + } + return obj.(*exampledashedv1.ClusterTestType), err +} + +// List takes label and field selectors, and returns the list of ClusterTestTypes that match those selectors. +func (c *clusterTestTypesClient) List(ctx context.Context, opts metav1.ListOptions) (*exampledashedv1.ClusterTestTypeList, error) { + obj, err := c.Fake.Invokes(kcptesting.NewRootListAction(clusterTestTypesResource, clusterTestTypesKind, c.ClusterPath, opts), &exampledashedv1.ClusterTestTypeList{}) + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &exampledashedv1.ClusterTestTypeList{ListMeta: obj.(*exampledashedv1.ClusterTestTypeList).ListMeta} + for _, item := range obj.(*exampledashedv1.ClusterTestTypeList).Items { + if label.Matches(labels.Set(item.Labels)) { + list.Items = append(list.Items, item) + } + } + return list, err +} + +func (c *clusterTestTypesClient) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { + return c.Fake.InvokesWatch(kcptesting.NewRootWatchAction(clusterTestTypesResource, c.ClusterPath, opts)) +} + +func (c *clusterTestTypesClient) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (*exampledashedv1.ClusterTestType, error) { + obj, err := c.Fake.Invokes(kcptesting.NewRootPatchSubresourceAction(clusterTestTypesResource, c.ClusterPath, name, pt, data, subresources...), &exampledashedv1.ClusterTestType{}) + if obj == nil { + return nil, err + } + return obj.(*exampledashedv1.ClusterTestType), err +} + +func (c *clusterTestTypesClient) Apply(ctx context.Context, applyConfiguration *applyconfigurationsexampledashedv1.ClusterTestTypeApplyConfiguration, opts metav1.ApplyOptions) (*exampledashedv1.ClusterTestType, 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(clusterTestTypesResource, c.ClusterPath, *name, types.ApplyPatchType, data), &exampledashedv1.ClusterTestType{}) + if obj == nil { + return nil, err + } + return obj.(*exampledashedv1.ClusterTestType), err +} + +func (c *clusterTestTypesClient) ApplyStatus(ctx context.Context, applyConfiguration *applyconfigurationsexampledashedv1.ClusterTestTypeApplyConfiguration, opts metav1.ApplyOptions) (*exampledashedv1.ClusterTestType, 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(clusterTestTypesResource, c.ClusterPath, *name, types.ApplyPatchType, data, "status"), &exampledashedv1.ClusterTestType{}) + if obj == nil { + return nil, err + } + return obj.(*exampledashedv1.ClusterTestType), err +} diff --git a/examples/pkg/kcp/clients/clientset/versioned/typed/exampledashed/v1/fake/exampledashed_client.go b/examples/pkg/kcp/clients/clientset/versioned/typed/exampledashed/v1/fake/exampledashed_client.go new file mode 100644 index 000000000..7e266d18b --- /dev/null +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/exampledashed/v1/fake/exampledashed_client.go @@ -0,0 +1,73 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The KCP 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" + + exampledashedv1 "acme.corp/pkg/generated/clientset/versioned/typed/exampledashed/v1" + kcpexampledashedv1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/exampledashed/v1" +) + +var _ kcpexampledashedv1.ExampleDashedV1ClusterInterface = (*ExampleDashedV1ClusterClient)(nil) + +type ExampleDashedV1ClusterClient struct { + *kcptesting.Fake +} + +func (c *ExampleDashedV1ClusterClient) Cluster(clusterPath logicalcluster.Path) exampledashedv1.ExampleDashedV1Interface { + if clusterPath == logicalcluster.Wildcard { + panic("A specific cluster must be provided when scoping, not the wildcard.") + } + return &ExampleDashedV1Client{Fake: c.Fake, ClusterPath: clusterPath} +} + +func (c *ExampleDashedV1ClusterClient) TestTypes() kcpexampledashedv1.TestTypeClusterInterface { + return &testTypesClusterClient{Fake: c.Fake} +} + +func (c *ExampleDashedV1ClusterClient) ClusterTestTypes() kcpexampledashedv1.ClusterTestTypeClusterInterface { + return &clusterTestTypesClusterClient{Fake: c.Fake} +} + +var _ exampledashedv1.ExampleDashedV1Interface = (*ExampleDashedV1Client)(nil) + +type ExampleDashedV1Client struct { + *kcptesting.Fake + ClusterPath logicalcluster.Path +} + +func (c *ExampleDashedV1Client) RESTClient() rest.Interface { + var ret *rest.RESTClient + return ret +} + +func (c *ExampleDashedV1Client) TestTypes(namespace string) exampledashedv1.TestTypeInterface { + return &testTypesClient{Fake: c.Fake, ClusterPath: c.ClusterPath, Namespace: namespace} +} + +func (c *ExampleDashedV1Client) ClusterTestTypes() exampledashedv1.ClusterTestTypeInterface { + return &clusterTestTypesClient{Fake: c.Fake, ClusterPath: c.ClusterPath} +} diff --git a/examples/pkg/kcp/clients/clientset/versioned/typed/exampledashed/v1/fake/testtype.go b/examples/pkg/kcp/clients/clientset/versioned/typed/exampledashed/v1/fake/testtype.go new file mode 100644 index 000000000..444efcb75 --- /dev/null +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/exampledashed/v1/fake/testtype.go @@ -0,0 +1,238 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The KCP 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" + + examplev1 "acme.corp/pkg/apis/example/v1" + exampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" + applyconfigurationsexampledashedv1 "acme.corp/pkg/generated/applyconfigurations/exampledashed/v1" + exampledashedv1client "acme.corp/pkg/generated/clientset/versioned/typed/exampledashed/v1" + kcpexampledashedv1 "acme.corp/pkg/kcp/clients/clientset/versioned/typed/exampledashed/v1" +) + +var testTypesResource = schema.GroupVersionResource{Group: "example-dashed.some.corp", Version: "v1", Resource: "testtypes"} +var testTypesKind = schema.GroupVersionKind{Group: "example-dashed.some.corp", Version: "v1", Kind: "TestType"} + +type testTypesClusterClient struct { + *kcptesting.Fake +} + +// Cluster scopes the client down to a particular cluster. +func (c *testTypesClusterClient) Cluster(clusterPath logicalcluster.Path) kcpexampledashedv1.TestTypesNamespacer { + if clusterPath == logicalcluster.Wildcard { + panic("A specific cluster must be provided when scoping, not the wildcard.") + } + + return &testTypesNamespacer{Fake: c.Fake, ClusterPath: clusterPath} +} + +// List takes label and field selectors, and returns the list of TestTypes that match those selectors across all clusters. +func (c *testTypesClusterClient) List(ctx context.Context, opts metav1.ListOptions) (*exampledashedv1.TestTypeList, error) { + obj, err := c.Fake.Invokes(kcptesting.NewListAction(testTypesResource, testTypesKind, logicalcluster.Wildcard, metav1.NamespaceAll, opts), &exampledashedv1.TestTypeList{}) + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &exampledashedv1.TestTypeList{ListMeta: obj.(*exampledashedv1.TestTypeList).ListMeta} + for _, item := range obj.(*exampledashedv1.TestTypeList).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 TestTypes across all clusters. +func (c *testTypesClusterClient) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { + return c.Fake.InvokesWatch(kcptesting.NewWatchAction(testTypesResource, logicalcluster.Wildcard, metav1.NamespaceAll, opts)) +} + +type testTypesNamespacer struct { + *kcptesting.Fake + ClusterPath logicalcluster.Path +} + +func (n *testTypesNamespacer) Namespace(namespace string) exampledashedv1client.TestTypeInterface { + return &testTypesClient{Fake: n.Fake, ClusterPath: n.ClusterPath, Namespace: namespace} +} + +type testTypesClient struct { + *kcptesting.Fake + ClusterPath logicalcluster.Path + Namespace string +} + +func (c *testTypesClient) Create(ctx context.Context, testType *exampledashedv1.TestType, opts metav1.CreateOptions) (*exampledashedv1.TestType, error) { + obj, err := c.Fake.Invokes(kcptesting.NewCreateAction(testTypesResource, c.ClusterPath, c.Namespace, testType), &exampledashedv1.TestType{}) + if obj == nil { + return nil, err + } + return obj.(*exampledashedv1.TestType), err +} + +func (c *testTypesClient) Update(ctx context.Context, testType *exampledashedv1.TestType, opts metav1.UpdateOptions) (*exampledashedv1.TestType, error) { + obj, err := c.Fake.Invokes(kcptesting.NewUpdateAction(testTypesResource, c.ClusterPath, c.Namespace, testType), &exampledashedv1.TestType{}) + if obj == nil { + return nil, err + } + return obj.(*exampledashedv1.TestType), err +} + +func (c *testTypesClient) UpdateStatus(ctx context.Context, testType *exampledashedv1.TestType, opts metav1.UpdateOptions) (*exampledashedv1.TestType, error) { + obj, err := c.Fake.Invokes(kcptesting.NewUpdateSubresourceAction(testTypesResource, c.ClusterPath, "status", c.Namespace, testType), &exampledashedv1.TestType{}) + if obj == nil { + return nil, err + } + return obj.(*exampledashedv1.TestType), err +} + +func (c *testTypesClient) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { + _, err := c.Fake.Invokes(kcptesting.NewDeleteActionWithOptions(testTypesResource, c.ClusterPath, c.Namespace, name, opts), &exampledashedv1.TestType{}) + return err +} + +func (c *testTypesClient) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { + action := kcptesting.NewDeleteCollectionAction(testTypesResource, c.ClusterPath, c.Namespace, listOpts) + + _, err := c.Fake.Invokes(action, &exampledashedv1.TestTypeList{}) + return err +} + +func (c *testTypesClient) Get(ctx context.Context, name string, options metav1.GetOptions) (*exampledashedv1.TestType, error) { + obj, err := c.Fake.Invokes(kcptesting.NewGetAction(testTypesResource, c.ClusterPath, c.Namespace, name), &exampledashedv1.TestType{}) + if obj == nil { + return nil, err + } + return obj.(*exampledashedv1.TestType), err +} + +// List takes label and field selectors, and returns the list of TestTypes that match those selectors. +func (c *testTypesClient) List(ctx context.Context, opts metav1.ListOptions) (*exampledashedv1.TestTypeList, error) { + obj, err := c.Fake.Invokes(kcptesting.NewListAction(testTypesResource, testTypesKind, c.ClusterPath, c.Namespace, opts), &exampledashedv1.TestTypeList{}) + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &exampledashedv1.TestTypeList{ListMeta: obj.(*exampledashedv1.TestTypeList).ListMeta} + for _, item := range obj.(*exampledashedv1.TestTypeList).Items { + if label.Matches(labels.Set(item.Labels)) { + list.Items = append(list.Items, item) + } + } + return list, err +} + +func (c *testTypesClient) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { + return c.Fake.InvokesWatch(kcptesting.NewWatchAction(testTypesResource, c.ClusterPath, c.Namespace, opts)) +} + +func (c *testTypesClient) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (*exampledashedv1.TestType, error) { + obj, err := c.Fake.Invokes(kcptesting.NewPatchSubresourceAction(testTypesResource, c.ClusterPath, c.Namespace, name, pt, data, subresources...), &exampledashedv1.TestType{}) + if obj == nil { + return nil, err + } + return obj.(*exampledashedv1.TestType), err +} + +func (c *testTypesClient) Apply(ctx context.Context, applyConfiguration *applyconfigurationsexampledashedv1.TestTypeApplyConfiguration, opts metav1.ApplyOptions) (*exampledashedv1.TestType, 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(testTypesResource, c.ClusterPath, c.Namespace, *name, types.ApplyPatchType, data), &exampledashedv1.TestType{}) + if obj == nil { + return nil, err + } + return obj.(*exampledashedv1.TestType), err +} + +func (c *testTypesClient) ApplyStatus(ctx context.Context, applyConfiguration *applyconfigurationsexampledashedv1.TestTypeApplyConfiguration, opts metav1.ApplyOptions) (*exampledashedv1.TestType, 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(testTypesResource, c.ClusterPath, c.Namespace, *name, types.ApplyPatchType, data, "status"), &exampledashedv1.TestType{}) + if obj == nil { + return nil, err + } + return obj.(*exampledashedv1.TestType), err +} + +func (c *testTypesClient) CreateField(ctx context.Context, testTypeName string, field *examplev1.Field, opts metav1.CreateOptions) (*examplev1.Field, error) { + obj, err := c.Fake.Invokes(kcptesting.NewCreateSubresourceAction(testTypesResource, c.ClusterPath, testTypeName, "field", c.Namespace, field), &examplev1.Field{}) + if obj == nil { + return nil, err + } + return obj.(*examplev1.Field), err +} + +func (c *testTypesClient) UpdateField(ctx context.Context, testTypeName string, field *examplev1.Field, opts metav1.UpdateOptions) (*examplev1.Field, error) { + obj, err := c.Fake.Invokes(kcptesting.NewUpdateSubresourceAction(testTypesResource, c.ClusterPath, "field", c.Namespace, field), &examplev1.Field{}) + if obj == nil { + return nil, err + } + return obj.(*examplev1.Field), err +} + +func (c *testTypesClient) GetField(ctx context.Context, testTypeName string, options metav1.GetOptions) (*examplev1.Field, error) { + obj, err := c.Fake.Invokes(kcptesting.NewGetSubresourceAction(testTypesResource, c.ClusterPath, "field", c.Namespace, testTypeName), &examplev1.Field{}) + if obj == nil { + return nil, err + } + return obj.(*examplev1.Field), err +} diff --git a/examples/pkg/kcp/clients/clientset/versioned/typed/exampledashed/v1/testtype.go b/examples/pkg/kcp/clients/clientset/versioned/typed/exampledashed/v1/testtype.go new file mode 100644 index 000000000..eb9eacdd1 --- /dev/null +++ b/examples/pkg/kcp/clients/clientset/versioned/typed/exampledashed/v1/testtype.go @@ -0,0 +1,86 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The KCP 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 v1 + +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" + + exampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" + exampledashedv1client "acme.corp/pkg/generated/clientset/versioned/typed/exampledashed/v1" +) + +// TestTypesClusterGetter has a method to return a TestTypeClusterInterface. +// A group's cluster client should implement this interface. +type TestTypesClusterGetter interface { + TestTypes() TestTypeClusterInterface +} + +// TestTypeClusterInterface can operate on TestTypes across all clusters, +// or scope down to one cluster and return a TestTypesNamespacer. +type TestTypeClusterInterface interface { + Cluster(logicalcluster.Path) TestTypesNamespacer + List(ctx context.Context, opts metav1.ListOptions) (*exampledashedv1.TestTypeList, error) + Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) +} + +type testTypesClusterInterface struct { + clientCache kcpclient.Cache[*exampledashedv1client.ExampleDashedV1Client] +} + +// Cluster scopes the client down to a particular cluster. +func (c *testTypesClusterInterface) Cluster(clusterPath logicalcluster.Path) TestTypesNamespacer { + if clusterPath == logicalcluster.Wildcard { + panic("A specific cluster must be provided when scoping, not the wildcard.") + } + + return &testTypesNamespacer{clientCache: c.clientCache, clusterPath: clusterPath} +} + +// List returns the entire collection of all TestTypes across all clusters. +func (c *testTypesClusterInterface) List(ctx context.Context, opts metav1.ListOptions) (*exampledashedv1.TestTypeList, error) { + return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).TestTypes(metav1.NamespaceAll).List(ctx, opts) +} + +// Watch begins to watch all TestTypes across all clusters. +func (c *testTypesClusterInterface) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { + return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).TestTypes(metav1.NamespaceAll).Watch(ctx, opts) +} + +// TestTypesNamespacer can scope to objects within a namespace, returning a exampledashedv1client.TestTypeInterface. +type TestTypesNamespacer interface { + Namespace(string) exampledashedv1client.TestTypeInterface +} + +type testTypesNamespacer struct { + clientCache kcpclient.Cache[*exampledashedv1client.ExampleDashedV1Client] + clusterPath logicalcluster.Path +} + +func (n *testTypesNamespacer) Namespace(namespace string) exampledashedv1client.TestTypeInterface { + return n.clientCache.ClusterOrDie(n.clusterPath).TestTypes(namespace) +} diff --git a/examples/pkg/kcp/clients/informers/externalversions/exampledashed/interface.go b/examples/pkg/kcp/clients/informers/externalversions/exampledashed/interface.go new file mode 100644 index 000000000..31fab0eab --- /dev/null +++ b/examples/pkg/kcp/clients/informers/externalversions/exampledashed/interface.go @@ -0,0 +1,68 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The KCP 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 exampledashed + +import ( + "acme.corp/pkg/kcp/clients/informers/externalversions/exampledashed/v1" + "acme.corp/pkg/kcp/clients/informers/externalversions/internalinterfaces" +) + +type ClusterInterface interface { + // V1 provides access to the shared informers in V1. + V1() v1.ClusterInterface +} + +type group struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc +} + +// New returns a new ClusterInterface. +func New(f internalinterfaces.SharedInformerFactory, tweakListOptions internalinterfaces.TweakListOptionsFunc) ClusterInterface { + return &group{factory: f, tweakListOptions: tweakListOptions} +} + +// V1 returns a new v1.ClusterInterface. +func (g *group) V1() v1.ClusterInterface { + return v1.New(g.factory, g.tweakListOptions) +} + +type Interface interface { + // V1 provides access to the shared informers in V1. + V1() v1.Interface +} + +type scopedGroup struct { + factory internalinterfaces.SharedScopedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc + namespace string +} + +// New returns a new Interface. +func NewScoped(f internalinterfaces.SharedScopedInformerFactory, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) Interface { + return &scopedGroup{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} +} + +// V1 returns a new v1.ClusterInterface. +func (g *scopedGroup) V1() v1.Interface { + return v1.NewScoped(g.factory, g.namespace, g.tweakListOptions) +} diff --git a/examples/pkg/kcp/clients/informers/externalversions/exampledashed/v1/clustertesttype.go b/examples/pkg/kcp/clients/informers/externalversions/exampledashed/v1/clustertesttype.go new file mode 100644 index 000000000..fa1d5ce7e --- /dev/null +++ b/examples/pkg/kcp/clients/informers/externalversions/exampledashed/v1/clustertesttype.go @@ -0,0 +1,179 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The KCP 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 v1 + +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" + + exampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" + scopedclientset "acme.corp/pkg/generated/clientset/versioned" + clientset "acme.corp/pkg/kcp/clients/clientset/versioned" + "acme.corp/pkg/kcp/clients/informers/externalversions/internalinterfaces" + exampledashedv1listers "acme.corp/pkg/kcp/clients/listers/exampledashed/v1" +) + +// ClusterTestTypeClusterInformer provides access to a shared informer and lister for +// ClusterTestTypes. +type ClusterTestTypeClusterInformer interface { + Cluster(logicalcluster.Name) ClusterTestTypeInformer + Informer() kcpcache.ScopeableSharedIndexInformer + Lister() exampledashedv1listers.ClusterTestTypeClusterLister +} + +type clusterTestTypeClusterInformer struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc +} + +// NewClusterTestTypeClusterInformer constructs a new informer for ClusterTestType 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 NewClusterTestTypeClusterInformer(client clientset.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers) kcpcache.ScopeableSharedIndexInformer { + return NewFilteredClusterTestTypeClusterInformer(client, resyncPeriod, indexers, nil) +} + +// NewFilteredClusterTestTypeClusterInformer constructs a new informer for ClusterTestType 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 NewFilteredClusterTestTypeClusterInformer(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.ExampleDashedV1().ClusterTestTypes().List(context.TODO(), options) + }, + WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ExampleDashedV1().ClusterTestTypes().Watch(context.TODO(), options) + }, + }, + &exampledashedv1.ClusterTestType{}, + resyncPeriod, + indexers, + ) +} + +func (f *clusterTestTypeClusterInformer) defaultInformer(client clientset.ClusterInterface, resyncPeriod time.Duration) kcpcache.ScopeableSharedIndexInformer { + return NewFilteredClusterTestTypeClusterInformer(client, resyncPeriod, cache.Indexers{ + kcpcache.ClusterIndexName: kcpcache.ClusterIndexFunc, + }, + f.tweakListOptions, + ) +} + +func (f *clusterTestTypeClusterInformer) Informer() kcpcache.ScopeableSharedIndexInformer { + return f.factory.InformerFor(&exampledashedv1.ClusterTestType{}, f.defaultInformer) +} + +func (f *clusterTestTypeClusterInformer) Lister() exampledashedv1listers.ClusterTestTypeClusterLister { + return exampledashedv1listers.NewClusterTestTypeClusterLister(f.Informer().GetIndexer()) +} + +// ClusterTestTypeInformer provides access to a shared informer and lister for +// ClusterTestTypes. +type ClusterTestTypeInformer interface { + Informer() cache.SharedIndexInformer + Lister() exampledashedv1listers.ClusterTestTypeLister +} + +func (f *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name) ClusterTestTypeInformer { + return &clusterTestTypeInformer{ + informer: f.Informer().Cluster(clusterName), + lister: f.Lister().Cluster(clusterName), + } +} + +type clusterTestTypeInformer struct { + informer cache.SharedIndexInformer + lister exampledashedv1listers.ClusterTestTypeLister +} + +func (f *clusterTestTypeInformer) Informer() cache.SharedIndexInformer { + return f.informer +} + +func (f *clusterTestTypeInformer) Lister() exampledashedv1listers.ClusterTestTypeLister { + return f.lister +} + +type clusterTestTypeScopedInformer struct { + factory internalinterfaces.SharedScopedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc +} + +func (f *clusterTestTypeScopedInformer) Informer() cache.SharedIndexInformer { + return f.factory.InformerFor(&exampledashedv1.ClusterTestType{}, f.defaultInformer) +} + +func (f *clusterTestTypeScopedInformer) Lister() exampledashedv1listers.ClusterTestTypeLister { + return exampledashedv1listers.NewClusterTestTypeLister(f.Informer().GetIndexer()) +} + +// NewClusterTestTypeInformer constructs a new informer for ClusterTestType 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 NewClusterTestTypeInformer(client scopedclientset.Interface, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return NewFilteredClusterTestTypeInformer(client, resyncPeriod, indexers, nil) +} + +// NewFilteredClusterTestTypeInformer constructs a new informer for ClusterTestType 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 NewFilteredClusterTestTypeInformer(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.ExampleDashedV1().ClusterTestTypes().List(context.TODO(), options) + }, + WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ExampleDashedV1().ClusterTestTypes().Watch(context.TODO(), options) + }, + }, + &exampledashedv1.ClusterTestType{}, + resyncPeriod, + indexers, + ) +} + +func (f *clusterTestTypeScopedInformer) defaultInformer(client scopedclientset.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewFilteredClusterTestTypeInformer(client, resyncPeriod, cache.Indexers{}, f.tweakListOptions) +} diff --git a/examples/pkg/kcp/clients/informers/externalversions/exampledashed/v1/interface.go b/examples/pkg/kcp/clients/informers/externalversions/exampledashed/v1/interface.go new file mode 100644 index 000000000..3034bb594 --- /dev/null +++ b/examples/pkg/kcp/clients/informers/externalversions/exampledashed/v1/interface.go @@ -0,0 +1,81 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The KCP 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 v1 + +import ( + "acme.corp/pkg/kcp/clients/informers/externalversions/internalinterfaces" +) + +type ClusterInterface interface { + // TestTypes returns a TestTypeClusterInformer + TestTypes() TestTypeClusterInformer + // ClusterTestTypes returns a ClusterTestTypeClusterInformer + ClusterTestTypes() ClusterTestTypeClusterInformer +} + +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} +} + +// TestTypes returns a TestTypeClusterInformer +func (v *version) TestTypes() TestTypeClusterInformer { + return &testTypeClusterInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} +} + +// ClusterTestTypes returns a ClusterTestTypeClusterInformer +func (v *version) ClusterTestTypes() ClusterTestTypeClusterInformer { + return &clusterTestTypeClusterInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} +} + +type Interface interface { + // TestTypes returns a TestTypeInformer + TestTypes() TestTypeInformer + // ClusterTestTypes returns a ClusterTestTypeInformer + ClusterTestTypes() ClusterTestTypeInformer +} + +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} +} + +// TestTypes returns a TestTypeInformer +func (v *scopedVersion) TestTypes() TestTypeInformer { + return &testTypeScopedInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} +} + +// ClusterTestTypes returns a ClusterTestTypeInformer +func (v *scopedVersion) ClusterTestTypes() ClusterTestTypeInformer { + return &clusterTestTypeScopedInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} +} diff --git a/examples/pkg/kcp/clients/informers/externalversions/exampledashed/v1/testtype.go b/examples/pkg/kcp/clients/informers/externalversions/exampledashed/v1/testtype.go new file mode 100644 index 000000000..ef617f707 --- /dev/null +++ b/examples/pkg/kcp/clients/informers/externalversions/exampledashed/v1/testtype.go @@ -0,0 +1,182 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The KCP 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 v1 + +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" + + exampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" + scopedclientset "acme.corp/pkg/generated/clientset/versioned" + clientset "acme.corp/pkg/kcp/clients/clientset/versioned" + "acme.corp/pkg/kcp/clients/informers/externalversions/internalinterfaces" + exampledashedv1listers "acme.corp/pkg/kcp/clients/listers/exampledashed/v1" +) + +// TestTypeClusterInformer provides access to a shared informer and lister for +// TestTypes. +type TestTypeClusterInformer interface { + Cluster(logicalcluster.Name) TestTypeInformer + Informer() kcpcache.ScopeableSharedIndexInformer + Lister() exampledashedv1listers.TestTypeClusterLister +} + +type testTypeClusterInformer struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc +} + +// NewTestTypeClusterInformer constructs a new informer for TestType 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 NewTestTypeClusterInformer(client clientset.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers) kcpcache.ScopeableSharedIndexInformer { + return NewFilteredTestTypeClusterInformer(client, resyncPeriod, indexers, nil) +} + +// NewFilteredTestTypeClusterInformer constructs a new informer for TestType 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 NewFilteredTestTypeClusterInformer(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.ExampleDashedV1().TestTypes().List(context.TODO(), options) + }, + WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ExampleDashedV1().TestTypes().Watch(context.TODO(), options) + }, + }, + &exampledashedv1.TestType{}, + resyncPeriod, + indexers, + ) +} + +func (f *testTypeClusterInformer) defaultInformer(client clientset.ClusterInterface, resyncPeriod time.Duration) kcpcache.ScopeableSharedIndexInformer { + return NewFilteredTestTypeClusterInformer(client, resyncPeriod, cache.Indexers{ + kcpcache.ClusterIndexName: kcpcache.ClusterIndexFunc, + kcpcache.ClusterAndNamespaceIndexName: kcpcache.ClusterAndNamespaceIndexFunc}, + f.tweakListOptions, + ) +} + +func (f *testTypeClusterInformer) Informer() kcpcache.ScopeableSharedIndexInformer { + return f.factory.InformerFor(&exampledashedv1.TestType{}, f.defaultInformer) +} + +func (f *testTypeClusterInformer) Lister() exampledashedv1listers.TestTypeClusterLister { + return exampledashedv1listers.NewTestTypeClusterLister(f.Informer().GetIndexer()) +} + +// TestTypeInformer provides access to a shared informer and lister for +// TestTypes. +type TestTypeInformer interface { + Informer() cache.SharedIndexInformer + Lister() exampledashedv1listers.TestTypeLister +} + +func (f *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) TestTypeInformer { + return &testTypeInformer{ + informer: f.Informer().Cluster(clusterName), + lister: f.Lister().Cluster(clusterName), + } +} + +type testTypeInformer struct { + informer cache.SharedIndexInformer + lister exampledashedv1listers.TestTypeLister +} + +func (f *testTypeInformer) Informer() cache.SharedIndexInformer { + return f.informer +} + +func (f *testTypeInformer) Lister() exampledashedv1listers.TestTypeLister { + return f.lister +} + +type testTypeScopedInformer struct { + factory internalinterfaces.SharedScopedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc + namespace string +} + +func (f *testTypeScopedInformer) Informer() cache.SharedIndexInformer { + return f.factory.InformerFor(&exampledashedv1.TestType{}, f.defaultInformer) +} + +func (f *testTypeScopedInformer) Lister() exampledashedv1listers.TestTypeLister { + return exampledashedv1listers.NewTestTypeLister(f.Informer().GetIndexer()) +} + +// NewTestTypeInformer constructs a new informer for TestType 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 NewTestTypeInformer(client scopedclientset.Interface, resyncPeriod time.Duration, namespace string, indexers cache.Indexers) cache.SharedIndexInformer { + return NewFilteredTestTypeInformer(client, resyncPeriod, namespace, indexers, nil) +} + +// NewFilteredTestTypeInformer constructs a new informer for TestType 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 NewFilteredTestTypeInformer(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.ExampleDashedV1().TestTypes(namespace).List(context.TODO(), options) + }, + WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ExampleDashedV1().TestTypes(namespace).Watch(context.TODO(), options) + }, + }, + &exampledashedv1.TestType{}, + resyncPeriod, + indexers, + ) +} + +func (f *testTypeScopedInformer) defaultInformer(client scopedclientset.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewFilteredTestTypeInformer(client, resyncPeriod, f.namespace, cache.Indexers{ + cache.NamespaceIndex: cache.MetaNamespaceIndexFunc, + }, f.tweakListOptions) +} diff --git a/examples/pkg/kcp/clients/informers/externalversions/factory.go b/examples/pkg/kcp/clients/informers/externalversions/factory.go index f6fafbfef..4f70c651f 100644 --- a/examples/pkg/kcp/clients/informers/externalversions/factory.go +++ b/examples/pkg/kcp/clients/informers/externalversions/factory.go @@ -38,6 +38,7 @@ import ( clientset "acme.corp/pkg/kcp/clients/clientset/versioned" exampleinformers "acme.corp/pkg/kcp/clients/informers/externalversions/example" example3informers "acme.corp/pkg/kcp/clients/informers/externalversions/example3" + exampledashedinformers "acme.corp/pkg/kcp/clients/informers/externalversions/exampledashed" existinginterfacesinformers "acme.corp/pkg/kcp/clients/informers/externalversions/existinginterfaces" "acme.corp/pkg/kcp/clients/informers/externalversions/internalinterfaces" secondexampleinformers "acme.corp/pkg/kcp/clients/informers/externalversions/secondexample" @@ -273,6 +274,7 @@ type SharedInformerFactory interface { InformerFor(obj runtime.Object, newFunc internalinterfaces.NewInformerFunc) kcpcache.ScopeableSharedIndexInformer Example() exampleinformers.ClusterInterface + ExampleDashed() exampledashedinformers.ClusterInterface Example3() example3informers.ClusterInterface Existinginterfaces() existinginterfacesinformers.ClusterInterface Secondexample() secondexampleinformers.ClusterInterface @@ -282,6 +284,10 @@ func (f *sharedInformerFactory) Example() exampleinformers.ClusterInterface { return exampleinformers.New(f, f.tweakListOptions) } +func (f *sharedInformerFactory) ExampleDashed() exampledashedinformers.ClusterInterface { + return exampledashedinformers.New(f, f.tweakListOptions) +} + func (f *sharedInformerFactory) Example3() example3informers.ClusterInterface { return example3informers.New(f, f.tweakListOptions) } @@ -439,6 +445,7 @@ type SharedScopedInformerFactory interface { WaitForCacheSync(stopCh <-chan struct{}) map[reflect.Type]bool Example() exampleinformers.Interface + ExampleDashed() exampledashedinformers.Interface Example3() example3informers.Interface Existinginterfaces() existinginterfacesinformers.Interface Secondexample() secondexampleinformers.Interface @@ -448,6 +455,10 @@ func (f *sharedScopedInformerFactory) Example() exampleinformers.Interface { return exampleinformers.NewScoped(f, f.namespace, f.tweakListOptions) } +func (f *sharedScopedInformerFactory) ExampleDashed() exampledashedinformers.Interface { + return exampledashedinformers.NewScoped(f, f.namespace, f.tweakListOptions) +} + func (f *sharedScopedInformerFactory) Example3() example3informers.Interface { return example3informers.NewScoped(f, f.namespace, f.tweakListOptions) } diff --git a/examples/pkg/kcp/clients/informers/externalversions/generic.go b/examples/pkg/kcp/clients/informers/externalversions/generic.go index 0e9e4a29d..9ff9079e1 100644 --- a/examples/pkg/kcp/clients/informers/externalversions/generic.go +++ b/examples/pkg/kcp/clients/informers/externalversions/generic.go @@ -35,6 +35,7 @@ import ( examplev1beta1 "acme.corp/pkg/apis/example/v1beta1" examplev2 "acme.corp/pkg/apis/example/v2" example3v1 "acme.corp/pkg/apis/example3/v1" + exampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" existinginterfacesv1 "acme.corp/pkg/apis/existinginterfaces/v1" secondexamplev1 "acme.corp/pkg/apis/secondexample/v1" ) @@ -92,6 +93,11 @@ func (f *genericInformer) Lister() cache.GenericLister { // TODO extend this to unknown resources with a client pool func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource) (GenericClusterInformer, error) { switch resource { + // Group=example-dashed.some.corp, Version=V1 + case exampledashedv1.SchemeGroupVersion.WithResource("testtypes"): + return &genericClusterInformer{resource: resource.GroupResource(), informer: f.ExampleDashed().V1().TestTypes().Informer()}, nil + case exampledashedv1.SchemeGroupVersion.WithResource("clustertesttypes"): + return &genericClusterInformer{resource: resource.GroupResource(), informer: f.ExampleDashed().V1().ClusterTestTypes().Informer()}, nil // Group=example3.some.corp, Version=V1 case example3v1.SchemeGroupVersion.WithResource("testtypes"): return &genericClusterInformer{resource: resource.GroupResource(), informer: f.Example3().V1().TestTypes().Informer()}, nil @@ -136,6 +142,13 @@ func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource // TODO extend this to unknown resources with a client pool func (f *sharedScopedInformerFactory) ForResource(resource schema.GroupVersionResource) (GenericInformer, error) { switch resource { + // Group=example-dashed.some.corp, Version=V1 + case exampledashedv1.SchemeGroupVersion.WithResource("testtypes"): + informer := f.ExampleDashed().V1().TestTypes().Informer() + return &genericInformer{lister: cache.NewGenericLister(informer.GetIndexer(), resource.GroupResource()), informer: informer}, nil + case exampledashedv1.SchemeGroupVersion.WithResource("clustertesttypes"): + informer := f.ExampleDashed().V1().ClusterTestTypes().Informer() + return &genericInformer{lister: cache.NewGenericLister(informer.GetIndexer(), resource.GroupResource()), informer: informer}, nil // Group=example3.some.corp, Version=V1 case example3v1.SchemeGroupVersion.WithResource("testtypes"): informer := f.Example3().V1().TestTypes().Informer() diff --git a/examples/pkg/kcp/clients/listers/exampledashed/v1/clustertesttype.go b/examples/pkg/kcp/clients/listers/exampledashed/v1/clustertesttype.go new file mode 100644 index 000000000..943a047e7 --- /dev/null +++ b/examples/pkg/kcp/clients/listers/exampledashed/v1/clustertesttype.go @@ -0,0 +1,143 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The KCP 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 v1 + +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" + + exampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" +) + +// ClusterTestTypeClusterLister can list ClusterTestTypes across all workspaces, or scope down to a ClusterTestTypeLister for one workspace. +// All objects returned here must be treated as read-only. +type ClusterTestTypeClusterLister interface { + // List lists all ClusterTestTypes in the indexer. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*exampledashedv1.ClusterTestType, err error) + // Cluster returns a lister that can list and get ClusterTestTypes in one workspace. + Cluster(clusterName logicalcluster.Name) ClusterTestTypeLister + ClusterTestTypeClusterListerExpansion +} + +type clusterTestTypeClusterLister struct { + indexer cache.Indexer +} + +// NewClusterTestTypeClusterLister returns a new ClusterTestTypeClusterLister. +// 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 NewClusterTestTypeClusterLister(indexer cache.Indexer) *clusterTestTypeClusterLister { + return &clusterTestTypeClusterLister{indexer: indexer} +} + +// List lists all ClusterTestTypes in the indexer across all workspaces. +func (s *clusterTestTypeClusterLister) List(selector labels.Selector) (ret []*exampledashedv1.ClusterTestType, err error) { + err = cache.ListAll(s.indexer, selector, func(m interface{}) { + ret = append(ret, m.(*exampledashedv1.ClusterTestType)) + }) + return ret, err +} + +// Cluster scopes the lister to one workspace, allowing users to list and get ClusterTestTypes. +func (s *clusterTestTypeClusterLister) Cluster(clusterName logicalcluster.Name) ClusterTestTypeLister { + return &clusterTestTypeLister{indexer: s.indexer, clusterName: clusterName} +} + +// ClusterTestTypeLister can list all ClusterTestTypes, or get one in particular. +// All objects returned here must be treated as read-only. +type ClusterTestTypeLister interface { + // List lists all ClusterTestTypes in the workspace. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*exampledashedv1.ClusterTestType, err error) + // Get retrieves the ClusterTestType from the indexer for a given workspace and name. + // Objects returned here must be treated as read-only. + Get(name string) (*exampledashedv1.ClusterTestType, error) + ClusterTestTypeListerExpansion +} + +// clusterTestTypeLister can list all ClusterTestTypes inside a workspace. +type clusterTestTypeLister struct { + indexer cache.Indexer + clusterName logicalcluster.Name +} + +// List lists all ClusterTestTypes in the indexer for a workspace. +func (s *clusterTestTypeLister) List(selector labels.Selector) (ret []*exampledashedv1.ClusterTestType, err error) { + err = kcpcache.ListAllByCluster(s.indexer, s.clusterName, selector, func(i interface{}) { + ret = append(ret, i.(*exampledashedv1.ClusterTestType)) + }) + return ret, err +} + +// Get retrieves the ClusterTestType from the indexer for a given workspace and name. +func (s *clusterTestTypeLister) Get(name string) (*exampledashedv1.ClusterTestType, 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(exampledashedv1.Resource("clustertesttypes"), name) + } + return obj.(*exampledashedv1.ClusterTestType), nil +} + +// NewClusterTestTypeLister returns a new ClusterTestTypeLister. +// We assume that the indexer: +// - is fed by a workspace-scoped LIST+WATCH +// - uses cache.MetaNamespaceKeyFunc as the key function +func NewClusterTestTypeLister(indexer cache.Indexer) *clusterTestTypeScopedLister { + return &clusterTestTypeScopedLister{indexer: indexer} +} + +// clusterTestTypeScopedLister can list all ClusterTestTypes inside a workspace. +type clusterTestTypeScopedLister struct { + indexer cache.Indexer +} + +// List lists all ClusterTestTypes in the indexer for a workspace. +func (s *clusterTestTypeScopedLister) List(selector labels.Selector) (ret []*exampledashedv1.ClusterTestType, err error) { + err = cache.ListAll(s.indexer, selector, func(i interface{}) { + ret = append(ret, i.(*exampledashedv1.ClusterTestType)) + }) + return ret, err +} + +// Get retrieves the ClusterTestType from the indexer for a given workspace and name. +func (s *clusterTestTypeScopedLister) Get(name string) (*exampledashedv1.ClusterTestType, error) { + key := name + obj, exists, err := s.indexer.GetByKey(key) + if err != nil { + return nil, err + } + if !exists { + return nil, errors.NewNotFound(exampledashedv1.Resource("clustertesttypes"), name) + } + return obj.(*exampledashedv1.ClusterTestType), nil +} diff --git a/examples/pkg/kcp/clients/listers/exampledashed/v1/clustertesttype_expansion.go b/examples/pkg/kcp/clients/listers/exampledashed/v1/clustertesttype_expansion.go new file mode 100644 index 000000000..a85e878f1 --- /dev/null +++ b/examples/pkg/kcp/clients/listers/exampledashed/v1/clustertesttype_expansion.go @@ -0,0 +1,28 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The KCP 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 v1 + +// ClusterTestTypeClusterListerExpansion allows custom methods to be added to ClusterTestTypeClusterLister. +type ClusterTestTypeClusterListerExpansion interface{} + +// ClusterTestTypeListerExpansion allows custom methods to be added to ClusterTestTypeLister. +type ClusterTestTypeListerExpansion interface{} diff --git a/examples/pkg/kcp/clients/listers/exampledashed/v1/testtype.go b/examples/pkg/kcp/clients/listers/exampledashed/v1/testtype.go new file mode 100644 index 000000000..30453a7d2 --- /dev/null +++ b/examples/pkg/kcp/clients/listers/exampledashed/v1/testtype.go @@ -0,0 +1,196 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The KCP 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 v1 + +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" + + exampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" +) + +// TestTypeClusterLister can list TestTypes across all workspaces, or scope down to a TestTypeLister for one workspace. +// All objects returned here must be treated as read-only. +type TestTypeClusterLister interface { + // List lists all TestTypes in the indexer. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*exampledashedv1.TestType, err error) + // Cluster returns a lister that can list and get TestTypes in one workspace. + Cluster(clusterName logicalcluster.Name) TestTypeLister + TestTypeClusterListerExpansion +} + +type testTypeClusterLister struct { + indexer cache.Indexer +} + +// NewTestTypeClusterLister returns a new TestTypeClusterLister. +// 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 NewTestTypeClusterLister(indexer cache.Indexer) *testTypeClusterLister { + return &testTypeClusterLister{indexer: indexer} +} + +// List lists all TestTypes in the indexer across all workspaces. +func (s *testTypeClusterLister) List(selector labels.Selector) (ret []*exampledashedv1.TestType, err error) { + err = cache.ListAll(s.indexer, selector, func(m interface{}) { + ret = append(ret, m.(*exampledashedv1.TestType)) + }) + return ret, err +} + +// Cluster scopes the lister to one workspace, allowing users to list and get TestTypes. +func (s *testTypeClusterLister) Cluster(clusterName logicalcluster.Name) TestTypeLister { + return &testTypeLister{indexer: s.indexer, clusterName: clusterName} +} + +// TestTypeLister can list TestTypes across all namespaces, or scope down to a TestTypeNamespaceLister for one namespace. +// All objects returned here must be treated as read-only. +type TestTypeLister interface { + // List lists all TestTypes in the workspace. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*exampledashedv1.TestType, err error) + // TestTypes returns a lister that can list and get TestTypes in one workspace and namespace. + TestTypes(namespace string) TestTypeNamespaceLister + TestTypeListerExpansion +} + +// testTypeLister can list all TestTypes inside a workspace or scope down to a TestTypeLister for one namespace. +type testTypeLister struct { + indexer cache.Indexer + clusterName logicalcluster.Name +} + +// List lists all TestTypes in the indexer for a workspace. +func (s *testTypeLister) List(selector labels.Selector) (ret []*exampledashedv1.TestType, err error) { + err = kcpcache.ListAllByCluster(s.indexer, s.clusterName, selector, func(i interface{}) { + ret = append(ret, i.(*exampledashedv1.TestType)) + }) + return ret, err +} + +// TestTypes returns an object that can list and get TestTypes in one namespace. +func (s *testTypeLister) TestTypes(namespace string) TestTypeNamespaceLister { + return &testTypeNamespaceLister{indexer: s.indexer, clusterName: s.clusterName, namespace: namespace} +} + +// testTypeNamespaceLister helps list and get TestTypes. +// All objects returned here must be treated as read-only. +type TestTypeNamespaceLister interface { + // List lists all TestTypes in the workspace and namespace. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*exampledashedv1.TestType, err error) + // Get retrieves the TestType from the indexer for a given workspace, namespace and name. + // Objects returned here must be treated as read-only. + Get(name string) (*exampledashedv1.TestType, error) + TestTypeNamespaceListerExpansion +} + +// testTypeNamespaceLister helps list and get TestTypes. +// All objects returned here must be treated as read-only. +type testTypeNamespaceLister struct { + indexer cache.Indexer + clusterName logicalcluster.Name + namespace string +} + +// List lists all TestTypes in the indexer for a given workspace and namespace. +func (s *testTypeNamespaceLister) List(selector labels.Selector) (ret []*exampledashedv1.TestType, err error) { + err = kcpcache.ListAllByClusterAndNamespace(s.indexer, s.clusterName, s.namespace, selector, func(i interface{}) { + ret = append(ret, i.(*exampledashedv1.TestType)) + }) + return ret, err +} + +// Get retrieves the TestType from the indexer for a given workspace, namespace and name. +func (s *testTypeNamespaceLister) Get(name string) (*exampledashedv1.TestType, 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(exampledashedv1.Resource("testtypes"), name) + } + return obj.(*exampledashedv1.TestType), nil +} + +// NewTestTypeLister returns a new TestTypeLister. +// 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 NewTestTypeLister(indexer cache.Indexer) *testTypeScopedLister { + return &testTypeScopedLister{indexer: indexer} +} + +// testTypeScopedLister can list all TestTypes inside a workspace or scope down to a TestTypeLister for one namespace. +type testTypeScopedLister struct { + indexer cache.Indexer +} + +// List lists all TestTypes in the indexer for a workspace. +func (s *testTypeScopedLister) List(selector labels.Selector) (ret []*exampledashedv1.TestType, err error) { + err = cache.ListAll(s.indexer, selector, func(i interface{}) { + ret = append(ret, i.(*exampledashedv1.TestType)) + }) + return ret, err +} + +// TestTypes returns an object that can list and get TestTypes in one namespace. +func (s *testTypeScopedLister) TestTypes(namespace string) TestTypeNamespaceLister { + return &testTypeScopedNamespaceLister{indexer: s.indexer, namespace: namespace} +} + +// testTypeScopedNamespaceLister helps list and get TestTypes. +type testTypeScopedNamespaceLister struct { + indexer cache.Indexer + namespace string +} + +// List lists all TestTypes in the indexer for a given workspace and namespace. +func (s *testTypeScopedNamespaceLister) List(selector labels.Selector) (ret []*exampledashedv1.TestType, err error) { + err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(i interface{}) { + ret = append(ret, i.(*exampledashedv1.TestType)) + }) + return ret, err +} + +// Get retrieves the TestType from the indexer for a given workspace, namespace and name. +func (s *testTypeScopedNamespaceLister) Get(name string) (*exampledashedv1.TestType, error) { + key := s.namespace + "/" + name + obj, exists, err := s.indexer.GetByKey(key) + if err != nil { + return nil, err + } + if !exists { + return nil, errors.NewNotFound(exampledashedv1.Resource("testtypes"), name) + } + return obj.(*exampledashedv1.TestType), nil +} diff --git a/examples/pkg/kcp/clients/listers/exampledashed/v1/testtype_expansion.go b/examples/pkg/kcp/clients/listers/exampledashed/v1/testtype_expansion.go new file mode 100644 index 000000000..3f50c325f --- /dev/null +++ b/examples/pkg/kcp/clients/listers/exampledashed/v1/testtype_expansion.go @@ -0,0 +1,31 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The KCP 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 v1 + +// TestTypeClusterListerExpansion allows custom methods to be added to TestTypeClusterLister. +type TestTypeClusterListerExpansion interface{} + +// TestTypeListerExpansion allows custom methods to be added to TestTypeLister. +type TestTypeListerExpansion interface{} + +// TestTypeNamespaceListerExpansion allows custom methods to be added to TestTypeNamespaceLister. +type TestTypeNamespaceListerExpansion interface{} diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/clientset.go b/examples/pkg/kcpexisting/clients/clientset/versioned/clientset.go index 5db861f6a..7e9030b3f 100644 --- a/examples/pkg/kcpexisting/clients/clientset/versioned/clientset.go +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/clientset.go @@ -38,6 +38,7 @@ import ( examplev1beta1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/example/v1beta1" examplev2 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/example/v2" example3v1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/example3/v1" + exampledashedv1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/exampledashed/v1" existinginterfacesv1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/existinginterfaces/v1" secondexamplev1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/secondexample/v1" ) @@ -45,6 +46,7 @@ import ( type ClusterInterface interface { Cluster(logicalcluster.Path) client.Interface Discovery() discovery.DiscoveryInterface + ExampleDashedV1() exampledashedv1.ExampleDashedV1ClusterInterface Example3V1() example3v1.Example3V1ClusterInterface ExampleV1() examplev1.ExampleV1ClusterInterface ExampleV1alpha1() examplev1alpha1.ExampleV1alpha1ClusterInterface @@ -58,6 +60,7 @@ type ClusterInterface interface { type ClusterClientset struct { *discovery.DiscoveryClient clientCache kcpclient.Cache[*client.Clientset] + exampledashedV1 *exampledashedv1.ExampleDashedV1ClusterClient example3V1 *example3v1.Example3V1ClusterClient exampleV1 *examplev1.ExampleV1ClusterClient exampleV1alpha1 *examplev1alpha1.ExampleV1alpha1ClusterClient @@ -75,6 +78,11 @@ func (c *ClusterClientset) Discovery() discovery.DiscoveryInterface { return c.DiscoveryClient } +// ExampleDashedV1 retrieves the ExampleDashedV1ClusterClient. +func (c *ClusterClientset) ExampleDashedV1() exampledashedv1.ExampleDashedV1ClusterInterface { + return c.exampledashedV1 +} + // Example3V1 retrieves the Example3V1ClusterClient. func (c *ClusterClientset) Example3V1() example3v1.Example3V1ClusterInterface { return c.example3V1 @@ -162,6 +170,10 @@ func NewForConfigAndClient(c *rest.Config, httpClient *http.Client) (*ClusterCli var cs ClusterClientset cs.clientCache = cache var err error + cs.exampledashedV1, err = exampledashedv1.NewForConfigAndClient(&configShallowCopy, httpClient) + if err != nil { + return nil, err + } cs.example3V1, err = example3v1.NewForConfigAndClient(&configShallowCopy, httpClient) if err != nil { return nil, err diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/fake/clientset.go b/examples/pkg/kcpexisting/clients/clientset/versioned/fake/clientset.go index ec95d4394..19382ce62 100644 --- a/examples/pkg/kcpexisting/clients/clientset/versioned/fake/clientset.go +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/fake/clientset.go @@ -36,6 +36,7 @@ import ( examplev1beta1 "acme.corp/pkg/generated/clientset/versioned/typed/example/v1beta1" examplev2 "acme.corp/pkg/generated/clientset/versioned/typed/example/v2" example3v1 "acme.corp/pkg/generated/clientset/versioned/typed/example3/v1" + exampledashedv1 "acme.corp/pkg/generated/clientset/versioned/typed/exampledashed/v1" existinginterfacesv1 "acme.corp/pkg/generated/clientset/versioned/typed/existinginterfaces/v1" secondexamplev1 "acme.corp/pkg/generated/clientset/versioned/typed/secondexample/v1" kcpclient "acme.corp/pkg/kcpexisting/clients/clientset/versioned" @@ -49,6 +50,8 @@ import ( fakeexamplev2 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/example/v2/fake" kcpexample3v1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/example3/v1" fakeexample3v1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/example3/v1/fake" + kcpexampledashedv1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/exampledashed/v1" + fakeexampledashedv1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/exampledashed/v1/fake" kcpexistinginterfacesv1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/existinginterfaces/v1" fakeexistinginterfacesv1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/existinginterfaces/v1/fake" kcpsecondexamplev1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/secondexample/v1" @@ -89,6 +92,11 @@ func (c *ClusterClientset) Tracker() kcptesting.ObjectTracker { return c.tracker } +// ExampleDashedV1 retrieves the ExampleDashedV1ClusterClient. +func (c *ClusterClientset) ExampleDashedV1() kcpexampledashedv1.ExampleDashedV1ClusterInterface { + return &fakeexampledashedv1.ExampleDashedV1ClusterClient{Fake: c.Fake} +} + // Example3V1 retrieves the Example3V1ClusterClient. func (c *ClusterClientset) Example3V1() kcpexample3v1.Example3V1ClusterInterface { return &fakeexample3v1.Example3V1ClusterClient{Fake: c.Fake} @@ -156,6 +164,11 @@ func (c *Clientset) Tracker() kcptesting.ScopedObjectTracker { return c.tracker } +// ExampleDashedV1 retrieves the ExampleDashedV1Client. +func (c *Clientset) ExampleDashedV1() exampledashedv1.ExampleDashedV1Interface { + return &fakeexampledashedv1.ExampleDashedV1Client{Fake: c.Fake, ClusterPath: c.clusterPath} +} + // Example3V1 retrieves the Example3V1Client. func (c *Clientset) Example3V1() example3v1.Example3V1Interface { return &fakeexample3v1.Example3V1Client{Fake: c.Fake, ClusterPath: c.clusterPath} diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/scheme/register.go b/examples/pkg/kcpexisting/clients/clientset/versioned/scheme/register.go index 2a57d2e75..9761d7ec8 100644 --- a/examples/pkg/kcpexisting/clients/clientset/versioned/scheme/register.go +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/scheme/register.go @@ -33,6 +33,7 @@ import ( examplev1beta1 "acme.corp/pkg/apis/example/v1beta1" examplev2 "acme.corp/pkg/apis/example/v2" example3v1 "acme.corp/pkg/apis/example3/v1" + exampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" existinginterfacesv1 "acme.corp/pkg/apis/existinginterfaces/v1" secondexamplev1 "acme.corp/pkg/apis/secondexample/v1" ) @@ -41,6 +42,7 @@ var Scheme = runtime.NewScheme() var Codecs = serializer.NewCodecFactory(Scheme) var ParameterCodec = runtime.NewParameterCodec(Scheme) var localSchemeBuilder = runtime.SchemeBuilder{ + exampledashedv1.AddToScheme, example3v1.AddToScheme, examplev1.AddToScheme, examplev1alpha1.AddToScheme, diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/exampledashed/v1/clustertesttype.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/exampledashed/v1/clustertesttype.go new file mode 100644 index 000000000..85031ddd1 --- /dev/null +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/exampledashed/v1/clustertesttype.go @@ -0,0 +1,72 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The KCP 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 v1 + +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" + + exampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" + exampledashedv1client "acme.corp/pkg/generated/clientset/versioned/typed/exampledashed/v1" +) + +// ClusterTestTypesClusterGetter has a method to return a ClusterTestTypeClusterInterface. +// A group's cluster client should implement this interface. +type ClusterTestTypesClusterGetter interface { + ClusterTestTypes() ClusterTestTypeClusterInterface +} + +// ClusterTestTypeClusterInterface can operate on ClusterTestTypes across all clusters, +// or scope down to one cluster and return a exampledashedv1client.ClusterTestTypeInterface. +type ClusterTestTypeClusterInterface interface { + Cluster(logicalcluster.Path) exampledashedv1client.ClusterTestTypeInterface + List(ctx context.Context, opts metav1.ListOptions) (*exampledashedv1.ClusterTestTypeList, error) + Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) +} + +type clusterTestTypesClusterInterface struct { + clientCache kcpclient.Cache[*exampledashedv1client.ExampleDashedV1Client] +} + +// Cluster scopes the client down to a particular cluster. +func (c *clusterTestTypesClusterInterface) Cluster(clusterPath logicalcluster.Path) exampledashedv1client.ClusterTestTypeInterface { + if clusterPath == logicalcluster.Wildcard { + panic("A specific cluster must be provided when scoping, not the wildcard.") + } + + return c.clientCache.ClusterOrDie(clusterPath).ClusterTestTypes() +} + +// List returns the entire collection of all ClusterTestTypes across all clusters. +func (c *clusterTestTypesClusterInterface) List(ctx context.Context, opts metav1.ListOptions) (*exampledashedv1.ClusterTestTypeList, error) { + return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).ClusterTestTypes().List(ctx, opts) +} + +// Watch begins to watch all ClusterTestTypes across all clusters. +func (c *clusterTestTypesClusterInterface) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { + return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).ClusterTestTypes().Watch(ctx, opts) +} diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/exampledashed/v1/exampledashed_client.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/exampledashed/v1/exampledashed_client.go new file mode 100644 index 000000000..6030bf227 --- /dev/null +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/exampledashed/v1/exampledashed_client.go @@ -0,0 +1,95 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The KCP 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 v1 + +import ( + "net/http" + + kcpclient "github.com/kcp-dev/apimachinery/v2/pkg/client" + "github.com/kcp-dev/logicalcluster/v3" + + "k8s.io/client-go/rest" + + exampledashedv1 "acme.corp/pkg/generated/clientset/versioned/typed/exampledashed/v1" +) + +type ExampleDashedV1ClusterInterface interface { + ExampleDashedV1ClusterScoper + TestTypesClusterGetter + ClusterTestTypesClusterGetter +} + +type ExampleDashedV1ClusterScoper interface { + Cluster(logicalcluster.Path) exampledashedv1.ExampleDashedV1Interface +} + +type ExampleDashedV1ClusterClient struct { + clientCache kcpclient.Cache[*exampledashedv1.ExampleDashedV1Client] +} + +func (c *ExampleDashedV1ClusterClient) Cluster(clusterPath logicalcluster.Path) exampledashedv1.ExampleDashedV1Interface { + if clusterPath == logicalcluster.Wildcard { + panic("A specific cluster must be provided when scoping, not the wildcard.") + } + return c.clientCache.ClusterOrDie(clusterPath) +} + +func (c *ExampleDashedV1ClusterClient) TestTypes() TestTypeClusterInterface { + return &testTypesClusterInterface{clientCache: c.clientCache} +} + +func (c *ExampleDashedV1ClusterClient) ClusterTestTypes() ClusterTestTypeClusterInterface { + return &clusterTestTypesClusterInterface{clientCache: c.clientCache} +} + +// NewForConfig creates a new ExampleDashedV1ClusterClient for the given config. +// NewForConfig is equivalent to NewForConfigAndClient(c, httpClient), +// where httpClient was generated with rest.HTTPClientFor(c). +func NewForConfig(c *rest.Config) (*ExampleDashedV1ClusterClient, error) { + client, err := rest.HTTPClientFor(c) + if err != nil { + return nil, err + } + return NewForConfigAndClient(c, client) +} + +// NewForConfigAndClient creates a new ExampleDashedV1ClusterClient 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) (*ExampleDashedV1ClusterClient, error) { + cache := kcpclient.NewCache(c, h, &kcpclient.Constructor[*exampledashedv1.ExampleDashedV1Client]{ + NewForConfigAndClient: exampledashedv1.NewForConfigAndClient, + }) + if _, err := cache.Cluster(logicalcluster.Name("root").Path()); err != nil { + return nil, err + } + return &ExampleDashedV1ClusterClient{clientCache: cache}, nil +} + +// NewForConfigOrDie creates a new ExampleDashedV1ClusterClient for the given config and +// panics if there is an error in the config. +func NewForConfigOrDie(c *rest.Config) *ExampleDashedV1ClusterClient { + client, err := NewForConfig(c) + if err != nil { + panic(err) + } + return client +} diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/exampledashed/v1/fake/clustertesttype.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/exampledashed/v1/fake/clustertesttype.go new file mode 100644 index 000000000..58dbc19e9 --- /dev/null +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/exampledashed/v1/fake/clustertesttype.go @@ -0,0 +1,202 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The KCP 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" + + exampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" + applyconfigurationsexampledashedv1 "acme.corp/pkg/generated/applyconfigurations/exampledashed/v1" + exampledashedv1client "acme.corp/pkg/generated/clientset/versioned/typed/exampledashed/v1" +) + +var clusterTestTypesResource = schema.GroupVersionResource{Group: "example-dashed.some.corp", Version: "v1", Resource: "clustertesttypes"} +var clusterTestTypesKind = schema.GroupVersionKind{Group: "example-dashed.some.corp", Version: "v1", Kind: "ClusterTestType"} + +type clusterTestTypesClusterClient struct { + *kcptesting.Fake +} + +// Cluster scopes the client down to a particular cluster. +func (c *clusterTestTypesClusterClient) Cluster(clusterPath logicalcluster.Path) exampledashedv1client.ClusterTestTypeInterface { + if clusterPath == logicalcluster.Wildcard { + panic("A specific cluster must be provided when scoping, not the wildcard.") + } + + return &clusterTestTypesClient{Fake: c.Fake, ClusterPath: clusterPath} +} + +// List takes label and field selectors, and returns the list of ClusterTestTypes that match those selectors across all clusters. +func (c *clusterTestTypesClusterClient) List(ctx context.Context, opts metav1.ListOptions) (*exampledashedv1.ClusterTestTypeList, error) { + obj, err := c.Fake.Invokes(kcptesting.NewRootListAction(clusterTestTypesResource, clusterTestTypesKind, logicalcluster.Wildcard, opts), &exampledashedv1.ClusterTestTypeList{}) + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &exampledashedv1.ClusterTestTypeList{ListMeta: obj.(*exampledashedv1.ClusterTestTypeList).ListMeta} + for _, item := range obj.(*exampledashedv1.ClusterTestTypeList).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 ClusterTestTypes across all clusters. +func (c *clusterTestTypesClusterClient) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { + return c.Fake.InvokesWatch(kcptesting.NewRootWatchAction(clusterTestTypesResource, logicalcluster.Wildcard, opts)) +} + +type clusterTestTypesClient struct { + *kcptesting.Fake + ClusterPath logicalcluster.Path +} + +func (c *clusterTestTypesClient) Create(ctx context.Context, clusterTestType *exampledashedv1.ClusterTestType, opts metav1.CreateOptions) (*exampledashedv1.ClusterTestType, error) { + obj, err := c.Fake.Invokes(kcptesting.NewRootCreateAction(clusterTestTypesResource, c.ClusterPath, clusterTestType), &exampledashedv1.ClusterTestType{}) + if obj == nil { + return nil, err + } + return obj.(*exampledashedv1.ClusterTestType), err +} + +func (c *clusterTestTypesClient) Update(ctx context.Context, clusterTestType *exampledashedv1.ClusterTestType, opts metav1.UpdateOptions) (*exampledashedv1.ClusterTestType, error) { + obj, err := c.Fake.Invokes(kcptesting.NewRootUpdateAction(clusterTestTypesResource, c.ClusterPath, clusterTestType), &exampledashedv1.ClusterTestType{}) + if obj == nil { + return nil, err + } + return obj.(*exampledashedv1.ClusterTestType), err +} + +func (c *clusterTestTypesClient) UpdateStatus(ctx context.Context, clusterTestType *exampledashedv1.ClusterTestType, opts metav1.UpdateOptions) (*exampledashedv1.ClusterTestType, error) { + obj, err := c.Fake.Invokes(kcptesting.NewRootUpdateSubresourceAction(clusterTestTypesResource, c.ClusterPath, "status", clusterTestType), &exampledashedv1.ClusterTestType{}) + if obj == nil { + return nil, err + } + return obj.(*exampledashedv1.ClusterTestType), err +} + +func (c *clusterTestTypesClient) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { + _, err := c.Fake.Invokes(kcptesting.NewRootDeleteActionWithOptions(clusterTestTypesResource, c.ClusterPath, name, opts), &exampledashedv1.ClusterTestType{}) + return err +} + +func (c *clusterTestTypesClient) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { + action := kcptesting.NewRootDeleteCollectionAction(clusterTestTypesResource, c.ClusterPath, listOpts) + + _, err := c.Fake.Invokes(action, &exampledashedv1.ClusterTestTypeList{}) + return err +} + +func (c *clusterTestTypesClient) Get(ctx context.Context, name string, options metav1.GetOptions) (*exampledashedv1.ClusterTestType, error) { + obj, err := c.Fake.Invokes(kcptesting.NewRootGetAction(clusterTestTypesResource, c.ClusterPath, name), &exampledashedv1.ClusterTestType{}) + if obj == nil { + return nil, err + } + return obj.(*exampledashedv1.ClusterTestType), err +} + +// List takes label and field selectors, and returns the list of ClusterTestTypes that match those selectors. +func (c *clusterTestTypesClient) List(ctx context.Context, opts metav1.ListOptions) (*exampledashedv1.ClusterTestTypeList, error) { + obj, err := c.Fake.Invokes(kcptesting.NewRootListAction(clusterTestTypesResource, clusterTestTypesKind, c.ClusterPath, opts), &exampledashedv1.ClusterTestTypeList{}) + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &exampledashedv1.ClusterTestTypeList{ListMeta: obj.(*exampledashedv1.ClusterTestTypeList).ListMeta} + for _, item := range obj.(*exampledashedv1.ClusterTestTypeList).Items { + if label.Matches(labels.Set(item.Labels)) { + list.Items = append(list.Items, item) + } + } + return list, err +} + +func (c *clusterTestTypesClient) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { + return c.Fake.InvokesWatch(kcptesting.NewRootWatchAction(clusterTestTypesResource, c.ClusterPath, opts)) +} + +func (c *clusterTestTypesClient) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (*exampledashedv1.ClusterTestType, error) { + obj, err := c.Fake.Invokes(kcptesting.NewRootPatchSubresourceAction(clusterTestTypesResource, c.ClusterPath, name, pt, data, subresources...), &exampledashedv1.ClusterTestType{}) + if obj == nil { + return nil, err + } + return obj.(*exampledashedv1.ClusterTestType), err +} + +func (c *clusterTestTypesClient) Apply(ctx context.Context, applyConfiguration *applyconfigurationsexampledashedv1.ClusterTestTypeApplyConfiguration, opts metav1.ApplyOptions) (*exampledashedv1.ClusterTestType, 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(clusterTestTypesResource, c.ClusterPath, *name, types.ApplyPatchType, data), &exampledashedv1.ClusterTestType{}) + if obj == nil { + return nil, err + } + return obj.(*exampledashedv1.ClusterTestType), err +} + +func (c *clusterTestTypesClient) ApplyStatus(ctx context.Context, applyConfiguration *applyconfigurationsexampledashedv1.ClusterTestTypeApplyConfiguration, opts metav1.ApplyOptions) (*exampledashedv1.ClusterTestType, 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(clusterTestTypesResource, c.ClusterPath, *name, types.ApplyPatchType, data, "status"), &exampledashedv1.ClusterTestType{}) + if obj == nil { + return nil, err + } + return obj.(*exampledashedv1.ClusterTestType), err +} diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/exampledashed/v1/fake/exampledashed_client.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/exampledashed/v1/fake/exampledashed_client.go new file mode 100644 index 000000000..2ddf83e98 --- /dev/null +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/exampledashed/v1/fake/exampledashed_client.go @@ -0,0 +1,73 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The KCP 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" + + exampledashedv1 "acme.corp/pkg/generated/clientset/versioned/typed/exampledashed/v1" + kcpexampledashedv1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/exampledashed/v1" +) + +var _ kcpexampledashedv1.ExampleDashedV1ClusterInterface = (*ExampleDashedV1ClusterClient)(nil) + +type ExampleDashedV1ClusterClient struct { + *kcptesting.Fake +} + +func (c *ExampleDashedV1ClusterClient) Cluster(clusterPath logicalcluster.Path) exampledashedv1.ExampleDashedV1Interface { + if clusterPath == logicalcluster.Wildcard { + panic("A specific cluster must be provided when scoping, not the wildcard.") + } + return &ExampleDashedV1Client{Fake: c.Fake, ClusterPath: clusterPath} +} + +func (c *ExampleDashedV1ClusterClient) TestTypes() kcpexampledashedv1.TestTypeClusterInterface { + return &testTypesClusterClient{Fake: c.Fake} +} + +func (c *ExampleDashedV1ClusterClient) ClusterTestTypes() kcpexampledashedv1.ClusterTestTypeClusterInterface { + return &clusterTestTypesClusterClient{Fake: c.Fake} +} + +var _ exampledashedv1.ExampleDashedV1Interface = (*ExampleDashedV1Client)(nil) + +type ExampleDashedV1Client struct { + *kcptesting.Fake + ClusterPath logicalcluster.Path +} + +func (c *ExampleDashedV1Client) RESTClient() rest.Interface { + var ret *rest.RESTClient + return ret +} + +func (c *ExampleDashedV1Client) TestTypes(namespace string) exampledashedv1.TestTypeInterface { + return &testTypesClient{Fake: c.Fake, ClusterPath: c.ClusterPath, Namespace: namespace} +} + +func (c *ExampleDashedV1Client) ClusterTestTypes() exampledashedv1.ClusterTestTypeInterface { + return &clusterTestTypesClient{Fake: c.Fake, ClusterPath: c.ClusterPath} +} diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/exampledashed/v1/fake/testtype.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/exampledashed/v1/fake/testtype.go new file mode 100644 index 000000000..73f0976d3 --- /dev/null +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/exampledashed/v1/fake/testtype.go @@ -0,0 +1,238 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The KCP 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" + + examplev1 "acme.corp/pkg/apis/example/v1" + exampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" + applyconfigurationsexampledashedv1 "acme.corp/pkg/generated/applyconfigurations/exampledashed/v1" + exampledashedv1client "acme.corp/pkg/generated/clientset/versioned/typed/exampledashed/v1" + kcpexampledashedv1 "acme.corp/pkg/kcpexisting/clients/clientset/versioned/typed/exampledashed/v1" +) + +var testTypesResource = schema.GroupVersionResource{Group: "example-dashed.some.corp", Version: "v1", Resource: "testtypes"} +var testTypesKind = schema.GroupVersionKind{Group: "example-dashed.some.corp", Version: "v1", Kind: "TestType"} + +type testTypesClusterClient struct { + *kcptesting.Fake +} + +// Cluster scopes the client down to a particular cluster. +func (c *testTypesClusterClient) Cluster(clusterPath logicalcluster.Path) kcpexampledashedv1.TestTypesNamespacer { + if clusterPath == logicalcluster.Wildcard { + panic("A specific cluster must be provided when scoping, not the wildcard.") + } + + return &testTypesNamespacer{Fake: c.Fake, ClusterPath: clusterPath} +} + +// List takes label and field selectors, and returns the list of TestTypes that match those selectors across all clusters. +func (c *testTypesClusterClient) List(ctx context.Context, opts metav1.ListOptions) (*exampledashedv1.TestTypeList, error) { + obj, err := c.Fake.Invokes(kcptesting.NewListAction(testTypesResource, testTypesKind, logicalcluster.Wildcard, metav1.NamespaceAll, opts), &exampledashedv1.TestTypeList{}) + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &exampledashedv1.TestTypeList{ListMeta: obj.(*exampledashedv1.TestTypeList).ListMeta} + for _, item := range obj.(*exampledashedv1.TestTypeList).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 TestTypes across all clusters. +func (c *testTypesClusterClient) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { + return c.Fake.InvokesWatch(kcptesting.NewWatchAction(testTypesResource, logicalcluster.Wildcard, metav1.NamespaceAll, opts)) +} + +type testTypesNamespacer struct { + *kcptesting.Fake + ClusterPath logicalcluster.Path +} + +func (n *testTypesNamespacer) Namespace(namespace string) exampledashedv1client.TestTypeInterface { + return &testTypesClient{Fake: n.Fake, ClusterPath: n.ClusterPath, Namespace: namespace} +} + +type testTypesClient struct { + *kcptesting.Fake + ClusterPath logicalcluster.Path + Namespace string +} + +func (c *testTypesClient) Create(ctx context.Context, testType *exampledashedv1.TestType, opts metav1.CreateOptions) (*exampledashedv1.TestType, error) { + obj, err := c.Fake.Invokes(kcptesting.NewCreateAction(testTypesResource, c.ClusterPath, c.Namespace, testType), &exampledashedv1.TestType{}) + if obj == nil { + return nil, err + } + return obj.(*exampledashedv1.TestType), err +} + +func (c *testTypesClient) Update(ctx context.Context, testType *exampledashedv1.TestType, opts metav1.UpdateOptions) (*exampledashedv1.TestType, error) { + obj, err := c.Fake.Invokes(kcptesting.NewUpdateAction(testTypesResource, c.ClusterPath, c.Namespace, testType), &exampledashedv1.TestType{}) + if obj == nil { + return nil, err + } + return obj.(*exampledashedv1.TestType), err +} + +func (c *testTypesClient) UpdateStatus(ctx context.Context, testType *exampledashedv1.TestType, opts metav1.UpdateOptions) (*exampledashedv1.TestType, error) { + obj, err := c.Fake.Invokes(kcptesting.NewUpdateSubresourceAction(testTypesResource, c.ClusterPath, "status", c.Namespace, testType), &exampledashedv1.TestType{}) + if obj == nil { + return nil, err + } + return obj.(*exampledashedv1.TestType), err +} + +func (c *testTypesClient) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { + _, err := c.Fake.Invokes(kcptesting.NewDeleteActionWithOptions(testTypesResource, c.ClusterPath, c.Namespace, name, opts), &exampledashedv1.TestType{}) + return err +} + +func (c *testTypesClient) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { + action := kcptesting.NewDeleteCollectionAction(testTypesResource, c.ClusterPath, c.Namespace, listOpts) + + _, err := c.Fake.Invokes(action, &exampledashedv1.TestTypeList{}) + return err +} + +func (c *testTypesClient) Get(ctx context.Context, name string, options metav1.GetOptions) (*exampledashedv1.TestType, error) { + obj, err := c.Fake.Invokes(kcptesting.NewGetAction(testTypesResource, c.ClusterPath, c.Namespace, name), &exampledashedv1.TestType{}) + if obj == nil { + return nil, err + } + return obj.(*exampledashedv1.TestType), err +} + +// List takes label and field selectors, and returns the list of TestTypes that match those selectors. +func (c *testTypesClient) List(ctx context.Context, opts metav1.ListOptions) (*exampledashedv1.TestTypeList, error) { + obj, err := c.Fake.Invokes(kcptesting.NewListAction(testTypesResource, testTypesKind, c.ClusterPath, c.Namespace, opts), &exampledashedv1.TestTypeList{}) + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &exampledashedv1.TestTypeList{ListMeta: obj.(*exampledashedv1.TestTypeList).ListMeta} + for _, item := range obj.(*exampledashedv1.TestTypeList).Items { + if label.Matches(labels.Set(item.Labels)) { + list.Items = append(list.Items, item) + } + } + return list, err +} + +func (c *testTypesClient) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { + return c.Fake.InvokesWatch(kcptesting.NewWatchAction(testTypesResource, c.ClusterPath, c.Namespace, opts)) +} + +func (c *testTypesClient) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (*exampledashedv1.TestType, error) { + obj, err := c.Fake.Invokes(kcptesting.NewPatchSubresourceAction(testTypesResource, c.ClusterPath, c.Namespace, name, pt, data, subresources...), &exampledashedv1.TestType{}) + if obj == nil { + return nil, err + } + return obj.(*exampledashedv1.TestType), err +} + +func (c *testTypesClient) Apply(ctx context.Context, applyConfiguration *applyconfigurationsexampledashedv1.TestTypeApplyConfiguration, opts metav1.ApplyOptions) (*exampledashedv1.TestType, 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(testTypesResource, c.ClusterPath, c.Namespace, *name, types.ApplyPatchType, data), &exampledashedv1.TestType{}) + if obj == nil { + return nil, err + } + return obj.(*exampledashedv1.TestType), err +} + +func (c *testTypesClient) ApplyStatus(ctx context.Context, applyConfiguration *applyconfigurationsexampledashedv1.TestTypeApplyConfiguration, opts metav1.ApplyOptions) (*exampledashedv1.TestType, 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(testTypesResource, c.ClusterPath, c.Namespace, *name, types.ApplyPatchType, data, "status"), &exampledashedv1.TestType{}) + if obj == nil { + return nil, err + } + return obj.(*exampledashedv1.TestType), err +} + +func (c *testTypesClient) CreateField(ctx context.Context, testTypeName string, field *examplev1.Field, opts metav1.CreateOptions) (*examplev1.Field, error) { + obj, err := c.Fake.Invokes(kcptesting.NewCreateSubresourceAction(testTypesResource, c.ClusterPath, testTypeName, "field", c.Namespace, field), &examplev1.Field{}) + if obj == nil { + return nil, err + } + return obj.(*examplev1.Field), err +} + +func (c *testTypesClient) UpdateField(ctx context.Context, testTypeName string, field *examplev1.Field, opts metav1.UpdateOptions) (*examplev1.Field, error) { + obj, err := c.Fake.Invokes(kcptesting.NewUpdateSubresourceAction(testTypesResource, c.ClusterPath, "field", c.Namespace, field), &examplev1.Field{}) + if obj == nil { + return nil, err + } + return obj.(*examplev1.Field), err +} + +func (c *testTypesClient) GetField(ctx context.Context, testTypeName string, options metav1.GetOptions) (*examplev1.Field, error) { + obj, err := c.Fake.Invokes(kcptesting.NewGetSubresourceAction(testTypesResource, c.ClusterPath, "field", c.Namespace, testTypeName), &examplev1.Field{}) + if obj == nil { + return nil, err + } + return obj.(*examplev1.Field), err +} diff --git a/examples/pkg/kcpexisting/clients/clientset/versioned/typed/exampledashed/v1/testtype.go b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/exampledashed/v1/testtype.go new file mode 100644 index 000000000..eb9eacdd1 --- /dev/null +++ b/examples/pkg/kcpexisting/clients/clientset/versioned/typed/exampledashed/v1/testtype.go @@ -0,0 +1,86 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The KCP 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 v1 + +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" + + exampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" + exampledashedv1client "acme.corp/pkg/generated/clientset/versioned/typed/exampledashed/v1" +) + +// TestTypesClusterGetter has a method to return a TestTypeClusterInterface. +// A group's cluster client should implement this interface. +type TestTypesClusterGetter interface { + TestTypes() TestTypeClusterInterface +} + +// TestTypeClusterInterface can operate on TestTypes across all clusters, +// or scope down to one cluster and return a TestTypesNamespacer. +type TestTypeClusterInterface interface { + Cluster(logicalcluster.Path) TestTypesNamespacer + List(ctx context.Context, opts metav1.ListOptions) (*exampledashedv1.TestTypeList, error) + Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) +} + +type testTypesClusterInterface struct { + clientCache kcpclient.Cache[*exampledashedv1client.ExampleDashedV1Client] +} + +// Cluster scopes the client down to a particular cluster. +func (c *testTypesClusterInterface) Cluster(clusterPath logicalcluster.Path) TestTypesNamespacer { + if clusterPath == logicalcluster.Wildcard { + panic("A specific cluster must be provided when scoping, not the wildcard.") + } + + return &testTypesNamespacer{clientCache: c.clientCache, clusterPath: clusterPath} +} + +// List returns the entire collection of all TestTypes across all clusters. +func (c *testTypesClusterInterface) List(ctx context.Context, opts metav1.ListOptions) (*exampledashedv1.TestTypeList, error) { + return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).TestTypes(metav1.NamespaceAll).List(ctx, opts) +} + +// Watch begins to watch all TestTypes across all clusters. +func (c *testTypesClusterInterface) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { + return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).TestTypes(metav1.NamespaceAll).Watch(ctx, opts) +} + +// TestTypesNamespacer can scope to objects within a namespace, returning a exampledashedv1client.TestTypeInterface. +type TestTypesNamespacer interface { + Namespace(string) exampledashedv1client.TestTypeInterface +} + +type testTypesNamespacer struct { + clientCache kcpclient.Cache[*exampledashedv1client.ExampleDashedV1Client] + clusterPath logicalcluster.Path +} + +func (n *testTypesNamespacer) Namespace(namespace string) exampledashedv1client.TestTypeInterface { + return n.clientCache.ClusterOrDie(n.clusterPath).TestTypes(namespace) +} diff --git a/examples/pkg/kcpexisting/clients/informers/externalversions/exampledashed/interface.go b/examples/pkg/kcpexisting/clients/informers/externalversions/exampledashed/interface.go new file mode 100644 index 000000000..8d96762d0 --- /dev/null +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/exampledashed/interface.go @@ -0,0 +1,47 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The KCP 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 exampledashed + +import ( + "acme.corp/pkg/kcpexisting/clients/informers/externalversions/exampledashed/v1" + "acme.corp/pkg/kcpexisting/clients/informers/externalversions/internalinterfaces" +) + +type ClusterInterface interface { + // V1 provides access to the shared informers in V1. + V1() v1.ClusterInterface +} + +type group struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc +} + +// New returns a new ClusterInterface. +func New(f internalinterfaces.SharedInformerFactory, tweakListOptions internalinterfaces.TweakListOptionsFunc) ClusterInterface { + return &group{factory: f, tweakListOptions: tweakListOptions} +} + +// V1 returns a new v1.ClusterInterface. +func (g *group) V1() v1.ClusterInterface { + return v1.New(g.factory, g.tweakListOptions) +} diff --git a/examples/pkg/kcpexisting/clients/informers/externalversions/exampledashed/v1/clustertesttype.go b/examples/pkg/kcpexisting/clients/informers/externalversions/exampledashed/v1/clustertesttype.go new file mode 100644 index 000000000..9352b82d5 --- /dev/null +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/exampledashed/v1/clustertesttype.go @@ -0,0 +1,124 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The KCP 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 v1 + +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" + + exampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" + upstreamexampledashedv1informers "acme.corp/pkg/generated/informers/externalversions/exampledashed/v1" + upstreamexampledashedv1listers "acme.corp/pkg/generated/listers/exampledashed/v1" + clientset "acme.corp/pkg/kcpexisting/clients/clientset/versioned" + "acme.corp/pkg/kcpexisting/clients/informers/externalversions/internalinterfaces" + exampledashedv1listers "acme.corp/pkg/kcpexisting/clients/listers/exampledashed/v1" +) + +// ClusterTestTypeClusterInformer provides access to a shared informer and lister for +// ClusterTestTypes. +type ClusterTestTypeClusterInformer interface { + Cluster(logicalcluster.Name) upstreamexampledashedv1informers.ClusterTestTypeInformer + Informer() kcpcache.ScopeableSharedIndexInformer + Lister() exampledashedv1listers.ClusterTestTypeClusterLister +} + +type clusterTestTypeClusterInformer struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc +} + +// NewClusterTestTypeClusterInformer constructs a new informer for ClusterTestType 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 NewClusterTestTypeClusterInformer(client clientset.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers) kcpcache.ScopeableSharedIndexInformer { + return NewFilteredClusterTestTypeClusterInformer(client, resyncPeriod, indexers, nil) +} + +// NewFilteredClusterTestTypeClusterInformer constructs a new informer for ClusterTestType 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 NewFilteredClusterTestTypeClusterInformer(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.ExampleDashedV1().ClusterTestTypes().List(context.TODO(), options) + }, + WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ExampleDashedV1().ClusterTestTypes().Watch(context.TODO(), options) + }, + }, + &exampledashedv1.ClusterTestType{}, + resyncPeriod, + indexers, + ) +} + +func (f *clusterTestTypeClusterInformer) defaultInformer(client clientset.ClusterInterface, resyncPeriod time.Duration) kcpcache.ScopeableSharedIndexInformer { + return NewFilteredClusterTestTypeClusterInformer(client, resyncPeriod, cache.Indexers{ + kcpcache.ClusterIndexName: kcpcache.ClusterIndexFunc, + }, + f.tweakListOptions, + ) +} + +func (f *clusterTestTypeClusterInformer) Informer() kcpcache.ScopeableSharedIndexInformer { + return f.factory.InformerFor(&exampledashedv1.ClusterTestType{}, f.defaultInformer) +} + +func (f *clusterTestTypeClusterInformer) Lister() exampledashedv1listers.ClusterTestTypeClusterLister { + return exampledashedv1listers.NewClusterTestTypeClusterLister(f.Informer().GetIndexer()) +} + +func (f *clusterTestTypeClusterInformer) Cluster(clusterName logicalcluster.Name) upstreamexampledashedv1informers.ClusterTestTypeInformer { + return &clusterTestTypeInformer{ + informer: f.Informer().Cluster(clusterName), + lister: f.Lister().Cluster(clusterName), + } +} + +type clusterTestTypeInformer struct { + informer cache.SharedIndexInformer + lister upstreamexampledashedv1listers.ClusterTestTypeLister +} + +func (f *clusterTestTypeInformer) Informer() cache.SharedIndexInformer { + return f.informer +} + +func (f *clusterTestTypeInformer) Lister() upstreamexampledashedv1listers.ClusterTestTypeLister { + return f.lister +} diff --git a/examples/pkg/kcpexisting/clients/informers/externalversions/exampledashed/v1/interface.go b/examples/pkg/kcpexisting/clients/informers/externalversions/exampledashed/v1/interface.go new file mode 100644 index 000000000..ebae731bf --- /dev/null +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/exampledashed/v1/interface.go @@ -0,0 +1,53 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The KCP 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 v1 + +import ( + "acme.corp/pkg/kcpexisting/clients/informers/externalversions/internalinterfaces" +) + +type ClusterInterface interface { + // TestTypes returns a TestTypeClusterInformer + TestTypes() TestTypeClusterInformer + // ClusterTestTypes returns a ClusterTestTypeClusterInformer + ClusterTestTypes() ClusterTestTypeClusterInformer +} + +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} +} + +// TestTypes returns a TestTypeClusterInformer +func (v *version) TestTypes() TestTypeClusterInformer { + return &testTypeClusterInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} +} + +// ClusterTestTypes returns a ClusterTestTypeClusterInformer +func (v *version) ClusterTestTypes() ClusterTestTypeClusterInformer { + return &clusterTestTypeClusterInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} +} diff --git a/examples/pkg/kcpexisting/clients/informers/externalversions/exampledashed/v1/testtype.go b/examples/pkg/kcpexisting/clients/informers/externalversions/exampledashed/v1/testtype.go new file mode 100644 index 000000000..063961533 --- /dev/null +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/exampledashed/v1/testtype.go @@ -0,0 +1,124 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The KCP 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 v1 + +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" + + exampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" + upstreamexampledashedv1informers "acme.corp/pkg/generated/informers/externalversions/exampledashed/v1" + upstreamexampledashedv1listers "acme.corp/pkg/generated/listers/exampledashed/v1" + clientset "acme.corp/pkg/kcpexisting/clients/clientset/versioned" + "acme.corp/pkg/kcpexisting/clients/informers/externalversions/internalinterfaces" + exampledashedv1listers "acme.corp/pkg/kcpexisting/clients/listers/exampledashed/v1" +) + +// TestTypeClusterInformer provides access to a shared informer and lister for +// TestTypes. +type TestTypeClusterInformer interface { + Cluster(logicalcluster.Name) upstreamexampledashedv1informers.TestTypeInformer + Informer() kcpcache.ScopeableSharedIndexInformer + Lister() exampledashedv1listers.TestTypeClusterLister +} + +type testTypeClusterInformer struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc +} + +// NewTestTypeClusterInformer constructs a new informer for TestType 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 NewTestTypeClusterInformer(client clientset.ClusterInterface, resyncPeriod time.Duration, indexers cache.Indexers) kcpcache.ScopeableSharedIndexInformer { + return NewFilteredTestTypeClusterInformer(client, resyncPeriod, indexers, nil) +} + +// NewFilteredTestTypeClusterInformer constructs a new informer for TestType 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 NewFilteredTestTypeClusterInformer(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.ExampleDashedV1().TestTypes().List(context.TODO(), options) + }, + WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ExampleDashedV1().TestTypes().Watch(context.TODO(), options) + }, + }, + &exampledashedv1.TestType{}, + resyncPeriod, + indexers, + ) +} + +func (f *testTypeClusterInformer) defaultInformer(client clientset.ClusterInterface, resyncPeriod time.Duration) kcpcache.ScopeableSharedIndexInformer { + return NewFilteredTestTypeClusterInformer(client, resyncPeriod, cache.Indexers{ + kcpcache.ClusterIndexName: kcpcache.ClusterIndexFunc, + kcpcache.ClusterAndNamespaceIndexName: kcpcache.ClusterAndNamespaceIndexFunc}, + f.tweakListOptions, + ) +} + +func (f *testTypeClusterInformer) Informer() kcpcache.ScopeableSharedIndexInformer { + return f.factory.InformerFor(&exampledashedv1.TestType{}, f.defaultInformer) +} + +func (f *testTypeClusterInformer) Lister() exampledashedv1listers.TestTypeClusterLister { + return exampledashedv1listers.NewTestTypeClusterLister(f.Informer().GetIndexer()) +} + +func (f *testTypeClusterInformer) Cluster(clusterName logicalcluster.Name) upstreamexampledashedv1informers.TestTypeInformer { + return &testTypeInformer{ + informer: f.Informer().Cluster(clusterName), + lister: f.Lister().Cluster(clusterName), + } +} + +type testTypeInformer struct { + informer cache.SharedIndexInformer + lister upstreamexampledashedv1listers.TestTypeLister +} + +func (f *testTypeInformer) Informer() cache.SharedIndexInformer { + return f.informer +} + +func (f *testTypeInformer) Lister() upstreamexampledashedv1listers.TestTypeLister { + return f.lister +} diff --git a/examples/pkg/kcpexisting/clients/informers/externalversions/factory.go b/examples/pkg/kcpexisting/clients/informers/externalversions/factory.go index d0645ef3f..c17b9e5c0 100644 --- a/examples/pkg/kcpexisting/clients/informers/externalversions/factory.go +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/factory.go @@ -38,6 +38,7 @@ import ( clientset "acme.corp/pkg/kcpexisting/clients/clientset/versioned" exampleinformers "acme.corp/pkg/kcpexisting/clients/informers/externalversions/example" example3informers "acme.corp/pkg/kcpexisting/clients/informers/externalversions/example3" + exampledashedinformers "acme.corp/pkg/kcpexisting/clients/informers/externalversions/exampledashed" existinginterfacesinformers "acme.corp/pkg/kcpexisting/clients/informers/externalversions/existinginterfaces" "acme.corp/pkg/kcpexisting/clients/informers/externalversions/internalinterfaces" secondexampleinformers "acme.corp/pkg/kcpexisting/clients/informers/externalversions/secondexample" @@ -272,6 +273,7 @@ type SharedInformerFactory interface { InformerFor(obj runtime.Object, newFunc internalinterfaces.NewInformerFunc) kcpcache.ScopeableSharedIndexInformer Example() exampleinformers.ClusterInterface + ExampleDashed() exampledashedinformers.ClusterInterface Example3() example3informers.ClusterInterface Existinginterfaces() existinginterfacesinformers.ClusterInterface Secondexample() secondexampleinformers.ClusterInterface @@ -281,6 +283,10 @@ func (f *sharedInformerFactory) Example() exampleinformers.ClusterInterface { return exampleinformers.New(f, f.tweakListOptions) } +func (f *sharedInformerFactory) ExampleDashed() exampledashedinformers.ClusterInterface { + return exampledashedinformers.New(f, f.tweakListOptions) +} + func (f *sharedInformerFactory) Example3() example3informers.ClusterInterface { return example3informers.New(f, f.tweakListOptions) } diff --git a/examples/pkg/kcpexisting/clients/informers/externalversions/generic.go b/examples/pkg/kcpexisting/clients/informers/externalversions/generic.go index 96a664308..f3b0f2c01 100644 --- a/examples/pkg/kcpexisting/clients/informers/externalversions/generic.go +++ b/examples/pkg/kcpexisting/clients/informers/externalversions/generic.go @@ -35,6 +35,7 @@ import ( examplev1beta1 "acme.corp/pkg/apis/example/v1beta1" examplev2 "acme.corp/pkg/apis/example/v2" example3v1 "acme.corp/pkg/apis/example3/v1" + exampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" existinginterfacesv1 "acme.corp/pkg/apis/existinginterfaces/v1" secondexamplev1 "acme.corp/pkg/apis/secondexample/v1" upstreaminformers "acme.corp/pkg/generated/informers/externalversions" @@ -88,6 +89,11 @@ func (f *genericInformer) Lister() cache.GenericLister { // TODO extend this to unknown resources with a client pool func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource) (GenericClusterInformer, error) { switch resource { + // Group=example-dashed.some.corp, Version=V1 + case exampledashedv1.SchemeGroupVersion.WithResource("testtypes"): + return &genericClusterInformer{resource: resource.GroupResource(), informer: f.ExampleDashed().V1().TestTypes().Informer()}, nil + case exampledashedv1.SchemeGroupVersion.WithResource("clustertesttypes"): + return &genericClusterInformer{resource: resource.GroupResource(), informer: f.ExampleDashed().V1().ClusterTestTypes().Informer()}, nil // Group=example3.some.corp, Version=V1 case example3v1.SchemeGroupVersion.WithResource("testtypes"): return &genericClusterInformer{resource: resource.GroupResource(), informer: f.Example3().V1().TestTypes().Informer()}, nil diff --git a/examples/pkg/kcpexisting/clients/listers/exampledashed/v1/clustertesttype.go b/examples/pkg/kcpexisting/clients/listers/exampledashed/v1/clustertesttype.go new file mode 100644 index 000000000..ed5630a23 --- /dev/null +++ b/examples/pkg/kcpexisting/clients/listers/exampledashed/v1/clustertesttype.go @@ -0,0 +1,98 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The KCP 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 v1 + +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" + + exampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" + exampledashedv1listers "acme.corp/pkg/generated/listers/exampledashed/v1" +) + +// ClusterTestTypeClusterLister can list ClusterTestTypes across all workspaces, or scope down to a ClusterTestTypeLister for one workspace. +// All objects returned here must be treated as read-only. +type ClusterTestTypeClusterLister interface { + // List lists all ClusterTestTypes in the indexer. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*exampledashedv1.ClusterTestType, err error) + // Cluster returns a lister that can list and get ClusterTestTypes in one workspace. + Cluster(clusterName logicalcluster.Name) exampledashedv1listers.ClusterTestTypeLister + ClusterTestTypeClusterListerExpansion +} + +type clusterTestTypeClusterLister struct { + indexer cache.Indexer +} + +// NewClusterTestTypeClusterLister returns a new ClusterTestTypeClusterLister. +// 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 NewClusterTestTypeClusterLister(indexer cache.Indexer) *clusterTestTypeClusterLister { + return &clusterTestTypeClusterLister{indexer: indexer} +} + +// List lists all ClusterTestTypes in the indexer across all workspaces. +func (s *clusterTestTypeClusterLister) List(selector labels.Selector) (ret []*exampledashedv1.ClusterTestType, err error) { + err = cache.ListAll(s.indexer, selector, func(m interface{}) { + ret = append(ret, m.(*exampledashedv1.ClusterTestType)) + }) + return ret, err +} + +// Cluster scopes the lister to one workspace, allowing users to list and get ClusterTestTypes. +func (s *clusterTestTypeClusterLister) Cluster(clusterName logicalcluster.Name) exampledashedv1listers.ClusterTestTypeLister { + return &clusterTestTypeLister{indexer: s.indexer, clusterName: clusterName} +} + +// clusterTestTypeLister implements the exampledashedv1listers.ClusterTestTypeLister interface. +type clusterTestTypeLister struct { + indexer cache.Indexer + clusterName logicalcluster.Name +} + +// List lists all ClusterTestTypes in the indexer for a workspace. +func (s *clusterTestTypeLister) List(selector labels.Selector) (ret []*exampledashedv1.ClusterTestType, err error) { + err = kcpcache.ListAllByCluster(s.indexer, s.clusterName, selector, func(i interface{}) { + ret = append(ret, i.(*exampledashedv1.ClusterTestType)) + }) + return ret, err +} + +// Get retrieves the ClusterTestType from the indexer for a given workspace and name. +func (s *clusterTestTypeLister) Get(name string) (*exampledashedv1.ClusterTestType, 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(exampledashedv1.Resource("clustertesttypes"), name) + } + return obj.(*exampledashedv1.ClusterTestType), nil +} diff --git a/examples/pkg/kcpexisting/clients/listers/exampledashed/v1/clustertesttype_expansion.go b/examples/pkg/kcpexisting/clients/listers/exampledashed/v1/clustertesttype_expansion.go new file mode 100644 index 000000000..08fb95b1c --- /dev/null +++ b/examples/pkg/kcpexisting/clients/listers/exampledashed/v1/clustertesttype_expansion.go @@ -0,0 +1,25 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The KCP 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 v1 + +// ClusterTestTypeClusterListerExpansion allows custom methods to be added to ClusterTestTypeClusterLister. +type ClusterTestTypeClusterListerExpansion interface{} diff --git a/examples/pkg/kcpexisting/clients/listers/exampledashed/v1/testtype.go b/examples/pkg/kcpexisting/clients/listers/exampledashed/v1/testtype.go new file mode 100644 index 000000000..07d6dc46d --- /dev/null +++ b/examples/pkg/kcpexisting/clients/listers/exampledashed/v1/testtype.go @@ -0,0 +1,119 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The KCP 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 v1 + +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" + + exampledashedv1 "acme.corp/pkg/apis/exampledashed/v1" + exampledashedv1listers "acme.corp/pkg/generated/listers/exampledashed/v1" +) + +// TestTypeClusterLister can list TestTypes across all workspaces, or scope down to a TestTypeLister for one workspace. +// All objects returned here must be treated as read-only. +type TestTypeClusterLister interface { + // List lists all TestTypes in the indexer. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*exampledashedv1.TestType, err error) + // Cluster returns a lister that can list and get TestTypes in one workspace. + Cluster(clusterName logicalcluster.Name) exampledashedv1listers.TestTypeLister + TestTypeClusterListerExpansion +} + +type testTypeClusterLister struct { + indexer cache.Indexer +} + +// NewTestTypeClusterLister returns a new TestTypeClusterLister. +// 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 NewTestTypeClusterLister(indexer cache.Indexer) *testTypeClusterLister { + return &testTypeClusterLister{indexer: indexer} +} + +// List lists all TestTypes in the indexer across all workspaces. +func (s *testTypeClusterLister) List(selector labels.Selector) (ret []*exampledashedv1.TestType, err error) { + err = cache.ListAll(s.indexer, selector, func(m interface{}) { + ret = append(ret, m.(*exampledashedv1.TestType)) + }) + return ret, err +} + +// Cluster scopes the lister to one workspace, allowing users to list and get TestTypes. +func (s *testTypeClusterLister) Cluster(clusterName logicalcluster.Name) exampledashedv1listers.TestTypeLister { + return &testTypeLister{indexer: s.indexer, clusterName: clusterName} +} + +// testTypeLister implements the exampledashedv1listers.TestTypeLister interface. +type testTypeLister struct { + indexer cache.Indexer + clusterName logicalcluster.Name +} + +// List lists all TestTypes in the indexer for a workspace. +func (s *testTypeLister) List(selector labels.Selector) (ret []*exampledashedv1.TestType, err error) { + err = kcpcache.ListAllByCluster(s.indexer, s.clusterName, selector, func(i interface{}) { + ret = append(ret, i.(*exampledashedv1.TestType)) + }) + return ret, err +} + +// TestTypes returns an object that can list and get TestTypes in one namespace. +func (s *testTypeLister) TestTypes(namespace string) exampledashedv1listers.TestTypeNamespaceLister { + return &testTypeNamespaceLister{indexer: s.indexer, clusterName: s.clusterName, namespace: namespace} +} + +// testTypeNamespaceLister implements the exampledashedv1listers.TestTypeNamespaceLister interface. +type testTypeNamespaceLister struct { + indexer cache.Indexer + clusterName logicalcluster.Name + namespace string +} + +// List lists all TestTypes in the indexer for a given workspace and namespace. +func (s *testTypeNamespaceLister) List(selector labels.Selector) (ret []*exampledashedv1.TestType, err error) { + err = kcpcache.ListAllByClusterAndNamespace(s.indexer, s.clusterName, s.namespace, selector, func(i interface{}) { + ret = append(ret, i.(*exampledashedv1.TestType)) + }) + return ret, err +} + +// Get retrieves the TestType from the indexer for a given workspace, namespace and name. +func (s *testTypeNamespaceLister) Get(name string) (*exampledashedv1.TestType, 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(exampledashedv1.Resource("testtypes"), name) + } + return obj.(*exampledashedv1.TestType), nil +} diff --git a/examples/pkg/kcpexisting/clients/listers/exampledashed/v1/testtype_expansion.go b/examples/pkg/kcpexisting/clients/listers/exampledashed/v1/testtype_expansion.go new file mode 100644 index 000000000..835da85d6 --- /dev/null +++ b/examples/pkg/kcpexisting/clients/listers/exampledashed/v1/testtype_expansion.go @@ -0,0 +1,25 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The KCP 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 v1 + +// TestTypeClusterListerExpansion allows custom methods to be added to TestTypeClusterLister. +type TestTypeClusterListerExpansion interface{} diff --git a/hack/update-codegen.sh b/hack/update-codegen.sh index 2e70d5403..f38bda0ae 100755 --- a/hack/update-codegen.sh +++ b/hack/update-codegen.sh @@ -39,6 +39,7 @@ ${KUBE_CLIENT_GEN} \ --input example/v1beta1 \ --input example/v2 \ --input example3/v1 \ + --input exampledashed/v1 \ --input secondexample/v1 \ --input existinginterfaces/v1 \ --output-dir ./pkg/generated/clientset \ @@ -48,13 +49,13 @@ ${KUBE_APPLYCONFIGURATION_GEN} \ --go-header-file ./../hack/boilerplate/boilerplate.generatego.txt \ --output-dir ./pkg/generated/applyconfigurations \ --output-pkg acme.corp/pkg/generated/applyconfigurations \ - acme.corp/pkg/apis/example/v1 acme.corp/pkg/apis/example/v1alpha1 acme.corp/pkg/apis/example/v1beta1 acme.corp/pkg/apis/example/v2 acme.corp/pkg/apis/example3/v1 acme.corp/pkg/apis/secondexample/v1 acme.corp/pkg/apis/existinginterfaces/v1 + acme.corp/pkg/apis/example/v1 acme.corp/pkg/apis/example/v1alpha1 acme.corp/pkg/apis/example/v1beta1 acme.corp/pkg/apis/example/v2 acme.corp/pkg/apis/example3/v1 acme.corp/pkg/apis/exampledashed/v1 acme.corp/pkg/apis/secondexample/v1 acme.corp/pkg/apis/existinginterfaces/v1 ${KUBE_LISTER_GEN} \ --go-header-file ./../hack/boilerplate/boilerplate.generatego.txt \ --output-dir ./pkg/generated/listers \ --output-pkg acme.corp/pkg/generated/listers \ - acme.corp/pkg/apis/example/v1 acme.corp/pkg/apis/example/v1alpha1 acme.corp/pkg/apis/example/v1beta1 acme.corp/pkg/apis/example/v2 acme.corp/pkg/apis/example3/v1 acme.corp/pkg/apis/secondexample/v1 acme.corp/pkg/apis/existinginterfaces/v1 + acme.corp/pkg/apis/example/v1 acme.corp/pkg/apis/example/v1alpha1 acme.corp/pkg/apis/example/v1beta1 acme.corp/pkg/apis/example/v2 acme.corp/pkg/apis/example3/v1 acme.corp/pkg/apis/exampledashed/v1 acme.corp/pkg/apis/secondexample/v1 acme.corp/pkg/apis/existinginterfaces/v1 ${KUBE_INFORMER_GEN} \ --versioned-clientset-package acme.corp/pkg/generated/clientset/versioned \ @@ -62,7 +63,7 @@ ${KUBE_INFORMER_GEN} \ --go-header-file ./../hack/boilerplate/boilerplate.generatego.txt \ --output-dir ./pkg/generated/informers \ --output-pkg acme.corp/pkg/generated/informers \ - acme.corp/pkg/apis/example/v1 acme.corp/pkg/apis/example/v1alpha1 acme.corp/pkg/apis/example/v1beta1 acme.corp/pkg/apis/example/v2 acme.corp/pkg/apis/example3/v1 acme.corp/pkg/apis/secondexample/v1 acme.corp/pkg/apis/existinginterfaces/v1 + acme.corp/pkg/apis/example/v1 acme.corp/pkg/apis/example/v1alpha1 acme.corp/pkg/apis/example/v1beta1 acme.corp/pkg/apis/example/v2 acme.corp/pkg/apis/example3/v1 acme.corp/pkg/apis/exampledashed/v1 acme.corp/pkg/apis/secondexample/v1 acme.corp/pkg/apis/existinginterfaces/v1 # Generate cluster-aware clients, informers and listers using generated single-cluster code ./../bin/code-generator \ diff --git a/pkg/generators/clientgen/clientgen.go b/pkg/generators/clientgen/clientgen.go index d6d10a229..bae3cb579 100644 --- a/pkg/generators/clientgen/clientgen.go +++ b/pkg/generators/clientgen/clientgen.go @@ -226,8 +226,8 @@ func (g Generator) Generate(ctx *genall.GenerationContext) error { } // adapted from https://github.com/kubernetes/kubernetes/blob/8f269d6df2a57544b73d5ca35e04451373ef334c/staging/src/k8s.io/code-generator/cmd/client-gen/types/helpers.go#L87-L103 -func toGroupVersionInfos(groupVersionKinds map[parser.Group]map[types.PackageVersion][]parser.Kind) []types.GroupVersionInfo { - var info []types.GroupVersionInfo +func toGroupVersionInfos(groupVersionKinds map[parser.Group]map[types.PackageVersion][]parser.Kind) []parser.Group { + var info []parser.Group for group, versions := range groupVersionKinds { for version := range versions { info = append(info, toGroupVersionInfo(group, version)) @@ -240,12 +240,12 @@ func toGroupVersionInfos(groupVersionKinds map[parser.Group]map[types.PackageVer } // adapted from https://github.com/kubernetes/kubernetes/blob/8f269d6df2a57544b73d5ca35e04451373ef334c/staging/src/k8s.io/code-generator/cmd/client-gen/types/helpers.go#L87-L103 -func toGroupVersionInfo(group parser.Group, version types.PackageVersion) types.GroupVersionInfo { - return types.GroupVersionInfo{ +func toGroupVersionInfo(group parser.Group, version types.PackageVersion) parser.Group { + return parser.Group{ Group: group.Group, - Version: types.Version(namer.IC(version.Version.String())), + Version: parser.Version(namer.IC(version.Version.String())), PackageAlias: strings.ToLower(group.GoName + version.Version.NonEmpty()), - GroupGoName: group.GoName, + GoName: group.GoName, LowerCaseGroupGoName: namer.IL(group.GoName), } } diff --git a/pkg/generators/informergen/informergen.go b/pkg/generators/informergen/informergen.go index 157585c87..c24514b5c 100644 --- a/pkg/generators/informergen/informergen.go +++ b/pkg/generators/informergen/informergen.go @@ -146,12 +146,12 @@ func (g Generator) Generate(ctx *genall.GenerationContext) error { return err } - gvks := map[types.Group]map[types.Version][]parser.Kind{} + gvks := map[types.Group]map[parser.Version][]parser.Kind{} for group, versions := range groupVersionKinds { for version, kinds := range versions { info := toGroupVersionInfo(group, version) if _, exists := gvks[info.Group]; !exists { - gvks[info.Group] = map[types.Version][]parser.Kind{} + gvks[info.Group] = map[parser.Version][]parser.Kind{} } gvks[info.Group][info.Version] = kinds } @@ -184,9 +184,9 @@ func (g Generator) Generate(ctx *genall.GenerationContext) error { "group", group.String(), ) - var onlyVersions []types.Version + var onlyVersions []parser.Version for version := range versions { - onlyVersions = append(onlyVersions, types.Version(namer.IC(version.Version.String()))) + onlyVersions = append(onlyVersions, parser.Version(namer.IC(version.Version.String()))) } sort.Slice(onlyVersions, func(i, j int) bool { return onlyVersions[i].PackageName() < onlyVersions[j].PackageName() @@ -246,8 +246,8 @@ func (g Generator) Generate(ctx *genall.GenerationContext) error { } // adapted from https://github.com/kubernetes/kubernetes/blob/8f269d6df2a57544b73d5ca35e04451373ef334c/staging/src/k8s.io/code-generator/cmd/client-gen/types/helpers.go#L87-L103 -func toGroupVersionInfos(groupVersionKinds map[parser.Group]map[types.PackageVersion][]parser.Kind) []types.GroupVersionInfo { - var info []types.GroupVersionInfo +func toGroupVersionInfos(groupVersionKinds map[parser.Group]map[types.PackageVersion][]parser.Kind) []parser.Group { + var info []parser.Group for group, versions := range groupVersionKinds { for version := range versions { info = append(info, toGroupVersionInfo(group, version)) @@ -260,12 +260,12 @@ func toGroupVersionInfos(groupVersionKinds map[parser.Group]map[types.PackageVer } // adapted from https://github.com/kubernetes/kubernetes/blob/8f269d6df2a57544b73d5ca35e04451373ef334c/staging/src/k8s.io/code-generator/cmd/client-gen/types/helpers.go#L87-L103 -func toGroupVersionInfo(group parser.Group, version types.PackageVersion) types.GroupVersionInfo { - return types.GroupVersionInfo{ +func toGroupVersionInfo(group parser.Group, version types.PackageVersion) parser.Group { + return parser.Group{ Group: group.Group, - Version: types.Version(namer.IC(version.Version.String())), PackageAlias: strings.ToLower(group.GoName + version.Version.NonEmpty()), - GroupGoName: group.GoName, + Version: parser.Version(namer.IC(version.Version.String())), + GoName: group.GoName, LowerCaseGroupGoName: namer.IL(group.GoName), } } diff --git a/pkg/generators/listergen/listergen.go b/pkg/generators/listergen/listergen.go index 0aa7ebe48..cde9d6b7b 100644 --- a/pkg/generators/listergen/listergen.go +++ b/pkg/generators/listergen/listergen.go @@ -126,12 +126,12 @@ func (g Generator) Generate(ctx *genall.GenerationContext) error { } // adapted from https://github.com/kubernetes/kubernetes/blob/8f269d6df2a57544b73d5ca35e04451373ef334c/staging/src/k8s.io/code-generator/cmd/client-gen/types/helpers.go#L87-L103 -func toGroupVersionInfo(group parser.Group, version types.PackageVersion) types.GroupVersionInfo { - return types.GroupVersionInfo{ +func toGroupVersionInfo(group parser.Group, version types.PackageVersion) parser.Group { + return parser.Group{ Group: group.Group, - Version: types.Version(namer.IC(version.Version.String())), + Version: parser.Version(namer.IC(version.Version.String())), PackageAlias: strings.ToLower(group.GoName + version.Version.NonEmpty()), - GroupGoName: group.GoName, + GoName: group.GoName, LowerCaseGroupGoName: namer.IL(group.GoName), } } diff --git a/pkg/internal/clientgen/clientset.go b/pkg/internal/clientgen/clientset.go index 943a15fbb..b42849c40 100644 --- a/pkg/internal/clientgen/clientset.go +++ b/pkg/internal/clientgen/clientset.go @@ -5,8 +5,7 @@ import ( "strings" "text/template" - "k8s.io/code-generator/cmd/client-gen/types" - + "github.com/kcp-dev/code-generator/v2/pkg/parser" "github.com/kcp-dev/code-generator/v2/pkg/util" ) @@ -15,7 +14,7 @@ type ClientSet struct { Name string // Groups are the groups in this client-set. - Groups []types.GroupVersionInfo + Groups []parser.Group // PackagePath is the package under which this client-set will be exposed. // TODO(skuznets) we should be able to figure this out from the output dir, ideally @@ -38,6 +37,7 @@ func (c *ClientSet) WriteContent(w io.Writer) error { m := map[string]interface{}{ "name": c.Name, + "packageName": strings.ReplaceAll(c.Name, "-", ""), "packagePath": c.PackagePath, "groups": c.Groups, "singleClusterClientPackagePath": c.SingleClusterClientPackagePath, @@ -51,7 +51,7 @@ var clientset = ` // Code generated by kcp code-generator. DO NOT EDIT. -package {{.name}} +package {{.packageName}} import ( "fmt" @@ -66,14 +66,14 @@ import ( "k8s.io/client-go/rest" "k8s.io/client-go/util/flowcontrol" -{{range .groups}} {{.PackageAlias}} "{{$.packagePath}}/typed/{{.Group.PackageName}}/{{.Version.PackageName}}" +{{range .groups}} {{.GoPackageAlias}} "{{$.packagePath}}/typed/{{.PackageName}}/{{.Version.PackageName}}" {{end -}} ) type ClusterInterface interface { Cluster(logicalcluster.Path) client.Interface Discovery() discovery.DiscoveryInterface -{{range .groups}} {{.GroupGoName}}{{.Version}}() {{.PackageAlias}}.{{.GroupGoName}}{{.Version}}ClusterInterface +{{range .groups}} {{.GroupGoName}}{{.Version}}() {{.GoPackageAlias}}.{{.GroupGoName}}{{.Version}}ClusterInterface {{end -}} } @@ -81,7 +81,7 @@ type ClusterInterface interface { type ClusterClientset struct { *discovery.DiscoveryClient clientCache kcpclient.Cache[*client.Clientset] -{{range .groups}} {{.LowerCaseGroupGoName}}{{.Version}} *{{.PackageAlias}}.{{.GroupGoName}}{{.Version}}ClusterClient +{{range .groups}} {{.GroupGoNameLower}}{{.Version}} *{{.GoPackageAlias}}.{{.GroupGoName}}{{.Version}}ClusterClient {{end -}} } @@ -95,8 +95,8 @@ func (c *ClusterClientset) Discovery() discovery.DiscoveryInterface { {{range .groups}} // {{.GroupGoName}}{{.Version}} retrieves the {{.GroupGoName}}{{.Version}}ClusterClient. -func (c *ClusterClientset) {{.GroupGoName}}{{.Version}}() {{.PackageAlias}}.{{.GroupGoName}}{{.Version}}ClusterInterface { - return c.{{.LowerCaseGroupGoName}}{{.Version}} +func (c *ClusterClientset) {{.GroupGoName}}{{.Version}}() {{.GoPackageAlias}}.{{.GroupGoName}}{{.Version}}ClusterInterface { + return c.{{.GroupGoNameLower}}{{.Version}} } {{end -}} @@ -152,7 +152,7 @@ func NewForConfigAndClient(c *rest.Config, httpClient *http.Client) (*ClusterCli var cs ClusterClientset cs.clientCache = cache var err error -{{range .groups}} cs.{{.LowerCaseGroupGoName}}{{.Version}}, err = {{.PackageAlias}}.NewForConfigAndClient(&configShallowCopy, httpClient) +{{range .groups}} cs.{{.GroupGoNameLower}}{{.Version}}, err = {{.GoPackageAlias}}.NewForConfigAndClient(&configShallowCopy, httpClient) if err != nil { return nil, err } diff --git a/pkg/internal/clientgen/fake_clientset.go b/pkg/internal/clientgen/fake_clientset.go index 511f61e70..a1c55251f 100644 --- a/pkg/internal/clientgen/fake_clientset.go +++ b/pkg/internal/clientgen/fake_clientset.go @@ -5,8 +5,7 @@ import ( "strings" "text/template" - "k8s.io/code-generator/cmd/client-gen/types" - + "github.com/kcp-dev/code-generator/v2/pkg/parser" "github.com/kcp-dev/code-generator/v2/pkg/util" ) @@ -15,7 +14,7 @@ type FakeClientset struct { Name string // Groups are the groups in this client-set. - Groups []types.GroupVersionInfo + Groups []parser.Group // PackagePath is the package under which this client-set will be exposed. // TODO(skuznets) we should be able to figure this out from the output dir, ideally @@ -65,11 +64,11 @@ import ( clientscheme "{{.singleClusterClientPackagePath}}/scheme" kcpclient "{{.packagePath}}" -{{range .groups}} {{.PackageAlias}} "{{$.singleClusterClientPackagePath}}/typed/{{.Group.PackageName}}/{{.Version.PackageName}}" +{{range .groups}} {{.GoPackageAlias}} "{{$.singleClusterClientPackagePath}}/typed/{{.PackageName}}/{{.Version.PackageName}}" {{end -}} -{{range .groups}} kcp{{.PackageAlias}} "{{$.packagePath}}/typed/{{.Group.PackageName}}/{{.Version.PackageName}}" +{{range .groups}} kcp{{.GoPackageAlias}} "{{$.packagePath}}/typed/{{.PackageName}}/{{.Version.PackageName}}" {{end -}} -{{range .groups}} fake{{.PackageAlias}} "{{$.packagePath}}/typed/{{.Group.PackageName}}/{{.Version.PackageName}}/fake" +{{range .groups}} fake{{.GoPackageAlias}} "{{$.packagePath}}/typed/{{.PackageName}}/{{.Version.PackageName}}/fake" {{end -}} ) @@ -109,8 +108,8 @@ func (c *ClusterClientset) Tracker() kcptesting.ObjectTracker { {{range .groups}} // {{.GroupGoName}}{{.Version}} retrieves the {{.GroupGoName}}{{.Version}}ClusterClient. -func (c *ClusterClientset) {{.GroupGoName}}{{.Version}}() kcp{{.PackageAlias}}.{{.GroupGoName}}{{.Version}}ClusterInterface { - return &fake{{.PackageAlias}}.{{.GroupGoName}}{{.Version}}ClusterClient{Fake: c.Fake} +func (c *ClusterClientset) {{.GroupGoName}}{{.Version}}() kcp{{.GoPackageAlias}}.{{.GroupGoName}}{{.Version}}ClusterInterface { + return &fake{{.GoPackageAlias}}.{{.GroupGoName}}{{.Version}}ClusterClient{Fake: c.Fake} } {{end -}} @@ -148,8 +147,8 @@ func (c *Clientset) Tracker() kcptesting.ScopedObjectTracker { {{range .groups}} // {{.GroupGoName}}{{.Version}} retrieves the {{.GroupGoName}}{{.Version}}Client. -func (c *Clientset) {{.GroupGoName}}{{.Version}}() {{.PackageAlias}}.{{.GroupGoName}}{{.Version}}Interface { - return &fake{{.PackageAlias}}.{{.GroupGoName}}{{.Version}}Client{Fake: c.Fake, ClusterPath: c.clusterPath} +func (c *Clientset) {{.GroupGoName}}{{.Version}}() {{.GoPackageAlias}}.{{.GroupGoName}}{{.Version}}Interface { + return &fake{{.GoPackageAlias}}.{{.GroupGoName}}{{.Version}}Client{Fake: c.Fake, ClusterPath: c.clusterPath} } {{end -}} ` diff --git a/pkg/internal/clientgen/fake_group.go b/pkg/internal/clientgen/fake_group.go index cd3b96b0b..8d9f6672d 100644 --- a/pkg/internal/clientgen/fake_group.go +++ b/pkg/internal/clientgen/fake_group.go @@ -5,15 +5,13 @@ import ( "strings" "text/template" - "k8s.io/code-generator/cmd/client-gen/types" - "github.com/kcp-dev/code-generator/v2/pkg/parser" "github.com/kcp-dev/code-generator/v2/pkg/util" ) type FakeGroup struct { // Group is the group in this client. - Group types.GroupVersionInfo + Group parser.Group // Kinds are the kinds in the group. Kinds []parser.Kind @@ -59,17 +57,17 @@ import ( "github.com/kcp-dev/logicalcluster/v3" "k8s.io/client-go/rest" - kcp{{.group.PackageAlias}} "{{.packagePath}}/typed/{{.group.Group.PackageName}}/{{.group.Version.PackageName}}" - {{.group.PackageAlias}} "{{.singleClusterClientPackagePath}}/typed/{{.group.Group.PackageName}}/{{.group.Version.PackageName}}" + kcp{{.group.GoPackageAlias}} "{{.packagePath}}/typed/{{.group.PackageName}}/{{.group.Version.PackageName}}" + {{.group.GoPackageAlias}} "{{.singleClusterClientPackagePath}}/typed/{{.group.PackageName}}/{{.group.Version.PackageName}}" ) -var _ kcp{{.group.PackageAlias}}.{{.group.GroupGoName}}{{.group.Version}}ClusterInterface = (*{{.group.GroupGoName}}{{.group.Version}}ClusterClient)(nil) +var _ kcp{{.group.GoPackageAlias}}.{{.group.GroupGoName}}{{.group.Version}}ClusterInterface = (*{{.group.GroupGoName}}{{.group.Version}}ClusterClient)(nil) type {{.group.GroupGoName}}{{.group.Version}}ClusterClient struct { *kcptesting.Fake } -func (c *{{.group.GroupGoName}}{{.group.Version}}ClusterClient) Cluster(clusterPath logicalcluster.Path) {{.group.PackageAlias}}.{{.group.GroupGoName}}{{.group.Version}}Interface { +func (c *{{.group.GroupGoName}}{{.group.Version}}ClusterClient) Cluster(clusterPath logicalcluster.Path) {{.group.GoPackageAlias}}.{{.group.GroupGoName}}{{.group.Version}}Interface { if clusterPath == logicalcluster.Wildcard { panic("A specific cluster must be provided when scoping, not the wildcard.") } @@ -77,12 +75,12 @@ func (c *{{.group.GroupGoName}}{{.group.Version}}ClusterClient) Cluster(clusterP } {{ range .kinds}} -func (c *{{$.group.GroupGoName}}{{$.group.Version}}ClusterClient) {{.Plural}}() kcp{{$.group.PackageAlias}}.{{.String}}ClusterInterface { +func (c *{{$.group.GroupGoName}}{{$.group.Version}}ClusterClient) {{.Plural}}() kcp{{$.group.GoPackageAlias}}.{{.String}}ClusterInterface { return &{{.Plural | lowerFirst}}ClusterClient{Fake: c.Fake} } {{end -}} -var _ {{.group.PackageAlias}}.{{.group.GroupGoName}}{{.group.Version}}Interface = (*{{.group.GroupGoName}}{{.group.Version}}Client)(nil) +var _ {{.group.GoPackageAlias}}.{{.group.GroupGoName}}{{.group.Version}}Interface = (*{{.group.GroupGoName}}{{.group.Version}}Client)(nil) type {{.group.GroupGoName}}{{.group.Version}}Client struct { *kcptesting.Fake @@ -95,7 +93,7 @@ func (c *{{.group.GroupGoName}}{{.group.Version}}Client) RESTClient() rest.Inter } {{ range .kinds}} -func (c *{{$.group.GroupGoName}}{{$.group.Version}}Client) {{.Plural}}({{if .IsNamespaced}}namespace string{{end}}) {{$.group.PackageAlias}}.{{.String}}Interface { +func (c *{{$.group.GroupGoName}}{{$.group.Version}}Client) {{.Plural}}({{if .IsNamespaced}}namespace string{{end}}) {{$.group.GoPackageAlias}}.{{.String}}Interface { return &{{.Plural | lowerFirst}}Client{Fake: c.Fake, ClusterPath: c.ClusterPath{{if .IsNamespaced}}, Namespace: namespace{{end}}} } {{end -}} diff --git a/pkg/internal/clientgen/fake_type.go b/pkg/internal/clientgen/fake_type.go index c52abf527..00099ab4a 100644 --- a/pkg/internal/clientgen/fake_type.go +++ b/pkg/internal/clientgen/fake_type.go @@ -8,7 +8,6 @@ import ( "text/template" "k8s.io/apimachinery/pkg/util/sets" - "k8s.io/code-generator/cmd/client-gen/types" "github.com/kcp-dev/code-generator/v2/pkg/parser" "github.com/kcp-dev/code-generator/v2/pkg/util" @@ -16,7 +15,7 @@ import ( type FakeTypedClient struct { // Group is the group in this client. - Group types.GroupVersionInfo + Group parser.Group // Kind is the kinds in this file. Kind parser.Kind @@ -148,7 +147,7 @@ import ( {{- if .hasMethods }} "context" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - {{.group.PackageAlias}} "{{.apiPackagePath}}/{{.group.Group.PackageName}}/{{.group.Version.PackageName}}" + {{.group.GoPackageAlias}} "{{.apiPackagePath}}/{{.group.PackageName}}/{{.group.Version.PackageName}}" {{end}} {{- if "watch" | .kind.SupportedVerbs.Has }} @@ -168,13 +167,13 @@ import ( "k8s.io/apimachinery/pkg/types" {{end}} {{- if and .generateApplyVerbs ("apply" | .kind.SupportedVerbs.Has) }} - applyconfigurations{{.group.PackageAlias}} "{{.singleClusterApplyConfigurationsPackagePath}}/{{.group.Group.PackageName}}/{{.group.Version.PackageName}}" + applyconfigurations{{.group.GoPackageAlias}} "{{.singleClusterApplyConfigurationsPackagePath}}/{{.group.PackageName}}/{{.group.Version.PackageName}}" {{end}} {{- if .kind.IsNamespaced}} - kcp{{.group.PackageAlias}} "{{.packagePath}}/typed/{{.group.Group.PackageName}}/{{.group.Version.PackageName}}" + kcp{{.group.GoPackageAlias}} "{{.packagePath}}/typed/{{.group.PackageName}}/{{.group.Version.PackageName}}" {{end}} - {{.group.PackageAlias}}client "{{.singleClusterClientPackagePath}}/typed/{{.group.Group.PackageName}}/{{.group.Version.PackageName}}" + {{.group.GoPackageAlias}}client "{{.singleClusterClientPackagePath}}/typed/{{.group.PackageName}}/{{.group.Version.PackageName}}" ) var {{.kind.Plural | lowerFirst}}Resource = schema.GroupVersionResource{Group: "{{.groupName}}", Version: "{{.group.Version.String | toLower}}", Resource: "{{.kind.Plural | toLower}}"} @@ -185,7 +184,7 @@ type {{.kind.Plural | lowerFirst}}ClusterClient struct { } // Cluster scopes the client down to a particular cluster. -func (c *{{.kind.Plural | lowerFirst}}ClusterClient) Cluster(clusterPath logicalcluster.Path) {{if .kind.IsNamespaced}}kcp{{.group.PackageAlias}}.{{.kind.Plural}}Namespacer{{else}}{{.group.PackageAlias}}client.{{.kind.String}}Interface{{end}} { +func (c *{{.kind.Plural | lowerFirst}}ClusterClient) Cluster(clusterPath logicalcluster.Path) {{if .kind.IsNamespaced}}kcp{{.group.GoPackageAlias}}.{{.kind.Plural}}Namespacer{{else}}{{.group.GoPackageAlias}}client.{{.kind.String}}Interface{{end}} { if clusterPath == logicalcluster.Wildcard { panic("A specific cluster must be provided when scoping, not the wildcard.") } @@ -198,8 +197,8 @@ func (c *{{.kind.Plural | lowerFirst}}ClusterClient) Cluster(clusterPath logical {{ if .kind.SupportsListWatch }} // List takes label and field selectors, and returns the list of {{.kind.Plural}} that match those selectors across all clusters. -func (c *{{.kind.Plural | lowerFirst}}ClusterClient) List(ctx context.Context, opts metav1.ListOptions) (*{{.group.PackageAlias}}.{{.kind.String}}List, error) { - obj, err := c.Fake.Invokes(kcptesting.New{{if not .kind.IsNamespaced}}Root{{end}}ListAction({{.kind.Plural | lowerFirst}}Resource, {{.kind.Plural | lowerFirst}}Kind, logicalcluster.Wildcard, {{if .kind.IsNamespaced}}metav1.NamespaceAll, {{end}}opts), &{{.group.PackageAlias}}.{{.kind.String}}List{}) +func (c *{{.kind.Plural | lowerFirst}}ClusterClient) List(ctx context.Context, opts metav1.ListOptions) (*{{.group.GoPackageAlias}}.{{.kind.String}}List, error) { + obj, err := c.Fake.Invokes(kcptesting.New{{if not .kind.IsNamespaced}}Root{{end}}ListAction({{.kind.Plural | lowerFirst}}Resource, {{.kind.Plural | lowerFirst}}Kind, logicalcluster.Wildcard, {{if .kind.IsNamespaced}}metav1.NamespaceAll, {{end}}opts), &{{.group.GoPackageAlias}}.{{.kind.String}}List{}) if obj == nil { return nil, err } @@ -208,8 +207,8 @@ func (c *{{.kind.Plural | lowerFirst}}ClusterClient) List(ctx context.Context, o if label == nil { label = labels.Everything() } - list := &{{.group.PackageAlias}}.{{.kind.String}}List{ListMeta: obj.(*{{.group.PackageAlias}}.{{.kind.String}}List).ListMeta} - for _, item := range obj.(*{{.group.PackageAlias}}.{{.kind.String}}List).Items { + list := &{{.group.GoPackageAlias}}.{{.kind.String}}List{ListMeta: obj.(*{{.group.GoPackageAlias}}.{{.kind.String}}List).ListMeta} + for _, item := range obj.(*{{.group.GoPackageAlias}}.{{.kind.String}}List).Items { if label.Matches(labels.Set(item.Labels)) { list.Items = append(list.Items, item) } @@ -229,7 +228,7 @@ type {{.kind.Plural | lowerFirst}}Namespacer struct { ClusterPath logicalcluster.Path } -func (n *{{.kind.Plural | lowerFirst}}Namespacer) Namespace(namespace string) {{.group.PackageAlias}}client.{{.kind.String}}Interface { +func (n *{{.kind.Plural | lowerFirst}}Namespacer) Namespace(namespace string) {{.group.GoPackageAlias}}client.{{.kind.String}}Interface { return &{{.kind.Plural | lowerFirst}}Client{Fake: n.Fake, ClusterPath: n.ClusterPath, Namespace: namespace} } {{ end -}} @@ -241,38 +240,38 @@ type {{.kind.Plural | lowerFirst}}Client struct { } {{if "create" | .kind.SupportedVerbs.Has}} -func (c *{{.kind.Plural | lowerFirst}}Client) Create(ctx context.Context, {{.kind.String | lowerFirst}} *{{.group.PackageAlias}}.{{.kind.String}}, opts metav1.CreateOptions) (*{{.group.PackageAlias}}.{{.kind.String}}, error) { - obj, err := c.Fake.Invokes(kcptesting.New{{if not .kind.IsNamespaced}}Root{{end}}CreateAction({{.kind.Plural | lowerFirst}}Resource, c.ClusterPath, {{if .kind.IsNamespaced}}c.Namespace, {{end}}{{.kind.String | lowerFirst}}), &{{.group.PackageAlias}}.{{.kind.String}}{}) +func (c *{{.kind.Plural | lowerFirst}}Client) Create(ctx context.Context, {{.kind.String | lowerFirst}} *{{.group.GoPackageAlias}}.{{.kind.String}}, opts metav1.CreateOptions) (*{{.group.GoPackageAlias}}.{{.kind.String}}, error) { + obj, err := c.Fake.Invokes(kcptesting.New{{if not .kind.IsNamespaced}}Root{{end}}CreateAction({{.kind.Plural | lowerFirst}}Resource, c.ClusterPath, {{if .kind.IsNamespaced}}c.Namespace, {{end}}{{.kind.String | lowerFirst}}), &{{.group.GoPackageAlias}}.{{.kind.String}}{}) if obj == nil { return nil, err } - return obj.(*{{.group.PackageAlias}}.{{.kind.String}}), err + return obj.(*{{.group.GoPackageAlias}}.{{.kind.String}}), err } {{end -}} {{if "update" | .kind.SupportedVerbs.Has}} -func (c *{{.kind.Plural | lowerFirst}}Client) Update(ctx context.Context, {{.kind.String | lowerFirst}} *{{.group.PackageAlias}}.{{.kind.String}}, opts metav1.UpdateOptions) (*{{.group.PackageAlias}}.{{.kind.String}}, error) { - obj, err := c.Fake.Invokes(kcptesting.New{{if not .kind.IsNamespaced}}Root{{end}}UpdateAction({{.kind.Plural | lowerFirst}}Resource, c.ClusterPath, {{if .kind.IsNamespaced}}c.Namespace, {{end}}{{.kind.String | lowerFirst}}), &{{.group.PackageAlias}}.{{.kind.String}}{}) +func (c *{{.kind.Plural | lowerFirst}}Client) Update(ctx context.Context, {{.kind.String | lowerFirst}} *{{.group.GoPackageAlias}}.{{.kind.String}}, opts metav1.UpdateOptions) (*{{.group.GoPackageAlias}}.{{.kind.String}}, error) { + obj, err := c.Fake.Invokes(kcptesting.New{{if not .kind.IsNamespaced}}Root{{end}}UpdateAction({{.kind.Plural | lowerFirst}}Resource, c.ClusterPath, {{if .kind.IsNamespaced}}c.Namespace, {{end}}{{.kind.String | lowerFirst}}), &{{.group.GoPackageAlias}}.{{.kind.String}}{}) if obj == nil { return nil, err } - return obj.(*{{.group.PackageAlias}}.{{.kind.String}}), err + return obj.(*{{.group.GoPackageAlias}}.{{.kind.String}}), err } {{end -}} {{if "updateStatus" | .kind.SupportedVerbs.Has}} -func (c *{{.kind.Plural | lowerFirst}}Client) UpdateStatus(ctx context.Context, {{.kind.String | lowerFirst}} *{{.group.PackageAlias}}.{{.kind.String}}, opts metav1.UpdateOptions) (*{{.group.PackageAlias}}.{{.kind.String}}, error) { - obj, err := c.Fake.Invokes(kcptesting.New{{if not .kind.IsNamespaced}}Root{{end}}UpdateSubresourceAction({{.kind.Plural | lowerFirst}}Resource, c.ClusterPath, "status", {{if .kind.IsNamespaced}}c.Namespace, {{end}}{{.kind.String | lowerFirst}}), &{{.group.PackageAlias}}.{{.kind.String}}{}) +func (c *{{.kind.Plural | lowerFirst}}Client) UpdateStatus(ctx context.Context, {{.kind.String | lowerFirst}} *{{.group.GoPackageAlias}}.{{.kind.String}}, opts metav1.UpdateOptions) (*{{.group.GoPackageAlias}}.{{.kind.String}}, error) { + obj, err := c.Fake.Invokes(kcptesting.New{{if not .kind.IsNamespaced}}Root{{end}}UpdateSubresourceAction({{.kind.Plural | lowerFirst}}Resource, c.ClusterPath, "status", {{if .kind.IsNamespaced}}c.Namespace, {{end}}{{.kind.String | lowerFirst}}), &{{.group.GoPackageAlias}}.{{.kind.String}}{}) if obj == nil { return nil, err } - return obj.(*{{.group.PackageAlias}}.{{.kind.String}}), err + return obj.(*{{.group.GoPackageAlias}}.{{.kind.String}}), err } {{end -}} {{if "delete" | .kind.SupportedVerbs.Has}} func (c *{{.kind.Plural | lowerFirst}}Client) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { - _, err := c.Fake.Invokes(kcptesting.New{{if not .kind.IsNamespaced}}Root{{end}}DeleteActionWithOptions({{.kind.Plural | lowerFirst}}Resource, c.ClusterPath, {{if .kind.IsNamespaced}}c.Namespace, {{end}}name, opts), &{{.group.PackageAlias}}.{{.kind.String}}{}) + _, err := c.Fake.Invokes(kcptesting.New{{if not .kind.IsNamespaced}}Root{{end}}DeleteActionWithOptions({{.kind.Plural | lowerFirst}}Resource, c.ClusterPath, {{if .kind.IsNamespaced}}c.Namespace, {{end}}name, opts), &{{.group.GoPackageAlias}}.{{.kind.String}}{}) return err } {{end -}} @@ -281,25 +280,25 @@ func (c *{{.kind.Plural | lowerFirst}}Client) Delete(ctx context.Context, name s func (c *{{.kind.Plural | lowerFirst}}Client) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { action := kcptesting.New{{if not .kind.IsNamespaced}}Root{{end}}DeleteCollectionAction({{.kind.Plural | lowerFirst}}Resource, c.ClusterPath, {{if .kind.IsNamespaced}}c.Namespace, {{end}}listOpts) - _, err := c.Fake.Invokes(action, &{{.group.PackageAlias}}.{{.kind.String}}List{}) + _, err := c.Fake.Invokes(action, &{{.group.GoPackageAlias}}.{{.kind.String}}List{}) return err } {{end -}} {{if "get" | .kind.SupportedVerbs.Has}} -func (c *{{.kind.Plural | lowerFirst}}Client) Get(ctx context.Context, name string, options metav1.GetOptions) (*{{.group.PackageAlias}}.{{.kind.String}}, error) { - obj, err := c.Fake.Invokes(kcptesting.New{{if not .kind.IsNamespaced}}Root{{end}}GetAction({{.kind.Plural | lowerFirst}}Resource, c.ClusterPath, {{if .kind.IsNamespaced}}c.Namespace, {{end}}name), &{{.group.PackageAlias}}.{{.kind.String}}{}) +func (c *{{.kind.Plural | lowerFirst}}Client) Get(ctx context.Context, name string, options metav1.GetOptions) (*{{.group.GoPackageAlias}}.{{.kind.String}}, error) { + obj, err := c.Fake.Invokes(kcptesting.New{{if not .kind.IsNamespaced}}Root{{end}}GetAction({{.kind.Plural | lowerFirst}}Resource, c.ClusterPath, {{if .kind.IsNamespaced}}c.Namespace, {{end}}name), &{{.group.GoPackageAlias}}.{{.kind.String}}{}) if obj == nil { return nil, err } - return obj.(*{{.group.PackageAlias}}.{{.kind.String}}), err + return obj.(*{{.group.GoPackageAlias}}.{{.kind.String}}), err } {{end -}} {{if "list" | .kind.SupportedVerbs.Has}} // List takes label and field selectors, and returns the list of {{.kind.Plural}} that match those selectors. -func (c *{{.kind.Plural | lowerFirst}}Client) List(ctx context.Context, opts metav1.ListOptions) (*{{.group.PackageAlias}}.{{.kind.String}}List, error) { - obj, err := c.Fake.Invokes(kcptesting.New{{if not .kind.IsNamespaced}}Root{{end}}ListAction({{.kind.Plural | lowerFirst}}Resource, {{.kind.Plural | lowerFirst}}Kind, c.ClusterPath, {{if .kind.IsNamespaced}}c.Namespace, {{end}}opts), &{{.group.PackageAlias}}.{{.kind.String}}List{}) +func (c *{{.kind.Plural | lowerFirst}}Client) List(ctx context.Context, opts metav1.ListOptions) (*{{.group.GoPackageAlias}}.{{.kind.String}}List, error) { + obj, err := c.Fake.Invokes(kcptesting.New{{if not .kind.IsNamespaced}}Root{{end}}ListAction({{.kind.Plural | lowerFirst}}Resource, {{.kind.Plural | lowerFirst}}Kind, c.ClusterPath, {{if .kind.IsNamespaced}}c.Namespace, {{end}}opts), &{{.group.GoPackageAlias}}.{{.kind.String}}List{}) if obj == nil { return nil, err } @@ -308,8 +307,8 @@ func (c *{{.kind.Plural | lowerFirst}}Client) List(ctx context.Context, opts met if label == nil { label = labels.Everything() } - list := &{{.group.PackageAlias}}.{{.kind.String}}List{ListMeta: obj.(*{{.group.PackageAlias}}.{{.kind.String}}List).ListMeta} - for _, item := range obj.(*{{.group.PackageAlias}}.{{.kind.String}}List).Items { + list := &{{.group.GoPackageAlias}}.{{.kind.String}}List{ListMeta: obj.(*{{.group.GoPackageAlias}}.{{.kind.String}}List).ListMeta} + for _, item := range obj.(*{{.group.GoPackageAlias}}.{{.kind.String}}List).Items { if label.Matches(labels.Set(item.Labels)) { list.Items = append(list.Items, item) } @@ -325,17 +324,17 @@ func (c *{{.kind.Plural | lowerFirst}}Client) Watch(ctx context.Context, opts me {{end -}} {{if "patch" | .kind.SupportedVerbs.Has}} -func (c *{{.kind.Plural | lowerFirst}}Client) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (*{{.group.PackageAlias}}.{{.kind.String}}, error) { - obj, err := c.Fake.Invokes(kcptesting.New{{if not .kind.IsNamespaced}}Root{{end}}PatchSubresourceAction({{.kind.Plural | lowerFirst}}Resource, c.ClusterPath, {{if .kind.IsNamespaced}}c.Namespace, {{end}}name, pt, data, subresources...), &{{.group.PackageAlias}}.{{.kind.String}}{}) +func (c *{{.kind.Plural | lowerFirst}}Client) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (*{{.group.GoPackageAlias}}.{{.kind.String}}, error) { + obj, err := c.Fake.Invokes(kcptesting.New{{if not .kind.IsNamespaced}}Root{{end}}PatchSubresourceAction({{.kind.Plural | lowerFirst}}Resource, c.ClusterPath, {{if .kind.IsNamespaced}}c.Namespace, {{end}}name, pt, data, subresources...), &{{.group.GoPackageAlias}}.{{.kind.String}}{}) if obj == nil { return nil, err } - return obj.(*{{.group.PackageAlias}}.{{.kind.String}}), err + return obj.(*{{.group.GoPackageAlias}}.{{.kind.String}}), err } {{end -}} {{if and .generateApplyVerbs ("apply" | .kind.SupportedVerbs.Has) }} -func (c *{{.kind.Plural | lowerFirst}}Client) Apply(ctx context.Context, applyConfiguration *applyconfigurations{{.group.PackageAlias}}.{{.kind.String}}ApplyConfiguration, opts metav1.ApplyOptions) (*{{.group.PackageAlias}}.{{.kind.String}}, error) { +func (c *{{.kind.Plural | lowerFirst}}Client) Apply(ctx context.Context, applyConfiguration *applyconfigurations{{.group.GoPackageAlias}}.{{.kind.String}}ApplyConfiguration, opts metav1.ApplyOptions) (*{{.group.GoPackageAlias}}.{{.kind.String}}, error) { if applyConfiguration == nil { return nil, fmt.Errorf("applyConfiguration provided to Apply must not be nil") } @@ -347,16 +346,16 @@ func (c *{{.kind.Plural | lowerFirst}}Client) Apply(ctx context.Context, applyCo if name == nil { return nil, fmt.Errorf("applyConfiguration.Name must be provided to Apply") } - obj, err := c.Fake.Invokes(kcptesting.New{{if not .kind.IsNamespaced}}Root{{end}}PatchSubresourceAction({{.kind.Plural | lowerFirst}}Resource, c.ClusterPath, {{if .kind.IsNamespaced}}c.Namespace, {{end}}*name, types.ApplyPatchType, data), &{{.group.PackageAlias}}.{{.kind.String}}{}) + obj, err := c.Fake.Invokes(kcptesting.New{{if not .kind.IsNamespaced}}Root{{end}}PatchSubresourceAction({{.kind.Plural | lowerFirst}}Resource, c.ClusterPath, {{if .kind.IsNamespaced}}c.Namespace, {{end}}*name, types.ApplyPatchType, data), &{{.group.GoPackageAlias}}.{{.kind.String}}{}) if obj == nil { return nil, err } - return obj.(*{{.group.PackageAlias}}.{{.kind.String}}), err + return obj.(*{{.group.GoPackageAlias}}.{{.kind.String}}), err } {{end -}} {{if and .generateApplyVerbs ("applyStatus" | .kind.SupportedVerbs.Has) }} -func (c *{{.kind.Plural | lowerFirst}}Client) ApplyStatus(ctx context.Context, applyConfiguration *applyconfigurations{{.group.PackageAlias}}.{{.kind.String}}ApplyConfiguration, opts metav1.ApplyOptions) (*{{.group.PackageAlias}}.{{.kind.String}}, error) { +func (c *{{.kind.Plural | lowerFirst}}Client) ApplyStatus(ctx context.Context, applyConfiguration *applyconfigurations{{.group.GoPackageAlias}}.{{.kind.String}}ApplyConfiguration, opts metav1.ApplyOptions) (*{{.group.GoPackageAlias}}.{{.kind.String}}, error) { if applyConfiguration == nil { return nil, fmt.Errorf("applyConfiguration provided to Apply must not be nil") } @@ -368,17 +367,17 @@ func (c *{{.kind.Plural | lowerFirst}}Client) ApplyStatus(ctx context.Context, a if name == nil { return nil, fmt.Errorf("applyConfiguration.Name must be provided to Apply") } - obj, err := c.Fake.Invokes(kcptesting.New{{if not .kind.IsNamespaced}}Root{{end}}PatchSubresourceAction({{.kind.Plural | lowerFirst}}Resource, c.ClusterPath, {{if .kind.IsNamespaced}}c.Namespace, {{end}}*name, types.ApplyPatchType, data, "status"), &{{.group.PackageAlias}}.{{.kind.String}}{}) + obj, err := c.Fake.Invokes(kcptesting.New{{if not .kind.IsNamespaced}}Root{{end}}PatchSubresourceAction({{.kind.Plural | lowerFirst}}Resource, c.ClusterPath, {{if .kind.IsNamespaced}}c.Namespace, {{end}}*name, types.ApplyPatchType, data, "status"), &{{.group.GoPackageAlias}}.{{.kind.String}}{}) if obj == nil { return nil, err } - return obj.(*{{.group.PackageAlias}}.{{.kind.String}}), err + return obj.(*{{.group.GoPackageAlias}}.{{.kind.String}}), err } {{end -}} {{range .kind.Extensions}} {{if eq .Verb "create"}} -func (c *{{$.kind.Plural | lowerFirst}}Client) {{.Method}}(ctx context.Context, {{$.kind.String | lowerFirst}}Name string, {{if .InputType}}{{.InputType | lowerFirst}} *{{index $.extraImports .InputPath}}.{{.InputType}}{{else}}{{$.kind.String | lowerFirst}} *{{.group.PackageAlias}}.{{$.kind.String}}{{end}}, opts metav1.CreateOptions) (*{{index $.extraImports .ResultPath}}.{{if .ResultType}}{{.ResultType}}{{else}}{{$.kind.String}}{{end}}, error) { +func (c *{{$.kind.Plural | lowerFirst}}Client) {{.Method}}(ctx context.Context, {{$.kind.String | lowerFirst}}Name string, {{if .InputType}}{{.InputType | lowerFirst}} *{{index $.extraImports .InputPath}}.{{.InputType}}{{else}}{{$.kind.String | lowerFirst}} *{{.group.GoPackageAlias}}.{{$.kind.String}}{{end}}, opts metav1.CreateOptions) (*{{index $.extraImports .ResultPath}}.{{if .ResultType}}{{.ResultType}}{{else}}{{$.kind.String}}{{end}}, error) { obj, err := c.Fake.Invokes(kcptesting.New{{if not $.kind.IsNamespaced}}Root{{end}}CreateSubresourceAction({{$.kind.Plural | lowerFirst}}Resource, c.ClusterPath, {{$.kind.String | lowerFirst}}Name, "{{.Subresource}}", {{if $.kind.IsNamespaced}}c.Namespace, {{end}}{{if .InputType}}{{.InputType | lowerFirst}}{{else}}{{$.kind.String | lowerFirst}}{{end}}), &{{index $.extraImports .ResultPath}}.{{if .ResultType}}{{.ResultType}}{{else}}{{$.kind.String}}{{end}}{}) if obj == nil { return nil, err @@ -440,7 +439,7 @@ func (c *{{$.kind.Plural | lowerFirst}}Client) {{.Method}}(ctx context.Context, {{end -}} {{if and $.generateApplyVerbs (eq .Verb "apply") }} -func (c *{{$.kind.Plural | lowerFirst}}Client) {{.Method}}(ctx context.Context, {{$.kind.String | lowerFirst}}Name string, applyConfiguration {{if .InputType}}*{{index $.extraImports .InputPath}}.{{.InputType}}{{else}}*applyconfigurations{{$.group.PackageAlias}}.{{$.kind.String}}ApplyConfiguration,{{end}}, opts metav1.ApplyOptions) (*{{index $.extraImports .ResultPath}}.{{if .ResultType}}{{.ResultType}}{{else}}{{$.kind.String}}{{end}}, error) { +func (c *{{$.kind.Plural | lowerFirst}}Client) {{.Method}}(ctx context.Context, {{$.kind.String | lowerFirst}}Name string, applyConfiguration {{if .InputType}}*{{index $.extraImports .InputPath}}.{{.InputType}}{{else}}*applyconfigurations{{$.group.GoPackageAlias}}.{{$.kind.String}}ApplyConfiguration,{{end}}, opts metav1.ApplyOptions) (*{{index $.extraImports .ResultPath}}.{{if .ResultType}}{{.ResultType}}{{else}}{{$.kind.String}}{{end}}, error) { if applyConfiguration == nil { return nil, fmt.Errorf("applyConfiguration provided to Apply must not be nil") } diff --git a/pkg/internal/clientgen/group.go b/pkg/internal/clientgen/group.go index 9421c1733..89dfa91ba 100644 --- a/pkg/internal/clientgen/group.go +++ b/pkg/internal/clientgen/group.go @@ -5,15 +5,13 @@ import ( "strings" "text/template" - "k8s.io/code-generator/cmd/client-gen/types" - "github.com/kcp-dev/code-generator/v2/pkg/parser" "github.com/kcp-dev/code-generator/v2/pkg/util" ) type Group struct { // Group is the group in this client. - Group types.GroupVersionInfo + Group parser.Group // Kinds are the kinds in the group. Kinds []parser.Kind @@ -57,7 +55,7 @@ import ( "k8s.io/client-go/rest" - {{.group.PackageAlias}} "{{.singleClusterClientPackagePath}}/typed/{{.group.Group.PackageName}}/{{.group.Version.PackageName}}" + {{.group.GoPackageAlias}} "{{.singleClusterClientPackagePath}}/typed/{{.group.PackageName}}/{{.group.Version.PackageName}}" ) type {{.group.GroupGoName}}{{.group.Version}}ClusterInterface interface { @@ -67,14 +65,14 @@ type {{.group.GroupGoName}}{{.group.Version}}ClusterInterface interface { } type {{.group.GroupGoName}}{{.group.Version}}ClusterScoper interface { - Cluster(logicalcluster.Path) {{.group.PackageAlias}}.{{.group.GroupGoName}}{{.group.Version}}Interface + Cluster(logicalcluster.Path) {{.group.GoPackageAlias}}.{{.group.GroupGoName}}{{.group.Version}}Interface } type {{.group.GroupGoName}}{{.group.Version}}ClusterClient struct { - clientCache kcpclient.Cache[*{{.group.PackageAlias}}.{{.group.GroupGoName}}{{.group.Version}}Client] + clientCache kcpclient.Cache[*{{.group.GoPackageAlias}}.{{.group.GroupGoName}}{{.group.Version}}Client] } -func (c *{{.group.GroupGoName}}{{.group.Version}}ClusterClient) Cluster(clusterPath logicalcluster.Path) {{.group.PackageAlias}}.{{.group.GroupGoName}}{{.group.Version}}Interface { +func (c *{{.group.GroupGoName}}{{.group.Version}}ClusterClient) Cluster(clusterPath logicalcluster.Path) {{.group.GoPackageAlias}}.{{.group.GroupGoName}}{{.group.Version}}Interface { if clusterPath == logicalcluster.Wildcard { panic("A specific cluster must be provided when scoping, not the wildcard.") } @@ -101,8 +99,8 @@ func NewForConfig(c *rest.Config) (*{{.group.GroupGoName}}{{.group.Version}}Clus // NewForConfigAndClient creates a new {{.group.GroupGoName}}{{.group.Version}}ClusterClient 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) (*{{.group.GroupGoName}}{{.group.Version}}ClusterClient, error) { - cache := kcpclient.NewCache(c, h, &kcpclient.Constructor[*{{.group.PackageAlias}}.{{.group.GroupGoName}}{{.group.Version}}Client]{ - NewForConfigAndClient: {{.group.PackageAlias}}.NewForConfigAndClient, + cache := kcpclient.NewCache(c, h, &kcpclient.Constructor[*{{.group.GoPackageAlias}}.{{.group.GroupGoName}}{{.group.Version}}Client]{ + NewForConfigAndClient: {{.group.GoPackageAlias}}.NewForConfigAndClient, }) if _, err := cache.Cluster(logicalcluster.Name("root").Path()); err != nil { return nil, err diff --git a/pkg/internal/clientgen/scheme.go b/pkg/internal/clientgen/scheme.go index 6b5524e35..305e98cdd 100644 --- a/pkg/internal/clientgen/scheme.go +++ b/pkg/internal/clientgen/scheme.go @@ -5,14 +5,13 @@ import ( "strings" "text/template" - "k8s.io/code-generator/cmd/client-gen/types" - + "github.com/kcp-dev/code-generator/v2/pkg/parser" "github.com/kcp-dev/code-generator/v2/pkg/util" ) type Scheme struct { // Groups are the groups in this client-set. - Groups []types.GroupVersionInfo + Groups []parser.Group // APIPackagePath is the root directory under which API types exist. // e.g. "k8s.io/api" @@ -51,7 +50,7 @@ import ( "k8s.io/apimachinery/pkg/runtime/serializer" utilruntime "k8s.io/apimachinery/pkg/util/runtime" -{{range .groups}} {{.PackageAlias}} "{{$.apiPackagePath}}/{{.Group.PackageName}}/{{.Version.PackageName}}" +{{range .groups}} {{.GoPackageAlias}} "{{$.apiPackagePath}}/{{.PackageName}}/{{.Version.PackageName}}" {{end -}} ) @@ -59,7 +58,7 @@ var Scheme = runtime.NewScheme() var Codecs = serializer.NewCodecFactory(Scheme) var ParameterCodec = runtime.NewParameterCodec(Scheme) var localSchemeBuilder = runtime.SchemeBuilder{ -{{range .groups}} {{.PackageAlias}}.AddToScheme, +{{range .groups}} {{.GoPackageAlias}}.AddToScheme, {{end -}} } diff --git a/pkg/internal/clientgen/type.go b/pkg/internal/clientgen/type.go index bb5a95e33..a633c46c2 100644 --- a/pkg/internal/clientgen/type.go +++ b/pkg/internal/clientgen/type.go @@ -5,15 +5,13 @@ import ( "strings" "text/template" - "k8s.io/code-generator/cmd/client-gen/types" - "github.com/kcp-dev/code-generator/v2/pkg/parser" "github.com/kcp-dev/code-generator/v2/pkg/util" ) type TypedClient struct { // Group is the group in this client. - Group types.GroupVersionInfo + Group parser.Group // Kind is the kinds in this file. Kind parser.Kind @@ -62,10 +60,10 @@ import ( "context" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/watch" - {{.group.PackageAlias}} "{{.apiPackagePath}}/{{.group.Group.PackageName}}/{{.group.Version.PackageName}}" + {{.group.GoPackageAlias}} "{{.apiPackagePath}}/{{.group.PackageName}}/{{.group.Version.PackageName}}" {{end}} - {{.group.PackageAlias}}client "{{.singleClusterClientPackagePath}}/typed/{{.group.Group.PackageName}}/{{.group.Version.PackageName}}" + {{.group.GoPackageAlias}}client "{{.singleClusterClientPackagePath}}/typed/{{.group.PackageName}}/{{.group.Version.PackageName}}" ) // {{.kind.Plural}}ClusterGetter has a method to return a {{.kind.String}}ClusterInterface. @@ -76,24 +74,24 @@ type {{.kind.Plural}}ClusterGetter interface { {{ if .kind.SupportsListWatch -}} // {{.kind.String}}ClusterInterface can operate on {{.kind.Plural}} across all clusters, -// or scope down to one cluster and return a {{if .kind.IsNamespaced}}{{.kind.Plural}}Namespacer{{else}}{{.group.PackageAlias}}client.{{.kind.String}}Interface{{end}}. +// or scope down to one cluster and return a {{if .kind.IsNamespaced}}{{.kind.Plural}}Namespacer{{else}}{{.group.GoPackageAlias}}client.{{.kind.String}}Interface{{end}}. {{ else -}} -// {{.kind.String}}ClusterInterface can scope down to one cluster and return a {{if .kind.IsNamespaced}}{{.kind.Plural}}Namespacer{{else}}{{.group.PackageAlias}}client.{{.kind.String}}Interface{{end}}. +// {{.kind.String}}ClusterInterface can scope down to one cluster and return a {{if .kind.IsNamespaced}}{{.kind.Plural}}Namespacer{{else}}{{.group.GoPackageAlias}}client.{{.kind.String}}Interface{{end}}. {{ end -}} type {{.kind.String}}ClusterInterface interface { - Cluster(logicalcluster.Path) {{if .kind.IsNamespaced}}{{.kind.Plural}}Namespacer{{else}}{{.group.PackageAlias}}client.{{.kind.String}}Interface{{end}} + Cluster(logicalcluster.Path) {{if .kind.IsNamespaced}}{{.kind.Plural}}Namespacer{{else}}{{.group.GoPackageAlias}}client.{{.kind.String}}Interface{{end}} {{- if .kind.SupportsListWatch }} - List(ctx context.Context, opts metav1.ListOptions) (*{{.group.PackageAlias}}.{{.kind.String}}List, error) + List(ctx context.Context, opts metav1.ListOptions) (*{{.group.GoPackageAlias}}.{{.kind.String}}List, error) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) {{ end -}} } type {{.kind.Plural | lowerFirst}}ClusterInterface struct { - clientCache kcpclient.Cache[*{{.group.PackageAlias}}client.{{.group.GroupGoName}}{{.group.Version}}Client] + clientCache kcpclient.Cache[*{{.group.GoPackageAlias}}client.{{.group.GroupGoName}}{{.group.Version}}Client] } // Cluster scopes the client down to a particular cluster. -func (c *{{.kind.Plural | lowerFirst}}ClusterInterface) Cluster(clusterPath logicalcluster.Path) {{if .kind.IsNamespaced}}{{.kind.Plural}}Namespacer{{else}}{{.group.PackageAlias}}client.{{.kind.String}}Interface{{end}} { +func (c *{{.kind.Plural | lowerFirst}}ClusterInterface) Cluster(clusterPath logicalcluster.Path) {{if .kind.IsNamespaced}}{{.kind.Plural}}Namespacer{{else}}{{.group.GoPackageAlias}}client.{{.kind.String}}Interface{{end}} { if clusterPath == logicalcluster.Wildcard { panic("A specific cluster must be provided when scoping, not the wildcard.") } @@ -106,7 +104,7 @@ func (c *{{.kind.Plural | lowerFirst}}ClusterInterface) Cluster(clusterPath logi {{ if .kind.SupportsListWatch }} // List returns the entire collection of all {{.kind.Plural}} across all clusters. -func (c *{{.kind.Plural | lowerFirst}}ClusterInterface) List(ctx context.Context, opts metav1.ListOptions) (*{{.group.PackageAlias}}.{{.kind.String}}List, error) { +func (c *{{.kind.Plural | lowerFirst}}ClusterInterface) List(ctx context.Context, opts metav1.ListOptions) (*{{.group.GoPackageAlias}}.{{.kind.String}}List, error) { return c.clientCache.ClusterOrDie(logicalcluster.Wildcard).{{.kind.Plural}}({{if .kind.IsNamespaced }}metav1.NamespaceAll{{end}}).List(ctx, opts) } @@ -117,17 +115,17 @@ func (c *{{.kind.Plural | lowerFirst}}ClusterInterface) Watch(ctx context.Contex {{ end -}} {{ if .kind.IsNamespaced -}} -// {{.kind.Plural}}Namespacer can scope to objects within a namespace, returning a {{.group.PackageAlias}}client.{{.kind.String}}Interface. +// {{.kind.Plural}}Namespacer can scope to objects within a namespace, returning a {{.group.GoPackageAlias}}client.{{.kind.String}}Interface. type {{.kind.Plural}}Namespacer interface { - Namespace(string) {{.group.PackageAlias}}client.{{.kind.String}}Interface + Namespace(string) {{.group.GoPackageAlias}}client.{{.kind.String}}Interface } type {{.kind.Plural | lowerFirst}}Namespacer struct { - clientCache kcpclient.Cache[*{{.group.PackageAlias}}client.{{.group.GroupGoName}}{{.group.Version}}Client] + clientCache kcpclient.Cache[*{{.group.GoPackageAlias}}client.{{.group.GroupGoName}}{{.group.Version}}Client] clusterPath logicalcluster.Path } -func (n *{{.kind.Plural | lowerFirst}}Namespacer) Namespace(namespace string) {{.group.PackageAlias}}client.{{.kind.String}}Interface { +func (n *{{.kind.Plural | lowerFirst}}Namespacer) Namespace(namespace string) {{.group.GoPackageAlias}}client.{{.kind.String}}Interface { return n.clientCache.ClusterOrDie(n.clusterPath).{{.kind.Plural}}(namespace) } {{ end -}} diff --git a/pkg/internal/informergen/factory.go b/pkg/internal/informergen/factory.go index 9563eeaa9..c125a378f 100644 --- a/pkg/internal/informergen/factory.go +++ b/pkg/internal/informergen/factory.go @@ -92,7 +92,7 @@ import ( upstreaminformers "{{.singleClusterInformerPackagePath}}" {{end -}} -{{range .groups}} {{.Group.PackageName}}informers "{{$.packagePath}}/{{.Group.PackageName}}" +{{range .groups}} {{.PackageName}}informers "{{$.packagePath}}/{{.PackageName}}" {{end -}} "{{.packagePath}}/internalinterfaces" @@ -329,13 +329,13 @@ type SharedInformerFactory interface { // InformerFor returns the SharedIndexInformer for obj. InformerFor(obj runtime.Object, newFunc internalinterfaces.NewInformerFunc) kcpcache.ScopeableSharedIndexInformer -{{range .groups}} {{.GoName}}() {{.Group.PackageName}}informers.ClusterInterface +{{range .groups}} {{.GroupGoName}}() {{.PackageName}}informers.ClusterInterface {{end -}} } {{range .groups}} -func (f *sharedInformerFactory) {{.GoName}}() {{.Group.PackageName}}informers.ClusterInterface { - return {{.Group.PackageName}}informers.New(f, f.tweakListOptions) +func (f *sharedInformerFactory) {{.GroupGoName}}() {{.PackageName}}informers.ClusterInterface { + return {{.PackageName}}informers.New(f, f.tweakListOptions) } {{end}} @@ -485,14 +485,14 @@ type SharedScopedInformerFactory interface { ForResource(resource schema.GroupVersionResource) (GenericInformer, error) WaitForCacheSync(stopCh <-chan struct{}) map[reflect.Type]bool -{{range .groups}} {{.GoName}}() {{.Group.PackageName}}informers.Interface +{{range .groups}} {{.GroupGoName}}() {{.PackageName}}informers.Interface {{end -}} } {{range .groups}} -func (f *sharedScopedInformerFactory) {{.GoName}}() {{.Group.PackageName}}informers.Interface { - return {{.Group.PackageName}}informers.NewScoped(f, f.namespace, f.tweakListOptions) +func (f *sharedScopedInformerFactory) {{.GroupGoName}}() {{.PackageName}}informers.Interface { + return {{.PackageName}}informers.NewScoped(f, f.namespace, f.tweakListOptions) } {{end}} {{end}} diff --git a/pkg/internal/informergen/generic.go b/pkg/internal/informergen/generic.go index 18ce9b072..3a863838d 100644 --- a/pkg/internal/informergen/generic.go +++ b/pkg/internal/informergen/generic.go @@ -27,10 +27,10 @@ import ( type Generic struct { // Groups are the groups in this informer factory. - Groups []types.GroupVersionInfo + Groups []parser.Group // GroupVersionKinds are all the kinds we need to support,indexed by group and version. - GroupVersionKinds map[types.Group]map[types.Version][]parser.Kind + GroupVersionKinds map[types.Group]map[parser.Version][]parser.Kind // APIPackagePath is the root directory under which API types exist. // e.g. "k8s.io/api" @@ -78,7 +78,7 @@ import ( upstreaminformers "{{.singleClusterInformerPackagePath}}" {{end -}} -{{range .groups}} {{.PackageAlias}} "{{$.apiPackagePath}}/{{.Group.PackageName}}/{{.Version.PackageName}}" +{{range .groups}} {{.GoPackageAlias}} "{{$.apiPackagePath}}/{{.PackageName}}/{{.Version.PackageName}}" {{end -}} ) @@ -138,7 +138,7 @@ func (f *genericInformer) Lister() cache.GenericLister { func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource) (GenericClusterInformer, error) { switch resource { {{range $group := .groups}} // Group={{.Group.NonEmpty}}, Version={{.Version}} -{{range $kind := index (index $.groupVersionKinds .Group) .Version}} case {{$group.PackageAlias}}.SchemeGroupVersion.WithResource("{{$kind.Plural|toLower}}"): +{{range $kind := index (index $.groupVersionKinds .Group) .Version}} case {{$group.GoPackageAlias}}.SchemeGroupVersion.WithResource("{{$kind.Plural|toLower}}"): return &genericClusterInformer{resource: resource.GroupResource(), informer: f.{{$group.GroupGoName}}().{{$group.Version}}().{{$kind.Plural}}().Informer()}, nil {{end -}} {{end -}} @@ -153,7 +153,7 @@ func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource func (f *sharedScopedInformerFactory) ForResource(resource schema.GroupVersionResource) ({{if .useUpstreamInterfaces}}upstreaminformers.{{end}}GenericInformer, error) { switch resource { {{range $group := .groups}} // Group={{.Group.NonEmpty}}, Version={{.Version}} -{{range $kind := index (index $.groupVersionKinds .Group) .Version}} case {{$group.PackageAlias}}.SchemeGroupVersion.WithResource("{{$kind.Plural|toLower}}"): +{{range $kind := index (index $.groupVersionKinds .Group) .Version}} case {{$group.GoPackageAlias}}.SchemeGroupVersion.WithResource("{{$kind.Plural|toLower}}"): informer := f.{{$group.GroupGoName}}().{{$group.Version}}().{{$kind.Plural}}().Informer() return &genericInformer{lister: cache.NewGenericLister(informer.GetIndexer(), resource.GroupResource()), informer: informer}, nil {{end -}} diff --git a/pkg/internal/informergen/groupinterface.go b/pkg/internal/informergen/groupinterface.go index 9848d4336..b2f1d156e 100644 --- a/pkg/internal/informergen/groupinterface.go +++ b/pkg/internal/informergen/groupinterface.go @@ -18,10 +18,9 @@ package informergen import ( "io" + "strings" "text/template" - "k8s.io/code-generator/cmd/client-gen/types" - "github.com/kcp-dev/code-generator/v2/pkg/parser" ) @@ -30,7 +29,7 @@ type GroupInterface struct { Group parser.Group // Versions are the versions of this group for which we're generating interfaces - Versions []types.Version + Versions []parser.Version // PackagePath is the package under which these informers will be exposed. // e.g. "github.com/kcp-dev/client-go/clients/informers" @@ -49,6 +48,7 @@ func (g GroupInterface) WriteContent(w io.Writer) error { m := map[string]interface{}{ "group": g.Group, + "packageName": strings.ReplaceAll(g.Group.PackageName(), "-", ""), "packagePath": g.PackagePath, "versions": g.Versions, "useUpstreamInterfaces": g.UseUpstreamInterfaces, @@ -62,10 +62,10 @@ var groupInterface = ` // Code generated by kcp code-generator. DO NOT EDIT. -package {{.group.Group.PackageName}} +package {{.packageName}} import ( -{{range .versions}} "{{$.packagePath}}/{{$.group.Group.PackageName}}/{{.PackageName}}" +{{range .versions}} "{{$.packagePath}}/{{$.group.PackageName}}/{{.PackageName}}" {{end -}} "{{.packagePath}}/internalinterfaces" diff --git a/pkg/internal/informergen/informer.go b/pkg/internal/informergen/informer.go index 91b2b35f8..8405a0744 100644 --- a/pkg/internal/informergen/informer.go +++ b/pkg/internal/informergen/informer.go @@ -20,14 +20,12 @@ import ( "io" "text/template" - "k8s.io/code-generator/cmd/client-gen/types" - "github.com/kcp-dev/code-generator/v2/pkg/parser" ) type Informer struct { // Group is the group in this informer. - Group types.GroupVersionInfo + Group parser.Group // Kind is the kind in this file. Kind parser.Kind @@ -105,11 +103,11 @@ import ( kcpinformers "github.com/kcp-dev/apimachinery/v2/third_party/informers" "github.com/kcp-dev/logicalcluster/v3" - {{.group.PackageAlias}} "{{.apiPackagePath}}/{{.group.Group.PackageName}}/{{.group.Version.PackageName}}" - {{.group.PackageAlias}}listers "{{.listerPackagePath}}/{{.group.Group.PackageName}}/{{.group.Version.PackageName}}" + {{.group.GoPackageAlias}} "{{.apiPackagePath}}/{{.group.PackageName}}/{{.group.Version.PackageName}}" + {{.group.GoPackageAlias}}listers "{{.listerPackagePath}}/{{.group.PackageName}}/{{.group.Version.PackageName}}" {{if .useUpstreamInterfaces -}} - upstream{{.group.PackageAlias}}listers "{{.singleClusterListerPackagePath}}/{{.group.Group.PackageName}}/{{.group.Version.PackageName}}" - upstream{{.group.PackageAlias}}informers "{{.singleClusterInformerPackagePath}}/{{.group.Group.PackageName}}/{{.group.Version.PackageName}}" + upstream{{.group.GoPackageAlias}}listers "{{.singleClusterListerPackagePath}}/{{.group.PackageName}}/{{.group.Version.PackageName}}" + upstream{{.group.GoPackageAlias}}informers "{{.singleClusterInformerPackagePath}}/{{.group.PackageName}}/{{.group.Version.PackageName}}" {{end -}} clientset "{{.clientsetPackagePath}}" @@ -123,9 +121,9 @@ import ( // {{.kind}}ClusterInformer provides access to a shared informer and lister for // {{.kind.Plural}}. type {{.kind}}ClusterInformer interface { - Cluster(logicalcluster.Name) {{if .useUpstreamInterfaces}}upstream{{.group.PackageAlias}}informers.{{end}}{{.kind}}Informer + Cluster(logicalcluster.Name) {{if .useUpstreamInterfaces}}upstream{{.group.GoPackageAlias}}informers.{{end}}{{.kind}}Informer Informer() kcpcache.ScopeableSharedIndexInformer - Lister() {{.group.PackageAlias}}listers.{{.kind}}ClusterLister + Lister() {{.group.GoPackageAlias}}listers.{{.kind}}ClusterLister } type {{.kind.String | lowerFirst}}ClusterInformer struct { @@ -159,7 +157,7 @@ func NewFiltered{{.kind}}ClusterInformer(client clientset.ClusterInterface, resy return client.{{.group.GroupGoName}}{{.group.Version}}().{{.kind.Plural}}().Watch(context.TODO(), options) }, }, - &{{.group.PackageAlias}}.{{.kind.String}}{}, + &{{.group.GoPackageAlias}}.{{.kind.String}}{}, resyncPeriod, indexers, ) @@ -175,11 +173,11 @@ func (f *{{.kind.String|lowerFirst}}ClusterInformer) defaultInformer(client clie } func (f *{{.kind.String|lowerFirst}}ClusterInformer) Informer() kcpcache.ScopeableSharedIndexInformer { - return f.factory.InformerFor(&{{.group.PackageAlias}}.{{.kind}}{}, f.defaultInformer) + return f.factory.InformerFor(&{{.group.GoPackageAlias}}.{{.kind}}{}, f.defaultInformer) } -func (f *{{.kind.String|lowerFirst}}ClusterInformer) Lister() {{.group.PackageAlias}}listers.{{.kind.String}}ClusterLister { - return {{.group.PackageAlias}}listers.New{{.kind}}ClusterLister(f.Informer().GetIndexer()) +func (f *{{.kind.String|lowerFirst}}ClusterInformer) Lister() {{.group.GoPackageAlias}}listers.{{.kind.String}}ClusterLister { + return {{.group.GoPackageAlias}}listers.New{{.kind}}ClusterLister(f.Informer().GetIndexer()) } {{ if not .useUpstreamInterfaces }} @@ -187,11 +185,11 @@ func (f *{{.kind.String|lowerFirst}}ClusterInformer) Lister() {{.group.PackageAl // {{.kind.Plural}}. type {{.kind}}Informer interface { Informer() cache.SharedIndexInformer - Lister() {{.group.PackageAlias}}listers.{{.kind}}Lister + Lister() {{.group.GoPackageAlias}}listers.{{.kind}}Lister } {{end -}} -func (f *{{.kind.String|lowerFirst}}ClusterInformer) Cluster(clusterName logicalcluster.Name) {{if .useUpstreamInterfaces}}upstream{{.group.PackageAlias}}informers.{{end}}{{.kind}}Informer { +func (f *{{.kind.String|lowerFirst}}ClusterInformer) Cluster(clusterName logicalcluster.Name) {{if .useUpstreamInterfaces}}upstream{{.group.GoPackageAlias}}informers.{{end}}{{.kind}}Informer { return &{{.kind.String|lowerFirst}}Informer{ informer: f.Informer().Cluster(clusterName), lister: f.Lister().Cluster(clusterName), @@ -200,14 +198,14 @@ func (f *{{.kind.String|lowerFirst}}ClusterInformer) Cluster(clusterName logical type {{.kind.String|lowerFirst}}Informer struct { informer cache.SharedIndexInformer - lister {{if .useUpstreamInterfaces}}upstream{{end}}{{.group.PackageAlias}}listers.{{.kind.String}}Lister + lister {{if .useUpstreamInterfaces}}upstream{{end}}{{.group.GoPackageAlias}}listers.{{.kind.String}}Lister } func (f *{{.kind.String|lowerFirst}}Informer) Informer() cache.SharedIndexInformer { return f.informer } -func (f *{{.kind.String|lowerFirst}}Informer) Lister() {{if .useUpstreamInterfaces}}upstream{{end}}{{.group.PackageAlias}}listers.{{.kind.String}}Lister { +func (f *{{.kind.String|lowerFirst}}Informer) Lister() {{if .useUpstreamInterfaces}}upstream{{end}}{{.group.GoPackageAlias}}listers.{{.kind.String}}Lister { return f.lister } @@ -219,11 +217,11 @@ type {{.kind.String | lowerFirst}}ScopedInformer struct { } func (f *{{.kind.String|lowerFirst}}ScopedInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&{{.group.PackageAlias}}.{{.kind}}{}, f.defaultInformer) + return f.factory.InformerFor(&{{.group.GoPackageAlias}}.{{.kind}}{}, f.defaultInformer) } -func (f *{{.kind.String|lowerFirst}}ScopedInformer) Lister() {{.group.PackageAlias}}listers.{{.kind.String}}Lister { - return {{.group.PackageAlias}}listers.New{{.kind}}Lister(f.Informer().GetIndexer()) +func (f *{{.kind.String|lowerFirst}}ScopedInformer) Lister() {{.group.GoPackageAlias}}listers.{{.kind.String}}Lister { + return {{.group.GoPackageAlias}}listers.New{{.kind}}Lister(f.Informer().GetIndexer()) } // New{{.kind}}Informer constructs a new informer for {{.kind.String}} type. @@ -252,7 +250,7 @@ func NewFiltered{{.kind}}Informer(client scopedclientset.Interface, resyncPeriod return client.{{.group.GroupGoName}}{{.group.Version}}().{{.kind.Plural}}({{if .kind.IsNamespaced}}namespace{{end -}}).Watch(context.TODO(), options) }, }, - &{{.group.PackageAlias}}.{{.kind.String}}{}, + &{{.group.GoPackageAlias}}.{{.kind.String}}{}, resyncPeriod, indexers, ) diff --git a/pkg/internal/informergen/versioninterface.go b/pkg/internal/informergen/versioninterface.go index fb20d35ac..41905a2bf 100644 --- a/pkg/internal/informergen/versioninterface.go +++ b/pkg/internal/informergen/versioninterface.go @@ -18,6 +18,7 @@ package informergen import ( "io" + "strings" "text/template" "k8s.io/code-generator/cmd/client-gen/types" @@ -51,6 +52,7 @@ func (v *VersionInterface) WriteContent(w io.Writer) error { "version": v.Version, "kinds": v.Kinds, "packagePath": v.PackagePath, + "packageName": strings.ReplaceAll(v.Version.PackageName(), "-", ""), "useUpstreamInterfaces": v.UseUpstreamInterfaces, } return templ.Execute(w, m) @@ -62,7 +64,7 @@ var versionInterfaceTemplate = ` // Code generated by kcp code-generator. DO NOT EDIT. -package {{.version.PackageName}} +package {{.packageName}} import ( "{{.packagePath}}/internalinterfaces" diff --git a/pkg/internal/listergen/expansions.go b/pkg/internal/listergen/expansions.go index 13edd29ab..5c4f3089c 100644 --- a/pkg/internal/listergen/expansions.go +++ b/pkg/internal/listergen/expansions.go @@ -4,8 +4,6 @@ import ( "io" "text/template" - clientgentypes "k8s.io/code-generator/cmd/client-gen/types" - "github.com/kcp-dev/code-generator/v2/pkg/parser" ) @@ -13,7 +11,7 @@ type Expansions struct { // Group is: // - the name of the API group, e.g. "authorization", // - the version and package path of the API, e.g. "v1" and "k8s.io/api/rbac/v1" - Group clientgentypes.GroupVersionInfo + Group parser.Group // Kind is the kind for which we are generating listers, e.g. "ClusterRole" Kind parser.Kind diff --git a/pkg/internal/listergen/lister.go b/pkg/internal/listergen/lister.go index 48ff2416c..662c53e92 100644 --- a/pkg/internal/listergen/lister.go +++ b/pkg/internal/listergen/lister.go @@ -4,8 +4,6 @@ import ( "io" "text/template" - clientgentypes "k8s.io/code-generator/cmd/client-gen/types" - "github.com/kcp-dev/code-generator/v2/pkg/parser" ) @@ -13,7 +11,7 @@ type Lister struct { // Group is: // - the name of the API group, e.g. "authorization", // - the version and package path of the API, e.g. "v1" and "k8s.io/api/rbac/v1" - Group clientgentypes.GroupVersionInfo + Group parser.Group // Kind is the kind for which we are generating listers, e.g. "ClusterRole" Kind parser.Kind @@ -58,9 +56,9 @@ import ( "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/api/errors" - {{.group.PackageAlias}} "{{.apiPackagePath}}/{{.group.Group.PackageName}}/{{.group.Version.PackageName}}" + {{.group.GoPackageAlias}} "{{.apiPackagePath}}/{{.group.PackageName}}/{{.group.Version.PackageName}}" {{if .useUpstreamInterfaces -}} - {{.group.PackageAlias}}listers "{{.singleClusterListerPackagePath}}/{{.group.Group.PackageName}}/{{.group.Version.PackageName}}" + {{.group.GoPackageAlias}}listers "{{.singleClusterListerPackagePath}}/{{.group.PackageName}}/{{.group.Version.PackageName}}" {{end -}} ) @@ -69,12 +67,12 @@ import ( type {{.kind.String}}ClusterLister interface { // List lists all {{.kind.Plural}} in the indexer. // Objects returned here must be treated as read-only. - List(selector labels.Selector) (ret []*{{.group.PackageAlias}}.{{.kind.String}}, err error) + List(selector labels.Selector) (ret []*{{.group.GoPackageAlias}}.{{.kind.String}}, err error) // Cluster returns a lister that can list and get {{.kind.Plural}} in one workspace. {{if not .useUpstreamInterfaces -}} Cluster(clusterName logicalcluster.Name) {{.kind.String}}Lister {{else -}} - Cluster(clusterName logicalcluster.Name){{.group.PackageAlias}}listers.{{.kind.String}}Lister + Cluster(clusterName logicalcluster.Name){{.group.GoPackageAlias}}listers.{{.kind.String}}Lister {{end -}} {{.kind.String}}ClusterListerExpansion } @@ -96,9 +94,9 @@ func New{{.kind.String}}ClusterLister(indexer cache.Indexer) *{{.kind.String | l } // List lists all {{.kind.Plural}} in the indexer across all workspaces. -func (s *{{.kind.String | lowerFirst}}ClusterLister) List(selector labels.Selector) (ret []*{{.group.PackageAlias}}.{{.kind.String}}, err error) { +func (s *{{.kind.String | lowerFirst}}ClusterLister) List(selector labels.Selector) (ret []*{{.group.GoPackageAlias}}.{{.kind.String}}, err error) { err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*{{.group.PackageAlias}}.{{.kind.String}})) + ret = append(ret, m.(*{{.group.GoPackageAlias}}.{{.kind.String}})) }) return ret, err } @@ -107,7 +105,7 @@ func (s *{{.kind.String | lowerFirst}}ClusterLister) List(selector labels.Select {{if not .useUpstreamInterfaces -}} func (s *{{.kind.String | lowerFirst}}ClusterLister) Cluster(clusterName logicalcluster.Name) {{.kind.String}}Lister { {{else -}} -func (s *{{.kind.String | lowerFirst}}ClusterLister) Cluster(clusterName logicalcluster.Name){{.group.PackageAlias}}listers.{{.kind.String}}Lister { +func (s *{{.kind.String | lowerFirst}}ClusterLister) Cluster(clusterName logicalcluster.Name){{.group.GoPackageAlias}}listers.{{.kind.String}}Lister { {{end -}} return &{{.kind.String | lowerFirst}}Lister{indexer: s.indexer, clusterName: clusterName} } @@ -122,11 +120,11 @@ func (s *{{.kind.String | lowerFirst}}ClusterLister) Cluster(clusterName logical type {{.kind.String}}Lister interface { // List lists all {{.kind.Plural}} in the workspace. // Objects returned here must be treated as read-only. - List(selector labels.Selector) (ret []*{{.group.PackageAlias}}.{{.kind.String}}, err error) + List(selector labels.Selector) (ret []*{{.group.GoPackageAlias}}.{{.kind.String}}, err error) {{ if not .kind.IsNamespaced -}} // Get retrieves the {{.kind.String}} from the indexer for a given workspace and name. // Objects returned here must be treated as read-only. - Get(name string) (*{{.group.PackageAlias}}.{{.kind.String}}, error) + Get(name string) (*{{.group.GoPackageAlias}}.{{.kind.String}}, error) {{else -}} // {{.kind.Plural}} returns a lister that can list and get {{.kind.Plural}} in one workspace and namespace. {{.kind.Plural}}(namespace string) {{.kind.String}}NamespaceLister @@ -138,7 +136,7 @@ type {{.kind.String}}Lister interface { {{if not .useUpstreamInterfaces -}} // {{.kind.String | lowerFirst}}Lister can list all {{.kind.Plural}} inside a workspace{{ if .kind.IsNamespaced }} or scope down to a {{.kind.String}}Lister for one namespace{{end}}. {{else -}} -// {{.kind.String | lowerFirst}}Lister implements the {{.group.PackageAlias}}listers.{{.kind.String}}Lister interface. +// {{.kind.String | lowerFirst}}Lister implements the {{.group.GoPackageAlias}}listers.{{.kind.String}}Lister interface. {{end -}} type {{.kind.String | lowerFirst}}Lister struct { indexer cache.Indexer @@ -146,32 +144,32 @@ type {{.kind.String | lowerFirst}}Lister struct { } // List lists all {{.kind.Plural}} in the indexer for a workspace. -func (s *{{.kind.String | lowerFirst}}Lister) List(selector labels.Selector) (ret []*{{.group.PackageAlias}}.{{.kind.String}}, err error) { +func (s *{{.kind.String | lowerFirst}}Lister) List(selector labels.Selector) (ret []*{{.group.GoPackageAlias}}.{{.kind.String}}, err error) { err = kcpcache.ListAllByCluster(s.indexer, s.clusterName, selector, func(i interface{}) { - ret = append(ret, i.(*{{.group.PackageAlias}}.{{.kind.String}})) + ret = append(ret, i.(*{{.group.GoPackageAlias}}.{{.kind.String}})) }) return ret, err } {{ if not .kind.IsNamespaced -}} // Get retrieves the {{.kind.String}} from the indexer for a given workspace and name. -func (s *{{.kind.String | lowerFirst}}Lister) Get(name string) (*{{.group.PackageAlias}}.{{.kind.String}}, error) { +func (s *{{.kind.String | lowerFirst}}Lister) Get(name string) (*{{.group.GoPackageAlias}}.{{.kind.String}}, 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({{.group.PackageAlias}}.Resource("{{.kind.Plural | toLower}}"), name) + return nil, errors.NewNotFound({{.group.GoPackageAlias}}.Resource("{{.kind.Plural | toLower}}"), name) } - return obj.(*{{.group.PackageAlias}}.{{.kind.String}}), nil + return obj.(*{{.group.GoPackageAlias}}.{{.kind.String}}), nil } {{ else -}} // {{.kind.Plural}} returns an object that can list and get {{.kind.Plural}} in one namespace. {{if not .useUpstreamInterfaces -}} func (s *{{.kind.String | lowerFirst}}Lister) {{.kind.Plural}}(namespace string) {{.kind.String}}NamespaceLister { {{else -}} -func (s *{{.kind.String | lowerFirst}}Lister) {{.kind.Plural}}(namespace string) {{.group.PackageAlias}}listers.{{.kind.String}}NamespaceLister { +func (s *{{.kind.String | lowerFirst}}Lister) {{.kind.Plural}}(namespace string) {{.group.GoPackageAlias}}listers.{{.kind.String}}NamespaceLister { {{end -}} return &{{.kind.String | lowerFirst}}NamespaceLister{indexer: s.indexer, clusterName: s.clusterName, namespace: namespace} } @@ -182,10 +180,10 @@ func (s *{{.kind.String | lowerFirst}}Lister) {{.kind.Plural}}(namespace string) type {{.kind.String}}NamespaceLister interface { // List lists all {{.kind.Plural}} in the workspace and namespace. // Objects returned here must be treated as read-only. - List(selector labels.Selector) (ret []*{{.group.PackageAlias}}.{{.kind.String}}, err error) + List(selector labels.Selector) (ret []*{{.group.GoPackageAlias}}.{{.kind.String}}, err error) // Get retrieves the {{.kind.String}} from the indexer for a given workspace, namespace and name. // Objects returned here must be treated as read-only. - Get(name string) (*{{.group.PackageAlias}}.{{.kind.String}}, error) + Get(name string) (*{{.group.GoPackageAlias}}.{{.kind.String}}, error) {{.kind.String}}NamespaceListerExpansion } {{end -}} @@ -195,7 +193,7 @@ type {{.kind.String}}NamespaceLister interface { // All objects returned here must be treated as read-only. {{ end -}} {{ if .useUpstreamInterfaces -}} -// {{.kind.String | lowerFirst}}NamespaceLister implements the {{.group.PackageAlias}}listers.{{.kind.String}}NamespaceLister interface. +// {{.kind.String | lowerFirst}}NamespaceLister implements the {{.group.GoPackageAlias}}listers.{{.kind.String}}NamespaceLister interface. {{ end -}} type {{.kind.String | lowerFirst}}NamespaceLister struct { indexer cache.Indexer @@ -204,24 +202,24 @@ type {{.kind.String | lowerFirst}}NamespaceLister struct { } // List lists all {{.kind.Plural}} in the indexer for a given workspace and namespace. -func (s *{{.kind.String | lowerFirst}}NamespaceLister) List(selector labels.Selector) (ret []*{{.group.PackageAlias}}.{{.kind.String}}, err error) { +func (s *{{.kind.String | lowerFirst}}NamespaceLister) List(selector labels.Selector) (ret []*{{.group.GoPackageAlias}}.{{.kind.String}}, err error) { err = kcpcache.ListAllByClusterAndNamespace(s.indexer, s.clusterName, s.namespace, selector, func(i interface{}) { - ret = append(ret, i.(*{{.group.PackageAlias}}.{{.kind.String}})) + ret = append(ret, i.(*{{.group.GoPackageAlias}}.{{.kind.String}})) }) return ret, err } // Get retrieves the {{.kind.String}} from the indexer for a given workspace, namespace and name. -func (s *{{.kind.String | lowerFirst}}NamespaceLister) Get(name string) (*{{.group.PackageAlias}}.{{.kind.String}}, error) { +func (s *{{.kind.String | lowerFirst}}NamespaceLister) Get(name string) (*{{.group.GoPackageAlias}}.{{.kind.String}}, 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({{.group.PackageAlias}}.Resource("{{.kind.Plural | toLower}}"), name) + return nil, errors.NewNotFound({{.group.GoPackageAlias}}.Resource("{{.kind.Plural | toLower}}"), name) } - return obj.(*{{.group.PackageAlias}}.{{.kind.String}}), nil + return obj.(*{{.group.GoPackageAlias}}.{{.kind.String}}), nil } {{ end -}} @@ -243,25 +241,25 @@ type {{.kind.String | lowerFirst}}ScopedLister struct { } // List lists all {{.kind.Plural}} in the indexer for a workspace. -func (s *{{.kind.String | lowerFirst}}ScopedLister) List(selector labels.Selector) (ret []*{{.group.PackageAlias}}.{{.kind.String}}, err error) { +func (s *{{.kind.String | lowerFirst}}ScopedLister) List(selector labels.Selector) (ret []*{{.group.GoPackageAlias}}.{{.kind.String}}, err error) { err = cache.ListAll(s.indexer, selector, func(i interface{}) { - ret = append(ret, i.(*{{.group.PackageAlias}}.{{.kind.String}})) + ret = append(ret, i.(*{{.group.GoPackageAlias}}.{{.kind.String}})) }) return ret, err } {{ if not .kind.IsNamespaced -}} // Get retrieves the {{.kind.String}} from the indexer for a given workspace and name. -func (s *{{.kind.String | lowerFirst}}ScopedLister) Get(name string) (*{{.group.PackageAlias}}.{{.kind.String}}, error) { +func (s *{{.kind.String | lowerFirst}}ScopedLister) Get(name string) (*{{.group.GoPackageAlias}}.{{.kind.String}}, error) { key := name obj, exists, err := s.indexer.GetByKey(key) if err != nil { return nil, err } if !exists { - return nil, errors.NewNotFound({{.group.PackageAlias}}.Resource("{{.kind.Plural | toLower}}"), name) + return nil, errors.NewNotFound({{.group.GoPackageAlias}}.Resource("{{.kind.Plural | toLower}}"), name) } - return obj.(*{{.group.PackageAlias}}.{{.kind.String}}), nil + return obj.(*{{.group.GoPackageAlias}}.{{.kind.String}}), nil } {{ else -}} // {{.kind.Plural}} returns an object that can list and get {{.kind.Plural}} in one namespace. @@ -276,24 +274,24 @@ type {{.kind.String | lowerFirst}}ScopedNamespaceLister struct { } // List lists all {{.kind.Plural}} in the indexer for a given workspace and namespace. -func (s *{{.kind.String | lowerFirst}}ScopedNamespaceLister) List(selector labels.Selector) (ret []*{{.group.PackageAlias}}.{{.kind.String}}, err error) { +func (s *{{.kind.String | lowerFirst}}ScopedNamespaceLister) List(selector labels.Selector) (ret []*{{.group.GoPackageAlias}}.{{.kind.String}}, err error) { err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(i interface{}) { - ret = append(ret, i.(*{{.group.PackageAlias}}.{{.kind.String}})) + ret = append(ret, i.(*{{.group.GoPackageAlias}}.{{.kind.String}})) }) return ret, err } // Get retrieves the {{.kind.String}} from the indexer for a given workspace, namespace and name. -func (s *{{.kind.String | lowerFirst}}ScopedNamespaceLister) Get(name string) (*{{.group.PackageAlias}}.{{.kind.String}}, error) { +func (s *{{.kind.String | lowerFirst}}ScopedNamespaceLister) Get(name string) (*{{.group.GoPackageAlias}}.{{.kind.String}}, error) { key := s.namespace + "/" + name obj, exists, err := s.indexer.GetByKey(key) if err != nil { return nil, err } if !exists { - return nil, errors.NewNotFound({{.group.PackageAlias}}.Resource("{{.kind.Plural | toLower}}"), name) + return nil, errors.NewNotFound({{.group.GoPackageAlias}}.Resource("{{.kind.Plural | toLower}}"), name) } - return obj.(*{{.group.PackageAlias}}.{{.kind.String}}), nil + return obj.(*{{.group.GoPackageAlias}}.{{.kind.String}}), nil } {{ end -}} {{end -}} diff --git a/pkg/parser/types.go b/pkg/parser/types.go index 00fbd86e5..845e78fcf 100644 --- a/pkg/parser/types.go +++ b/pkg/parser/types.go @@ -17,6 +17,11 @@ limitations under the License. package parser import ( + "strings" + + "golang.org/x/text/cases" + "golang.org/x/text/language" + "k8s.io/apimachinery/pkg/util/sets" "k8s.io/code-generator/cmd/client-gen/types" @@ -34,7 +39,41 @@ type Kind struct { type Group struct { types.Group - GoName string + GoName string `marker:",+groupGoName"` + Version Version + PackageAlias string + LowerCaseGroupGoName string +} + +func (g Group) GoPackageAlias() string { + if g.PackageAlias == "" { + panic("PackageAlias is empty. Programmer error.") + } + return strings.ReplaceAll(g.PackageAlias, "-", "") +} + +func (g Group) GroupGoName() string { + if g.GoName == "" { + panic("GroupGoName is empty. Programmer error.") + } + caser := cases.Title(language.English) + parts := strings.Split(g.GoName, "-") + for i, part := range parts { + parts[i] = caser.String(part) + } + return strings.Join(parts, "") +} + +func (g Group) GroupGoNameLower() string { + if g.LowerCaseGroupGoName == "" { + panic("LowerCaseGroupGoName is empty. Programmer error.") + } + result := strings.ToLower(g.LowerCaseGroupGoName) + return strings.ReplaceAll(result, "-", "") +} + +func (g Group) PackageName() string { + return strings.ToLower(strings.ReplaceAll(g.Group.PackageName(), "-", "")) } func (k *Kind) Plural() string { @@ -53,6 +92,24 @@ func (k *Kind) SupportsListWatch() bool { return k.SupportedVerbs.HasAll("list", "watch") } +type Version string + +func (v Version) String() string { + return string(v) +} + +func (v Version) NonEmpty() string { + if v == "" { + return "internalVersion" + } + return v.String() +} + +func (v Version) PackageName() string { + _v := strings.ReplaceAll(v.NonEmpty(), "-", "") + return strings.ToLower(_v) +} + // TODO(skuznets): // add an e2e for a kind that has no verbs, but uses an extension for something // then ensure we add in fake_type.go entries for the extension