diff --git a/config/crd/device_example.yaml b/config/crd/device_example.yaml new file mode 100644 index 000000000..32a1c7dd8 --- /dev/null +++ b/config/crd/device_example.yaml @@ -0,0 +1,11 @@ +apiVersion: sonick8s.io/v1alpha1 +kind: NetworkDevice +metadata: + name: example-networkdevice + namespace: default +spec: + os: + type: "LeafRouter" + osVersion: "202305" + firmwareProfile: "test-profile" + operation: "OSUpgrade" diff --git a/config/crd/sonick8s.io_networkdevices.yaml b/config/crd/sonick8s.io_networkdevices.yaml new file mode 100644 index 000000000..a06a93c1e --- /dev/null +++ b/config/crd/sonick8s.io_networkdevices.yaml @@ -0,0 +1,80 @@ +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: v0.19.0 + name: networkdevices.sonick8s.io +spec: + group: sonick8s.io + names: + kind: NetworkDevice + listKind: NetworkDeviceList + plural: networkdevices + singular: networkdevice + scope: Namespaced + versions: + - name: v1 + schema: + openAPIV3Schema: + description: NetworkDevice is a specification for a NetworkDevice resource + 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: NetworkDeviceSpec is the spec for a NetworkDevice resource + properties: + firmwareProfile: + type: string + operation: + type: string + operationAction: + type: string + osVersion: + type: string + type: + description: device type of the network device + type: string + type: object + status: + description: NetworkDeviceStatus is the status for a NetworkDevice resource + properties: + lastTransitionTime: + description: last transition time of the network device state + format: date-time + type: string + operationActionState: + description: current operation action state of the network device + type: string + operationState: + description: current operation state of the network device + type: string + osVersion: + description: current OS version of the network device + type: string + state: + description: current state of the network device + type: string + type: object + required: + - spec + type: object + served: true + storage: true + subresources: + status: {} diff --git a/go.mod b/go.mod index 35b04c1cc..98f3f56f8 100644 --- a/go.mod +++ b/go.mod @@ -4,56 +4,53 @@ module k8s.io/sample-controller go 1.25.0 -godebug default=go1.25 +// godebug default=go1.25 require ( + github.com/davecgh/go-spew v1.1.1 + github.com/emicklei/go-restful/v3 v3.12.2 + github.com/fxamacker/cbor/v2 v2.9.0 + github.com/go-logr/logr v1.4.3 + github.com/go-openapi/jsonpointer v0.21.0 + github.com/go-openapi/jsonreference v0.20.2 + github.com/go-openapi/swag v0.23.0 + github.com/google/gnostic-models v0.7.0 + github.com/google/go-cmp v0.7.0 + github.com/google/uuid v1.6.0 + github.com/josharian/intern v1.0.0 + github.com/json-iterator/go v1.1.12 + github.com/mailru/easyjson v0.7.7 + github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd + github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee + github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 + github.com/pmezard/go-difflib v1.0.0 + github.com/spf13/pflag v1.0.9 + github.com/x448/float16 v0.8.4 + go.yaml.in/yaml/v2 v2.4.2 + go.yaml.in/yaml/v3 v3.0.4 + golang.org/x/mod v0.27.0 + golang.org/x/net v0.43.0 + golang.org/x/oauth2 v0.30.0 + golang.org/x/sync v0.16.0 + golang.org/x/sys v0.35.0 + golang.org/x/term v0.34.0 + golang.org/x/text v0.28.0 golang.org/x/time v0.9.0 + golang.org/x/tools v0.36.0 + google.golang.org/protobuf v1.36.8 + gopkg.in/evanphx/json-patch.v4 v4.13.0 + gopkg.in/inf.v0 v0.9.1 + gopkg.in/yaml.v3 v3.0.1 k8s.io/api v0.0.0-20251022232024-e681e9f64143 k8s.io/apimachinery v0.0.0-20251022231703-e79daceaa31b k8s.io/client-go v0.0.0-20251022232504-715199a180dc k8s.io/code-generator v0.0.0-20251022233416-62789f7b54ab + k8s.io/gengo/v2 v2.0.0-20250922181213-ec3ebc5fd46b k8s.io/klog/v2 v2.130.1 + k8s.io/kube-openapi v0.0.0-20250910181357-589584f1c912 k8s.io/utils v0.0.0-20250604170112-4c0f3b243397 -) - -require ( - github.com/davecgh/go-spew v1.1.1 // indirect - github.com/emicklei/go-restful/v3 v3.12.2 // indirect - github.com/fxamacker/cbor/v2 v2.9.0 // indirect - github.com/go-logr/logr v1.4.3 // indirect - github.com/go-openapi/jsonpointer v0.21.0 // indirect - github.com/go-openapi/jsonreference v0.20.2 // indirect - github.com/go-openapi/swag v0.23.0 // indirect - github.com/google/gnostic-models v0.7.0 // indirect - github.com/google/go-cmp v0.7.0 // indirect - github.com/google/uuid v1.6.0 // indirect - github.com/josharian/intern v1.0.0 // indirect - github.com/json-iterator/go v1.1.12 // indirect - github.com/mailru/easyjson v0.7.7 // indirect - github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect - github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee // indirect - github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect - github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/spf13/pflag v1.0.9 // indirect - github.com/x448/float16 v0.8.4 // indirect - go.yaml.in/yaml/v2 v2.4.2 // indirect - go.yaml.in/yaml/v3 v3.0.4 // indirect - golang.org/x/mod v0.27.0 // indirect - golang.org/x/net v0.43.0 // indirect - golang.org/x/oauth2 v0.30.0 // indirect - golang.org/x/sync v0.16.0 // indirect - golang.org/x/sys v0.35.0 // indirect - golang.org/x/term v0.34.0 // indirect - golang.org/x/text v0.28.0 // indirect - golang.org/x/tools v0.36.0 // indirect - google.golang.org/protobuf v1.36.8 // indirect - gopkg.in/evanphx/json-patch.v4 v4.13.0 // indirect - gopkg.in/inf.v0 v0.9.1 // indirect - gopkg.in/yaml.v3 v3.0.1 // indirect - k8s.io/gengo/v2 v2.0.0-20250922181213-ec3ebc5fd46b // indirect - k8s.io/kube-openapi v0.0.0-20250910181357-589584f1c912 // indirect - sigs.k8s.io/json v0.0.0-20250730193827-2d320260d730 // indirect - sigs.k8s.io/randfill v1.0.0 // indirect - sigs.k8s.io/structured-merge-diff/v6 v6.3.0 // indirect - sigs.k8s.io/yaml v1.6.0 // indirect + sigs.k8s.io/json v0.0.0-20250730193827-2d320260d730 + sigs.k8s.io/randfill v1.0.0 + sigs.k8s.io/structured-merge-diff/v6 v6.3.0 + sigs.k8s.io/yaml v1.6.0 ) diff --git a/hack/update-codegen-sonic.sh b/hack/update-codegen-sonic.sh new file mode 100755 index 000000000..6333132f0 --- /dev/null +++ b/hack/update-codegen-sonic.sh @@ -0,0 +1,37 @@ +#!/usr/bin/env bash + +# Copyright 2017 The Kubernetes Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -o errexit +set -o nounset +set -o pipefail + +SCRIPT_ROOT=$(dirname "${BASH_SOURCE[0]}")/.. +CODEGEN_PKG=${CODEGEN_PKG:-$(cd "${SCRIPT_ROOT}"; ls -d -1 ./vendor/k8s.io/code-generator 2>/dev/null || echo ../code-generator)} + +source "${CODEGEN_PKG}/kube_codegen.sh" + +THIS_PKG="k8s.io/sample-controller" + +kube::codegen::gen_helpers \ + --boilerplate "${SCRIPT_ROOT}/hack/boilerplate.go.txt" \ + "${SCRIPT_ROOT}/pkg/apis" + +kube::codegen::gen_client \ + --with-watch \ + --output-dir "${SCRIPT_ROOT}/pkg/networkdevice/generated" \ + --output-pkg "${THIS_PKG}/pkg/networkdevice/generated" \ + --boilerplate "${SCRIPT_ROOT}/hack/boilerplate.go.txt" \ + "${SCRIPT_ROOT}/pkg/apis" diff --git a/main.go b/main.go index cda6ca198..48f710c99 100644 --- a/main.go +++ b/main.go @@ -27,9 +27,9 @@ import ( "k8s.io/sample-controller/pkg/signals" // Uncomment the following line to load the gcp plugin (only required to authenticate against GKE clusters). // _ "k8s.io/client-go/plugin/pkg/client/auth/gcp" - - clientset "k8s.io/sample-controller/pkg/generated/clientset/versioned" - informers "k8s.io/sample-controller/pkg/generated/informers/externalversions" + "k8s.io/sample-controller/pkg/controller" + clientset "k8s.io/sample-controller/pkg/networkdevice/generated/clientset/versioned" + informers "k8s.io/sample-controller/pkg/networkdevice/generated/informers/externalversions" ) var ( @@ -66,9 +66,9 @@ func main() { kubeInformerFactory := kubeinformers.NewSharedInformerFactory(kubeClient, time.Second*30) exampleInformerFactory := informers.NewSharedInformerFactory(exampleClient, time.Second*30) - controller := NewController(ctx, kubeClient, exampleClient, - kubeInformerFactory.Apps().V1().Deployments(), - exampleInformerFactory.Samplecontroller().V1alpha1().Foos()) + controller := controller.NewDeviceLifecycleController(ctx, kubeClient, exampleClient, + kubeInformerFactory.Core().V1().Nodes(), + exampleInformerFactory.Sonick8s().V1().NetworkDevices()) // notice that there is no need to run Start methods in a separate goroutine. (i.e. go kubeInformerFactory.Start(ctx.done()) // Start method is non-blocking and runs all registered informers in a dedicated goroutine. diff --git a/pkg/apis/samplecontroller/register.go b/pkg/apis/networkdevice/register.go similarity index 85% rename from pkg/apis/samplecontroller/register.go rename to pkg/apis/networkdevice/register.go index fd5a7888d..29b502497 100644 --- a/pkg/apis/samplecontroller/register.go +++ b/pkg/apis/networkdevice/register.go @@ -1,5 +1,5 @@ /* -Copyright 2017 The Kubernetes Authors. +Copyright 2025 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. @@ -14,9 +14,9 @@ See the License for the specific language governing permissions and limitations under the License. */ -package samplecontroller +package networkdevice // GroupName is the group name used in this package const ( - GroupName = "samplecontroller.k8s.io" + GroupName = "sonick8s.io" ) diff --git a/pkg/apis/samplecontroller/v1alpha1/doc.go b/pkg/apis/networkdevice/v1/doc.go similarity index 78% rename from pkg/apis/samplecontroller/v1alpha1/doc.go rename to pkg/apis/networkdevice/v1/doc.go index e6c135eed..91690d781 100644 --- a/pkg/apis/samplecontroller/v1alpha1/doc.go +++ b/pkg/apis/networkdevice/v1/doc.go @@ -1,5 +1,5 @@ /* -Copyright 2017 The Kubernetes Authors. +Copyright 2025 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. @@ -15,7 +15,7 @@ limitations under the License. */ // +k8s:deepcopy-gen=package -// +groupName=samplecontroller.k8s.io +// +groupName=sonick8s.io -// Package v1alpha1 is the v1alpha1 version of the API. -package v1alpha1 +// Package v1 is the v1 version of the API. +package v1 diff --git a/pkg/apis/samplecontroller/v1alpha1/register.go b/pkg/apis/networkdevice/v1/register.go similarity index 86% rename from pkg/apis/samplecontroller/v1alpha1/register.go rename to pkg/apis/networkdevice/v1/register.go index e8e0a28ef..9f53f3867 100644 --- a/pkg/apis/samplecontroller/v1alpha1/register.go +++ b/pkg/apis/networkdevice/v1/register.go @@ -1,5 +1,5 @@ /* -Copyright 2017 The Kubernetes Authors. +Copyright 2025 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. @@ -14,19 +14,18 @@ See the License for the specific language governing permissions and limitations under the License. */ -package v1alpha1 +package v1 import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" - samplecontroller "k8s.io/sample-controller/pkg/apis/samplecontroller" + networkdevice "k8s.io/sample-controller/pkg/apis/networkdevice" ) // SchemeGroupVersion is group version used to register these objects -var SchemeGroupVersion = schema.GroupVersion{Group: samplecontroller.GroupName, Version: "v1alpha1"} - +var SchemeGroupVersion = schema.GroupVersion{Group: networkdevice.GroupName, Version: "v1"} // Kind takes an unqualified kind and returns back a Group qualified GroupKind func Kind(kind string) schema.GroupKind { return SchemeGroupVersion.WithKind(kind).GroupKind() @@ -47,8 +46,8 @@ var ( // Adds the list of known types to Scheme. func addKnownTypes(scheme *runtime.Scheme) error { scheme.AddKnownTypes(SchemeGroupVersion, - &Foo{}, - &FooList{}, + &NetworkDevice{}, + &NetworkDeviceList{}, ) metav1.AddToGroupVersion(scheme, SchemeGroupVersion) return nil diff --git a/pkg/apis/networkdevice/v1/types.go b/pkg/apis/networkdevice/v1/types.go new file mode 100644 index 000000000..59651498e --- /dev/null +++ b/pkg/apis/networkdevice/v1/types.go @@ -0,0 +1,77 @@ +/* +Copyright 2025 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 v1 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +type NetworkDeviceState string + +const ( + // network device states + NetworkDeviceStateHealthy NetworkDeviceState = "Healthy" + NetworkDeviceStateOffline NetworkDeviceState = "Offline" +) + +// +genclient +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object +// +kubebuilder:object:root=true +// +kubebuilder:subresource:status +// NetworkDevice is a specification for a NetworkDevice resource +type NetworkDevice struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + + Spec NetworkDeviceSpec `json:"spec"` + Status NetworkDeviceStatus `json:"status,omitempty"` +} + +// NetworkDeviceSpec is the spec for a NetworkDevice resource +type NetworkDeviceSpec struct { + // device type of the network device + Type string `json:"type,omitempty"` + OsVersion string `json:"osVersion,omitempty"` + FirmwareProfile string `json:"firmwareProfile,omitempty"` + Operation string `json:"operation,omitempty"` + OperationAction string `json:"operationAction,omitempty"` +} + +// NetworkDeviceStatus is the status for a NetworkDevice resource +type NetworkDeviceStatus struct { + // current state of the network device + State string `json:"state,omitempty"` + // last transition time of the network device state + LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty"` + // current OS version of the network device + OsVersion string `json:"osVersion,omitempty"` + // current operation state of the network device + OperationState string `json:"operationState,omitempty"` + // current operation action state of the network device + OperationActionState string `json:"operationActionState,omitempty"` +} + +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// NetworkDeviceList is a list of NetworkDevice resources +// +kubebuilder:object:root=true +type NetworkDeviceList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata"` + + Items []NetworkDevice `json:"items"` +} diff --git a/pkg/apis/samplecontroller/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/networkdevice/v1/zz_generated.deepcopy.go similarity index 69% rename from pkg/apis/samplecontroller/v1alpha1/zz_generated.deepcopy.go rename to pkg/apis/networkdevice/v1/zz_generated.deepcopy.go index 26194609e..8ab030e25 100644 --- a/pkg/apis/samplecontroller/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/networkdevice/v1/zz_generated.deepcopy.go @@ -19,34 +19,34 @@ limitations under the License. // Code generated by deepcopy-gen. DO NOT EDIT. -package v1alpha1 +package v1 import ( runtime "k8s.io/apimachinery/pkg/runtime" ) // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *Foo) DeepCopyInto(out *Foo) { +func (in *NetworkDevice) DeepCopyInto(out *NetworkDevice) { *out = *in out.TypeMeta = in.TypeMeta in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - in.Spec.DeepCopyInto(&out.Spec) - out.Status = in.Status + out.Spec = in.Spec + in.Status.DeepCopyInto(&out.Status) return } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Foo. -func (in *Foo) DeepCopy() *Foo { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NetworkDevice. +func (in *NetworkDevice) DeepCopy() *NetworkDevice { if in == nil { return nil } - out := new(Foo) + out := new(NetworkDevice) in.DeepCopyInto(out) return out } // DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *Foo) DeepCopyObject() runtime.Object { +func (in *NetworkDevice) DeepCopyObject() runtime.Object { if c := in.DeepCopy(); c != nil { return c } @@ -54,13 +54,13 @@ func (in *Foo) DeepCopyObject() runtime.Object { } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *FooList) DeepCopyInto(out *FooList) { +func (in *NetworkDeviceList) DeepCopyInto(out *NetworkDeviceList) { *out = *in out.TypeMeta = in.TypeMeta in.ListMeta.DeepCopyInto(&out.ListMeta) if in.Items != nil { in, out := &in.Items, &out.Items - *out = make([]Foo, len(*in)) + *out = make([]NetworkDevice, len(*in)) for i := range *in { (*in)[i].DeepCopyInto(&(*out)[i]) } @@ -68,18 +68,18 @@ func (in *FooList) DeepCopyInto(out *FooList) { return } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new FooList. -func (in *FooList) DeepCopy() *FooList { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NetworkDeviceList. +func (in *NetworkDeviceList) DeepCopy() *NetworkDeviceList { if in == nil { return nil } - out := new(FooList) + out := new(NetworkDeviceList) in.DeepCopyInto(out) return out } // DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *FooList) DeepCopyObject() runtime.Object { +func (in *NetworkDeviceList) DeepCopyObject() runtime.Object { if c := in.DeepCopy(); c != nil { return c } @@ -87,38 +87,34 @@ func (in *FooList) DeepCopyObject() runtime.Object { } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *FooSpec) DeepCopyInto(out *FooSpec) { +func (in *NetworkDeviceSpec) DeepCopyInto(out *NetworkDeviceSpec) { *out = *in - if in.Replicas != nil { - in, out := &in.Replicas, &out.Replicas - *out = new(int32) - **out = **in - } return } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new FooSpec. -func (in *FooSpec) DeepCopy() *FooSpec { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NetworkDeviceSpec. +func (in *NetworkDeviceSpec) DeepCopy() *NetworkDeviceSpec { if in == nil { return nil } - out := new(FooSpec) + out := new(NetworkDeviceSpec) in.DeepCopyInto(out) return out } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *FooStatus) DeepCopyInto(out *FooStatus) { +func (in *NetworkDeviceStatus) DeepCopyInto(out *NetworkDeviceStatus) { *out = *in + in.LastTransitionTime.DeepCopyInto(&out.LastTransitionTime) return } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new FooStatus. -func (in *FooStatus) DeepCopy() *FooStatus { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NetworkDeviceStatus. +func (in *NetworkDeviceStatus) DeepCopy() *NetworkDeviceStatus { if in == nil { return nil } - out := new(FooStatus) + out := new(NetworkDeviceStatus) in.DeepCopyInto(out) return out } diff --git a/pkg/apis/samplecontroller/v1alpha1/types.go b/pkg/apis/samplecontroller/v1alpha1/types.go deleted file mode 100644 index 74ffc6721..000000000 --- a/pkg/apis/samplecontroller/v1alpha1/types.go +++ /dev/null @@ -1,54 +0,0 @@ -/* -Copyright 2017 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package v1alpha1 - -import ( - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" -) - -// +genclient -// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object - -// Foo is a specification for a Foo resource -type Foo struct { - metav1.TypeMeta `json:",inline"` - metav1.ObjectMeta `json:"metadata,omitempty"` - - Spec FooSpec `json:"spec"` - Status FooStatus `json:"status"` -} - -// FooSpec is the spec for a Foo resource -type FooSpec struct { - DeploymentName string `json:"deploymentName"` - Replicas *int32 `json:"replicas"` -} - -// FooStatus is the status for a Foo resource -type FooStatus struct { - AvailableReplicas int32 `json:"availableReplicas"` -} - -// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object - -// FooList is a list of Foo resources -type FooList struct { - metav1.TypeMeta `json:",inline"` - metav1.ListMeta `json:"metadata"` - - Items []Foo `json:"items"` -} diff --git a/controller.go b/pkg/controller/devicelifecycle_controller.go similarity index 51% rename from controller.go rename to pkg/controller/devicelifecycle_controller.go index dd6ac9a20..3340076ae 100644 --- a/controller.go +++ b/pkg/controller/devicelifecycle_controller.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package main +package controller import ( "context" @@ -23,59 +23,59 @@ import ( "golang.org/x/time/rate" - appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" utilruntime "k8s.io/apimachinery/pkg/util/runtime" "k8s.io/apimachinery/pkg/util/wait" - appsinformers "k8s.io/client-go/informers/apps/v1" "k8s.io/client-go/kubernetes" "k8s.io/client-go/kubernetes/scheme" typedcorev1 "k8s.io/client-go/kubernetes/typed/core/v1" - appslisters "k8s.io/client-go/listers/apps/v1" + corelisters "k8s.io/client-go/listers/core/v1" + coreinformers "k8s.io/client-go/informers/core/v1" "k8s.io/client-go/tools/cache" "k8s.io/client-go/tools/record" "k8s.io/client-go/util/workqueue" "k8s.io/klog/v2" - samplev1alpha1 "k8s.io/sample-controller/pkg/apis/samplecontroller/v1alpha1" - clientset "k8s.io/sample-controller/pkg/generated/clientset/versioned" - samplescheme "k8s.io/sample-controller/pkg/generated/clientset/versioned/scheme" - informers "k8s.io/sample-controller/pkg/generated/informers/externalversions/samplecontroller/v1alpha1" - listers "k8s.io/sample-controller/pkg/generated/listers/samplecontroller/v1alpha1" + networkdevicev1 "k8s.io/sample-controller/pkg/apis/networkdevice/v1" + opt "k8s.io/sample-controller/pkg/networkoperation" + clientset "k8s.io/sample-controller/pkg/networkdevice/generated/clientset/versioned" + samplescheme "k8s.io/sample-controller/pkg/networkdevice/generated/clientset/versioned/scheme" + informers "k8s.io/sample-controller/pkg/networkdevice/generated/informers/externalversions/networkdevice/v1" + listers "k8s.io/sample-controller/pkg/networkdevice/generated/listers/networkdevice/v1" ) -const controllerAgentName = "sample-controller" +const controllerAgentName = "devicelifecycle-controller" const ( - // SuccessSynced is used as part of the Event 'reason' when a Foo is synced + // SuccessSynced is used as part of the Event 'reason' when a NetworkDevice is synced SuccessSynced = "Synced" - // ErrResourceExists is used as part of the Event 'reason' when a Foo fails + // ErrResourceExists is used as part of the Event 'reason' when a NetworkDevice fails // to sync due to a Deployment of the same name already existing. ErrResourceExists = "ErrResourceExists" // MessageResourceExists is the message used for Events when a resource // fails to sync due to a Deployment already existing - MessageResourceExists = "Resource %q already exists and is not managed by Foo" - // MessageResourceSynced is the message used for an Event fired when a Foo + MessageResourceExists = "Resource %q already exists and is not managed by NetworkDevice" + // MessageResourceSynced is the message used for an Event fired when a NetworkDevice // is synced successfully - MessageResourceSynced = "Foo synced successfully" + MessageResourceSynced = "NetworkDevice synced successfully" // FieldManager distinguishes this controller from other things writing to API objects FieldManager = controllerAgentName ) -// Controller is the controller implementation for Foo resources -type Controller struct { +// DeviceLifecycleController is the controller implementation for NetworkDevice resources +type DeviceLifecycleController struct { // kubeclientset is a standard kubernetes clientset kubeclientset kubernetes.Interface // sampleclientset is a clientset for our own API group sampleclientset clientset.Interface - deploymentsLister appslisters.DeploymentLister - deploymentsSynced cache.InformerSynced - foosLister listers.FooLister - foosSynced cache.InformerSynced + nodesLister corelisters.NodeLister + nodesSynced cache.InformerSynced + networkDeviceLister listers.NetworkDeviceLister + networkDevicesSynced cache.InformerSynced // workqueue is a rate limited work queue. This is used to queue work to be // processed instead of performing it as soon as a change happens. This @@ -86,15 +86,18 @@ type Controller struct { // recorder is an event recorder for recording Event resources to the // Kubernetes API. recorder record.EventRecorder + + // operation map + operationHandlers map[string]opt.OperationHandler } // NewController returns a new sample controller -func NewController( +func NewDeviceLifecycleController( ctx context.Context, kubeclientset kubernetes.Interface, sampleclientset clientset.Interface, - deploymentInformer appsinformers.DeploymentInformer, - fooInformer informers.FooInformer) *Controller { + nodeInformer coreinformers.NodeInformer, + networkDeviceInformer informers.NetworkDeviceInformer) *DeviceLifecycleController { logger := klog.FromContext(ctx) // Create event broadcaster @@ -112,46 +115,26 @@ func NewController( &workqueue.TypedBucketRateLimiter[cache.ObjectName]{Limiter: rate.NewLimiter(rate.Limit(50), 300)}, ) - controller := &Controller{ + controller := &DeviceLifecycleController{ kubeclientset: kubeclientset, sampleclientset: sampleclientset, - deploymentsLister: deploymentInformer.Lister(), - deploymentsSynced: deploymentInformer.Informer().HasSynced, - foosLister: fooInformer.Lister(), - foosSynced: fooInformer.Informer().HasSynced, + nodesLister: nodeInformer.Lister(), + nodesSynced: nodeInformer.Informer().HasSynced, + networkDeviceLister: networkDeviceInformer.Lister(), + networkDevicesSynced: networkDeviceInformer.Informer().HasSynced, workqueue: workqueue.NewTypedRateLimitingQueue(ratelimiter), recorder: recorder, } logger.Info("Setting up event handlers") - // Set up an event handler for when Foo resources change - fooInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{ - AddFunc: controller.enqueueFoo, - UpdateFunc: func(old, new interface{}) { - controller.enqueueFoo(new) - }, - }) - // Set up an event handler for when Deployment resources change. This - // handler will lookup the owner of the given Deployment, and if it is - // owned by a Foo resource then the handler will enqueue that Foo resource for - // processing. This way, we don't need to implement custom logic for - // handling Deployment resources. More info on this pattern: - // https://github.com/kubernetes/community/blob/8cafef897a22026d42f5e5bb3f104febe7e29830/contributors/devel/controllers.md - deploymentInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{ - AddFunc: controller.handleObject, + // Set up an event handler for when Device resources change + networkDeviceInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{ + AddFunc: controller.enqueueDevice, UpdateFunc: func(old, new interface{}) { - newDepl := new.(*appsv1.Deployment) - oldDepl := old.(*appsv1.Deployment) - if newDepl.ResourceVersion == oldDepl.ResourceVersion { - // Periodic resync will send update events for all known Deployments. - // Two different versions of the same Deployment will always have different RVs. - return - } - controller.handleObject(new) + controller.enqueueDevice(new) }, - DeleteFunc: controller.handleObject, }) - + return controller } @@ -159,23 +142,23 @@ func NewController( // as syncing informer caches and starting workers. It will block until stopCh // is closed, at which point it will shutdown the workqueue and wait for // workers to finish processing their current work items. -func (c *Controller) Run(ctx context.Context, workers int) error { +func (c *DeviceLifecycleController) Run(ctx context.Context, workers int) error { defer utilruntime.HandleCrash() defer c.workqueue.ShutDown() logger := klog.FromContext(ctx) // Start the informer factories to begin populating the informer caches - logger.Info("Starting Foo controller") + logger.Info("Starting NetworkDevice controller") // Wait for the caches to be synced before starting workers logger.Info("Waiting for informer caches to sync") - if ok := cache.WaitForCacheSync(ctx.Done(), c.deploymentsSynced, c.foosSynced); !ok { + if ok := cache.WaitForCacheSync(ctx.Done(), c.nodesSynced, c.networkDevicesSynced); !ok { return fmt.Errorf("failed to wait for caches to sync") } logger.Info("Starting workers", "count", workers) - // Launch two workers to process Foo resources + // Launch two workers to process NetworkDevice resources for i := 0; i < workers; i++ { go wait.UntilWithContext(ctx, c.runWorker, time.Second) } @@ -190,14 +173,14 @@ func (c *Controller) Run(ctx context.Context, workers int) error { // runWorker is a long-running function that will continually call the // processNextWorkItem function in order to read and process a message on the // workqueue. -func (c *Controller) runWorker(ctx context.Context) { +func (c *DeviceLifecycleController) runWorker(ctx context.Context) { for c.processNextWorkItem(ctx) { } } // processNextWorkItem will read a single work item off the workqueue and // attempt to process it, by calling the syncHandler. -func (c *Controller) processNextWorkItem(ctx context.Context) bool { +func (c *DeviceLifecycleController) processNextWorkItem(ctx context.Context) bool { objRef, shutdown := c.workqueue.Get() logger := klog.FromContext(ctx) @@ -236,99 +219,99 @@ func (c *Controller) processNextWorkItem(ctx context.Context) bool { } // syncHandler compares the actual state with the desired, and attempts to -// converge the two. It then updates the Status block of the Foo resource +// converge the two. It then updates the Status block of the NetworkDevice resource // with the current status of the resource. -func (c *Controller) syncHandler(ctx context.Context, objectRef cache.ObjectName) error { +func (c *DeviceLifecycleController) syncHandler(ctx context.Context, objectRef cache.ObjectName) error { logger := klog.LoggerWithValues(klog.FromContext(ctx), "objectRef", objectRef) - // Get the Foo resource with this namespace/name - foo, err := c.foosLister.Foos(objectRef.Namespace).Get(objectRef.Name) + // Get the NetworkDevice resource with this namespace/name + device, err := c.networkDeviceLister.NetworkDevices(objectRef.Namespace).Get(objectRef.Name) if err != nil { - // The Foo resource may no longer exist, in which case we stop + // The NetworkDevice resource may no longer exist, in which case we stop // processing. if errors.IsNotFound(err) { - utilruntime.HandleErrorWithContext(ctx, err, "Foo referenced by item in work queue no longer exists", "objectReference", objectRef) + utilruntime.HandleErrorWithContext(ctx, err, "NetworkDevice referenced by item in work queue no longer exists", "objectReference", objectRef) return nil } return err } - deploymentName := foo.Spec.DeploymentName - if deploymentName == "" { - // We choose to absorb the error here as the worker would requeue the - // resource otherwise. Instead, the next time the resource is updated - // the resource will be queued again. - utilruntime.HandleErrorWithContext(ctx, nil, "Deployment name missing from object reference", "objectReference", objectRef) + // if the status is nil, initialize it + if device.Status.State == "" { + device.Status = networkdevicev1.NetworkDeviceStatus{ + State: string(networkdevicev1.NetworkDeviceStateHealthy), + } + c.updateNetworkDeviceStatus(ctx, device) + logger.Info("Initialized NetworkDevice status", "deviceStatus", device.Status) return nil } - // Get the deployment with the name specified in Foo.spec - deployment, err := c.deploymentsLister.Deployments(foo.Namespace).Get(deploymentName) - // If the resource doesn't exist, we'll create it - if errors.IsNotFound(err) { - deployment, err = c.kubeclientset.AppsV1().Deployments(foo.Namespace).Create(ctx, newDeployment(foo), metav1.CreateOptions{FieldManager: FieldManager}) + // if device has no status or no operation, nothing to do + if device.Spec.Operation == "" { + logger.Info("NetworkDevice has no operation defined, skipping processing") + return nil } - // If an error occurs during Get/Create, we'll requeue the item so we can - // attempt processing again later. This could have been caused by a - // temporary network failure, or any other transient reason. - if err != nil { - return err + // only handle OSUpgradeOperation operations for demo purposes + if device.Spec.Operation != "OSUpgradeOperation" { + logger.Info("Ignoring NetworkDevice with unsupported operation type", "operationType", device.Spec.Operation) + return nil } - // If the Deployment is not controlled by this Foo resource, we should log - // a warning to the event recorder and return error msg. - if !metav1.IsControlledBy(deployment, foo) { - msg := fmt.Sprintf(MessageResourceExists, deployment.Name) - c.recorder.Event(foo, corev1.EventTypeWarning, ErrResourceExists, msg) - return fmt.Errorf("%s", msg) + operationHandler := opt.NewOSUpgradeOperation() + + if !operationHandler.Proceed(device) { + logger.Info("Operation action state is not 'Proceed', skipping processing", "status", device.Status) + return nil } - // If this number of the replicas on the Foo resource is specified, and the - // number does not equal the current desired replicas on the Deployment, we - // should update the Deployment resource. - if foo.Spec.Replicas != nil && *foo.Spec.Replicas != *deployment.Spec.Replicas { - logger.V(4).Info("Update deployment resource", "currentReplicas", *deployment.Spec.Replicas, "desiredReplicas", *foo.Spec.Replicas) - deployment, err = c.kubeclientset.AppsV1().Deployments(foo.Namespace).Update(ctx, newDeployment(foo), metav1.UpdateOptions{FieldManager: FieldManager}) - } + // move to the next action + nextAction, hasNext := operationHandler.NextAction(device) + if hasNext { + logger.Info("Moving to next action", "nextAction", nextAction) + device.Spec.OperationAction = nextAction + device.Status.OperationActionState = "Pending" - // If an error occurs during Update, we'll requeue the item so we can - // attempt processing again later. This could have been caused by a - // temporary network failure, or any other transient reason. - if err != nil { - return err + } else { + logger.Info("No more actions left, marking operation as Completed") + device.Status.OperationState = "Completed" } - // Finally, we update the status block of the Foo resource to reflect the - // current state of the world - err = c.updateFooStatus(ctx, foo, deployment) - if err != nil { - return err - } + c.updateNetworkDeviceStatus(ctx, device) + // just logging for demo purposes + logger.Info("Processing NetworkDevice", "deviceSpec", device.Spec, "deviceStatus", device.Status) - c.recorder.Event(foo, corev1.EventTypeNormal, SuccessSynced, MessageResourceSynced) + c.recorder.Event(device, corev1.EventTypeNormal, SuccessSynced, MessageResourceSynced) return nil } -func (c *Controller) updateFooStatus(ctx context.Context, foo *samplev1alpha1.Foo, deployment *appsv1.Deployment) error { +func (c *DeviceLifecycleController) updateNetworkDeviceStatus(ctx context.Context, device *networkdevicev1.NetworkDevice) error { // NEVER modify objects from the store. It's a read-only, local cache. // You can use DeepCopy() to make a deep copy of original object and modify this copy // Or create a copy manually for better performance - fooCopy := foo.DeepCopy() - fooCopy.Status.AvailableReplicas = deployment.Status.AvailableReplicas - // If the CustomResourceSubresources feature gate is not enabled, - // we must use Update instead of UpdateStatus to update the Status block of the Foo resource. - // UpdateStatus will not allow changes to the Spec of the resource, - // which is ideal for ensuring nothing other than resource status has been updated. - _, err := c.sampleclientset.SamplecontrollerV1alpha1().Foos(foo.Namespace).UpdateStatus(ctx, fooCopy, metav1.UpdateOptions{FieldManager: FieldManager}) + deviceCopy := device.DeepCopy() + deviceCopy.Status.State = "Healthy" + if deviceCopy.Status.LastTransitionTime == (metav1.Time{}) { + deviceCopy.Status.LastTransitionTime = metav1.Now() + } + + // set the os info in status to match spec for demo purposes + deviceCopy.Status.OsVersion = deviceCopy.Spec.OsVersion + + // logging the status update for demo purposes + logger := klog.FromContext(ctx) + msg := fmt.Sprintf("Updating NetworkDevice %s status to %v", deviceCopy.Name, deviceCopy.Status.OperationState) + logger.Info(msg) + + _, err := c.sampleclientset.Sonick8sV1().NetworkDevices(device.Namespace).UpdateStatus(ctx, deviceCopy, metav1.UpdateOptions{FieldManager: FieldManager}) return err } -// enqueueFoo takes a Foo resource and converts it into a namespace/name +// enqueueDevice takes a Device resource and converts it into a namespace/name // string which is then put onto the work queue. This method should *not* be -// passed resources of any type other than Foo. -func (c *Controller) enqueueFoo(obj interface{}) { +// passed resources of any type other than Device. +func (c *DeviceLifecycleController) enqueueDevice(obj interface{}) { if objectRef, err := cache.ObjectToName(obj); err != nil { utilruntime.HandleError(err) return @@ -338,11 +321,11 @@ func (c *Controller) enqueueFoo(obj interface{}) { } // handleObject will take any resource implementing metav1.Object and attempt -// to find the Foo resource that 'owns' it. It does this by looking at the +// to find the Device resource that 'owns' it. It does this by looking at the // objects metadata.ownerReferences field for an appropriate OwnerReference. -// It then enqueues that Foo resource to be processed. If the object does not +// It then enqueues that Device resource to be processed. If the object does not // have an appropriate OwnerReference, it will simply be skipped. -func (c *Controller) handleObject(obj interface{}) { +func (c *DeviceLifecycleController) handleObject(obj interface{}) { var object metav1.Object var ok bool logger := klog.FromContext(context.Background()) @@ -365,57 +348,19 @@ func (c *Controller) handleObject(obj interface{}) { } logger.V(4).Info("Processing object", "object", klog.KObj(object)) if ownerRef := metav1.GetControllerOf(object); ownerRef != nil { - // If this object is not owned by a Foo, we should not do anything more + // If this object is not owned by a NetworkDevice, we should not do anything more // with it. - if ownerRef.Kind != "Foo" { + if ownerRef.Kind != "NetworkDevice" { return } - foo, err := c.foosLister.Foos(object.GetNamespace()).Get(ownerRef.Name) + networkDevice, err := c.networkDeviceLister.NetworkDevices(object.GetNamespace()).Get(ownerRef.Name) if err != nil { - logger.V(4).Info("Ignore orphaned object", "object", klog.KObj(object), "foo", ownerRef.Name) + logger.V(4).Info("Ignore orphaned object", "object", klog.KObj(networkDevice), "networkDevice", ownerRef.Name) return } - c.enqueueFoo(foo) + c.enqueueDevice(networkDevice) return } } - -// newDeployment creates a new Deployment for a Foo resource. It also sets -// the appropriate OwnerReferences on the resource so handleObject can discover -// the Foo resource that 'owns' it. -func newDeployment(foo *samplev1alpha1.Foo) *appsv1.Deployment { - labels := map[string]string{ - "app": "nginx", - "controller": foo.Name, - } - return &appsv1.Deployment{ - ObjectMeta: metav1.ObjectMeta{ - Name: foo.Spec.DeploymentName, - Namespace: foo.Namespace, - OwnerReferences: []metav1.OwnerReference{ - *metav1.NewControllerRef(foo, samplev1alpha1.SchemeGroupVersion.WithKind("Foo")), - }, - }, - Spec: appsv1.DeploymentSpec{ - Replicas: foo.Spec.Replicas, - Selector: &metav1.LabelSelector{ - MatchLabels: labels, - }, - Template: corev1.PodTemplateSpec{ - ObjectMeta: metav1.ObjectMeta{ - Labels: labels, - }, - Spec: corev1.PodSpec{ - Containers: []corev1.Container{ - { - Name: "nginx", - Image: "nginx:latest", - }, - }, - }, - }, - }, - } -} diff --git a/pkg/generated/clientset/versioned/clientset.go b/pkg/generated/clientset/versioned/clientset.go index 6362e3e2b..c64e04820 100644 --- a/pkg/generated/clientset/versioned/clientset.go +++ b/pkg/generated/clientset/versioned/clientset.go @@ -25,23 +25,23 @@ import ( discovery "k8s.io/client-go/discovery" rest "k8s.io/client-go/rest" flowcontrol "k8s.io/client-go/util/flowcontrol" - samplecontrollerv1alpha1 "k8s.io/sample-controller/pkg/generated/clientset/versioned/typed/samplecontroller/v1alpha1" + sonick8sv1 "k8s.io/sample-controller/pkg/generated/clientset/versioned/typed/networkdevice/v1" ) type Interface interface { Discovery() discovery.DiscoveryInterface - SamplecontrollerV1alpha1() samplecontrollerv1alpha1.SamplecontrollerV1alpha1Interface + Sonick8sV1() sonick8sv1.Sonick8sV1Interface } // Clientset contains the clients for groups. type Clientset struct { *discovery.DiscoveryClient - samplecontrollerV1alpha1 *samplecontrollerv1alpha1.SamplecontrollerV1alpha1Client + sonick8sV1 *sonick8sv1.Sonick8sV1Client } -// SamplecontrollerV1alpha1 retrieves the SamplecontrollerV1alpha1Client -func (c *Clientset) SamplecontrollerV1alpha1() samplecontrollerv1alpha1.SamplecontrollerV1alpha1Interface { - return c.samplecontrollerV1alpha1 +// Sonick8sV1 retrieves the Sonick8sV1Client +func (c *Clientset) Sonick8sV1() sonick8sv1.Sonick8sV1Interface { + return c.sonick8sV1 } // Discovery retrieves the DiscoveryClient @@ -88,7 +88,7 @@ func NewForConfigAndClient(c *rest.Config, httpClient *http.Client) (*Clientset, var cs Clientset var err error - cs.samplecontrollerV1alpha1, err = samplecontrollerv1alpha1.NewForConfigAndClient(&configShallowCopy, httpClient) + cs.sonick8sV1, err = sonick8sv1.NewForConfigAndClient(&configShallowCopy, httpClient) if err != nil { return nil, err } @@ -113,7 +113,7 @@ func NewForConfigOrDie(c *rest.Config) *Clientset { // New creates a new Clientset for the given RESTClient. func New(c rest.Interface) *Clientset { var cs Clientset - cs.samplecontrollerV1alpha1 = samplecontrollerv1alpha1.New(c) + cs.sonick8sV1 = sonick8sv1.New(c) cs.DiscoveryClient = discovery.NewDiscoveryClient(c) return &cs diff --git a/pkg/generated/clientset/versioned/fake/clientset_generated.go b/pkg/generated/clientset/versioned/fake/clientset_generated.go index 4fe43173e..83296cd09 100644 --- a/pkg/generated/clientset/versioned/fake/clientset_generated.go +++ b/pkg/generated/clientset/versioned/fake/clientset_generated.go @@ -26,8 +26,8 @@ import ( fakediscovery "k8s.io/client-go/discovery/fake" "k8s.io/client-go/testing" clientset "k8s.io/sample-controller/pkg/generated/clientset/versioned" - samplecontrollerv1alpha1 "k8s.io/sample-controller/pkg/generated/clientset/versioned/typed/samplecontroller/v1alpha1" - fakesamplecontrollerv1alpha1 "k8s.io/sample-controller/pkg/generated/clientset/versioned/typed/samplecontroller/v1alpha1/fake" + sonick8sv1 "k8s.io/sample-controller/pkg/generated/clientset/versioned/typed/networkdevice/v1" + fakesonick8sv1 "k8s.io/sample-controller/pkg/generated/clientset/versioned/typed/networkdevice/v1/fake" ) // NewSimpleClientset returns a clientset that will respond with the provided objects. @@ -99,7 +99,7 @@ var ( _ testing.FakeClient = &Clientset{} ) -// SamplecontrollerV1alpha1 retrieves the SamplecontrollerV1alpha1Client -func (c *Clientset) SamplecontrollerV1alpha1() samplecontrollerv1alpha1.SamplecontrollerV1alpha1Interface { - return &fakesamplecontrollerv1alpha1.FakeSamplecontrollerV1alpha1{Fake: &c.Fake} +// Sonick8sV1 retrieves the Sonick8sV1Client +func (c *Clientset) Sonick8sV1() sonick8sv1.Sonick8sV1Interface { + return &fakesonick8sv1.FakeSonick8sV1{Fake: &c.Fake} } diff --git a/pkg/generated/clientset/versioned/fake/register.go b/pkg/generated/clientset/versioned/fake/register.go index 74013e464..7061ff37d 100644 --- a/pkg/generated/clientset/versioned/fake/register.go +++ b/pkg/generated/clientset/versioned/fake/register.go @@ -24,14 +24,14 @@ import ( schema "k8s.io/apimachinery/pkg/runtime/schema" serializer "k8s.io/apimachinery/pkg/runtime/serializer" utilruntime "k8s.io/apimachinery/pkg/util/runtime" - samplecontrollerv1alpha1 "k8s.io/sample-controller/pkg/apis/samplecontroller/v1alpha1" + sonick8sv1 "k8s.io/sample-controller/pkg/apis/networkdevice/v1" ) var scheme = runtime.NewScheme() var codecs = serializer.NewCodecFactory(scheme) var localSchemeBuilder = runtime.SchemeBuilder{ - samplecontrollerv1alpha1.AddToScheme, + sonick8sv1.AddToScheme, } // AddToScheme adds all types of this clientset into the given scheme. This allows composition diff --git a/pkg/generated/clientset/versioned/scheme/register.go b/pkg/generated/clientset/versioned/scheme/register.go index c3378226d..99b7b9423 100644 --- a/pkg/generated/clientset/versioned/scheme/register.go +++ b/pkg/generated/clientset/versioned/scheme/register.go @@ -24,14 +24,14 @@ import ( schema "k8s.io/apimachinery/pkg/runtime/schema" serializer "k8s.io/apimachinery/pkg/runtime/serializer" utilruntime "k8s.io/apimachinery/pkg/util/runtime" - samplecontrollerv1alpha1 "k8s.io/sample-controller/pkg/apis/samplecontroller/v1alpha1" + sonick8sv1 "k8s.io/sample-controller/pkg/apis/networkdevice/v1" ) var Scheme = runtime.NewScheme() var Codecs = serializer.NewCodecFactory(Scheme) var ParameterCodec = runtime.NewParameterCodec(Scheme) var localSchemeBuilder = runtime.SchemeBuilder{ - samplecontrollerv1alpha1.AddToScheme, + sonick8sv1.AddToScheme, } // AddToScheme adds all types of this clientset into the given scheme. This allows composition diff --git a/pkg/generated/clientset/versioned/typed/samplecontroller/v1alpha1/doc.go b/pkg/generated/clientset/versioned/typed/networkdevice/v1/doc.go similarity index 97% rename from pkg/generated/clientset/versioned/typed/samplecontroller/v1alpha1/doc.go rename to pkg/generated/clientset/versioned/typed/networkdevice/v1/doc.go index df51baa4d..3af5d054f 100644 --- a/pkg/generated/clientset/versioned/typed/samplecontroller/v1alpha1/doc.go +++ b/pkg/generated/clientset/versioned/typed/networkdevice/v1/doc.go @@ -17,4 +17,4 @@ limitations under the License. // Code generated by client-gen. DO NOT EDIT. // This package has the automatically generated typed clients. -package v1alpha1 +package v1 diff --git a/pkg/generated/clientset/versioned/typed/samplecontroller/v1alpha1/fake/doc.go b/pkg/generated/clientset/versioned/typed/networkdevice/v1/fake/doc.go similarity index 100% rename from pkg/generated/clientset/versioned/typed/samplecontroller/v1alpha1/fake/doc.go rename to pkg/generated/clientset/versioned/typed/networkdevice/v1/fake/doc.go diff --git a/pkg/generated/clientset/versioned/typed/networkdevice/v1/fake/fake_networkdevice.go b/pkg/generated/clientset/versioned/typed/networkdevice/v1/fake/fake_networkdevice.go new file mode 100644 index 000000000..097df1123 --- /dev/null +++ b/pkg/generated/clientset/versioned/typed/networkdevice/v1/fake/fake_networkdevice.go @@ -0,0 +1,50 @@ +/* +Copyright 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. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +package fake + +import ( + gentype "k8s.io/client-go/gentype" + v1 "k8s.io/sample-controller/pkg/apis/networkdevice/v1" + networkdevicev1 "k8s.io/sample-controller/pkg/generated/clientset/versioned/typed/networkdevice/v1" +) + +// fakeNetworkDevices implements NetworkDeviceInterface +type fakeNetworkDevices struct { + *gentype.FakeClientWithList[*v1.NetworkDevice, *v1.NetworkDeviceList] + Fake *FakeSonick8sV1 +} + +func newFakeNetworkDevices(fake *FakeSonick8sV1, namespace string) networkdevicev1.NetworkDeviceInterface { + return &fakeNetworkDevices{ + gentype.NewFakeClientWithList[*v1.NetworkDevice, *v1.NetworkDeviceList]( + fake.Fake, + namespace, + v1.SchemeGroupVersion.WithResource("networkdevices"), + v1.SchemeGroupVersion.WithKind("NetworkDevice"), + func() *v1.NetworkDevice { return &v1.NetworkDevice{} }, + func() *v1.NetworkDeviceList { return &v1.NetworkDeviceList{} }, + func(dst, src *v1.NetworkDeviceList) { dst.ListMeta = src.ListMeta }, + func(list *v1.NetworkDeviceList) []*v1.NetworkDevice { return gentype.ToPointerSlice(list.Items) }, + func(list *v1.NetworkDeviceList, items []*v1.NetworkDevice) { + list.Items = gentype.FromPointerSlice(items) + }, + ), + fake, + } +} diff --git a/pkg/generated/clientset/versioned/typed/samplecontroller/v1alpha1/fake/fake_samplecontroller_client.go b/pkg/generated/clientset/versioned/typed/networkdevice/v1/fake/fake_networkdevice_client.go similarity index 72% rename from pkg/generated/clientset/versioned/typed/samplecontroller/v1alpha1/fake/fake_samplecontroller_client.go rename to pkg/generated/clientset/versioned/typed/networkdevice/v1/fake/fake_networkdevice_client.go index d5dad62fe..c734e38f2 100644 --- a/pkg/generated/clientset/versioned/typed/samplecontroller/v1alpha1/fake/fake_samplecontroller_client.go +++ b/pkg/generated/clientset/versioned/typed/networkdevice/v1/fake/fake_networkdevice_client.go @@ -21,20 +21,20 @@ package fake import ( rest "k8s.io/client-go/rest" testing "k8s.io/client-go/testing" - v1alpha1 "k8s.io/sample-controller/pkg/generated/clientset/versioned/typed/samplecontroller/v1alpha1" + v1 "k8s.io/sample-controller/pkg/generated/clientset/versioned/typed/networkdevice/v1" ) -type FakeSamplecontrollerV1alpha1 struct { +type FakeSonick8sV1 struct { *testing.Fake } -func (c *FakeSamplecontrollerV1alpha1) Foos(namespace string) v1alpha1.FooInterface { - return newFakeFoos(c, namespace) +func (c *FakeSonick8sV1) NetworkDevices(namespace string) v1.NetworkDeviceInterface { + return newFakeNetworkDevices(c, namespace) } // RESTClient returns a RESTClient that is used to communicate // with API server by this client implementation. -func (c *FakeSamplecontrollerV1alpha1) RESTClient() rest.Interface { +func (c *FakeSonick8sV1) RESTClient() rest.Interface { var ret *rest.RESTClient return ret } diff --git a/pkg/generated/clientset/versioned/typed/samplecontroller/v1alpha1/generated_expansion.go b/pkg/generated/clientset/versioned/typed/networkdevice/v1/generated_expansion.go similarity index 92% rename from pkg/generated/clientset/versioned/typed/samplecontroller/v1alpha1/generated_expansion.go rename to pkg/generated/clientset/versioned/typed/networkdevice/v1/generated_expansion.go index b64ea0250..984192c28 100644 --- a/pkg/generated/clientset/versioned/typed/samplecontroller/v1alpha1/generated_expansion.go +++ b/pkg/generated/clientset/versioned/typed/networkdevice/v1/generated_expansion.go @@ -16,6 +16,6 @@ limitations under the License. // Code generated by client-gen. DO NOT EDIT. -package v1alpha1 +package v1 -type FooExpansion interface{} +type NetworkDeviceExpansion interface{} diff --git a/pkg/generated/clientset/versioned/typed/networkdevice/v1/networkdevice.go b/pkg/generated/clientset/versioned/typed/networkdevice/v1/networkdevice.go new file mode 100644 index 000000000..67fd991c2 --- /dev/null +++ b/pkg/generated/clientset/versioned/typed/networkdevice/v1/networkdevice.go @@ -0,0 +1,70 @@ +/* +Copyright 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. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +package v1 + +import ( + context "context" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + gentype "k8s.io/client-go/gentype" + networkdevicev1 "k8s.io/sample-controller/pkg/apis/networkdevice/v1" + scheme "k8s.io/sample-controller/pkg/generated/clientset/versioned/scheme" +) + +// NetworkDevicesGetter has a method to return a NetworkDeviceInterface. +// A group's client should implement this interface. +type NetworkDevicesGetter interface { + NetworkDevices(namespace string) NetworkDeviceInterface +} + +// NetworkDeviceInterface has methods to work with NetworkDevice resources. +type NetworkDeviceInterface interface { + Create(ctx context.Context, networkDevice *networkdevicev1.NetworkDevice, opts metav1.CreateOptions) (*networkdevicev1.NetworkDevice, error) + Update(ctx context.Context, networkDevice *networkdevicev1.NetworkDevice, opts metav1.UpdateOptions) (*networkdevicev1.NetworkDevice, error) + // Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). + UpdateStatus(ctx context.Context, networkDevice *networkdevicev1.NetworkDevice, opts metav1.UpdateOptions) (*networkdevicev1.NetworkDevice, error) + Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error + DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error + Get(ctx context.Context, name string, opts metav1.GetOptions) (*networkdevicev1.NetworkDevice, error) + List(ctx context.Context, opts metav1.ListOptions) (*networkdevicev1.NetworkDeviceList, error) + Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) + Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *networkdevicev1.NetworkDevice, err error) + NetworkDeviceExpansion +} + +// networkDevices implements NetworkDeviceInterface +type networkDevices struct { + *gentype.ClientWithList[*networkdevicev1.NetworkDevice, *networkdevicev1.NetworkDeviceList] +} + +// newNetworkDevices returns a NetworkDevices +func newNetworkDevices(c *Sonick8sV1Client, namespace string) *networkDevices { + return &networkDevices{ + gentype.NewClientWithList[*networkdevicev1.NetworkDevice, *networkdevicev1.NetworkDeviceList]( + "networkdevices", + c.RESTClient(), + scheme.ParameterCodec, + namespace, + func() *networkdevicev1.NetworkDevice { return &networkdevicev1.NetworkDevice{} }, + func() *networkdevicev1.NetworkDeviceList { return &networkdevicev1.NetworkDeviceList{} }, + ), + } +} diff --git a/pkg/generated/clientset/versioned/typed/samplecontroller/v1alpha1/samplecontroller_client.go b/pkg/generated/clientset/versioned/typed/networkdevice/v1/networkdevice_client.go similarity index 59% rename from pkg/generated/clientset/versioned/typed/samplecontroller/v1alpha1/samplecontroller_client.go rename to pkg/generated/clientset/versioned/typed/networkdevice/v1/networkdevice_client.go index e21476fb1..69f989bf7 100644 --- a/pkg/generated/clientset/versioned/typed/samplecontroller/v1alpha1/samplecontroller_client.go +++ b/pkg/generated/clientset/versioned/typed/networkdevice/v1/networkdevice_client.go @@ -16,34 +16,34 @@ limitations under the License. // Code generated by client-gen. DO NOT EDIT. -package v1alpha1 +package v1 import ( http "net/http" rest "k8s.io/client-go/rest" - samplecontrollerv1alpha1 "k8s.io/sample-controller/pkg/apis/samplecontroller/v1alpha1" + networkdevicev1 "k8s.io/sample-controller/pkg/apis/networkdevice/v1" scheme "k8s.io/sample-controller/pkg/generated/clientset/versioned/scheme" ) -type SamplecontrollerV1alpha1Interface interface { +type Sonick8sV1Interface interface { RESTClient() rest.Interface - FoosGetter + NetworkDevicesGetter } -// SamplecontrollerV1alpha1Client is used to interact with features provided by the samplecontroller.k8s.io group. -type SamplecontrollerV1alpha1Client struct { +// Sonick8sV1Client is used to interact with features provided by the sonick8s.io group. +type Sonick8sV1Client struct { restClient rest.Interface } -func (c *SamplecontrollerV1alpha1Client) Foos(namespace string) FooInterface { - return newFoos(c, namespace) +func (c *Sonick8sV1Client) NetworkDevices(namespace string) NetworkDeviceInterface { + return newNetworkDevices(c, namespace) } -// NewForConfig creates a new SamplecontrollerV1alpha1Client for the given config. +// NewForConfig creates a new Sonick8sV1Client for the given config. // NewForConfig is equivalent to NewForConfigAndClient(c, httpClient), // where httpClient was generated with rest.HTTPClientFor(c). -func NewForConfig(c *rest.Config) (*SamplecontrollerV1alpha1Client, error) { +func NewForConfig(c *rest.Config) (*Sonick8sV1Client, error) { config := *c setConfigDefaults(&config) httpClient, err := rest.HTTPClientFor(&config) @@ -53,21 +53,21 @@ func NewForConfig(c *rest.Config) (*SamplecontrollerV1alpha1Client, error) { return NewForConfigAndClient(&config, httpClient) } -// NewForConfigAndClient creates a new SamplecontrollerV1alpha1Client for the given config and http client. +// NewForConfigAndClient creates a new Sonick8sV1Client 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) (*SamplecontrollerV1alpha1Client, error) { +func NewForConfigAndClient(c *rest.Config, h *http.Client) (*Sonick8sV1Client, error) { config := *c setConfigDefaults(&config) client, err := rest.RESTClientForConfigAndClient(&config, h) if err != nil { return nil, err } - return &SamplecontrollerV1alpha1Client{client}, nil + return &Sonick8sV1Client{client}, nil } -// NewForConfigOrDie creates a new SamplecontrollerV1alpha1Client for the given config and +// NewForConfigOrDie creates a new Sonick8sV1Client for the given config and // panics if there is an error in the config. -func NewForConfigOrDie(c *rest.Config) *SamplecontrollerV1alpha1Client { +func NewForConfigOrDie(c *rest.Config) *Sonick8sV1Client { client, err := NewForConfig(c) if err != nil { panic(err) @@ -75,13 +75,13 @@ func NewForConfigOrDie(c *rest.Config) *SamplecontrollerV1alpha1Client { return client } -// New creates a new SamplecontrollerV1alpha1Client for the given RESTClient. -func New(c rest.Interface) *SamplecontrollerV1alpha1Client { - return &SamplecontrollerV1alpha1Client{c} +// New creates a new Sonick8sV1Client for the given RESTClient. +func New(c rest.Interface) *Sonick8sV1Client { + return &Sonick8sV1Client{c} } func setConfigDefaults(config *rest.Config) { - gv := samplecontrollerv1alpha1.SchemeGroupVersion + gv := networkdevicev1.SchemeGroupVersion config.GroupVersion = &gv config.APIPath = "/apis" config.NegotiatedSerializer = rest.CodecFactoryForGeneratedClient(scheme.Scheme, scheme.Codecs).WithoutConversion() @@ -93,7 +93,7 @@ func setConfigDefaults(config *rest.Config) { // RESTClient returns a RESTClient that is used to communicate // with API server by this client implementation. -func (c *SamplecontrollerV1alpha1Client) RESTClient() rest.Interface { +func (c *Sonick8sV1Client) RESTClient() rest.Interface { if c == nil { return nil } diff --git a/pkg/generated/clientset/versioned/typed/samplecontroller/v1alpha1/fake/fake_foo.go b/pkg/generated/clientset/versioned/typed/samplecontroller/v1alpha1/fake/fake_foo.go deleted file mode 100644 index a3a767f17..000000000 --- a/pkg/generated/clientset/versioned/typed/samplecontroller/v1alpha1/fake/fake_foo.go +++ /dev/null @@ -1,48 +0,0 @@ -/* -Copyright 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. -*/ - -// Code generated by client-gen. DO NOT EDIT. - -package fake - -import ( - gentype "k8s.io/client-go/gentype" - v1alpha1 "k8s.io/sample-controller/pkg/apis/samplecontroller/v1alpha1" - samplecontrollerv1alpha1 "k8s.io/sample-controller/pkg/generated/clientset/versioned/typed/samplecontroller/v1alpha1" -) - -// fakeFoos implements FooInterface -type fakeFoos struct { - *gentype.FakeClientWithList[*v1alpha1.Foo, *v1alpha1.FooList] - Fake *FakeSamplecontrollerV1alpha1 -} - -func newFakeFoos(fake *FakeSamplecontrollerV1alpha1, namespace string) samplecontrollerv1alpha1.FooInterface { - return &fakeFoos{ - gentype.NewFakeClientWithList[*v1alpha1.Foo, *v1alpha1.FooList]( - fake.Fake, - namespace, - v1alpha1.SchemeGroupVersion.WithResource("foos"), - v1alpha1.SchemeGroupVersion.WithKind("Foo"), - func() *v1alpha1.Foo { return &v1alpha1.Foo{} }, - func() *v1alpha1.FooList { return &v1alpha1.FooList{} }, - func(dst, src *v1alpha1.FooList) { dst.ListMeta = src.ListMeta }, - func(list *v1alpha1.FooList) []*v1alpha1.Foo { return gentype.ToPointerSlice(list.Items) }, - func(list *v1alpha1.FooList, items []*v1alpha1.Foo) { list.Items = gentype.FromPointerSlice(items) }, - ), - fake, - } -} diff --git a/pkg/generated/clientset/versioned/typed/samplecontroller/v1alpha1/foo.go b/pkg/generated/clientset/versioned/typed/samplecontroller/v1alpha1/foo.go deleted file mode 100644 index e44caa8dc..000000000 --- a/pkg/generated/clientset/versioned/typed/samplecontroller/v1alpha1/foo.go +++ /dev/null @@ -1,70 +0,0 @@ -/* -Copyright 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. -*/ - -// Code generated by client-gen. DO NOT EDIT. - -package v1alpha1 - -import ( - context "context" - - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - types "k8s.io/apimachinery/pkg/types" - watch "k8s.io/apimachinery/pkg/watch" - gentype "k8s.io/client-go/gentype" - samplecontrollerv1alpha1 "k8s.io/sample-controller/pkg/apis/samplecontroller/v1alpha1" - scheme "k8s.io/sample-controller/pkg/generated/clientset/versioned/scheme" -) - -// FoosGetter has a method to return a FooInterface. -// A group's client should implement this interface. -type FoosGetter interface { - Foos(namespace string) FooInterface -} - -// FooInterface has methods to work with Foo resources. -type FooInterface interface { - Create(ctx context.Context, foo *samplecontrollerv1alpha1.Foo, opts v1.CreateOptions) (*samplecontrollerv1alpha1.Foo, error) - Update(ctx context.Context, foo *samplecontrollerv1alpha1.Foo, opts v1.UpdateOptions) (*samplecontrollerv1alpha1.Foo, error) - // Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). - UpdateStatus(ctx context.Context, foo *samplecontrollerv1alpha1.Foo, opts v1.UpdateOptions) (*samplecontrollerv1alpha1.Foo, 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) (*samplecontrollerv1alpha1.Foo, error) - List(ctx context.Context, opts v1.ListOptions) (*samplecontrollerv1alpha1.FooList, 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 *samplecontrollerv1alpha1.Foo, err error) - FooExpansion -} - -// foos implements FooInterface -type foos struct { - *gentype.ClientWithList[*samplecontrollerv1alpha1.Foo, *samplecontrollerv1alpha1.FooList] -} - -// newFoos returns a Foos -func newFoos(c *SamplecontrollerV1alpha1Client, namespace string) *foos { - return &foos{ - gentype.NewClientWithList[*samplecontrollerv1alpha1.Foo, *samplecontrollerv1alpha1.FooList]( - "foos", - c.RESTClient(), - scheme.ParameterCodec, - namespace, - func() *samplecontrollerv1alpha1.Foo { return &samplecontrollerv1alpha1.Foo{} }, - func() *samplecontrollerv1alpha1.FooList { return &samplecontrollerv1alpha1.FooList{} }, - ), - } -} diff --git a/pkg/generated/informers/externalversions/factory.go b/pkg/generated/informers/externalversions/factory.go index d04a0c451..9d11bb7e8 100644 --- a/pkg/generated/informers/externalversions/factory.go +++ b/pkg/generated/informers/externalversions/factory.go @@ -29,7 +29,7 @@ import ( cache "k8s.io/client-go/tools/cache" versioned "k8s.io/sample-controller/pkg/generated/clientset/versioned" internalinterfaces "k8s.io/sample-controller/pkg/generated/informers/externalversions/internalinterfaces" - samplecontroller "k8s.io/sample-controller/pkg/generated/informers/externalversions/samplecontroller" + networkdevice "k8s.io/sample-controller/pkg/generated/informers/externalversions/networkdevice" ) // SharedInformerOption defines the functional option type for SharedInformerFactory. @@ -255,9 +255,9 @@ type SharedInformerFactory interface { // client. InformerFor(obj runtime.Object, newFunc internalinterfaces.NewInformerFunc) cache.SharedIndexInformer - Samplecontroller() samplecontroller.Interface + Sonick8s() networkdevice.Interface } -func (f *sharedInformerFactory) Samplecontroller() samplecontroller.Interface { - return samplecontroller.New(f, f.namespace, f.tweakListOptions) +func (f *sharedInformerFactory) Sonick8s() networkdevice.Interface { + return networkdevice.New(f, f.namespace, f.tweakListOptions) } diff --git a/pkg/generated/informers/externalversions/generic.go b/pkg/generated/informers/externalversions/generic.go index dbb89d316..c63ce5469 100644 --- a/pkg/generated/informers/externalversions/generic.go +++ b/pkg/generated/informers/externalversions/generic.go @@ -23,7 +23,7 @@ import ( schema "k8s.io/apimachinery/pkg/runtime/schema" cache "k8s.io/client-go/tools/cache" - v1alpha1 "k8s.io/sample-controller/pkg/apis/samplecontroller/v1alpha1" + v1 "k8s.io/sample-controller/pkg/apis/networkdevice/v1" ) // GenericInformer is type of SharedIndexInformer which will locate and delegate to other @@ -52,9 +52,9 @@ func (f *genericInformer) Lister() cache.GenericLister { // TODO extend this to unknown resources with a client pool func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource) (GenericInformer, error) { switch resource { - // Group=samplecontroller.k8s.io, Version=v1alpha1 - case v1alpha1.SchemeGroupVersion.WithResource("foos"): - return &genericInformer{resource: resource.GroupResource(), informer: f.Samplecontroller().V1alpha1().Foos().Informer()}, nil + // Group=sonick8s.io, Version=v1 + case v1.SchemeGroupVersion.WithResource("networkdevices"): + return &genericInformer{resource: resource.GroupResource(), informer: f.Sonick8s().V1().NetworkDevices().Informer()}, nil } diff --git a/pkg/generated/informers/externalversions/samplecontroller/interface.go b/pkg/generated/informers/externalversions/networkdevice/interface.go similarity index 76% rename from pkg/generated/informers/externalversions/samplecontroller/interface.go rename to pkg/generated/informers/externalversions/networkdevice/interface.go index d06266ac5..4069cd360 100644 --- a/pkg/generated/informers/externalversions/samplecontroller/interface.go +++ b/pkg/generated/informers/externalversions/networkdevice/interface.go @@ -16,17 +16,17 @@ limitations under the License. // Code generated by informer-gen. DO NOT EDIT. -package samplecontroller +package networkdevice import ( internalinterfaces "k8s.io/sample-controller/pkg/generated/informers/externalversions/internalinterfaces" - v1alpha1 "k8s.io/sample-controller/pkg/generated/informers/externalversions/samplecontroller/v1alpha1" + v1 "k8s.io/sample-controller/pkg/generated/informers/externalversions/networkdevice/v1" ) // 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 + // V1 provides access to shared informers for resources in V1. + V1() v1.Interface } type group struct { @@ -40,7 +40,7 @@ func New(f internalinterfaces.SharedInformerFactory, namespace string, tweakList 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) +// V1 returns a new v1.Interface. +func (g *group) V1() v1.Interface { + return v1.New(g.factory, g.namespace, g.tweakListOptions) } diff --git a/pkg/generated/informers/externalversions/samplecontroller/v1alpha1/interface.go b/pkg/generated/informers/externalversions/networkdevice/v1/interface.go similarity index 79% rename from pkg/generated/informers/externalversions/samplecontroller/v1alpha1/interface.go rename to pkg/generated/informers/externalversions/networkdevice/v1/interface.go index 403b02760..56fd687a6 100644 --- a/pkg/generated/informers/externalversions/samplecontroller/v1alpha1/interface.go +++ b/pkg/generated/informers/externalversions/networkdevice/v1/interface.go @@ -16,7 +16,7 @@ limitations under the License. // Code generated by informer-gen. DO NOT EDIT. -package v1alpha1 +package v1 import ( internalinterfaces "k8s.io/sample-controller/pkg/generated/informers/externalversions/internalinterfaces" @@ -24,8 +24,8 @@ import ( // Interface provides access to all the informers in this group version. type Interface interface { - // Foos returns a FooInformer. - Foos() FooInformer + // NetworkDevices returns a NetworkDeviceInformer. + NetworkDevices() NetworkDeviceInformer } type version struct { @@ -39,7 +39,7 @@ func New(f internalinterfaces.SharedInformerFactory, namespace string, tweakList return &version{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} } -// Foos returns a FooInformer. -func (v *version) Foos() FooInformer { - return &fooInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} +// NetworkDevices returns a NetworkDeviceInformer. +func (v *version) NetworkDevices() NetworkDeviceInformer { + return &networkDeviceInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} } diff --git a/pkg/generated/informers/externalversions/networkdevice/v1/networkdevice.go b/pkg/generated/informers/externalversions/networkdevice/v1/networkdevice.go new file mode 100644 index 000000000..babe7f3fc --- /dev/null +++ b/pkg/generated/informers/externalversions/networkdevice/v1/networkdevice.go @@ -0,0 +1,102 @@ +/* +Copyright 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. +*/ + +// Code generated by informer-gen. DO NOT EDIT. + +package v1 + +import ( + context "context" + time "time" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + watch "k8s.io/apimachinery/pkg/watch" + cache "k8s.io/client-go/tools/cache" + apisnetworkdevicev1 "k8s.io/sample-controller/pkg/apis/networkdevice/v1" + versioned "k8s.io/sample-controller/pkg/generated/clientset/versioned" + internalinterfaces "k8s.io/sample-controller/pkg/generated/informers/externalversions/internalinterfaces" + networkdevicev1 "k8s.io/sample-controller/pkg/generated/listers/networkdevice/v1" +) + +// NetworkDeviceInformer provides access to a shared informer and lister for +// NetworkDevices. +type NetworkDeviceInformer interface { + Informer() cache.SharedIndexInformer + Lister() networkdevicev1.NetworkDeviceLister +} + +type networkDeviceInformer struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc + namespace string +} + +// NewNetworkDeviceInformer constructs a new informer for NetworkDevice 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 NewNetworkDeviceInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return NewFilteredNetworkDeviceInformer(client, namespace, resyncPeriod, indexers, nil) +} + +// NewFilteredNetworkDeviceInformer constructs a new informer for NetworkDevice 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 NewFilteredNetworkDeviceInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { + return cache.NewSharedIndexInformer( + cache.ToListWatcherWithWatchListSemantics(&cache.ListWatch{ + ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.Sonick8sV1().NetworkDevices(namespace).List(context.Background(), options) + }, + WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.Sonick8sV1().NetworkDevices(namespace).Watch(context.Background(), options) + }, + ListWithContextFunc: func(ctx context.Context, options metav1.ListOptions) (runtime.Object, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.Sonick8sV1().NetworkDevices(namespace).List(ctx, options) + }, + WatchFuncWithContext: func(ctx context.Context, options metav1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.Sonick8sV1().NetworkDevices(namespace).Watch(ctx, options) + }, + }, client), + &apisnetworkdevicev1.NetworkDevice{}, + resyncPeriod, + indexers, + ) +} + +func (f *networkDeviceInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewFilteredNetworkDeviceInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) +} + +func (f *networkDeviceInformer) Informer() cache.SharedIndexInformer { + return f.factory.InformerFor(&apisnetworkdevicev1.NetworkDevice{}, f.defaultInformer) +} + +func (f *networkDeviceInformer) Lister() networkdevicev1.NetworkDeviceLister { + return networkdevicev1.NewNetworkDeviceLister(f.Informer().GetIndexer()) +} diff --git a/pkg/generated/informers/externalversions/samplecontroller/v1alpha1/foo.go b/pkg/generated/informers/externalversions/samplecontroller/v1alpha1/foo.go deleted file mode 100644 index 658033c20..000000000 --- a/pkg/generated/informers/externalversions/samplecontroller/v1alpha1/foo.go +++ /dev/null @@ -1,102 +0,0 @@ -/* -Copyright 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. -*/ - -// Code generated by informer-gen. DO NOT EDIT. - -package v1alpha1 - -import ( - context "context" - time "time" - - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - runtime "k8s.io/apimachinery/pkg/runtime" - watch "k8s.io/apimachinery/pkg/watch" - cache "k8s.io/client-go/tools/cache" - apissamplecontrollerv1alpha1 "k8s.io/sample-controller/pkg/apis/samplecontroller/v1alpha1" - versioned "k8s.io/sample-controller/pkg/generated/clientset/versioned" - internalinterfaces "k8s.io/sample-controller/pkg/generated/informers/externalversions/internalinterfaces" - samplecontrollerv1alpha1 "k8s.io/sample-controller/pkg/generated/listers/samplecontroller/v1alpha1" -) - -// FooInformer provides access to a shared informer and lister for -// Foos. -type FooInformer interface { - Informer() cache.SharedIndexInformer - Lister() samplecontrollerv1alpha1.FooLister -} - -type fooInformer struct { - factory internalinterfaces.SharedInformerFactory - tweakListOptions internalinterfaces.TweakListOptionsFunc - namespace string -} - -// NewFooInformer constructs a new informer for Foo 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 NewFooInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { - return NewFilteredFooInformer(client, namespace, resyncPeriod, indexers, nil) -} - -// NewFilteredFooInformer constructs a new informer for Foo 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 NewFilteredFooInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { - return cache.NewSharedIndexInformer( - cache.ToListWatcherWithWatchListSemantics(&cache.ListWatch{ - ListFunc: func(options v1.ListOptions) (runtime.Object, error) { - if tweakListOptions != nil { - tweakListOptions(&options) - } - return client.SamplecontrollerV1alpha1().Foos(namespace).List(context.Background(), options) - }, - WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { - if tweakListOptions != nil { - tweakListOptions(&options) - } - return client.SamplecontrollerV1alpha1().Foos(namespace).Watch(context.Background(), options) - }, - ListWithContextFunc: func(ctx context.Context, options v1.ListOptions) (runtime.Object, error) { - if tweakListOptions != nil { - tweakListOptions(&options) - } - return client.SamplecontrollerV1alpha1().Foos(namespace).List(ctx, options) - }, - WatchFuncWithContext: func(ctx context.Context, options v1.ListOptions) (watch.Interface, error) { - if tweakListOptions != nil { - tweakListOptions(&options) - } - return client.SamplecontrollerV1alpha1().Foos(namespace).Watch(ctx, options) - }, - }, client), - &apissamplecontrollerv1alpha1.Foo{}, - resyncPeriod, - indexers, - ) -} - -func (f *fooInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { - return NewFilteredFooInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) -} - -func (f *fooInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&apissamplecontrollerv1alpha1.Foo{}, f.defaultInformer) -} - -func (f *fooInformer) Lister() samplecontrollerv1alpha1.FooLister { - return samplecontrollerv1alpha1.NewFooLister(f.Informer().GetIndexer()) -} diff --git a/pkg/generated/listers/samplecontroller/v1alpha1/expansion_generated.go b/pkg/generated/listers/networkdevice/v1/expansion_generated.go similarity index 66% rename from pkg/generated/listers/samplecontroller/v1alpha1/expansion_generated.go rename to pkg/generated/listers/networkdevice/v1/expansion_generated.go index 9a34636b0..78d12856b 100644 --- a/pkg/generated/listers/samplecontroller/v1alpha1/expansion_generated.go +++ b/pkg/generated/listers/networkdevice/v1/expansion_generated.go @@ -16,12 +16,12 @@ limitations under the License. // Code generated by lister-gen. DO NOT EDIT. -package v1alpha1 +package v1 -// FooListerExpansion allows custom methods to be added to -// FooLister. -type FooListerExpansion interface{} +// NetworkDeviceListerExpansion allows custom methods to be added to +// NetworkDeviceLister. +type NetworkDeviceListerExpansion interface{} -// FooNamespaceListerExpansion allows custom methods to be added to -// FooNamespaceLister. -type FooNamespaceListerExpansion interface{} +// NetworkDeviceNamespaceListerExpansion allows custom methods to be added to +// NetworkDeviceNamespaceLister. +type NetworkDeviceNamespaceListerExpansion interface{} diff --git a/pkg/generated/listers/networkdevice/v1/networkdevice.go b/pkg/generated/listers/networkdevice/v1/networkdevice.go new file mode 100644 index 000000000..9d8530515 --- /dev/null +++ b/pkg/generated/listers/networkdevice/v1/networkdevice.go @@ -0,0 +1,70 @@ +/* +Copyright 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. +*/ + +// Code generated by lister-gen. DO NOT EDIT. + +package v1 + +import ( + labels "k8s.io/apimachinery/pkg/labels" + listers "k8s.io/client-go/listers" + cache "k8s.io/client-go/tools/cache" + networkdevicev1 "k8s.io/sample-controller/pkg/apis/networkdevice/v1" +) + +// NetworkDeviceLister helps list NetworkDevices. +// All objects returned here must be treated as read-only. +type NetworkDeviceLister interface { + // List lists all NetworkDevices in the indexer. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*networkdevicev1.NetworkDevice, err error) + // NetworkDevices returns an object that can list and get NetworkDevices. + NetworkDevices(namespace string) NetworkDeviceNamespaceLister + NetworkDeviceListerExpansion +} + +// networkDeviceLister implements the NetworkDeviceLister interface. +type networkDeviceLister struct { + listers.ResourceIndexer[*networkdevicev1.NetworkDevice] +} + +// NewNetworkDeviceLister returns a new NetworkDeviceLister. +func NewNetworkDeviceLister(indexer cache.Indexer) NetworkDeviceLister { + return &networkDeviceLister{listers.New[*networkdevicev1.NetworkDevice](indexer, networkdevicev1.Resource("networkdevice"))} +} + +// NetworkDevices returns an object that can list and get NetworkDevices. +func (s *networkDeviceLister) NetworkDevices(namespace string) NetworkDeviceNamespaceLister { + return networkDeviceNamespaceLister{listers.NewNamespaced[*networkdevicev1.NetworkDevice](s.ResourceIndexer, namespace)} +} + +// NetworkDeviceNamespaceLister helps list and get NetworkDevices. +// All objects returned here must be treated as read-only. +type NetworkDeviceNamespaceLister interface { + // List lists all NetworkDevices in the indexer for a given namespace. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*networkdevicev1.NetworkDevice, err error) + // Get retrieves the NetworkDevice from the indexer for a given namespace and name. + // Objects returned here must be treated as read-only. + Get(name string) (*networkdevicev1.NetworkDevice, error) + NetworkDeviceNamespaceListerExpansion +} + +// networkDeviceNamespaceLister implements the NetworkDeviceNamespaceLister +// interface. +type networkDeviceNamespaceLister struct { + listers.ResourceIndexer[*networkdevicev1.NetworkDevice] +} diff --git a/pkg/generated/listers/samplecontroller/v1alpha1/foo.go b/pkg/generated/listers/samplecontroller/v1alpha1/foo.go deleted file mode 100644 index cbe948fe3..000000000 --- a/pkg/generated/listers/samplecontroller/v1alpha1/foo.go +++ /dev/null @@ -1,70 +0,0 @@ -/* -Copyright 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. -*/ - -// Code generated by lister-gen. DO NOT EDIT. - -package v1alpha1 - -import ( - labels "k8s.io/apimachinery/pkg/labels" - listers "k8s.io/client-go/listers" - cache "k8s.io/client-go/tools/cache" - samplecontrollerv1alpha1 "k8s.io/sample-controller/pkg/apis/samplecontroller/v1alpha1" -) - -// FooLister helps list Foos. -// All objects returned here must be treated as read-only. -type FooLister interface { - // List lists all Foos in the indexer. - // Objects returned here must be treated as read-only. - List(selector labels.Selector) (ret []*samplecontrollerv1alpha1.Foo, err error) - // Foos returns an object that can list and get Foos. - Foos(namespace string) FooNamespaceLister - FooListerExpansion -} - -// fooLister implements the FooLister interface. -type fooLister struct { - listers.ResourceIndexer[*samplecontrollerv1alpha1.Foo] -} - -// NewFooLister returns a new FooLister. -func NewFooLister(indexer cache.Indexer) FooLister { - return &fooLister{listers.New[*samplecontrollerv1alpha1.Foo](indexer, samplecontrollerv1alpha1.Resource("foo"))} -} - -// Foos returns an object that can list and get Foos. -func (s *fooLister) Foos(namespace string) FooNamespaceLister { - return fooNamespaceLister{listers.NewNamespaced[*samplecontrollerv1alpha1.Foo](s.ResourceIndexer, namespace)} -} - -// FooNamespaceLister helps list and get Foos. -// All objects returned here must be treated as read-only. -type FooNamespaceLister interface { - // List lists all Foos in the indexer for a given namespace. - // Objects returned here must be treated as read-only. - List(selector labels.Selector) (ret []*samplecontrollerv1alpha1.Foo, err error) - // Get retrieves the Foo from the indexer for a given namespace and name. - // Objects returned here must be treated as read-only. - Get(name string) (*samplecontrollerv1alpha1.Foo, error) - FooNamespaceListerExpansion -} - -// fooNamespaceLister implements the FooNamespaceLister -// interface. -type fooNamespaceLister struct { - listers.ResourceIndexer[*samplecontrollerv1alpha1.Foo] -} diff --git a/pkg/networkdevice/generated/clientset/versioned/clientset.go b/pkg/networkdevice/generated/clientset/versioned/clientset.go new file mode 100644 index 000000000..a42b65035 --- /dev/null +++ b/pkg/networkdevice/generated/clientset/versioned/clientset.go @@ -0,0 +1,120 @@ +/* +Copyright 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. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +package versioned + +import ( + fmt "fmt" + http "net/http" + + discovery "k8s.io/client-go/discovery" + rest "k8s.io/client-go/rest" + flowcontrol "k8s.io/client-go/util/flowcontrol" + sonick8sv1 "k8s.io/sample-controller/pkg/networkdevice/generated/clientset/versioned/typed/networkdevice/v1" +) + +type Interface interface { + Discovery() discovery.DiscoveryInterface + Sonick8sV1() sonick8sv1.Sonick8sV1Interface +} + +// Clientset contains the clients for groups. +type Clientset struct { + *discovery.DiscoveryClient + sonick8sV1 *sonick8sv1.Sonick8sV1Client +} + +// Sonick8sV1 retrieves the Sonick8sV1Client +func (c *Clientset) Sonick8sV1() sonick8sv1.Sonick8sV1Interface { + return c.sonick8sV1 +} + +// 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.sonick8sV1, err = sonick8sv1.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.sonick8sV1 = sonick8sv1.New(c) + + cs.DiscoveryClient = discovery.NewDiscoveryClient(c) + return &cs +} diff --git a/pkg/networkdevice/generated/clientset/versioned/fake/clientset_generated.go b/pkg/networkdevice/generated/clientset/versioned/fake/clientset_generated.go new file mode 100644 index 000000000..807f430cb --- /dev/null +++ b/pkg/networkdevice/generated/clientset/versioned/fake/clientset_generated.go @@ -0,0 +1,105 @@ +/* +Copyright 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. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +package fake + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "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" + clientset "k8s.io/sample-controller/pkg/networkdevice/generated/clientset/versioned" + sonick8sv1 "k8s.io/sample-controller/pkg/networkdevice/generated/clientset/versioned/typed/networkdevice/v1" + fakesonick8sv1 "k8s.io/sample-controller/pkg/networkdevice/generated/clientset/versioned/typed/networkdevice/v1/fake" +) + +// 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 field management, validations and/or defaults. It shouldn't be considered a replacement +// for a real clientset and is mostly useful in simple unit tests. +// +// Deprecated: NewClientset replaces this with support for field management, which significantly improves +// server side apply testing. NewClientset is only available when apply configurations are generated (e.g. +// via --with-applyconfig). +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) { + var opts metav1.ListOptions + if watchAction, ok := action.(testing.WatchActionImpl); ok { + opts = watchAction.ListOptions + } + gvr := action.GetResource() + ns := action.GetNamespace() + watch, err := o.Watch(gvr, ns, opts) + 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 +} + +// IsWatchListSemanticsSupported informs the reflector that this client +// doesn't support WatchList semantics. +// +// This is a synthetic method whose sole purpose is to satisfy the optional +// interface check performed by the reflector. +// Returning true signals that WatchList can NOT be used. +// No additional logic is implemented here. +func (c *Clientset) IsWatchListSemanticsUnSupported() bool { + return true +} + +var ( + _ clientset.Interface = &Clientset{} + _ testing.FakeClient = &Clientset{} +) + +// Sonick8sV1 retrieves the Sonick8sV1Client +func (c *Clientset) Sonick8sV1() sonick8sv1.Sonick8sV1Interface { + return &fakesonick8sv1.FakeSonick8sV1{Fake: &c.Fake} +} diff --git a/pkg/networkdevice/generated/clientset/versioned/fake/doc.go b/pkg/networkdevice/generated/clientset/versioned/fake/doc.go new file mode 100644 index 000000000..9b99e7167 --- /dev/null +++ b/pkg/networkdevice/generated/clientset/versioned/fake/doc.go @@ -0,0 +1,20 @@ +/* +Copyright 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. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +// This package has the automatically generated fake clientset. +package fake diff --git a/pkg/networkdevice/generated/clientset/versioned/fake/register.go b/pkg/networkdevice/generated/clientset/versioned/fake/register.go new file mode 100644 index 000000000..7061ff37d --- /dev/null +++ b/pkg/networkdevice/generated/clientset/versioned/fake/register.go @@ -0,0 +1,56 @@ +/* +Copyright 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. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +package fake + +import ( + 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" + sonick8sv1 "k8s.io/sample-controller/pkg/apis/networkdevice/v1" +) + +var scheme = runtime.NewScheme() +var codecs = serializer.NewCodecFactory(scheme) + +var localSchemeBuilder = runtime.SchemeBuilder{ + sonick8sv1.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/networkdevice/generated/clientset/versioned/scheme/doc.go b/pkg/networkdevice/generated/clientset/versioned/scheme/doc.go new file mode 100644 index 000000000..7dc375616 --- /dev/null +++ b/pkg/networkdevice/generated/clientset/versioned/scheme/doc.go @@ -0,0 +1,20 @@ +/* +Copyright 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. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +// This package contains the scheme of the automatically generated clientset. +package scheme diff --git a/pkg/networkdevice/generated/clientset/versioned/scheme/register.go b/pkg/networkdevice/generated/clientset/versioned/scheme/register.go new file mode 100644 index 000000000..99b7b9423 --- /dev/null +++ b/pkg/networkdevice/generated/clientset/versioned/scheme/register.go @@ -0,0 +1,56 @@ +/* +Copyright 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. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +package scheme + +import ( + 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" + sonick8sv1 "k8s.io/sample-controller/pkg/apis/networkdevice/v1" +) + +var Scheme = runtime.NewScheme() +var Codecs = serializer.NewCodecFactory(Scheme) +var ParameterCodec = runtime.NewParameterCodec(Scheme) +var localSchemeBuilder = runtime.SchemeBuilder{ + sonick8sv1.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/networkdevice/generated/clientset/versioned/typed/networkdevice/v1/doc.go b/pkg/networkdevice/generated/clientset/versioned/typed/networkdevice/v1/doc.go new file mode 100644 index 000000000..3af5d054f --- /dev/null +++ b/pkg/networkdevice/generated/clientset/versioned/typed/networkdevice/v1/doc.go @@ -0,0 +1,20 @@ +/* +Copyright 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. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +// This package has the automatically generated typed clients. +package v1 diff --git a/pkg/networkdevice/generated/clientset/versioned/typed/networkdevice/v1/fake/doc.go b/pkg/networkdevice/generated/clientset/versioned/typed/networkdevice/v1/fake/doc.go new file mode 100644 index 000000000..16f443990 --- /dev/null +++ b/pkg/networkdevice/generated/clientset/versioned/typed/networkdevice/v1/fake/doc.go @@ -0,0 +1,20 @@ +/* +Copyright 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. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +// Package fake has the automatically generated clients. +package fake diff --git a/pkg/networkdevice/generated/clientset/versioned/typed/networkdevice/v1/fake/fake_networkdevice.go b/pkg/networkdevice/generated/clientset/versioned/typed/networkdevice/v1/fake/fake_networkdevice.go new file mode 100644 index 000000000..70197913f --- /dev/null +++ b/pkg/networkdevice/generated/clientset/versioned/typed/networkdevice/v1/fake/fake_networkdevice.go @@ -0,0 +1,50 @@ +/* +Copyright 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. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +package fake + +import ( + gentype "k8s.io/client-go/gentype" + v1 "k8s.io/sample-controller/pkg/apis/networkdevice/v1" + networkdevicev1 "k8s.io/sample-controller/pkg/networkdevice/generated/clientset/versioned/typed/networkdevice/v1" +) + +// fakeNetworkDevices implements NetworkDeviceInterface +type fakeNetworkDevices struct { + *gentype.FakeClientWithList[*v1.NetworkDevice, *v1.NetworkDeviceList] + Fake *FakeSonick8sV1 +} + +func newFakeNetworkDevices(fake *FakeSonick8sV1, namespace string) networkdevicev1.NetworkDeviceInterface { + return &fakeNetworkDevices{ + gentype.NewFakeClientWithList[*v1.NetworkDevice, *v1.NetworkDeviceList]( + fake.Fake, + namespace, + v1.SchemeGroupVersion.WithResource("networkdevices"), + v1.SchemeGroupVersion.WithKind("NetworkDevice"), + func() *v1.NetworkDevice { return &v1.NetworkDevice{} }, + func() *v1.NetworkDeviceList { return &v1.NetworkDeviceList{} }, + func(dst, src *v1.NetworkDeviceList) { dst.ListMeta = src.ListMeta }, + func(list *v1.NetworkDeviceList) []*v1.NetworkDevice { return gentype.ToPointerSlice(list.Items) }, + func(list *v1.NetworkDeviceList, items []*v1.NetworkDevice) { + list.Items = gentype.FromPointerSlice(items) + }, + ), + fake, + } +} diff --git a/pkg/networkdevice/generated/clientset/versioned/typed/networkdevice/v1/fake/fake_networkdevice_client.go b/pkg/networkdevice/generated/clientset/versioned/typed/networkdevice/v1/fake/fake_networkdevice_client.go new file mode 100644 index 000000000..53661ba29 --- /dev/null +++ b/pkg/networkdevice/generated/clientset/versioned/typed/networkdevice/v1/fake/fake_networkdevice_client.go @@ -0,0 +1,40 @@ +/* +Copyright 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. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +package fake + +import ( + rest "k8s.io/client-go/rest" + testing "k8s.io/client-go/testing" + v1 "k8s.io/sample-controller/pkg/networkdevice/generated/clientset/versioned/typed/networkdevice/v1" +) + +type FakeSonick8sV1 struct { + *testing.Fake +} + +func (c *FakeSonick8sV1) NetworkDevices(namespace string) v1.NetworkDeviceInterface { + return newFakeNetworkDevices(c, namespace) +} + +// RESTClient returns a RESTClient that is used to communicate +// with API server by this client implementation. +func (c *FakeSonick8sV1) RESTClient() rest.Interface { + var ret *rest.RESTClient + return ret +} diff --git a/pkg/networkdevice/generated/clientset/versioned/typed/networkdevice/v1/generated_expansion.go b/pkg/networkdevice/generated/clientset/versioned/typed/networkdevice/v1/generated_expansion.go new file mode 100644 index 000000000..984192c28 --- /dev/null +++ b/pkg/networkdevice/generated/clientset/versioned/typed/networkdevice/v1/generated_expansion.go @@ -0,0 +1,21 @@ +/* +Copyright 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. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +package v1 + +type NetworkDeviceExpansion interface{} diff --git a/pkg/networkdevice/generated/clientset/versioned/typed/networkdevice/v1/networkdevice.go b/pkg/networkdevice/generated/clientset/versioned/typed/networkdevice/v1/networkdevice.go new file mode 100644 index 000000000..8b4bd1075 --- /dev/null +++ b/pkg/networkdevice/generated/clientset/versioned/typed/networkdevice/v1/networkdevice.go @@ -0,0 +1,70 @@ +/* +Copyright 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. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +package v1 + +import ( + context "context" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + gentype "k8s.io/client-go/gentype" + networkdevicev1 "k8s.io/sample-controller/pkg/apis/networkdevice/v1" + scheme "k8s.io/sample-controller/pkg/networkdevice/generated/clientset/versioned/scheme" +) + +// NetworkDevicesGetter has a method to return a NetworkDeviceInterface. +// A group's client should implement this interface. +type NetworkDevicesGetter interface { + NetworkDevices(namespace string) NetworkDeviceInterface +} + +// NetworkDeviceInterface has methods to work with NetworkDevice resources. +type NetworkDeviceInterface interface { + Create(ctx context.Context, networkDevice *networkdevicev1.NetworkDevice, opts metav1.CreateOptions) (*networkdevicev1.NetworkDevice, error) + Update(ctx context.Context, networkDevice *networkdevicev1.NetworkDevice, opts metav1.UpdateOptions) (*networkdevicev1.NetworkDevice, error) + // Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). + UpdateStatus(ctx context.Context, networkDevice *networkdevicev1.NetworkDevice, opts metav1.UpdateOptions) (*networkdevicev1.NetworkDevice, error) + Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error + DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error + Get(ctx context.Context, name string, opts metav1.GetOptions) (*networkdevicev1.NetworkDevice, error) + List(ctx context.Context, opts metav1.ListOptions) (*networkdevicev1.NetworkDeviceList, error) + Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) + Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *networkdevicev1.NetworkDevice, err error) + NetworkDeviceExpansion +} + +// networkDevices implements NetworkDeviceInterface +type networkDevices struct { + *gentype.ClientWithList[*networkdevicev1.NetworkDevice, *networkdevicev1.NetworkDeviceList] +} + +// newNetworkDevices returns a NetworkDevices +func newNetworkDevices(c *Sonick8sV1Client, namespace string) *networkDevices { + return &networkDevices{ + gentype.NewClientWithList[*networkdevicev1.NetworkDevice, *networkdevicev1.NetworkDeviceList]( + "networkdevices", + c.RESTClient(), + scheme.ParameterCodec, + namespace, + func() *networkdevicev1.NetworkDevice { return &networkdevicev1.NetworkDevice{} }, + func() *networkdevicev1.NetworkDeviceList { return &networkdevicev1.NetworkDeviceList{} }, + ), + } +} diff --git a/pkg/networkdevice/generated/clientset/versioned/typed/networkdevice/v1/networkdevice_client.go b/pkg/networkdevice/generated/clientset/versioned/typed/networkdevice/v1/networkdevice_client.go new file mode 100644 index 000000000..d780ceea9 --- /dev/null +++ b/pkg/networkdevice/generated/clientset/versioned/typed/networkdevice/v1/networkdevice_client.go @@ -0,0 +1,101 @@ +/* +Copyright 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. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +package v1 + +import ( + http "net/http" + + rest "k8s.io/client-go/rest" + networkdevicev1 "k8s.io/sample-controller/pkg/apis/networkdevice/v1" + scheme "k8s.io/sample-controller/pkg/networkdevice/generated/clientset/versioned/scheme" +) + +type Sonick8sV1Interface interface { + RESTClient() rest.Interface + NetworkDevicesGetter +} + +// Sonick8sV1Client is used to interact with features provided by the sonick8s.io group. +type Sonick8sV1Client struct { + restClient rest.Interface +} + +func (c *Sonick8sV1Client) NetworkDevices(namespace string) NetworkDeviceInterface { + return newNetworkDevices(c, namespace) +} + +// NewForConfig creates a new Sonick8sV1Client for the given config. +// NewForConfig is equivalent to NewForConfigAndClient(c, httpClient), +// where httpClient was generated with rest.HTTPClientFor(c). +func NewForConfig(c *rest.Config) (*Sonick8sV1Client, error) { + config := *c + setConfigDefaults(&config) + httpClient, err := rest.HTTPClientFor(&config) + if err != nil { + return nil, err + } + return NewForConfigAndClient(&config, httpClient) +} + +// NewForConfigAndClient creates a new Sonick8sV1Client 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) (*Sonick8sV1Client, error) { + config := *c + setConfigDefaults(&config) + client, err := rest.RESTClientForConfigAndClient(&config, h) + if err != nil { + return nil, err + } + return &Sonick8sV1Client{client}, nil +} + +// NewForConfigOrDie creates a new Sonick8sV1Client for the given config and +// panics if there is an error in the config. +func NewForConfigOrDie(c *rest.Config) *Sonick8sV1Client { + client, err := NewForConfig(c) + if err != nil { + panic(err) + } + return client +} + +// New creates a new Sonick8sV1Client for the given RESTClient. +func New(c rest.Interface) *Sonick8sV1Client { + return &Sonick8sV1Client{c} +} + +func setConfigDefaults(config *rest.Config) { + gv := networkdevicev1.SchemeGroupVersion + config.GroupVersion = &gv + config.APIPath = "/apis" + config.NegotiatedSerializer = rest.CodecFactoryForGeneratedClient(scheme.Scheme, scheme.Codecs).WithoutConversion() + + if config.UserAgent == "" { + config.UserAgent = rest.DefaultKubernetesUserAgent() + } +} + +// RESTClient returns a RESTClient that is used to communicate +// with API server by this client implementation. +func (c *Sonick8sV1Client) RESTClient() rest.Interface { + if c == nil { + return nil + } + return c.restClient +} diff --git a/pkg/networkdevice/generated/informers/externalversions/factory.go b/pkg/networkdevice/generated/informers/externalversions/factory.go new file mode 100644 index 000000000..1211c46b9 --- /dev/null +++ b/pkg/networkdevice/generated/informers/externalversions/factory.go @@ -0,0 +1,263 @@ +/* +Copyright 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. +*/ + +// Code generated by informer-gen. DO NOT EDIT. + +package externalversions + +import ( + reflect "reflect" + sync "sync" + time "time" + + 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" + versioned "k8s.io/sample-controller/pkg/networkdevice/generated/clientset/versioned" + internalinterfaces "k8s.io/sample-controller/pkg/networkdevice/generated/informers/externalversions/internalinterfaces" + networkdevice "k8s.io/sample-controller/pkg/networkdevice/generated/informers/externalversions/networkdevice" +) + +// 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.WithCancel(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. + // Warning: Start does not block. When run in a go-routine, it will race with a later WaitForCacheSync. + 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 + + Sonick8s() networkdevice.Interface +} + +func (f *sharedInformerFactory) Sonick8s() networkdevice.Interface { + return networkdevice.New(f, f.namespace, f.tweakListOptions) +} diff --git a/pkg/networkdevice/generated/informers/externalversions/generic.go b/pkg/networkdevice/generated/informers/externalversions/generic.go new file mode 100644 index 000000000..c63ce5469 --- /dev/null +++ b/pkg/networkdevice/generated/informers/externalversions/generic.go @@ -0,0 +1,62 @@ +/* +Copyright 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. +*/ + +// Code generated by informer-gen. DO NOT EDIT. + +package externalversions + +import ( + fmt "fmt" + + schema "k8s.io/apimachinery/pkg/runtime/schema" + cache "k8s.io/client-go/tools/cache" + v1 "k8s.io/sample-controller/pkg/apis/networkdevice/v1" +) + +// 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=sonick8s.io, Version=v1 + case v1.SchemeGroupVersion.WithResource("networkdevices"): + return &genericInformer{resource: resource.GroupResource(), informer: f.Sonick8s().V1().NetworkDevices().Informer()}, nil + + } + + return nil, fmt.Errorf("no informer found for %v", resource) +} diff --git a/pkg/networkdevice/generated/informers/externalversions/internalinterfaces/factory_interfaces.go b/pkg/networkdevice/generated/informers/externalversions/internalinterfaces/factory_interfaces.go new file mode 100644 index 000000000..cb7c2fab9 --- /dev/null +++ b/pkg/networkdevice/generated/informers/externalversions/internalinterfaces/factory_interfaces.go @@ -0,0 +1,40 @@ +/* +Copyright 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. +*/ + +// Code generated by informer-gen. DO NOT EDIT. + +package internalinterfaces + +import ( + time "time" + + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + cache "k8s.io/client-go/tools/cache" + versioned "k8s.io/sample-controller/pkg/networkdevice/generated/clientset/versioned" +) + +// 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/networkdevice/generated/informers/externalversions/networkdevice/interface.go b/pkg/networkdevice/generated/informers/externalversions/networkdevice/interface.go new file mode 100644 index 000000000..14b4fcc0e --- /dev/null +++ b/pkg/networkdevice/generated/informers/externalversions/networkdevice/interface.go @@ -0,0 +1,46 @@ +/* +Copyright 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. +*/ + +// Code generated by informer-gen. DO NOT EDIT. + +package networkdevice + +import ( + internalinterfaces "k8s.io/sample-controller/pkg/networkdevice/generated/informers/externalversions/internalinterfaces" + v1 "k8s.io/sample-controller/pkg/networkdevice/generated/informers/externalversions/networkdevice/v1" +) + +// Interface provides access to each of this group's versions. +type Interface interface { + // V1 provides access to shared informers for resources in V1. + V1() v1.Interface +} + +type group struct { + factory internalinterfaces.SharedInformerFactory + namespace string + tweakListOptions internalinterfaces.TweakListOptionsFunc +} + +// New returns a new Interface. +func New(f internalinterfaces.SharedInformerFactory, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) Interface { + return &group{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} +} + +// V1 returns a new v1.Interface. +func (g *group) V1() v1.Interface { + return v1.New(g.factory, g.namespace, g.tweakListOptions) +} diff --git a/pkg/networkdevice/generated/informers/externalversions/networkdevice/v1/interface.go b/pkg/networkdevice/generated/informers/externalversions/networkdevice/v1/interface.go new file mode 100644 index 000000000..4f580b8ad --- /dev/null +++ b/pkg/networkdevice/generated/informers/externalversions/networkdevice/v1/interface.go @@ -0,0 +1,45 @@ +/* +Copyright 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. +*/ + +// Code generated by informer-gen. DO NOT EDIT. + +package v1 + +import ( + internalinterfaces "k8s.io/sample-controller/pkg/networkdevice/generated/informers/externalversions/internalinterfaces" +) + +// Interface provides access to all the informers in this group version. +type Interface interface { + // NetworkDevices returns a NetworkDeviceInformer. + NetworkDevices() NetworkDeviceInformer +} + +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} +} + +// NetworkDevices returns a NetworkDeviceInformer. +func (v *version) NetworkDevices() NetworkDeviceInformer { + return &networkDeviceInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} +} diff --git a/pkg/networkdevice/generated/informers/externalversions/networkdevice/v1/networkdevice.go b/pkg/networkdevice/generated/informers/externalversions/networkdevice/v1/networkdevice.go new file mode 100644 index 000000000..ce56f6e7f --- /dev/null +++ b/pkg/networkdevice/generated/informers/externalversions/networkdevice/v1/networkdevice.go @@ -0,0 +1,102 @@ +/* +Copyright 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. +*/ + +// Code generated by informer-gen. DO NOT EDIT. + +package v1 + +import ( + context "context" + time "time" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + watch "k8s.io/apimachinery/pkg/watch" + cache "k8s.io/client-go/tools/cache" + apisnetworkdevicev1 "k8s.io/sample-controller/pkg/apis/networkdevice/v1" + versioned "k8s.io/sample-controller/pkg/networkdevice/generated/clientset/versioned" + internalinterfaces "k8s.io/sample-controller/pkg/networkdevice/generated/informers/externalversions/internalinterfaces" + networkdevicev1 "k8s.io/sample-controller/pkg/networkdevice/generated/listers/networkdevice/v1" +) + +// NetworkDeviceInformer provides access to a shared informer and lister for +// NetworkDevices. +type NetworkDeviceInformer interface { + Informer() cache.SharedIndexInformer + Lister() networkdevicev1.NetworkDeviceLister +} + +type networkDeviceInformer struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc + namespace string +} + +// NewNetworkDeviceInformer constructs a new informer for NetworkDevice 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 NewNetworkDeviceInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return NewFilteredNetworkDeviceInformer(client, namespace, resyncPeriod, indexers, nil) +} + +// NewFilteredNetworkDeviceInformer constructs a new informer for NetworkDevice 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 NewFilteredNetworkDeviceInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { + return cache.NewSharedIndexInformer( + cache.ToListWatcherWithWatchListSemantics(&cache.ListWatch{ + ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.Sonick8sV1().NetworkDevices(namespace).List(context.Background(), options) + }, + WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.Sonick8sV1().NetworkDevices(namespace).Watch(context.Background(), options) + }, + ListWithContextFunc: func(ctx context.Context, options metav1.ListOptions) (runtime.Object, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.Sonick8sV1().NetworkDevices(namespace).List(ctx, options) + }, + WatchFuncWithContext: func(ctx context.Context, options metav1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.Sonick8sV1().NetworkDevices(namespace).Watch(ctx, options) + }, + }, client), + &apisnetworkdevicev1.NetworkDevice{}, + resyncPeriod, + indexers, + ) +} + +func (f *networkDeviceInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewFilteredNetworkDeviceInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) +} + +func (f *networkDeviceInformer) Informer() cache.SharedIndexInformer { + return f.factory.InformerFor(&apisnetworkdevicev1.NetworkDevice{}, f.defaultInformer) +} + +func (f *networkDeviceInformer) Lister() networkdevicev1.NetworkDeviceLister { + return networkdevicev1.NewNetworkDeviceLister(f.Informer().GetIndexer()) +} diff --git a/pkg/networkdevice/generated/listers/networkdevice/v1/expansion_generated.go b/pkg/networkdevice/generated/listers/networkdevice/v1/expansion_generated.go new file mode 100644 index 000000000..78d12856b --- /dev/null +++ b/pkg/networkdevice/generated/listers/networkdevice/v1/expansion_generated.go @@ -0,0 +1,27 @@ +/* +Copyright 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. +*/ + +// Code generated by lister-gen. DO NOT EDIT. + +package v1 + +// NetworkDeviceListerExpansion allows custom methods to be added to +// NetworkDeviceLister. +type NetworkDeviceListerExpansion interface{} + +// NetworkDeviceNamespaceListerExpansion allows custom methods to be added to +// NetworkDeviceNamespaceLister. +type NetworkDeviceNamespaceListerExpansion interface{} diff --git a/pkg/networkdevice/generated/listers/networkdevice/v1/networkdevice.go b/pkg/networkdevice/generated/listers/networkdevice/v1/networkdevice.go new file mode 100644 index 000000000..9d8530515 --- /dev/null +++ b/pkg/networkdevice/generated/listers/networkdevice/v1/networkdevice.go @@ -0,0 +1,70 @@ +/* +Copyright 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. +*/ + +// Code generated by lister-gen. DO NOT EDIT. + +package v1 + +import ( + labels "k8s.io/apimachinery/pkg/labels" + listers "k8s.io/client-go/listers" + cache "k8s.io/client-go/tools/cache" + networkdevicev1 "k8s.io/sample-controller/pkg/apis/networkdevice/v1" +) + +// NetworkDeviceLister helps list NetworkDevices. +// All objects returned here must be treated as read-only. +type NetworkDeviceLister interface { + // List lists all NetworkDevices in the indexer. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*networkdevicev1.NetworkDevice, err error) + // NetworkDevices returns an object that can list and get NetworkDevices. + NetworkDevices(namespace string) NetworkDeviceNamespaceLister + NetworkDeviceListerExpansion +} + +// networkDeviceLister implements the NetworkDeviceLister interface. +type networkDeviceLister struct { + listers.ResourceIndexer[*networkdevicev1.NetworkDevice] +} + +// NewNetworkDeviceLister returns a new NetworkDeviceLister. +func NewNetworkDeviceLister(indexer cache.Indexer) NetworkDeviceLister { + return &networkDeviceLister{listers.New[*networkdevicev1.NetworkDevice](indexer, networkdevicev1.Resource("networkdevice"))} +} + +// NetworkDevices returns an object that can list and get NetworkDevices. +func (s *networkDeviceLister) NetworkDevices(namespace string) NetworkDeviceNamespaceLister { + return networkDeviceNamespaceLister{listers.NewNamespaced[*networkdevicev1.NetworkDevice](s.ResourceIndexer, namespace)} +} + +// NetworkDeviceNamespaceLister helps list and get NetworkDevices. +// All objects returned here must be treated as read-only. +type NetworkDeviceNamespaceLister interface { + // List lists all NetworkDevices in the indexer for a given namespace. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*networkdevicev1.NetworkDevice, err error) + // Get retrieves the NetworkDevice from the indexer for a given namespace and name. + // Objects returned here must be treated as read-only. + Get(name string) (*networkdevicev1.NetworkDevice, error) + NetworkDeviceNamespaceListerExpansion +} + +// networkDeviceNamespaceLister implements the NetworkDeviceNamespaceLister +// interface. +type networkDeviceNamespaceLister struct { + listers.ResourceIndexer[*networkdevicev1.NetworkDevice] +} diff --git a/pkg/networkoperation/operation.go b/pkg/networkoperation/operation.go new file mode 100644 index 000000000..5d93a0693 --- /dev/null +++ b/pkg/networkoperation/operation.go @@ -0,0 +1,66 @@ +package networkoperation + +import ( + networkdevicev1 "k8s.io/sample-controller/pkg/apis/networkdevice/v1" +) + +type OperationActionState string +type OperationState string + +const ( + // operation names + OperationOSUpgrade = "OSUpgrade" + OperationPreloadImage = "PreloadImage" + + // operation action states + OperationActionStatePending OperationActionState = "Pending" + OperationActionStateInProgress OperationActionState = "InProgress" + OperationActionStateProceed OperationActionState = "Proceed" + OperationActionStateFailed OperationActionState = "Failed" + + // operation states + OperationStatePending OperationState = "Pending" + OperationStateProceed OperationState = "Proceed" + OperationStateSucceeded OperationState = "Succeeded" + OperationStateFailed OperationState = "Failed" +) + +// define an interface for operation handling +type OperationHandler interface { + Proceed(device *networkdevicev1.NetworkDevice) bool + NextAction(device *networkdevicev1.NetworkDevice) (string, bool) +} + +type PreloadImageOperation struct { + Actions []string +} + +// NewPreloadImageOperation creates a new operation with the defined actions +func NewPreloadImageOperation() *PreloadImageOperation { + return &PreloadImageOperation{ + Actions: []string{ + "PreloadImage", + }, + } +} + +// Proceed checks if the current action's state is "proceed" +func (op *PreloadImageOperation) Proceed(device *networkdevicev1.NetworkDevice) bool { + // if no operation action is defined, cannot proceed + deviceStatus := device.Status + if device.Spec.Operation != OperationPreloadImage { + return false + } + + return deviceStatus.OperationActionState == string(OperationActionStateProceed) +} + +// NextAction returns the next action after the current one +func (op *PreloadImageOperation) NextAction(device *networkdevicev1.NetworkDevice) (string, bool) { + if device.Spec.Operation != OperationPreloadImage { + return "", false + } + + // always return the only action for PreloadImage operation + return op.Actions[0], true +} diff --git a/pkg/networkoperation/osupgrade_operation.go b/pkg/networkoperation/osupgrade_operation.go new file mode 100644 index 000000000..520c44d70 --- /dev/null +++ b/pkg/networkoperation/osupgrade_operation.go @@ -0,0 +1,54 @@ +package networkoperation + +import ( + networkdevicev1 "k8s.io/sample-controller/pkg/apis/networkdevice/v1" +) + + +type OSUpgradeOperation struct { + Actions []string +} + +// NewOSUpgradeOperation creates a new operation with the defined actions +func NewOSUpgradeOperation() *OSUpgradeOperation { + return &OSUpgradeOperation{ + Actions: []string{ + "SafetyCheck", + "DeviceIsolation", + "PreloadImage", + "SetBootPartition", + "RebootDevice", + }, + } +} + +// Proceed checks if the current action's state is "proceed" +func (op *OSUpgradeOperation) Proceed(device *networkdevicev1.NetworkDevice) bool { + if device.Spec.Operation != OperationOSUpgrade { + return false + } + + return device.Status.OperationActionState == string(OperationActionStateProceed) +} + +// NextAction returns the next action after the current one +func (op *OSUpgradeOperation) NextAction(device *networkdevicev1.NetworkDevice) (string, bool) { + if device.Spec.Operation != OperationOSUpgrade { + return "", false + } + // if no operation action is defined, return the first action + if device.Spec.OperationAction == "" { + return op.Actions[0], true + } + + for i, action := range op.Actions { + if action == device.Spec.OperationAction { + if i+1 < len(op.Actions) { + return op.Actions[i+1], true + } + return "", false // No next action + } + } + // If current action is not found, return the first action + return op.Actions[0], true +}