From 3b15a227360580591d4ff2b134cb905ebaf83ad0 Mon Sep 17 00:00:00 2001 From: Longquan Sha Date: Tue, 11 Apr 2023 22:34:46 +0800 Subject: [PATCH 01/22] Create sonic dc daemonset --- artifacts/examples/crd-sonic.yaml | 50 +++++++++++++++++++++ pkg/apis/sonick8s/register.go | 22 ++++++++++ pkg/apis/sonick8s/v1alpha1/doc.go | 21 +++++++++ pkg/apis/sonick8s/v1alpha1/register.go | 53 ++++++++++++++++++++++ pkg/apis/sonick8s/v1alpha1/types.go | 61 ++++++++++++++++++++++++++ 5 files changed, 207 insertions(+) create mode 100644 artifacts/examples/crd-sonic.yaml create mode 100644 pkg/apis/sonick8s/register.go create mode 100644 pkg/apis/sonick8s/v1alpha1/doc.go create mode 100644 pkg/apis/sonick8s/v1alpha1/register.go create mode 100644 pkg/apis/sonick8s/v1alpha1/types.go diff --git a/artifacts/examples/crd-sonic.yaml b/artifacts/examples/crd-sonic.yaml new file mode 100644 index 000000000..3553bacb6 --- /dev/null +++ b/artifacts/examples/crd-sonic.yaml @@ -0,0 +1,50 @@ +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + name: dcdaemonsets.sonic.k8s.io + # for more information on the below annotation, please see + # https://github.com/kubernetes/enhancements/blob/master/keps/sig-api-machinery/2337-k8s.io-group-protection/README.md + annotations: + "api-approved.kubernetes.io": "unapproved, experimental-only; please get an approval from Kubernetes API reviewers if you're trying to develop a CRD in the *.k8s.io or *.kubernetes.io groups" +spec: + group: sonic.k8s.io + versions: + - name: v1alpha1 + served: true + storage: true + schema: + # schema used for validation + openAPIV3Schema: + type: object + properties: + spec: + type: object + properties: + daemonsetVersion: + type: string + pause: + type: boolean + status: + type: object + properties: + desiredDaemonSetCount: + type: integer + currentDaemonSetCount: + type: integer + daemonsetList: + type: array + items: + type: object + properties: + daemonsetName: + type: string + daemonsetVersion: + type: string + # subresources for the custom resource + subresources: + # enables the status subresource + status: {} + names: + kind: DcDaemonSet + plural: dcdaemonsets + scope: Namespaced \ No newline at end of file diff --git a/pkg/apis/sonick8s/register.go b/pkg/apis/sonick8s/register.go new file mode 100644 index 000000000..fd5a7888d --- /dev/null +++ b/pkg/apis/sonick8s/register.go @@ -0,0 +1,22 @@ +/* +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 samplecontroller + +// GroupName is the group name used in this package +const ( + GroupName = "samplecontroller.k8s.io" +) diff --git a/pkg/apis/sonick8s/v1alpha1/doc.go b/pkg/apis/sonick8s/v1alpha1/doc.go new file mode 100644 index 000000000..a2f601599 --- /dev/null +++ b/pkg/apis/sonick8s/v1alpha1/doc.go @@ -0,0 +1,21 @@ +/* +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. +*/ + +// +k8s:deepcopy-gen=package +// +groupName=sonic.k8s.io + +// Package v1alpha1 is the v1alpha1 version of the API. +package v1alpha1 // import "k8s.io/sample-controller/pkg/apis/sonick8s/v1alpha1" diff --git a/pkg/apis/sonick8s/v1alpha1/register.go b/pkg/apis/sonick8s/v1alpha1/register.go new file mode 100644 index 000000000..cc644e54a --- /dev/null +++ b/pkg/apis/sonick8s/v1alpha1/register.go @@ -0,0 +1,53 @@ +/* +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" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/schema" +) + +// SchemeGroupVersion is group version used to register these objects +var SchemeGroupVersion = schema.GroupVersion{Group: "sonic.k8s.io", Version: "v1alpha1"} + +// Kind takes an unqualified kind and returns back a Group qualified GroupKind +func Kind(kind string) schema.GroupKind { + return SchemeGroupVersion.WithKind(kind).GroupKind() +} + +// Resource takes an unqualified resource and returns a Group qualified GroupResource +func Resource(resource string) schema.GroupResource { + return SchemeGroupVersion.WithResource(resource).GroupResource() +} + +var ( + // SchemeBuilder initializes a scheme builder + SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes) + // AddToScheme is a global function that registers this API group & version to a scheme + AddToScheme = SchemeBuilder.AddToScheme +) + +// Adds the list of known types to Scheme. +func addKnownTypes(scheme *runtime.Scheme) error { + scheme.AddKnownTypes(SchemeGroupVersion, + &DcDaemonSet{}, + &DcDaemonSetList{}, + ) + metav1.AddToGroupVersion(scheme, SchemeGroupVersion) + return nil +} diff --git a/pkg/apis/sonick8s/v1alpha1/types.go b/pkg/apis/sonick8s/v1alpha1/types.go new file mode 100644 index 000000000..5800c602b --- /dev/null +++ b/pkg/apis/sonick8s/v1alpha1/types.go @@ -0,0 +1,61 @@ +/* +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 DcDaemonSet struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + + Spec DcDaemonSetSpec `json:"spec"` + Status DcDaemonSetStatus `json:"status"` +} + +// FooSpec is the spec for a Foo resource +type DcDaemonSetSpec struct { + DaemonSetVersion string `json:"daemonSetVersion"` + Pause bool `json:"pause"` +} + +// FooStatus is the status for a Foo resource +type DcDaemonSetStatus struct { + DesiredDaemonSetCount int `json:"desiredDaemonSetCount"` + CurrentDaemonSetCount int `json:"currentDaemonSetCount"` + DaemonsetList []DaemonSetItem `json:"daemonsetList"` +} + +type DaemonSetItem struct { + DaemonSetName string `json:"daemonSetName"` + DaemonSetVersion string `json:"daemonSetVersion"` +} + +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// FooList is a list of Foo resources +type DcDaemonSetList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata"` + + Items []DcDaemonSet `json:"items"` +} From 9ab88bbf754b6750a4f4d42f0e8bab1d7af0cd83 Mon Sep 17 00:00:00 2001 From: Longquan Sha Date: Tue, 11 Apr 2023 22:36:46 +0800 Subject: [PATCH 02/22] update --- artifacts/examples/example-sonic.yaml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 artifacts/examples/example-sonic.yaml diff --git a/artifacts/examples/example-sonic.yaml b/artifacts/examples/example-sonic.yaml new file mode 100644 index 000000000..60ddb41f3 --- /dev/null +++ b/artifacts/examples/example-sonic.yaml @@ -0,0 +1,6 @@ +apiVersion: sonic.k8s.io/v1alpha1 +kind: DcDaemonSet +metadata: + name: example-dc-daemonset +spec: + daemonsetVersion: telemetry-20220531.24 \ No newline at end of file From b85e1e0c585e9aaa347e35e959229c3ce21d4a95 Mon Sep 17 00:00:00 2001 From: Longquan Sha Date: Tue, 11 Apr 2023 23:00:15 +0800 Subject: [PATCH 03/22] update --- hack/update-codegen-sonic.sh | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 hack/update-codegen-sonic.sh diff --git a/hack/update-codegen-sonic.sh b/hack/update-codegen-sonic.sh new file mode 100644 index 000000000..7d725ecb9 --- /dev/null +++ b/hack/update-codegen-sonic.sh @@ -0,0 +1,36 @@ +#!/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)} + +# generate the code with: +# --output-base because this script should also be able to run inside the vendor dir of +# k8s.io/kubernetes. The output-base is needed for the generators to output into the vendor dir +# instead of the $GOPATH directly. For normal projects this can be dropped. +"${CODEGEN_PKG}/generate-groups.sh" "deepcopy,client,informer,lister" \ + k8s.io/sample-controller/pkg/generated \ + k8s.io/sample-controller/pkg/apis \ + sonick8s:v1alpha1 \ + --output-base "$(dirname "${BASH_SOURCE[0]}")/../../.." \ + --go-header-file "${SCRIPT_ROOT}"/hack/boilerplate.go.txt + +# To use your own boilerplate text append: +# --go-header-file "${SCRIPT_ROOT}"/hack/custom-boilerplate.go.txt From 08232e02a22dba3040ab4ed513f4126d353958fa Mon Sep 17 00:00:00 2001 From: Longquan Sha Date: Tue, 11 Apr 2023 23:22:10 +0800 Subject: [PATCH 04/22] update --- hack/update-codegen-sonic.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hack/update-codegen-sonic.sh b/hack/update-codegen-sonic.sh index 7d725ecb9..10c371ce6 100644 --- a/hack/update-codegen-sonic.sh +++ b/hack/update-codegen-sonic.sh @@ -26,7 +26,7 @@ CODEGEN_PKG=${CODEGEN_PKG:-$(cd "${SCRIPT_ROOT}"; ls -d -1 ./vendor/k8s.io/code- # k8s.io/kubernetes. The output-base is needed for the generators to output into the vendor dir # instead of the $GOPATH directly. For normal projects this can be dropped. "${CODEGEN_PKG}/generate-groups.sh" "deepcopy,client,informer,lister" \ - k8s.io/sample-controller/pkg/generated \ + k8s.io/sample-controller/pkg/sonick8s/generated \ k8s.io/sample-controller/pkg/apis \ sonick8s:v1alpha1 \ --output-base "$(dirname "${BASH_SOURCE[0]}")/../../.." \ From 8519bcb4eb83f6cef93313ad8197390a111093ea Mon Sep 17 00:00:00 2001 From: LOngquan Sha Date: Tue, 11 Apr 2023 15:27:35 +0000 Subject: [PATCH 05/22] Generate code for sonic dc ds --- hack/update-codegen-sonic.sh | 0 .../v1alpha1/zz_generated.deepcopy.go | 140 ++++++++++ .../typed/sonick8s/v1alpha1/dcdaemonset.go | 195 ++++++++++++++ .../versioned/typed/sonick8s/v1alpha1/doc.go | 20 ++ .../typed/sonick8s/v1alpha1/fake/doc.go | 20 ++ .../v1alpha1/fake/fake_dcdaemonset.go | 141 ++++++++++ .../v1alpha1/fake/fake_sonick8s_client.go | 40 +++ .../sonick8s/v1alpha1/generated_expansion.go | 21 ++ .../sonick8s/v1alpha1/sonick8s_client.go | 107 ++++++++ .../externalversions/sonick8s/interface.go | 46 ++++ .../sonick8s/v1alpha1/dcdaemonset.go | 90 +++++++ .../sonick8s/v1alpha1/interface.go | 45 ++++ .../listers/sonick8s/v1alpha1/dcdaemonset.go | 99 +++++++ .../sonick8s/v1alpha1/expansion_generated.go | 27 ++ .../clientset/versioned/clientset.go | 120 +++++++++ .../versioned/fake/clientset_generated.go | 85 ++++++ .../generated/clientset/versioned/fake/doc.go | 20 ++ .../clientset/versioned/fake/register.go | 56 ++++ .../clientset/versioned/scheme/doc.go | 20 ++ .../clientset/versioned/scheme/register.go | 56 ++++ .../typed/sonick8s/v1alpha1/dcdaemonset.go | 195 ++++++++++++++ .../versioned/typed/sonick8s/v1alpha1/doc.go | 20 ++ .../typed/sonick8s/v1alpha1/fake/doc.go | 20 ++ .../v1alpha1/fake/fake_dcdaemonset.go | 141 ++++++++++ .../v1alpha1/fake/fake_sonick8s_client.go | 40 +++ .../sonick8s/v1alpha1/generated_expansion.go | 21 ++ .../sonick8s/v1alpha1/sonick8s_client.go | 107 ++++++++ .../informers/externalversions/factory.go | 251 ++++++++++++++++++ .../informers/externalversions/generic.go | 62 +++++ .../internalinterfaces/factory_interfaces.go | 40 +++ .../externalversions/sonick8s/interface.go | 46 ++++ .../sonick8s/v1alpha1/dcdaemonset.go | 90 +++++++ .../sonick8s/v1alpha1/interface.go | 45 ++++ .../listers/sonick8s/v1alpha1/dcdaemonset.go | 99 +++++++ .../sonick8s/v1alpha1/expansion_generated.go | 27 ++ 35 files changed, 2552 insertions(+) mode change 100644 => 100755 hack/update-codegen-sonic.sh create mode 100644 pkg/apis/sonick8s/v1alpha1/zz_generated.deepcopy.go create mode 100644 pkg/generated/clientset/versioned/typed/sonick8s/v1alpha1/dcdaemonset.go create mode 100644 pkg/generated/clientset/versioned/typed/sonick8s/v1alpha1/doc.go create mode 100644 pkg/generated/clientset/versioned/typed/sonick8s/v1alpha1/fake/doc.go create mode 100644 pkg/generated/clientset/versioned/typed/sonick8s/v1alpha1/fake/fake_dcdaemonset.go create mode 100644 pkg/generated/clientset/versioned/typed/sonick8s/v1alpha1/fake/fake_sonick8s_client.go create mode 100644 pkg/generated/clientset/versioned/typed/sonick8s/v1alpha1/generated_expansion.go create mode 100644 pkg/generated/clientset/versioned/typed/sonick8s/v1alpha1/sonick8s_client.go create mode 100644 pkg/generated/informers/externalversions/sonick8s/interface.go create mode 100644 pkg/generated/informers/externalversions/sonick8s/v1alpha1/dcdaemonset.go create mode 100644 pkg/generated/informers/externalversions/sonick8s/v1alpha1/interface.go create mode 100644 pkg/generated/listers/sonick8s/v1alpha1/dcdaemonset.go create mode 100644 pkg/generated/listers/sonick8s/v1alpha1/expansion_generated.go create mode 100644 pkg/sonick8s/generated/clientset/versioned/clientset.go create mode 100644 pkg/sonick8s/generated/clientset/versioned/fake/clientset_generated.go create mode 100644 pkg/sonick8s/generated/clientset/versioned/fake/doc.go create mode 100644 pkg/sonick8s/generated/clientset/versioned/fake/register.go create mode 100644 pkg/sonick8s/generated/clientset/versioned/scheme/doc.go create mode 100644 pkg/sonick8s/generated/clientset/versioned/scheme/register.go create mode 100644 pkg/sonick8s/generated/clientset/versioned/typed/sonick8s/v1alpha1/dcdaemonset.go create mode 100644 pkg/sonick8s/generated/clientset/versioned/typed/sonick8s/v1alpha1/doc.go create mode 100644 pkg/sonick8s/generated/clientset/versioned/typed/sonick8s/v1alpha1/fake/doc.go create mode 100644 pkg/sonick8s/generated/clientset/versioned/typed/sonick8s/v1alpha1/fake/fake_dcdaemonset.go create mode 100644 pkg/sonick8s/generated/clientset/versioned/typed/sonick8s/v1alpha1/fake/fake_sonick8s_client.go create mode 100644 pkg/sonick8s/generated/clientset/versioned/typed/sonick8s/v1alpha1/generated_expansion.go create mode 100644 pkg/sonick8s/generated/clientset/versioned/typed/sonick8s/v1alpha1/sonick8s_client.go create mode 100644 pkg/sonick8s/generated/informers/externalversions/factory.go create mode 100644 pkg/sonick8s/generated/informers/externalversions/generic.go create mode 100644 pkg/sonick8s/generated/informers/externalversions/internalinterfaces/factory_interfaces.go create mode 100644 pkg/sonick8s/generated/informers/externalversions/sonick8s/interface.go create mode 100644 pkg/sonick8s/generated/informers/externalversions/sonick8s/v1alpha1/dcdaemonset.go create mode 100644 pkg/sonick8s/generated/informers/externalversions/sonick8s/v1alpha1/interface.go create mode 100644 pkg/sonick8s/generated/listers/sonick8s/v1alpha1/dcdaemonset.go create mode 100644 pkg/sonick8s/generated/listers/sonick8s/v1alpha1/expansion_generated.go diff --git a/hack/update-codegen-sonic.sh b/hack/update-codegen-sonic.sh old mode 100644 new mode 100755 diff --git a/pkg/apis/sonick8s/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/sonick8s/v1alpha1/zz_generated.deepcopy.go new file mode 100644 index 000000000..6a333837a --- /dev/null +++ b/pkg/apis/sonick8s/v1alpha1/zz_generated.deepcopy.go @@ -0,0 +1,140 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +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 deepcopy-gen. DO NOT EDIT. + +package v1alpha1 + +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 *DaemonSetItem) DeepCopyInto(out *DaemonSetItem) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DaemonSetItem. +func (in *DaemonSetItem) DeepCopy() *DaemonSetItem { + if in == nil { + return nil + } + out := new(DaemonSetItem) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *DcDaemonSet) DeepCopyInto(out *DcDaemonSet) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + out.Spec = in.Spec + in.Status.DeepCopyInto(&out.Status) + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DcDaemonSet. +func (in *DcDaemonSet) DeepCopy() *DcDaemonSet { + if in == nil { + return nil + } + out := new(DcDaemonSet) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *DcDaemonSet) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *DcDaemonSetList) DeepCopyInto(out *DcDaemonSetList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]DcDaemonSet, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DcDaemonSetList. +func (in *DcDaemonSetList) DeepCopy() *DcDaemonSetList { + if in == nil { + return nil + } + out := new(DcDaemonSetList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *DcDaemonSetList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *DcDaemonSetSpec) DeepCopyInto(out *DcDaemonSetSpec) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DcDaemonSetSpec. +func (in *DcDaemonSetSpec) DeepCopy() *DcDaemonSetSpec { + if in == nil { + return nil + } + out := new(DcDaemonSetSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *DcDaemonSetStatus) DeepCopyInto(out *DcDaemonSetStatus) { + *out = *in + if in.DaemonsetList != nil { + in, out := &in.DaemonsetList, &out.DaemonsetList + *out = make([]DaemonSetItem, len(*in)) + copy(*out, *in) + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DcDaemonSetStatus. +func (in *DcDaemonSetStatus) DeepCopy() *DcDaemonSetStatus { + if in == nil { + return nil + } + out := new(DcDaemonSetStatus) + in.DeepCopyInto(out) + return out +} diff --git a/pkg/generated/clientset/versioned/typed/sonick8s/v1alpha1/dcdaemonset.go b/pkg/generated/clientset/versioned/typed/sonick8s/v1alpha1/dcdaemonset.go new file mode 100644 index 000000000..b9f2ad9a0 --- /dev/null +++ b/pkg/generated/clientset/versioned/typed/sonick8s/v1alpha1/dcdaemonset.go @@ -0,0 +1,195 @@ +/* +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" + "time" + + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + rest "k8s.io/client-go/rest" + v1alpha1 "k8s.io/sample-controller/pkg/apis/sonick8s/v1alpha1" + scheme "k8s.io/sample-controller/pkg/generated/clientset/versioned/scheme" +) + +// DcDaemonSetsGetter has a method to return a DcDaemonSetInterface. +// A group's client should implement this interface. +type DcDaemonSetsGetter interface { + DcDaemonSets(namespace string) DcDaemonSetInterface +} + +// DcDaemonSetInterface has methods to work with DcDaemonSet resources. +type DcDaemonSetInterface interface { + Create(ctx context.Context, dcDaemonSet *v1alpha1.DcDaemonSet, opts v1.CreateOptions) (*v1alpha1.DcDaemonSet, error) + Update(ctx context.Context, dcDaemonSet *v1alpha1.DcDaemonSet, opts v1.UpdateOptions) (*v1alpha1.DcDaemonSet, error) + UpdateStatus(ctx context.Context, dcDaemonSet *v1alpha1.DcDaemonSet, opts v1.UpdateOptions) (*v1alpha1.DcDaemonSet, error) + Delete(ctx context.Context, name string, opts v1.DeleteOptions) error + DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error + Get(ctx context.Context, name string, opts v1.GetOptions) (*v1alpha1.DcDaemonSet, error) + List(ctx context.Context, opts v1.ListOptions) (*v1alpha1.DcDaemonSetList, error) + Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) + Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.DcDaemonSet, err error) + DcDaemonSetExpansion +} + +// dcDaemonSets implements DcDaemonSetInterface +type dcDaemonSets struct { + client rest.Interface + ns string +} + +// newDcDaemonSets returns a DcDaemonSets +func newDcDaemonSets(c *SonicV1alpha1Client, namespace string) *dcDaemonSets { + return &dcDaemonSets{ + client: c.RESTClient(), + ns: namespace, + } +} + +// Get takes name of the dcDaemonSet, and returns the corresponding dcDaemonSet object, and an error if there is any. +func (c *dcDaemonSets) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha1.DcDaemonSet, err error) { + result = &v1alpha1.DcDaemonSet{} + err = c.client.Get(). + Namespace(c.ns). + Resource("dcdaemonsets"). + Name(name). + VersionedParams(&options, scheme.ParameterCodec). + Do(ctx). + Into(result) + return +} + +// List takes label and field selectors, and returns the list of DcDaemonSets that match those selectors. +func (c *dcDaemonSets) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha1.DcDaemonSetList, err error) { + var timeout time.Duration + if opts.TimeoutSeconds != nil { + timeout = time.Duration(*opts.TimeoutSeconds) * time.Second + } + result = &v1alpha1.DcDaemonSetList{} + err = c.client.Get(). + Namespace(c.ns). + Resource("dcdaemonsets"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Do(ctx). + Into(result) + return +} + +// Watch returns a watch.Interface that watches the requested dcDaemonSets. +func (c *dcDaemonSets) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { + var timeout time.Duration + if opts.TimeoutSeconds != nil { + timeout = time.Duration(*opts.TimeoutSeconds) * time.Second + } + opts.Watch = true + return c.client.Get(). + Namespace(c.ns). + Resource("dcdaemonsets"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Watch(ctx) +} + +// Create takes the representation of a dcDaemonSet and creates it. Returns the server's representation of the dcDaemonSet, and an error, if there is any. +func (c *dcDaemonSets) Create(ctx context.Context, dcDaemonSet *v1alpha1.DcDaemonSet, opts v1.CreateOptions) (result *v1alpha1.DcDaemonSet, err error) { + result = &v1alpha1.DcDaemonSet{} + err = c.client.Post(). + Namespace(c.ns). + Resource("dcdaemonsets"). + VersionedParams(&opts, scheme.ParameterCodec). + Body(dcDaemonSet). + Do(ctx). + Into(result) + return +} + +// Update takes the representation of a dcDaemonSet and updates it. Returns the server's representation of the dcDaemonSet, and an error, if there is any. +func (c *dcDaemonSets) Update(ctx context.Context, dcDaemonSet *v1alpha1.DcDaemonSet, opts v1.UpdateOptions) (result *v1alpha1.DcDaemonSet, err error) { + result = &v1alpha1.DcDaemonSet{} + err = c.client.Put(). + Namespace(c.ns). + Resource("dcdaemonsets"). + Name(dcDaemonSet.Name). + VersionedParams(&opts, scheme.ParameterCodec). + Body(dcDaemonSet). + Do(ctx). + Into(result) + return +} + +// UpdateStatus was generated because the type contains a Status member. +// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). +func (c *dcDaemonSets) UpdateStatus(ctx context.Context, dcDaemonSet *v1alpha1.DcDaemonSet, opts v1.UpdateOptions) (result *v1alpha1.DcDaemonSet, err error) { + result = &v1alpha1.DcDaemonSet{} + err = c.client.Put(). + Namespace(c.ns). + Resource("dcdaemonsets"). + Name(dcDaemonSet.Name). + SubResource("status"). + VersionedParams(&opts, scheme.ParameterCodec). + Body(dcDaemonSet). + Do(ctx). + Into(result) + return +} + +// Delete takes name of the dcDaemonSet and deletes it. Returns an error if one occurs. +func (c *dcDaemonSets) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { + return c.client.Delete(). + Namespace(c.ns). + Resource("dcdaemonsets"). + Name(name). + Body(&opts). + Do(ctx). + Error() +} + +// DeleteCollection deletes a collection of objects. +func (c *dcDaemonSets) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { + var timeout time.Duration + if listOpts.TimeoutSeconds != nil { + timeout = time.Duration(*listOpts.TimeoutSeconds) * time.Second + } + return c.client.Delete(). + Namespace(c.ns). + Resource("dcdaemonsets"). + VersionedParams(&listOpts, scheme.ParameterCodec). + Timeout(timeout). + Body(&opts). + Do(ctx). + Error() +} + +// Patch applies the patch and returns the patched dcDaemonSet. +func (c *dcDaemonSets) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.DcDaemonSet, err error) { + result = &v1alpha1.DcDaemonSet{} + err = c.client.Patch(pt). + Namespace(c.ns). + Resource("dcdaemonsets"). + Name(name). + SubResource(subresources...). + VersionedParams(&opts, scheme.ParameterCodec). + Body(data). + Do(ctx). + Into(result) + return +} diff --git a/pkg/generated/clientset/versioned/typed/sonick8s/v1alpha1/doc.go b/pkg/generated/clientset/versioned/typed/sonick8s/v1alpha1/doc.go new file mode 100644 index 000000000..df51baa4d --- /dev/null +++ b/pkg/generated/clientset/versioned/typed/sonick8s/v1alpha1/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 v1alpha1 diff --git a/pkg/generated/clientset/versioned/typed/sonick8s/v1alpha1/fake/doc.go b/pkg/generated/clientset/versioned/typed/sonick8s/v1alpha1/fake/doc.go new file mode 100644 index 000000000..16f443990 --- /dev/null +++ b/pkg/generated/clientset/versioned/typed/sonick8s/v1alpha1/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/generated/clientset/versioned/typed/sonick8s/v1alpha1/fake/fake_dcdaemonset.go b/pkg/generated/clientset/versioned/typed/sonick8s/v1alpha1/fake/fake_dcdaemonset.go new file mode 100644 index 000000000..966bc6585 --- /dev/null +++ b/pkg/generated/clientset/versioned/typed/sonick8s/v1alpha1/fake/fake_dcdaemonset.go @@ -0,0 +1,141 @@ +/* +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 ( + "context" + + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + labels "k8s.io/apimachinery/pkg/labels" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + testing "k8s.io/client-go/testing" + v1alpha1 "k8s.io/sample-controller/pkg/apis/sonick8s/v1alpha1" +) + +// FakeDcDaemonSets implements DcDaemonSetInterface +type FakeDcDaemonSets struct { + Fake *FakeSonicV1alpha1 + ns string +} + +var dcdaemonsetsResource = v1alpha1.SchemeGroupVersion.WithResource("dcdaemonsets") + +var dcdaemonsetsKind = v1alpha1.SchemeGroupVersion.WithKind("DcDaemonSet") + +// Get takes name of the dcDaemonSet, and returns the corresponding dcDaemonSet object, and an error if there is any. +func (c *FakeDcDaemonSets) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha1.DcDaemonSet, err error) { + obj, err := c.Fake. + Invokes(testing.NewGetAction(dcdaemonsetsResource, c.ns, name), &v1alpha1.DcDaemonSet{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.DcDaemonSet), err +} + +// List takes label and field selectors, and returns the list of DcDaemonSets that match those selectors. +func (c *FakeDcDaemonSets) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha1.DcDaemonSetList, err error) { + obj, err := c.Fake. + Invokes(testing.NewListAction(dcdaemonsetsResource, dcdaemonsetsKind, c.ns, opts), &v1alpha1.DcDaemonSetList{}) + + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &v1alpha1.DcDaemonSetList{ListMeta: obj.(*v1alpha1.DcDaemonSetList).ListMeta} + for _, item := range obj.(*v1alpha1.DcDaemonSetList).Items { + if label.Matches(labels.Set(item.Labels)) { + list.Items = append(list.Items, item) + } + } + return list, err +} + +// Watch returns a watch.Interface that watches the requested dcDaemonSets. +func (c *FakeDcDaemonSets) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { + return c.Fake. + InvokesWatch(testing.NewWatchAction(dcdaemonsetsResource, c.ns, opts)) + +} + +// Create takes the representation of a dcDaemonSet and creates it. Returns the server's representation of the dcDaemonSet, and an error, if there is any. +func (c *FakeDcDaemonSets) Create(ctx context.Context, dcDaemonSet *v1alpha1.DcDaemonSet, opts v1.CreateOptions) (result *v1alpha1.DcDaemonSet, err error) { + obj, err := c.Fake. + Invokes(testing.NewCreateAction(dcdaemonsetsResource, c.ns, dcDaemonSet), &v1alpha1.DcDaemonSet{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.DcDaemonSet), err +} + +// Update takes the representation of a dcDaemonSet and updates it. Returns the server's representation of the dcDaemonSet, and an error, if there is any. +func (c *FakeDcDaemonSets) Update(ctx context.Context, dcDaemonSet *v1alpha1.DcDaemonSet, opts v1.UpdateOptions) (result *v1alpha1.DcDaemonSet, err error) { + obj, err := c.Fake. + Invokes(testing.NewUpdateAction(dcdaemonsetsResource, c.ns, dcDaemonSet), &v1alpha1.DcDaemonSet{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.DcDaemonSet), err +} + +// UpdateStatus was generated because the type contains a Status member. +// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). +func (c *FakeDcDaemonSets) UpdateStatus(ctx context.Context, dcDaemonSet *v1alpha1.DcDaemonSet, opts v1.UpdateOptions) (*v1alpha1.DcDaemonSet, error) { + obj, err := c.Fake. + Invokes(testing.NewUpdateSubresourceAction(dcdaemonsetsResource, "status", c.ns, dcDaemonSet), &v1alpha1.DcDaemonSet{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.DcDaemonSet), err +} + +// Delete takes name of the dcDaemonSet and deletes it. Returns an error if one occurs. +func (c *FakeDcDaemonSets) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { + _, err := c.Fake. + Invokes(testing.NewDeleteActionWithOptions(dcdaemonsetsResource, c.ns, name, opts), &v1alpha1.DcDaemonSet{}) + + return err +} + +// DeleteCollection deletes a collection of objects. +func (c *FakeDcDaemonSets) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { + action := testing.NewDeleteCollectionAction(dcdaemonsetsResource, c.ns, listOpts) + + _, err := c.Fake.Invokes(action, &v1alpha1.DcDaemonSetList{}) + return err +} + +// Patch applies the patch and returns the patched dcDaemonSet. +func (c *FakeDcDaemonSets) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.DcDaemonSet, err error) { + obj, err := c.Fake. + Invokes(testing.NewPatchSubresourceAction(dcdaemonsetsResource, c.ns, name, pt, data, subresources...), &v1alpha1.DcDaemonSet{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.DcDaemonSet), err +} diff --git a/pkg/generated/clientset/versioned/typed/sonick8s/v1alpha1/fake/fake_sonick8s_client.go b/pkg/generated/clientset/versioned/typed/sonick8s/v1alpha1/fake/fake_sonick8s_client.go new file mode 100644 index 000000000..1b60cdd21 --- /dev/null +++ b/pkg/generated/clientset/versioned/typed/sonick8s/v1alpha1/fake/fake_sonick8s_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" + v1alpha1 "k8s.io/sample-controller/pkg/generated/clientset/versioned/typed/sonick8s/v1alpha1" +) + +type FakeSonicV1alpha1 struct { + *testing.Fake +} + +func (c *FakeSonicV1alpha1) DcDaemonSets(namespace string) v1alpha1.DcDaemonSetInterface { + return &FakeDcDaemonSets{c, namespace} +} + +// RESTClient returns a RESTClient that is used to communicate +// with API server by this client implementation. +func (c *FakeSonicV1alpha1) RESTClient() rest.Interface { + var ret *rest.RESTClient + return ret +} diff --git a/pkg/generated/clientset/versioned/typed/sonick8s/v1alpha1/generated_expansion.go b/pkg/generated/clientset/versioned/typed/sonick8s/v1alpha1/generated_expansion.go new file mode 100644 index 000000000..87c70d7a7 --- /dev/null +++ b/pkg/generated/clientset/versioned/typed/sonick8s/v1alpha1/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 v1alpha1 + +type DcDaemonSetExpansion interface{} diff --git a/pkg/generated/clientset/versioned/typed/sonick8s/v1alpha1/sonick8s_client.go b/pkg/generated/clientset/versioned/typed/sonick8s/v1alpha1/sonick8s_client.go new file mode 100644 index 000000000..aa864173f --- /dev/null +++ b/pkg/generated/clientset/versioned/typed/sonick8s/v1alpha1/sonick8s_client.go @@ -0,0 +1,107 @@ +/* +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 ( + "net/http" + + rest "k8s.io/client-go/rest" + v1alpha1 "k8s.io/sample-controller/pkg/apis/sonick8s/v1alpha1" + "k8s.io/sample-controller/pkg/generated/clientset/versioned/scheme" +) + +type SonicV1alpha1Interface interface { + RESTClient() rest.Interface + DcDaemonSetsGetter +} + +// SonicV1alpha1Client is used to interact with features provided by the sonic.k8s.io group. +type SonicV1alpha1Client struct { + restClient rest.Interface +} + +func (c *SonicV1alpha1Client) DcDaemonSets(namespace string) DcDaemonSetInterface { + return newDcDaemonSets(c, namespace) +} + +// NewForConfig creates a new SonicV1alpha1Client for the given config. +// NewForConfig is equivalent to NewForConfigAndClient(c, httpClient), +// where httpClient was generated with rest.HTTPClientFor(c). +func NewForConfig(c *rest.Config) (*SonicV1alpha1Client, error) { + config := *c + if err := setConfigDefaults(&config); err != nil { + return nil, err + } + httpClient, err := rest.HTTPClientFor(&config) + if err != nil { + return nil, err + } + return NewForConfigAndClient(&config, httpClient) +} + +// NewForConfigAndClient creates a new SonicV1alpha1Client 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) (*SonicV1alpha1Client, error) { + config := *c + if err := setConfigDefaults(&config); err != nil { + return nil, err + } + client, err := rest.RESTClientForConfigAndClient(&config, h) + if err != nil { + return nil, err + } + return &SonicV1alpha1Client{client}, nil +} + +// NewForConfigOrDie creates a new SonicV1alpha1Client for the given config and +// panics if there is an error in the config. +func NewForConfigOrDie(c *rest.Config) *SonicV1alpha1Client { + client, err := NewForConfig(c) + if err != nil { + panic(err) + } + return client +} + +// New creates a new SonicV1alpha1Client for the given RESTClient. +func New(c rest.Interface) *SonicV1alpha1Client { + return &SonicV1alpha1Client{c} +} + +func setConfigDefaults(config *rest.Config) error { + gv := v1alpha1.SchemeGroupVersion + config.GroupVersion = &gv + config.APIPath = "/apis" + config.NegotiatedSerializer = scheme.Codecs.WithoutConversion() + + if config.UserAgent == "" { + config.UserAgent = rest.DefaultKubernetesUserAgent() + } + + return nil +} + +// RESTClient returns a RESTClient that is used to communicate +// with API server by this client implementation. +func (c *SonicV1alpha1Client) RESTClient() rest.Interface { + if c == nil { + return nil + } + return c.restClient +} diff --git a/pkg/generated/informers/externalversions/sonick8s/interface.go b/pkg/generated/informers/externalversions/sonick8s/interface.go new file mode 100644 index 000000000..dbf2d12e2 --- /dev/null +++ b/pkg/generated/informers/externalversions/sonick8s/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 sonick8s + +import ( + internalinterfaces "k8s.io/sample-controller/pkg/generated/informers/externalversions/internalinterfaces" + v1alpha1 "k8s.io/sample-controller/pkg/generated/informers/externalversions/sonick8s/v1alpha1" +) + +// Interface provides access to each of this group's versions. +type Interface interface { + // V1alpha1 provides access to shared informers for resources in V1alpha1. + V1alpha1() v1alpha1.Interface +} + +type group struct { + factory internalinterfaces.SharedInformerFactory + namespace string + tweakListOptions internalinterfaces.TweakListOptionsFunc +} + +// New returns a new Interface. +func New(f internalinterfaces.SharedInformerFactory, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) Interface { + return &group{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} +} + +// V1alpha1 returns a new v1alpha1.Interface. +func (g *group) V1alpha1() v1alpha1.Interface { + return v1alpha1.New(g.factory, g.namespace, g.tweakListOptions) +} diff --git a/pkg/generated/informers/externalversions/sonick8s/v1alpha1/dcdaemonset.go b/pkg/generated/informers/externalversions/sonick8s/v1alpha1/dcdaemonset.go new file mode 100644 index 000000000..af9e7d626 --- /dev/null +++ b/pkg/generated/informers/externalversions/sonick8s/v1alpha1/dcdaemonset.go @@ -0,0 +1,90 @@ +/* +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" + 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" + sonick8sv1alpha1 "k8s.io/sample-controller/pkg/apis/sonick8s/v1alpha1" + versioned "k8s.io/sample-controller/pkg/generated/clientset/versioned" + internalinterfaces "k8s.io/sample-controller/pkg/generated/informers/externalversions/internalinterfaces" + v1alpha1 "k8s.io/sample-controller/pkg/generated/listers/sonick8s/v1alpha1" +) + +// DcDaemonSetInformer provides access to a shared informer and lister for +// DcDaemonSets. +type DcDaemonSetInformer interface { + Informer() cache.SharedIndexInformer + Lister() v1alpha1.DcDaemonSetLister +} + +type dcDaemonSetInformer struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc + namespace string +} + +// NewDcDaemonSetInformer constructs a new informer for DcDaemonSet 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 NewDcDaemonSetInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return NewFilteredDcDaemonSetInformer(client, namespace, resyncPeriod, indexers, nil) +} + +// NewFilteredDcDaemonSetInformer constructs a new informer for DcDaemonSet 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 NewFilteredDcDaemonSetInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { + return cache.NewSharedIndexInformer( + &cache.ListWatch{ + ListFunc: func(options v1.ListOptions) (runtime.Object, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.SonicV1alpha1().DcDaemonSets(namespace).List(context.TODO(), options) + }, + WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.SonicV1alpha1().DcDaemonSets(namespace).Watch(context.TODO(), options) + }, + }, + &sonick8sv1alpha1.DcDaemonSet{}, + resyncPeriod, + indexers, + ) +} + +func (f *dcDaemonSetInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewFilteredDcDaemonSetInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) +} + +func (f *dcDaemonSetInformer) Informer() cache.SharedIndexInformer { + return f.factory.InformerFor(&sonick8sv1alpha1.DcDaemonSet{}, f.defaultInformer) +} + +func (f *dcDaemonSetInformer) Lister() v1alpha1.DcDaemonSetLister { + return v1alpha1.NewDcDaemonSetLister(f.Informer().GetIndexer()) +} diff --git a/pkg/generated/informers/externalversions/sonick8s/v1alpha1/interface.go b/pkg/generated/informers/externalversions/sonick8s/v1alpha1/interface.go new file mode 100644 index 000000000..9cc6e73fa --- /dev/null +++ b/pkg/generated/informers/externalversions/sonick8s/v1alpha1/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 v1alpha1 + +import ( + internalinterfaces "k8s.io/sample-controller/pkg/generated/informers/externalversions/internalinterfaces" +) + +// Interface provides access to all the informers in this group version. +type Interface interface { + // DcDaemonSets returns a DcDaemonSetInformer. + DcDaemonSets() DcDaemonSetInformer +} + +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} +} + +// DcDaemonSets returns a DcDaemonSetInformer. +func (v *version) DcDaemonSets() DcDaemonSetInformer { + return &dcDaemonSetInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} +} diff --git a/pkg/generated/listers/sonick8s/v1alpha1/dcdaemonset.go b/pkg/generated/listers/sonick8s/v1alpha1/dcdaemonset.go new file mode 100644 index 000000000..febd5deda --- /dev/null +++ b/pkg/generated/listers/sonick8s/v1alpha1/dcdaemonset.go @@ -0,0 +1,99 @@ +/* +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 ( + "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/tools/cache" + v1alpha1 "k8s.io/sample-controller/pkg/apis/sonick8s/v1alpha1" +) + +// DcDaemonSetLister helps list DcDaemonSets. +// All objects returned here must be treated as read-only. +type DcDaemonSetLister interface { + // List lists all DcDaemonSets in the indexer. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*v1alpha1.DcDaemonSet, err error) + // DcDaemonSets returns an object that can list and get DcDaemonSets. + DcDaemonSets(namespace string) DcDaemonSetNamespaceLister + DcDaemonSetListerExpansion +} + +// dcDaemonSetLister implements the DcDaemonSetLister interface. +type dcDaemonSetLister struct { + indexer cache.Indexer +} + +// NewDcDaemonSetLister returns a new DcDaemonSetLister. +func NewDcDaemonSetLister(indexer cache.Indexer) DcDaemonSetLister { + return &dcDaemonSetLister{indexer: indexer} +} + +// List lists all DcDaemonSets in the indexer. +func (s *dcDaemonSetLister) List(selector labels.Selector) (ret []*v1alpha1.DcDaemonSet, err error) { + err = cache.ListAll(s.indexer, selector, func(m interface{}) { + ret = append(ret, m.(*v1alpha1.DcDaemonSet)) + }) + return ret, err +} + +// DcDaemonSets returns an object that can list and get DcDaemonSets. +func (s *dcDaemonSetLister) DcDaemonSets(namespace string) DcDaemonSetNamespaceLister { + return dcDaemonSetNamespaceLister{indexer: s.indexer, namespace: namespace} +} + +// DcDaemonSetNamespaceLister helps list and get DcDaemonSets. +// All objects returned here must be treated as read-only. +type DcDaemonSetNamespaceLister interface { + // List lists all DcDaemonSets in the indexer for a given namespace. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*v1alpha1.DcDaemonSet, err error) + // Get retrieves the DcDaemonSet from the indexer for a given namespace and name. + // Objects returned here must be treated as read-only. + Get(name string) (*v1alpha1.DcDaemonSet, error) + DcDaemonSetNamespaceListerExpansion +} + +// dcDaemonSetNamespaceLister implements the DcDaemonSetNamespaceLister +// interface. +type dcDaemonSetNamespaceLister struct { + indexer cache.Indexer + namespace string +} + +// List lists all DcDaemonSets in the indexer for a given namespace. +func (s dcDaemonSetNamespaceLister) List(selector labels.Selector) (ret []*v1alpha1.DcDaemonSet, err error) { + err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { + ret = append(ret, m.(*v1alpha1.DcDaemonSet)) + }) + return ret, err +} + +// Get retrieves the DcDaemonSet from the indexer for a given namespace and name. +func (s dcDaemonSetNamespaceLister) Get(name string) (*v1alpha1.DcDaemonSet, error) { + obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) + if err != nil { + return nil, err + } + if !exists { + return nil, errors.NewNotFound(v1alpha1.Resource("dcdaemonset"), name) + } + return obj.(*v1alpha1.DcDaemonSet), nil +} diff --git a/pkg/generated/listers/sonick8s/v1alpha1/expansion_generated.go b/pkg/generated/listers/sonick8s/v1alpha1/expansion_generated.go new file mode 100644 index 000000000..ebb17c3f7 --- /dev/null +++ b/pkg/generated/listers/sonick8s/v1alpha1/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 v1alpha1 + +// DcDaemonSetListerExpansion allows custom methods to be added to +// DcDaemonSetLister. +type DcDaemonSetListerExpansion interface{} + +// DcDaemonSetNamespaceListerExpansion allows custom methods to be added to +// DcDaemonSetNamespaceLister. +type DcDaemonSetNamespaceListerExpansion interface{} diff --git a/pkg/sonick8s/generated/clientset/versioned/clientset.go b/pkg/sonick8s/generated/clientset/versioned/clientset.go new file mode 100644 index 000000000..ee68ab21d --- /dev/null +++ b/pkg/sonick8s/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" + "net/http" + + discovery "k8s.io/client-go/discovery" + rest "k8s.io/client-go/rest" + flowcontrol "k8s.io/client-go/util/flowcontrol" + sonicv1alpha1 "k8s.io/sample-controller/pkg/sonick8s/generated/clientset/versioned/typed/sonick8s/v1alpha1" +) + +type Interface interface { + Discovery() discovery.DiscoveryInterface + SonicV1alpha1() sonicv1alpha1.SonicV1alpha1Interface +} + +// Clientset contains the clients for groups. +type Clientset struct { + *discovery.DiscoveryClient + sonicV1alpha1 *sonicv1alpha1.SonicV1alpha1Client +} + +// SonicV1alpha1 retrieves the SonicV1alpha1Client +func (c *Clientset) SonicV1alpha1() sonicv1alpha1.SonicV1alpha1Interface { + return c.sonicV1alpha1 +} + +// 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.sonicV1alpha1, err = sonicv1alpha1.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.sonicV1alpha1 = sonicv1alpha1.New(c) + + cs.DiscoveryClient = discovery.NewDiscoveryClient(c) + return &cs +} diff --git a/pkg/sonick8s/generated/clientset/versioned/fake/clientset_generated.go b/pkg/sonick8s/generated/clientset/versioned/fake/clientset_generated.go new file mode 100644 index 000000000..b0293bc14 --- /dev/null +++ b/pkg/sonick8s/generated/clientset/versioned/fake/clientset_generated.go @@ -0,0 +1,85 @@ +/* +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 ( + "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/sonick8s/generated/clientset/versioned" + sonicv1alpha1 "k8s.io/sample-controller/pkg/sonick8s/generated/clientset/versioned/typed/sonick8s/v1alpha1" + fakesonicv1alpha1 "k8s.io/sample-controller/pkg/sonick8s/generated/clientset/versioned/typed/sonick8s/v1alpha1/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 validations and/or defaults. It shouldn't be considered a replacement +// for a real clientset and is mostly useful in simple unit tests. +func NewSimpleClientset(objects ...runtime.Object) *Clientset { + o := testing.NewObjectTracker(scheme, codecs.UniversalDecoder()) + for _, obj := range objects { + if err := o.Add(obj); err != nil { + panic(err) + } + } + + cs := &Clientset{tracker: o} + cs.discovery = &fakediscovery.FakeDiscovery{Fake: &cs.Fake} + cs.AddReactor("*", "*", testing.ObjectReaction(o)) + cs.AddWatchReactor("*", func(action testing.Action) (handled bool, ret watch.Interface, err error) { + gvr := action.GetResource() + ns := action.GetNamespace() + watch, err := o.Watch(gvr, ns) + if err != nil { + return false, nil, err + } + return true, watch, nil + }) + + return cs +} + +// Clientset implements clientset.Interface. Meant to be embedded into a +// struct to get a default implementation. This makes faking out just the method +// you want to test easier. +type Clientset struct { + testing.Fake + discovery *fakediscovery.FakeDiscovery + tracker testing.ObjectTracker +} + +func (c *Clientset) Discovery() discovery.DiscoveryInterface { + return c.discovery +} + +func (c *Clientset) Tracker() testing.ObjectTracker { + return c.tracker +} + +var ( + _ clientset.Interface = &Clientset{} + _ testing.FakeClient = &Clientset{} +) + +// SonicV1alpha1 retrieves the SonicV1alpha1Client +func (c *Clientset) SonicV1alpha1() sonicv1alpha1.SonicV1alpha1Interface { + return &fakesonicv1alpha1.FakeSonicV1alpha1{Fake: &c.Fake} +} diff --git a/pkg/sonick8s/generated/clientset/versioned/fake/doc.go b/pkg/sonick8s/generated/clientset/versioned/fake/doc.go new file mode 100644 index 000000000..9b99e7167 --- /dev/null +++ b/pkg/sonick8s/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/sonick8s/generated/clientset/versioned/fake/register.go b/pkg/sonick8s/generated/clientset/versioned/fake/register.go new file mode 100644 index 000000000..151bc55a4 --- /dev/null +++ b/pkg/sonick8s/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" + sonicv1alpha1 "k8s.io/sample-controller/pkg/apis/sonick8s/v1alpha1" +) + +var scheme = runtime.NewScheme() +var codecs = serializer.NewCodecFactory(scheme) + +var localSchemeBuilder = runtime.SchemeBuilder{ + sonicv1alpha1.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/sonick8s/generated/clientset/versioned/scheme/doc.go b/pkg/sonick8s/generated/clientset/versioned/scheme/doc.go new file mode 100644 index 000000000..7dc375616 --- /dev/null +++ b/pkg/sonick8s/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/sonick8s/generated/clientset/versioned/scheme/register.go b/pkg/sonick8s/generated/clientset/versioned/scheme/register.go new file mode 100644 index 000000000..ee8a97ff3 --- /dev/null +++ b/pkg/sonick8s/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" + sonicv1alpha1 "k8s.io/sample-controller/pkg/apis/sonick8s/v1alpha1" +) + +var Scheme = runtime.NewScheme() +var Codecs = serializer.NewCodecFactory(Scheme) +var ParameterCodec = runtime.NewParameterCodec(Scheme) +var localSchemeBuilder = runtime.SchemeBuilder{ + sonicv1alpha1.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/sonick8s/generated/clientset/versioned/typed/sonick8s/v1alpha1/dcdaemonset.go b/pkg/sonick8s/generated/clientset/versioned/typed/sonick8s/v1alpha1/dcdaemonset.go new file mode 100644 index 000000000..364e5bdeb --- /dev/null +++ b/pkg/sonick8s/generated/clientset/versioned/typed/sonick8s/v1alpha1/dcdaemonset.go @@ -0,0 +1,195 @@ +/* +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" + "time" + + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + rest "k8s.io/client-go/rest" + v1alpha1 "k8s.io/sample-controller/pkg/apis/sonick8s/v1alpha1" + scheme "k8s.io/sample-controller/pkg/sonick8s/generated/clientset/versioned/scheme" +) + +// DcDaemonSetsGetter has a method to return a DcDaemonSetInterface. +// A group's client should implement this interface. +type DcDaemonSetsGetter interface { + DcDaemonSets(namespace string) DcDaemonSetInterface +} + +// DcDaemonSetInterface has methods to work with DcDaemonSet resources. +type DcDaemonSetInterface interface { + Create(ctx context.Context, dcDaemonSet *v1alpha1.DcDaemonSet, opts v1.CreateOptions) (*v1alpha1.DcDaemonSet, error) + Update(ctx context.Context, dcDaemonSet *v1alpha1.DcDaemonSet, opts v1.UpdateOptions) (*v1alpha1.DcDaemonSet, error) + UpdateStatus(ctx context.Context, dcDaemonSet *v1alpha1.DcDaemonSet, opts v1.UpdateOptions) (*v1alpha1.DcDaemonSet, error) + Delete(ctx context.Context, name string, opts v1.DeleteOptions) error + DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error + Get(ctx context.Context, name string, opts v1.GetOptions) (*v1alpha1.DcDaemonSet, error) + List(ctx context.Context, opts v1.ListOptions) (*v1alpha1.DcDaemonSetList, error) + Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) + Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.DcDaemonSet, err error) + DcDaemonSetExpansion +} + +// dcDaemonSets implements DcDaemonSetInterface +type dcDaemonSets struct { + client rest.Interface + ns string +} + +// newDcDaemonSets returns a DcDaemonSets +func newDcDaemonSets(c *SonicV1alpha1Client, namespace string) *dcDaemonSets { + return &dcDaemonSets{ + client: c.RESTClient(), + ns: namespace, + } +} + +// Get takes name of the dcDaemonSet, and returns the corresponding dcDaemonSet object, and an error if there is any. +func (c *dcDaemonSets) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha1.DcDaemonSet, err error) { + result = &v1alpha1.DcDaemonSet{} + err = c.client.Get(). + Namespace(c.ns). + Resource("dcdaemonsets"). + Name(name). + VersionedParams(&options, scheme.ParameterCodec). + Do(ctx). + Into(result) + return +} + +// List takes label and field selectors, and returns the list of DcDaemonSets that match those selectors. +func (c *dcDaemonSets) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha1.DcDaemonSetList, err error) { + var timeout time.Duration + if opts.TimeoutSeconds != nil { + timeout = time.Duration(*opts.TimeoutSeconds) * time.Second + } + result = &v1alpha1.DcDaemonSetList{} + err = c.client.Get(). + Namespace(c.ns). + Resource("dcdaemonsets"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Do(ctx). + Into(result) + return +} + +// Watch returns a watch.Interface that watches the requested dcDaemonSets. +func (c *dcDaemonSets) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { + var timeout time.Duration + if opts.TimeoutSeconds != nil { + timeout = time.Duration(*opts.TimeoutSeconds) * time.Second + } + opts.Watch = true + return c.client.Get(). + Namespace(c.ns). + Resource("dcdaemonsets"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Watch(ctx) +} + +// Create takes the representation of a dcDaemonSet and creates it. Returns the server's representation of the dcDaemonSet, and an error, if there is any. +func (c *dcDaemonSets) Create(ctx context.Context, dcDaemonSet *v1alpha1.DcDaemonSet, opts v1.CreateOptions) (result *v1alpha1.DcDaemonSet, err error) { + result = &v1alpha1.DcDaemonSet{} + err = c.client.Post(). + Namespace(c.ns). + Resource("dcdaemonsets"). + VersionedParams(&opts, scheme.ParameterCodec). + Body(dcDaemonSet). + Do(ctx). + Into(result) + return +} + +// Update takes the representation of a dcDaemonSet and updates it. Returns the server's representation of the dcDaemonSet, and an error, if there is any. +func (c *dcDaemonSets) Update(ctx context.Context, dcDaemonSet *v1alpha1.DcDaemonSet, opts v1.UpdateOptions) (result *v1alpha1.DcDaemonSet, err error) { + result = &v1alpha1.DcDaemonSet{} + err = c.client.Put(). + Namespace(c.ns). + Resource("dcdaemonsets"). + Name(dcDaemonSet.Name). + VersionedParams(&opts, scheme.ParameterCodec). + Body(dcDaemonSet). + Do(ctx). + Into(result) + return +} + +// UpdateStatus was generated because the type contains a Status member. +// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). +func (c *dcDaemonSets) UpdateStatus(ctx context.Context, dcDaemonSet *v1alpha1.DcDaemonSet, opts v1.UpdateOptions) (result *v1alpha1.DcDaemonSet, err error) { + result = &v1alpha1.DcDaemonSet{} + err = c.client.Put(). + Namespace(c.ns). + Resource("dcdaemonsets"). + Name(dcDaemonSet.Name). + SubResource("status"). + VersionedParams(&opts, scheme.ParameterCodec). + Body(dcDaemonSet). + Do(ctx). + Into(result) + return +} + +// Delete takes name of the dcDaemonSet and deletes it. Returns an error if one occurs. +func (c *dcDaemonSets) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { + return c.client.Delete(). + Namespace(c.ns). + Resource("dcdaemonsets"). + Name(name). + Body(&opts). + Do(ctx). + Error() +} + +// DeleteCollection deletes a collection of objects. +func (c *dcDaemonSets) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { + var timeout time.Duration + if listOpts.TimeoutSeconds != nil { + timeout = time.Duration(*listOpts.TimeoutSeconds) * time.Second + } + return c.client.Delete(). + Namespace(c.ns). + Resource("dcdaemonsets"). + VersionedParams(&listOpts, scheme.ParameterCodec). + Timeout(timeout). + Body(&opts). + Do(ctx). + Error() +} + +// Patch applies the patch and returns the patched dcDaemonSet. +func (c *dcDaemonSets) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.DcDaemonSet, err error) { + result = &v1alpha1.DcDaemonSet{} + err = c.client.Patch(pt). + Namespace(c.ns). + Resource("dcdaemonsets"). + Name(name). + SubResource(subresources...). + VersionedParams(&opts, scheme.ParameterCodec). + Body(data). + Do(ctx). + Into(result) + return +} diff --git a/pkg/sonick8s/generated/clientset/versioned/typed/sonick8s/v1alpha1/doc.go b/pkg/sonick8s/generated/clientset/versioned/typed/sonick8s/v1alpha1/doc.go new file mode 100644 index 000000000..df51baa4d --- /dev/null +++ b/pkg/sonick8s/generated/clientset/versioned/typed/sonick8s/v1alpha1/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 v1alpha1 diff --git a/pkg/sonick8s/generated/clientset/versioned/typed/sonick8s/v1alpha1/fake/doc.go b/pkg/sonick8s/generated/clientset/versioned/typed/sonick8s/v1alpha1/fake/doc.go new file mode 100644 index 000000000..16f443990 --- /dev/null +++ b/pkg/sonick8s/generated/clientset/versioned/typed/sonick8s/v1alpha1/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/sonick8s/generated/clientset/versioned/typed/sonick8s/v1alpha1/fake/fake_dcdaemonset.go b/pkg/sonick8s/generated/clientset/versioned/typed/sonick8s/v1alpha1/fake/fake_dcdaemonset.go new file mode 100644 index 000000000..966bc6585 --- /dev/null +++ b/pkg/sonick8s/generated/clientset/versioned/typed/sonick8s/v1alpha1/fake/fake_dcdaemonset.go @@ -0,0 +1,141 @@ +/* +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 ( + "context" + + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + labels "k8s.io/apimachinery/pkg/labels" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + testing "k8s.io/client-go/testing" + v1alpha1 "k8s.io/sample-controller/pkg/apis/sonick8s/v1alpha1" +) + +// FakeDcDaemonSets implements DcDaemonSetInterface +type FakeDcDaemonSets struct { + Fake *FakeSonicV1alpha1 + ns string +} + +var dcdaemonsetsResource = v1alpha1.SchemeGroupVersion.WithResource("dcdaemonsets") + +var dcdaemonsetsKind = v1alpha1.SchemeGroupVersion.WithKind("DcDaemonSet") + +// Get takes name of the dcDaemonSet, and returns the corresponding dcDaemonSet object, and an error if there is any. +func (c *FakeDcDaemonSets) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha1.DcDaemonSet, err error) { + obj, err := c.Fake. + Invokes(testing.NewGetAction(dcdaemonsetsResource, c.ns, name), &v1alpha1.DcDaemonSet{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.DcDaemonSet), err +} + +// List takes label and field selectors, and returns the list of DcDaemonSets that match those selectors. +func (c *FakeDcDaemonSets) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha1.DcDaemonSetList, err error) { + obj, err := c.Fake. + Invokes(testing.NewListAction(dcdaemonsetsResource, dcdaemonsetsKind, c.ns, opts), &v1alpha1.DcDaemonSetList{}) + + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &v1alpha1.DcDaemonSetList{ListMeta: obj.(*v1alpha1.DcDaemonSetList).ListMeta} + for _, item := range obj.(*v1alpha1.DcDaemonSetList).Items { + if label.Matches(labels.Set(item.Labels)) { + list.Items = append(list.Items, item) + } + } + return list, err +} + +// Watch returns a watch.Interface that watches the requested dcDaemonSets. +func (c *FakeDcDaemonSets) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { + return c.Fake. + InvokesWatch(testing.NewWatchAction(dcdaemonsetsResource, c.ns, opts)) + +} + +// Create takes the representation of a dcDaemonSet and creates it. Returns the server's representation of the dcDaemonSet, and an error, if there is any. +func (c *FakeDcDaemonSets) Create(ctx context.Context, dcDaemonSet *v1alpha1.DcDaemonSet, opts v1.CreateOptions) (result *v1alpha1.DcDaemonSet, err error) { + obj, err := c.Fake. + Invokes(testing.NewCreateAction(dcdaemonsetsResource, c.ns, dcDaemonSet), &v1alpha1.DcDaemonSet{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.DcDaemonSet), err +} + +// Update takes the representation of a dcDaemonSet and updates it. Returns the server's representation of the dcDaemonSet, and an error, if there is any. +func (c *FakeDcDaemonSets) Update(ctx context.Context, dcDaemonSet *v1alpha1.DcDaemonSet, opts v1.UpdateOptions) (result *v1alpha1.DcDaemonSet, err error) { + obj, err := c.Fake. + Invokes(testing.NewUpdateAction(dcdaemonsetsResource, c.ns, dcDaemonSet), &v1alpha1.DcDaemonSet{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.DcDaemonSet), err +} + +// UpdateStatus was generated because the type contains a Status member. +// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). +func (c *FakeDcDaemonSets) UpdateStatus(ctx context.Context, dcDaemonSet *v1alpha1.DcDaemonSet, opts v1.UpdateOptions) (*v1alpha1.DcDaemonSet, error) { + obj, err := c.Fake. + Invokes(testing.NewUpdateSubresourceAction(dcdaemonsetsResource, "status", c.ns, dcDaemonSet), &v1alpha1.DcDaemonSet{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.DcDaemonSet), err +} + +// Delete takes name of the dcDaemonSet and deletes it. Returns an error if one occurs. +func (c *FakeDcDaemonSets) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { + _, err := c.Fake. + Invokes(testing.NewDeleteActionWithOptions(dcdaemonsetsResource, c.ns, name, opts), &v1alpha1.DcDaemonSet{}) + + return err +} + +// DeleteCollection deletes a collection of objects. +func (c *FakeDcDaemonSets) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { + action := testing.NewDeleteCollectionAction(dcdaemonsetsResource, c.ns, listOpts) + + _, err := c.Fake.Invokes(action, &v1alpha1.DcDaemonSetList{}) + return err +} + +// Patch applies the patch and returns the patched dcDaemonSet. +func (c *FakeDcDaemonSets) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.DcDaemonSet, err error) { + obj, err := c.Fake. + Invokes(testing.NewPatchSubresourceAction(dcdaemonsetsResource, c.ns, name, pt, data, subresources...), &v1alpha1.DcDaemonSet{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.DcDaemonSet), err +} diff --git a/pkg/sonick8s/generated/clientset/versioned/typed/sonick8s/v1alpha1/fake/fake_sonick8s_client.go b/pkg/sonick8s/generated/clientset/versioned/typed/sonick8s/v1alpha1/fake/fake_sonick8s_client.go new file mode 100644 index 000000000..7a05150fb --- /dev/null +++ b/pkg/sonick8s/generated/clientset/versioned/typed/sonick8s/v1alpha1/fake/fake_sonick8s_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" + v1alpha1 "k8s.io/sample-controller/pkg/sonick8s/generated/clientset/versioned/typed/sonick8s/v1alpha1" +) + +type FakeSonicV1alpha1 struct { + *testing.Fake +} + +func (c *FakeSonicV1alpha1) DcDaemonSets(namespace string) v1alpha1.DcDaemonSetInterface { + return &FakeDcDaemonSets{c, namespace} +} + +// RESTClient returns a RESTClient that is used to communicate +// with API server by this client implementation. +func (c *FakeSonicV1alpha1) RESTClient() rest.Interface { + var ret *rest.RESTClient + return ret +} diff --git a/pkg/sonick8s/generated/clientset/versioned/typed/sonick8s/v1alpha1/generated_expansion.go b/pkg/sonick8s/generated/clientset/versioned/typed/sonick8s/v1alpha1/generated_expansion.go new file mode 100644 index 000000000..87c70d7a7 --- /dev/null +++ b/pkg/sonick8s/generated/clientset/versioned/typed/sonick8s/v1alpha1/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 v1alpha1 + +type DcDaemonSetExpansion interface{} diff --git a/pkg/sonick8s/generated/clientset/versioned/typed/sonick8s/v1alpha1/sonick8s_client.go b/pkg/sonick8s/generated/clientset/versioned/typed/sonick8s/v1alpha1/sonick8s_client.go new file mode 100644 index 000000000..ceed0625a --- /dev/null +++ b/pkg/sonick8s/generated/clientset/versioned/typed/sonick8s/v1alpha1/sonick8s_client.go @@ -0,0 +1,107 @@ +/* +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 ( + "net/http" + + rest "k8s.io/client-go/rest" + v1alpha1 "k8s.io/sample-controller/pkg/apis/sonick8s/v1alpha1" + "k8s.io/sample-controller/pkg/sonick8s/generated/clientset/versioned/scheme" +) + +type SonicV1alpha1Interface interface { + RESTClient() rest.Interface + DcDaemonSetsGetter +} + +// SonicV1alpha1Client is used to interact with features provided by the sonic.k8s.io group. +type SonicV1alpha1Client struct { + restClient rest.Interface +} + +func (c *SonicV1alpha1Client) DcDaemonSets(namespace string) DcDaemonSetInterface { + return newDcDaemonSets(c, namespace) +} + +// NewForConfig creates a new SonicV1alpha1Client for the given config. +// NewForConfig is equivalent to NewForConfigAndClient(c, httpClient), +// where httpClient was generated with rest.HTTPClientFor(c). +func NewForConfig(c *rest.Config) (*SonicV1alpha1Client, error) { + config := *c + if err := setConfigDefaults(&config); err != nil { + return nil, err + } + httpClient, err := rest.HTTPClientFor(&config) + if err != nil { + return nil, err + } + return NewForConfigAndClient(&config, httpClient) +} + +// NewForConfigAndClient creates a new SonicV1alpha1Client 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) (*SonicV1alpha1Client, error) { + config := *c + if err := setConfigDefaults(&config); err != nil { + return nil, err + } + client, err := rest.RESTClientForConfigAndClient(&config, h) + if err != nil { + return nil, err + } + return &SonicV1alpha1Client{client}, nil +} + +// NewForConfigOrDie creates a new SonicV1alpha1Client for the given config and +// panics if there is an error in the config. +func NewForConfigOrDie(c *rest.Config) *SonicV1alpha1Client { + client, err := NewForConfig(c) + if err != nil { + panic(err) + } + return client +} + +// New creates a new SonicV1alpha1Client for the given RESTClient. +func New(c rest.Interface) *SonicV1alpha1Client { + return &SonicV1alpha1Client{c} +} + +func setConfigDefaults(config *rest.Config) error { + gv := v1alpha1.SchemeGroupVersion + config.GroupVersion = &gv + config.APIPath = "/apis" + config.NegotiatedSerializer = scheme.Codecs.WithoutConversion() + + if config.UserAgent == "" { + config.UserAgent = rest.DefaultKubernetesUserAgent() + } + + return nil +} + +// RESTClient returns a RESTClient that is used to communicate +// with API server by this client implementation. +func (c *SonicV1alpha1Client) RESTClient() rest.Interface { + if c == nil { + return nil + } + return c.restClient +} diff --git a/pkg/sonick8s/generated/informers/externalversions/factory.go b/pkg/sonick8s/generated/informers/externalversions/factory.go new file mode 100644 index 000000000..e57508d01 --- /dev/null +++ b/pkg/sonick8s/generated/informers/externalversions/factory.go @@ -0,0 +1,251 @@ +/* +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/sonick8s/generated/clientset/versioned" + internalinterfaces "k8s.io/sample-controller/pkg/sonick8s/generated/informers/externalversions/internalinterfaces" + sonick8s "k8s.io/sample-controller/pkg/sonick8s/generated/informers/externalversions/sonick8s" +) + +// 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 + + 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 + } +} + +// 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 +} + +// InternalInformerFor 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) + f.informers[informerType] = informer + + return informer +} + +// SharedInformerFactory provides shared informers for resources in all known +// API group versions. +// +// It is typically used like this: +// +// ctx, cancel := context.Background() +// defer cancel() +// factory := NewSharedInformerFactory(client, resyncPeriod) +// defer factory.WaitForStop() // Returns immediately if nothing was started. +// genericInformer := factory.ForResource(resource) +// typedInformer := factory.SomeAPIGroup().V1().SomeType() +// factory.Start(ctx.Done()) // Start processing these informers. +// synced := factory.WaitForCacheSync(ctx.Done()) +// for v, ok := range synced { +// if !ok { +// fmt.Fprintf(os.Stderr, "caches failed to sync: %v", v) +// return +// } +// } +// +// // Creating informers can also be created after Start, but then +// // Start must be called again: +// anotherGenericInformer := factory.ForResource(resource) +// factory.Start(ctx.Done()) +type SharedInformerFactory interface { + internalinterfaces.SharedInformerFactory + + // Start initializes all requested informers. They are handled in goroutines + // which run until the stop channel gets closed. + Start(stopCh <-chan struct{}) + + // Shutdown marks a factory as shutting down. At that point no new + // informers can be started anymore and Start will return without + // doing anything. + // + // In addition, Shutdown blocks until all goroutines have terminated. For that + // to happen, the close channel(s) that they were started with must be closed, + // either before Shutdown gets called or while it is waiting. + // + // Shutdown may be called multiple times, even concurrently. All such calls will + // block until all goroutines have terminated. + Shutdown() + + // WaitForCacheSync blocks until all started informers' caches were synced + // or the stop channel gets closed. + WaitForCacheSync(stopCh <-chan struct{}) map[reflect.Type]bool + + // ForResource gives generic access to a shared informer of the matching type. + ForResource(resource schema.GroupVersionResource) (GenericInformer, error) + + // InternalInformerFor returns the SharedIndexInformer for obj using an internal + // client. + InformerFor(obj runtime.Object, newFunc internalinterfaces.NewInformerFunc) cache.SharedIndexInformer + + Sonic() sonick8s.Interface +} + +func (f *sharedInformerFactory) Sonic() sonick8s.Interface { + return sonick8s.New(f, f.namespace, f.tweakListOptions) +} diff --git a/pkg/sonick8s/generated/informers/externalversions/generic.go b/pkg/sonick8s/generated/informers/externalversions/generic.go new file mode 100644 index 000000000..6ca406dba --- /dev/null +++ b/pkg/sonick8s/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" + + schema "k8s.io/apimachinery/pkg/runtime/schema" + cache "k8s.io/client-go/tools/cache" + v1alpha1 "k8s.io/sample-controller/pkg/apis/sonick8s/v1alpha1" +) + +// 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=sonic.k8s.io, Version=v1alpha1 + case v1alpha1.SchemeGroupVersion.WithResource("dcdaemonsets"): + return &genericInformer{resource: resource.GroupResource(), informer: f.Sonic().V1alpha1().DcDaemonSets().Informer()}, nil + + } + + return nil, fmt.Errorf("no informer found for %v", resource) +} diff --git a/pkg/sonick8s/generated/informers/externalversions/internalinterfaces/factory_interfaces.go b/pkg/sonick8s/generated/informers/externalversions/internalinterfaces/factory_interfaces.go new file mode 100644 index 000000000..5a8d3086b --- /dev/null +++ b/pkg/sonick8s/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/sonick8s/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/sonick8s/generated/informers/externalversions/sonick8s/interface.go b/pkg/sonick8s/generated/informers/externalversions/sonick8s/interface.go new file mode 100644 index 000000000..bd136f9c9 --- /dev/null +++ b/pkg/sonick8s/generated/informers/externalversions/sonick8s/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 sonick8s + +import ( + internalinterfaces "k8s.io/sample-controller/pkg/sonick8s/generated/informers/externalversions/internalinterfaces" + v1alpha1 "k8s.io/sample-controller/pkg/sonick8s/generated/informers/externalversions/sonick8s/v1alpha1" +) + +// Interface provides access to each of this group's versions. +type Interface interface { + // V1alpha1 provides access to shared informers for resources in V1alpha1. + V1alpha1() v1alpha1.Interface +} + +type group struct { + factory internalinterfaces.SharedInformerFactory + namespace string + tweakListOptions internalinterfaces.TweakListOptionsFunc +} + +// New returns a new Interface. +func New(f internalinterfaces.SharedInformerFactory, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) Interface { + return &group{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} +} + +// V1alpha1 returns a new v1alpha1.Interface. +func (g *group) V1alpha1() v1alpha1.Interface { + return v1alpha1.New(g.factory, g.namespace, g.tweakListOptions) +} diff --git a/pkg/sonick8s/generated/informers/externalversions/sonick8s/v1alpha1/dcdaemonset.go b/pkg/sonick8s/generated/informers/externalversions/sonick8s/v1alpha1/dcdaemonset.go new file mode 100644 index 000000000..9ebfc89b5 --- /dev/null +++ b/pkg/sonick8s/generated/informers/externalversions/sonick8s/v1alpha1/dcdaemonset.go @@ -0,0 +1,90 @@ +/* +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" + 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" + sonick8sv1alpha1 "k8s.io/sample-controller/pkg/apis/sonick8s/v1alpha1" + versioned "k8s.io/sample-controller/pkg/sonick8s/generated/clientset/versioned" + internalinterfaces "k8s.io/sample-controller/pkg/sonick8s/generated/informers/externalversions/internalinterfaces" + v1alpha1 "k8s.io/sample-controller/pkg/sonick8s/generated/listers/sonick8s/v1alpha1" +) + +// DcDaemonSetInformer provides access to a shared informer and lister for +// DcDaemonSets. +type DcDaemonSetInformer interface { + Informer() cache.SharedIndexInformer + Lister() v1alpha1.DcDaemonSetLister +} + +type dcDaemonSetInformer struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc + namespace string +} + +// NewDcDaemonSetInformer constructs a new informer for DcDaemonSet 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 NewDcDaemonSetInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return NewFilteredDcDaemonSetInformer(client, namespace, resyncPeriod, indexers, nil) +} + +// NewFilteredDcDaemonSetInformer constructs a new informer for DcDaemonSet 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 NewFilteredDcDaemonSetInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { + return cache.NewSharedIndexInformer( + &cache.ListWatch{ + ListFunc: func(options v1.ListOptions) (runtime.Object, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.SonicV1alpha1().DcDaemonSets(namespace).List(context.TODO(), options) + }, + WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.SonicV1alpha1().DcDaemonSets(namespace).Watch(context.TODO(), options) + }, + }, + &sonick8sv1alpha1.DcDaemonSet{}, + resyncPeriod, + indexers, + ) +} + +func (f *dcDaemonSetInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewFilteredDcDaemonSetInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) +} + +func (f *dcDaemonSetInformer) Informer() cache.SharedIndexInformer { + return f.factory.InformerFor(&sonick8sv1alpha1.DcDaemonSet{}, f.defaultInformer) +} + +func (f *dcDaemonSetInformer) Lister() v1alpha1.DcDaemonSetLister { + return v1alpha1.NewDcDaemonSetLister(f.Informer().GetIndexer()) +} diff --git a/pkg/sonick8s/generated/informers/externalversions/sonick8s/v1alpha1/interface.go b/pkg/sonick8s/generated/informers/externalversions/sonick8s/v1alpha1/interface.go new file mode 100644 index 000000000..2f3ad79ff --- /dev/null +++ b/pkg/sonick8s/generated/informers/externalversions/sonick8s/v1alpha1/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 v1alpha1 + +import ( + internalinterfaces "k8s.io/sample-controller/pkg/sonick8s/generated/informers/externalversions/internalinterfaces" +) + +// Interface provides access to all the informers in this group version. +type Interface interface { + // DcDaemonSets returns a DcDaemonSetInformer. + DcDaemonSets() DcDaemonSetInformer +} + +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} +} + +// DcDaemonSets returns a DcDaemonSetInformer. +func (v *version) DcDaemonSets() DcDaemonSetInformer { + return &dcDaemonSetInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} +} diff --git a/pkg/sonick8s/generated/listers/sonick8s/v1alpha1/dcdaemonset.go b/pkg/sonick8s/generated/listers/sonick8s/v1alpha1/dcdaemonset.go new file mode 100644 index 000000000..febd5deda --- /dev/null +++ b/pkg/sonick8s/generated/listers/sonick8s/v1alpha1/dcdaemonset.go @@ -0,0 +1,99 @@ +/* +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 ( + "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/tools/cache" + v1alpha1 "k8s.io/sample-controller/pkg/apis/sonick8s/v1alpha1" +) + +// DcDaemonSetLister helps list DcDaemonSets. +// All objects returned here must be treated as read-only. +type DcDaemonSetLister interface { + // List lists all DcDaemonSets in the indexer. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*v1alpha1.DcDaemonSet, err error) + // DcDaemonSets returns an object that can list and get DcDaemonSets. + DcDaemonSets(namespace string) DcDaemonSetNamespaceLister + DcDaemonSetListerExpansion +} + +// dcDaemonSetLister implements the DcDaemonSetLister interface. +type dcDaemonSetLister struct { + indexer cache.Indexer +} + +// NewDcDaemonSetLister returns a new DcDaemonSetLister. +func NewDcDaemonSetLister(indexer cache.Indexer) DcDaemonSetLister { + return &dcDaemonSetLister{indexer: indexer} +} + +// List lists all DcDaemonSets in the indexer. +func (s *dcDaemonSetLister) List(selector labels.Selector) (ret []*v1alpha1.DcDaemonSet, err error) { + err = cache.ListAll(s.indexer, selector, func(m interface{}) { + ret = append(ret, m.(*v1alpha1.DcDaemonSet)) + }) + return ret, err +} + +// DcDaemonSets returns an object that can list and get DcDaemonSets. +func (s *dcDaemonSetLister) DcDaemonSets(namespace string) DcDaemonSetNamespaceLister { + return dcDaemonSetNamespaceLister{indexer: s.indexer, namespace: namespace} +} + +// DcDaemonSetNamespaceLister helps list and get DcDaemonSets. +// All objects returned here must be treated as read-only. +type DcDaemonSetNamespaceLister interface { + // List lists all DcDaemonSets in the indexer for a given namespace. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*v1alpha1.DcDaemonSet, err error) + // Get retrieves the DcDaemonSet from the indexer for a given namespace and name. + // Objects returned here must be treated as read-only. + Get(name string) (*v1alpha1.DcDaemonSet, error) + DcDaemonSetNamespaceListerExpansion +} + +// dcDaemonSetNamespaceLister implements the DcDaemonSetNamespaceLister +// interface. +type dcDaemonSetNamespaceLister struct { + indexer cache.Indexer + namespace string +} + +// List lists all DcDaemonSets in the indexer for a given namespace. +func (s dcDaemonSetNamespaceLister) List(selector labels.Selector) (ret []*v1alpha1.DcDaemonSet, err error) { + err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { + ret = append(ret, m.(*v1alpha1.DcDaemonSet)) + }) + return ret, err +} + +// Get retrieves the DcDaemonSet from the indexer for a given namespace and name. +func (s dcDaemonSetNamespaceLister) Get(name string) (*v1alpha1.DcDaemonSet, error) { + obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) + if err != nil { + return nil, err + } + if !exists { + return nil, errors.NewNotFound(v1alpha1.Resource("dcdaemonset"), name) + } + return obj.(*v1alpha1.DcDaemonSet), nil +} diff --git a/pkg/sonick8s/generated/listers/sonick8s/v1alpha1/expansion_generated.go b/pkg/sonick8s/generated/listers/sonick8s/v1alpha1/expansion_generated.go new file mode 100644 index 000000000..ebb17c3f7 --- /dev/null +++ b/pkg/sonick8s/generated/listers/sonick8s/v1alpha1/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 v1alpha1 + +// DcDaemonSetListerExpansion allows custom methods to be added to +// DcDaemonSetLister. +type DcDaemonSetListerExpansion interface{} + +// DcDaemonSetNamespaceListerExpansion allows custom methods to be added to +// DcDaemonSetNamespaceLister. +type DcDaemonSetNamespaceListerExpansion interface{} From efd17682983e4ef41a592100da14dfd190b5d5f0 Mon Sep 17 00:00:00 2001 From: Longquan Sha Date: Wed, 12 Apr 2023 09:26:50 +0800 Subject: [PATCH 06/22] update --- artifacts/examples/crd-sonic.yaml | 31 +++++++++++++++++++------- pkg/apis/sonick8s/v1alpha1/types.go | 34 +++++++++++++++++------------ 2 files changed, 43 insertions(+), 22 deletions(-) diff --git a/artifacts/examples/crd-sonic.yaml b/artifacts/examples/crd-sonic.yaml index 3553bacb6..587e1c853 100644 --- a/artifacts/examples/crd-sonic.yaml +++ b/artifacts/examples/crd-sonic.yaml @@ -1,13 +1,13 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: - name: dcdaemonsets.sonic.k8s.io + name: sonicdaemonsetdeployments.sonic.k8s.io # for more information on the below annotation, please see # https://github.com/kubernetes/enhancements/blob/master/keps/sig-api-machinery/2337-k8s.io-group-protection/README.md annotations: "api-approved.kubernetes.io": "unapproved, experimental-only; please get an approval from Kubernetes API reviewers if you're trying to develop a CRD in the *.k8s.io or *.kubernetes.io groups" spec: - group: sonic.k8s.io + group: sonick8s.io versions: - name: v1alpha1 served: true @@ -20,7 +20,13 @@ spec: spec: type: object properties: - daemonsetVersion: + scopeType: + type: string + scopeValue: + type: string + daemonSetType: + type: string + daemonSetVersion: type: string pause: type: boolean @@ -31,20 +37,29 @@ spec: type: integer currentDaemonSetCount: type: integer - daemonsetList: + daemonSetList: + type: array + items: + type: object + properties: + daemonSetName: + type: string + daemonSetVersion: + type: string + updateInProgressDaemonSetList: type: array items: type: object properties: - daemonsetName: + daemonSetName: type: string - daemonsetVersion: + daemonSetVersion: type: string # subresources for the custom resource subresources: # enables the status subresource status: {} names: - kind: DcDaemonSet - plural: dcdaemonsets + kind: SonicDaemonSetDeployment + plural: sonicdaemonsetdeployments scope: Namespaced \ No newline at end of file diff --git a/pkg/apis/sonick8s/v1alpha1/types.go b/pkg/apis/sonick8s/v1alpha1/types.go index 5800c602b..f2a514b1b 100644 --- a/pkg/apis/sonick8s/v1alpha1/types.go +++ b/pkg/apis/sonick8s/v1alpha1/types.go @@ -23,26 +23,32 @@ import ( // +genclient // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object -// Foo is a specification for a Foo resource -type DcDaemonSet struct { +// SonicDaemonSetDeployment is a specification for a SonicDaemonSetDeployment resource +type SonicDaemonSetDeployment struct { metav1.TypeMeta `json:",inline"` metav1.ObjectMeta `json:"metadata,omitempty"` - Spec DcDaemonSetSpec `json:"spec"` - Status DcDaemonSetStatus `json:"status"` + Spec SonicDaemonSetDeploymentSpec `json:"spec"` + Status SonicDaemonSetDeploymentStatus `json:"status"` } -// FooSpec is the spec for a Foo resource -type DcDaemonSetSpec struct { +// SonicDaemonSetDeploymentSpec is the spec for a SonicDaemonSetDeployment resource +type SonicDaemonSetDeploymentSpec struct { + // ScopeType: datacenter or region + ScopeType string `json:"scopeType"` + ScopeValue string `json:"scopeValue"` + // sonic feature such as telemetry, snmp, etc + DaemonSetType string `json:"daemonSetType"` DaemonSetVersion string `json:"daemonSetVersion"` Pause bool `json:"pause"` } -// FooStatus is the status for a Foo resource -type DcDaemonSetStatus struct { - DesiredDaemonSetCount int `json:"desiredDaemonSetCount"` - CurrentDaemonSetCount int `json:"currentDaemonSetCount"` - DaemonsetList []DaemonSetItem `json:"daemonsetList"` +// SonicDaemonSetDeploymentStatus is the status for a SonicDaemonSetDeployment resource +type SonicDaemonSetDeploymentStatus struct { + DesiredDaemonSetCount int `json:"desiredDaemonSetCount"` + CurrentDaemonSetCount int `json:"currentDaemonSetCount"` + DaemonsetList []DaemonSetItem `json:"daemonSetList"` + UpdateInProgressDaemonsetList []DaemonSetItem `json:"updateInProgressDaemonSetList"` } type DaemonSetItem struct { @@ -52,10 +58,10 @@ type DaemonSetItem struct { // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object -// FooList is a list of Foo resources -type DcDaemonSetList struct { +// SonicDaemonSetDeploymentList is a list of SonicDaemonSetDeployment resources +type SonicDaemonSetDeploymentList struct { metav1.TypeMeta `json:",inline"` metav1.ListMeta `json:"metadata"` - Items []DcDaemonSet `json:"items"` + Items []SonicDaemonSetDeployment `json:"items"` } From 5c2b54a02847f8f72262a1a92cd7b48757efe48e Mon Sep 17 00:00:00 2001 From: LOngquan Sha Date: Wed, 12 Apr 2023 01:29:44 +0000 Subject: [PATCH 07/22] Generate resource client code for sonic --- .../v1alpha1/zz_generated.deepcopy.go | 43 ++-- .../fake/fake_sonicdaemonsetdeployment.go | 141 +++++++++++++ .../v1alpha1/fake/fake_sonick8s_client.go | 4 +- .../sonick8s/v1alpha1/generated_expansion.go | 2 +- .../v1alpha1/sonicdaemonsetdeployment.go | 195 ++++++++++++++++++ .../sonick8s/v1alpha1/sonick8s_client.go | 6 +- .../informers/externalversions/generic.go | 4 +- .../sonick8s/v1alpha1/interface.go | 10 +- .../v1alpha1/sonicdaemonsetdeployment.go | 90 ++++++++ .../sonick8s/v1alpha1/expansion_generated.go | 12 +- .../v1alpha1/sonicdaemonsetdeployment.go | 99 +++++++++ 11 files changed, 568 insertions(+), 38 deletions(-) create mode 100644 pkg/sonick8s/generated/clientset/versioned/typed/sonick8s/v1alpha1/fake/fake_sonicdaemonsetdeployment.go create mode 100644 pkg/sonick8s/generated/clientset/versioned/typed/sonick8s/v1alpha1/sonicdaemonsetdeployment.go create mode 100644 pkg/sonick8s/generated/informers/externalversions/sonick8s/v1alpha1/sonicdaemonsetdeployment.go create mode 100644 pkg/sonick8s/generated/listers/sonick8s/v1alpha1/sonicdaemonsetdeployment.go diff --git a/pkg/apis/sonick8s/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/sonick8s/v1alpha1/zz_generated.deepcopy.go index 6a333837a..1cf7027ac 100644 --- a/pkg/apis/sonick8s/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/sonick8s/v1alpha1/zz_generated.deepcopy.go @@ -42,7 +42,7 @@ func (in *DaemonSetItem) DeepCopy() *DaemonSetItem { } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *DcDaemonSet) DeepCopyInto(out *DcDaemonSet) { +func (in *SonicDaemonSetDeployment) DeepCopyInto(out *SonicDaemonSetDeployment) { *out = *in out.TypeMeta = in.TypeMeta in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) @@ -51,18 +51,18 @@ func (in *DcDaemonSet) DeepCopyInto(out *DcDaemonSet) { return } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DcDaemonSet. -func (in *DcDaemonSet) DeepCopy() *DcDaemonSet { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SonicDaemonSetDeployment. +func (in *SonicDaemonSetDeployment) DeepCopy() *SonicDaemonSetDeployment { if in == nil { return nil } - out := new(DcDaemonSet) + out := new(SonicDaemonSetDeployment) in.DeepCopyInto(out) return out } // DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *DcDaemonSet) DeepCopyObject() runtime.Object { +func (in *SonicDaemonSetDeployment) DeepCopyObject() runtime.Object { if c := in.DeepCopy(); c != nil { return c } @@ -70,13 +70,13 @@ func (in *DcDaemonSet) DeepCopyObject() runtime.Object { } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *DcDaemonSetList) DeepCopyInto(out *DcDaemonSetList) { +func (in *SonicDaemonSetDeploymentList) DeepCopyInto(out *SonicDaemonSetDeploymentList) { *out = *in out.TypeMeta = in.TypeMeta in.ListMeta.DeepCopyInto(&out.ListMeta) if in.Items != nil { in, out := &in.Items, &out.Items - *out = make([]DcDaemonSet, len(*in)) + *out = make([]SonicDaemonSetDeployment, len(*in)) for i := range *in { (*in)[i].DeepCopyInto(&(*out)[i]) } @@ -84,18 +84,18 @@ func (in *DcDaemonSetList) DeepCopyInto(out *DcDaemonSetList) { return } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DcDaemonSetList. -func (in *DcDaemonSetList) DeepCopy() *DcDaemonSetList { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SonicDaemonSetDeploymentList. +func (in *SonicDaemonSetDeploymentList) DeepCopy() *SonicDaemonSetDeploymentList { if in == nil { return nil } - out := new(DcDaemonSetList) + out := new(SonicDaemonSetDeploymentList) in.DeepCopyInto(out) return out } // DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *DcDaemonSetList) DeepCopyObject() runtime.Object { +func (in *SonicDaemonSetDeploymentList) DeepCopyObject() runtime.Object { if c := in.DeepCopy(); c != nil { return c } @@ -103,38 +103,43 @@ func (in *DcDaemonSetList) DeepCopyObject() runtime.Object { } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *DcDaemonSetSpec) DeepCopyInto(out *DcDaemonSetSpec) { +func (in *SonicDaemonSetDeploymentSpec) DeepCopyInto(out *SonicDaemonSetDeploymentSpec) { *out = *in return } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DcDaemonSetSpec. -func (in *DcDaemonSetSpec) DeepCopy() *DcDaemonSetSpec { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SonicDaemonSetDeploymentSpec. +func (in *SonicDaemonSetDeploymentSpec) DeepCopy() *SonicDaemonSetDeploymentSpec { if in == nil { return nil } - out := new(DcDaemonSetSpec) + out := new(SonicDaemonSetDeploymentSpec) in.DeepCopyInto(out) return out } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *DcDaemonSetStatus) DeepCopyInto(out *DcDaemonSetStatus) { +func (in *SonicDaemonSetDeploymentStatus) DeepCopyInto(out *SonicDaemonSetDeploymentStatus) { *out = *in if in.DaemonsetList != nil { in, out := &in.DaemonsetList, &out.DaemonsetList *out = make([]DaemonSetItem, len(*in)) copy(*out, *in) } + if in.UpdateInProgressDaemonsetList != nil { + in, out := &in.UpdateInProgressDaemonsetList, &out.UpdateInProgressDaemonsetList + *out = make([]DaemonSetItem, len(*in)) + copy(*out, *in) + } return } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DcDaemonSetStatus. -func (in *DcDaemonSetStatus) DeepCopy() *DcDaemonSetStatus { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SonicDaemonSetDeploymentStatus. +func (in *SonicDaemonSetDeploymentStatus) DeepCopy() *SonicDaemonSetDeploymentStatus { if in == nil { return nil } - out := new(DcDaemonSetStatus) + out := new(SonicDaemonSetDeploymentStatus) in.DeepCopyInto(out) return out } diff --git a/pkg/sonick8s/generated/clientset/versioned/typed/sonick8s/v1alpha1/fake/fake_sonicdaemonsetdeployment.go b/pkg/sonick8s/generated/clientset/versioned/typed/sonick8s/v1alpha1/fake/fake_sonicdaemonsetdeployment.go new file mode 100644 index 000000000..a44b1acea --- /dev/null +++ b/pkg/sonick8s/generated/clientset/versioned/typed/sonick8s/v1alpha1/fake/fake_sonicdaemonsetdeployment.go @@ -0,0 +1,141 @@ +/* +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 ( + "context" + + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + labels "k8s.io/apimachinery/pkg/labels" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + testing "k8s.io/client-go/testing" + v1alpha1 "k8s.io/sample-controller/pkg/apis/sonick8s/v1alpha1" +) + +// FakeSonicDaemonSetDeployments implements SonicDaemonSetDeploymentInterface +type FakeSonicDaemonSetDeployments struct { + Fake *FakeSonicV1alpha1 + ns string +} + +var sonicdaemonsetdeploymentsResource = v1alpha1.SchemeGroupVersion.WithResource("sonicdaemonsetdeployments") + +var sonicdaemonsetdeploymentsKind = v1alpha1.SchemeGroupVersion.WithKind("SonicDaemonSetDeployment") + +// Get takes name of the sonicDaemonSetDeployment, and returns the corresponding sonicDaemonSetDeployment object, and an error if there is any. +func (c *FakeSonicDaemonSetDeployments) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha1.SonicDaemonSetDeployment, err error) { + obj, err := c.Fake. + Invokes(testing.NewGetAction(sonicdaemonsetdeploymentsResource, c.ns, name), &v1alpha1.SonicDaemonSetDeployment{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.SonicDaemonSetDeployment), err +} + +// List takes label and field selectors, and returns the list of SonicDaemonSetDeployments that match those selectors. +func (c *FakeSonicDaemonSetDeployments) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha1.SonicDaemonSetDeploymentList, err error) { + obj, err := c.Fake. + Invokes(testing.NewListAction(sonicdaemonsetdeploymentsResource, sonicdaemonsetdeploymentsKind, c.ns, opts), &v1alpha1.SonicDaemonSetDeploymentList{}) + + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &v1alpha1.SonicDaemonSetDeploymentList{ListMeta: obj.(*v1alpha1.SonicDaemonSetDeploymentList).ListMeta} + for _, item := range obj.(*v1alpha1.SonicDaemonSetDeploymentList).Items { + if label.Matches(labels.Set(item.Labels)) { + list.Items = append(list.Items, item) + } + } + return list, err +} + +// Watch returns a watch.Interface that watches the requested sonicDaemonSetDeployments. +func (c *FakeSonicDaemonSetDeployments) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { + return c.Fake. + InvokesWatch(testing.NewWatchAction(sonicdaemonsetdeploymentsResource, c.ns, opts)) + +} + +// Create takes the representation of a sonicDaemonSetDeployment and creates it. Returns the server's representation of the sonicDaemonSetDeployment, and an error, if there is any. +func (c *FakeSonicDaemonSetDeployments) Create(ctx context.Context, sonicDaemonSetDeployment *v1alpha1.SonicDaemonSetDeployment, opts v1.CreateOptions) (result *v1alpha1.SonicDaemonSetDeployment, err error) { + obj, err := c.Fake. + Invokes(testing.NewCreateAction(sonicdaemonsetdeploymentsResource, c.ns, sonicDaemonSetDeployment), &v1alpha1.SonicDaemonSetDeployment{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.SonicDaemonSetDeployment), err +} + +// Update takes the representation of a sonicDaemonSetDeployment and updates it. Returns the server's representation of the sonicDaemonSetDeployment, and an error, if there is any. +func (c *FakeSonicDaemonSetDeployments) Update(ctx context.Context, sonicDaemonSetDeployment *v1alpha1.SonicDaemonSetDeployment, opts v1.UpdateOptions) (result *v1alpha1.SonicDaemonSetDeployment, err error) { + obj, err := c.Fake. + Invokes(testing.NewUpdateAction(sonicdaemonsetdeploymentsResource, c.ns, sonicDaemonSetDeployment), &v1alpha1.SonicDaemonSetDeployment{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.SonicDaemonSetDeployment), err +} + +// UpdateStatus was generated because the type contains a Status member. +// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). +func (c *FakeSonicDaemonSetDeployments) UpdateStatus(ctx context.Context, sonicDaemonSetDeployment *v1alpha1.SonicDaemonSetDeployment, opts v1.UpdateOptions) (*v1alpha1.SonicDaemonSetDeployment, error) { + obj, err := c.Fake. + Invokes(testing.NewUpdateSubresourceAction(sonicdaemonsetdeploymentsResource, "status", c.ns, sonicDaemonSetDeployment), &v1alpha1.SonicDaemonSetDeployment{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.SonicDaemonSetDeployment), err +} + +// Delete takes name of the sonicDaemonSetDeployment and deletes it. Returns an error if one occurs. +func (c *FakeSonicDaemonSetDeployments) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { + _, err := c.Fake. + Invokes(testing.NewDeleteActionWithOptions(sonicdaemonsetdeploymentsResource, c.ns, name, opts), &v1alpha1.SonicDaemonSetDeployment{}) + + return err +} + +// DeleteCollection deletes a collection of objects. +func (c *FakeSonicDaemonSetDeployments) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { + action := testing.NewDeleteCollectionAction(sonicdaemonsetdeploymentsResource, c.ns, listOpts) + + _, err := c.Fake.Invokes(action, &v1alpha1.SonicDaemonSetDeploymentList{}) + return err +} + +// Patch applies the patch and returns the patched sonicDaemonSetDeployment. +func (c *FakeSonicDaemonSetDeployments) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.SonicDaemonSetDeployment, err error) { + obj, err := c.Fake. + Invokes(testing.NewPatchSubresourceAction(sonicdaemonsetdeploymentsResource, c.ns, name, pt, data, subresources...), &v1alpha1.SonicDaemonSetDeployment{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.SonicDaemonSetDeployment), err +} diff --git a/pkg/sonick8s/generated/clientset/versioned/typed/sonick8s/v1alpha1/fake/fake_sonick8s_client.go b/pkg/sonick8s/generated/clientset/versioned/typed/sonick8s/v1alpha1/fake/fake_sonick8s_client.go index 7a05150fb..8568624bf 100644 --- a/pkg/sonick8s/generated/clientset/versioned/typed/sonick8s/v1alpha1/fake/fake_sonick8s_client.go +++ b/pkg/sonick8s/generated/clientset/versioned/typed/sonick8s/v1alpha1/fake/fake_sonick8s_client.go @@ -28,8 +28,8 @@ type FakeSonicV1alpha1 struct { *testing.Fake } -func (c *FakeSonicV1alpha1) DcDaemonSets(namespace string) v1alpha1.DcDaemonSetInterface { - return &FakeDcDaemonSets{c, namespace} +func (c *FakeSonicV1alpha1) SonicDaemonSetDeployments(namespace string) v1alpha1.SonicDaemonSetDeploymentInterface { + return &FakeSonicDaemonSetDeployments{c, namespace} } // RESTClient returns a RESTClient that is used to communicate diff --git a/pkg/sonick8s/generated/clientset/versioned/typed/sonick8s/v1alpha1/generated_expansion.go b/pkg/sonick8s/generated/clientset/versioned/typed/sonick8s/v1alpha1/generated_expansion.go index 87c70d7a7..47ee5aaed 100644 --- a/pkg/sonick8s/generated/clientset/versioned/typed/sonick8s/v1alpha1/generated_expansion.go +++ b/pkg/sonick8s/generated/clientset/versioned/typed/sonick8s/v1alpha1/generated_expansion.go @@ -18,4 +18,4 @@ limitations under the License. package v1alpha1 -type DcDaemonSetExpansion interface{} +type SonicDaemonSetDeploymentExpansion interface{} diff --git a/pkg/sonick8s/generated/clientset/versioned/typed/sonick8s/v1alpha1/sonicdaemonsetdeployment.go b/pkg/sonick8s/generated/clientset/versioned/typed/sonick8s/v1alpha1/sonicdaemonsetdeployment.go new file mode 100644 index 000000000..de01c9263 --- /dev/null +++ b/pkg/sonick8s/generated/clientset/versioned/typed/sonick8s/v1alpha1/sonicdaemonsetdeployment.go @@ -0,0 +1,195 @@ +/* +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" + "time" + + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + rest "k8s.io/client-go/rest" + v1alpha1 "k8s.io/sample-controller/pkg/apis/sonick8s/v1alpha1" + scheme "k8s.io/sample-controller/pkg/sonick8s/generated/clientset/versioned/scheme" +) + +// SonicDaemonSetDeploymentsGetter has a method to return a SonicDaemonSetDeploymentInterface. +// A group's client should implement this interface. +type SonicDaemonSetDeploymentsGetter interface { + SonicDaemonSetDeployments(namespace string) SonicDaemonSetDeploymentInterface +} + +// SonicDaemonSetDeploymentInterface has methods to work with SonicDaemonSetDeployment resources. +type SonicDaemonSetDeploymentInterface interface { + Create(ctx context.Context, sonicDaemonSetDeployment *v1alpha1.SonicDaemonSetDeployment, opts v1.CreateOptions) (*v1alpha1.SonicDaemonSetDeployment, error) + Update(ctx context.Context, sonicDaemonSetDeployment *v1alpha1.SonicDaemonSetDeployment, opts v1.UpdateOptions) (*v1alpha1.SonicDaemonSetDeployment, error) + UpdateStatus(ctx context.Context, sonicDaemonSetDeployment *v1alpha1.SonicDaemonSetDeployment, opts v1.UpdateOptions) (*v1alpha1.SonicDaemonSetDeployment, error) + Delete(ctx context.Context, name string, opts v1.DeleteOptions) error + DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error + Get(ctx context.Context, name string, opts v1.GetOptions) (*v1alpha1.SonicDaemonSetDeployment, error) + List(ctx context.Context, opts v1.ListOptions) (*v1alpha1.SonicDaemonSetDeploymentList, error) + Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) + Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.SonicDaemonSetDeployment, err error) + SonicDaemonSetDeploymentExpansion +} + +// sonicDaemonSetDeployments implements SonicDaemonSetDeploymentInterface +type sonicDaemonSetDeployments struct { + client rest.Interface + ns string +} + +// newSonicDaemonSetDeployments returns a SonicDaemonSetDeployments +func newSonicDaemonSetDeployments(c *SonicV1alpha1Client, namespace string) *sonicDaemonSetDeployments { + return &sonicDaemonSetDeployments{ + client: c.RESTClient(), + ns: namespace, + } +} + +// Get takes name of the sonicDaemonSetDeployment, and returns the corresponding sonicDaemonSetDeployment object, and an error if there is any. +func (c *sonicDaemonSetDeployments) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha1.SonicDaemonSetDeployment, err error) { + result = &v1alpha1.SonicDaemonSetDeployment{} + err = c.client.Get(). + Namespace(c.ns). + Resource("sonicdaemonsetdeployments"). + Name(name). + VersionedParams(&options, scheme.ParameterCodec). + Do(ctx). + Into(result) + return +} + +// List takes label and field selectors, and returns the list of SonicDaemonSetDeployments that match those selectors. +func (c *sonicDaemonSetDeployments) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha1.SonicDaemonSetDeploymentList, err error) { + var timeout time.Duration + if opts.TimeoutSeconds != nil { + timeout = time.Duration(*opts.TimeoutSeconds) * time.Second + } + result = &v1alpha1.SonicDaemonSetDeploymentList{} + err = c.client.Get(). + Namespace(c.ns). + Resource("sonicdaemonsetdeployments"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Do(ctx). + Into(result) + return +} + +// Watch returns a watch.Interface that watches the requested sonicDaemonSetDeployments. +func (c *sonicDaemonSetDeployments) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { + var timeout time.Duration + if opts.TimeoutSeconds != nil { + timeout = time.Duration(*opts.TimeoutSeconds) * time.Second + } + opts.Watch = true + return c.client.Get(). + Namespace(c.ns). + Resource("sonicdaemonsetdeployments"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Watch(ctx) +} + +// Create takes the representation of a sonicDaemonSetDeployment and creates it. Returns the server's representation of the sonicDaemonSetDeployment, and an error, if there is any. +func (c *sonicDaemonSetDeployments) Create(ctx context.Context, sonicDaemonSetDeployment *v1alpha1.SonicDaemonSetDeployment, opts v1.CreateOptions) (result *v1alpha1.SonicDaemonSetDeployment, err error) { + result = &v1alpha1.SonicDaemonSetDeployment{} + err = c.client.Post(). + Namespace(c.ns). + Resource("sonicdaemonsetdeployments"). + VersionedParams(&opts, scheme.ParameterCodec). + Body(sonicDaemonSetDeployment). + Do(ctx). + Into(result) + return +} + +// Update takes the representation of a sonicDaemonSetDeployment and updates it. Returns the server's representation of the sonicDaemonSetDeployment, and an error, if there is any. +func (c *sonicDaemonSetDeployments) Update(ctx context.Context, sonicDaemonSetDeployment *v1alpha1.SonicDaemonSetDeployment, opts v1.UpdateOptions) (result *v1alpha1.SonicDaemonSetDeployment, err error) { + result = &v1alpha1.SonicDaemonSetDeployment{} + err = c.client.Put(). + Namespace(c.ns). + Resource("sonicdaemonsetdeployments"). + Name(sonicDaemonSetDeployment.Name). + VersionedParams(&opts, scheme.ParameterCodec). + Body(sonicDaemonSetDeployment). + Do(ctx). + Into(result) + return +} + +// UpdateStatus was generated because the type contains a Status member. +// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). +func (c *sonicDaemonSetDeployments) UpdateStatus(ctx context.Context, sonicDaemonSetDeployment *v1alpha1.SonicDaemonSetDeployment, opts v1.UpdateOptions) (result *v1alpha1.SonicDaemonSetDeployment, err error) { + result = &v1alpha1.SonicDaemonSetDeployment{} + err = c.client.Put(). + Namespace(c.ns). + Resource("sonicdaemonsetdeployments"). + Name(sonicDaemonSetDeployment.Name). + SubResource("status"). + VersionedParams(&opts, scheme.ParameterCodec). + Body(sonicDaemonSetDeployment). + Do(ctx). + Into(result) + return +} + +// Delete takes name of the sonicDaemonSetDeployment and deletes it. Returns an error if one occurs. +func (c *sonicDaemonSetDeployments) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { + return c.client.Delete(). + Namespace(c.ns). + Resource("sonicdaemonsetdeployments"). + Name(name). + Body(&opts). + Do(ctx). + Error() +} + +// DeleteCollection deletes a collection of objects. +func (c *sonicDaemonSetDeployments) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { + var timeout time.Duration + if listOpts.TimeoutSeconds != nil { + timeout = time.Duration(*listOpts.TimeoutSeconds) * time.Second + } + return c.client.Delete(). + Namespace(c.ns). + Resource("sonicdaemonsetdeployments"). + VersionedParams(&listOpts, scheme.ParameterCodec). + Timeout(timeout). + Body(&opts). + Do(ctx). + Error() +} + +// Patch applies the patch and returns the patched sonicDaemonSetDeployment. +func (c *sonicDaemonSetDeployments) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.SonicDaemonSetDeployment, err error) { + result = &v1alpha1.SonicDaemonSetDeployment{} + err = c.client.Patch(pt). + Namespace(c.ns). + Resource("sonicdaemonsetdeployments"). + Name(name). + SubResource(subresources...). + VersionedParams(&opts, scheme.ParameterCodec). + Body(data). + Do(ctx). + Into(result) + return +} diff --git a/pkg/sonick8s/generated/clientset/versioned/typed/sonick8s/v1alpha1/sonick8s_client.go b/pkg/sonick8s/generated/clientset/versioned/typed/sonick8s/v1alpha1/sonick8s_client.go index ceed0625a..839d25ad9 100644 --- a/pkg/sonick8s/generated/clientset/versioned/typed/sonick8s/v1alpha1/sonick8s_client.go +++ b/pkg/sonick8s/generated/clientset/versioned/typed/sonick8s/v1alpha1/sonick8s_client.go @@ -28,7 +28,7 @@ import ( type SonicV1alpha1Interface interface { RESTClient() rest.Interface - DcDaemonSetsGetter + SonicDaemonSetDeploymentsGetter } // SonicV1alpha1Client is used to interact with features provided by the sonic.k8s.io group. @@ -36,8 +36,8 @@ type SonicV1alpha1Client struct { restClient rest.Interface } -func (c *SonicV1alpha1Client) DcDaemonSets(namespace string) DcDaemonSetInterface { - return newDcDaemonSets(c, namespace) +func (c *SonicV1alpha1Client) SonicDaemonSetDeployments(namespace string) SonicDaemonSetDeploymentInterface { + return newSonicDaemonSetDeployments(c, namespace) } // NewForConfig creates a new SonicV1alpha1Client for the given config. diff --git a/pkg/sonick8s/generated/informers/externalversions/generic.go b/pkg/sonick8s/generated/informers/externalversions/generic.go index 6ca406dba..91188ac00 100644 --- a/pkg/sonick8s/generated/informers/externalversions/generic.go +++ b/pkg/sonick8s/generated/informers/externalversions/generic.go @@ -53,8 +53,8 @@ func (f *genericInformer) Lister() cache.GenericLister { func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource) (GenericInformer, error) { switch resource { // Group=sonic.k8s.io, Version=v1alpha1 - case v1alpha1.SchemeGroupVersion.WithResource("dcdaemonsets"): - return &genericInformer{resource: resource.GroupResource(), informer: f.Sonic().V1alpha1().DcDaemonSets().Informer()}, nil + case v1alpha1.SchemeGroupVersion.WithResource("sonicdaemonsetdeployments"): + return &genericInformer{resource: resource.GroupResource(), informer: f.Sonic().V1alpha1().SonicDaemonSetDeployments().Informer()}, nil } diff --git a/pkg/sonick8s/generated/informers/externalversions/sonick8s/v1alpha1/interface.go b/pkg/sonick8s/generated/informers/externalversions/sonick8s/v1alpha1/interface.go index 2f3ad79ff..cef3e40c9 100644 --- a/pkg/sonick8s/generated/informers/externalversions/sonick8s/v1alpha1/interface.go +++ b/pkg/sonick8s/generated/informers/externalversions/sonick8s/v1alpha1/interface.go @@ -24,8 +24,8 @@ import ( // Interface provides access to all the informers in this group version. type Interface interface { - // DcDaemonSets returns a DcDaemonSetInformer. - DcDaemonSets() DcDaemonSetInformer + // SonicDaemonSetDeployments returns a SonicDaemonSetDeploymentInformer. + SonicDaemonSetDeployments() SonicDaemonSetDeploymentInformer } type version struct { @@ -39,7 +39,7 @@ func New(f internalinterfaces.SharedInformerFactory, namespace string, tweakList return &version{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} } -// DcDaemonSets returns a DcDaemonSetInformer. -func (v *version) DcDaemonSets() DcDaemonSetInformer { - return &dcDaemonSetInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} +// SonicDaemonSetDeployments returns a SonicDaemonSetDeploymentInformer. +func (v *version) SonicDaemonSetDeployments() SonicDaemonSetDeploymentInformer { + return &sonicDaemonSetDeploymentInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} } diff --git a/pkg/sonick8s/generated/informers/externalversions/sonick8s/v1alpha1/sonicdaemonsetdeployment.go b/pkg/sonick8s/generated/informers/externalversions/sonick8s/v1alpha1/sonicdaemonsetdeployment.go new file mode 100644 index 000000000..b51f31685 --- /dev/null +++ b/pkg/sonick8s/generated/informers/externalversions/sonick8s/v1alpha1/sonicdaemonsetdeployment.go @@ -0,0 +1,90 @@ +/* +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" + 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" + sonick8sv1alpha1 "k8s.io/sample-controller/pkg/apis/sonick8s/v1alpha1" + versioned "k8s.io/sample-controller/pkg/sonick8s/generated/clientset/versioned" + internalinterfaces "k8s.io/sample-controller/pkg/sonick8s/generated/informers/externalversions/internalinterfaces" + v1alpha1 "k8s.io/sample-controller/pkg/sonick8s/generated/listers/sonick8s/v1alpha1" +) + +// SonicDaemonSetDeploymentInformer provides access to a shared informer and lister for +// SonicDaemonSetDeployments. +type SonicDaemonSetDeploymentInformer interface { + Informer() cache.SharedIndexInformer + Lister() v1alpha1.SonicDaemonSetDeploymentLister +} + +type sonicDaemonSetDeploymentInformer struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc + namespace string +} + +// NewSonicDaemonSetDeploymentInformer constructs a new informer for SonicDaemonSetDeployment 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 NewSonicDaemonSetDeploymentInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return NewFilteredSonicDaemonSetDeploymentInformer(client, namespace, resyncPeriod, indexers, nil) +} + +// NewFilteredSonicDaemonSetDeploymentInformer constructs a new informer for SonicDaemonSetDeployment 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 NewFilteredSonicDaemonSetDeploymentInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { + return cache.NewSharedIndexInformer( + &cache.ListWatch{ + ListFunc: func(options v1.ListOptions) (runtime.Object, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.SonicV1alpha1().SonicDaemonSetDeployments(namespace).List(context.TODO(), options) + }, + WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.SonicV1alpha1().SonicDaemonSetDeployments(namespace).Watch(context.TODO(), options) + }, + }, + &sonick8sv1alpha1.SonicDaemonSetDeployment{}, + resyncPeriod, + indexers, + ) +} + +func (f *sonicDaemonSetDeploymentInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewFilteredSonicDaemonSetDeploymentInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) +} + +func (f *sonicDaemonSetDeploymentInformer) Informer() cache.SharedIndexInformer { + return f.factory.InformerFor(&sonick8sv1alpha1.SonicDaemonSetDeployment{}, f.defaultInformer) +} + +func (f *sonicDaemonSetDeploymentInformer) Lister() v1alpha1.SonicDaemonSetDeploymentLister { + return v1alpha1.NewSonicDaemonSetDeploymentLister(f.Informer().GetIndexer()) +} diff --git a/pkg/sonick8s/generated/listers/sonick8s/v1alpha1/expansion_generated.go b/pkg/sonick8s/generated/listers/sonick8s/v1alpha1/expansion_generated.go index ebb17c3f7..91264768f 100644 --- a/pkg/sonick8s/generated/listers/sonick8s/v1alpha1/expansion_generated.go +++ b/pkg/sonick8s/generated/listers/sonick8s/v1alpha1/expansion_generated.go @@ -18,10 +18,10 @@ limitations under the License. package v1alpha1 -// DcDaemonSetListerExpansion allows custom methods to be added to -// DcDaemonSetLister. -type DcDaemonSetListerExpansion interface{} +// SonicDaemonSetDeploymentListerExpansion allows custom methods to be added to +// SonicDaemonSetDeploymentLister. +type SonicDaemonSetDeploymentListerExpansion interface{} -// DcDaemonSetNamespaceListerExpansion allows custom methods to be added to -// DcDaemonSetNamespaceLister. -type DcDaemonSetNamespaceListerExpansion interface{} +// SonicDaemonSetDeploymentNamespaceListerExpansion allows custom methods to be added to +// SonicDaemonSetDeploymentNamespaceLister. +type SonicDaemonSetDeploymentNamespaceListerExpansion interface{} diff --git a/pkg/sonick8s/generated/listers/sonick8s/v1alpha1/sonicdaemonsetdeployment.go b/pkg/sonick8s/generated/listers/sonick8s/v1alpha1/sonicdaemonsetdeployment.go new file mode 100644 index 000000000..3f295ad26 --- /dev/null +++ b/pkg/sonick8s/generated/listers/sonick8s/v1alpha1/sonicdaemonsetdeployment.go @@ -0,0 +1,99 @@ +/* +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 ( + "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/tools/cache" + v1alpha1 "k8s.io/sample-controller/pkg/apis/sonick8s/v1alpha1" +) + +// SonicDaemonSetDeploymentLister helps list SonicDaemonSetDeployments. +// All objects returned here must be treated as read-only. +type SonicDaemonSetDeploymentLister interface { + // List lists all SonicDaemonSetDeployments in the indexer. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*v1alpha1.SonicDaemonSetDeployment, err error) + // SonicDaemonSetDeployments returns an object that can list and get SonicDaemonSetDeployments. + SonicDaemonSetDeployments(namespace string) SonicDaemonSetDeploymentNamespaceLister + SonicDaemonSetDeploymentListerExpansion +} + +// sonicDaemonSetDeploymentLister implements the SonicDaemonSetDeploymentLister interface. +type sonicDaemonSetDeploymentLister struct { + indexer cache.Indexer +} + +// NewSonicDaemonSetDeploymentLister returns a new SonicDaemonSetDeploymentLister. +func NewSonicDaemonSetDeploymentLister(indexer cache.Indexer) SonicDaemonSetDeploymentLister { + return &sonicDaemonSetDeploymentLister{indexer: indexer} +} + +// List lists all SonicDaemonSetDeployments in the indexer. +func (s *sonicDaemonSetDeploymentLister) List(selector labels.Selector) (ret []*v1alpha1.SonicDaemonSetDeployment, err error) { + err = cache.ListAll(s.indexer, selector, func(m interface{}) { + ret = append(ret, m.(*v1alpha1.SonicDaemonSetDeployment)) + }) + return ret, err +} + +// SonicDaemonSetDeployments returns an object that can list and get SonicDaemonSetDeployments. +func (s *sonicDaemonSetDeploymentLister) SonicDaemonSetDeployments(namespace string) SonicDaemonSetDeploymentNamespaceLister { + return sonicDaemonSetDeploymentNamespaceLister{indexer: s.indexer, namespace: namespace} +} + +// SonicDaemonSetDeploymentNamespaceLister helps list and get SonicDaemonSetDeployments. +// All objects returned here must be treated as read-only. +type SonicDaemonSetDeploymentNamespaceLister interface { + // List lists all SonicDaemonSetDeployments in the indexer for a given namespace. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*v1alpha1.SonicDaemonSetDeployment, err error) + // Get retrieves the SonicDaemonSetDeployment from the indexer for a given namespace and name. + // Objects returned here must be treated as read-only. + Get(name string) (*v1alpha1.SonicDaemonSetDeployment, error) + SonicDaemonSetDeploymentNamespaceListerExpansion +} + +// sonicDaemonSetDeploymentNamespaceLister implements the SonicDaemonSetDeploymentNamespaceLister +// interface. +type sonicDaemonSetDeploymentNamespaceLister struct { + indexer cache.Indexer + namespace string +} + +// List lists all SonicDaemonSetDeployments in the indexer for a given namespace. +func (s sonicDaemonSetDeploymentNamespaceLister) List(selector labels.Selector) (ret []*v1alpha1.SonicDaemonSetDeployment, err error) { + err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { + ret = append(ret, m.(*v1alpha1.SonicDaemonSetDeployment)) + }) + return ret, err +} + +// Get retrieves the SonicDaemonSetDeployment from the indexer for a given namespace and name. +func (s sonicDaemonSetDeploymentNamespaceLister) Get(name string) (*v1alpha1.SonicDaemonSetDeployment, error) { + obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) + if err != nil { + return nil, err + } + if !exists { + return nil, errors.NewNotFound(v1alpha1.Resource("sonicdaemonsetdeployment"), name) + } + return obj.(*v1alpha1.SonicDaemonSetDeployment), nil +} From 69588edf2a561279f4b7c5428a0fb1906481e46b Mon Sep 17 00:00:00 2001 From: Longquan Sha Date: Wed, 12 Apr 2023 11:09:21 +0800 Subject: [PATCH 08/22] Add sonic controller --- artifacts/examples/crd-sonic.yaml | 2 + main.go | 21 + pkg/apis/sonick8s/v1alpha1/register.go | 4 +- pkg/apis/sonick8s/v1alpha1/types.go | 1 + .../typed/sonick8s/v1alpha1/dcdaemonset.go | 195 --------- .../sonick8s/v1alpha1/dcdaemonset.go | 90 ---- .../listers/sonick8s/v1alpha1/dcdaemonset.go | 99 ----- sonic_deployment_controller.go | 386 ++++++++++++++++++ 8 files changed, 412 insertions(+), 386 deletions(-) delete mode 100644 pkg/sonick8s/generated/clientset/versioned/typed/sonick8s/v1alpha1/dcdaemonset.go delete mode 100644 pkg/sonick8s/generated/informers/externalversions/sonick8s/v1alpha1/dcdaemonset.go delete mode 100644 pkg/sonick8s/generated/listers/sonick8s/v1alpha1/dcdaemonset.go create mode 100644 sonic_deployment_controller.go diff --git a/artifacts/examples/crd-sonic.yaml b/artifacts/examples/crd-sonic.yaml index 587e1c853..64c81e37b 100644 --- a/artifacts/examples/crd-sonic.yaml +++ b/artifacts/examples/crd-sonic.yaml @@ -20,6 +20,8 @@ spec: spec: type: object properties: + deploymentName: + type: string scopeType: type: string scopeValue: diff --git a/main.go b/main.go index cda6ca198..1daeec51c 100644 --- a/main.go +++ b/main.go @@ -25,11 +25,14 @@ import ( "k8s.io/client-go/tools/clientcmd" "k8s.io/klog/v2" "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" + sonicclientset "k8s.io/sample-controller/pkg/sonick8s/generated/clientset/versioned" + sonicinformers "k8s.io/sample-controller/pkg/sonick8s/generated/informers/externalversions" ) var ( @@ -66,6 +69,24 @@ func main() { kubeInformerFactory := kubeinformers.NewSharedInformerFactory(kubeClient, time.Second*30) exampleInformerFactory := informers.NewSharedInformerFactory(exampleClient, time.Second*30) + // sonic resource client + sonicDsClient, err := sonicclientset.NewForConfig(cfg) + if err != nil { + logger.Error(err, "Error building kubernetes clientset") + klog.FlushAndExit(klog.ExitFlushTimeout, 1) + } + + //sonickubeInformerFactory := kubeinformers.NewSharedInformerFactory(kubeClient, time.Second*30) + sonicInformerFactory := sonicinformers.NewSharedInformerFactory(sonicDsClient, time.Second*30) + sonicController := NewSonicDaemonsetDeploymentController(ctx, kubeClient, sonicDsClient, + kubeInformerFactory.Apps().V1().DaemonSets(), + sonicInformerFactory.Sonic().V1alpha1().SonicDaemonSetDeployments()) + + if err = sonicController.Run(ctx, 2); err != nil { + logger.Error(err, "Error running controller") + klog.FlushAndExit(klog.ExitFlushTimeout, 1) + } + controller := NewController(ctx, kubeClient, exampleClient, kubeInformerFactory.Apps().V1().Deployments(), exampleInformerFactory.Samplecontroller().V1alpha1().Foos()) diff --git a/pkg/apis/sonick8s/v1alpha1/register.go b/pkg/apis/sonick8s/v1alpha1/register.go index cc644e54a..c916bf057 100644 --- a/pkg/apis/sonick8s/v1alpha1/register.go +++ b/pkg/apis/sonick8s/v1alpha1/register.go @@ -45,8 +45,8 @@ var ( // Adds the list of known types to Scheme. func addKnownTypes(scheme *runtime.Scheme) error { scheme.AddKnownTypes(SchemeGroupVersion, - &DcDaemonSet{}, - &DcDaemonSetList{}, + &SonicDaemonSetDeployment{}, + &SonicDaemonSetDeploymentList{}, ) metav1.AddToGroupVersion(scheme, SchemeGroupVersion) return nil diff --git a/pkg/apis/sonick8s/v1alpha1/types.go b/pkg/apis/sonick8s/v1alpha1/types.go index f2a514b1b..38684946b 100644 --- a/pkg/apis/sonick8s/v1alpha1/types.go +++ b/pkg/apis/sonick8s/v1alpha1/types.go @@ -34,6 +34,7 @@ type SonicDaemonSetDeployment struct { // SonicDaemonSetDeploymentSpec is the spec for a SonicDaemonSetDeployment resource type SonicDaemonSetDeploymentSpec struct { + DeploymentName string `json:"deploymentName"` // ScopeType: datacenter or region ScopeType string `json:"scopeType"` ScopeValue string `json:"scopeValue"` diff --git a/pkg/sonick8s/generated/clientset/versioned/typed/sonick8s/v1alpha1/dcdaemonset.go b/pkg/sonick8s/generated/clientset/versioned/typed/sonick8s/v1alpha1/dcdaemonset.go deleted file mode 100644 index 364e5bdeb..000000000 --- a/pkg/sonick8s/generated/clientset/versioned/typed/sonick8s/v1alpha1/dcdaemonset.go +++ /dev/null @@ -1,195 +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" - "time" - - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - types "k8s.io/apimachinery/pkg/types" - watch "k8s.io/apimachinery/pkg/watch" - rest "k8s.io/client-go/rest" - v1alpha1 "k8s.io/sample-controller/pkg/apis/sonick8s/v1alpha1" - scheme "k8s.io/sample-controller/pkg/sonick8s/generated/clientset/versioned/scheme" -) - -// DcDaemonSetsGetter has a method to return a DcDaemonSetInterface. -// A group's client should implement this interface. -type DcDaemonSetsGetter interface { - DcDaemonSets(namespace string) DcDaemonSetInterface -} - -// DcDaemonSetInterface has methods to work with DcDaemonSet resources. -type DcDaemonSetInterface interface { - Create(ctx context.Context, dcDaemonSet *v1alpha1.DcDaemonSet, opts v1.CreateOptions) (*v1alpha1.DcDaemonSet, error) - Update(ctx context.Context, dcDaemonSet *v1alpha1.DcDaemonSet, opts v1.UpdateOptions) (*v1alpha1.DcDaemonSet, error) - UpdateStatus(ctx context.Context, dcDaemonSet *v1alpha1.DcDaemonSet, opts v1.UpdateOptions) (*v1alpha1.DcDaemonSet, error) - Delete(ctx context.Context, name string, opts v1.DeleteOptions) error - DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error - Get(ctx context.Context, name string, opts v1.GetOptions) (*v1alpha1.DcDaemonSet, error) - List(ctx context.Context, opts v1.ListOptions) (*v1alpha1.DcDaemonSetList, error) - Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) - Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.DcDaemonSet, err error) - DcDaemonSetExpansion -} - -// dcDaemonSets implements DcDaemonSetInterface -type dcDaemonSets struct { - client rest.Interface - ns string -} - -// newDcDaemonSets returns a DcDaemonSets -func newDcDaemonSets(c *SonicV1alpha1Client, namespace string) *dcDaemonSets { - return &dcDaemonSets{ - client: c.RESTClient(), - ns: namespace, - } -} - -// Get takes name of the dcDaemonSet, and returns the corresponding dcDaemonSet object, and an error if there is any. -func (c *dcDaemonSets) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha1.DcDaemonSet, err error) { - result = &v1alpha1.DcDaemonSet{} - err = c.client.Get(). - Namespace(c.ns). - Resource("dcdaemonsets"). - Name(name). - VersionedParams(&options, scheme.ParameterCodec). - Do(ctx). - Into(result) - return -} - -// List takes label and field selectors, and returns the list of DcDaemonSets that match those selectors. -func (c *dcDaemonSets) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha1.DcDaemonSetList, err error) { - var timeout time.Duration - if opts.TimeoutSeconds != nil { - timeout = time.Duration(*opts.TimeoutSeconds) * time.Second - } - result = &v1alpha1.DcDaemonSetList{} - err = c.client.Get(). - Namespace(c.ns). - Resource("dcdaemonsets"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Do(ctx). - Into(result) - return -} - -// Watch returns a watch.Interface that watches the requested dcDaemonSets. -func (c *dcDaemonSets) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { - var timeout time.Duration - if opts.TimeoutSeconds != nil { - timeout = time.Duration(*opts.TimeoutSeconds) * time.Second - } - opts.Watch = true - return c.client.Get(). - Namespace(c.ns). - Resource("dcdaemonsets"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Watch(ctx) -} - -// Create takes the representation of a dcDaemonSet and creates it. Returns the server's representation of the dcDaemonSet, and an error, if there is any. -func (c *dcDaemonSets) Create(ctx context.Context, dcDaemonSet *v1alpha1.DcDaemonSet, opts v1.CreateOptions) (result *v1alpha1.DcDaemonSet, err error) { - result = &v1alpha1.DcDaemonSet{} - err = c.client.Post(). - Namespace(c.ns). - Resource("dcdaemonsets"). - VersionedParams(&opts, scheme.ParameterCodec). - Body(dcDaemonSet). - Do(ctx). - Into(result) - return -} - -// Update takes the representation of a dcDaemonSet and updates it. Returns the server's representation of the dcDaemonSet, and an error, if there is any. -func (c *dcDaemonSets) Update(ctx context.Context, dcDaemonSet *v1alpha1.DcDaemonSet, opts v1.UpdateOptions) (result *v1alpha1.DcDaemonSet, err error) { - result = &v1alpha1.DcDaemonSet{} - err = c.client.Put(). - Namespace(c.ns). - Resource("dcdaemonsets"). - Name(dcDaemonSet.Name). - VersionedParams(&opts, scheme.ParameterCodec). - Body(dcDaemonSet). - Do(ctx). - Into(result) - return -} - -// UpdateStatus was generated because the type contains a Status member. -// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). -func (c *dcDaemonSets) UpdateStatus(ctx context.Context, dcDaemonSet *v1alpha1.DcDaemonSet, opts v1.UpdateOptions) (result *v1alpha1.DcDaemonSet, err error) { - result = &v1alpha1.DcDaemonSet{} - err = c.client.Put(). - Namespace(c.ns). - Resource("dcdaemonsets"). - Name(dcDaemonSet.Name). - SubResource("status"). - VersionedParams(&opts, scheme.ParameterCodec). - Body(dcDaemonSet). - Do(ctx). - Into(result) - return -} - -// Delete takes name of the dcDaemonSet and deletes it. Returns an error if one occurs. -func (c *dcDaemonSets) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { - return c.client.Delete(). - Namespace(c.ns). - Resource("dcdaemonsets"). - Name(name). - Body(&opts). - Do(ctx). - Error() -} - -// DeleteCollection deletes a collection of objects. -func (c *dcDaemonSets) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { - var timeout time.Duration - if listOpts.TimeoutSeconds != nil { - timeout = time.Duration(*listOpts.TimeoutSeconds) * time.Second - } - return c.client.Delete(). - Namespace(c.ns). - Resource("dcdaemonsets"). - VersionedParams(&listOpts, scheme.ParameterCodec). - Timeout(timeout). - Body(&opts). - Do(ctx). - Error() -} - -// Patch applies the patch and returns the patched dcDaemonSet. -func (c *dcDaemonSets) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.DcDaemonSet, err error) { - result = &v1alpha1.DcDaemonSet{} - err = c.client.Patch(pt). - Namespace(c.ns). - Resource("dcdaemonsets"). - Name(name). - SubResource(subresources...). - VersionedParams(&opts, scheme.ParameterCodec). - Body(data). - Do(ctx). - Into(result) - return -} diff --git a/pkg/sonick8s/generated/informers/externalversions/sonick8s/v1alpha1/dcdaemonset.go b/pkg/sonick8s/generated/informers/externalversions/sonick8s/v1alpha1/dcdaemonset.go deleted file mode 100644 index 9ebfc89b5..000000000 --- a/pkg/sonick8s/generated/informers/externalversions/sonick8s/v1alpha1/dcdaemonset.go +++ /dev/null @@ -1,90 +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" - 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" - sonick8sv1alpha1 "k8s.io/sample-controller/pkg/apis/sonick8s/v1alpha1" - versioned "k8s.io/sample-controller/pkg/sonick8s/generated/clientset/versioned" - internalinterfaces "k8s.io/sample-controller/pkg/sonick8s/generated/informers/externalversions/internalinterfaces" - v1alpha1 "k8s.io/sample-controller/pkg/sonick8s/generated/listers/sonick8s/v1alpha1" -) - -// DcDaemonSetInformer provides access to a shared informer and lister for -// DcDaemonSets. -type DcDaemonSetInformer interface { - Informer() cache.SharedIndexInformer - Lister() v1alpha1.DcDaemonSetLister -} - -type dcDaemonSetInformer struct { - factory internalinterfaces.SharedInformerFactory - tweakListOptions internalinterfaces.TweakListOptionsFunc - namespace string -} - -// NewDcDaemonSetInformer constructs a new informer for DcDaemonSet 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 NewDcDaemonSetInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { - return NewFilteredDcDaemonSetInformer(client, namespace, resyncPeriod, indexers, nil) -} - -// NewFilteredDcDaemonSetInformer constructs a new informer for DcDaemonSet 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 NewFilteredDcDaemonSetInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { - return cache.NewSharedIndexInformer( - &cache.ListWatch{ - ListFunc: func(options v1.ListOptions) (runtime.Object, error) { - if tweakListOptions != nil { - tweakListOptions(&options) - } - return client.SonicV1alpha1().DcDaemonSets(namespace).List(context.TODO(), options) - }, - WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { - if tweakListOptions != nil { - tweakListOptions(&options) - } - return client.SonicV1alpha1().DcDaemonSets(namespace).Watch(context.TODO(), options) - }, - }, - &sonick8sv1alpha1.DcDaemonSet{}, - resyncPeriod, - indexers, - ) -} - -func (f *dcDaemonSetInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { - return NewFilteredDcDaemonSetInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) -} - -func (f *dcDaemonSetInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&sonick8sv1alpha1.DcDaemonSet{}, f.defaultInformer) -} - -func (f *dcDaemonSetInformer) Lister() v1alpha1.DcDaemonSetLister { - return v1alpha1.NewDcDaemonSetLister(f.Informer().GetIndexer()) -} diff --git a/pkg/sonick8s/generated/listers/sonick8s/v1alpha1/dcdaemonset.go b/pkg/sonick8s/generated/listers/sonick8s/v1alpha1/dcdaemonset.go deleted file mode 100644 index febd5deda..000000000 --- a/pkg/sonick8s/generated/listers/sonick8s/v1alpha1/dcdaemonset.go +++ /dev/null @@ -1,99 +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 ( - "k8s.io/apimachinery/pkg/api/errors" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/client-go/tools/cache" - v1alpha1 "k8s.io/sample-controller/pkg/apis/sonick8s/v1alpha1" -) - -// DcDaemonSetLister helps list DcDaemonSets. -// All objects returned here must be treated as read-only. -type DcDaemonSetLister interface { - // List lists all DcDaemonSets in the indexer. - // Objects returned here must be treated as read-only. - List(selector labels.Selector) (ret []*v1alpha1.DcDaemonSet, err error) - // DcDaemonSets returns an object that can list and get DcDaemonSets. - DcDaemonSets(namespace string) DcDaemonSetNamespaceLister - DcDaemonSetListerExpansion -} - -// dcDaemonSetLister implements the DcDaemonSetLister interface. -type dcDaemonSetLister struct { - indexer cache.Indexer -} - -// NewDcDaemonSetLister returns a new DcDaemonSetLister. -func NewDcDaemonSetLister(indexer cache.Indexer) DcDaemonSetLister { - return &dcDaemonSetLister{indexer: indexer} -} - -// List lists all DcDaemonSets in the indexer. -func (s *dcDaemonSetLister) List(selector labels.Selector) (ret []*v1alpha1.DcDaemonSet, err error) { - err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*v1alpha1.DcDaemonSet)) - }) - return ret, err -} - -// DcDaemonSets returns an object that can list and get DcDaemonSets. -func (s *dcDaemonSetLister) DcDaemonSets(namespace string) DcDaemonSetNamespaceLister { - return dcDaemonSetNamespaceLister{indexer: s.indexer, namespace: namespace} -} - -// DcDaemonSetNamespaceLister helps list and get DcDaemonSets. -// All objects returned here must be treated as read-only. -type DcDaemonSetNamespaceLister interface { - // List lists all DcDaemonSets in the indexer for a given namespace. - // Objects returned here must be treated as read-only. - List(selector labels.Selector) (ret []*v1alpha1.DcDaemonSet, err error) - // Get retrieves the DcDaemonSet from the indexer for a given namespace and name. - // Objects returned here must be treated as read-only. - Get(name string) (*v1alpha1.DcDaemonSet, error) - DcDaemonSetNamespaceListerExpansion -} - -// dcDaemonSetNamespaceLister implements the DcDaemonSetNamespaceLister -// interface. -type dcDaemonSetNamespaceLister struct { - indexer cache.Indexer - namespace string -} - -// List lists all DcDaemonSets in the indexer for a given namespace. -func (s dcDaemonSetNamespaceLister) List(selector labels.Selector) (ret []*v1alpha1.DcDaemonSet, err error) { - err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { - ret = append(ret, m.(*v1alpha1.DcDaemonSet)) - }) - return ret, err -} - -// Get retrieves the DcDaemonSet from the indexer for a given namespace and name. -func (s dcDaemonSetNamespaceLister) Get(name string) (*v1alpha1.DcDaemonSet, error) { - obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(v1alpha1.Resource("dcdaemonset"), name) - } - return obj.(*v1alpha1.DcDaemonSet), nil -} diff --git a/sonic_deployment_controller.go b/sonic_deployment_controller.go new file mode 100644 index 000000000..7dee9dfc8 --- /dev/null +++ b/sonic_deployment_controller.go @@ -0,0 +1,386 @@ +/* +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 main + +import ( + "context" + "fmt" + "time" + + 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" + "k8s.io/apimachinery/pkg/labels" + 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" + "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/sonick8s/v1alpha1" + clientset "k8s.io/sample-controller/pkg/sonick8s/generated/clientset/versioned" + samplescheme "k8s.io/sample-controller/pkg/sonick8s/generated/clientset/versioned/scheme" + informers "k8s.io/sample-controller/pkg/sonick8s/generated/informers/externalversions/sonick8s/v1alpha1" + listers "k8s.io/sample-controller/pkg/sonick8s/generated/listers/sonick8s/v1alpha1" +) + +const sonicControllerAgentName = "sonic-controller" + +// Controller is the controller implementation for Foo resources +type SonicDaemonsetDeploymentController struct { + // kubeclientset is a standard kubernetes clientset + kubeclientset kubernetes.Interface + // sampleclientset is a clientset for our own API group + sampleclientset clientset.Interface + + deploymentsLister appslisters.DaemonSetLister + deploymentsSynced cache.InformerSynced + foosLister listers.SonicDaemonSetDeploymentLister + foosSynced 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 + // means we can ensure we only process a fixed amount of resources at a + // time, and makes it easy to ensure we are never processing the same item + // simultaneously in two different workers. + workqueue workqueue.RateLimitingInterface + // recorder is an event recorder for recording Event resources to the + // Kubernetes API. + recorder record.EventRecorder +} + +// NewController returns a new sample controller +func NewSonicDaemonsetDeploymentController( + ctx context.Context, + kubeclientset kubernetes.Interface, + sampleclientset clientset.Interface, + deploymentInformer appsinformers.DaemonSetInformer, + fooInformer informers.SonicDaemonSetDeploymentInformer) *SonicDaemonsetDeploymentController { + logger := klog.FromContext(ctx) + + // Create event broadcaster + // Add sample-controller types to the default Kubernetes Scheme so Events can be + // logged for sample-controller types. + utilruntime.Must(samplescheme.AddToScheme(scheme.Scheme)) + logger.V(4).Info("Creating event broadcaster") + + eventBroadcaster := record.NewBroadcaster() + eventBroadcaster.StartStructuredLogging(0) + eventBroadcaster.StartRecordingToSink(&typedcorev1.EventSinkImpl{Interface: kubeclientset.CoreV1().Events("")}) + recorder := eventBroadcaster.NewRecorder(scheme.Scheme, corev1.EventSource{Component: controllerAgentName}) + + controller := &SonicDaemonsetDeploymentController{ + kubeclientset: kubeclientset, + sampleclientset: sampleclientset, + deploymentsLister: deploymentInformer.Lister(), + deploymentsSynced: deploymentInformer.Informer().HasSynced, + foosLister: fooInformer.Lister(), + foosSynced: fooInformer.Informer().HasSynced, + workqueue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "Foos"), + 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, + 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) + }, + DeleteFunc: controller.handleObject, + }) + + return controller +} + +// Run will set up the event handlers for types we are interested in, as well +// 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 *SonicDaemonsetDeploymentController) 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") + + // 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 { + return fmt.Errorf("failed to wait for caches to sync") + } + + logger.Info("Starting workers", "count", workers) + // Launch two workers to process Foo resources + for i := 0; i < workers; i++ { + go wait.UntilWithContext(ctx, c.runWorker, time.Second) + } + + logger.Info("Started workers") + <-ctx.Done() + logger.Info("Shutting down workers") + + return nil +} + +// 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 *SonicDaemonsetDeploymentController) 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 *SonicDaemonsetDeploymentController) processNextWorkItem(ctx context.Context) bool { + obj, shutdown := c.workqueue.Get() + logger := klog.FromContext(ctx) + + if shutdown { + return false + } + + // We wrap this block in a func so we can defer c.workqueue.Done. + err := func(obj interface{}) error { + // We call Done here so the workqueue knows we have finished + // processing this item. We also must remember to call Forget if we + // do not want this work item being re-queued. For example, we do + // not call Forget if a transient error occurs, instead the item is + // put back on the workqueue and attempted again after a back-off + // period. + defer c.workqueue.Done(obj) + var key string + var ok bool + // We expect strings to come off the workqueue. These are of the + // form namespace/name. We do this as the delayed nature of the + // workqueue means the items in the informer cache may actually be + // more up to date that when the item was initially put onto the + // workqueue. + if key, ok = obj.(string); !ok { + // As the item in the workqueue is actually invalid, we call + // Forget here else we'd go into a loop of attempting to + // process a work item that is invalid. + c.workqueue.Forget(obj) + utilruntime.HandleError(fmt.Errorf("expected string in workqueue but got %#v", obj)) + return nil + } + // Run the syncHandler, passing it the namespace/name string of the + // Foo resource to be synced. + if err := c.syncHandler(ctx, key); err != nil { + // Put the item back on the workqueue to handle any transient errors. + c.workqueue.AddRateLimited(key) + return fmt.Errorf("error syncing '%s': %s, requeuing", key, err.Error()) + } + // Finally, if no error occurs we Forget this item so it does not + // get queued again until another change happens. + c.workqueue.Forget(obj) + logger.Info("Successfully synced", "resourceName", key) + return nil + }(obj) + + if err != nil { + utilruntime.HandleError(err) + return true + } + + return true +} + +// syncHandler compares the actual state with the desired, and attempts to +// converge the two. It then updates the Status block of the Foo resource +// with the current status of the resource. +func (c *SonicDaemonsetDeploymentController) syncHandler(ctx context.Context, key string) error { + // Convert the namespace/name string into a distinct namespace and name + logger := klog.LoggerWithValues(klog.FromContext(ctx), "resourceName", key) + + namespace, name, err := cache.SplitMetaNamespaceKey(key) + if err != nil { + utilruntime.HandleError(fmt.Errorf("invalid resource key: %s", key)) + return nil + } + + // Get the Foo resource with this namespace/name + foo, err := c.foosLister.SonicDaemonSetDeployments(namespace).Get(name) + if err != nil { + // The Foo resource may no longer exist, in which case we stop + // processing. + if errors.IsNotFound(err) { + utilruntime.HandleError(fmt.Errorf("foo '%s' in work queue no longer exists", key)) + 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.HandleError(fmt.Errorf("%s: deployment name must be specified", key)) + return nil + } + + // Get daemonset list + dsList, err := c.deploymentsLister.DaemonSets(foo.Namespace).List(labels.Everything()) + // If the resource doesn't exist, we'll create it + if err != nil { + logger.V(4).Info("fail to list daemonset") + return err + } + + // 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 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) + } + + // 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", *foo.Spec.Replicas, "desiredReplicas", *deployment.Spec.Replicas) + deployment, err = c.kubeclientset.AppsV1().Deployments(foo.Namespace).Update(context.TODO(), newDeployment(foo), metav1.UpdateOptions{}) + } + */ + // 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 + } + + // Finally, we update the status block of the Foo resource to reflect the + // current state of the world + err = c.updateFooStatus(foo, dsList) + if err != nil { + return err + } + + c.recorder.Event(foo, corev1.EventTypeNormal, SuccessSynced, MessageResourceSynced) + return nil +} + +func (c *SonicDaemonsetDeploymentController) updateFooStatus(foo *samplev1alpha1.SonicDaemonSetDeployment, deployments []*appsv1.DaemonSet) 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() + for _, v := range deployments { + fooCopy.Status.DaemonsetList = append(fooCopy.Status.DaemonsetList, samplev1alpha1.DaemonSetItem{DaemonSetName: v.Name, DaemonSetVersion: v.Spec.Template.Spec.Containers[0].Image}) + } + // 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.SonicV1alpha1().SonicDaemonSetDeployments(foo.Namespace).UpdateStatus(context.TODO(), fooCopy, metav1.UpdateOptions{}) + return err +} + +// enqueueFoo takes a Foo 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 *SonicDaemonsetDeploymentController) enqueueFoo(obj interface{}) { + var key string + var err error + if key, err = cache.MetaNamespaceKeyFunc(obj); err != nil { + utilruntime.HandleError(err) + return + } + c.workqueue.Add(key) +} + +// 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 +// objects metadata.ownerReferences field for an appropriate OwnerReference. +// It then enqueues that Foo resource to be processed. If the object does not +// have an appropriate OwnerReference, it will simply be skipped. +func (c *SonicDaemonsetDeploymentController) handleObject(obj interface{}) { + var object metav1.Object + var ok bool + logger := klog.FromContext(context.Background()) + if object, ok = obj.(metav1.Object); !ok { + tombstone, ok := obj.(cache.DeletedFinalStateUnknown) + if !ok { + utilruntime.HandleError(fmt.Errorf("error decoding object, invalid type")) + return + } + object, ok = tombstone.Obj.(metav1.Object) + if !ok { + utilruntime.HandleError(fmt.Errorf("error decoding object tombstone, invalid type")) + return + } + logger.V(4).Info("Recovered deleted object", "resourceName", object.GetName()) + } + 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 + // with it. + if ownerRef.Kind != "Foo" { + return + } + + foo, err := c.foosLister.SonicDaemonSetDeployments(object.GetNamespace()).Get(ownerRef.Name) + if err != nil { + logger.V(4).Info("Ignore orphaned object", "object", klog.KObj(object), "foo", ownerRef.Name) + return + } + + c.enqueueFoo(foo) + 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. From 900481daeef4a017cca86283a8586735001ef99f Mon Sep 17 00:00:00 2001 From: Longquan Sha Date: Wed, 12 Apr 2023 11:16:58 +0800 Subject: [PATCH 09/22] update group name --- artifacts/examples/crd-sonic.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/artifacts/examples/crd-sonic.yaml b/artifacts/examples/crd-sonic.yaml index 64c81e37b..fb0835a47 100644 --- a/artifacts/examples/crd-sonic.yaml +++ b/artifacts/examples/crd-sonic.yaml @@ -7,7 +7,7 @@ metadata: annotations: "api-approved.kubernetes.io": "unapproved, experimental-only; please get an approval from Kubernetes API reviewers if you're trying to develop a CRD in the *.k8s.io or *.kubernetes.io groups" spec: - group: sonick8s.io + group: sonic.k8s.io versions: - name: v1alpha1 served: true From a9f26835048f153e730e7a71c9251ef34aabfafc Mon Sep 17 00:00:00 2001 From: Longquan Sha Date: Wed, 12 Apr 2023 11:23:06 +0800 Subject: [PATCH 10/22] update --- artifacts/examples/example-sonic.yaml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/artifacts/examples/example-sonic.yaml b/artifacts/examples/example-sonic.yaml index 60ddb41f3..0aa53ace3 100644 --- a/artifacts/examples/example-sonic.yaml +++ b/artifacts/examples/example-sonic.yaml @@ -1,6 +1,10 @@ apiVersion: sonic.k8s.io/v1alpha1 -kind: DcDaemonSet +kind: SonicDaemonSetDeployment metadata: name: example-dc-daemonset spec: - daemonsetVersion: telemetry-20220531.24 \ No newline at end of file + deploymentName: dc-ds-demo + scopeType: datacenter + scopeValue: starlab + daemonSetType: telemetry + daemonSetVersion: telemetry-20220531.24 \ No newline at end of file From 46112359a1cd4e91947893d3329ced08e50e24ad Mon Sep 17 00:00:00 2001 From: Longquan Sha Date: Wed, 12 Apr 2023 11:32:00 +0800 Subject: [PATCH 11/22] update --- artifacts/examples/example-sonic.yaml | 2 +- sonic_deployment_controller.go | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/artifacts/examples/example-sonic.yaml b/artifacts/examples/example-sonic.yaml index 0aa53ace3..b791a4acb 100644 --- a/artifacts/examples/example-sonic.yaml +++ b/artifacts/examples/example-sonic.yaml @@ -1,7 +1,7 @@ apiVersion: sonic.k8s.io/v1alpha1 kind: SonicDaemonSetDeployment metadata: - name: example-dc-daemonset + name: dc-ds-demo spec: deploymentName: dc-ds-demo scopeType: datacenter diff --git a/sonic_deployment_controller.go b/sonic_deployment_controller.go index 7dee9dfc8..ebd7103ae 100644 --- a/sonic_deployment_controller.go +++ b/sonic_deployment_controller.go @@ -366,16 +366,16 @@ func (c *SonicDaemonsetDeploymentController) handleObject(obj interface{}) { if ownerRef := metav1.GetControllerOf(object); ownerRef != nil { // If this object is not owned by a Foo, we should not do anything more // with it. - if ownerRef.Kind != "Foo" { + if ownerRef.Kind == "" { return } - foo, err := c.foosLister.SonicDaemonSetDeployments(object.GetNamespace()).Get(ownerRef.Name) + foo, err := c.foosLister.SonicDaemonSetDeployments(object.GetNamespace()).Get("dc-ds-demo") if err != nil { logger.V(4).Info("Ignore orphaned object", "object", klog.KObj(object), "foo", ownerRef.Name) return } - + logger.V(4).Info("enque the dc-ds-demo") c.enqueueFoo(foo) return } From bebde8599ad7e43eb83f03b9d8f1792dfa8da5cb Mon Sep 17 00:00:00 2001 From: Longquan Sha Date: Wed, 12 Apr 2023 11:36:29 +0800 Subject: [PATCH 12/22] update --- main.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index 1daeec51c..6846c6cca 100644 --- a/main.go +++ b/main.go @@ -82,10 +82,12 @@ func main() { kubeInformerFactory.Apps().V1().DaemonSets(), sonicInformerFactory.Sonic().V1alpha1().SonicDaemonSetDeployments()) - if err = sonicController.Run(ctx, 2); err != nil { - logger.Error(err, "Error running controller") - klog.FlushAndExit(klog.ExitFlushTimeout, 1) - } + /* + if err = sonicController.Run(ctx, 2); err != nil { + logger.Error(err, "Error running controller") + klog.FlushAndExit(klog.ExitFlushTimeout, 1) + } + */ controller := NewController(ctx, kubeClient, exampleClient, kubeInformerFactory.Apps().V1().Deployments(), @@ -95,6 +97,12 @@ func main() { // Start method is non-blocking and runs all registered informers in a dedicated goroutine. kubeInformerFactory.Start(ctx.Done()) exampleInformerFactory.Start(ctx.Done()) + sonicInformerFactory.Start(ctx.Done()) + //go sonicController.Run(ctx, 2) + if err = sonicController.Run(ctx, 2); err != nil { + logger.Error(err, "Error running sonic controller") + klog.FlushAndExit(klog.ExitFlushTimeout, 1) + } if err = controller.Run(ctx, 2); err != nil { logger.Error(err, "Error running controller") From 1fc6ed91997a246f8b7b055858a8f5b359a081dc Mon Sep 17 00:00:00 2001 From: Longquan Sha Date: Wed, 12 Apr 2023 11:47:29 +0800 Subject: [PATCH 13/22] update --- sonic_deployment_controller.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/sonic_deployment_controller.go b/sonic_deployment_controller.go index ebd7103ae..8b9ca5039 100644 --- a/sonic_deployment_controller.go +++ b/sonic_deployment_controller.go @@ -316,8 +316,17 @@ func (c *SonicDaemonsetDeploymentController) updateFooStatus(foo *samplev1alpha1 // 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() + dsMap := make(map[string]int) + updated := false for _, v := range deployments { - fooCopy.Status.DaemonsetList = append(fooCopy.Status.DaemonsetList, samplev1alpha1.DaemonSetItem{DaemonSetName: v.Name, DaemonSetVersion: v.Spec.Template.Spec.Containers[0].Image}) + if _, ok := dsMap[v.Name]; !ok { + updated = true + dsMap[v.Name] = 1 + fooCopy.Status.DaemonsetList = append(fooCopy.Status.DaemonsetList, samplev1alpha1.DaemonSetItem{DaemonSetName: v.Name, DaemonSetVersion: v.Spec.Template.Spec.Containers[0].Image}) + } + } + if !updated { + return nil } // If the CustomResourceSubresources feature gate is not enabled, // we must use Update instead of UpdateStatus to update the Status block of the Foo resource. From a8c5534789d0092a7c8a24234a2a5778f8c595b9 Mon Sep 17 00:00:00 2001 From: Longquan Sha Date: Wed, 12 Apr 2023 11:51:20 +0800 Subject: [PATCH 14/22] update --- sonic_deployment_controller.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sonic_deployment_controller.go b/sonic_deployment_controller.go index 8b9ca5039..a28f2a1c5 100644 --- a/sonic_deployment_controller.go +++ b/sonic_deployment_controller.go @@ -317,6 +317,10 @@ func (c *SonicDaemonsetDeploymentController) updateFooStatus(foo *samplev1alpha1 // Or create a copy manually for better performance fooCopy := foo.DeepCopy() dsMap := make(map[string]int) + for _, v := range fooCopy.Status.DaemonsetList { + dsMap[v.DaemonSetName] = 1 + } + updated := false for _, v := range deployments { if _, ok := dsMap[v.Name]; !ok { From b5eb966eb9118fad820895dc253d969383677a60 Mon Sep 17 00:00:00 2001 From: Longquan Sha Date: Wed, 12 Apr 2023 11:53:45 +0800 Subject: [PATCH 15/22] update --- sonic_deployment_controller.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sonic_deployment_controller.go b/sonic_deployment_controller.go index a28f2a1c5..97e5ca0cf 100644 --- a/sonic_deployment_controller.go +++ b/sonic_deployment_controller.go @@ -118,8 +118,8 @@ func NewSonicDaemonsetDeploymentController( deploymentInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{ AddFunc: controller.handleObject, UpdateFunc: func(old, new interface{}) { - newDepl := new.(*appsv1.Deployment) - oldDepl := old.(*appsv1.Deployment) + newDepl := new.(*appsv1.DaemonSet) + oldDepl := old.(*appsv1.DaemonSet) 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. From 0a4168531771e799299ba4a9edeb77643c5662b9 Mon Sep 17 00:00:00 2001 From: Longquan Sha Date: Wed, 12 Apr 2023 11:57:41 +0800 Subject: [PATCH 16/22] update --- sonic_deployment_controller.go | 1 + 1 file changed, 1 insertion(+) diff --git a/sonic_deployment_controller.go b/sonic_deployment_controller.go index 97e5ca0cf..feb7dc0c9 100644 --- a/sonic_deployment_controller.go +++ b/sonic_deployment_controller.go @@ -322,6 +322,7 @@ func (c *SonicDaemonsetDeploymentController) updateFooStatus(foo *samplev1alpha1 } updated := false + fooCopy.Status.DaemonsetList = []samplev1alpha1.DaemonSetItem{} for _, v := range deployments { if _, ok := dsMap[v.Name]; !ok { updated = true From 0c9d5c44fc5f1d03f7344a40a4099378c507720b Mon Sep 17 00:00:00 2001 From: Longquan Sha Date: Wed, 12 Apr 2023 12:01:45 +0800 Subject: [PATCH 17/22] update --- sonic_deployment_controller.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sonic_deployment_controller.go b/sonic_deployment_controller.go index feb7dc0c9..ecafbfc59 100644 --- a/sonic_deployment_controller.go +++ b/sonic_deployment_controller.go @@ -315,6 +315,7 @@ func (c *SonicDaemonsetDeploymentController) updateFooStatus(foo *samplev1alpha1 // 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 + logger := klog.LoggerWithValues(klog.FromContext(context.TODO()), "resourceName", foo.Name) fooCopy := foo.DeepCopy() dsMap := make(map[string]int) for _, v := range fooCopy.Status.DaemonsetList { @@ -322,10 +323,11 @@ func (c *SonicDaemonsetDeploymentController) updateFooStatus(foo *samplev1alpha1 } updated := false - fooCopy.Status.DaemonsetList = []samplev1alpha1.DaemonSetItem{} + //fooCopy.Status.DaemonsetList = []samplev1alpha1.DaemonSetItem{} for _, v := range deployments { if _, ok := dsMap[v.Name]; !ok { updated = true + logger.Info(fmt.Sprintf("Add ds %s", v.Name)) dsMap[v.Name] = 1 fooCopy.Status.DaemonsetList = append(fooCopy.Status.DaemonsetList, samplev1alpha1.DaemonSetItem{DaemonSetName: v.Name, DaemonSetVersion: v.Spec.Template.Spec.Containers[0].Image}) } From eb469e78889cd2df9e73ae7683fa411ee0f37a30 Mon Sep 17 00:00:00 2001 From: Longquan Sha Date: Wed, 12 Apr 2023 15:58:32 +0800 Subject: [PATCH 18/22] update --- artifacts/examples/example-sonic.yaml | 3 +- go.mod | 15 ++++-- go.sum | 20 ++++++++ sonic_deployment_controller.go | 70 ++++++++++++++++++++++++++- 4 files changed, 103 insertions(+), 5 deletions(-) diff --git a/artifacts/examples/example-sonic.yaml b/artifacts/examples/example-sonic.yaml index b791a4acb..13d56afb6 100644 --- a/artifacts/examples/example-sonic.yaml +++ b/artifacts/examples/example-sonic.yaml @@ -7,4 +7,5 @@ spec: scopeType: datacenter scopeValue: starlab daemonSetType: telemetry - daemonSetVersion: telemetry-20220531.24 \ No newline at end of file + # nginx:1.15.2 + daemonSetVersion: nginx:1.14.2 \ No newline at end of file diff --git a/go.mod b/go.mod index a8416d204..3fc84ce93 100644 --- a/go.mod +++ b/go.mod @@ -5,9 +5,9 @@ module k8s.io/sample-controller go 1.20 require ( - k8s.io/api v0.0.0-20230327181730-ec59454f24f5 - k8s.io/apimachinery v0.0.0-20230315054728-8d1258da8f38 - k8s.io/client-go v0.0.0-20230327182304-04ef61f72b7b + k8s.io/api v0.27.0 + k8s.io/apimachinery v0.27.0 + k8s.io/client-go v0.27.0 k8s.io/code-generator v0.0.0-20230327155628-450bfcd76181 k8s.io/klog/v2 v2.90.1 ) @@ -16,6 +16,7 @@ require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/emicklei/go-restful/v3 v3.9.0 // indirect github.com/evanphx/json-patch v4.12.0+incompatible // indirect + github.com/go-errors/errors v1.4.2 // indirect github.com/go-logr/logr v1.2.3 // indirect github.com/go-openapi/jsonpointer v0.19.6 // indirect github.com/go-openapi/jsonreference v0.20.1 // indirect @@ -26,6 +27,7 @@ require ( github.com/google/gnostic v0.5.7-v3refs // indirect github.com/google/go-cmp v0.5.9 // indirect github.com/google/gofuzz v1.1.0 // indirect + github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect github.com/google/uuid v1.3.0 // indirect github.com/imdario/mergo v0.3.6 // indirect github.com/josharian/intern v1.0.0 // indirect @@ -33,9 +35,12 @@ require ( 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.2 // indirect + github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/spf13/pflag v1.0.5 // indirect + github.com/xlab/treeprint v1.1.0 // indirect + go.starlark.net v0.0.0-20200306205701-8dd3e2ee1dd5 // indirect golang.org/x/mod v0.9.0 // indirect golang.org/x/net v0.8.0 // indirect golang.org/x/oauth2 v0.0.0-20220223155221-ee480838109b // indirect @@ -49,10 +54,14 @@ require ( gopkg.in/inf.v0 v0.9.1 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect + k8s.io/cli-runtime v0.27.0 // indirect k8s.io/gengo v0.0.0-20220902162205-c0856e24416d // indirect k8s.io/kube-openapi v0.0.0-20230308215209-15aac26d736a // indirect + k8s.io/kubectl v0.27.0 // indirect k8s.io/utils v0.0.0-20230209194617-a36077c30491 // indirect sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect + sigs.k8s.io/kustomize/api v0.13.2 // indirect + sigs.k8s.io/kustomize/kyaml v0.14.1 // indirect sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect sigs.k8s.io/yaml v1.3.0 // indirect ) diff --git a/go.sum b/go.sum index 3596d1f8b..49c21e4f6 100644 --- a/go.sum +++ b/go.sum @@ -52,6 +52,8 @@ github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1m github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/evanphx/json-patch v4.12.0+incompatible h1:4onqiflcdA9EOZ4RxV643DvftH5pOlLGNtQ5lPWQu84= github.com/evanphx/json-patch v4.12.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk= +github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA= +github.com/go-errors/errors v1.4.2/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3BopGUQ5a5Og= github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= @@ -126,6 +128,8 @@ github.com/google/pprof v0.0.0-20200430221834-fc25d7d30c6d/go.mod h1:ZgVRPoUq/hf github.com/google/pprof v0.0.0-20200708004538-1a94d8640e99/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 h1:K6RDEckDVWvDI9JAJYCmNdQXq6neHJOYx3V6jnqNEec= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= +github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4= +github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ= github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= @@ -158,6 +162,8 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= +github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 h1:n6/2gBQ3RWajuToeY6ZtZTIKv2v7ThUy5KKusIT0yc0= +github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00/go.mod h1:Pm3mSP3c5uWn86xMLZ5Sa7JB9GsEZySvHYXCTK4E9q4= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= github.com/onsi/ginkgo/v2 v2.9.1 h1:zie5Ly042PD3bsCvsSOPvRnFwyo3rKe64TJlD6nu0mk= @@ -178,10 +184,13 @@ github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpE github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/xlab/treeprint v1.1.0 h1:G/1DjNkPpfZCFt9CSh6b5/nY4VimlbHF3Rh4obvtzDk= +github.com/xlab/treeprint v1.1.0/go.mod h1:gj5Gd3gPdKtR1ikdDK6fnFLdmIS0X30kTTuNd/WEJu0= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= @@ -191,6 +200,8 @@ go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= +go.starlark.net v0.0.0-20200306205701-8dd3e2ee1dd5 h1:+FNtrFTmVw0YZGpBGX56XDee331t6JAXeK2bcyhLOOc= +go.starlark.net v0.0.0-20200306205701-8dd3e2ee1dd5/go.mod h1:nmDLcffg48OtT/PSW0Hg7FvpRQsQh5OSqIylirxKC7o= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= @@ -284,6 +295,7 @@ golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191002063906-3421d5a6bb1c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200113162924-86b910548bc1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -476,6 +488,8 @@ k8s.io/api v0.0.0-20230327181730-ec59454f24f5 h1:w1YnXoFKIeL9JZfIYRn9CRdkX8/kW10 k8s.io/api v0.0.0-20230327181730-ec59454f24f5/go.mod h1:RAYThv5ELmDNk2Kt+PWiwWtAI1TZyap1JK1QStRzwyw= k8s.io/apimachinery v0.0.0-20230315054728-8d1258da8f38 h1:n1qDRCTPAXwyXYg7eSpWDO9FdW79lwAQ9dAr1vETpn4= k8s.io/apimachinery v0.0.0-20230315054728-8d1258da8f38/go.mod h1:5ikh59fK3AJ287GUvpUsryoMFtH9zj/ARfWCo3AyXTM= +k8s.io/cli-runtime v0.27.0 h1:kYVGqjmBbaj22nJ7je/3tigjiSlB04kVbjW+51zivu8= +k8s.io/cli-runtime v0.27.0/go.mod h1:kN+Q+5L37DFCdpNuCLTHO7w+dwlJb0xzn8jveB3bPSw= k8s.io/client-go v0.0.0-20230327182304-04ef61f72b7b h1:i7ybYFiSOVv9P25DBnXGGve5ZIC4zdhFP0bTqkWJp1c= k8s.io/client-go v0.0.0-20230327182304-04ef61f72b7b/go.mod h1:dBvRRpzMiHmy81Mlb3+3GW9DkCYV6b/bEEwMBTmfzFM= k8s.io/code-generator v0.0.0-20230327155628-450bfcd76181 h1:wUOaOuF+LaBw/y8h4FviQPgdaQvpIaRI7aUOV0tonjs= @@ -487,6 +501,8 @@ k8s.io/klog/v2 v2.90.1 h1:m4bYOKall2MmOiRaR1J+We67Do7vm9KiQVlT96lnHUw= k8s.io/klog/v2 v2.90.1/go.mod h1:y1WjHnz7Dj687irZUWR/WLkLc5N1YHtjLdmgWjndZn0= k8s.io/kube-openapi v0.0.0-20230308215209-15aac26d736a h1:gmovKNur38vgoWfGtP5QOGNOA7ki4n6qNYoFAgMlNvg= k8s.io/kube-openapi v0.0.0-20230308215209-15aac26d736a/go.mod h1:y5VtZWM9sHHc2ZodIH/6SHzXj+TPU5USoA8lcIeKEKY= +k8s.io/kubectl v0.27.0 h1:ZcWS6ufixDXwovWtzF149gd5GzxdpsIl4YqfioSkq5w= +k8s.io/kubectl v0.27.0/go.mod h1:tyFzo+6WfbUEccm8rFIliQ79FAmm9uTFN+1oC5Ytamo= k8s.io/utils v0.0.0-20230209194617-a36077c30491 h1:r0BAOLElQnnFhE/ApUsg3iHdVYYPBjNSSOMowRZxxsY= k8s.io/utils v0.0.0-20230209194617-a36077c30491/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0= rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= @@ -494,6 +510,10 @@ rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0= rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd h1:EDPBXCAspyGV4jQlpZSudPeMmr1bNJefnuqLsRAsHZo= sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd/go.mod h1:B8JuhiUyNFVKdsE8h686QcCxMaH6HrOAZj4vswFpcB0= +sigs.k8s.io/kustomize/api v0.13.2 h1:kejWfLeJhUsTGioDoFNJET5LQe/ajzXhJGYoU+pJsiA= +sigs.k8s.io/kustomize/api v0.13.2/go.mod h1:DUp325VVMFVcQSq+ZxyDisA8wtldwHxLZbr1g94UHsw= +sigs.k8s.io/kustomize/kyaml v0.14.1 h1:c8iibius7l24G2wVAGZn/Va2wNys03GXLjYVIcFVxKA= +sigs.k8s.io/kustomize/kyaml v0.14.1/go.mod h1:AN1/IpawKilWD7V+YvQwRGUvuUOOWpjsHu6uHwonSF4= sigs.k8s.io/structured-merge-diff/v4 v4.2.3 h1:PRbqxJClWWYMNV1dhaG4NsibJbArud9kFxnAMREiWFE= sigs.k8s.io/structured-merge-diff/v4 v4.2.3/go.mod h1:qjx8mGObPmV2aSZepjQjbmb2ihdVs8cGKBraizNC69E= sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc= diff --git a/sonic_deployment_controller.go b/sonic_deployment_controller.go index ecafbfc59..159aed9fd 100644 --- a/sonic_deployment_controller.go +++ b/sonic_deployment_controller.go @@ -18,6 +18,7 @@ package main import ( "context" + "encoding/json" "fmt" "time" @@ -26,6 +27,7 @@ import ( "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/labels" + "k8s.io/apimachinery/pkg/types" utilruntime "k8s.io/apimachinery/pkg/util/runtime" "k8s.io/apimachinery/pkg/util/wait" appsinformers "k8s.io/client-go/informers/apps/v1" @@ -37,6 +39,7 @@ import ( "k8s.io/client-go/tools/record" "k8s.io/client-go/util/workqueue" "k8s.io/klog/v2" + deploymentutil "k8s.io/kubectl/pkg/util/deployment" samplev1alpha1 "k8s.io/sample-controller/pkg/apis/sonick8s/v1alpha1" clientset "k8s.io/sample-controller/pkg/sonick8s/generated/clientset/versioned" @@ -323,7 +326,6 @@ func (c *SonicDaemonsetDeploymentController) updateFooStatus(foo *samplev1alpha1 } updated := false - //fooCopy.Status.DaemonsetList = []samplev1alpha1.DaemonSetItem{} for _, v := range deployments { if _, ok := dsMap[v.Name]; !ok { updated = true @@ -331,6 +333,12 @@ func (c *SonicDaemonsetDeploymentController) updateFooStatus(foo *samplev1alpha1 dsMap[v.Name] = 1 fooCopy.Status.DaemonsetList = append(fooCopy.Status.DaemonsetList, samplev1alpha1.DaemonSetItem{DaemonSetName: v.Name, DaemonSetVersion: v.Spec.Template.Spec.Containers[0].Image}) } + + // update daemonset if version is mismatch + if foo.Spec.DaemonSetVersion != v.Spec.Template.Spec.Containers[0].Image { + logger.Info(fmt.Sprintf("Need to update ds versoin for ds %s to %s", v.Name, foo.Spec.DaemonSetVersion)) + c.updateDaemonset(v, foo.Spec.DaemonSetVersion) + } } if !updated { return nil @@ -397,6 +405,66 @@ func (c *SonicDaemonsetDeploymentController) handleObject(obj interface{}) { } } +func (c *SonicDaemonsetDeploymentController) getDeploymentPatch(podTemplate *corev1.PodTemplateSpec, annotations map[string]string) (types.PatchType, []byte, error) { + // Create a patch of the Deployment that replaces spec.template + patch, err := json.Marshal([]interface{}{ + map[string]interface{}{ + "op": "replace", + "path": "/spec/template", + "value": podTemplate, + }, + map[string]interface{}{ + "op": "replace", + "path": "/metadata/annotations", + "value": annotations, + }, + }) + return types.JSONPatchType, patch, err +} + +func (c *SonicDaemonsetDeploymentController) updateDaemonset(ds *appsv1.DaemonSet, version string) (bool, error) { + klog.Infof("Aboute to update daemonset %s/%s to %s", ds.Namespace, ds, version) + targetDs := ds.DeepCopy() + var annotationsToSkip = map[string]bool{ + corev1.LastAppliedConfigAnnotation: true, + deploymentutil.RevisionAnnotation: true, + deploymentutil.RevisionHistoryAnnotation: true, + deploymentutil.DesiredReplicasAnnotation: true, + deploymentutil.MaxReplicasAnnotation: true, + appsv1.DeprecatedRollbackTo: true, + } + delete(targetDs.Spec.Template.Labels, appsv1.DefaultDeploymentUniqueLabelKey) + + // compute deployment annotations + annotations := map[string]string{} + for k := range annotationsToSkip { + if v, ok := ds.Annotations[k]; ok { + annotations[k] = v + } + } + for k, v := range targetDs.Annotations { + if !annotationsToSkip[k] { + annotations[k] = v + } + } + + targetDs.Spec.Template.Spec.Containers[0].Image = version + patchType, patch, err := c.getDeploymentPatch(&targetDs.Spec.Template, targetDs.Annotations) + if err != nil { + return false, fmt.Errorf("failed restoring revision %s: %v", targetDs.ResourceVersion, err) + } + + patchOptions := metav1.PatchOptions{} + + // update ds revision + if _, err = c.kubeclientset.AppsV1().DaemonSets(targetDs.Namespace).Patch(context.TODO(), targetDs.Name, patchType, patch, patchOptions); err != nil { + klog.Errorf("Updating daemonset %s/%s is failed:%v", targetDs.Namespace, targetDs.Name, err) + return false, fmt.Errorf("failed restoring revision %s: %v", targetDs.ResourceVersion, err) + } + klog.Infof("Updating daemonset %s/%s is successful", targetDs.Namespace, targetDs.Name) + return true, nil +} + // 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. From 7bc95c254c1476a2527519a01e545e4aecd9e93b Mon Sep 17 00:00:00 2001 From: Longquan Sha Date: Wed, 12 Apr 2023 16:37:57 +0800 Subject: [PATCH 19/22] update --- sonic_deployment_controller.go | 39 +++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/sonic_deployment_controller.go b/sonic_deployment_controller.go index 159aed9fd..8a8e5338c 100644 --- a/sonic_deployment_controller.go +++ b/sonic_deployment_controller.go @@ -320,29 +320,38 @@ func (c *SonicDaemonsetDeploymentController) updateFooStatus(foo *samplev1alpha1 // Or create a copy manually for better performance logger := klog.LoggerWithValues(klog.FromContext(context.TODO()), "resourceName", foo.Name) fooCopy := foo.DeepCopy() - dsMap := make(map[string]int) - for _, v := range fooCopy.Status.DaemonsetList { - dsMap[v.DaemonSetName] = 1 - } + fooCopy.Status.DaemonsetList = []samplev1alpha1.DaemonSetItem{} + //dsMap := make(map[string]string) - updated := false for _, v := range deployments { - if _, ok := dsMap[v.Name]; !ok { - updated = true - logger.Info(fmt.Sprintf("Add ds %s", v.Name)) - dsMap[v.Name] = 1 - fooCopy.Status.DaemonsetList = append(fooCopy.Status.DaemonsetList, samplev1alpha1.DaemonSetItem{DaemonSetName: v.Name, DaemonSetVersion: v.Spec.Template.Spec.Containers[0].Image}) - } - + fooCopy.Status.DaemonsetList = append(fooCopy.Status.DaemonsetList, samplev1alpha1.DaemonSetItem{DaemonSetName: v.Name, DaemonSetVersion: v.Spec.Template.Spec.Containers[0].Image}) + /* + if _, ok := dsMap[v.Name]; !ok { + updated = true + logger.Info(fmt.Sprintf("Add ds %s", v.Name)) + dsMap[v.Name] = v.Spec.Template.Spec.Containers[0].Image + fooCopy.Status.DaemonsetList = append(fooCopy.Status.DaemonsetList, samplev1alpha1.DaemonSetItem{DaemonSetName: v.Name, DaemonSetVersion: v.Spec.Template.Spec.Containers[0].Image}) + } else { + if dsMap[v.Name] != v.Spec.Template.Spec.Containers[0].Image { + for _, d := range fooCopy.Status.DaemonsetList { + if d.DaemonSetName == v.Name { + d.DaemonSetVersion = dsMap[v.Name] + } + } + } + } + */ // update daemonset if version is mismatch if foo.Spec.DaemonSetVersion != v.Spec.Template.Spec.Containers[0].Image { logger.Info(fmt.Sprintf("Need to update ds versoin for ds %s to %s", v.Name, foo.Spec.DaemonSetVersion)) c.updateDaemonset(v, foo.Spec.DaemonSetVersion) } } - if !updated { - return nil - } + /* + if !updated { + return nil + } + */ // 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, From 650522c1b48e3d885145653d960d427c3051bff6 Mon Sep 17 00:00:00 2001 From: Longquan Sha Date: Wed, 12 Apr 2023 16:50:59 +0800 Subject: [PATCH 20/22] update --- sonic_deployment_controller.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/sonic_deployment_controller.go b/sonic_deployment_controller.go index 8a8e5338c..8d4ecf776 100644 --- a/sonic_deployment_controller.go +++ b/sonic_deployment_controller.go @@ -342,9 +342,16 @@ func (c *SonicDaemonsetDeploymentController) updateFooStatus(foo *samplev1alpha1 } */ // update daemonset if version is mismatch + + } + _, err := c.sampleclientset.SonicV1alpha1().SonicDaemonSetDeployments(foo.Namespace).UpdateStatus(context.TODO(), fooCopy, metav1.UpdateOptions{}) + //rolling update for daemonset + for _, v := range deployments { if foo.Spec.DaemonSetVersion != v.Spec.Template.Spec.Containers[0].Image { logger.Info(fmt.Sprintf("Need to update ds versoin for ds %s to %s", v.Name, foo.Spec.DaemonSetVersion)) c.updateDaemonset(v, foo.Spec.DaemonSetVersion) + time.Sleep(10 * time.Second) + break } } /* @@ -356,7 +363,7 @@ func (c *SonicDaemonsetDeploymentController) updateFooStatus(foo *samplev1alpha1 // 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.SonicV1alpha1().SonicDaemonSetDeployments(foo.Namespace).UpdateStatus(context.TODO(), fooCopy, metav1.UpdateOptions{}) + return err } From 467d4870c127fade1fb2b22ff34589381b890342 Mon Sep 17 00:00:00 2001 From: Longquan Sha Date: Fri, 14 Apr 2023 10:51:59 +0800 Subject: [PATCH 21/22] update --- README.md | 3 ++ sonic_deployment_controller.go | 50 ++++++++++++++++++++++++++++++++-- 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3b73b33a8..5e72688d8 100644 --- a/README.md +++ b/README.md @@ -177,3 +177,6 @@ https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/sample-c Code changes are made in that location, merged into k8s.io/kubernetes and later synced here. +## How to test it in local env +./sample-controller --kubeconfig /home/azureuser/.kube/config + diff --git a/sonic_deployment_controller.go b/sonic_deployment_controller.go index 8d4ecf776..32766c6bc 100644 --- a/sonic_deployment_controller.go +++ b/sonic_deployment_controller.go @@ -22,11 +22,15 @@ import ( "fmt" "time" + "reflect" + "unsafe" + 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" "k8s.io/apimachinery/pkg/labels" + "k8s.io/apimachinery/pkg/selection" "k8s.io/apimachinery/pkg/types" utilruntime "k8s.io/apimachinery/pkg/util/runtime" "k8s.io/apimachinery/pkg/util/wait" @@ -40,7 +44,6 @@ import ( "k8s.io/client-go/util/workqueue" "k8s.io/klog/v2" deploymentutil "k8s.io/kubectl/pkg/util/deployment" - samplev1alpha1 "k8s.io/sample-controller/pkg/apis/sonick8s/v1alpha1" clientset "k8s.io/sample-controller/pkg/sonick8s/generated/clientset/versioned" samplescheme "k8s.io/sample-controller/pkg/sonick8s/generated/clientset/versioned/scheme" @@ -310,7 +313,7 @@ func (c *SonicDaemonsetDeploymentController) syncHandler(ctx context.Context, ke return err } - c.recorder.Event(foo, corev1.EventTypeNormal, SuccessSynced, MessageResourceSynced) + c.recorder.Event(foo, corev1.EventTypeNormal, SuccessSynced, "SonicDaemonsetDeployment") return nil } @@ -322,8 +325,14 @@ func (c *SonicDaemonsetDeploymentController) updateFooStatus(foo *samplev1alpha1 fooCopy := foo.DeepCopy() fooCopy.Status.DaemonsetList = []samplev1alpha1.DaemonSetItem{} //dsMap := make(map[string]string) + totalNum := 0 + currentNum := 0 for _, v := range deployments { + totalNum++ + if foo.Spec.DaemonSetVersion == v.Spec.Template.Spec.Containers[0].Image { + currentNum++ + } fooCopy.Status.DaemonsetList = append(fooCopy.Status.DaemonsetList, samplev1alpha1.DaemonSetItem{DaemonSetName: v.Name, DaemonSetVersion: v.Spec.Template.Spec.Containers[0].Image}) /* if _, ok := dsMap[v.Name]; !ok { @@ -344,11 +353,14 @@ func (c *SonicDaemonsetDeploymentController) updateFooStatus(foo *samplev1alpha1 // update daemonset if version is mismatch } + fooCopy.Status.CurrentDaemonSetCount = currentNum + fooCopy.Status.DesiredDaemonSetCount = totalNum _, err := c.sampleclientset.SonicV1alpha1().SonicDaemonSetDeployments(foo.Namespace).UpdateStatus(context.TODO(), fooCopy, metav1.UpdateOptions{}) //rolling update for daemonset for _, v := range deployments { if foo.Spec.DaemonSetVersion != v.Spec.Template.Spec.Containers[0].Image { logger.Info(fmt.Sprintf("Need to update ds versoin for ds %s to %s", v.Name, foo.Spec.DaemonSetVersion)) + c.recorder.Event(foo, corev1.EventTypeNormal, "DaemonSetUpdate", fmt.Sprintf("%s is updated", v.Name)) c.updateDaemonset(v, foo.Spec.DaemonSetVersion) time.Sleep(10 * time.Second) break @@ -484,3 +496,37 @@ func (c *SonicDaemonsetDeploymentController) updateDaemonset(ds *appsv1.DaemonSe // 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 createSelector(k, v string) (labels.Selector, error) { + selector := labels.NewSelector() + //for k, v := range ps.MatchLabels { + r, err := newRequirement(k, selection.Equals, []string{v}) + if err != nil { + return nil, err + } + selector = selector.Add(*r) + //} + return selector, nil +} + +func newRequirement(key string, op selection.Operator, vals []string) (*labels.Requirement, error) { + sel := &labels.Requirement{} + selVal := reflect.ValueOf(sel) + val := reflect.Indirect(selVal) + + keyField := val.FieldByName("key") + keyFieldPtr := (*string)(unsafe.Pointer(keyField.UnsafeAddr())) + *keyFieldPtr = key + + opField := val.FieldByName("operator") + opFieldPtr := (*selection.Operator)(unsafe.Pointer(opField.UnsafeAddr())) + *opFieldPtr = op + + if len(vals) > 0 { + valuesField := val.FieldByName("strValues") + valuesFieldPtr := (*[]string)(unsafe.Pointer(valuesField.UnsafeAddr())) + *valuesFieldPtr = vals + } + + return sel, nil +} From 88dcb2e9fef9b2820ebb5c8a873496d76ec26af6 Mon Sep 17 00:00:00 2001 From: Longquan Sha Date: Fri, 14 Apr 2023 11:02:57 +0800 Subject: [PATCH 22/22] update --- sonic_deployment_controller.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sonic_deployment_controller.go b/sonic_deployment_controller.go index 32766c6bc..66f61acf1 100644 --- a/sonic_deployment_controller.go +++ b/sonic_deployment_controller.go @@ -23,6 +23,7 @@ import ( "time" "reflect" + "sort" "unsafe" appsv1 "k8s.io/api/apps/v1" @@ -327,7 +328,9 @@ func (c *SonicDaemonsetDeploymentController) updateFooStatus(foo *samplev1alpha1 //dsMap := make(map[string]string) totalNum := 0 currentNum := 0 - + sort.Slice(deployments, func(i, j int) bool { + return deployments[i].Name < deployments[j].Name + }) for _, v := range deployments { totalNum++ if foo.Spec.DaemonSetVersion == v.Spec.Template.Spec.Containers[0].Image {