From ab4a55f635cb79db13354aa42b7b37b33575f199 Mon Sep 17 00:00:00 2001 From: Kevin Klues Date: Thu, 9 Jan 2025 14:24:56 +0000 Subject: [PATCH] Add generated MultiNodeEnvironment CRD, client, and deepcopy Signed-off-by: Kevin Klues --- .../gpu/v1alpha1/zz_generated.deepcopy.go | 73 +++++++ .../gpu.nvidia.com_multinodeenvironments.yaml | 53 ++++++ .../resource/clientset/versioned/clientset.go | 120 ++++++++++++ .../versioned/fake/clientset_generated.go | 85 +++++++++ .../resource/clientset/versioned/fake/doc.go | 20 ++ .../clientset/versioned/fake/register.go | 56 ++++++ .../clientset/versioned/scheme/doc.go | 20 ++ .../clientset/versioned/scheme/register.go | 56 ++++++ .../versioned/typed/gpu/v1alpha1/doc.go | 20 ++ .../versioned/typed/gpu/v1alpha1/fake/doc.go | 20 ++ .../gpu/v1alpha1/fake/fake_gpu_client.go | 40 ++++ .../fake/fake_multinodeenvironment.go | 129 +++++++++++++ .../typed/gpu/v1alpha1/generated_expansion.go | 21 ++ .../typed/gpu/v1alpha1/gpu_client.go | 107 +++++++++++ .../gpu/v1alpha1/multinodeenvironment.go | 178 +++++++++++++++++ .../client-go/discovery/fake/discovery.go | 180 ++++++++++++++++++ vendor/modules.txt | 1 + 17 files changed, 1179 insertions(+) create mode 100644 deployments/helm/k8s-dra-driver/crds/gpu.nvidia.com_multinodeenvironments.yaml create mode 100644 pkg/nvidia.com/resource/clientset/versioned/clientset.go create mode 100644 pkg/nvidia.com/resource/clientset/versioned/fake/clientset_generated.go create mode 100644 pkg/nvidia.com/resource/clientset/versioned/fake/doc.go create mode 100644 pkg/nvidia.com/resource/clientset/versioned/fake/register.go create mode 100644 pkg/nvidia.com/resource/clientset/versioned/scheme/doc.go create mode 100644 pkg/nvidia.com/resource/clientset/versioned/scheme/register.go create mode 100644 pkg/nvidia.com/resource/clientset/versioned/typed/gpu/v1alpha1/doc.go create mode 100644 pkg/nvidia.com/resource/clientset/versioned/typed/gpu/v1alpha1/fake/doc.go create mode 100644 pkg/nvidia.com/resource/clientset/versioned/typed/gpu/v1alpha1/fake/fake_gpu_client.go create mode 100644 pkg/nvidia.com/resource/clientset/versioned/typed/gpu/v1alpha1/fake/fake_multinodeenvironment.go create mode 100644 pkg/nvidia.com/resource/clientset/versioned/typed/gpu/v1alpha1/generated_expansion.go create mode 100644 pkg/nvidia.com/resource/clientset/versioned/typed/gpu/v1alpha1/gpu_client.go create mode 100644 pkg/nvidia.com/resource/clientset/versioned/typed/gpu/v1alpha1/multinodeenvironment.go create mode 100644 vendor/k8s.io/client-go/discovery/fake/discovery.go diff --git a/api/nvidia.com/resource/gpu/v1alpha1/zz_generated.deepcopy.go b/api/nvidia.com/resource/gpu/v1alpha1/zz_generated.deepcopy.go index 86a9f407..4252a5d5 100644 --- a/api/nvidia.com/resource/gpu/v1alpha1/zz_generated.deepcopy.go +++ b/api/nvidia.com/resource/gpu/v1alpha1/zz_generated.deepcopy.go @@ -204,6 +204,79 @@ func (in MpsPerDevicePinnedMemoryLimit) DeepCopy() MpsPerDevicePinnedMemoryLimit return *out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *MultiNodeEnvironment) DeepCopyInto(out *MultiNodeEnvironment) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + out.Spec = in.Spec +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MultiNodeEnvironment. +func (in *MultiNodeEnvironment) DeepCopy() *MultiNodeEnvironment { + if in == nil { + return nil + } + out := new(MultiNodeEnvironment) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *MultiNodeEnvironment) 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 *MultiNodeEnvironmentList) DeepCopyInto(out *MultiNodeEnvironmentList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]MultiNodeEnvironment, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MultiNodeEnvironmentList. +func (in *MultiNodeEnvironmentList) DeepCopy() *MultiNodeEnvironmentList { + if in == nil { + return nil + } + out := new(MultiNodeEnvironmentList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *MultiNodeEnvironmentList) 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 *MultiNodeEnvironmentSpec) DeepCopyInto(out *MultiNodeEnvironmentSpec) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MultiNodeEnvironmentSpec. +func (in *MultiNodeEnvironmentSpec) DeepCopy() *MultiNodeEnvironmentSpec { + if in == nil { + return nil + } + out := new(MultiNodeEnvironmentSpec) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *TimeSlicingConfig) DeepCopyInto(out *TimeSlicingConfig) { *out = *in diff --git a/deployments/helm/k8s-dra-driver/crds/gpu.nvidia.com_multinodeenvironments.yaml b/deployments/helm/k8s-dra-driver/crds/gpu.nvidia.com_multinodeenvironments.yaml new file mode 100644 index 00000000..cb4fac04 --- /dev/null +++ b/deployments/helm/k8s-dra-driver/crds/gpu.nvidia.com_multinodeenvironments.yaml @@ -0,0 +1,53 @@ +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: v0.14.0 + name: multinodeenvironments.gpu.nvidia.com +spec: + group: gpu.nvidia.com + names: + kind: MultiNodeEnvironment + listKind: MultiNodeEnvironmentList + plural: multinodeenvironments + singular: multinodeenvironment + scope: Namespaced + versions: + - name: v1alpha1 + schema: + openAPIV3Schema: + description: MultiNodeEnvironment prepares a set of nodes to run a multi-node + workload in. + properties: + apiVersion: + description: |- + APIVersion defines the versioned schema of this representation of an object. + Servers should convert recognized schemas to the latest internal value, and + may reject unrecognized values. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources + type: string + kind: + description: |- + Kind is a string value representing the REST resource this object represents. + Servers may infer this from the endpoint the client submits requests to. + Cannot be updated. + In CamelCase. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds + type: string + metadata: + type: object + spec: + description: MultiNodeEnvironmentSpec provides the spec for a MultiNodeEnvironment. + properties: + numNodes: + type: integer + resourceClaimName: + type: string + required: + - numNodes + - resourceClaimName + type: object + type: object + served: true + storage: true diff --git a/pkg/nvidia.com/resource/clientset/versioned/clientset.go b/pkg/nvidia.com/resource/clientset/versioned/clientset.go new file mode 100644 index 00000000..72812cf7 --- /dev/null +++ b/pkg/nvidia.com/resource/clientset/versioned/clientset.go @@ -0,0 +1,120 @@ +/* + * Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// Code generated by client-gen. DO NOT EDIT. + +package versioned + +import ( + "fmt" + "net/http" + + gpuv1alpha1 "github.com/NVIDIA/k8s-dra-driver/pkg/nvidia.com/resource/clientset/versioned/typed/gpu/v1alpha1" + discovery "k8s.io/client-go/discovery" + rest "k8s.io/client-go/rest" + flowcontrol "k8s.io/client-go/util/flowcontrol" +) + +type Interface interface { + Discovery() discovery.DiscoveryInterface + GpuV1alpha1() gpuv1alpha1.GpuV1alpha1Interface +} + +// Clientset contains the clients for groups. +type Clientset struct { + *discovery.DiscoveryClient + gpuV1alpha1 *gpuv1alpha1.GpuV1alpha1Client +} + +// GpuV1alpha1 retrieves the GpuV1alpha1Client +func (c *Clientset) GpuV1alpha1() gpuv1alpha1.GpuV1alpha1Interface { + return c.gpuV1alpha1 +} + +// Discovery retrieves the DiscoveryClient +func (c *Clientset) Discovery() discovery.DiscoveryInterface { + if c == nil { + return nil + } + return c.DiscoveryClient +} + +// NewForConfig creates a new Clientset for the given config. +// If config's RateLimiter is not set and QPS and Burst are acceptable, +// NewForConfig will generate a rate-limiter in configShallowCopy. +// NewForConfig is equivalent to NewForConfigAndClient(c, httpClient), +// where httpClient was generated with rest.HTTPClientFor(c). +func NewForConfig(c *rest.Config) (*Clientset, error) { + configShallowCopy := *c + + if configShallowCopy.UserAgent == "" { + configShallowCopy.UserAgent = rest.DefaultKubernetesUserAgent() + } + + // share the transport between all clients + httpClient, err := rest.HTTPClientFor(&configShallowCopy) + if err != nil { + return nil, err + } + + return NewForConfigAndClient(&configShallowCopy, httpClient) +} + +// NewForConfigAndClient creates a new Clientset for the given config and http client. +// Note the http client provided takes precedence over the configured transport values. +// If config's RateLimiter is not set and QPS and Burst are acceptable, +// NewForConfigAndClient will generate a rate-limiter in configShallowCopy. +func NewForConfigAndClient(c *rest.Config, httpClient *http.Client) (*Clientset, error) { + configShallowCopy := *c + if configShallowCopy.RateLimiter == nil && configShallowCopy.QPS > 0 { + if configShallowCopy.Burst <= 0 { + return nil, fmt.Errorf("burst is required to be greater than 0 when RateLimiter is not set and QPS is set to greater than 0") + } + configShallowCopy.RateLimiter = flowcontrol.NewTokenBucketRateLimiter(configShallowCopy.QPS, configShallowCopy.Burst) + } + + var cs Clientset + var err error + cs.gpuV1alpha1, err = gpuv1alpha1.NewForConfigAndClient(&configShallowCopy, httpClient) + if err != nil { + return nil, err + } + + cs.DiscoveryClient, err = discovery.NewDiscoveryClientForConfigAndClient(&configShallowCopy, httpClient) + if err != nil { + return nil, err + } + return &cs, nil +} + +// NewForConfigOrDie creates a new Clientset for the given config and +// panics if there is an error in the config. +func NewForConfigOrDie(c *rest.Config) *Clientset { + cs, err := NewForConfig(c) + if err != nil { + panic(err) + } + return cs +} + +// New creates a new Clientset for the given RESTClient. +func New(c rest.Interface) *Clientset { + var cs Clientset + cs.gpuV1alpha1 = gpuv1alpha1.New(c) + + cs.DiscoveryClient = discovery.NewDiscoveryClient(c) + return &cs +} diff --git a/pkg/nvidia.com/resource/clientset/versioned/fake/clientset_generated.go b/pkg/nvidia.com/resource/clientset/versioned/fake/clientset_generated.go new file mode 100644 index 00000000..243b479a --- /dev/null +++ b/pkg/nvidia.com/resource/clientset/versioned/fake/clientset_generated.go @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// Code generated by client-gen. DO NOT EDIT. + +package fake + +import ( + clientset "github.com/NVIDIA/k8s-dra-driver/pkg/nvidia.com/resource/clientset/versioned" + gpuv1alpha1 "github.com/NVIDIA/k8s-dra-driver/pkg/nvidia.com/resource/clientset/versioned/typed/gpu/v1alpha1" + fakegpuv1alpha1 "github.com/NVIDIA/k8s-dra-driver/pkg/nvidia.com/resource/clientset/versioned/typed/gpu/v1alpha1/fake" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/watch" + "k8s.io/client-go/discovery" + fakediscovery "k8s.io/client-go/discovery/fake" + "k8s.io/client-go/testing" +) + +// NewSimpleClientset returns a clientset that will respond with the provided objects. +// It's backed by a very simple object tracker that processes creates, updates and deletions as-is, +// without applying any validations and/or defaults. It shouldn't be considered a replacement +// for a real clientset and is mostly useful in simple unit tests. +func NewSimpleClientset(objects ...runtime.Object) *Clientset { + o := testing.NewObjectTracker(scheme, codecs.UniversalDecoder()) + for _, obj := range objects { + if err := o.Add(obj); err != nil { + panic(err) + } + } + + cs := &Clientset{tracker: o} + cs.discovery = &fakediscovery.FakeDiscovery{Fake: &cs.Fake} + cs.AddReactor("*", "*", testing.ObjectReaction(o)) + cs.AddWatchReactor("*", func(action testing.Action) (handled bool, ret watch.Interface, err error) { + gvr := action.GetResource() + ns := action.GetNamespace() + watch, err := o.Watch(gvr, ns) + if err != nil { + return false, nil, err + } + return true, watch, nil + }) + + return cs +} + +// Clientset implements clientset.Interface. Meant to be embedded into a +// struct to get a default implementation. This makes faking out just the method +// you want to test easier. +type Clientset struct { + testing.Fake + discovery *fakediscovery.FakeDiscovery + tracker testing.ObjectTracker +} + +func (c *Clientset) Discovery() discovery.DiscoveryInterface { + return c.discovery +} + +func (c *Clientset) Tracker() testing.ObjectTracker { + return c.tracker +} + +var ( + _ clientset.Interface = &Clientset{} + _ testing.FakeClient = &Clientset{} +) + +// GpuV1alpha1 retrieves the GpuV1alpha1Client +func (c *Clientset) GpuV1alpha1() gpuv1alpha1.GpuV1alpha1Interface { + return &fakegpuv1alpha1.FakeGpuV1alpha1{Fake: &c.Fake} +} diff --git a/pkg/nvidia.com/resource/clientset/versioned/fake/doc.go b/pkg/nvidia.com/resource/clientset/versioned/fake/doc.go new file mode 100644 index 00000000..ffec4dc3 --- /dev/null +++ b/pkg/nvidia.com/resource/clientset/versioned/fake/doc.go @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// Code generated by client-gen. DO NOT EDIT. + +// This package has the automatically generated fake clientset. +package fake diff --git a/pkg/nvidia.com/resource/clientset/versioned/fake/register.go b/pkg/nvidia.com/resource/clientset/versioned/fake/register.go new file mode 100644 index 00000000..d6a9dd52 --- /dev/null +++ b/pkg/nvidia.com/resource/clientset/versioned/fake/register.go @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// Code generated by client-gen. DO NOT EDIT. + +package fake + +import ( + gpuv1alpha1 "github.com/NVIDIA/k8s-dra-driver/api/nvidia.com/resource/gpu/v1alpha1" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + schema "k8s.io/apimachinery/pkg/runtime/schema" + serializer "k8s.io/apimachinery/pkg/runtime/serializer" + utilruntime "k8s.io/apimachinery/pkg/util/runtime" +) + +var scheme = runtime.NewScheme() +var codecs = serializer.NewCodecFactory(scheme) + +var localSchemeBuilder = runtime.SchemeBuilder{ + gpuv1alpha1.AddToScheme, +} + +// AddToScheme adds all types of this clientset into the given scheme. This allows composition +// of clientsets, like in: +// +// import ( +// "k8s.io/client-go/kubernetes" +// clientsetscheme "k8s.io/client-go/kubernetes/scheme" +// aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme" +// ) +// +// kclientset, _ := kubernetes.NewForConfig(c) +// _ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme) +// +// After this, RawExtensions in Kubernetes types will serialize kube-aggregator types +// correctly. +var AddToScheme = localSchemeBuilder.AddToScheme + +func init() { + v1.AddToGroupVersion(scheme, schema.GroupVersion{Version: "v1"}) + utilruntime.Must(AddToScheme(scheme)) +} diff --git a/pkg/nvidia.com/resource/clientset/versioned/scheme/doc.go b/pkg/nvidia.com/resource/clientset/versioned/scheme/doc.go new file mode 100644 index 00000000..caf9e125 --- /dev/null +++ b/pkg/nvidia.com/resource/clientset/versioned/scheme/doc.go @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// Code generated by client-gen. DO NOT EDIT. + +// This package contains the scheme of the automatically generated clientset. +package scheme diff --git a/pkg/nvidia.com/resource/clientset/versioned/scheme/register.go b/pkg/nvidia.com/resource/clientset/versioned/scheme/register.go new file mode 100644 index 00000000..49250359 --- /dev/null +++ b/pkg/nvidia.com/resource/clientset/versioned/scheme/register.go @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// Code generated by client-gen. DO NOT EDIT. + +package scheme + +import ( + gpuv1alpha1 "github.com/NVIDIA/k8s-dra-driver/api/nvidia.com/resource/gpu/v1alpha1" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + schema "k8s.io/apimachinery/pkg/runtime/schema" + serializer "k8s.io/apimachinery/pkg/runtime/serializer" + utilruntime "k8s.io/apimachinery/pkg/util/runtime" +) + +var Scheme = runtime.NewScheme() +var Codecs = serializer.NewCodecFactory(Scheme) +var ParameterCodec = runtime.NewParameterCodec(Scheme) +var localSchemeBuilder = runtime.SchemeBuilder{ + gpuv1alpha1.AddToScheme, +} + +// AddToScheme adds all types of this clientset into the given scheme. This allows composition +// of clientsets, like in: +// +// import ( +// "k8s.io/client-go/kubernetes" +// clientsetscheme "k8s.io/client-go/kubernetes/scheme" +// aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme" +// ) +// +// kclientset, _ := kubernetes.NewForConfig(c) +// _ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme) +// +// After this, RawExtensions in Kubernetes types will serialize kube-aggregator types +// correctly. +var AddToScheme = localSchemeBuilder.AddToScheme + +func init() { + v1.AddToGroupVersion(Scheme, schema.GroupVersion{Version: "v1"}) + utilruntime.Must(AddToScheme(Scheme)) +} diff --git a/pkg/nvidia.com/resource/clientset/versioned/typed/gpu/v1alpha1/doc.go b/pkg/nvidia.com/resource/clientset/versioned/typed/gpu/v1alpha1/doc.go new file mode 100644 index 00000000..6cf78ff5 --- /dev/null +++ b/pkg/nvidia.com/resource/clientset/versioned/typed/gpu/v1alpha1/doc.go @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// Code generated by client-gen. DO NOT EDIT. + +// This package has the automatically generated typed clients. +package v1alpha1 diff --git a/pkg/nvidia.com/resource/clientset/versioned/typed/gpu/v1alpha1/fake/doc.go b/pkg/nvidia.com/resource/clientset/versioned/typed/gpu/v1alpha1/fake/doc.go new file mode 100644 index 00000000..48029921 --- /dev/null +++ b/pkg/nvidia.com/resource/clientset/versioned/typed/gpu/v1alpha1/fake/doc.go @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// Code generated by client-gen. DO NOT EDIT. + +// Package fake has the automatically generated clients. +package fake diff --git a/pkg/nvidia.com/resource/clientset/versioned/typed/gpu/v1alpha1/fake/fake_gpu_client.go b/pkg/nvidia.com/resource/clientset/versioned/typed/gpu/v1alpha1/fake/fake_gpu_client.go new file mode 100644 index 00000000..dd746390 --- /dev/null +++ b/pkg/nvidia.com/resource/clientset/versioned/typed/gpu/v1alpha1/fake/fake_gpu_client.go @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// Code generated by client-gen. DO NOT EDIT. + +package fake + +import ( + v1alpha1 "github.com/NVIDIA/k8s-dra-driver/pkg/nvidia.com/resource/clientset/versioned/typed/gpu/v1alpha1" + rest "k8s.io/client-go/rest" + testing "k8s.io/client-go/testing" +) + +type FakeGpuV1alpha1 struct { + *testing.Fake +} + +func (c *FakeGpuV1alpha1) MultiNodeEnvironments(namespace string) v1alpha1.MultiNodeEnvironmentInterface { + return &FakeMultiNodeEnvironments{c, namespace} +} + +// RESTClient returns a RESTClient that is used to communicate +// with API server by this client implementation. +func (c *FakeGpuV1alpha1) RESTClient() rest.Interface { + var ret *rest.RESTClient + return ret +} diff --git a/pkg/nvidia.com/resource/clientset/versioned/typed/gpu/v1alpha1/fake/fake_multinodeenvironment.go b/pkg/nvidia.com/resource/clientset/versioned/typed/gpu/v1alpha1/fake/fake_multinodeenvironment.go new file mode 100644 index 00000000..f4c2b62a --- /dev/null +++ b/pkg/nvidia.com/resource/clientset/versioned/typed/gpu/v1alpha1/fake/fake_multinodeenvironment.go @@ -0,0 +1,129 @@ +/* + * Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// Code generated by client-gen. DO NOT EDIT. + +package fake + +import ( + "context" + + v1alpha1 "github.com/NVIDIA/k8s-dra-driver/api/nvidia.com/resource/gpu/v1alpha1" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + labels "k8s.io/apimachinery/pkg/labels" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + testing "k8s.io/client-go/testing" +) + +// FakeMultiNodeEnvironments implements MultiNodeEnvironmentInterface +type FakeMultiNodeEnvironments struct { + Fake *FakeGpuV1alpha1 + ns string +} + +var multinodeenvironmentsResource = v1alpha1.SchemeGroupVersion.WithResource("multinodeenvironments") + +var multinodeenvironmentsKind = v1alpha1.SchemeGroupVersion.WithKind("MultiNodeEnvironment") + +// Get takes name of the multiNodeEnvironment, and returns the corresponding multiNodeEnvironment object, and an error if there is any. +func (c *FakeMultiNodeEnvironments) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha1.MultiNodeEnvironment, err error) { + obj, err := c.Fake. + Invokes(testing.NewGetAction(multinodeenvironmentsResource, c.ns, name), &v1alpha1.MultiNodeEnvironment{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.MultiNodeEnvironment), err +} + +// List takes label and field selectors, and returns the list of MultiNodeEnvironments that match those selectors. +func (c *FakeMultiNodeEnvironments) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha1.MultiNodeEnvironmentList, err error) { + obj, err := c.Fake. + Invokes(testing.NewListAction(multinodeenvironmentsResource, multinodeenvironmentsKind, c.ns, opts), &v1alpha1.MultiNodeEnvironmentList{}) + + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &v1alpha1.MultiNodeEnvironmentList{ListMeta: obj.(*v1alpha1.MultiNodeEnvironmentList).ListMeta} + for _, item := range obj.(*v1alpha1.MultiNodeEnvironmentList).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 multiNodeEnvironments. +func (c *FakeMultiNodeEnvironments) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { + return c.Fake. + InvokesWatch(testing.NewWatchAction(multinodeenvironmentsResource, c.ns, opts)) + +} + +// Create takes the representation of a multiNodeEnvironment and creates it. Returns the server's representation of the multiNodeEnvironment, and an error, if there is any. +func (c *FakeMultiNodeEnvironments) Create(ctx context.Context, multiNodeEnvironment *v1alpha1.MultiNodeEnvironment, opts v1.CreateOptions) (result *v1alpha1.MultiNodeEnvironment, err error) { + obj, err := c.Fake. + Invokes(testing.NewCreateAction(multinodeenvironmentsResource, c.ns, multiNodeEnvironment), &v1alpha1.MultiNodeEnvironment{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.MultiNodeEnvironment), err +} + +// Update takes the representation of a multiNodeEnvironment and updates it. Returns the server's representation of the multiNodeEnvironment, and an error, if there is any. +func (c *FakeMultiNodeEnvironments) Update(ctx context.Context, multiNodeEnvironment *v1alpha1.MultiNodeEnvironment, opts v1.UpdateOptions) (result *v1alpha1.MultiNodeEnvironment, err error) { + obj, err := c.Fake. + Invokes(testing.NewUpdateAction(multinodeenvironmentsResource, c.ns, multiNodeEnvironment), &v1alpha1.MultiNodeEnvironment{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.MultiNodeEnvironment), err +} + +// Delete takes name of the multiNodeEnvironment and deletes it. Returns an error if one occurs. +func (c *FakeMultiNodeEnvironments) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { + _, err := c.Fake. + Invokes(testing.NewDeleteActionWithOptions(multinodeenvironmentsResource, c.ns, name, opts), &v1alpha1.MultiNodeEnvironment{}) + + return err +} + +// DeleteCollection deletes a collection of objects. +func (c *FakeMultiNodeEnvironments) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { + action := testing.NewDeleteCollectionAction(multinodeenvironmentsResource, c.ns, listOpts) + + _, err := c.Fake.Invokes(action, &v1alpha1.MultiNodeEnvironmentList{}) + return err +} + +// Patch applies the patch and returns the patched multiNodeEnvironment. +func (c *FakeMultiNodeEnvironments) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.MultiNodeEnvironment, err error) { + obj, err := c.Fake. + Invokes(testing.NewPatchSubresourceAction(multinodeenvironmentsResource, c.ns, name, pt, data, subresources...), &v1alpha1.MultiNodeEnvironment{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.MultiNodeEnvironment), err +} diff --git a/pkg/nvidia.com/resource/clientset/versioned/typed/gpu/v1alpha1/generated_expansion.go b/pkg/nvidia.com/resource/clientset/versioned/typed/gpu/v1alpha1/generated_expansion.go new file mode 100644 index 00000000..f6e75cd5 --- /dev/null +++ b/pkg/nvidia.com/resource/clientset/versioned/typed/gpu/v1alpha1/generated_expansion.go @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// Code generated by client-gen. DO NOT EDIT. + +package v1alpha1 + +type MultiNodeEnvironmentExpansion interface{} diff --git a/pkg/nvidia.com/resource/clientset/versioned/typed/gpu/v1alpha1/gpu_client.go b/pkg/nvidia.com/resource/clientset/versioned/typed/gpu/v1alpha1/gpu_client.go new file mode 100644 index 00000000..fa5ebec9 --- /dev/null +++ b/pkg/nvidia.com/resource/clientset/versioned/typed/gpu/v1alpha1/gpu_client.go @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// Code generated by client-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + "net/http" + + v1alpha1 "github.com/NVIDIA/k8s-dra-driver/api/nvidia.com/resource/gpu/v1alpha1" + "github.com/NVIDIA/k8s-dra-driver/pkg/nvidia.com/resource/clientset/versioned/scheme" + rest "k8s.io/client-go/rest" +) + +type GpuV1alpha1Interface interface { + RESTClient() rest.Interface + MultiNodeEnvironmentsGetter +} + +// GpuV1alpha1Client is used to interact with features provided by the gpu.nvidia.com group. +type GpuV1alpha1Client struct { + restClient rest.Interface +} + +func (c *GpuV1alpha1Client) MultiNodeEnvironments(namespace string) MultiNodeEnvironmentInterface { + return newMultiNodeEnvironments(c, namespace) +} + +// NewForConfig creates a new GpuV1alpha1Client for the given config. +// NewForConfig is equivalent to NewForConfigAndClient(c, httpClient), +// where httpClient was generated with rest.HTTPClientFor(c). +func NewForConfig(c *rest.Config) (*GpuV1alpha1Client, 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 GpuV1alpha1Client 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) (*GpuV1alpha1Client, 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 &GpuV1alpha1Client{client}, nil +} + +// NewForConfigOrDie creates a new GpuV1alpha1Client for the given config and +// panics if there is an error in the config. +func NewForConfigOrDie(c *rest.Config) *GpuV1alpha1Client { + client, err := NewForConfig(c) + if err != nil { + panic(err) + } + return client +} + +// New creates a new GpuV1alpha1Client for the given RESTClient. +func New(c rest.Interface) *GpuV1alpha1Client { + return &GpuV1alpha1Client{c} +} + +func setConfigDefaults(config *rest.Config) error { + gv := v1alpha1.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 *GpuV1alpha1Client) RESTClient() rest.Interface { + if c == nil { + return nil + } + return c.restClient +} diff --git a/pkg/nvidia.com/resource/clientset/versioned/typed/gpu/v1alpha1/multinodeenvironment.go b/pkg/nvidia.com/resource/clientset/versioned/typed/gpu/v1alpha1/multinodeenvironment.go new file mode 100644 index 00000000..112cc335 --- /dev/null +++ b/pkg/nvidia.com/resource/clientset/versioned/typed/gpu/v1alpha1/multinodeenvironment.go @@ -0,0 +1,178 @@ +/* + * Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// Code generated by client-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + "context" + "time" + + v1alpha1 "github.com/NVIDIA/k8s-dra-driver/api/nvidia.com/resource/gpu/v1alpha1" + scheme "github.com/NVIDIA/k8s-dra-driver/pkg/nvidia.com/resource/clientset/versioned/scheme" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + rest "k8s.io/client-go/rest" +) + +// MultiNodeEnvironmentsGetter has a method to return a MultiNodeEnvironmentInterface. +// A group's client should implement this interface. +type MultiNodeEnvironmentsGetter interface { + MultiNodeEnvironments(namespace string) MultiNodeEnvironmentInterface +} + +// MultiNodeEnvironmentInterface has methods to work with MultiNodeEnvironment resources. +type MultiNodeEnvironmentInterface interface { + Create(ctx context.Context, multiNodeEnvironment *v1alpha1.MultiNodeEnvironment, opts v1.CreateOptions) (*v1alpha1.MultiNodeEnvironment, error) + Update(ctx context.Context, multiNodeEnvironment *v1alpha1.MultiNodeEnvironment, opts v1.UpdateOptions) (*v1alpha1.MultiNodeEnvironment, error) + Delete(ctx context.Context, name string, opts v1.DeleteOptions) error + DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error + Get(ctx context.Context, name string, opts v1.GetOptions) (*v1alpha1.MultiNodeEnvironment, error) + List(ctx context.Context, opts v1.ListOptions) (*v1alpha1.MultiNodeEnvironmentList, error) + Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) + Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.MultiNodeEnvironment, err error) + MultiNodeEnvironmentExpansion +} + +// multiNodeEnvironments implements MultiNodeEnvironmentInterface +type multiNodeEnvironments struct { + client rest.Interface + ns string +} + +// newMultiNodeEnvironments returns a MultiNodeEnvironments +func newMultiNodeEnvironments(c *GpuV1alpha1Client, namespace string) *multiNodeEnvironments { + return &multiNodeEnvironments{ + client: c.RESTClient(), + ns: namespace, + } +} + +// Get takes name of the multiNodeEnvironment, and returns the corresponding multiNodeEnvironment object, and an error if there is any. +func (c *multiNodeEnvironments) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha1.MultiNodeEnvironment, err error) { + result = &v1alpha1.MultiNodeEnvironment{} + err = c.client.Get(). + Namespace(c.ns). + Resource("multinodeenvironments"). + Name(name). + VersionedParams(&options, scheme.ParameterCodec). + Do(ctx). + Into(result) + return +} + +// List takes label and field selectors, and returns the list of MultiNodeEnvironments that match those selectors. +func (c *multiNodeEnvironments) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha1.MultiNodeEnvironmentList, err error) { + var timeout time.Duration + if opts.TimeoutSeconds != nil { + timeout = time.Duration(*opts.TimeoutSeconds) * time.Second + } + result = &v1alpha1.MultiNodeEnvironmentList{} + err = c.client.Get(). + Namespace(c.ns). + Resource("multinodeenvironments"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Do(ctx). + Into(result) + return +} + +// Watch returns a watch.Interface that watches the requested multiNodeEnvironments. +func (c *multiNodeEnvironments) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { + var timeout time.Duration + if opts.TimeoutSeconds != nil { + timeout = time.Duration(*opts.TimeoutSeconds) * time.Second + } + opts.Watch = true + return c.client.Get(). + Namespace(c.ns). + Resource("multinodeenvironments"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Watch(ctx) +} + +// Create takes the representation of a multiNodeEnvironment and creates it. Returns the server's representation of the multiNodeEnvironment, and an error, if there is any. +func (c *multiNodeEnvironments) Create(ctx context.Context, multiNodeEnvironment *v1alpha1.MultiNodeEnvironment, opts v1.CreateOptions) (result *v1alpha1.MultiNodeEnvironment, err error) { + result = &v1alpha1.MultiNodeEnvironment{} + err = c.client.Post(). + Namespace(c.ns). + Resource("multinodeenvironments"). + VersionedParams(&opts, scheme.ParameterCodec). + Body(multiNodeEnvironment). + Do(ctx). + Into(result) + return +} + +// Update takes the representation of a multiNodeEnvironment and updates it. Returns the server's representation of the multiNodeEnvironment, and an error, if there is any. +func (c *multiNodeEnvironments) Update(ctx context.Context, multiNodeEnvironment *v1alpha1.MultiNodeEnvironment, opts v1.UpdateOptions) (result *v1alpha1.MultiNodeEnvironment, err error) { + result = &v1alpha1.MultiNodeEnvironment{} + err = c.client.Put(). + Namespace(c.ns). + Resource("multinodeenvironments"). + Name(multiNodeEnvironment.Name). + VersionedParams(&opts, scheme.ParameterCodec). + Body(multiNodeEnvironment). + Do(ctx). + Into(result) + return +} + +// Delete takes name of the multiNodeEnvironment and deletes it. Returns an error if one occurs. +func (c *multiNodeEnvironments) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { + return c.client.Delete(). + Namespace(c.ns). + Resource("multinodeenvironments"). + Name(name). + Body(&opts). + Do(ctx). + Error() +} + +// DeleteCollection deletes a collection of objects. +func (c *multiNodeEnvironments) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { + var timeout time.Duration + if listOpts.TimeoutSeconds != nil { + timeout = time.Duration(*listOpts.TimeoutSeconds) * time.Second + } + return c.client.Delete(). + Namespace(c.ns). + Resource("multinodeenvironments"). + VersionedParams(&listOpts, scheme.ParameterCodec). + Timeout(timeout). + Body(&opts). + Do(ctx). + Error() +} + +// Patch applies the patch and returns the patched multiNodeEnvironment. +func (c *multiNodeEnvironments) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.MultiNodeEnvironment, err error) { + result = &v1alpha1.MultiNodeEnvironment{} + err = c.client.Patch(pt). + Namespace(c.ns). + Resource("multinodeenvironments"). + Name(name). + SubResource(subresources...). + VersionedParams(&opts, scheme.ParameterCodec). + Body(data). + Do(ctx). + Into(result) + return +} diff --git a/vendor/k8s.io/client-go/discovery/fake/discovery.go b/vendor/k8s.io/client-go/discovery/fake/discovery.go new file mode 100644 index 00000000..e5d9e7f8 --- /dev/null +++ b/vendor/k8s.io/client-go/discovery/fake/discovery.go @@ -0,0 +1,180 @@ +/* +Copyright 2016 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package fake + +import ( + "fmt" + "net/http" + + openapi_v2 "github.com/google/gnostic-models/openapiv2" + + "k8s.io/apimachinery/pkg/api/errors" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime/schema" + "k8s.io/apimachinery/pkg/version" + "k8s.io/client-go/discovery" + "k8s.io/client-go/openapi" + kubeversion "k8s.io/client-go/pkg/version" + restclient "k8s.io/client-go/rest" + "k8s.io/client-go/testing" +) + +// FakeDiscovery implements discovery.DiscoveryInterface and sometimes calls testing.Fake.Invoke with an action, +// but doesn't respect the return value if any. There is a way to fake static values like ServerVersion by using the Faked... fields on the struct. +type FakeDiscovery struct { + *testing.Fake + FakedServerVersion *version.Info +} + +// ServerResourcesForGroupVersion returns the supported resources for a group +// and version. +func (c *FakeDiscovery) ServerResourcesForGroupVersion(groupVersion string) (*metav1.APIResourceList, error) { + action := testing.ActionImpl{ + Verb: "get", + Resource: schema.GroupVersionResource{Resource: "resource"}, + } + if _, err := c.Invokes(action, nil); err != nil { + return nil, err + } + for _, resourceList := range c.Resources { + if resourceList.GroupVersion == groupVersion { + return resourceList, nil + } + } + return nil, &errors.StatusError{ + ErrStatus: metav1.Status{ + Status: metav1.StatusFailure, + Code: http.StatusNotFound, + Reason: metav1.StatusReasonNotFound, + Message: fmt.Sprintf("the server could not find the requested resource, GroupVersion %q not found", groupVersion), + }} +} + +// ServerGroupsAndResources returns the supported groups and resources for all groups and versions. +func (c *FakeDiscovery) ServerGroupsAndResources() ([]*metav1.APIGroup, []*metav1.APIResourceList, error) { + sgs, err := c.ServerGroups() + if err != nil { + return nil, nil, err + } + resultGroups := []*metav1.APIGroup{} + for i := range sgs.Groups { + resultGroups = append(resultGroups, &sgs.Groups[i]) + } + + action := testing.ActionImpl{ + Verb: "get", + Resource: schema.GroupVersionResource{Resource: "resource"}, + } + if _, err = c.Invokes(action, nil); err != nil { + return resultGroups, c.Resources, err + } + return resultGroups, c.Resources, nil +} + +// ServerPreferredResources returns the supported resources with the version +// preferred by the server. +func (c *FakeDiscovery) ServerPreferredResources() ([]*metav1.APIResourceList, error) { + return nil, nil +} + +// ServerPreferredNamespacedResources returns the supported namespaced resources +// with the version preferred by the server. +func (c *FakeDiscovery) ServerPreferredNamespacedResources() ([]*metav1.APIResourceList, error) { + return nil, nil +} + +// ServerGroups returns the supported groups, with information like supported +// versions and the preferred version. +func (c *FakeDiscovery) ServerGroups() (*metav1.APIGroupList, error) { + action := testing.ActionImpl{ + Verb: "get", + Resource: schema.GroupVersionResource{Resource: "group"}, + } + if _, err := c.Invokes(action, nil); err != nil { + return nil, err + } + + groups := map[string]*metav1.APIGroup{} + + for _, res := range c.Resources { + gv, err := schema.ParseGroupVersion(res.GroupVersion) + if err != nil { + return nil, err + } + group := groups[gv.Group] + if group == nil { + group = &metav1.APIGroup{ + Name: gv.Group, + PreferredVersion: metav1.GroupVersionForDiscovery{ + GroupVersion: res.GroupVersion, + Version: gv.Version, + }, + } + groups[gv.Group] = group + } + + group.Versions = append(group.Versions, metav1.GroupVersionForDiscovery{ + GroupVersion: res.GroupVersion, + Version: gv.Version, + }) + } + + list := &metav1.APIGroupList{} + for _, apiGroup := range groups { + list.Groups = append(list.Groups, *apiGroup) + } + + return list, nil + +} + +// ServerVersion retrieves and parses the server's version. +func (c *FakeDiscovery) ServerVersion() (*version.Info, error) { + action := testing.ActionImpl{} + action.Verb = "get" + action.Resource = schema.GroupVersionResource{Resource: "version"} + _, err := c.Invokes(action, nil) + if err != nil { + return nil, err + } + + if c.FakedServerVersion != nil { + return c.FakedServerVersion, nil + } + + versionInfo := kubeversion.Get() + return &versionInfo, nil +} + +// OpenAPISchema retrieves and parses the swagger API schema the server supports. +func (c *FakeDiscovery) OpenAPISchema() (*openapi_v2.Document, error) { + return &openapi_v2.Document{}, nil +} + +func (c *FakeDiscovery) OpenAPIV3() openapi.Client { + panic("unimplemented") +} + +// RESTClient returns a RESTClient that is used to communicate with API server +// by this client implementation. +func (c *FakeDiscovery) RESTClient() restclient.Interface { + return nil +} + +func (c *FakeDiscovery) WithLegacy() discovery.DiscoveryInterface { + panic("unimplemented") +} diff --git a/vendor/modules.txt b/vendor/modules.txt index 5147882e..6e6ae7d0 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -525,6 +525,7 @@ k8s.io/client-go/applyconfigurations/storage/v1alpha1 k8s.io/client-go/applyconfigurations/storage/v1beta1 k8s.io/client-go/applyconfigurations/storagemigration/v1alpha1 k8s.io/client-go/discovery +k8s.io/client-go/discovery/fake k8s.io/client-go/features k8s.io/client-go/gentype k8s.io/client-go/informers