From 48886919d2977a8e05bfbe7a46432c8835bdaa5c Mon Sep 17 00:00:00 2001 From: "weizhou.lan@daocloud.io" Date: Sun, 18 Feb 2024 19:17:59 +0800 Subject: [PATCH] asd Signed-off-by: weizhou.lan@daocloud.io --- .../rocktemplate.spidernet.io_mybooks.yaml | 10 +- charts/templates/role.yaml | 4 +- charts/templates/tls.yaml | 12 +- cmd/controller/cmd/daemon.go | 4 +- docs/README.md | 18 +-- docs/develop/dev.md | 12 +- docs/usage/usage.md | 12 +- .../v1/doc.go | 0 .../v1/groupversion_info.go | 0 .../v1/mybook_types.go | 18 +-- .../v1/rbac.go | 4 +- .../v1/register.go | 0 .../v1/zz_generated.deepcopy.go | 38 +++---- .../v1/fake/fake_mybook.go | 74 ++++++------ .../fake_rocktemplate.spidernet.io_client.go | 4 +- .../v1/generated_expansion.go | 2 +- .../rocktemplate.spidernet.io/v1/mybook.go | 106 +++++++++--------- .../v1/rocktemplate.spidernet.io_client.go | 6 +- .../informers/externalversions/generic.go | 4 +- .../rocktemplate.spidernet.io/v1/interface.go | 10 +- .../rocktemplate.spidernet.io/v1/mybook.go | 38 +++---- .../v1/expansion_generated.go | 6 +- .../rocktemplate.spidernet.io/v1/mybook.go | 38 +++---- .../controller.go | 32 +++--- .../controller_worker.go | 10 +- pkg/kclusterManager/manager.go | 24 ++++ .../types/type.go | 2 +- .../webhook.go | 16 +-- pkg/mybookManager/manager.go | 24 ---- 29 files changed, 264 insertions(+), 264 deletions(-) rename pkg/k8s/apis/{rocktemplate.spidernet.io => koffloader.koffloader.io}/v1/doc.go (100%) rename pkg/k8s/apis/{rocktemplate.spidernet.io => koffloader.koffloader.io}/v1/groupversion_info.go (100%) rename pkg/k8s/apis/{rocktemplate.spidernet.io => koffloader.koffloader.io}/v1/mybook_types.go (83%) rename pkg/k8s/apis/{rocktemplate.spidernet.io => koffloader.koffloader.io}/v1/rbac.go (76%) rename pkg/k8s/apis/{rocktemplate.spidernet.io => koffloader.koffloader.io}/v1/register.go (100%) rename pkg/k8s/apis/{rocktemplate.spidernet.io => koffloader.koffloader.io}/v1/zz_generated.deepcopy.go (76%) rename pkg/{mybookManager => kclusterManager}/controller.go (88%) rename pkg/{mybookManager => kclusterManager}/controller_worker.go (78%) create mode 100644 pkg/kclusterManager/manager.go rename pkg/{mybookManager => kclusterManager}/types/type.go (86%) rename pkg/{mybookManager => kclusterManager}/webhook.go (93%) delete mode 100644 pkg/mybookManager/manager.go diff --git a/charts/crds/rocktemplate.spidernet.io_mybooks.yaml b/charts/crds/rocktemplate.spidernet.io_mybooks.yaml index f33eea6b..1a2a5ea4 100644 --- a/charts/crds/rocktemplate.spidernet.io_mybooks.yaml +++ b/charts/crds/rocktemplate.spidernet.io_mybooks.yaml @@ -5,18 +5,18 @@ metadata: annotations: controller-gen.kubebuilder.io/version: (unknown) creationTimestamp: null - name: mybooks.koffloader.koffloader.io + name: kclusters.koffloader.koffloader.io spec: group: koffloader.koffloader.io names: categories: - koffloader - kind: Mybook - listKind: MybookList - plural: mybooks + kind: Kcluster + listKind: KclusterList + plural: kclusters shortNames: - mb - singular: mybook + singular: kcluster scope: Cluster versions: - additionalPrinterColumns: diff --git a/charts/templates/role.yaml b/charts/templates/role.yaml index 7c237727..0006be5f 100644 --- a/charts/templates/role.yaml +++ b/charts/templates/role.yaml @@ -61,7 +61,7 @@ rules: - apiGroups: - koffloader.koffloader.io resources: - - mybooks + - kclusters verbs: - create - delete @@ -73,7 +73,7 @@ rules: - apiGroups: - koffloader.koffloader.io resources: - - mybooks/status + - kclusters/status verbs: - get - patch diff --git a/charts/templates/tls.yaml b/charts/templates/tls.yaml index e6aaa4a5..b5b68293 100644 --- a/charts/templates/tls.yaml +++ b/charts/templates/tls.yaml @@ -18,7 +18,7 @@ webhooks: name: {{ .Values.koffloaderController.name | trunc 63 | trimSuffix "-" }} namespace: {{ .Release.Namespace }} # ====modify==== the mutating route path : "/mutate-" + strings.ReplaceAll(gvk.Group, ".", "-") + "-" + gvk.Version + "-" + strings.ToLower(gvk.Kind) - path: "/mutate-koffloader-koffloader-io-v1-mybook" + path: "/mutate-koffloader-koffloader-io-v1-kcluster" port: {{ .Values.koffloaderController.webhookPort }} {{- if (eq .Values.koffloaderController.tls.method "provided") }} caBundle: {{ .Values.koffloaderController.tls.provided.tlsCa | required "missing tls.provided.tlsCa" }} @@ -27,7 +27,7 @@ webhooks: {{- end }} failurePolicy: Fail # ====modify==== - name: mybook.koffloader.koffloader.io + name: kcluster.koffloader.koffloader.io rules: - apiGroups: # ====modify==== @@ -40,7 +40,7 @@ webhooks: - DELETE resources: # ====modify==== crdName - - mybooks + - kclusters sideEffects: None --- @@ -60,7 +60,7 @@ webhooks: name: {{ .Values.koffloaderController.name | trunc 63 | trimSuffix "-" }} namespace: {{ .Release.Namespace }} # ====modify==== the validate route path : "/validate-" + strings.ReplaceAll(gvk.Group, ".", "-") + "-" + gvk.Version + "-" + strings.ToLower(gvk.Kind) - path: "/validate-koffloader-koffloader-io-v1-mybook" + path: "/validate-koffloader-koffloader-io-v1-kcluster" port: {{ .Values.koffloaderController.webhookPort }} {{- if (eq .Values.koffloaderController.tls.method "provided") }} caBundle: {{ .Values.koffloaderController.tls.provided.tlsCa | required "missing tls.provided.tlsCa" }} @@ -69,7 +69,7 @@ webhooks: {{- end }} failurePolicy: Fail # ====modify==== - name: mybook.koffloader.koffloader.io + name: kcluster.koffloader.koffloader.io rules: - apiGroups: # ====modify==== @@ -82,7 +82,7 @@ webhooks: - DELETE resources: # ====modify==== crdName - - mybooks + - kclusters sideEffects: None {{- if eq .Values.koffloaderController.tls.method "certmanager" -}} diff --git a/cmd/controller/cmd/daemon.go b/cmd/controller/cmd/daemon.go index 34f3b2ff..91150918 100644 --- a/cmd/controller/cmd/daemon.go +++ b/cmd/controller/cmd/daemon.go @@ -6,7 +6,7 @@ package cmd import ( "context" "github.com/koffloader-io/koffloader/pkg/debug" - "github.com/koffloader-io/koffloader/pkg/mybookManager" + "github.com/koffloader-io/koffloader/pkg/kclusterManager" "github.com/koffloader-io/koffloader/pkg/types" "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/metric" @@ -52,7 +52,7 @@ func DaemonMain() { MetricHistogramDuration.Record(context.Background(), 20) // ---------- - s := mybookManager.New(rootLogger.Named("mybook")) + s := kclusterManager.New(rootLogger.Named("kcluster")) s.RunController("testlease", types.ControllerConfig.PodNamespace, types.ControllerConfig.PodName) s.RunWebhookServer(int(types.ControllerConfig.WebhookPort), filepath.Dir(types.ControllerConfig.TlsServerCertPath)) diff --git a/docs/README.md b/docs/README.md index d57edad8..24412238 100644 --- a/docs/README.md +++ b/docs/README.md @@ -16,15 +16,15 @@ 4. redefine CRD in pkg/k8s/v1 rename directory name 'pkg/k8s/apis/koffloader.koffloader.io' - replace all 'mybook' to 'YourCRDName' - and `make update_crd_sdk`, and write code in pkg/mybookManager + replace all 'kcluster' to 'YourCRDName' + and `make update_crd_sdk`, and write code in pkg/kclusterManager - rename pkg/mybookManager and replace all 'mybook' with your CRD name in this directory + rename pkg/kclusterManager and replace all 'kcluster' with your CRD name in this directory - rm charts/crds/koffloader.koffloader.io_mybooks.yaml + rm charts/crds/koffloader.koffloader.io_kclusters.yaml - # in repo: replace all "github.com/koffloader-io/spiderdoctor/pkg/mybookManager" to "github.com/koffloader-io/spiderdoctor/pkg/${crdName}Manager" - # in repo: find and replace all "mybook" to YourCrd + # in repo: replace all "github.com/koffloader-io/spiderdoctor/pkg/kclusterManager" to "github.com/koffloader-io/spiderdoctor/pkg/${crdName}Manager" + # in repo: find and replace all "kcluster" to YourCrd 5. update charts/ , and images/ , and CODEOWNERS @@ -98,16 +98,16 @@ 5. apply cr - cat < mybook.yaml + cat < kcluster.yaml apiVersion: koffloader.koffloader.io/v1 - kind: Mybook + kind: Kcluster metadata: name: test spec: ipVersion: 4 subnet: "1.0.0.0/8" EOF - kubectl apply -f mybook.yaml + kubectl apply -f kcluster.yaml ## chart develop diff --git a/docs/develop/dev.md b/docs/develop/dev.md index c32ac4d9..cd075c8c 100644 --- a/docs/develop/dev.md +++ b/docs/develop/dev.md @@ -21,9 +21,9 @@ helm repo add koffloader https://koffloader-io.github.io/koffloader ```shell -cat < mybook1.yaml +cat < kcluster1.yaml apiVersion: koffloader.koffloader.io/v1 -kind: Mybook +kind: Kcluster metadata: name: test1 spec: @@ -31,12 +31,12 @@ spec: subnet: "1.0.0.0/8" EOF -kubectl apply -f mybook1.yaml +kubectl apply -f kcluster1.yaml -cat < mybook2.yaml +cat < kcluster2.yaml apiVersion: koffloader.koffloader.io/v1 -kind: Mybook +kind: Kcluster metadata: name: test2 spec: @@ -44,7 +44,7 @@ spec: subnet: "2.0.0.0/8" EOF -kubectl apply -f mybook2.yaml +kubectl apply -f kcluster2.yaml ``` diff --git a/docs/usage/usage.md b/docs/usage/usage.md index 6b97b99d..dd7095a7 100644 --- a/docs/usage/usage.md +++ b/docs/usage/usage.md @@ -2,9 +2,9 @@ ```shell -cat < mybook1.yaml +cat < kcluster1.yaml apiVersion: koffloader.koffloader.io/v1 -kind: Mybook +kind: Kcluster metadata: name: test1 spec: @@ -12,12 +12,12 @@ spec: subnet: "1.0.0.0/8" EOF -kubectl apply -f mybook1.yaml +kubectl apply -f kcluster1.yaml -cat < mybook2.yaml +cat < kcluster2.yaml apiVersion: koffloader.koffloader.io/v1 -kind: Mybook +kind: Kcluster metadata: name: test2 spec: @@ -25,7 +25,7 @@ spec: subnet: "2.0.0.0/8" EOF -kubectl apply -f mybook2.yaml +kubectl apply -f kcluster2.yaml ``` diff --git a/pkg/k8s/apis/rocktemplate.spidernet.io/v1/doc.go b/pkg/k8s/apis/koffloader.koffloader.io/v1/doc.go similarity index 100% rename from pkg/k8s/apis/rocktemplate.spidernet.io/v1/doc.go rename to pkg/k8s/apis/koffloader.koffloader.io/v1/doc.go diff --git a/pkg/k8s/apis/rocktemplate.spidernet.io/v1/groupversion_info.go b/pkg/k8s/apis/koffloader.koffloader.io/v1/groupversion_info.go similarity index 100% rename from pkg/k8s/apis/rocktemplate.spidernet.io/v1/groupversion_info.go rename to pkg/k8s/apis/koffloader.koffloader.io/v1/groupversion_info.go diff --git a/pkg/k8s/apis/rocktemplate.spidernet.io/v1/mybook_types.go b/pkg/k8s/apis/koffloader.koffloader.io/v1/mybook_types.go similarity index 83% rename from pkg/k8s/apis/rocktemplate.spidernet.io/v1/mybook_types.go rename to pkg/k8s/apis/koffloader.koffloader.io/v1/mybook_types.go index ef582d5f..731dac41 100644 --- a/pkg/k8s/apis/rocktemplate.spidernet.io/v1/mybook_types.go +++ b/pkg/k8s/apis/koffloader.koffloader.io/v1/mybook_types.go @@ -13,7 +13,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) -type MybookSpec struct { +type KclusterSpec struct { // +kubebuilder:validation:Enum=4;6 // +kubebuilder:validation:Optional IPVersion *int64 `json:"ipVersion,omitempty"` @@ -38,7 +38,7 @@ type MybookSpec struct { NodeAffinity *metav1.LabelSelector `json:"nodeAffinity,omitempty"` } -type MybookStatus struct { +type KclusterStatus struct { // +kubebuilder:validation:Minimum=0 TotalIPCount int64 `json:"totalIPCount"` @@ -49,7 +49,7 @@ type MybookStatus struct { } // scope(Namespaced or Cluster) -// +kubebuilder:resource:categories={koffloader},path="mybooks",singular="mybook",scope="Cluster",shortName={mb} +// +kubebuilder:resource:categories={koffloader},path="kclusters",singular="kcluster",scope="Cluster",shortName={mb} // +kubebuilder:printcolumn:JSONPath=".spec.ipVersion",description="ipVersion",name="VERSION",type=string // +kubebuilder:printcolumn:JSONPath=".spec.subnet",description="subnet",name="SUBNET",type=string // +kubebuilder:printcolumn:JSONPath=".status.totalIPCount",description="totalIPCount",name="TOTAL-IP-COUNT",type=integer @@ -58,23 +58,23 @@ type MybookStatus struct { // +genclient // +genclient:nonNamespaced -type Mybook struct { +type Kcluster struct { metav1.TypeMeta `json:",inline"` metav1.ObjectMeta `json:"metadata"` - Spec MybookSpec `json:"spec,omitempty"` - Status MybookStatus `json:"status,omitempty"` + Spec KclusterSpec `json:"spec,omitempty"` + Status KclusterStatus `json:"status,omitempty"` } // +kubebuilder:object:root=true -type MybookList struct { +type KclusterList struct { metav1.TypeMeta `json:",inline"` metav1.ListMeta `json:"metadata"` - Items []Mybook `json:"items"` + Items []Kcluster `json:"items"` } func init() { - SchemeBuilder.Register(&Mybook{}, &MybookList{}) + SchemeBuilder.Register(&Kcluster{}, &KclusterList{}) } diff --git a/pkg/k8s/apis/rocktemplate.spidernet.io/v1/rbac.go b/pkg/k8s/apis/koffloader.koffloader.io/v1/rbac.go similarity index 76% rename from pkg/k8s/apis/rocktemplate.spidernet.io/v1/rbac.go rename to pkg/k8s/apis/koffloader.koffloader.io/v1/rbac.go index 530bbce4..26b53b33 100644 --- a/pkg/k8s/apis/rocktemplate.spidernet.io/v1/rbac.go +++ b/pkg/k8s/apis/koffloader.koffloader.io/v1/rbac.go @@ -5,8 +5,8 @@ // https://github.com/kubernetes-sigs/controller-tools/blob/master/pkg/rbac/parser.go // https://book.kubebuilder.io/reference/markers/rbac.html -// +kubebuilder:rbac:groups=koffloader.koffloader.io,resources=mybooks,verbs=get;list;watch;create;update;patch;delete -// +kubebuilder:rbac:groups=koffloader.koffloader.io,resources=mybooks/status,verbs=get;update;patch +// +kubebuilder:rbac:groups=koffloader.koffloader.io,resources=kclusters,verbs=get;list;watch;create;update;patch;delete +// +kubebuilder:rbac:groups=koffloader.koffloader.io,resources=kclusters/status,verbs=get;update;patch // +kubebuilder:rbac:groups="",resources=events,verbs=create;get;list;watch;update;delete // +kubebuilder:rbac:groups="coordination.k8s.io",resources=leases,verbs=create;get;update diff --git a/pkg/k8s/apis/rocktemplate.spidernet.io/v1/register.go b/pkg/k8s/apis/koffloader.koffloader.io/v1/register.go similarity index 100% rename from pkg/k8s/apis/rocktemplate.spidernet.io/v1/register.go rename to pkg/k8s/apis/koffloader.koffloader.io/v1/register.go diff --git a/pkg/k8s/apis/rocktemplate.spidernet.io/v1/zz_generated.deepcopy.go b/pkg/k8s/apis/koffloader.koffloader.io/v1/zz_generated.deepcopy.go similarity index 76% rename from pkg/k8s/apis/rocktemplate.spidernet.io/v1/zz_generated.deepcopy.go rename to pkg/k8s/apis/koffloader.koffloader.io/v1/zz_generated.deepcopy.go index afc86f95..bb00ec8d 100644 --- a/pkg/k8s/apis/rocktemplate.spidernet.io/v1/zz_generated.deepcopy.go +++ b/pkg/k8s/apis/koffloader.koffloader.io/v1/zz_generated.deepcopy.go @@ -11,7 +11,7 @@ import ( ) // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *Mybook) DeepCopyInto(out *Mybook) { +func (in *Kcluster) DeepCopyInto(out *Kcluster) { *out = *in out.TypeMeta = in.TypeMeta in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) @@ -19,18 +19,18 @@ func (in *Mybook) DeepCopyInto(out *Mybook) { in.Status.DeepCopyInto(&out.Status) } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Mybook. -func (in *Mybook) DeepCopy() *Mybook { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Kcluster. +func (in *Kcluster) DeepCopy() *Kcluster { if in == nil { return nil } - out := new(Mybook) + out := new(Kcluster) in.DeepCopyInto(out) return out } // DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *Mybook) DeepCopyObject() runtime.Object { +func (in *Kcluster) DeepCopyObject() runtime.Object { if c := in.DeepCopy(); c != nil { return c } @@ -38,31 +38,31 @@ func (in *Mybook) DeepCopyObject() runtime.Object { } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *MybookList) DeepCopyInto(out *MybookList) { +func (in *KclusterList) DeepCopyInto(out *KclusterList) { *out = *in out.TypeMeta = in.TypeMeta in.ListMeta.DeepCopyInto(&out.ListMeta) if in.Items != nil { in, out := &in.Items, &out.Items - *out = make([]Mybook, len(*in)) + *out = make([]Kcluster, len(*in)) for i := range *in { (*in)[i].DeepCopyInto(&(*out)[i]) } } } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MybookList. -func (in *MybookList) DeepCopy() *MybookList { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new KclusterList. +func (in *KclusterList) DeepCopy() *KclusterList { if in == nil { return nil } - out := new(MybookList) + out := new(KclusterList) in.DeepCopyInto(out) return out } // DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *MybookList) DeepCopyObject() runtime.Object { +func (in *KclusterList) DeepCopyObject() runtime.Object { if c := in.DeepCopy(); c != nil { return c } @@ -70,7 +70,7 @@ func (in *MybookList) DeepCopyObject() runtime.Object { } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *MybookSpec) DeepCopyInto(out *MybookSpec) { +func (in *KclusterSpec) DeepCopyInto(out *KclusterSpec) { *out = *in if in.IPVersion != nil { in, out := &in.IPVersion, &out.IPVersion @@ -99,18 +99,18 @@ func (in *MybookSpec) DeepCopyInto(out *MybookSpec) { } } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MybookSpec. -func (in *MybookSpec) DeepCopy() *MybookSpec { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new KclusterSpec. +func (in *KclusterSpec) DeepCopy() *KclusterSpec { if in == nil { return nil } - out := new(MybookSpec) + out := new(KclusterSpec) in.DeepCopyInto(out) return out } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *MybookStatus) DeepCopyInto(out *MybookStatus) { +func (in *KclusterStatus) DeepCopyInto(out *KclusterStatus) { *out = *in if in.TimeStamp != nil { in, out := &in.TimeStamp, &out.TimeStamp @@ -118,12 +118,12 @@ func (in *MybookStatus) DeepCopyInto(out *MybookStatus) { } } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MybookStatus. -func (in *MybookStatus) DeepCopy() *MybookStatus { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new KclusterStatus. +func (in *KclusterStatus) DeepCopy() *KclusterStatus { if in == nil { return nil } - out := new(MybookStatus) + out := new(KclusterStatus) in.DeepCopyInto(out) return out } diff --git a/pkg/k8s/client/clientset/versioned/typed/rocktemplate.spidernet.io/v1/fake/fake_mybook.go b/pkg/k8s/client/clientset/versioned/typed/rocktemplate.spidernet.io/v1/fake/fake_mybook.go index 46352c76..1ea63b4d 100644 --- a/pkg/k8s/client/clientset/versioned/typed/rocktemplate.spidernet.io/v1/fake/fake_mybook.go +++ b/pkg/k8s/client/clientset/versioned/typed/rocktemplate.spidernet.io/v1/fake/fake_mybook.go @@ -17,29 +17,29 @@ import ( testing "k8s.io/client-go/testing" ) -// FakeMybooks implements MybookInterface -type FakeMybooks struct { +// FakeKclusters implements KclusterInterface +type FakeKclusters struct { Fake *FakekoffloaderV1 } -var mybooksResource = schema.GroupVersionResource{Group: "koffloader.koffloader.io", Version: "v1", Resource: "mybooks"} +var kclustersResource = schema.GroupVersionResource{Group: "koffloader.koffloader.io", Version: "v1", Resource: "kclusters"} -var mybooksKind = schema.GroupVersionKind{Group: "koffloader.koffloader.io", Version: "v1", Kind: "Mybook"} +var kclustersKind = schema.GroupVersionKind{Group: "koffloader.koffloader.io", Version: "v1", Kind: "Kcluster"} -// Get takes name of the mybook, and returns the corresponding mybook object, and an error if there is any. -func (c *FakeMybooks) Get(ctx context.Context, name string, options v1.GetOptions) (result *koffloaderspidernetiov1.Mybook, err error) { +// Get takes name of the kcluster, and returns the corresponding kcluster object, and an error if there is any. +func (c *FakeKclusters) Get(ctx context.Context, name string, options v1.GetOptions) (result *koffloaderspidernetiov1.Kcluster, err error) { obj, err := c.Fake. - Invokes(testing.NewRootGetAction(mybooksResource, name), &koffloaderspidernetiov1.Mybook{}) + Invokes(testing.NewRootGetAction(kclustersResource, name), &koffloaderspidernetiov1.Kcluster{}) if obj == nil { return nil, err } - return obj.(*koffloaderspidernetiov1.Mybook), err + return obj.(*koffloaderspidernetiov1.Kcluster), err } -// List takes label and field selectors, and returns the list of Mybooks that match those selectors. -func (c *FakeMybooks) List(ctx context.Context, opts v1.ListOptions) (result *koffloaderspidernetiov1.MybookList, err error) { +// List takes label and field selectors, and returns the list of Kclusters that match those selectors. +func (c *FakeKclusters) List(ctx context.Context, opts v1.ListOptions) (result *koffloaderspidernetiov1.KclusterList, err error) { obj, err := c.Fake. - Invokes(testing.NewRootListAction(mybooksResource, mybooksKind, opts), &koffloaderspidernetiov1.MybookList{}) + Invokes(testing.NewRootListAction(kclustersResource, kclustersKind, opts), &koffloaderspidernetiov1.KclusterList{}) if obj == nil { return nil, err } @@ -48,8 +48,8 @@ func (c *FakeMybooks) List(ctx context.Context, opts v1.ListOptions) (result *ko if label == nil { label = labels.Everything() } - list := &koffloaderspidernetiov1.MybookList{ListMeta: obj.(*koffloaderspidernetiov1.MybookList).ListMeta} - for _, item := range obj.(*koffloaderspidernetiov1.MybookList).Items { + list := &koffloaderspidernetiov1.KclusterList{ListMeta: obj.(*koffloaderspidernetiov1.KclusterList).ListMeta} + for _, item := range obj.(*koffloaderspidernetiov1.KclusterList).Items { if label.Matches(labels.Set(item.Labels)) { list.Items = append(list.Items, item) } @@ -57,64 +57,64 @@ func (c *FakeMybooks) List(ctx context.Context, opts v1.ListOptions) (result *ko return list, err } -// Watch returns a watch.Interface that watches the requested mybooks. -func (c *FakeMybooks) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { +// Watch returns a watch.Interface that watches the requested kclusters. +func (c *FakeKclusters) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { return c.Fake. - InvokesWatch(testing.NewRootWatchAction(mybooksResource, opts)) + InvokesWatch(testing.NewRootWatchAction(kclustersResource, opts)) } -// Create takes the representation of a mybook and creates it. Returns the server's representation of the mybook, and an error, if there is any. -func (c *FakeMybooks) Create(ctx context.Context, mybook *koffloaderspidernetiov1.Mybook, opts v1.CreateOptions) (result *koffloaderspidernetiov1.Mybook, err error) { +// Create takes the representation of a kcluster and creates it. Returns the server's representation of the kcluster, and an error, if there is any. +func (c *FakeKclusters) Create(ctx context.Context, kcluster *koffloaderspidernetiov1.Kcluster, opts v1.CreateOptions) (result *koffloaderspidernetiov1.Kcluster, err error) { obj, err := c.Fake. - Invokes(testing.NewRootCreateAction(mybooksResource, mybook), &koffloaderspidernetiov1.Mybook{}) + Invokes(testing.NewRootCreateAction(kclustersResource, kcluster), &koffloaderspidernetiov1.Kcluster{}) if obj == nil { return nil, err } - return obj.(*koffloaderspidernetiov1.Mybook), err + return obj.(*koffloaderspidernetiov1.Kcluster), err } -// Update takes the representation of a mybook and updates it. Returns the server's representation of the mybook, and an error, if there is any. -func (c *FakeMybooks) Update(ctx context.Context, mybook *koffloaderspidernetiov1.Mybook, opts v1.UpdateOptions) (result *koffloaderspidernetiov1.Mybook, err error) { +// Update takes the representation of a kcluster and updates it. Returns the server's representation of the kcluster, and an error, if there is any. +func (c *FakeKclusters) Update(ctx context.Context, kcluster *koffloaderspidernetiov1.Kcluster, opts v1.UpdateOptions) (result *koffloaderspidernetiov1.Kcluster, err error) { obj, err := c.Fake. - Invokes(testing.NewRootUpdateAction(mybooksResource, mybook), &koffloaderspidernetiov1.Mybook{}) + Invokes(testing.NewRootUpdateAction(kclustersResource, kcluster), &koffloaderspidernetiov1.Kcluster{}) if obj == nil { return nil, err } - return obj.(*koffloaderspidernetiov1.Mybook), err + return obj.(*koffloaderspidernetiov1.Kcluster), 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 *FakeMybooks) UpdateStatus(ctx context.Context, mybook *koffloaderspidernetiov1.Mybook, opts v1.UpdateOptions) (*koffloaderspidernetiov1.Mybook, error) { +func (c *FakeKclusters) UpdateStatus(ctx context.Context, kcluster *koffloaderspidernetiov1.Kcluster, opts v1.UpdateOptions) (*koffloaderspidernetiov1.Kcluster, error) { obj, err := c.Fake. - Invokes(testing.NewRootUpdateSubresourceAction(mybooksResource, "status", mybook), &koffloaderspidernetiov1.Mybook{}) + Invokes(testing.NewRootUpdateSubresourceAction(kclustersResource, "status", kcluster), &koffloaderspidernetiov1.Kcluster{}) if obj == nil { return nil, err } - return obj.(*koffloaderspidernetiov1.Mybook), err + return obj.(*koffloaderspidernetiov1.Kcluster), err } -// Delete takes name of the mybook and deletes it. Returns an error if one occurs. -func (c *FakeMybooks) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { +// Delete takes name of the kcluster and deletes it. Returns an error if one occurs. +func (c *FakeKclusters) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { _, err := c.Fake. - Invokes(testing.NewRootDeleteActionWithOptions(mybooksResource, name, opts), &koffloaderspidernetiov1.Mybook{}) + Invokes(testing.NewRootDeleteActionWithOptions(kclustersResource, name, opts), &koffloaderspidernetiov1.Kcluster{}) return err } // DeleteCollection deletes a collection of objects. -func (c *FakeMybooks) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { - action := testing.NewRootDeleteCollectionAction(mybooksResource, listOpts) +func (c *FakeKclusters) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { + action := testing.NewRootDeleteCollectionAction(kclustersResource, listOpts) - _, err := c.Fake.Invokes(action, &koffloaderspidernetiov1.MybookList{}) + _, err := c.Fake.Invokes(action, &koffloaderspidernetiov1.KclusterList{}) return err } -// Patch applies the patch and returns the patched mybook. -func (c *FakeMybooks) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *koffloaderspidernetiov1.Mybook, err error) { +// Patch applies the patch and returns the patched kcluster. +func (c *FakeKclusters) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *koffloaderspidernetiov1.Kcluster, err error) { obj, err := c.Fake. - Invokes(testing.NewRootPatchSubresourceAction(mybooksResource, name, pt, data, subresources...), &koffloaderspidernetiov1.Mybook{}) + Invokes(testing.NewRootPatchSubresourceAction(kclustersResource, name, pt, data, subresources...), &koffloaderspidernetiov1.Kcluster{}) if obj == nil { return nil, err } - return obj.(*koffloaderspidernetiov1.Mybook), err + return obj.(*koffloaderspidernetiov1.Kcluster), err } diff --git a/pkg/k8s/client/clientset/versioned/typed/rocktemplate.spidernet.io/v1/fake/fake_rocktemplate.spidernet.io_client.go b/pkg/k8s/client/clientset/versioned/typed/rocktemplate.spidernet.io/v1/fake/fake_rocktemplate.spidernet.io_client.go index 703da997..b0b4b651 100644 --- a/pkg/k8s/client/clientset/versioned/typed/rocktemplate.spidernet.io/v1/fake/fake_rocktemplate.spidernet.io_client.go +++ b/pkg/k8s/client/clientset/versioned/typed/rocktemplate.spidernet.io/v1/fake/fake_rocktemplate.spidernet.io_client.go @@ -15,8 +15,8 @@ type FakekoffloaderV1 struct { *testing.Fake } -func (c *FakekoffloaderV1) Mybooks() v1.MybookInterface { - return &FakeMybooks{c} +func (c *FakekoffloaderV1) Kclusters() v1.KclusterInterface { + return &FakeKclusters{c} } // RESTClient returns a RESTClient that is used to communicate diff --git a/pkg/k8s/client/clientset/versioned/typed/rocktemplate.spidernet.io/v1/generated_expansion.go b/pkg/k8s/client/clientset/versioned/typed/rocktemplate.spidernet.io/v1/generated_expansion.go index 6e83fd46..77ebe921 100644 --- a/pkg/k8s/client/clientset/versioned/typed/rocktemplate.spidernet.io/v1/generated_expansion.go +++ b/pkg/k8s/client/clientset/versioned/typed/rocktemplate.spidernet.io/v1/generated_expansion.go @@ -5,4 +5,4 @@ package v1 -type MybookExpansion interface{} +type KclusterExpansion interface{} diff --git a/pkg/k8s/client/clientset/versioned/typed/rocktemplate.spidernet.io/v1/mybook.go b/pkg/k8s/client/clientset/versioned/typed/rocktemplate.spidernet.io/v1/mybook.go index 9e43666e..2a30542e 100644 --- a/pkg/k8s/client/clientset/versioned/typed/rocktemplate.spidernet.io/v1/mybook.go +++ b/pkg/k8s/client/clientset/versioned/typed/rocktemplate.spidernet.io/v1/mybook.go @@ -17,43 +17,43 @@ import ( rest "k8s.io/client-go/rest" ) -// MybooksGetter has a method to return a MybookInterface. +// KclustersGetter has a method to return a KclusterInterface. // A group's client should implement this interface. -type MybooksGetter interface { - Mybooks() MybookInterface +type KclustersGetter interface { + Kclusters() KclusterInterface } -// MybookInterface has methods to work with Mybook resources. -type MybookInterface interface { - Create(ctx context.Context, mybook *v1.Mybook, opts metav1.CreateOptions) (*v1.Mybook, error) - Update(ctx context.Context, mybook *v1.Mybook, opts metav1.UpdateOptions) (*v1.Mybook, error) - UpdateStatus(ctx context.Context, mybook *v1.Mybook, opts metav1.UpdateOptions) (*v1.Mybook, error) +// KclusterInterface has methods to work with Kcluster resources. +type KclusterInterface interface { + Create(ctx context.Context, kcluster *v1.Kcluster, opts metav1.CreateOptions) (*v1.Kcluster, error) + Update(ctx context.Context, kcluster *v1.Kcluster, opts metav1.UpdateOptions) (*v1.Kcluster, error) + UpdateStatus(ctx context.Context, kcluster *v1.Kcluster, opts metav1.UpdateOptions) (*v1.Kcluster, error) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error - Get(ctx context.Context, name string, opts metav1.GetOptions) (*v1.Mybook, error) - List(ctx context.Context, opts metav1.ListOptions) (*v1.MybookList, error) + Get(ctx context.Context, name string, opts metav1.GetOptions) (*v1.Kcluster, error) + List(ctx context.Context, opts metav1.ListOptions) (*v1.KclusterList, error) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) - Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.Mybook, err error) - MybookExpansion + Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.Kcluster, err error) + KclusterExpansion } -// mybooks implements MybookInterface -type mybooks struct { +// kclusters implements KclusterInterface +type kclusters struct { client rest.Interface } -// newMybooks returns a Mybooks -func newMybooks(c *koffloaderV1Client) *mybooks { - return &mybooks{ +// newKclusters returns a Kclusters +func newKclusters(c *koffloaderV1Client) *kclusters { + return &kclusters{ client: c.RESTClient(), } } -// Get takes name of the mybook, and returns the corresponding mybook object, and an error if there is any. -func (c *mybooks) Get(ctx context.Context, name string, options metav1.GetOptions) (result *v1.Mybook, err error) { - result = &v1.Mybook{} +// Get takes name of the kcluster, and returns the corresponding kcluster object, and an error if there is any. +func (c *kclusters) Get(ctx context.Context, name string, options metav1.GetOptions) (result *v1.Kcluster, err error) { + result = &v1.Kcluster{} err = c.client.Get(). - Resource("mybooks"). + Resource("kclusters"). Name(name). VersionedParams(&options, scheme.ParameterCodec). Do(ctx). @@ -61,15 +61,15 @@ func (c *mybooks) Get(ctx context.Context, name string, options metav1.GetOption return } -// List takes label and field selectors, and returns the list of Mybooks that match those selectors. -func (c *mybooks) List(ctx context.Context, opts metav1.ListOptions) (result *v1.MybookList, err error) { +// List takes label and field selectors, and returns the list of Kclusters that match those selectors. +func (c *kclusters) List(ctx context.Context, opts metav1.ListOptions) (result *v1.KclusterList, err error) { var timeout time.Duration if opts.TimeoutSeconds != nil { timeout = time.Duration(*opts.TimeoutSeconds) * time.Second } - result = &v1.MybookList{} + result = &v1.KclusterList{} err = c.client.Get(). - Resource("mybooks"). + Resource("kclusters"). VersionedParams(&opts, scheme.ParameterCodec). Timeout(timeout). Do(ctx). @@ -77,40 +77,40 @@ func (c *mybooks) List(ctx context.Context, opts metav1.ListOptions) (result *v1 return } -// Watch returns a watch.Interface that watches the requested mybooks. -func (c *mybooks) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { +// Watch returns a watch.Interface that watches the requested kclusters. +func (c *kclusters) Watch(ctx context.Context, opts metav1.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(). - Resource("mybooks"). + Resource("kclusters"). VersionedParams(&opts, scheme.ParameterCodec). Timeout(timeout). Watch(ctx) } -// Create takes the representation of a mybook and creates it. Returns the server's representation of the mybook, and an error, if there is any. -func (c *mybooks) Create(ctx context.Context, mybook *v1.Mybook, opts metav1.CreateOptions) (result *v1.Mybook, err error) { - result = &v1.Mybook{} +// Create takes the representation of a kcluster and creates it. Returns the server's representation of the kcluster, and an error, if there is any. +func (c *kclusters) Create(ctx context.Context, kcluster *v1.Kcluster, opts metav1.CreateOptions) (result *v1.Kcluster, err error) { + result = &v1.Kcluster{} err = c.client.Post(). - Resource("mybooks"). + Resource("kclusters"). VersionedParams(&opts, scheme.ParameterCodec). - Body(mybook). + Body(kcluster). Do(ctx). Into(result) return } -// Update takes the representation of a mybook and updates it. Returns the server's representation of the mybook, and an error, if there is any. -func (c *mybooks) Update(ctx context.Context, mybook *v1.Mybook, opts metav1.UpdateOptions) (result *v1.Mybook, err error) { - result = &v1.Mybook{} +// Update takes the representation of a kcluster and updates it. Returns the server's representation of the kcluster, and an error, if there is any. +func (c *kclusters) Update(ctx context.Context, kcluster *v1.Kcluster, opts metav1.UpdateOptions) (result *v1.Kcluster, err error) { + result = &v1.Kcluster{} err = c.client.Put(). - Resource("mybooks"). - Name(mybook.Name). + Resource("kclusters"). + Name(kcluster.Name). VersionedParams(&opts, scheme.ParameterCodec). - Body(mybook). + Body(kcluster). Do(ctx). Into(result) return @@ -118,23 +118,23 @@ func (c *mybooks) Update(ctx context.Context, mybook *v1.Mybook, opts metav1.Upd // UpdateStatus was generated because the type contains a Status member. // Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). -func (c *mybooks) UpdateStatus(ctx context.Context, mybook *v1.Mybook, opts metav1.UpdateOptions) (result *v1.Mybook, err error) { - result = &v1.Mybook{} +func (c *kclusters) UpdateStatus(ctx context.Context, kcluster *v1.Kcluster, opts metav1.UpdateOptions) (result *v1.Kcluster, err error) { + result = &v1.Kcluster{} err = c.client.Put(). - Resource("mybooks"). - Name(mybook.Name). + Resource("kclusters"). + Name(kcluster.Name). SubResource("status"). VersionedParams(&opts, scheme.ParameterCodec). - Body(mybook). + Body(kcluster). Do(ctx). Into(result) return } -// Delete takes name of the mybook and deletes it. Returns an error if one occurs. -func (c *mybooks) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { +// Delete takes name of the kcluster and deletes it. Returns an error if one occurs. +func (c *kclusters) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { return c.client.Delete(). - Resource("mybooks"). + Resource("kclusters"). Name(name). Body(&opts). Do(ctx). @@ -142,13 +142,13 @@ func (c *mybooks) Delete(ctx context.Context, name string, opts metav1.DeleteOpt } // DeleteCollection deletes a collection of objects. -func (c *mybooks) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { +func (c *kclusters) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error { var timeout time.Duration if listOpts.TimeoutSeconds != nil { timeout = time.Duration(*listOpts.TimeoutSeconds) * time.Second } return c.client.Delete(). - Resource("mybooks"). + Resource("kclusters"). VersionedParams(&listOpts, scheme.ParameterCodec). Timeout(timeout). Body(&opts). @@ -156,11 +156,11 @@ func (c *mybooks) DeleteCollection(ctx context.Context, opts metav1.DeleteOption Error() } -// Patch applies the patch and returns the patched mybook. -func (c *mybooks) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.Mybook, err error) { - result = &v1.Mybook{} +// Patch applies the patch and returns the patched kcluster. +func (c *kclusters) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.Kcluster, err error) { + result = &v1.Kcluster{} err = c.client.Patch(pt). - Resource("mybooks"). + Resource("kclusters"). Name(name). SubResource(subresources...). VersionedParams(&opts, scheme.ParameterCodec). diff --git a/pkg/k8s/client/clientset/versioned/typed/rocktemplate.spidernet.io/v1/rocktemplate.spidernet.io_client.go b/pkg/k8s/client/clientset/versioned/typed/rocktemplate.spidernet.io/v1/rocktemplate.spidernet.io_client.go index 6a776c0e..b3912d13 100644 --- a/pkg/k8s/client/clientset/versioned/typed/rocktemplate.spidernet.io/v1/rocktemplate.spidernet.io_client.go +++ b/pkg/k8s/client/clientset/versioned/typed/rocktemplate.spidernet.io/v1/rocktemplate.spidernet.io_client.go @@ -15,7 +15,7 @@ import ( type koffloaderV1Interface interface { RESTClient() rest.Interface - MybooksGetter + KclustersGetter } // koffloaderV1Client is used to interact with features provided by the koffloader.koffloader.io group. @@ -23,8 +23,8 @@ type koffloaderV1Client struct { restClient rest.Interface } -func (c *koffloaderV1Client) Mybooks() MybookInterface { - return newMybooks(c) +func (c *koffloaderV1Client) Kclusters() KclusterInterface { + return newKclusters(c) } // NewForConfig creates a new koffloaderV1Client for the given config. diff --git a/pkg/k8s/client/informers/externalversions/generic.go b/pkg/k8s/client/informers/externalversions/generic.go index 58034492..b94f50f8 100644 --- a/pkg/k8s/client/informers/externalversions/generic.go +++ b/pkg/k8s/client/informers/externalversions/generic.go @@ -40,8 +40,8 @@ func (f *genericInformer) Lister() cache.GenericLister { func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource) (GenericInformer, error) { switch resource { // Group=koffloader.koffloader.io, Version=v1 - case v1.SchemeGroupVersion.WithResource("mybooks"): - return &genericInformer{resource: resource.GroupResource(), informer: f.koffloader().V1().Mybooks().Informer()}, nil + case v1.SchemeGroupVersion.WithResource("kclusters"): + return &genericInformer{resource: resource.GroupResource(), informer: f.koffloader().V1().Kclusters().Informer()}, nil } diff --git a/pkg/k8s/client/informers/externalversions/rocktemplate.spidernet.io/v1/interface.go b/pkg/k8s/client/informers/externalversions/rocktemplate.spidernet.io/v1/interface.go index e32e498a..babe38d4 100644 --- a/pkg/k8s/client/informers/externalversions/rocktemplate.spidernet.io/v1/interface.go +++ b/pkg/k8s/client/informers/externalversions/rocktemplate.spidernet.io/v1/interface.go @@ -11,8 +11,8 @@ import ( // Interface provides access to all the informers in this group version. type Interface interface { - // Mybooks returns a MybookInformer. - Mybooks() MybookInformer + // Kclusters returns a KclusterInformer. + Kclusters() KclusterInformer } type version struct { @@ -26,7 +26,7 @@ func New(f internalinterfaces.SharedInformerFactory, namespace string, tweakList return &version{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} } -// Mybooks returns a MybookInformer. -func (v *version) Mybooks() MybookInformer { - return &mybookInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} +// Kclusters returns a KclusterInformer. +func (v *version) Kclusters() KclusterInformer { + return &kclusterInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} } diff --git a/pkg/k8s/client/informers/externalversions/rocktemplate.spidernet.io/v1/mybook.go b/pkg/k8s/client/informers/externalversions/rocktemplate.spidernet.io/v1/mybook.go index 4b807cdb..76fc5bf5 100644 --- a/pkg/k8s/client/informers/externalversions/rocktemplate.spidernet.io/v1/mybook.go +++ b/pkg/k8s/client/informers/externalversions/rocktemplate.spidernet.io/v1/mybook.go @@ -19,58 +19,58 @@ import ( cache "k8s.io/client-go/tools/cache" ) -// MybookInformer provides access to a shared informer and lister for -// Mybooks. -type MybookInformer interface { +// KclusterInformer provides access to a shared informer and lister for +// Kclusters. +type KclusterInformer interface { Informer() cache.SharedIndexInformer - Lister() v1.MybookLister + Lister() v1.KclusterLister } -type mybookInformer struct { +type kclusterInformer struct { factory internalinterfaces.SharedInformerFactory tweakListOptions internalinterfaces.TweakListOptionsFunc } -// NewMybookInformer constructs a new informer for Mybook type. +// NewKclusterInformer constructs a new informer for Kcluster 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 NewMybookInformer(client versioned.Interface, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { - return NewFilteredMybookInformer(client, resyncPeriod, indexers, nil) +func NewKclusterInformer(client versioned.Interface, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return NewFilteredKclusterInformer(client, resyncPeriod, indexers, nil) } -// NewFilteredMybookInformer constructs a new informer for Mybook type. +// NewFilteredKclusterInformer constructs a new informer for Kcluster 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 NewFilteredMybookInformer(client versioned.Interface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { +func NewFilteredKclusterInformer(client versioned.Interface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { return cache.NewSharedIndexInformer( &cache.ListWatch{ ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.koffloaderV1().Mybooks().List(context.TODO(), options) + return client.koffloaderV1().Kclusters().List(context.TODO(), options) }, WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { if tweakListOptions != nil { tweakListOptions(&options) } - return client.koffloaderV1().Mybooks().Watch(context.TODO(), options) + return client.koffloaderV1().Kclusters().Watch(context.TODO(), options) }, }, - &koffloaderspidernetiov1.Mybook{}, + &koffloaderspidernetiov1.Kcluster{}, resyncPeriod, indexers, ) } -func (f *mybookInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { - return NewFilteredMybookInformer(client, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) +func (f *kclusterInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewFilteredKclusterInformer(client, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) } -func (f *mybookInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&koffloaderspidernetiov1.Mybook{}, f.defaultInformer) +func (f *kclusterInformer) Informer() cache.SharedIndexInformer { + return f.factory.InformerFor(&koffloaderspidernetiov1.Kcluster{}, f.defaultInformer) } -func (f *mybookInformer) Lister() v1.MybookLister { - return v1.NewMybookLister(f.Informer().GetIndexer()) +func (f *kclusterInformer) Lister() v1.KclusterLister { + return v1.NewKclusterLister(f.Informer().GetIndexer()) } diff --git a/pkg/k8s/client/listers/rocktemplate.spidernet.io/v1/expansion_generated.go b/pkg/k8s/client/listers/rocktemplate.spidernet.io/v1/expansion_generated.go index 40bc791c..a5996393 100644 --- a/pkg/k8s/client/listers/rocktemplate.spidernet.io/v1/expansion_generated.go +++ b/pkg/k8s/client/listers/rocktemplate.spidernet.io/v1/expansion_generated.go @@ -5,6 +5,6 @@ package v1 -// MybookListerExpansion allows custom methods to be added to -// MybookLister. -type MybookListerExpansion interface{} +// KclusterListerExpansion allows custom methods to be added to +// KclusterLister. +type KclusterListerExpansion interface{} diff --git a/pkg/k8s/client/listers/rocktemplate.spidernet.io/v1/mybook.go b/pkg/k8s/client/listers/rocktemplate.spidernet.io/v1/mybook.go index 17fe24c3..c80823ae 100644 --- a/pkg/k8s/client/listers/rocktemplate.spidernet.io/v1/mybook.go +++ b/pkg/k8s/client/listers/rocktemplate.spidernet.io/v1/mybook.go @@ -12,44 +12,44 @@ import ( "k8s.io/client-go/tools/cache" ) -// MybookLister helps list Mybooks. +// KclusterLister helps list Kclusters. // All objects returned here must be treated as read-only. -type MybookLister interface { - // List lists all Mybooks in the indexer. +type KclusterLister interface { + // List lists all Kclusters in the indexer. // Objects returned here must be treated as read-only. - List(selector labels.Selector) (ret []*v1.Mybook, err error) - // Get retrieves the Mybook from the index for a given name. + List(selector labels.Selector) (ret []*v1.Kcluster, err error) + // Get retrieves the Kcluster from the index for a given name. // Objects returned here must be treated as read-only. - Get(name string) (*v1.Mybook, error) - MybookListerExpansion + Get(name string) (*v1.Kcluster, error) + KclusterListerExpansion } -// mybookLister implements the MybookLister interface. -type mybookLister struct { +// kclusterLister implements the KclusterLister interface. +type kclusterLister struct { indexer cache.Indexer } -// NewMybookLister returns a new MybookLister. -func NewMybookLister(indexer cache.Indexer) MybookLister { - return &mybookLister{indexer: indexer} +// NewKclusterLister returns a new KclusterLister. +func NewKclusterLister(indexer cache.Indexer) KclusterLister { + return &kclusterLister{indexer: indexer} } -// List lists all Mybooks in the indexer. -func (s *mybookLister) List(selector labels.Selector) (ret []*v1.Mybook, err error) { +// List lists all Kclusters in the indexer. +func (s *kclusterLister) List(selector labels.Selector) (ret []*v1.Kcluster, err error) { err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*v1.Mybook)) + ret = append(ret, m.(*v1.Kcluster)) }) return ret, err } -// Get retrieves the Mybook from the index for a given name. -func (s *mybookLister) Get(name string) (*v1.Mybook, error) { +// Get retrieves the Kcluster from the index for a given name. +func (s *kclusterLister) Get(name string) (*v1.Kcluster, error) { obj, exists, err := s.indexer.GetByKey(name) if err != nil { return nil, err } if !exists { - return nil, errors.NewNotFound(v1.Resource("mybook"), name) + return nil, errors.NewNotFound(v1.Resource("kcluster"), name) } - return obj.(*v1.Mybook), nil + return obj.(*v1.Kcluster), nil } diff --git a/pkg/mybookManager/controller.go b/pkg/kclusterManager/controller.go similarity index 88% rename from pkg/mybookManager/controller.go rename to pkg/kclusterManager/controller.go index 87bc634b..86fad9c8 100644 --- a/pkg/mybookManager/controller.go +++ b/pkg/kclusterManager/controller.go @@ -1,7 +1,7 @@ // Copyright 2024 Authors of koffloader-io // SPDX-License-Identifier: Apache-2.0 -package mybookManager +package kclusterManager import ( "context" @@ -35,7 +35,7 @@ type informerHandler struct { leaseId string eventRecord record.EventRecorder queue workqueue.RateLimitingInterface - crdlister crdlisterv1.MybookLister + crdlister crdlisterv1.KclusterLister k8sclient crdclientset.Interface } @@ -51,7 +51,7 @@ func (s *informerHandler) processNextWorkItem(ctx context.Context) bool { } defer s.queue.Done(key) - err := s.syncHandler(ctx, key.(*crd.Mybook)) + err := s.syncHandler(ctx, key.(*crd.Kcluster)) if err == nil { s.queue.Forget(key) } else { @@ -71,29 +71,29 @@ func (s *informerHandler) processNextWorkItem(ctx context.Context) bool { func (s *informerHandler) informerAddHandler(obj interface{}) { - r, ok := obj.(*crd.Mybook) + r, ok := obj.(*crd.Kcluster) if !ok { s.logger.Sugar().Errorf("failed to get crd: %+v", obj) return } - s.logger.Sugar().Infof("add mybook : %+v", r) + s.logger.Sugar().Infof("add kcluster : %+v", r) // enqueue s.queue.AddRateLimited(r) // 基于工作队列,生产者和消费者模型,使得事件能够本可靠的 异步执行 成功 // 例如 resourceVersion、断网等失败,最终都能够不断重试而手工 - s.eventRecord.Eventf(r, corev1.EventTypeNormal, "newMybook", "crd event, new mybook %v", r.Name) + s.eventRecord.Eventf(r, corev1.EventTypeNormal, "newKcluster", "crd event, new kcluster %v", r.Name) } func (s *informerHandler) informerUpdateHandler(oldObj interface{}, newObj interface{}) { - _, ok := oldObj.(*crd.Mybook) + _, ok := oldObj.(*crd.Kcluster) if !ok { s.logger.Sugar().Errorf("failed to get crd: %+v", oldObj) return } - newone, ok := newObj.(*crd.Mybook) + newone, ok := newObj.(*crd.Kcluster) if !ok { s.logger.Sugar().Errorf("failed to get crd: %+v", newObj) return @@ -108,13 +108,13 @@ func (s *informerHandler) informerUpdateHandler(oldObj interface{}, newObj inter // return s.handleCrdEvent(context.Background(), curPod) // }) // if err != nil { - // s.logger.Sugar().Errorf("failed to update mybook status, error=%v", err) + // s.logger.Sugar().Errorf("failed to update kcluster status, error=%v", err) // } // } } func (s *informerHandler) informerDeleteHandler(obj interface{}) { - r, ok := obj.(*crd.Mybook) + r, ok := obj.(*crd.Kcluster) if !ok { s.logger.Sugar().Errorf("failed to get crd: %+v", obj) return @@ -166,7 +166,7 @@ func (s *informerHandler) executeInformer() { factory := externalversions.NewSharedInformerFactory(clientset, 0) // 注意,一个 factory 下 对同一种 CRD 不能 创建 多个Informer,不然会 数据竞争 问题。 而 一个 factory 下, 可对不同 CRD 产生 各种的 Informer - t := factory.koffloader().V1().Mybooks() + t := factory.koffloader().V1().Kclusters() s.crdlister = t.Lister() inform := t.Informer() @@ -191,7 +191,7 @@ func (s *informerHandler) executeInformer() { go func() { s.logger.Info("start worker") - if !cache.WaitForNamedCacheSync("mybook-controller", ctx.Done(), inform.HasSynced) { + if !cache.WaitForNamedCacheSync("kcluster-controller", ctx.Done(), inform.HasSynced) { s.logger.Error("failed to sync cache") cancel() return @@ -206,7 +206,7 @@ func (s *informerHandler) executeInformer() { } -func (s *mybookManager) RunController(leaseName, leaseNameSpace string, leaseId string) { +func (s *kclusterManager) RunController(leaseName, leaseNameSpace string, leaseId string) { scheme, e := crd.SchemeBuilder.Build() if e != nil { @@ -216,9 +216,9 @@ func (s *mybookManager) RunController(leaseName, leaseNameSpace string, leaseId Events: Type Reason Age From Message ---- ------ ---- ---- ------- - Normal newMybook 13s mybook crd event, new mybook test + Normal newKcluster 13s kcluster crd event, new kcluster test */ - p := k8s.NewEventRecord(scheme, "mybook", s.logger) + p := k8s.NewEventRecord(scheme, "kcluster", s.logger) // ----------- t := &informerHandler{ @@ -227,7 +227,7 @@ func (s *mybookManager) RunController(leaseName, leaseNameSpace string, leaseId leaseNameSpace: leaseNameSpace, leaseId: leaseId, eventRecord: p, - queue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "mybook"), + queue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "kcluster"), } s.informer = t diff --git a/pkg/mybookManager/controller_worker.go b/pkg/kclusterManager/controller_worker.go similarity index 78% rename from pkg/mybookManager/controller_worker.go rename to pkg/kclusterManager/controller_worker.go index 74159b3e..d0b4beec 100644 --- a/pkg/mybookManager/controller_worker.go +++ b/pkg/kclusterManager/controller_worker.go @@ -1,7 +1,7 @@ // Copyright 2024 Authors of koffloader-io // SPDX-License-Identifier: Apache-2.0 -package mybookManager +package kclusterManager import ( "context" @@ -12,14 +12,14 @@ import ( "reflect" ) -func (s *informerHandler) syncHandler(ctx context.Context, obj *crd.Mybook) error { +func (s *informerHandler) syncHandler(ctx context.Context, obj *crd.Kcluster) error { if obj == nil { return nil } logger := s.logger.Named("worker") // 通过 clientset 向 api server 实时获取最新数据 - // old, err := s.k8sclient.koffloaderV1().Mybooks().Get(ctx, obj.Name, metav1.GetOptions{}) + // old, err := s.k8sclient.koffloaderV1().Kclusters().Get(ctx, obj.Name, metav1.GetOptions{}) // 获取最新cache中的数据(cache中的数据有延时风险) old, err := s.crdlister.Get(obj.Name) if err != nil { @@ -37,14 +37,14 @@ func (s *informerHandler) syncHandler(ctx context.Context, obj *crd.Mybook) erro newone.Status.TotalIPCount = 100 if !reflect.DeepEqual(old, newone) { - if _, err := s.k8sclient.koffloaderV1().Mybooks().UpdateStatus(ctx, newone, metav1.UpdateOptions{}); err != nil { + if _, err := s.k8sclient.koffloaderV1().Kclusters().UpdateStatus(ctx, newone, metav1.UpdateOptions{}); err != nil { // if conflicted, queue will retry it later return err } logger.Info("succeed to update " + obj.Name) // generate crd event - s.eventRecord.Eventf(newone, corev1.EventTypeNormal, "modified Mybook", "crd event, new mybook %v", newone.Name) + s.eventRecord.Eventf(newone, corev1.EventTypeNormal, "modified Kcluster", "crd event, new kcluster %v", newone.Name) } diff --git a/pkg/kclusterManager/manager.go b/pkg/kclusterManager/manager.go new file mode 100644 index 00000000..fd8a9c59 --- /dev/null +++ b/pkg/kclusterManager/manager.go @@ -0,0 +1,24 @@ +// Copyright 2024 Authors of koffloader-io +// SPDX-License-Identifier: Apache-2.0 + +package kclusterManager + +import ( + "github.com/koffloader-io/koffloader/pkg/kclusterManager/types" + "go.uber.org/zap" +) + +type kclusterManager struct { + logger *zap.Logger + webhook *webhookhander + informer *informerHandler +} + +var _ types.KclusterManager = (*kclusterManager)(nil) + +func New(logger *zap.Logger) types.KclusterManager { + + return &kclusterManager{ + logger: logger.Named("kclusterManager"), + } +} diff --git a/pkg/mybookManager/types/type.go b/pkg/kclusterManager/types/type.go similarity index 86% rename from pkg/mybookManager/types/type.go rename to pkg/kclusterManager/types/type.go index cea502ef..871e1ce5 100644 --- a/pkg/mybookManager/types/type.go +++ b/pkg/kclusterManager/types/type.go @@ -3,7 +3,7 @@ package types -type MybookManager interface { +type KclusterManager interface { RunWebhookServer(webhookPort int, tlsDir string) RunController(leaseName, leaseNameSpace string, leaseId string) } diff --git a/pkg/mybookManager/webhook.go b/pkg/kclusterManager/webhook.go similarity index 93% rename from pkg/mybookManager/webhook.go rename to pkg/kclusterManager/webhook.go index af186664..122543ce 100644 --- a/pkg/mybookManager/webhook.go +++ b/pkg/kclusterManager/webhook.go @@ -1,7 +1,7 @@ // Copyright 2024 Authors of koffloader-io // SPDX-License-Identifier: Apache-2.0 -package mybookManager +package kclusterManager import ( "context" @@ -29,7 +29,7 @@ var _ webhook.CustomValidator = (*webhookhander)(nil) func (s *webhookhander) Default(ctx context.Context, obj runtime.Object) error { logger := s.logger.Named("mutating wehbook") - r, ok := obj.(*crd.Mybook) + r, ok := obj.(*crd.Kcluster) if !ok { s := "failed to get obj" logger.Error(s) @@ -50,7 +50,7 @@ func (s *webhookhander) Default(ctx context.Context, obj runtime.Object) error { func (s *webhookhander) ValidateCreate(ctx context.Context, obj runtime.Object) error { logger := s.logger.Named("validating create webhook") - r, ok := obj.(*crd.Mybook) + r, ok := obj.(*crd.Kcluster) if !ok { s := "failed to get obj" logger.Error(s) @@ -64,13 +64,13 @@ func (s *webhookhander) ValidateCreate(ctx context.Context, obj runtime.Object) func (s *webhookhander) ValidateUpdate(ctx context.Context, oldObj, newObj runtime.Object) error { logger := s.logger.Named("validating update webhook") - old, ok := oldObj.(*crd.Mybook) + old, ok := oldObj.(*crd.Kcluster) if !ok { s := "failed to get oldObj" logger.Error(s) return apierrors.NewBadRequest(s) } - new, ok := newObj.(*crd.Mybook) + new, ok := newObj.(*crd.Kcluster) if !ok { s := "failed to get newObj" logger.Error(s) @@ -86,7 +86,7 @@ func (s *webhookhander) ValidateUpdate(ctx context.Context, oldObj, newObj runti func (s *webhookhander) ValidateDelete(ctx context.Context, obj runtime.Object) error { logger := s.logger.Named("validating delete webhook") - r, ok := obj.(*crd.Mybook) + r, ok := obj.(*crd.Kcluster) if !ok { s := "failed to get obj" logger.Error(s) @@ -101,7 +101,7 @@ func (s *webhookhander) ValidateDelete(ctx context.Context, obj runtime.Object) // https://github.com/kubernetes-sigs/controller-runtime/blob/master/pkg/builder/example_webhook_test.go // https://github.com/kubernetes-sigs/controller-runtime/blob/master/pkg/builder/webhook_test.go -func (s *mybookManager) RunWebhookServer(webhookPort int, tlsDir string) { +func (s *kclusterManager) RunWebhookServer(webhookPort int, tlsDir string) { logger := s.logger r := &webhookhander{ logger: logger, @@ -131,7 +131,7 @@ func (s *mybookManager) RunWebhookServer(webhookPort int, tlsDir string) { // the mutating route path : "/mutate-" + strings.ReplaceAll(gvk.Group, ".", "-") + "-" + gvk.Version + "-" + strings.ToLower(gvk.Kind) // the validate route path : "/validate-" + strings.ReplaceAll(gvk.Group, ".", "-") + "-" + gvk.Version + "-" + strings.ToLower(gvk.Kind) e := ctrl.NewWebhookManagedBy(mgr). - For(&crd.Mybook{}). + For(&crd.Kcluster{}). WithDefaulter(r). WithValidator(r). Complete() diff --git a/pkg/mybookManager/manager.go b/pkg/mybookManager/manager.go deleted file mode 100644 index 7e73d5d4..00000000 --- a/pkg/mybookManager/manager.go +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright 2024 Authors of koffloader-io -// SPDX-License-Identifier: Apache-2.0 - -package mybookManager - -import ( - "github.com/koffloader-io/koffloader/pkg/mybookManager/types" - "go.uber.org/zap" -) - -type mybookManager struct { - logger *zap.Logger - webhook *webhookhander - informer *informerHandler -} - -var _ types.MybookManager = (*mybookManager)(nil) - -func New(logger *zap.Logger) types.MybookManager { - - return &mybookManager{ - logger: logger.Named("mybookManager"), - } -}