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/pkg/nvidia.com/resource/informers/externalversions/factory.go b/pkg/nvidia.com/resource/informers/externalversions/factory.go new file mode 100644 index 00000000..6cb8e7f6 --- /dev/null +++ b/pkg/nvidia.com/resource/informers/externalversions/factory.go @@ -0,0 +1,261 @@ +/* + * 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 informer-gen. DO NOT EDIT. + +package externalversions + +import ( + reflect "reflect" + sync "sync" + time "time" + + versioned "github.com/NVIDIA/k8s-dra-driver/pkg/nvidia.com/resource/clientset/versioned" + gpu "github.com/NVIDIA/k8s-dra-driver/pkg/nvidia.com/resource/informers/externalversions/gpu" + internalinterfaces "github.com/NVIDIA/k8s-dra-driver/pkg/nvidia.com/resource/informers/externalversions/internalinterfaces" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + schema "k8s.io/apimachinery/pkg/runtime/schema" + cache "k8s.io/client-go/tools/cache" +) + +// SharedInformerOption defines the functional option type for SharedInformerFactory. +type SharedInformerOption func(*sharedInformerFactory) *sharedInformerFactory + +type sharedInformerFactory struct { + client versioned.Interface + namespace string + tweakListOptions internalinterfaces.TweakListOptionsFunc + lock sync.Mutex + defaultResync time.Duration + customResync map[reflect.Type]time.Duration + transform cache.TransformFunc + + informers map[reflect.Type]cache.SharedIndexInformer + // startedInformers is used for tracking which informers have been started. + // This allows Start() to be called multiple times safely. + startedInformers map[reflect.Type]bool + // wg tracks how many goroutines were started. + wg sync.WaitGroup + // shuttingDown is true when Shutdown has been called. It may still be running + // because it needs to wait for goroutines. + shuttingDown bool +} + +// WithCustomResyncConfig sets a custom resync period for the specified informer types. +func WithCustomResyncConfig(resyncConfig map[v1.Object]time.Duration) SharedInformerOption { + return func(factory *sharedInformerFactory) *sharedInformerFactory { + for k, v := range resyncConfig { + factory.customResync[reflect.TypeOf(k)] = v + } + return factory + } +} + +// WithTweakListOptions sets a custom filter on all listers of the configured SharedInformerFactory. +func WithTweakListOptions(tweakListOptions internalinterfaces.TweakListOptionsFunc) SharedInformerOption { + return func(factory *sharedInformerFactory) *sharedInformerFactory { + factory.tweakListOptions = tweakListOptions + return factory + } +} + +// WithNamespace limits the SharedInformerFactory to the specified namespace. +func WithNamespace(namespace string) SharedInformerOption { + return func(factory *sharedInformerFactory) *sharedInformerFactory { + factory.namespace = namespace + return factory + } +} + +// WithTransform sets a transform on all informers. +func WithTransform(transform cache.TransformFunc) SharedInformerOption { + return func(factory *sharedInformerFactory) *sharedInformerFactory { + factory.transform = transform + return factory + } +} + +// NewSharedInformerFactory constructs a new instance of sharedInformerFactory for all namespaces. +func NewSharedInformerFactory(client versioned.Interface, defaultResync time.Duration) SharedInformerFactory { + return NewSharedInformerFactoryWithOptions(client, defaultResync) +} + +// NewFilteredSharedInformerFactory constructs a new instance of sharedInformerFactory. +// Listers obtained via this SharedInformerFactory will be subject to the same filters +// as specified here. +// Deprecated: Please use NewSharedInformerFactoryWithOptions instead +func NewFilteredSharedInformerFactory(client versioned.Interface, defaultResync time.Duration, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) SharedInformerFactory { + return NewSharedInformerFactoryWithOptions(client, defaultResync, WithNamespace(namespace), WithTweakListOptions(tweakListOptions)) +} + +// NewSharedInformerFactoryWithOptions constructs a new instance of a SharedInformerFactory with additional options. +func NewSharedInformerFactoryWithOptions(client versioned.Interface, defaultResync time.Duration, options ...SharedInformerOption) SharedInformerFactory { + factory := &sharedInformerFactory{ + client: client, + namespace: v1.NamespaceAll, + defaultResync: defaultResync, + informers: make(map[reflect.Type]cache.SharedIndexInformer), + startedInformers: make(map[reflect.Type]bool), + customResync: make(map[reflect.Type]time.Duration), + } + + // Apply all options + for _, opt := range options { + factory = opt(factory) + } + + return factory +} + +func (f *sharedInformerFactory) Start(stopCh <-chan struct{}) { + f.lock.Lock() + defer f.lock.Unlock() + + if f.shuttingDown { + return + } + + for informerType, informer := range f.informers { + if !f.startedInformers[informerType] { + f.wg.Add(1) + // We need a new variable in each loop iteration, + // otherwise the goroutine would use the loop variable + // and that keeps changing. + informer := informer + go func() { + defer f.wg.Done() + informer.Run(stopCh) + }() + f.startedInformers[informerType] = true + } + } +} + +func (f *sharedInformerFactory) Shutdown() { + f.lock.Lock() + f.shuttingDown = true + f.lock.Unlock() + + // Will return immediately if there is nothing to wait for. + f.wg.Wait() +} + +func (f *sharedInformerFactory) WaitForCacheSync(stopCh <-chan struct{}) map[reflect.Type]bool { + informers := func() map[reflect.Type]cache.SharedIndexInformer { + f.lock.Lock() + defer f.lock.Unlock() + + informers := map[reflect.Type]cache.SharedIndexInformer{} + for informerType, informer := range f.informers { + if f.startedInformers[informerType] { + informers[informerType] = informer + } + } + return informers + }() + + res := map[reflect.Type]bool{} + for informType, informer := range informers { + res[informType] = cache.WaitForCacheSync(stopCh, informer.HasSynced) + } + return res +} + +// InformerFor returns the SharedIndexInformer for obj using an internal +// client. +func (f *sharedInformerFactory) InformerFor(obj runtime.Object, newFunc internalinterfaces.NewInformerFunc) cache.SharedIndexInformer { + f.lock.Lock() + defer f.lock.Unlock() + + informerType := reflect.TypeOf(obj) + informer, exists := f.informers[informerType] + if exists { + return informer + } + + resyncPeriod, exists := f.customResync[informerType] + if !exists { + resyncPeriod = f.defaultResync + } + + informer = newFunc(f.client, resyncPeriod) + informer.SetTransform(f.transform) + f.informers[informerType] = informer + + return informer +} + +// SharedInformerFactory provides shared informers for resources in all known +// API group versions. +// +// It is typically used like this: +// +// ctx, cancel := context.Background() +// defer cancel() +// factory := NewSharedInformerFactory(client, resyncPeriod) +// defer factory.WaitForStop() // Returns immediately if nothing was started. +// genericInformer := factory.ForResource(resource) +// typedInformer := factory.SomeAPIGroup().V1().SomeType() +// factory.Start(ctx.Done()) // Start processing these informers. +// synced := factory.WaitForCacheSync(ctx.Done()) +// for v, ok := range synced { +// if !ok { +// fmt.Fprintf(os.Stderr, "caches failed to sync: %v", v) +// return +// } +// } +// +// // Creating informers can also be created after Start, but then +// // Start must be called again: +// anotherGenericInformer := factory.ForResource(resource) +// factory.Start(ctx.Done()) +type SharedInformerFactory interface { + internalinterfaces.SharedInformerFactory + + // Start initializes all requested informers. They are handled in goroutines + // which run until the stop channel gets closed. + Start(stopCh <-chan struct{}) + + // Shutdown marks a factory as shutting down. At that point no new + // informers can be started anymore and Start will return without + // doing anything. + // + // In addition, Shutdown blocks until all goroutines have terminated. For that + // to happen, the close channel(s) that they were started with must be closed, + // either before Shutdown gets called or while it is waiting. + // + // Shutdown may be called multiple times, even concurrently. All such calls will + // block until all goroutines have terminated. + Shutdown() + + // WaitForCacheSync blocks until all started informers' caches were synced + // or the stop channel gets closed. + WaitForCacheSync(stopCh <-chan struct{}) map[reflect.Type]bool + + // ForResource gives generic access to a shared informer of the matching type. + ForResource(resource schema.GroupVersionResource) (GenericInformer, error) + + // InformerFor returns the SharedIndexInformer for obj using an internal + // client. + InformerFor(obj runtime.Object, newFunc internalinterfaces.NewInformerFunc) cache.SharedIndexInformer + + Gpu() gpu.Interface +} + +func (f *sharedInformerFactory) Gpu() gpu.Interface { + return gpu.New(f, f.namespace, f.tweakListOptions) +} diff --git a/pkg/nvidia.com/resource/informers/externalversions/generic.go b/pkg/nvidia.com/resource/informers/externalversions/generic.go new file mode 100644 index 00000000..fd72ed7d --- /dev/null +++ b/pkg/nvidia.com/resource/informers/externalversions/generic.go @@ -0,0 +1,62 @@ +/* + * 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 informer-gen. DO NOT EDIT. + +package externalversions + +import ( + "fmt" + + v1alpha1 "github.com/NVIDIA/k8s-dra-driver/api/nvidia.com/resource/gpu/v1alpha1" + schema "k8s.io/apimachinery/pkg/runtime/schema" + cache "k8s.io/client-go/tools/cache" +) + +// GenericInformer is type of SharedIndexInformer which will locate and delegate to other +// sharedInformers based on type +type GenericInformer interface { + Informer() cache.SharedIndexInformer + Lister() cache.GenericLister +} + +type genericInformer struct { + informer cache.SharedIndexInformer + resource schema.GroupResource +} + +// Informer returns the SharedIndexInformer. +func (f *genericInformer) Informer() cache.SharedIndexInformer { + return f.informer +} + +// Lister returns the GenericLister. +func (f *genericInformer) Lister() cache.GenericLister { + return cache.NewGenericLister(f.Informer().GetIndexer(), f.resource) +} + +// ForResource gives generic access to a shared informer of the matching type +// TODO extend this to unknown resources with a client pool +func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource) (GenericInformer, error) { + switch resource { + // Group=gpu.nvidia.com, Version=v1alpha1 + case v1alpha1.SchemeGroupVersion.WithResource("multinodeenvironments"): + return &genericInformer{resource: resource.GroupResource(), informer: f.Gpu().V1alpha1().MultiNodeEnvironments().Informer()}, nil + + } + + return nil, fmt.Errorf("no informer found for %v", resource) +} diff --git a/pkg/nvidia.com/resource/informers/externalversions/gpu/interface.go b/pkg/nvidia.com/resource/informers/externalversions/gpu/interface.go new file mode 100644 index 00000000..d06204bf --- /dev/null +++ b/pkg/nvidia.com/resource/informers/externalversions/gpu/interface.go @@ -0,0 +1,46 @@ +/* + * 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 informer-gen. DO NOT EDIT. + +package gpu + +import ( + v1alpha1 "github.com/NVIDIA/k8s-dra-driver/pkg/nvidia.com/resource/informers/externalversions/gpu/v1alpha1" + internalinterfaces "github.com/NVIDIA/k8s-dra-driver/pkg/nvidia.com/resource/informers/externalversions/internalinterfaces" +) + +// Interface provides access to each of this group's versions. +type Interface interface { + // V1alpha1 provides access to shared informers for resources in V1alpha1. + V1alpha1() v1alpha1.Interface +} + +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} +} + +// V1alpha1 returns a new v1alpha1.Interface. +func (g *group) V1alpha1() v1alpha1.Interface { + return v1alpha1.New(g.factory, g.namespace, g.tweakListOptions) +} diff --git a/pkg/nvidia.com/resource/informers/externalversions/gpu/v1alpha1/interface.go b/pkg/nvidia.com/resource/informers/externalversions/gpu/v1alpha1/interface.go new file mode 100644 index 00000000..2db2429d --- /dev/null +++ b/pkg/nvidia.com/resource/informers/externalversions/gpu/v1alpha1/interface.go @@ -0,0 +1,45 @@ +/* + * 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 informer-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + internalinterfaces "github.com/NVIDIA/k8s-dra-driver/pkg/nvidia.com/resource/informers/externalversions/internalinterfaces" +) + +// Interface provides access to all the informers in this group version. +type Interface interface { + // MultiNodeEnvironments returns a MultiNodeEnvironmentInformer. + MultiNodeEnvironments() MultiNodeEnvironmentInformer +} + +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} +} + +// MultiNodeEnvironments returns a MultiNodeEnvironmentInformer. +func (v *version) MultiNodeEnvironments() MultiNodeEnvironmentInformer { + return &multiNodeEnvironmentInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} +} diff --git a/pkg/nvidia.com/resource/informers/externalversions/gpu/v1alpha1/multinodeenvironment.go b/pkg/nvidia.com/resource/informers/externalversions/gpu/v1alpha1/multinodeenvironment.go new file mode 100644 index 00000000..ba0416d5 --- /dev/null +++ b/pkg/nvidia.com/resource/informers/externalversions/gpu/v1alpha1/multinodeenvironment.go @@ -0,0 +1,90 @@ +/* + * 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 informer-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + "context" + time "time" + + gpuv1alpha1 "github.com/NVIDIA/k8s-dra-driver/api/nvidia.com/resource/gpu/v1alpha1" + versioned "github.com/NVIDIA/k8s-dra-driver/pkg/nvidia.com/resource/clientset/versioned" + internalinterfaces "github.com/NVIDIA/k8s-dra-driver/pkg/nvidia.com/resource/informers/externalversions/internalinterfaces" + v1alpha1 "github.com/NVIDIA/k8s-dra-driver/pkg/nvidia.com/resource/listers/gpu/v1alpha1" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + watch "k8s.io/apimachinery/pkg/watch" + cache "k8s.io/client-go/tools/cache" +) + +// MultiNodeEnvironmentInformer provides access to a shared informer and lister for +// MultiNodeEnvironments. +type MultiNodeEnvironmentInformer interface { + Informer() cache.SharedIndexInformer + Lister() v1alpha1.MultiNodeEnvironmentLister +} + +type multiNodeEnvironmentInformer struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc + namespace string +} + +// NewMultiNodeEnvironmentInformer constructs a new informer for MultiNodeEnvironment 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 NewMultiNodeEnvironmentInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return NewFilteredMultiNodeEnvironmentInformer(client, namespace, resyncPeriod, indexers, nil) +} + +// NewFilteredMultiNodeEnvironmentInformer constructs a new informer for MultiNodeEnvironment 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 NewFilteredMultiNodeEnvironmentInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { + return cache.NewSharedIndexInformer( + &cache.ListWatch{ + ListFunc: func(options v1.ListOptions) (runtime.Object, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.GpuV1alpha1().MultiNodeEnvironments(namespace).List(context.TODO(), options) + }, + WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.GpuV1alpha1().MultiNodeEnvironments(namespace).Watch(context.TODO(), options) + }, + }, + &gpuv1alpha1.MultiNodeEnvironment{}, + resyncPeriod, + indexers, + ) +} + +func (f *multiNodeEnvironmentInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewFilteredMultiNodeEnvironmentInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) +} + +func (f *multiNodeEnvironmentInformer) Informer() cache.SharedIndexInformer { + return f.factory.InformerFor(&gpuv1alpha1.MultiNodeEnvironment{}, f.defaultInformer) +} + +func (f *multiNodeEnvironmentInformer) Lister() v1alpha1.MultiNodeEnvironmentLister { + return v1alpha1.NewMultiNodeEnvironmentLister(f.Informer().GetIndexer()) +} diff --git a/pkg/nvidia.com/resource/informers/externalversions/internalinterfaces/factory_interfaces.go b/pkg/nvidia.com/resource/informers/externalversions/internalinterfaces/factory_interfaces.go new file mode 100644 index 00000000..eeac3da1 --- /dev/null +++ b/pkg/nvidia.com/resource/informers/externalversions/internalinterfaces/factory_interfaces.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 informer-gen. DO NOT EDIT. + +package internalinterfaces + +import ( + time "time" + + versioned "github.com/NVIDIA/k8s-dra-driver/pkg/nvidia.com/resource/clientset/versioned" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + cache "k8s.io/client-go/tools/cache" +) + +// NewInformerFunc takes versioned.Interface and time.Duration to return a SharedIndexInformer. +type NewInformerFunc func(versioned.Interface, time.Duration) cache.SharedIndexInformer + +// SharedInformerFactory a small interface to allow for adding an informer without an import cycle +type SharedInformerFactory interface { + Start(stopCh <-chan struct{}) + InformerFor(obj runtime.Object, newFunc NewInformerFunc) cache.SharedIndexInformer +} + +// TweakListOptionsFunc is a function that transforms a v1.ListOptions. +type TweakListOptionsFunc func(*v1.ListOptions) diff --git a/pkg/nvidia.com/resource/listers/gpu/v1alpha1/expansion_generated.go b/pkg/nvidia.com/resource/listers/gpu/v1alpha1/expansion_generated.go new file mode 100644 index 00000000..bd68be96 --- /dev/null +++ b/pkg/nvidia.com/resource/listers/gpu/v1alpha1/expansion_generated.go @@ -0,0 +1,27 @@ +/* + * 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 lister-gen. DO NOT EDIT. + +package v1alpha1 + +// MultiNodeEnvironmentListerExpansion allows custom methods to be added to +// MultiNodeEnvironmentLister. +type MultiNodeEnvironmentListerExpansion interface{} + +// MultiNodeEnvironmentNamespaceListerExpansion allows custom methods to be added to +// MultiNodeEnvironmentNamespaceLister. +type MultiNodeEnvironmentNamespaceListerExpansion interface{} diff --git a/pkg/nvidia.com/resource/listers/gpu/v1alpha1/multinodeenvironment.go b/pkg/nvidia.com/resource/listers/gpu/v1alpha1/multinodeenvironment.go new file mode 100644 index 00000000..d320d5b0 --- /dev/null +++ b/pkg/nvidia.com/resource/listers/gpu/v1alpha1/multinodeenvironment.go @@ -0,0 +1,99 @@ +/* + * 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 lister-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + v1alpha1 "github.com/NVIDIA/k8s-dra-driver/api/nvidia.com/resource/gpu/v1alpha1" + "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/tools/cache" +) + +// MultiNodeEnvironmentLister helps list MultiNodeEnvironments. +// All objects returned here must be treated as read-only. +type MultiNodeEnvironmentLister interface { + // List lists all MultiNodeEnvironments in the indexer. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*v1alpha1.MultiNodeEnvironment, err error) + // MultiNodeEnvironments returns an object that can list and get MultiNodeEnvironments. + MultiNodeEnvironments(namespace string) MultiNodeEnvironmentNamespaceLister + MultiNodeEnvironmentListerExpansion +} + +// multiNodeEnvironmentLister implements the MultiNodeEnvironmentLister interface. +type multiNodeEnvironmentLister struct { + indexer cache.Indexer +} + +// NewMultiNodeEnvironmentLister returns a new MultiNodeEnvironmentLister. +func NewMultiNodeEnvironmentLister(indexer cache.Indexer) MultiNodeEnvironmentLister { + return &multiNodeEnvironmentLister{indexer: indexer} +} + +// List lists all MultiNodeEnvironments in the indexer. +func (s *multiNodeEnvironmentLister) List(selector labels.Selector) (ret []*v1alpha1.MultiNodeEnvironment, err error) { + err = cache.ListAll(s.indexer, selector, func(m interface{}) { + ret = append(ret, m.(*v1alpha1.MultiNodeEnvironment)) + }) + return ret, err +} + +// MultiNodeEnvironments returns an object that can list and get MultiNodeEnvironments. +func (s *multiNodeEnvironmentLister) MultiNodeEnvironments(namespace string) MultiNodeEnvironmentNamespaceLister { + return multiNodeEnvironmentNamespaceLister{indexer: s.indexer, namespace: namespace} +} + +// MultiNodeEnvironmentNamespaceLister helps list and get MultiNodeEnvironments. +// All objects returned here must be treated as read-only. +type MultiNodeEnvironmentNamespaceLister interface { + // List lists all MultiNodeEnvironments in the indexer for a given namespace. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*v1alpha1.MultiNodeEnvironment, err error) + // Get retrieves the MultiNodeEnvironment from the indexer for a given namespace and name. + // Objects returned here must be treated as read-only. + Get(name string) (*v1alpha1.MultiNodeEnvironment, error) + MultiNodeEnvironmentNamespaceListerExpansion +} + +// multiNodeEnvironmentNamespaceLister implements the MultiNodeEnvironmentNamespaceLister +// interface. +type multiNodeEnvironmentNamespaceLister struct { + indexer cache.Indexer + namespace string +} + +// List lists all MultiNodeEnvironments in the indexer for a given namespace. +func (s multiNodeEnvironmentNamespaceLister) List(selector labels.Selector) (ret []*v1alpha1.MultiNodeEnvironment, err error) { + err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { + ret = append(ret, m.(*v1alpha1.MultiNodeEnvironment)) + }) + return ret, err +} + +// Get retrieves the MultiNodeEnvironment from the indexer for a given namespace and name. +func (s multiNodeEnvironmentNamespaceLister) Get(name string) (*v1alpha1.MultiNodeEnvironment, error) { + obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) + if err != nil { + return nil, err + } + if !exists { + return nil, errors.NewNotFound(v1alpha1.Resource("multinodeenvironment"), name) + } + return obj.(*v1alpha1.MultiNodeEnvironment), nil +} 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