From 9bd84627adaac915555e5b62b1a7998937d469c8 Mon Sep 17 00:00:00 2001 From: baowj Date: Mon, 11 Mar 2024 20:33:56 +0800 Subject: [PATCH 01/59] Add rulecheck CRD 1.add rulecheck CRD 2.generate rulecheck deepcopy, list, informer, clientset 3.add hack files Signed-off-by: baowj --- hack/boilerplate.go.txt | 14 + hack/tool.go | 3 + hack/update-codegen.sh | 34 +++ pkg/apis/caelus/v1/doc.go | 19 ++ pkg/apis/caelus/v1/register.go | 52 ++++ pkg/apis/caelus/v1/rulecheck_types.go | 83 ++++++ pkg/apis/caelus/v1/zz_generated.deepcopy.go | 249 ++++++++++++++++++ .../clientset/versioned/clientset.go | 119 +++++++++ pkg/generated/clientset/versioned/doc.go | 18 ++ .../versioned/fake/clientset_generated.go | 83 ++++++ pkg/generated/clientset/versioned/fake/doc.go | 18 ++ .../clientset/versioned/fake/register.go | 54 ++++ .../clientset/versioned/scheme/doc.go | 18 ++ .../clientset/versioned/scheme/register.go | 54 ++++ .../typed/caelus/v1/caelus_client.go | 105 ++++++++ .../versioned/typed/caelus/v1/doc.go | 18 ++ .../versioned/typed/caelus/v1/fake/doc.go | 18 ++ .../caelus/v1/fake/fake_caelus_client.go | 38 +++ .../typed/caelus/v1/fake/fake_rulecheck.go | 140 ++++++++++ .../typed/caelus/v1/generated_expansion.go | 19 ++ .../versioned/typed/caelus/v1/rulecheck.go | 193 ++++++++++++++ .../externalversions/caelus/interface.go | 44 ++++ .../externalversions/caelus/v1/interface.go | 43 +++ .../externalversions/caelus/v1/rulecheck.go | 88 +++++++ .../informers/externalversions/factory.go | 178 +++++++++++++ .../informers/externalversions/generic.go | 60 +++++ .../internalinterfaces/factory_interfaces.go | 38 +++ .../listers/caelus/v1/expansion_generated.go | 25 ++ pkg/generated/listers/caelus/v1/rulecheck.go | 97 +++++++ 29 files changed, 1922 insertions(+) create mode 100644 hack/boilerplate.go.txt create mode 100644 hack/tool.go create mode 100755 hack/update-codegen.sh create mode 100644 pkg/apis/caelus/v1/doc.go create mode 100644 pkg/apis/caelus/v1/register.go create mode 100644 pkg/apis/caelus/v1/rulecheck_types.go create mode 100644 pkg/apis/caelus/v1/zz_generated.deepcopy.go create mode 100644 pkg/generated/clientset/versioned/clientset.go create mode 100644 pkg/generated/clientset/versioned/doc.go create mode 100644 pkg/generated/clientset/versioned/fake/clientset_generated.go create mode 100644 pkg/generated/clientset/versioned/fake/doc.go create mode 100644 pkg/generated/clientset/versioned/fake/register.go create mode 100644 pkg/generated/clientset/versioned/scheme/doc.go create mode 100644 pkg/generated/clientset/versioned/scheme/register.go create mode 100644 pkg/generated/clientset/versioned/typed/caelus/v1/caelus_client.go create mode 100644 pkg/generated/clientset/versioned/typed/caelus/v1/doc.go create mode 100644 pkg/generated/clientset/versioned/typed/caelus/v1/fake/doc.go create mode 100644 pkg/generated/clientset/versioned/typed/caelus/v1/fake/fake_caelus_client.go create mode 100644 pkg/generated/clientset/versioned/typed/caelus/v1/fake/fake_rulecheck.go create mode 100644 pkg/generated/clientset/versioned/typed/caelus/v1/generated_expansion.go create mode 100644 pkg/generated/clientset/versioned/typed/caelus/v1/rulecheck.go create mode 100644 pkg/generated/informers/externalversions/caelus/interface.go create mode 100644 pkg/generated/informers/externalversions/caelus/v1/interface.go create mode 100644 pkg/generated/informers/externalversions/caelus/v1/rulecheck.go create mode 100644 pkg/generated/informers/externalversions/factory.go create mode 100644 pkg/generated/informers/externalversions/generic.go create mode 100644 pkg/generated/informers/externalversions/internalinterfaces/factory_interfaces.go create mode 100644 pkg/generated/listers/caelus/v1/expansion_generated.go create mode 100644 pkg/generated/listers/caelus/v1/rulecheck.go diff --git a/hack/boilerplate.go.txt b/hack/boilerplate.go.txt new file mode 100644 index 00000000..2fbfd10a --- /dev/null +++ b/hack/boilerplate.go.txt @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2021 THL A29 Limited, a Tencent company. + * + * 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. + */ \ No newline at end of file diff --git a/hack/tool.go b/hack/tool.go new file mode 100644 index 00000000..ed8aab6e --- /dev/null +++ b/hack/tool.go @@ -0,0 +1,3 @@ +package tools + +import _ "k8s.io/code-generator" diff --git a/hack/update-codegen.sh b/hack/update-codegen.sh new file mode 100755 index 00000000..046c0225 --- /dev/null +++ b/hack/update-codegen.sh @@ -0,0 +1,34 @@ +#!/usr/bin/env bash + +# Copyright (c) 2021 THL A29 Limited, a Tencent company. +# +# 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=$(go env GOPATH)/pkg/mod/k8s.io/code-generator@v0.24.2-rc.0 +echo $SCRIPT_ROOT +# 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. +bash "${CODEGEN_PKG}"/generate-groups.sh "deepcopy,client,informer,lister" \ + github.com/tencent/caelus/pkg/generated github.com/tencent/caelus/pkg/apis \ + caelus:v1 \ + --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 \ No newline at end of file diff --git a/pkg/apis/caelus/v1/doc.go b/pkg/apis/caelus/v1/doc.go new file mode 100644 index 00000000..71fb844c --- /dev/null +++ b/pkg/apis/caelus/v1/doc.go @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2021 THL A29 Limited, a Tencent company. + * + * 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=caelus + +package v1 diff --git a/pkg/apis/caelus/v1/register.go b/pkg/apis/caelus/v1/register.go new file mode 100644 index 00000000..563e55b3 --- /dev/null +++ b/pkg/apis/caelus/v1/register.go @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2021 THL A29 Limited, a Tencent company. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * + * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package v1 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "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: "caelus", Version: "v1"} + +// Kind takes an unqualified kind and returns back a Group qualified GroupKind +func Kind(kind string) schema.GroupKind { + return SchemeGroupVersion.WithKind(kind).GroupKind() +} + +// 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, + &RuleCheck{}, + &RuleCheckList{}, + ) + metav1.AddToGroupVersion(scheme, SchemeGroupVersion) + return nil +} diff --git a/pkg/apis/caelus/v1/rulecheck_types.go b/pkg/apis/caelus/v1/rulecheck_types.go new file mode 100644 index 00000000..f25fc852 --- /dev/null +++ b/pkg/apis/caelus/v1/rulecheck_types.go @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2021 THL A29 Limited, a Tencent company. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * + * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package v1 + +import ( + "encoding/json" + "github.com/tencent/caelus/pkg/util/times" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +// +genclient +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// RuleCheck is a specification for a RuleCheck resource +type RuleCheck struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + + Spec RuleCheckSpec `json:"spec"` + Status RuleCheckStatus `json:"status"` +} + +// RuleCheckSpec is the spec for a RuleCheck resource +type RuleCheckSpec struct { + NodeSelector map[string]string `json:"nodeSelector"` + + Metrics []string `json:"metrics"` + // CheckInterval describes the interval to trigger detection + CheckInterval *times.Duration `json:"checkInterval"` + // HandleInterval describes the interval to handle conflicts after detecting abnormal result + HandleInterval *times.Duration `json:"handleInterval"` + // RecoverInterval describes the interval to recover conflicts after detecting normal result + RecoverInterval *times.Duration `json:"recoverInterval"` + + Rules []*DetectActionRules `json:"rules"` + RecoverRules []*DetectActionRules `json:"recoverRules"` +} + +// DetectActionRules define detectors and actions +type DetectActionRules struct { + Detects []*DetectAction `json:"detects"` + Actions []*DetectAction `json:"actions"` +} + +// DetectAction define detector config +type DetectAction struct { + Name string `json:"name"` + Args json.RawMessage `json:"args"` +} + +// ActionConfig define action config +type ActionConfig struct { + Name string `json:"name"` + Args json.RawMessage `json:"args"` +} + +// RuleCheckStatus is the status for a RuleCheck resource +type RuleCheckStatus struct { + AvailableReplicas int32 `json:"availableReplicas"` +} + +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// RuleCheckList is a list of RuleCheck resources +type RuleCheckList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata"` + + Items []RuleCheck `json:"items"` +} diff --git a/pkg/apis/caelus/v1/zz_generated.deepcopy.go b/pkg/apis/caelus/v1/zz_generated.deepcopy.go new file mode 100644 index 00000000..d6315943 --- /dev/null +++ b/pkg/apis/caelus/v1/zz_generated.deepcopy.go @@ -0,0 +1,249 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* + * Copyright (c) 2021 THL A29 Limited, a Tencent company. + * + * 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 v1 + +import ( + json "encoding/json" + + times "github.com/tencent/caelus/pkg/util/times" + 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 *ActionConfig) DeepCopyInto(out *ActionConfig) { + *out = *in + if in.Args != nil { + in, out := &in.Args, &out.Args + *out = make(json.RawMessage, len(*in)) + copy(*out, *in) + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ActionConfig. +func (in *ActionConfig) DeepCopy() *ActionConfig { + if in == nil { + return nil + } + out := new(ActionConfig) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *DetectAction) DeepCopyInto(out *DetectAction) { + *out = *in + if in.Args != nil { + in, out := &in.Args, &out.Args + *out = make(json.RawMessage, len(*in)) + copy(*out, *in) + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DetectAction. +func (in *DetectAction) DeepCopy() *DetectAction { + if in == nil { + return nil + } + out := new(DetectAction) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *DetectActionRules) DeepCopyInto(out *DetectActionRules) { + *out = *in + if in.Detects != nil { + in, out := &in.Detects, &out.Detects + *out = make([]*DetectAction, len(*in)) + for i := range *in { + if (*in)[i] != nil { + in, out := &(*in)[i], &(*out)[i] + *out = new(DetectAction) + (*in).DeepCopyInto(*out) + } + } + } + if in.Actions != nil { + in, out := &in.Actions, &out.Actions + *out = make([]*DetectAction, len(*in)) + for i := range *in { + if (*in)[i] != nil { + in, out := &(*in)[i], &(*out)[i] + *out = new(DetectAction) + (*in).DeepCopyInto(*out) + } + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DetectActionRules. +func (in *DetectActionRules) DeepCopy() *DetectActionRules { + if in == nil { + return nil + } + out := new(DetectActionRules) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *RuleCheck) DeepCopyInto(out *RuleCheck) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) + out.Status = in.Status + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RuleCheck. +func (in *RuleCheck) DeepCopy() *RuleCheck { + if in == nil { + return nil + } + out := new(RuleCheck) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *RuleCheck) 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 *RuleCheckList) DeepCopyInto(out *RuleCheckList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]RuleCheck, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RuleCheckList. +func (in *RuleCheckList) DeepCopy() *RuleCheckList { + if in == nil { + return nil + } + out := new(RuleCheckList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *RuleCheckList) 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 *RuleCheckSpec) DeepCopyInto(out *RuleCheckSpec) { + *out = *in + if in.NodeSelector != nil { + in, out := &in.NodeSelector, &out.NodeSelector + *out = make(map[string]string, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } + if in.Metrics != nil { + in, out := &in.Metrics, &out.Metrics + *out = make([]string, len(*in)) + copy(*out, *in) + } + if in.CheckInterval != nil { + in, out := &in.CheckInterval, &out.CheckInterval + *out = new(times.Duration) + **out = **in + } + if in.HandleInterval != nil { + in, out := &in.HandleInterval, &out.HandleInterval + *out = new(times.Duration) + **out = **in + } + if in.RecoverInterval != nil { + in, out := &in.RecoverInterval, &out.RecoverInterval + *out = new(times.Duration) + **out = **in + } + if in.Rules != nil { + in, out := &in.Rules, &out.Rules + *out = make([]*DetectActionRules, len(*in)) + for i := range *in { + if (*in)[i] != nil { + in, out := &(*in)[i], &(*out)[i] + *out = new(DetectActionRules) + (*in).DeepCopyInto(*out) + } + } + } + if in.RecoverRules != nil { + in, out := &in.RecoverRules, &out.RecoverRules + *out = make([]*DetectActionRules, len(*in)) + for i := range *in { + if (*in)[i] != nil { + in, out := &(*in)[i], &(*out)[i] + *out = new(DetectActionRules) + (*in).DeepCopyInto(*out) + } + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RuleCheckSpec. +func (in *RuleCheckSpec) DeepCopy() *RuleCheckSpec { + if in == nil { + return nil + } + out := new(RuleCheckSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *RuleCheckStatus) DeepCopyInto(out *RuleCheckStatus) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RuleCheckStatus. +func (in *RuleCheckStatus) DeepCopy() *RuleCheckStatus { + if in == nil { + return nil + } + out := new(RuleCheckStatus) + in.DeepCopyInto(out) + return out +} diff --git a/pkg/generated/clientset/versioned/clientset.go b/pkg/generated/clientset/versioned/clientset.go new file mode 100644 index 00000000..e5de8b2e --- /dev/null +++ b/pkg/generated/clientset/versioned/clientset.go @@ -0,0 +1,119 @@ +/* + * Copyright (c) 2021 THL A29 Limited, a Tencent company. + * + * 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" + + caelusv1 "github.com/tencent/caelus/pkg/generated/clientset/versioned/typed/caelus/v1" + discovery "k8s.io/client-go/discovery" + rest "k8s.io/client-go/rest" + flowcontrol "k8s.io/client-go/util/flowcontrol" +) + +type Interface interface { + Discovery() discovery.DiscoveryInterface + CaelusV1() caelusv1.CaelusV1Interface +} + +// Clientset contains the clients for groups. Each group has exactly one +// version included in a Clientset. +type Clientset struct { + *discovery.DiscoveryClient + caelusV1 *caelusv1.CaelusV1Client +} + +// CaelusV1 retrieves the CaelusV1Client +func (c *Clientset) CaelusV1() caelusv1.CaelusV1Interface { + return c.caelusV1 +} + +// 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.caelusV1, err = caelusv1.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.caelusV1 = caelusv1.New(c) + + cs.DiscoveryClient = discovery.NewDiscoveryClient(c) + return &cs +} diff --git a/pkg/generated/clientset/versioned/doc.go b/pkg/generated/clientset/versioned/doc.go new file mode 100644 index 00000000..8eb91c9a --- /dev/null +++ b/pkg/generated/clientset/versioned/doc.go @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2021 THL A29 Limited, a Tencent company. + * + * 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 clientset. +package versioned diff --git a/pkg/generated/clientset/versioned/fake/clientset_generated.go b/pkg/generated/clientset/versioned/fake/clientset_generated.go new file mode 100644 index 00000000..96390304 --- /dev/null +++ b/pkg/generated/clientset/versioned/fake/clientset_generated.go @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2021 THL A29 Limited, a Tencent company. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * + * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// Code generated by client-gen. DO NOT EDIT. + +package fake + +import ( + clientset "github.com/tencent/caelus/pkg/generated/clientset/versioned" + caelusv1 "github.com/tencent/caelus/pkg/generated/clientset/versioned/typed/caelus/v1" + fakecaelusv1 "github.com/tencent/caelus/pkg/generated/clientset/versioned/typed/caelus/v1/fake" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/watch" + "k8s.io/client-go/discovery" + fakediscovery "k8s.io/client-go/discovery/fake" + "k8s.io/client-go/testing" +) + +// NewSimpleClientset returns a clientset that will respond with the provided objects. +// It's backed by a very simple object tracker that processes creates, updates and deletions as-is, +// without applying any validations and/or defaults. It shouldn't be considered a replacement +// for a real clientset and is mostly useful in simple unit tests. +func NewSimpleClientset(objects ...runtime.Object) *Clientset { + o := testing.NewObjectTracker(scheme, codecs.UniversalDecoder()) + for _, obj := range objects { + if err := o.Add(obj); err != nil { + panic(err) + } + } + + cs := &Clientset{tracker: o} + cs.discovery = &fakediscovery.FakeDiscovery{Fake: &cs.Fake} + cs.AddReactor("*", "*", testing.ObjectReaction(o)) + cs.AddWatchReactor("*", func(action testing.Action) (handled bool, ret watch.Interface, err error) { + gvr := action.GetResource() + ns := action.GetNamespace() + watch, err := o.Watch(gvr, ns) + if err != nil { + return false, nil, err + } + return true, watch, nil + }) + + return cs +} + +// Clientset implements clientset.Interface. Meant to be embedded into a +// struct to get a default implementation. This makes faking out just the method +// you want to test easier. +type Clientset struct { + testing.Fake + discovery *fakediscovery.FakeDiscovery + tracker testing.ObjectTracker +} + +func (c *Clientset) Discovery() discovery.DiscoveryInterface { + return c.discovery +} + +func (c *Clientset) Tracker() testing.ObjectTracker { + return c.tracker +} + +var ( + _ clientset.Interface = &Clientset{} + _ testing.FakeClient = &Clientset{} +) + +// CaelusV1 retrieves the CaelusV1Client +func (c *Clientset) CaelusV1() caelusv1.CaelusV1Interface { + return &fakecaelusv1.FakeCaelusV1{Fake: &c.Fake} +} diff --git a/pkg/generated/clientset/versioned/fake/doc.go b/pkg/generated/clientset/versioned/fake/doc.go new file mode 100644 index 00000000..c8a212b7 --- /dev/null +++ b/pkg/generated/clientset/versioned/fake/doc.go @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2021 THL A29 Limited, a Tencent company. + * + * 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/generated/clientset/versioned/fake/register.go b/pkg/generated/clientset/versioned/fake/register.go new file mode 100644 index 00000000..6f6f1cec --- /dev/null +++ b/pkg/generated/clientset/versioned/fake/register.go @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2021 THL A29 Limited, a Tencent company. + * + * 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 ( + caelusv1 "github.com/tencent/caelus/pkg/apis/caelus/v1" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + schema "k8s.io/apimachinery/pkg/runtime/schema" + serializer "k8s.io/apimachinery/pkg/runtime/serializer" + utilruntime "k8s.io/apimachinery/pkg/util/runtime" +) + +var scheme = runtime.NewScheme() +var codecs = serializer.NewCodecFactory(scheme) + +var localSchemeBuilder = runtime.SchemeBuilder{ + caelusv1.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/generated/clientset/versioned/scheme/doc.go b/pkg/generated/clientset/versioned/scheme/doc.go new file mode 100644 index 00000000..d5857dc0 --- /dev/null +++ b/pkg/generated/clientset/versioned/scheme/doc.go @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2021 THL A29 Limited, a Tencent company. + * + * 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/generated/clientset/versioned/scheme/register.go b/pkg/generated/clientset/versioned/scheme/register.go new file mode 100644 index 00000000..ea028ec2 --- /dev/null +++ b/pkg/generated/clientset/versioned/scheme/register.go @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2021 THL A29 Limited, a Tencent company. + * + * 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 ( + caelusv1 "github.com/tencent/caelus/pkg/apis/caelus/v1" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + schema "k8s.io/apimachinery/pkg/runtime/schema" + serializer "k8s.io/apimachinery/pkg/runtime/serializer" + utilruntime "k8s.io/apimachinery/pkg/util/runtime" +) + +var Scheme = runtime.NewScheme() +var Codecs = serializer.NewCodecFactory(Scheme) +var ParameterCodec = runtime.NewParameterCodec(Scheme) +var localSchemeBuilder = runtime.SchemeBuilder{ + caelusv1.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/generated/clientset/versioned/typed/caelus/v1/caelus_client.go b/pkg/generated/clientset/versioned/typed/caelus/v1/caelus_client.go new file mode 100644 index 00000000..be5877ad --- /dev/null +++ b/pkg/generated/clientset/versioned/typed/caelus/v1/caelus_client.go @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2021 THL A29 Limited, a Tencent company. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * + * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// Code generated by client-gen. DO NOT EDIT. + +package v1 + +import ( + "net/http" + + v1 "github.com/tencent/caelus/pkg/apis/caelus/v1" + "github.com/tencent/caelus/pkg/generated/clientset/versioned/scheme" + rest "k8s.io/client-go/rest" +) + +type CaelusV1Interface interface { + RESTClient() rest.Interface + RuleChecksGetter +} + +// CaelusV1Client is used to interact with features provided by the caelus group. +type CaelusV1Client struct { + restClient rest.Interface +} + +func (c *CaelusV1Client) RuleChecks(namespace string) RuleCheckInterface { + return newRuleChecks(c, namespace) +} + +// NewForConfig creates a new CaelusV1Client for the given config. +// NewForConfig is equivalent to NewForConfigAndClient(c, httpClient), +// where httpClient was generated with rest.HTTPClientFor(c). +func NewForConfig(c *rest.Config) (*CaelusV1Client, 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 CaelusV1Client 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) (*CaelusV1Client, 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 &CaelusV1Client{client}, nil +} + +// NewForConfigOrDie creates a new CaelusV1Client for the given config and +// panics if there is an error in the config. +func NewForConfigOrDie(c *rest.Config) *CaelusV1Client { + client, err := NewForConfig(c) + if err != nil { + panic(err) + } + return client +} + +// New creates a new CaelusV1Client for the given RESTClient. +func New(c rest.Interface) *CaelusV1Client { + return &CaelusV1Client{c} +} + +func setConfigDefaults(config *rest.Config) error { + gv := v1.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 *CaelusV1Client) RESTClient() rest.Interface { + if c == nil { + return nil + } + return c.restClient +} diff --git a/pkg/generated/clientset/versioned/typed/caelus/v1/doc.go b/pkg/generated/clientset/versioned/typed/caelus/v1/doc.go new file mode 100644 index 00000000..dd003f29 --- /dev/null +++ b/pkg/generated/clientset/versioned/typed/caelus/v1/doc.go @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2021 THL A29 Limited, a Tencent company. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * + * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// Code generated by client-gen. DO NOT EDIT. + +// This package has the automatically generated typed clients. +package v1 diff --git a/pkg/generated/clientset/versioned/typed/caelus/v1/fake/doc.go b/pkg/generated/clientset/versioned/typed/caelus/v1/fake/doc.go new file mode 100644 index 00000000..12074a52 --- /dev/null +++ b/pkg/generated/clientset/versioned/typed/caelus/v1/fake/doc.go @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2021 THL A29 Limited, a Tencent company. + * + * 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/caelus/v1/fake/fake_caelus_client.go b/pkg/generated/clientset/versioned/typed/caelus/v1/fake/fake_caelus_client.go new file mode 100644 index 00000000..6bca9267 --- /dev/null +++ b/pkg/generated/clientset/versioned/typed/caelus/v1/fake/fake_caelus_client.go @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2021 THL A29 Limited, a Tencent company. + * + * 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 "github.com/tencent/caelus/pkg/generated/clientset/versioned/typed/caelus/v1" + rest "k8s.io/client-go/rest" + testing "k8s.io/client-go/testing" +) + +type FakeCaelusV1 struct { + *testing.Fake +} + +func (c *FakeCaelusV1) RuleChecks(namespace string) v1.RuleCheckInterface { + return &FakeRuleChecks{c, namespace} +} + +// RESTClient returns a RESTClient that is used to communicate +// with API server by this client implementation. +func (c *FakeCaelusV1) RESTClient() rest.Interface { + var ret *rest.RESTClient + return ret +} diff --git a/pkg/generated/clientset/versioned/typed/caelus/v1/fake/fake_rulecheck.go b/pkg/generated/clientset/versioned/typed/caelus/v1/fake/fake_rulecheck.go new file mode 100644 index 00000000..66ca961d --- /dev/null +++ b/pkg/generated/clientset/versioned/typed/caelus/v1/fake/fake_rulecheck.go @@ -0,0 +1,140 @@ +/* + * Copyright (c) 2021 THL A29 Limited, a Tencent company. + * + * 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" + + caelusv1 "github.com/tencent/caelus/pkg/apis/caelus/v1" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + labels "k8s.io/apimachinery/pkg/labels" + schema "k8s.io/apimachinery/pkg/runtime/schema" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + testing "k8s.io/client-go/testing" +) + +// FakeRuleChecks implements RuleCheckInterface +type FakeRuleChecks struct { + Fake *FakeCaelusV1 + ns string +} + +var rulechecksResource = schema.GroupVersionResource{Group: "caelus", Version: "v1", Resource: "rulechecks"} + +var rulechecksKind = schema.GroupVersionKind{Group: "caelus", Version: "v1", Kind: "RuleCheck"} + +// Get takes name of the ruleCheck, and returns the corresponding ruleCheck object, and an error if there is any. +func (c *FakeRuleChecks) Get(ctx context.Context, name string, options v1.GetOptions) (result *caelusv1.RuleCheck, err error) { + obj, err := c.Fake. + Invokes(testing.NewGetAction(rulechecksResource, c.ns, name), &caelusv1.RuleCheck{}) + + if obj == nil { + return nil, err + } + return obj.(*caelusv1.RuleCheck), err +} + +// List takes label and field selectors, and returns the list of RuleChecks that match those selectors. +func (c *FakeRuleChecks) List(ctx context.Context, opts v1.ListOptions) (result *caelusv1.RuleCheckList, err error) { + obj, err := c.Fake. + Invokes(testing.NewListAction(rulechecksResource, rulechecksKind, c.ns, opts), &caelusv1.RuleCheckList{}) + + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &caelusv1.RuleCheckList{ListMeta: obj.(*caelusv1.RuleCheckList).ListMeta} + for _, item := range obj.(*caelusv1.RuleCheckList).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 ruleChecks. +func (c *FakeRuleChecks) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { + return c.Fake. + InvokesWatch(testing.NewWatchAction(rulechecksResource, c.ns, opts)) + +} + +// Create takes the representation of a ruleCheck and creates it. Returns the server's representation of the ruleCheck, and an error, if there is any. +func (c *FakeRuleChecks) Create(ctx context.Context, ruleCheck *caelusv1.RuleCheck, opts v1.CreateOptions) (result *caelusv1.RuleCheck, err error) { + obj, err := c.Fake. + Invokes(testing.NewCreateAction(rulechecksResource, c.ns, ruleCheck), &caelusv1.RuleCheck{}) + + if obj == nil { + return nil, err + } + return obj.(*caelusv1.RuleCheck), err +} + +// Update takes the representation of a ruleCheck and updates it. Returns the server's representation of the ruleCheck, and an error, if there is any. +func (c *FakeRuleChecks) Update(ctx context.Context, ruleCheck *caelusv1.RuleCheck, opts v1.UpdateOptions) (result *caelusv1.RuleCheck, err error) { + obj, err := c.Fake. + Invokes(testing.NewUpdateAction(rulechecksResource, c.ns, ruleCheck), &caelusv1.RuleCheck{}) + + if obj == nil { + return nil, err + } + return obj.(*caelusv1.RuleCheck), 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 *FakeRuleChecks) UpdateStatus(ctx context.Context, ruleCheck *caelusv1.RuleCheck, opts v1.UpdateOptions) (*caelusv1.RuleCheck, error) { + obj, err := c.Fake. + Invokes(testing.NewUpdateSubresourceAction(rulechecksResource, "status", c.ns, ruleCheck), &caelusv1.RuleCheck{}) + + if obj == nil { + return nil, err + } + return obj.(*caelusv1.RuleCheck), err +} + +// Delete takes name of the ruleCheck and deletes it. Returns an error if one occurs. +func (c *FakeRuleChecks) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { + _, err := c.Fake. + Invokes(testing.NewDeleteActionWithOptions(rulechecksResource, c.ns, name, opts), &caelusv1.RuleCheck{}) + + return err +} + +// DeleteCollection deletes a collection of objects. +func (c *FakeRuleChecks) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { + action := testing.NewDeleteCollectionAction(rulechecksResource, c.ns, listOpts) + + _, err := c.Fake.Invokes(action, &caelusv1.RuleCheckList{}) + return err +} + +// Patch applies the patch and returns the patched ruleCheck. +func (c *FakeRuleChecks) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *caelusv1.RuleCheck, err error) { + obj, err := c.Fake. + Invokes(testing.NewPatchSubresourceAction(rulechecksResource, c.ns, name, pt, data, subresources...), &caelusv1.RuleCheck{}) + + if obj == nil { + return nil, err + } + return obj.(*caelusv1.RuleCheck), err +} diff --git a/pkg/generated/clientset/versioned/typed/caelus/v1/generated_expansion.go b/pkg/generated/clientset/versioned/typed/caelus/v1/generated_expansion.go new file mode 100644 index 00000000..d25a65c6 --- /dev/null +++ b/pkg/generated/clientset/versioned/typed/caelus/v1/generated_expansion.go @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2021 THL A29 Limited, a Tencent company. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * + * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// Code generated by client-gen. DO NOT EDIT. + +package v1 + +type RuleCheckExpansion interface{} diff --git a/pkg/generated/clientset/versioned/typed/caelus/v1/rulecheck.go b/pkg/generated/clientset/versioned/typed/caelus/v1/rulecheck.go new file mode 100644 index 00000000..087d8966 --- /dev/null +++ b/pkg/generated/clientset/versioned/typed/caelus/v1/rulecheck.go @@ -0,0 +1,193 @@ +/* + * Copyright (c) 2021 THL A29 Limited, a Tencent company. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * + * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// Code generated by client-gen. DO NOT EDIT. + +package v1 + +import ( + "context" + "time" + + v1 "github.com/tencent/caelus/pkg/apis/caelus/v1" + scheme "github.com/tencent/caelus/pkg/generated/clientset/versioned/scheme" + metav1 "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" +) + +// RuleChecksGetter has a method to return a RuleCheckInterface. +// A group's client should implement this interface. +type RuleChecksGetter interface { + RuleChecks(namespace string) RuleCheckInterface +} + +// RuleCheckInterface has methods to work with RuleCheck resources. +type RuleCheckInterface interface { + Create(ctx context.Context, ruleCheck *v1.RuleCheck, opts metav1.CreateOptions) (*v1.RuleCheck, error) + Update(ctx context.Context, ruleCheck *v1.RuleCheck, opts metav1.UpdateOptions) (*v1.RuleCheck, error) + UpdateStatus(ctx context.Context, ruleCheck *v1.RuleCheck, opts metav1.UpdateOptions) (*v1.RuleCheck, 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.RuleCheck, error) + List(ctx context.Context, opts metav1.ListOptions) (*v1.RuleCheckList, 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.RuleCheck, err error) + RuleCheckExpansion +} + +// ruleChecks implements RuleCheckInterface +type ruleChecks struct { + client rest.Interface + ns string +} + +// newRuleChecks returns a RuleChecks +func newRuleChecks(c *CaelusV1Client, namespace string) *ruleChecks { + return &ruleChecks{ + client: c.RESTClient(), + ns: namespace, + } +} + +// Get takes name of the ruleCheck, and returns the corresponding ruleCheck object, and an error if there is any. +func (c *ruleChecks) Get(ctx context.Context, name string, options metav1.GetOptions) (result *v1.RuleCheck, err error) { + result = &v1.RuleCheck{} + err = c.client.Get(). + Namespace(c.ns). + Resource("rulechecks"). + Name(name). + VersionedParams(&options, scheme.ParameterCodec). + Do(ctx). + Into(result) + return +} + +// List takes label and field selectors, and returns the list of RuleChecks that match those selectors. +func (c *ruleChecks) List(ctx context.Context, opts metav1.ListOptions) (result *v1.RuleCheckList, err error) { + var timeout time.Duration + if opts.TimeoutSeconds != nil { + timeout = time.Duration(*opts.TimeoutSeconds) * time.Second + } + result = &v1.RuleCheckList{} + err = c.client.Get(). + Namespace(c.ns). + Resource("rulechecks"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Do(ctx). + Into(result) + return +} + +// Watch returns a watch.Interface that watches the requested ruleChecks. +func (c *ruleChecks) 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(). + Namespace(c.ns). + Resource("rulechecks"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Watch(ctx) +} + +// Create takes the representation of a ruleCheck and creates it. Returns the server's representation of the ruleCheck, and an error, if there is any. +func (c *ruleChecks) Create(ctx context.Context, ruleCheck *v1.RuleCheck, opts metav1.CreateOptions) (result *v1.RuleCheck, err error) { + result = &v1.RuleCheck{} + err = c.client.Post(). + Namespace(c.ns). + Resource("rulechecks"). + VersionedParams(&opts, scheme.ParameterCodec). + Body(ruleCheck). + Do(ctx). + Into(result) + return +} + +// Update takes the representation of a ruleCheck and updates it. Returns the server's representation of the ruleCheck, and an error, if there is any. +func (c *ruleChecks) Update(ctx context.Context, ruleCheck *v1.RuleCheck, opts metav1.UpdateOptions) (result *v1.RuleCheck, err error) { + result = &v1.RuleCheck{} + err = c.client.Put(). + Namespace(c.ns). + Resource("rulechecks"). + Name(ruleCheck.Name). + VersionedParams(&opts, scheme.ParameterCodec). + Body(ruleCheck). + 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 *ruleChecks) UpdateStatus(ctx context.Context, ruleCheck *v1.RuleCheck, opts metav1.UpdateOptions) (result *v1.RuleCheck, err error) { + result = &v1.RuleCheck{} + err = c.client.Put(). + Namespace(c.ns). + Resource("rulechecks"). + Name(ruleCheck.Name). + SubResource("status"). + VersionedParams(&opts, scheme.ParameterCodec). + Body(ruleCheck). + Do(ctx). + Into(result) + return +} + +// Delete takes name of the ruleCheck and deletes it. Returns an error if one occurs. +func (c *ruleChecks) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { + return c.client.Delete(). + Namespace(c.ns). + Resource("rulechecks"). + Name(name). + Body(&opts). + Do(ctx). + Error() +} + +// DeleteCollection deletes a collection of objects. +func (c *ruleChecks) 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(). + Namespace(c.ns). + Resource("rulechecks"). + VersionedParams(&listOpts, scheme.ParameterCodec). + Timeout(timeout). + Body(&opts). + Do(ctx). + Error() +} + +// Patch applies the patch and returns the patched ruleCheck. +func (c *ruleChecks) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.RuleCheck, err error) { + result = &v1.RuleCheck{} + err = c.client.Patch(pt). + Namespace(c.ns). + Resource("rulechecks"). + Name(name). + SubResource(subresources...). + VersionedParams(&opts, scheme.ParameterCodec). + Body(data). + Do(ctx). + Into(result) + return +} diff --git a/pkg/generated/informers/externalversions/caelus/interface.go b/pkg/generated/informers/externalversions/caelus/interface.go new file mode 100644 index 00000000..fc3afb4a --- /dev/null +++ b/pkg/generated/informers/externalversions/caelus/interface.go @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2021 THL A29 Limited, a Tencent company. + * + * 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 caelus + +import ( + v1 "github.com/tencent/caelus/pkg/generated/informers/externalversions/caelus/v1" + internalinterfaces "github.com/tencent/caelus/pkg/generated/informers/externalversions/internalinterfaces" +) + +// Interface provides access to each of this group's versions. +type Interface interface { + // V1 provides access to shared informers for resources in V1. + V1() v1.Interface +} + +type group struct { + factory internalinterfaces.SharedInformerFactory + namespace string + tweakListOptions internalinterfaces.TweakListOptionsFunc +} + +// New returns a new Interface. +func New(f internalinterfaces.SharedInformerFactory, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) Interface { + return &group{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} +} + +// V1 returns a new v1.Interface. +func (g *group) V1() v1.Interface { + return v1.New(g.factory, g.namespace, g.tweakListOptions) +} diff --git a/pkg/generated/informers/externalversions/caelus/v1/interface.go b/pkg/generated/informers/externalversions/caelus/v1/interface.go new file mode 100644 index 00000000..c76140d2 --- /dev/null +++ b/pkg/generated/informers/externalversions/caelus/v1/interface.go @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2021 THL A29 Limited, a Tencent company. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * + * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// Code generated by informer-gen. DO NOT EDIT. + +package v1 + +import ( + internalinterfaces "github.com/tencent/caelus/pkg/generated/informers/externalversions/internalinterfaces" +) + +// Interface provides access to all the informers in this group version. +type Interface interface { + // RuleChecks returns a RuleCheckInformer. + RuleChecks() RuleCheckInformer +} + +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} +} + +// RuleChecks returns a RuleCheckInformer. +func (v *version) RuleChecks() RuleCheckInformer { + return &ruleCheckInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} +} diff --git a/pkg/generated/informers/externalversions/caelus/v1/rulecheck.go b/pkg/generated/informers/externalversions/caelus/v1/rulecheck.go new file mode 100644 index 00000000..9c7b7fa7 --- /dev/null +++ b/pkg/generated/informers/externalversions/caelus/v1/rulecheck.go @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2021 THL A29 Limited, a Tencent company. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * + * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// Code generated by informer-gen. DO NOT EDIT. + +package v1 + +import ( + "context" + time "time" + + caelusv1 "github.com/tencent/caelus/pkg/apis/caelus/v1" + versioned "github.com/tencent/caelus/pkg/generated/clientset/versioned" + internalinterfaces "github.com/tencent/caelus/pkg/generated/informers/externalversions/internalinterfaces" + v1 "github.com/tencent/caelus/pkg/generated/listers/caelus/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + watch "k8s.io/apimachinery/pkg/watch" + cache "k8s.io/client-go/tools/cache" +) + +// RuleCheckInformer provides access to a shared informer and lister for +// RuleChecks. +type RuleCheckInformer interface { + Informer() cache.SharedIndexInformer + Lister() v1.RuleCheckLister +} + +type ruleCheckInformer struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc + namespace string +} + +// NewRuleCheckInformer constructs a new informer for RuleCheck 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 NewRuleCheckInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return NewFilteredRuleCheckInformer(client, namespace, resyncPeriod, indexers, nil) +} + +// NewFilteredRuleCheckInformer constructs a new informer for RuleCheck 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 NewFilteredRuleCheckInformer(client versioned.Interface, namespace string, 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.CaelusV1().RuleChecks(namespace).List(context.TODO(), options) + }, + WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.CaelusV1().RuleChecks(namespace).Watch(context.TODO(), options) + }, + }, + &caelusv1.RuleCheck{}, + resyncPeriod, + indexers, + ) +} + +func (f *ruleCheckInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewFilteredRuleCheckInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) +} + +func (f *ruleCheckInformer) Informer() cache.SharedIndexInformer { + return f.factory.InformerFor(&caelusv1.RuleCheck{}, f.defaultInformer) +} + +func (f *ruleCheckInformer) Lister() v1.RuleCheckLister { + return v1.NewRuleCheckLister(f.Informer().GetIndexer()) +} diff --git a/pkg/generated/informers/externalversions/factory.go b/pkg/generated/informers/externalversions/factory.go new file mode 100644 index 00000000..240dc7fa --- /dev/null +++ b/pkg/generated/informers/externalversions/factory.go @@ -0,0 +1,178 @@ +/* + * Copyright (c) 2021 THL A29 Limited, a Tencent company. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * + * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// Code generated by informer-gen. DO NOT EDIT. + +package externalversions + +import ( + reflect "reflect" + sync "sync" + time "time" + + versioned "github.com/tencent/caelus/pkg/generated/clientset/versioned" + caelus "github.com/tencent/caelus/pkg/generated/informers/externalversions/caelus" + internalinterfaces "github.com/tencent/caelus/pkg/generated/informers/externalversions/internalinterfaces" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + schema "k8s.io/apimachinery/pkg/runtime/schema" + cache "k8s.io/client-go/tools/cache" +) + +// SharedInformerOption defines the functional option type for SharedInformerFactory. +type SharedInformerOption func(*sharedInformerFactory) *sharedInformerFactory + +type sharedInformerFactory struct { + client versioned.Interface + namespace string + tweakListOptions internalinterfaces.TweakListOptionsFunc + lock sync.Mutex + defaultResync time.Duration + customResync map[reflect.Type]time.Duration + + 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 +} + +// 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 +} + +// Start initializes all requested informers. +func (f *sharedInformerFactory) Start(stopCh <-chan struct{}) { + f.lock.Lock() + defer f.lock.Unlock() + + for informerType, informer := range f.informers { + if !f.startedInformers[informerType] { + go informer.Run(stopCh) + f.startedInformers[informerType] = true + } + } +} + +// WaitForCacheSync waits for all started informers' cache were synced. +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. +type SharedInformerFactory interface { + internalinterfaces.SharedInformerFactory + ForResource(resource schema.GroupVersionResource) (GenericInformer, error) + WaitForCacheSync(stopCh <-chan struct{}) map[reflect.Type]bool + + Caelus() caelus.Interface +} + +func (f *sharedInformerFactory) Caelus() caelus.Interface { + return caelus.New(f, f.namespace, f.tweakListOptions) +} diff --git a/pkg/generated/informers/externalversions/generic.go b/pkg/generated/informers/externalversions/generic.go new file mode 100644 index 00000000..7a5a210f --- /dev/null +++ b/pkg/generated/informers/externalversions/generic.go @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2021 THL A29 Limited, a Tencent company. + * + * 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" + + v1 "github.com/tencent/caelus/pkg/apis/caelus/v1" + schema "k8s.io/apimachinery/pkg/runtime/schema" + cache "k8s.io/client-go/tools/cache" +) + +// GenericInformer is type of SharedIndexInformer which will locate and delegate to other +// sharedInformers based on type +type GenericInformer interface { + Informer() cache.SharedIndexInformer + Lister() cache.GenericLister +} + +type genericInformer struct { + informer cache.SharedIndexInformer + resource schema.GroupResource +} + +// Informer returns the SharedIndexInformer. +func (f *genericInformer) Informer() cache.SharedIndexInformer { + return f.informer +} + +// Lister returns the GenericLister. +func (f *genericInformer) Lister() cache.GenericLister { + return cache.NewGenericLister(f.Informer().GetIndexer(), f.resource) +} + +// ForResource gives generic access to a shared informer of the matching type +// TODO extend this to unknown resources with a client pool +func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource) (GenericInformer, error) { + switch resource { + // Group=caelus, Version=v1 + case v1.SchemeGroupVersion.WithResource("rulechecks"): + return &genericInformer{resource: resource.GroupResource(), informer: f.Caelus().V1().RuleChecks().Informer()}, nil + + } + + return nil, fmt.Errorf("no informer found for %v", resource) +} diff --git a/pkg/generated/informers/externalversions/internalinterfaces/factory_interfaces.go b/pkg/generated/informers/externalversions/internalinterfaces/factory_interfaces.go new file mode 100644 index 00000000..8865fb04 --- /dev/null +++ b/pkg/generated/informers/externalversions/internalinterfaces/factory_interfaces.go @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2021 THL A29 Limited, a Tencent company. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * + * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// Code generated by informer-gen. DO NOT EDIT. + +package internalinterfaces + +import ( + time "time" + + versioned "github.com/tencent/caelus/pkg/generated/clientset/versioned" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + cache "k8s.io/client-go/tools/cache" +) + +// NewInformerFunc takes versioned.Interface and time.Duration to return a SharedIndexInformer. +type NewInformerFunc func(versioned.Interface, time.Duration) cache.SharedIndexInformer + +// SharedInformerFactory a small interface to allow for adding an informer without an import cycle +type SharedInformerFactory interface { + Start(stopCh <-chan struct{}) + InformerFor(obj runtime.Object, newFunc NewInformerFunc) cache.SharedIndexInformer +} + +// TweakListOptionsFunc is a function that transforms a v1.ListOptions. +type TweakListOptionsFunc func(*v1.ListOptions) diff --git a/pkg/generated/listers/caelus/v1/expansion_generated.go b/pkg/generated/listers/caelus/v1/expansion_generated.go new file mode 100644 index 00000000..11f1e75d --- /dev/null +++ b/pkg/generated/listers/caelus/v1/expansion_generated.go @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2021 THL A29 Limited, a Tencent company. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * + * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// Code generated by lister-gen. DO NOT EDIT. + +package v1 + +// RuleCheckListerExpansion allows custom methods to be added to +// RuleCheckLister. +type RuleCheckListerExpansion interface{} + +// RuleCheckNamespaceListerExpansion allows custom methods to be added to +// RuleCheckNamespaceLister. +type RuleCheckNamespaceListerExpansion interface{} diff --git a/pkg/generated/listers/caelus/v1/rulecheck.go b/pkg/generated/listers/caelus/v1/rulecheck.go new file mode 100644 index 00000000..f9e5c68b --- /dev/null +++ b/pkg/generated/listers/caelus/v1/rulecheck.go @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2021 THL A29 Limited, a Tencent company. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * + * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// Code generated by lister-gen. DO NOT EDIT. + +package v1 + +import ( + v1 "github.com/tencent/caelus/pkg/apis/caelus/v1" + "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/tools/cache" +) + +// RuleCheckLister helps list RuleChecks. +// All objects returned here must be treated as read-only. +type RuleCheckLister interface { + // List lists all RuleChecks in the indexer. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*v1.RuleCheck, err error) + // RuleChecks returns an object that can list and get RuleChecks. + RuleChecks(namespace string) RuleCheckNamespaceLister + RuleCheckListerExpansion +} + +// ruleCheckLister implements the RuleCheckLister interface. +type ruleCheckLister struct { + indexer cache.Indexer +} + +// NewRuleCheckLister returns a new RuleCheckLister. +func NewRuleCheckLister(indexer cache.Indexer) RuleCheckLister { + return &ruleCheckLister{indexer: indexer} +} + +// List lists all RuleChecks in the indexer. +func (s *ruleCheckLister) List(selector labels.Selector) (ret []*v1.RuleCheck, err error) { + err = cache.ListAll(s.indexer, selector, func(m interface{}) { + ret = append(ret, m.(*v1.RuleCheck)) + }) + return ret, err +} + +// RuleChecks returns an object that can list and get RuleChecks. +func (s *ruleCheckLister) RuleChecks(namespace string) RuleCheckNamespaceLister { + return ruleCheckNamespaceLister{indexer: s.indexer, namespace: namespace} +} + +// RuleCheckNamespaceLister helps list and get RuleChecks. +// All objects returned here must be treated as read-only. +type RuleCheckNamespaceLister interface { + // List lists all RuleChecks in the indexer for a given namespace. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*v1.RuleCheck, err error) + // Get retrieves the RuleCheck from the indexer for a given namespace and name. + // Objects returned here must be treated as read-only. + Get(name string) (*v1.RuleCheck, error) + RuleCheckNamespaceListerExpansion +} + +// ruleCheckNamespaceLister implements the RuleCheckNamespaceLister +// interface. +type ruleCheckNamespaceLister struct { + indexer cache.Indexer + namespace string +} + +// List lists all RuleChecks in the indexer for a given namespace. +func (s ruleCheckNamespaceLister) List(selector labels.Selector) (ret []*v1.RuleCheck, err error) { + err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { + ret = append(ret, m.(*v1.RuleCheck)) + }) + return ret, err +} + +// Get retrieves the RuleCheck from the indexer for a given namespace and name. +func (s ruleCheckNamespaceLister) Get(name string) (*v1.RuleCheck, error) { + obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) + if err != nil { + return nil, err + } + if !exists { + return nil, errors.NewNotFound(v1.Resource("rulecheck"), name) + } + return obj.(*v1.RuleCheck), nil +} From 280b2329d7a69672e35d38d8f599bfc0f6b0641f Mon Sep 17 00:00:00 2001 From: wang-mask <2018091609006@std.uestc.edu.cn> Date: Mon, 11 Mar 2024 21:09:00 +0800 Subject: [PATCH 02/59] init the framework Signed-off-by: wang-mask <2018091609006@std.uestc.edu.cn> --- cmd/caelus/app/server.go | 9 ++-- cmd/caelus/context/context.go | 5 +- pkg/caelus/healthcheck/health_check.go | 72 ++++++++++++-------------- 3 files changed, 43 insertions(+), 43 deletions(-) diff --git a/cmd/caelus/app/server.go b/cmd/caelus/app/server.go index ab03f29f..2ada1d31 100644 --- a/cmd/caelus/app/server.go +++ b/cmd/caelus/app/server.go @@ -244,9 +244,12 @@ func (o *options) initModules(caelus *types.CaelusConfig, ctx *context.CaelusCon o.ApiOption.loadStatsMetric(metrics.StatsMetricDiskQuota, diskquotaManager) } // health check manager - healthCheckManager = health.NewHealthManager(types.InitHealthCheckConfigFunc(&caelus.Metrics.Node, - &caelus.Predicts[0].ReserveResource), stStore, resourceManager, qosManager, - conflictMn, podInformer) + // xxInformer := ctx.GetxxxFactory() + // healthCheckManager = health.NewHealthManager(types.InitHealthCheckConfigFunc(&caelus.Metrics.Node, + // &caelus.Predicts[0].ReserveResource), stStore, resourceManager, qosManager, + // conflictMn, podInformer, xxInformer1, xxInformer2, kubeClient) + healthCheckManager = health.NewHealthManager(stStore, resourceManager, qosManager, + conflictMn, podInformer, ctx.GetKubeClient()) modules = append(modules, healthCheckManager) return modules diff --git a/cmd/caelus/context/context.go b/cmd/caelus/context/context.go index 8982d808..304d8297 100644 --- a/cmd/caelus/context/context.go +++ b/cmd/caelus/context/context.go @@ -33,7 +33,7 @@ type CaelusContext struct { Kubeconfig string NodeName string kubeClient clientset.Interface - nodeFactory, podFactory informers.SharedInformerFactory + nodeFactory, podFactory informers.SharedInformerFactory // TODO add xxx informers } const ( @@ -90,6 +90,8 @@ func (c *CaelusContext) GetNodeFactory() informers.SharedInformerFactory { return c.nodeFactory } +// TODO add GetxxxxFactory returns xxx factory + // Name module name func (c *CaelusContext) Name() string { return "ModuleContext" @@ -105,4 +107,5 @@ func (c *CaelusContext) Run(stop <-chan struct{}) { c.nodeFactory.Start(stop) c.nodeFactory.WaitForCacheSync(stop) } + // TODO run xx informers } diff --git a/pkg/caelus/healthcheck/health_check.go b/pkg/caelus/healthcheck/health_check.go index a1dd08c0..c610704b 100644 --- a/pkg/caelus/healthcheck/health_check.go +++ b/pkg/caelus/healthcheck/health_check.go @@ -31,6 +31,7 @@ import ( "github.com/tencent/caelus/pkg/caelus/statestore" "github.com/tencent/caelus/pkg/caelus/types" "github.com/tencent/caelus/pkg/caelus/util" + clientset "k8s.io/client-go/kubernetes" "k8s.io/client-go/tools/cache" "k8s.io/klog/v2" ) @@ -50,41 +51,34 @@ type manager struct { config *types.HealthCheckConfig ruleChecker *rulecheck.Manager // support linux kernel PSI, now just memory event - cgroupNotifier notify.ResourceNotify - stStore statestore.StateStore - resource resource.Interface - qosManager qos.Manager - conflictMn conflict.Manager - podInformer cache.SharedIndexInformer - configUpdateFunc func(string) (*types.HealthCheckConfig, error) - configHash string - globalStopCh <-chan struct{} + cgroupNotifier notify.ResourceNotify + stStore statestore.StateStore + resource resource.Interface + qosManager qos.Manager + conflictMn conflict.Manager + podInformer cache.SharedIndexInformer + configHash string + globalStopCh <-chan struct{} + // xxxInformer1 + // xxxInformer2 + k8sClient clientset.Interface } // NewHealthManager create a new health check manager -func NewHealthManager(configFunc func(string) (*types.HealthCheckConfig, error), stStore statestore.StateStore, +func NewHealthManager(stStore statestore.StateStore, resource resource.Interface, qosManager qos.Manager, conflictMn conflict.Manager, - podInformer cache.SharedIndexInformer) Manager { - config, err := configFunc(checkConfigFile) - if err != nil { - klog.Fatalf("failed init health check config: %v", err) - } - hash, err := hashFile(checkConfigFile) - if err != nil { - klog.Fatal(err) - } + podInformer cache.SharedIndexInformer, k8sClient clientset.Interface) Manager { + + // TODO add the informer enent func + hm := &manager{ - config: config, - configUpdateFunc: configFunc, - stStore: stStore, - resource: resource, - qosManager: qosManager, - conflictMn: conflictMn, - podInformer: podInformer, - ruleChecker: rulecheck.NewManager(config.RuleCheck, stStore, resource, qosManager, conflictMn, - podInformer, config.PredictReserved), - cgroupNotifier: notify.NewNotifyManager(&config.CgroupNotify, resource), - configHash: hash, + stStore: stStore, + resource: resource, + qosManager: qosManager, + conflictMn: conflictMn, + podInformer: podInformer, + k8sClient: k8sClient, + // add informer } return hm @@ -144,16 +138,8 @@ func (h *manager) checkNeedReload(configFile string) (bool, string, *types.Healt // Run start checking health func (h *manager) Run(stop <-chan struct{}) { - if h.config.Disable { - klog.Warningf("health check is disabled") - return - } h.globalStopCh = stop - - klog.V(2).Infof("health manager running") - go h.ruleChecker.Run(stop) - go h.cgroupNotifier.Run(stop) - go h.configWatcher(stop) + <-stop } // configWatcher support reload rule check config dynamically, no need to restart the agent @@ -194,3 +180,11 @@ func hashFile(filePath string) (string, error) { hs := hex.EncodeToString(h) return hs, nil } + +func (h *manager) updateRulecheck() { + +} + +func (h *manager) updateCgroupNotifier() { + +} From 885177d02c04b290225a473493a72d8c06653b4a Mon Sep 17 00:00:00 2001 From: baowj Date: Tue, 12 Mar 2024 16:56:25 +0800 Subject: [PATCH 03/59] Update rulecheck CRD 1.update rulecheck CRD 2.add rulecheck clientset and factory to CaelusContext Signed-off-by: baowj --- cmd/caelus/context/context.go | 68 +++++++++++++++++---- pkg/apis/caelus/v1/rulecheck_types.go | 20 +++--- pkg/apis/caelus/v1/zz_generated.deepcopy.go | 22 +------ 3 files changed, 70 insertions(+), 40 deletions(-) diff --git a/cmd/caelus/context/context.go b/cmd/caelus/context/context.go index 8982d808..2b998f7c 100644 --- a/cmd/caelus/context/context.go +++ b/cmd/caelus/context/context.go @@ -18,22 +18,29 @@ package context import ( "time" + caelusclient "github.com/tencent/caelus/pkg/generated/clientset/versioned" + caelusfake "github.com/tencent/caelus/pkg/generated/clientset/versioned/fake" + caelusinformers "github.com/tencent/caelus/pkg/generated/informers/externalversions" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/fields" "k8s.io/client-go/informers" clientset "k8s.io/client-go/kubernetes" "k8s.io/client-go/kubernetes/fake" + "k8s.io/client-go/rest" "k8s.io/client-go/tools/clientcmd" "k8s.io/klog/v2" ) -// CaelusContext stores k8s client and factory +// CaelusContext stores k8s&caelus client and factory type CaelusContext struct { Master string Kubeconfig string NodeName string kubeClient clientset.Interface + caelusClient caelusclient.Interface nodeFactory, podFactory informers.SharedInformerFactory + ruleCheckFactory caelusinformers.SharedInformerFactory } const ( @@ -45,17 +52,35 @@ const ( // lazyInit build kubernetes client func (c *CaelusContext) lazyInit() { - if c.kubeClient != nil { - return + var kubeconfig *rest.Config = nil + var err error + if c.kubeClient == nil { + kubeconfig, err = clientcmd.BuildConfigFromFlags(c.Master, c.Kubeconfig) + if err != nil { + klog.Warning(err) + klog.Warning("fall back to creating fake kube-client") + // create a fake client to test caelus without k8s + c.kubeClient = fake.NewSimpleClientset() + } else { + c.kubeClient = clientset.NewForConfigOrDie(kubeconfig) + } + } - kubeconfig, err := clientcmd.BuildConfigFromFlags(c.Master, c.Kubeconfig) - if err != nil { - klog.Warning(err) - klog.Warning("fall back to creating fake kube-client") - // create a fake client to test caelus without k8s - c.kubeClient = fake.NewSimpleClientset() - } else { - c.kubeClient = clientset.NewForConfigOrDie(kubeconfig) + + // init caelus client + if c.caelusClient == nil { + err = nil + if kubeconfig == nil { + kubeconfig, err = clientcmd.BuildConfigFromFlags(c.Master, c.Kubeconfig) + } + if err != nil { + klog.Warning(err) + klog.Warning("fall back to creating fake caelus-client") + // create a fake client to test caelus without k8s + c.caelusClient = caelusfake.NewSimpleClientset() + } else { + c.caelusClient = caelusclient.NewForConfigOrDie(kubeconfig) + } } } @@ -65,6 +90,12 @@ func (c *CaelusContext) GetKubeClient() clientset.Interface { return c.kubeClient } +// GetCaelusClient returns caelus client +func (c *CaelusContext) GetCaelusClient() caelusclient.Interface { + c.lazyInit() + return c.caelusClient +} + // GetPodFactory returns pod factory func (c *CaelusContext) GetPodFactory() informers.SharedInformerFactory { if c.podFactory == nil { @@ -79,6 +110,17 @@ func (c *CaelusContext) GetPodFactory() informers.SharedInformerFactory { return c.podFactory } +// GetRuleCheckFactory returns ruleCheck factory +func (c *CaelusContext) GetRuleCheckFactory() caelusinformers.SharedInformerFactory { + if c.ruleCheckFactory == nil { + c.ruleCheckFactory = caelusinformers.NewSharedInformerFactoryWithOptions(c.GetCaelusClient(), informerSyncPeriod, + caelusinformers.WithTweakListOptions(func(options *metav1.ListOptions) { + options.FieldSelector = fields.OneTermEqualSelector(nodeNameField, c.NodeName).String() + })) + } + return c.ruleCheckFactory +} + // GetNodeFactory returns node factory func (c *CaelusContext) GetNodeFactory() informers.SharedInformerFactory { if c.nodeFactory == nil { @@ -105,4 +147,8 @@ func (c *CaelusContext) Run(stop <-chan struct{}) { c.nodeFactory.Start(stop) c.nodeFactory.WaitForCacheSync(stop) } + if c.ruleCheckFactory != nil { + c.ruleCheckFactory.Start(stop) + c.ruleCheckFactory.WaitForCacheSync(stop) + } } diff --git a/pkg/apis/caelus/v1/rulecheck_types.go b/pkg/apis/caelus/v1/rulecheck_types.go index f25fc852..b58becfc 100644 --- a/pkg/apis/caelus/v1/rulecheck_types.go +++ b/pkg/apis/caelus/v1/rulecheck_types.go @@ -17,10 +17,20 @@ package v1 import ( "encoding/json" + "github.com/tencent/caelus/pkg/util/times" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) +type RuleCheckType string + +const ( + AppType RuleCheckType = "app" + NodeType RuleCheckType = "node" + ContainerType RuleCheckType = "container" +) + // +genclient // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object @@ -37,7 +47,8 @@ type RuleCheck struct { type RuleCheckSpec struct { NodeSelector map[string]string `json:"nodeSelector"` - Metrics []string `json:"metrics"` + Type RuleCheckType `json:"type"` + Metrics []string `json:"metrics"` // CheckInterval describes the interval to trigger detection CheckInterval *times.Duration `json:"checkInterval"` // HandleInterval describes the interval to handle conflicts after detecting abnormal result @@ -61,15 +72,8 @@ type DetectAction struct { Args json.RawMessage `json:"args"` } -// ActionConfig define action config -type ActionConfig struct { - Name string `json:"name"` - Args json.RawMessage `json:"args"` -} - // RuleCheckStatus is the status for a RuleCheck resource type RuleCheckStatus struct { - AvailableReplicas int32 `json:"availableReplicas"` } // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object diff --git a/pkg/apis/caelus/v1/zz_generated.deepcopy.go b/pkg/apis/caelus/v1/zz_generated.deepcopy.go index d6315943..3061a3cd 100644 --- a/pkg/apis/caelus/v1/zz_generated.deepcopy.go +++ b/pkg/apis/caelus/v1/zz_generated.deepcopy.go @@ -23,30 +23,10 @@ import ( json "encoding/json" times "github.com/tencent/caelus/pkg/util/times" + 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 *ActionConfig) DeepCopyInto(out *ActionConfig) { - *out = *in - if in.Args != nil { - in, out := &in.Args, &out.Args - *out = make(json.RawMessage, len(*in)) - copy(*out, *in) - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ActionConfig. -func (in *ActionConfig) DeepCopy() *ActionConfig { - if in == nil { - return nil - } - out := new(ActionConfig) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *DetectAction) DeepCopyInto(out *DetectAction) { *out = *in From dab565fd40a51431b6a58111d071d67ba290a649 Mon Sep 17 00:00:00 2001 From: wang-mask <2018091609006@std.uestc.edu.cn> Date: Tue, 12 Mar 2024 19:00:08 +0800 Subject: [PATCH 04/59] add label field to the rulecheck and cgroupnofity config filed Signed-off-by: wang-mask <2018091609006@std.uestc.edu.cn> --- pkg/caelus/types/health_check.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pkg/caelus/types/health_check.go b/pkg/caelus/types/health_check.go index e889f9d0..ff1aead8 100644 --- a/pkg/caelus/types/health_check.go +++ b/pkg/caelus/types/health_check.go @@ -91,7 +91,6 @@ type EWMAArgs struct { // HealthCheckConfig is the config for checking health, such as node load or online job interference type HealthCheckConfig struct { Disable bool `json:"disable"` - RuleNodes []string `json:"rule_nodes"` RuleCheck RuleCheck `json:"rule_check"` CgroupNotify NotifyConfig `json:"cgroup_notify"` // assign the value when initialize @@ -107,8 +106,9 @@ type RuleCheck struct { // RuleCheckConfig define the rule config type RuleCheckConfig struct { - Name string `json:"name"` - Metrics []string `json:"metrics"` + Name string `json:"name"` + Metrics []string `json:"metrics"` + Labels map[string]string `json:"labels"` // CheckInterval describes the interval to trigger detection CheckInterval times.Duration `json:"check_interval"` // HandleInterval describes the interval to handle conflicts after detecting abnormal result @@ -142,6 +142,7 @@ type ActionConfig struct { // NotifyConfig monitor resource by kernel notify type NotifyConfig struct { MemoryCgroup *MemoryNotifyConfig `json:"memory_cgroup"` + Labels map[string]string `json:"labels"` } // MemoryNotifyConfig describe memory cgroup notify From 5bbfad35e1209767430063e002e890997fd31905 Mon Sep 17 00:00:00 2001 From: wang-mask <2018091609006@std.uestc.edu.cn> Date: Tue, 12 Mar 2024 19:00:54 +0800 Subject: [PATCH 05/59] add update rulecheck and cgroupnotify func Signed-off-by: wang-mask <2018091609006@std.uestc.edu.cn> --- pkg/caelus/healthcheck/health_check.go | 231 +++++++++++------- .../healthcheck/rulecheck/rule_check.go | 18 +- 2 files changed, 161 insertions(+), 88 deletions(-) diff --git a/pkg/caelus/healthcheck/health_check.go b/pkg/caelus/healthcheck/health_check.go index c610704b..cefc508d 100644 --- a/pkg/caelus/healthcheck/health_check.go +++ b/pkg/caelus/healthcheck/health_check.go @@ -16,13 +16,11 @@ package health import ( - "crypto/md5" - "encoding/hex" - "io" - "os" - "path/filepath" + "context" + "fmt" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "strings" - "github.com/fsnotify/fsnotify" "github.com/tencent/caelus/pkg/caelus/healthcheck/cgroupnotify" "github.com/tencent/caelus/pkg/caelus/healthcheck/conflict" "github.com/tencent/caelus/pkg/caelus/healthcheck/rulecheck" @@ -33,7 +31,6 @@ import ( "github.com/tencent/caelus/pkg/caelus/util" clientset "k8s.io/client-go/kubernetes" "k8s.io/client-go/tools/cache" - "k8s.io/klog/v2" ) const ( @@ -89,102 +86,162 @@ func (h *manager) Name() string { return "ModuleHealthCheck" } -// reload rule check config dynamically without restarting the agent -func (h *manager) reload() { - reload, hash, config := h.checkNeedReload(checkConfigFile) - if !reload { - return - } - h.configHash = hash - h.ruleChecker.Stop() - h.cgroupNotifier.Stop() - h.config = config - h.ruleChecker = rulecheck.NewManager(config.RuleCheck, h.stStore, h.resource, h.qosManager, h.conflictMn, - h.podInformer, config.PredictReserved) - h.cgroupNotifier = notify.NewNotifyManager(&config.CgroupNotify, h.resource) - go h.ruleChecker.Run(h.globalStopCh) - go h.cgroupNotifier.Run(h.globalStopCh) +//// reload rule check config dynamically without restarting the agent +//func (h *manager) reload() { +// reload, hash, config := h.checkNeedReload(checkConfigFile) +// if !reload { +// return +// } +// h.configHash = hash +// h.ruleChecker.Stop() +// h.cgroupNotifier.Stop() +// h.config = config +// h.ruleChecker = rulecheck.NewManager(config.RuleCheck, h.stStore, h.resource, h.qosManager, h.conflictMn, +// h.podInformer, config.PredictReserved) +// h.cgroupNotifier = notify.NewNotifyManager(&config.CgroupNotify, h.resource) +// go h.ruleChecker.Run(h.globalStopCh) +// go h.cgroupNotifier.Run(h.globalStopCh) +//} + +//// checkNeedReload checks if the config file is changed +//func (h *manager) checkNeedReload(configFile string) (bool, string, *types.HealthCheckConfig) { +// hash, err := hashFile(configFile) +// if err != nil { +// klog.Errorf("failed hash config file: %v", err) +// return false, "", nil +// } +// if hash == h.configHash { +// return false, "", nil +// } +// config, err := h.configUpdateFunc(configFile) +// if err != nil { +// klog.Fatalf("failed init health check config: %v", err) +// } +// if len(config.RuleNodes) != 0 { +// found := false +// for _, no := range config.RuleNodes { +// if no == util.NodeIP() { +// found = true +// break +// } +// } +// if !found { +// return false, "", nil +// } +// } +// +// return true, hash, config +//} + +// Run start checking health +func (h *manager) Run(stop <-chan struct{}) { + // the function is running in the informer evnet func + h.globalStopCh = stop } -// checkNeedReload checks if the config file is changed -func (h *manager) checkNeedReload(configFile string) (bool, string, *types.HealthCheckConfig) { - hash, err := hashFile(configFile) - if err != nil { - klog.Errorf("failed hash config file: %v", err) - return false, "", nil - } - if hash == h.configHash { - return false, "", nil - } - config, err := h.configUpdateFunc(configFile) +//// configWatcher support reload rule check config dynamically, no need to restart the agent +//func (h *manager) configWatcher(stop <-chan struct{}) { +// w, err := fsnotify.NewWatcher() +// if err != nil { +// klog.Fatalf("failed init fsnotify watcher: %v", err) +// } +// defer w.Close() +// err = w.Add(filepath.Dir(checkConfigFile)) +// if err != nil { +// klog.Fatalf("failed add dir watcher(%s): %v", filepath.Dir(checkConfigFile), err) +// } +// for { +// select { +// case <-w.Events: +// h.reload() +// case err := <-w.Errors: +// klog.Errorf("fsnotify error: %v", err) +// case <-stop: +// return +// } +// } +//} +// +//// hashFile generate hash code for the file +//func hashFile(filePath string) (string, error) { +// file, err := os.Open(filePath) +// if err != nil { +// return "", err +// } +// defer file.Close() +// hash := md5.New() +// if _, err = io.Copy(hash, file); err != nil { +// return "", err +// } +// h := hash.Sum(nil)[:16] +// hs := hex.EncodeToString(h) +// return hs, nil +//} + +// updateRuleCheck update the ruleChecker by the config +func (h *manager) updateRuleCheck() error { + matched, err := h.isLabelMatched(h.config.CgroupNotify.Labels) if err != nil { - klog.Fatalf("failed init health check config: %v", err) + return err } - if len(config.RuleNodes) != 0 { - found := false - for _, no := range config.RuleNodes { - if no == util.NodeIP() { - found = true - break - } + + if matched { + h.ruleChecker.UpdateManager(h.config.RuleCheck, h.stStore, h.podInformer, h.config.PredictReserved) + if h.ruleChecker == nil { + h.ruleChecker.Run(h.globalStopCh) } - if !found { - return false, "", nil + } else { + if h.ruleChecker != nil { + h.ruleChecker.Stop() + h.ruleChecker = nil } } - - return true, hash, config -} - -// Run start checking health -func (h *manager) Run(stop <-chan struct{}) { - h.globalStopCh = stop - <-stop + return nil } -// configWatcher support reload rule check config dynamically, no need to restart the agent -func (h *manager) configWatcher(stop <-chan struct{}) { - w, err := fsnotify.NewWatcher() - if err != nil { - klog.Fatalf("failed init fsnotify watcher: %v", err) - } - defer w.Close() - err = w.Add(filepath.Dir(checkConfigFile)) +// updateCgroupNotifier update the cgroupNotifier by the config +func (h *manager) updateCgroupNotifier() error { + matched, err := h.isLabelMatched(h.config.CgroupNotify.Labels) if err != nil { - klog.Fatalf("failed add dir watcher(%s): %v", filepath.Dir(checkConfigFile), err) + return err } - for { - select { - case <-w.Events: - h.reload() - case err := <-w.Errors: - klog.Errorf("fsnotify error: %v", err) - case <-stop: - return + + if matched { + if h.cgroupNotifier != nil { + // in case the cgroupNotifier is not enabled in last update + h.cgroupNotifier.Stop() + } + h.cgroupNotifier = notify.NewNotifyManager(&h.config.CgroupNotify, h.resource) + go h.cgroupNotifier.Run(h.globalStopCh) + } else { + if h.cgroupNotifier != nil { + // if the labels does not match this node, stop the cgroupNotifier + h.cgroupNotifier.Stop() + h.cgroupNotifier = nil } } + return nil } -// hashFile generate hash code for the file -func hashFile(filePath string) (string, error) { - file, err := os.Open(filePath) +// isLabelMatched determines whether the labels match this node +func (h *manager) isLabelMatched(labels map[string]string) (bool, error) { + if len(labels) == 0 { + return true, nil + } + selectors := make([]string, len(labels)) + index := 0 + for key, val := range labels { + selectors[index] = fmt.Sprintf("%s=%s", key, val) + index += 1 + } + nodes, err := h.k8sClient.CoreV1().Nodes().List(context.TODO(), metav1.ListOptions{LabelSelector: strings.Join(selectors, ",")}) if err != nil { - return "", err + return false, err } - defer file.Close() - hash := md5.New() - if _, err = io.Copy(hash, file); err != nil { - return "", err + for _, node := range nodes.Items { + if node.Name == util.NodeName() { + return true, nil + } } - h := hash.Sum(nil)[:16] - hs := hex.EncodeToString(h) - return hs, nil -} - -func (h *manager) updateRulecheck() { - -} - -func (h *manager) updateCgroupNotifier() { - + return false, nil } diff --git a/pkg/caelus/healthcheck/rulecheck/rule_check.go b/pkg/caelus/healthcheck/rulecheck/rule_check.go index 38ee51c3..f907d10f 100644 --- a/pkg/caelus/healthcheck/rulecheck/rule_check.go +++ b/pkg/caelus/healthcheck/rulecheck/rule_check.go @@ -45,7 +45,8 @@ type Manager struct { checkers []ruleChecker dispatcher *dispatcher.Dispatcher - stopCh chan struct{} + stopCh chan struct{} + rwMutex sync.RWMutex } // NewManager return a new rule check manager @@ -78,6 +79,7 @@ func (r *Manager) Run(stopCh <-chan struct{}) { return default: } + r.rwMutex.RLock() wg := sync.WaitGroup{} finalAC := &action.ActionResult{ UnscheduleMap: make(map[string]bool), @@ -98,6 +100,7 @@ func (r *Manager) Run(stopCh <-chan struct{}) { }() } wg.Wait() + r.rwMutex.RUnlock() // no need dispatch result when action is useless if actionResultAvailable(finalAC) { @@ -128,3 +131,16 @@ func actionResultAvailable(ac *action.ActionResult) bool { return false } + +func (r *Manager) UpdateManager(config types.RuleCheck, stStore statestore.StateStore, podInformer cache.SharedIndexInformer, + predictReserved *types.Resource) { + r.rwMutex.Lock() + defer r.rwMutex.Unlock() + + var checkers []ruleChecker + checkers = append(checkers, newContainerHealthChecker(stStore, podInformer, config.ContainerRules)) + checkers = append(checkers, newNodeHealthChecker(stStore, predictReserved, config.NodeRules)) + checkers = append(checkers, newAppHealthChecker(stStore, config.AppRules)) + + r.checkers = checkers +} From 4780e16f8afcc50372b1dce8bcd540de4a8e5874 Mon Sep 17 00:00:00 2001 From: baowj Date: Wed, 13 Mar 2024 10:48:04 +0800 Subject: [PATCH 06/59] add rulecheck crd yaml Signed-off-by: baowj --- .../bases/tencent.caelus.io_rulechecks.yaml | 179 ++++++++++++++++++ 1 file changed, 179 insertions(+) create mode 100644 config/crd/bases/tencent.caelus.io_rulechecks.yaml diff --git a/config/crd/bases/tencent.caelus.io_rulechecks.yaml b/config/crd/bases/tencent.caelus.io_rulechecks.yaml new file mode 100644 index 00000000..41bd1cdd --- /dev/null +++ b/config/crd/bases/tencent.caelus.io_rulechecks.yaml @@ -0,0 +1,179 @@ +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: v0.14.0 + name: rulechecks.caelus.io.tencent +spec: + group: caelus.io.tencent + names: + kind: RuleCheck + listKind: RuleCheckList + plural: rulechecks + singular: rulecheck + scope: Namespaced + versions: + - name: v1 + schema: + openAPIV3Schema: + description: RuleCheck is the Schema for the rulechecks API + properties: + apiVersion: + description: |- + APIVersion defines the versioned schema of this representation of an object. + Servers should convert recognized schemas to the latest internal value, and + may reject unrecognized values. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources + type: string + kind: + description: |- + Kind is a string value representing the REST resource this object represents. + Servers may infer this from the endpoint the client submits requests to. + Cannot be updated. + In CamelCase. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds + type: string + metadata: + type: object + spec: + description: RuleCheckSpec defines the desired state of RuleCheck + properties: + checkInterval: + description: CheckInterval describes the interval to trigger detection + format: int64 + type: integer + handleInterval: + description: HandleInterval describes the interval to handle conflicts + after detecting abnormal result + format: int64 + type: integer + metrics: + items: + type: string + type: array + nodeSelector: + additionalProperties: + type: string + description: |- + INSERT ADDITIONAL SPEC FIELDS - desired state of cluster + Important: Run "make" to regenerate code after modifying this file + type: object + recoverInterval: + description: RecoverInterval describes the interval to recover conflicts + after detecting normal result + format: int64 + type: integer + recoverRules: + items: + description: DetectActionRules define detectors and actions + properties: + actions: + items: + description: DetectAction define detector config + properties: + args: + description: |- + RawMessage is a raw encoded JSON value. + It implements Marshaler and Unmarshaler and can + be used to delay JSON decoding or precompute a JSON encoding. + format: byte + type: string + name: + type: string + required: + - args + - name + type: object + type: array + detects: + items: + description: DetectAction define detector config + properties: + args: + description: |- + RawMessage is a raw encoded JSON value. + It implements Marshaler and Unmarshaler and can + be used to delay JSON decoding or precompute a JSON encoding. + format: byte + type: string + name: + type: string + required: + - args + - name + type: object + type: array + required: + - actions + - detects + type: object + type: array + rules: + items: + description: DetectActionRules define detectors and actions + properties: + actions: + items: + description: DetectAction define detector config + properties: + args: + description: |- + RawMessage is a raw encoded JSON value. + It implements Marshaler and Unmarshaler and can + be used to delay JSON decoding or precompute a JSON encoding. + format: byte + type: string + name: + type: string + required: + - args + - name + type: object + type: array + detects: + items: + description: DetectAction define detector config + properties: + args: + description: |- + RawMessage is a raw encoded JSON value. + It implements Marshaler and Unmarshaler and can + be used to delay JSON decoding or precompute a JSON encoding. + format: byte + type: string + name: + type: string + required: + - args + - name + type: object + type: array + required: + - actions + - detects + type: object + type: array + type: + enum: + - app + - node + - container + type: string + required: + - checkInterval + - handleInterval + - metrics + - nodeSelector + - recoverInterval + - rules + - type + type: object + status: + description: RuleCheckStatus defines the observed state of RuleCheck + type: object + type: object + served: true + storage: true + subresources: + status: {} From f56b787a8347847fad1a1f6221d1a5de04769eb0 Mon Sep 17 00:00:00 2001 From: wang-mask <2018091609006@std.uestc.edu.cn> Date: Wed, 13 Mar 2024 19:42:16 +0800 Subject: [PATCH 07/59] fix update bug Signed-off-by: wang-mask <2018091609006@std.uestc.edu.cn> --- cmd/caelus/context/context.go | 3 +-- pkg/caelus/healthcheck/health_check.go | 4 +++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/cmd/caelus/context/context.go b/cmd/caelus/context/context.go index 13bfa466..07627921 100644 --- a/cmd/caelus/context/context.go +++ b/cmd/caelus/context/context.go @@ -41,8 +41,7 @@ type CaelusContext struct { caelusClient caelusclient.Interface nodeFactory, podFactory informers.SharedInformerFactory ruleCheckFactory caelusinformers.SharedInformerFactory - nodeFactory, podFactory informers.SharedInformerFactory - // TODO add xxx informers + // TODO add xxx informers } diff --git a/pkg/caelus/healthcheck/health_check.go b/pkg/caelus/healthcheck/health_check.go index cefc508d..b9b8ab58 100644 --- a/pkg/caelus/healthcheck/health_check.go +++ b/pkg/caelus/healthcheck/health_check.go @@ -186,9 +186,11 @@ func (h *manager) updateRuleCheck() error { } if matched { - h.ruleChecker.UpdateManager(h.config.RuleCheck, h.stStore, h.podInformer, h.config.PredictReserved) if h.ruleChecker == nil { + h.ruleChecker = rulecheck.NewManager(h.config.RuleCheck, h.stStore, h.resource, h.qosManager, h.conflictMn, h.podInformer, h.config.PredictReserved) h.ruleChecker.Run(h.globalStopCh) + } else { + h.ruleChecker.UpdateManager(h.config.RuleCheck, h.stStore, h.podInformer, h.config.PredictReserved) } } else { if h.ruleChecker != nil { From ee063d5f64bed5ed81b1a827903bdc2f56db72b4 Mon Sep 17 00:00:00 2001 From: yanxiaoqi932 Date: Fri, 15 Mar 2024 00:22:47 +0800 Subject: [PATCH 08/59] cgroup merge init-framwork --- cmd/caelus/app/server.go | 6 +- cmd/caelus/context/context.go | 45 +++- pkg/apis/cgroupnotifycrd/register.go | 5 + pkg/apis/cgroupnotifycrd/v1/doc.go | 4 + pkg/apis/cgroupnotifycrd/v1/register.go | 39 ++++ pkg/apis/cgroupnotifycrd/v1/types.go | 65 ++++++ .../v1/zz_generated.deepcopy.go | 193 +++++++++++++++++ pkg/caelus/healthcheck/health_check.go | 97 ++++++++- .../clientset/versioned/clientset.go | 117 +++++++++++ pkg/cgroupClient/clientset/versioned/doc.go | 20 ++ .../versioned/fake/clientset_generated.go | 85 ++++++++ .../clientset/versioned/fake/doc.go | 20 ++ .../clientset/versioned/fake/register.go | 56 +++++ .../clientset/versioned/scheme/doc.go | 20 ++ .../clientset/versioned/scheme/register.go | 56 +++++ .../cgroupnotifycrd/v1/cgroupnotifycrd.go | 195 ++++++++++++++++++ .../v1/cgroupnotifycrd_client.go | 107 ++++++++++ .../versioned/typed/cgroupnotifycrd/v1/doc.go | 20 ++ .../typed/cgroupnotifycrd/v1/fake/doc.go | 20 ++ .../v1/fake/fake_cgroupnotifycrd.go | 142 +++++++++++++ .../v1/fake/fake_cgroupnotifycrd_client.go | 40 ++++ .../cgroupnotifycrd/v1/generated_expansion.go | 21 ++ .../cgroupnotifycrd/interface.go | 46 +++++ .../cgroupnotifycrd/v1/cgroupnotifycrd.go | 90 ++++++++ .../cgroupnotifycrd/v1/interface.go | 45 ++++ .../informers/externalversions/factory.go | 180 ++++++++++++++++ .../informers/externalversions/generic.go | 62 ++++++ .../internalinterfaces/factory_interfaces.go | 40 ++++ .../cgroupnotifycrd/v1/cgroupnotifycrd.go | 99 +++++++++ .../cgroupnotifycrd/v1/expansion_generated.go | 27 +++ 30 files changed, 1956 insertions(+), 6 deletions(-) create mode 100644 pkg/apis/cgroupnotifycrd/register.go create mode 100644 pkg/apis/cgroupnotifycrd/v1/doc.go create mode 100644 pkg/apis/cgroupnotifycrd/v1/register.go create mode 100644 pkg/apis/cgroupnotifycrd/v1/types.go create mode 100644 pkg/apis/cgroupnotifycrd/v1/zz_generated.deepcopy.go create mode 100644 pkg/cgroupClient/clientset/versioned/clientset.go create mode 100644 pkg/cgroupClient/clientset/versioned/doc.go create mode 100644 pkg/cgroupClient/clientset/versioned/fake/clientset_generated.go create mode 100644 pkg/cgroupClient/clientset/versioned/fake/doc.go create mode 100644 pkg/cgroupClient/clientset/versioned/fake/register.go create mode 100644 pkg/cgroupClient/clientset/versioned/scheme/doc.go create mode 100644 pkg/cgroupClient/clientset/versioned/scheme/register.go create mode 100644 pkg/cgroupClient/clientset/versioned/typed/cgroupnotifycrd/v1/cgroupnotifycrd.go create mode 100644 pkg/cgroupClient/clientset/versioned/typed/cgroupnotifycrd/v1/cgroupnotifycrd_client.go create mode 100644 pkg/cgroupClient/clientset/versioned/typed/cgroupnotifycrd/v1/doc.go create mode 100644 pkg/cgroupClient/clientset/versioned/typed/cgroupnotifycrd/v1/fake/doc.go create mode 100644 pkg/cgroupClient/clientset/versioned/typed/cgroupnotifycrd/v1/fake/fake_cgroupnotifycrd.go create mode 100644 pkg/cgroupClient/clientset/versioned/typed/cgroupnotifycrd/v1/fake/fake_cgroupnotifycrd_client.go create mode 100644 pkg/cgroupClient/clientset/versioned/typed/cgroupnotifycrd/v1/generated_expansion.go create mode 100644 pkg/cgroupClient/informers/externalversions/cgroupnotifycrd/interface.go create mode 100644 pkg/cgroupClient/informers/externalversions/cgroupnotifycrd/v1/cgroupnotifycrd.go create mode 100644 pkg/cgroupClient/informers/externalversions/cgroupnotifycrd/v1/interface.go create mode 100644 pkg/cgroupClient/informers/externalversions/factory.go create mode 100644 pkg/cgroupClient/informers/externalversions/generic.go create mode 100644 pkg/cgroupClient/informers/externalversions/internalinterfaces/factory_interfaces.go create mode 100644 pkg/cgroupClient/listers/cgroupnotifycrd/v1/cgroupnotifycrd.go create mode 100644 pkg/cgroupClient/listers/cgroupnotifycrd/v1/expansion_generated.go diff --git a/cmd/caelus/app/server.go b/cmd/caelus/app/server.go index 2ada1d31..b9443577 100644 --- a/cmd/caelus/app/server.go +++ b/cmd/caelus/app/server.go @@ -24,7 +24,7 @@ import ( "github.com/tencent/caelus/pkg/caelus/checkpoint" "github.com/tencent/caelus/pkg/caelus/cpi" "github.com/tencent/caelus/pkg/caelus/diskquota" - "github.com/tencent/caelus/pkg/caelus/healthcheck" + health "github.com/tencent/caelus/pkg/caelus/healthcheck" "github.com/tencent/caelus/pkg/caelus/healthcheck/conflict" "github.com/tencent/caelus/pkg/caelus/metrics" "github.com/tencent/caelus/pkg/caelus/online" @@ -248,8 +248,10 @@ func (o *options) initModules(caelus *types.CaelusConfig, ctx *context.CaelusCon // healthCheckManager = health.NewHealthManager(types.InitHealthCheckConfigFunc(&caelus.Metrics.Node, // &caelus.Predicts[0].ReserveResource), stStore, resourceManager, qosManager, // conflictMn, podInformer, xxInformer1, xxInformer2, kubeClient) + cgroupFactory := ctx.GetCgroupNotifyFactory() + cgroupNotifyInformer := cgroupFactory.Cgroupnotifycrd().V1().CgroupNotifyCrds() healthCheckManager = health.NewHealthManager(stStore, resourceManager, qosManager, - conflictMn, podInformer, ctx.GetKubeClient()) + conflictMn, podInformer, cgroupNotifyInformer, ctx.GetKubeClient()) modules = append(modules, healthCheckManager) return modules diff --git a/cmd/caelus/context/context.go b/cmd/caelus/context/context.go index 13bfa466..945cd637 100644 --- a/cmd/caelus/context/context.go +++ b/cmd/caelus/context/context.go @@ -18,6 +18,9 @@ package context import ( "time" + cgroupclient "github.com/tencent/caelus/pkg/cgroupClient/clientset/versioned" + cgroupfake "github.com/tencent/caelus/pkg/cgroupClient/clientset/versioned/fake" + cgroupInformers "github.com/tencent/caelus/pkg/cgroupClient/informers/externalversions" caelusclient "github.com/tencent/caelus/pkg/generated/clientset/versioned" caelusfake "github.com/tencent/caelus/pkg/generated/clientset/versioned/fake" caelusinformers "github.com/tencent/caelus/pkg/generated/informers/externalversions" @@ -39,10 +42,11 @@ type CaelusContext struct { NodeName string kubeClient clientset.Interface caelusClient caelusclient.Interface + cgroupNotifyClient cgroupclient.Interface nodeFactory, podFactory informers.SharedInformerFactory ruleCheckFactory caelusinformers.SharedInformerFactory - nodeFactory, podFactory informers.SharedInformerFactory - // TODO add xxx informers + cgroupNotifyFactory cgroupInformers.SharedInformerFactory + // TODO add xxx informers } @@ -85,6 +89,22 @@ func (c *CaelusContext) lazyInit() { c.caelusClient = caelusclient.NewForConfigOrDie(kubeconfig) } } + + // init cgroupnotifycrd client + if c.cgroupNotifyClient == nil { + err = nil + if kubeconfig == nil { + kubeconfig, err = clientcmd.BuildConfigFromFlags(c.Master, c.Kubeconfig) + } + if err != nil { + klog.Warning(err) + klog.Warning("fall back to creating fake caelus-client") + // create a fake client to test caelus without k8s + c.cgroupNotifyClient = cgroupfake.NewSimpleClientset() + } else { + c.cgroupNotifyClient = cgroupclient.NewForConfigOrDie(kubeconfig) + } + } } // GetKubeClient returns k8s client @@ -99,6 +119,12 @@ func (c *CaelusContext) GetCaelusClient() caelusclient.Interface { return c.caelusClient } +// GetCaelusClient returns CgroupNotify client +func (c *CaelusContext) GetCgroupNotifyClient() cgroupclient.Interface { + c.lazyInit() + return c.cgroupNotifyClient +} + // GetPodFactory returns pod factory func (c *CaelusContext) GetPodFactory() informers.SharedInformerFactory { if c.podFactory == nil { @@ -124,6 +150,17 @@ func (c *CaelusContext) GetRuleCheckFactory() caelusinformers.SharedInformerFact return c.ruleCheckFactory } +// GetRuleCheckFactory returns cgroupnotify factory +func (c *CaelusContext) GetCgroupNotifyFactory() cgroupInformers.SharedInformerFactory { + if c.cgroupNotifyFactory == nil { + c.cgroupNotifyFactory = cgroupInformers.NewSharedInformerFactoryWithOptions(c.GetCgroupNotifyClient(), informerSyncPeriod, + cgroupInformers.WithTweakListOptions(func(options *metav1.ListOptions) { + options.FieldSelector = fields.OneTermEqualSelector(nodeNameField, c.NodeName).String() + })) + } + return c.cgroupNotifyFactory +} + // GetNodeFactory returns node factory func (c *CaelusContext) GetNodeFactory() informers.SharedInformerFactory { if c.nodeFactory == nil { @@ -156,5 +193,9 @@ func (c *CaelusContext) Run(stop <-chan struct{}) { c.ruleCheckFactory.Start(stop) c.ruleCheckFactory.WaitForCacheSync(stop) } + if c.cgroupNotifyFactory != nil { + c.cgroupNotifyFactory.Start(stop) + c.cgroupNotifyFactory.WaitForCacheSync(stop) + } // TODO run xx informers } diff --git a/pkg/apis/cgroupnotifycrd/register.go b/pkg/apis/cgroupnotifycrd/register.go new file mode 100644 index 00000000..b9d699da --- /dev/null +++ b/pkg/apis/cgroupnotifycrd/register.go @@ -0,0 +1,5 @@ +package cgroupnotifycontroller + +const ( + GroupName = "cgroupnotifycrd" +) diff --git a/pkg/apis/cgroupnotifycrd/v1/doc.go b/pkg/apis/cgroupnotifycrd/v1/doc.go new file mode 100644 index 00000000..37249499 --- /dev/null +++ b/pkg/apis/cgroupnotifycrd/v1/doc.go @@ -0,0 +1,4 @@ +// +k8s:deepcopy-gen=package +// +groupName=cgroupnotifycrd + +package v1 diff --git a/pkg/apis/cgroupnotifycrd/v1/register.go b/pkg/apis/cgroupnotifycrd/v1/register.go new file mode 100644 index 00000000..d52efa84 --- /dev/null +++ b/pkg/apis/cgroupnotifycrd/v1/register.go @@ -0,0 +1,39 @@ +package v1 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/schema" + + cgroupnotifycontroller "github.com/tencent/caelus/pkg/apis/cgroupnotifycrd" +) + +// SchemeGroupVersion is group version used to register these objects +var SchemeGroupVersion = schema.GroupVersion{Group: cgroupnotifycontroller.GroupName, Version: "v1"} + +// Kind takes an unqualified kind and returns back a Group qualified GroupKind +func Kind(kind string) schema.GroupKind { + return SchemeGroupVersion.WithKind(kind).GroupKind() +} + +// 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, + &CgroupNotifyCrd{}, + &CgroupNotifyCrdList{}, + ) + metav1.AddToGroupVersion(scheme, SchemeGroupVersion) + return nil +} diff --git a/pkg/apis/cgroupnotifycrd/v1/types.go b/pkg/apis/cgroupnotifycrd/v1/types.go new file mode 100644 index 00000000..b489e82e --- /dev/null +++ b/pkg/apis/cgroupnotifycrd/v1/types.go @@ -0,0 +1,65 @@ +package v1 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + + "github.com/tencent/caelus/pkg/util/times" +) + +// +genclient +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// CgroupNotifyCrd is a specification for a CgroupNotifyCrd resource +type CgroupNotifyCrd struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + + Spec CgroupNotifyCrdSpec `json:"spec"` + Status CgroupNotifyCrdStatus `json:"status"` +} + +// CgroupNotifyCrdSpec is the spec for a CgroupNotifyCrd resource +type CgroupNotifyCrdSpec struct { + MemoryCgroup MemoryNotifyConfig `json:"memory_cgroup"` + NodeSelector metav1.LabelSelector `json:"nodeSelector"` +} + +// MemoryNotifyConfig describe memory cgroup notify +type MemoryNotifyConfig struct { + Pressures []MemoryPressureNotifyConfig `json:"pressures"` + Usages []MemoryUsageNotifyConfig `json:"usages"` +} + +// MemoryPressureNotifyConfig describe memory.pressure_level notify data +type MemoryPressureNotifyConfig struct { + Cgroups []string `json:"cgroups"` + PressureLevel string `json:"pressure_level"` + // assign time duration the pressure has kept + Duration times.Duration `json:"duration"` + // assign event number in the duration time + Count int `json:"count"` +} + +// MemoryUsageNotifyConfig describe memory.usage_in_bytes notify data +type MemoryUsageNotifyConfig struct { + Cgroups []string `json:"cgroups"` + // the distance between limit and threshold + MarginMb int `json:"margin_mb"` + // when to handle event after receiving event + Duration times.Duration `json:"duration"` +} + +// CgroupNotifyCrdStatus is the status for a CgroupNotifyCrd resource +type CgroupNotifyCrdStatus struct { + AvailableReplicas int32 `json:"availableReplicas"` +} + +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// CgroupNotifyCrdList is a list of CgroupNotifyCrd resources +type CgroupNotifyCrdList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata"` + + Items []CgroupNotifyCrd `json:"items"` +} diff --git a/pkg/apis/cgroupnotifycrd/v1/zz_generated.deepcopy.go b/pkg/apis/cgroupnotifycrd/v1/zz_generated.deepcopy.go new file mode 100644 index 00000000..4edbef8c --- /dev/null +++ b/pkg/apis/cgroupnotifycrd/v1/zz_generated.deepcopy.go @@ -0,0 +1,193 @@ +//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 v1 + +import ( + runtime "k8s.io/apimachinery/pkg/runtime" +) + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *CgroupNotifyCrd) DeepCopyInto(out *CgroupNotifyCrd) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) + out.Status = in.Status + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CgroupNotifyCrd. +func (in *CgroupNotifyCrd) DeepCopy() *CgroupNotifyCrd { + if in == nil { + return nil + } + out := new(CgroupNotifyCrd) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *CgroupNotifyCrd) 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 *CgroupNotifyCrdList) DeepCopyInto(out *CgroupNotifyCrdList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]CgroupNotifyCrd, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CgroupNotifyCrdList. +func (in *CgroupNotifyCrdList) DeepCopy() *CgroupNotifyCrdList { + if in == nil { + return nil + } + out := new(CgroupNotifyCrdList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *CgroupNotifyCrdList) 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 *CgroupNotifyCrdSpec) DeepCopyInto(out *CgroupNotifyCrdSpec) { + *out = *in + in.MemoryCgroup.DeepCopyInto(&out.MemoryCgroup) + in.NodeSelector.DeepCopyInto(&out.NodeSelector) + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CgroupNotifyCrdSpec. +func (in *CgroupNotifyCrdSpec) DeepCopy() *CgroupNotifyCrdSpec { + if in == nil { + return nil + } + out := new(CgroupNotifyCrdSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *CgroupNotifyCrdStatus) DeepCopyInto(out *CgroupNotifyCrdStatus) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CgroupNotifyCrdStatus. +func (in *CgroupNotifyCrdStatus) DeepCopy() *CgroupNotifyCrdStatus { + if in == nil { + return nil + } + out := new(CgroupNotifyCrdStatus) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *MemoryNotifyConfig) DeepCopyInto(out *MemoryNotifyConfig) { + *out = *in + if in.Pressures != nil { + in, out := &in.Pressures, &out.Pressures + *out = make([]MemoryPressureNotifyConfig, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + if in.Usages != nil { + in, out := &in.Usages, &out.Usages + *out = make([]MemoryUsageNotifyConfig, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MemoryNotifyConfig. +func (in *MemoryNotifyConfig) DeepCopy() *MemoryNotifyConfig { + if in == nil { + return nil + } + out := new(MemoryNotifyConfig) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *MemoryPressureNotifyConfig) DeepCopyInto(out *MemoryPressureNotifyConfig) { + *out = *in + if in.Cgroups != nil { + in, out := &in.Cgroups, &out.Cgroups + *out = make([]string, len(*in)) + copy(*out, *in) + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MemoryPressureNotifyConfig. +func (in *MemoryPressureNotifyConfig) DeepCopy() *MemoryPressureNotifyConfig { + if in == nil { + return nil + } + out := new(MemoryPressureNotifyConfig) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *MemoryUsageNotifyConfig) DeepCopyInto(out *MemoryUsageNotifyConfig) { + *out = *in + if in.Cgroups != nil { + in, out := &in.Cgroups, &out.Cgroups + *out = make([]string, len(*in)) + copy(*out, *in) + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MemoryUsageNotifyConfig. +func (in *MemoryUsageNotifyConfig) DeepCopy() *MemoryUsageNotifyConfig { + if in == nil { + return nil + } + out := new(MemoryUsageNotifyConfig) + in.DeepCopyInto(out) + return out +} diff --git a/pkg/caelus/healthcheck/health_check.go b/pkg/caelus/healthcheck/health_check.go index c610704b..178bf967 100644 --- a/pkg/caelus/healthcheck/health_check.go +++ b/pkg/caelus/healthcheck/health_check.go @@ -16,6 +16,7 @@ package health import ( + "context" "crypto/md5" "encoding/hex" "io" @@ -23,7 +24,8 @@ import ( "path/filepath" "github.com/fsnotify/fsnotify" - "github.com/tencent/caelus/pkg/caelus/healthcheck/cgroupnotify" + cgroupCrd "github.com/tencent/caelus/pkg/apis/cgroupnotifycrd/v1" + notify "github.com/tencent/caelus/pkg/caelus/healthcheck/cgroupnotify" "github.com/tencent/caelus/pkg/caelus/healthcheck/conflict" "github.com/tencent/caelus/pkg/caelus/healthcheck/rulecheck" "github.com/tencent/caelus/pkg/caelus/qos" @@ -31,6 +33,9 @@ import ( "github.com/tencent/caelus/pkg/caelus/statestore" "github.com/tencent/caelus/pkg/caelus/types" "github.com/tencent/caelus/pkg/caelus/util" + cgroupInformer "github.com/tencent/caelus/pkg/cgroupClient/informers/externalversions/cgroupnotifycrd/v1" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" clientset "k8s.io/client-go/kubernetes" "k8s.io/client-go/tools/cache" "k8s.io/klog/v2" @@ -60,6 +65,7 @@ type manager struct { configHash string globalStopCh <-chan struct{} // xxxInformer1 + cgroupInformer cgroupInformer.CgroupNotifyCrdInformer // xxxInformer2 k8sClient clientset.Interface } @@ -67,7 +73,8 @@ type manager struct { // NewHealthManager create a new health check manager func NewHealthManager(stStore statestore.StateStore, resource resource.Interface, qosManager qos.Manager, conflictMn conflict.Manager, - podInformer cache.SharedIndexInformer, k8sClient clientset.Interface) Manager { + podInformer cache.SharedIndexInformer, cgroupInformer cgroupInformer.CgroupNotifyCrdInformer, + k8sClient clientset.Interface) Manager { // TODO add the informer enent func @@ -79,8 +86,15 @@ func NewHealthManager(stStore statestore.StateStore, podInformer: podInformer, k8sClient: k8sClient, // add informer + cgroupInformer: cgroupInformer, } + hm.cgroupInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{ + AddFunc: hm.OnAddCgropNotify, + UpdateFunc: hm.OnUpdateCgropNotify, + DeleteFunc: hm.OnDeleteCgropNotify, + }) + return hm } @@ -181,6 +195,21 @@ func hashFile(filePath string) (string, error) { return hs, nil } +func (h *manager) OnAddCgropNotify(obj interface{}) { + h.updateCgroupConfig(obj, false) + h.updateCgroupNotifier() +} + +func (h *manager) OnUpdateCgropNotify(oldObj, newObj interface{}) { + h.updateCgroupConfig(newObj, false) + h.updateCgroupNotifier() +} + +func (h *manager) OnDeleteCgropNotify(obj interface{}) { + h.updateCgroupConfig(obj, true) + h.updateCgroupNotifier() +} + func (h *manager) updateRulecheck() { } @@ -188,3 +217,67 @@ func (h *manager) updateRulecheck() { func (h *manager) updateCgroupNotifier() { } + +func (h *manager) HasNode(cgroupCrd *cgroupCrd.CgroupNotifyCrd) (bool, error) { + nodeSelector := cgroupCrd.Spec.NodeSelector + nodes, err := h.k8sClient.CoreV1().Nodes().List(context.TODO(), metav1.ListOptions{ + LabelSelector: metav1.FormatLabelSelector(&nodeSelector), + }) + if err != nil { + return false, err + } + + found := false + for _, n := range nodes.Items { + if n.Name == util.NodeName() { + found = true + break + } + } + return found, nil +} + +func (h *manager) CgroupCrddeepCopy(cgroupCrd *cgroupCrd.CgroupNotifyCrd) { + pressures := make([]types.MemoryPressureNotifyConfig, 0) + for _, p := range cgroupCrd.Spec.MemoryCgroup.Pressures { + newP := types.MemoryPressureNotifyConfig{} + newP.Cgroups = p.Cgroups + newP.Count = p.Count + newP.Duration = p.Duration + newP.PressureLevel = p.PressureLevel + pressures = append(pressures, newP) + } + usages := make([]types.MemoryUsageNotifyConfig, 0) + for _, u := range cgroupCrd.Spec.MemoryCgroup.Usages { + newU := types.MemoryUsageNotifyConfig{} + newU.Cgroups = u.Cgroups + newU.Duration = u.Duration + newU.MarginMb = u.MarginMb + usages = append(usages, newU) + } + h.config.CgroupNotify.MemoryCgroup.Pressures = pressures + h.config.CgroupNotify.MemoryCgroup.Usages = usages +} + +func (h *manager) updateCgroupConfig(obj interface{}, isDelete bool) { + object := obj.(metav1.Object) + ownerRef := metav1.GetControllerOf(object) + cgroupCrd, err := h.cgroupInformer.Lister().CgroupNotifyCrds(object.GetNamespace()).Get(ownerRef.Name) + if err != nil { + klog.Error("get cgroupNotifyCrd failed") + return + } + found, err := h.HasNode(cgroupCrd) + if err != nil { + klog.Error("get Nodes failed: %v", err) + return + } + if !found { + return + } + if isDelete { + h.config.CgroupNotify = types.NotifyConfig{} + } else { + h.CgroupCrddeepCopy(cgroupCrd) + } +} diff --git a/pkg/cgroupClient/clientset/versioned/clientset.go b/pkg/cgroupClient/clientset/versioned/clientset.go new file mode 100644 index 00000000..6c47b9bb --- /dev/null +++ b/pkg/cgroupClient/clientset/versioned/clientset.go @@ -0,0 +1,117 @@ +/* +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" + + cgroupnotifycrdv1 "github.com/tencent/caelus/pkg/cgroupClient/clientset/versioned/typed/cgroupnotifycrd/v1" + discovery "k8s.io/client-go/discovery" + rest "k8s.io/client-go/rest" + flowcontrol "k8s.io/client-go/util/flowcontrol" +) + +type Interface interface { + Discovery() discovery.DiscoveryInterface + CgroupnotifycrdV1() cgroupnotifycrdv1.CgroupnotifycrdV1Interface +} + +// Clientset contains the clients for groups. Each group has exactly one +// version included in a Clientset. +type Clientset struct { + *discovery.DiscoveryClient + cgroupnotifycrdV1 *cgroupnotifycrdv1.CgroupnotifycrdV1Client +} + +// CgroupnotifycrdV1 retrieves the CgroupnotifycrdV1Client +func (c *Clientset) CgroupnotifycrdV1() cgroupnotifycrdv1.CgroupnotifycrdV1Interface { + return c.cgroupnotifycrdV1 +} + +// 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 + + // 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.cgroupnotifycrdV1, err = cgroupnotifycrdv1.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.cgroupnotifycrdV1 = cgroupnotifycrdv1.New(c) + + cs.DiscoveryClient = discovery.NewDiscoveryClient(c) + return &cs +} diff --git a/pkg/cgroupClient/clientset/versioned/doc.go b/pkg/cgroupClient/clientset/versioned/doc.go new file mode 100644 index 00000000..41721ca5 --- /dev/null +++ b/pkg/cgroupClient/clientset/versioned/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 clientset. +package versioned diff --git a/pkg/cgroupClient/clientset/versioned/fake/clientset_generated.go b/pkg/cgroupClient/clientset/versioned/fake/clientset_generated.go new file mode 100644 index 00000000..8f7e9ea4 --- /dev/null +++ b/pkg/cgroupClient/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 ( + clientset "github.com/tencent/caelus/pkg/cgroupClient/clientset/versioned" + cgroupnotifycrdv1 "github.com/tencent/caelus/pkg/cgroupClient/clientset/versioned/typed/cgroupnotifycrd/v1" + fakecgroupnotifycrdv1 "github.com/tencent/caelus/pkg/cgroupClient/clientset/versioned/typed/cgroupnotifycrd/v1/fake" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/watch" + "k8s.io/client-go/discovery" + fakediscovery "k8s.io/client-go/discovery/fake" + "k8s.io/client-go/testing" +) + +// NewSimpleClientset returns a clientset that will respond with the provided objects. +// It's backed by a very simple object tracker that processes creates, updates and deletions as-is, +// without applying any validations and/or defaults. It shouldn't be considered a replacement +// for a real clientset and is mostly useful in simple unit tests. +func NewSimpleClientset(objects ...runtime.Object) *Clientset { + o := testing.NewObjectTracker(scheme, codecs.UniversalDecoder()) + for _, obj := range objects { + if err := o.Add(obj); err != nil { + panic(err) + } + } + + cs := &Clientset{tracker: o} + cs.discovery = &fakediscovery.FakeDiscovery{Fake: &cs.Fake} + cs.AddReactor("*", "*", testing.ObjectReaction(o)) + cs.AddWatchReactor("*", func(action testing.Action) (handled bool, ret watch.Interface, err error) { + gvr := action.GetResource() + ns := action.GetNamespace() + watch, err := o.Watch(gvr, ns) + if err != nil { + return false, nil, err + } + return true, watch, nil + }) + + return cs +} + +// Clientset implements clientset.Interface. Meant to be embedded into a +// struct to get a default implementation. This makes faking out just the method +// you want to test easier. +type Clientset struct { + testing.Fake + discovery *fakediscovery.FakeDiscovery + tracker testing.ObjectTracker +} + +func (c *Clientset) Discovery() discovery.DiscoveryInterface { + return c.discovery +} + +func (c *Clientset) Tracker() testing.ObjectTracker { + return c.tracker +} + +var ( + _ clientset.Interface = &Clientset{} + _ testing.FakeClient = &Clientset{} +) + +// CgroupnotifycrdV1 retrieves the CgroupnotifycrdV1Client +func (c *Clientset) CgroupnotifycrdV1() cgroupnotifycrdv1.CgroupnotifycrdV1Interface { + return &fakecgroupnotifycrdv1.FakeCgroupnotifycrdV1{Fake: &c.Fake} +} diff --git a/pkg/cgroupClient/clientset/versioned/fake/doc.go b/pkg/cgroupClient/clientset/versioned/fake/doc.go new file mode 100644 index 00000000..9b99e716 --- /dev/null +++ b/pkg/cgroupClient/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/cgroupClient/clientset/versioned/fake/register.go b/pkg/cgroupClient/clientset/versioned/fake/register.go new file mode 100644 index 00000000..bd2f297c --- /dev/null +++ b/pkg/cgroupClient/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 ( + cgroupnotifycrdv1 "github.com/tencent/caelus/pkg/apis/cgroupnotifycrd/v1" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + schema "k8s.io/apimachinery/pkg/runtime/schema" + serializer "k8s.io/apimachinery/pkg/runtime/serializer" + utilruntime "k8s.io/apimachinery/pkg/util/runtime" +) + +var scheme = runtime.NewScheme() +var codecs = serializer.NewCodecFactory(scheme) + +var localSchemeBuilder = runtime.SchemeBuilder{ + cgroupnotifycrdv1.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/cgroupClient/clientset/versioned/scheme/doc.go b/pkg/cgroupClient/clientset/versioned/scheme/doc.go new file mode 100644 index 00000000..7dc37561 --- /dev/null +++ b/pkg/cgroupClient/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/cgroupClient/clientset/versioned/scheme/register.go b/pkg/cgroupClient/clientset/versioned/scheme/register.go new file mode 100644 index 00000000..b25da229 --- /dev/null +++ b/pkg/cgroupClient/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 ( + cgroupnotifycrdv1 "github.com/tencent/caelus/pkg/apis/cgroupnotifycrd/v1" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + schema "k8s.io/apimachinery/pkg/runtime/schema" + serializer "k8s.io/apimachinery/pkg/runtime/serializer" + utilruntime "k8s.io/apimachinery/pkg/util/runtime" +) + +var Scheme = runtime.NewScheme() +var Codecs = serializer.NewCodecFactory(Scheme) +var ParameterCodec = runtime.NewParameterCodec(Scheme) +var localSchemeBuilder = runtime.SchemeBuilder{ + cgroupnotifycrdv1.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/cgroupClient/clientset/versioned/typed/cgroupnotifycrd/v1/cgroupnotifycrd.go b/pkg/cgroupClient/clientset/versioned/typed/cgroupnotifycrd/v1/cgroupnotifycrd.go new file mode 100644 index 00000000..63f75d71 --- /dev/null +++ b/pkg/cgroupClient/clientset/versioned/typed/cgroupnotifycrd/v1/cgroupnotifycrd.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 v1 + +import ( + "context" + "time" + + v1 "github.com/tencent/caelus/pkg/apis/cgroupnotifycrd/v1" + scheme "github.com/tencent/caelus/pkg/cgroupClient/clientset/versioned/scheme" + metav1 "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" +) + +// CgroupNotifyCrdsGetter has a method to return a CgroupNotifyCrdInterface. +// A group's client should implement this interface. +type CgroupNotifyCrdsGetter interface { + CgroupNotifyCrds(namespace string) CgroupNotifyCrdInterface +} + +// CgroupNotifyCrdInterface has methods to work with CgroupNotifyCrd resources. +type CgroupNotifyCrdInterface interface { + Create(ctx context.Context, cgroupNotifyCrd *v1.CgroupNotifyCrd, opts metav1.CreateOptions) (*v1.CgroupNotifyCrd, error) + Update(ctx context.Context, cgroupNotifyCrd *v1.CgroupNotifyCrd, opts metav1.UpdateOptions) (*v1.CgroupNotifyCrd, error) + UpdateStatus(ctx context.Context, cgroupNotifyCrd *v1.CgroupNotifyCrd, opts metav1.UpdateOptions) (*v1.CgroupNotifyCrd, 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.CgroupNotifyCrd, error) + List(ctx context.Context, opts metav1.ListOptions) (*v1.CgroupNotifyCrdList, 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.CgroupNotifyCrd, err error) + CgroupNotifyCrdExpansion +} + +// cgroupNotifyCrds implements CgroupNotifyCrdInterface +type cgroupNotifyCrds struct { + client rest.Interface + ns string +} + +// newCgroupNotifyCrds returns a CgroupNotifyCrds +func newCgroupNotifyCrds(c *CgroupnotifycrdV1Client, namespace string) *cgroupNotifyCrds { + return &cgroupNotifyCrds{ + client: c.RESTClient(), + ns: namespace, + } +} + +// Get takes name of the cgroupNotifyCrd, and returns the corresponding cgroupNotifyCrd object, and an error if there is any. +func (c *cgroupNotifyCrds) Get(ctx context.Context, name string, options metav1.GetOptions) (result *v1.CgroupNotifyCrd, err error) { + result = &v1.CgroupNotifyCrd{} + err = c.client.Get(). + Namespace(c.ns). + Resource("cgroupnotifycrds"). + Name(name). + VersionedParams(&options, scheme.ParameterCodec). + Do(ctx). + Into(result) + return +} + +// List takes label and field selectors, and returns the list of CgroupNotifyCrds that match those selectors. +func (c *cgroupNotifyCrds) List(ctx context.Context, opts metav1.ListOptions) (result *v1.CgroupNotifyCrdList, err error) { + var timeout time.Duration + if opts.TimeoutSeconds != nil { + timeout = time.Duration(*opts.TimeoutSeconds) * time.Second + } + result = &v1.CgroupNotifyCrdList{} + err = c.client.Get(). + Namespace(c.ns). + Resource("cgroupnotifycrds"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Do(ctx). + Into(result) + return +} + +// Watch returns a watch.Interface that watches the requested cgroupNotifyCrds. +func (c *cgroupNotifyCrds) 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(). + Namespace(c.ns). + Resource("cgroupnotifycrds"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Watch(ctx) +} + +// Create takes the representation of a cgroupNotifyCrd and creates it. Returns the server's representation of the cgroupNotifyCrd, and an error, if there is any. +func (c *cgroupNotifyCrds) Create(ctx context.Context, cgroupNotifyCrd *v1.CgroupNotifyCrd, opts metav1.CreateOptions) (result *v1.CgroupNotifyCrd, err error) { + result = &v1.CgroupNotifyCrd{} + err = c.client.Post(). + Namespace(c.ns). + Resource("cgroupnotifycrds"). + VersionedParams(&opts, scheme.ParameterCodec). + Body(cgroupNotifyCrd). + Do(ctx). + Into(result) + return +} + +// Update takes the representation of a cgroupNotifyCrd and updates it. Returns the server's representation of the cgroupNotifyCrd, and an error, if there is any. +func (c *cgroupNotifyCrds) Update(ctx context.Context, cgroupNotifyCrd *v1.CgroupNotifyCrd, opts metav1.UpdateOptions) (result *v1.CgroupNotifyCrd, err error) { + result = &v1.CgroupNotifyCrd{} + err = c.client.Put(). + Namespace(c.ns). + Resource("cgroupnotifycrds"). + Name(cgroupNotifyCrd.Name). + VersionedParams(&opts, scheme.ParameterCodec). + Body(cgroupNotifyCrd). + 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 *cgroupNotifyCrds) UpdateStatus(ctx context.Context, cgroupNotifyCrd *v1.CgroupNotifyCrd, opts metav1.UpdateOptions) (result *v1.CgroupNotifyCrd, err error) { + result = &v1.CgroupNotifyCrd{} + err = c.client.Put(). + Namespace(c.ns). + Resource("cgroupnotifycrds"). + Name(cgroupNotifyCrd.Name). + SubResource("status"). + VersionedParams(&opts, scheme.ParameterCodec). + Body(cgroupNotifyCrd). + Do(ctx). + Into(result) + return +} + +// Delete takes name of the cgroupNotifyCrd and deletes it. Returns an error if one occurs. +func (c *cgroupNotifyCrds) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { + return c.client.Delete(). + Namespace(c.ns). + Resource("cgroupnotifycrds"). + Name(name). + Body(&opts). + Do(ctx). + Error() +} + +// DeleteCollection deletes a collection of objects. +func (c *cgroupNotifyCrds) 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(). + Namespace(c.ns). + Resource("cgroupnotifycrds"). + VersionedParams(&listOpts, scheme.ParameterCodec). + Timeout(timeout). + Body(&opts). + Do(ctx). + Error() +} + +// Patch applies the patch and returns the patched cgroupNotifyCrd. +func (c *cgroupNotifyCrds) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.CgroupNotifyCrd, err error) { + result = &v1.CgroupNotifyCrd{} + err = c.client.Patch(pt). + Namespace(c.ns). + Resource("cgroupnotifycrds"). + Name(name). + SubResource(subresources...). + VersionedParams(&opts, scheme.ParameterCodec). + Body(data). + Do(ctx). + Into(result) + return +} diff --git a/pkg/cgroupClient/clientset/versioned/typed/cgroupnotifycrd/v1/cgroupnotifycrd_client.go b/pkg/cgroupClient/clientset/versioned/typed/cgroupnotifycrd/v1/cgroupnotifycrd_client.go new file mode 100644 index 00000000..ff573199 --- /dev/null +++ b/pkg/cgroupClient/clientset/versioned/typed/cgroupnotifycrd/v1/cgroupnotifycrd_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 v1 + +import ( + "net/http" + + v1 "github.com/tencent/caelus/pkg/apis/cgroupnotifycrd/v1" + "github.com/tencent/caelus/pkg/cgroupClient/clientset/versioned/scheme" + rest "k8s.io/client-go/rest" +) + +type CgroupnotifycrdV1Interface interface { + RESTClient() rest.Interface + CgroupNotifyCrdsGetter +} + +// CgroupnotifycrdV1Client is used to interact with features provided by the cgroupnotifycrd group. +type CgroupnotifycrdV1Client struct { + restClient rest.Interface +} + +func (c *CgroupnotifycrdV1Client) CgroupNotifyCrds(namespace string) CgroupNotifyCrdInterface { + return newCgroupNotifyCrds(c, namespace) +} + +// NewForConfig creates a new CgroupnotifycrdV1Client for the given config. +// NewForConfig is equivalent to NewForConfigAndClient(c, httpClient), +// where httpClient was generated with rest.HTTPClientFor(c). +func NewForConfig(c *rest.Config) (*CgroupnotifycrdV1Client, 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 CgroupnotifycrdV1Client 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) (*CgroupnotifycrdV1Client, 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 &CgroupnotifycrdV1Client{client}, nil +} + +// NewForConfigOrDie creates a new CgroupnotifycrdV1Client for the given config and +// panics if there is an error in the config. +func NewForConfigOrDie(c *rest.Config) *CgroupnotifycrdV1Client { + client, err := NewForConfig(c) + if err != nil { + panic(err) + } + return client +} + +// New creates a new CgroupnotifycrdV1Client for the given RESTClient. +func New(c rest.Interface) *CgroupnotifycrdV1Client { + return &CgroupnotifycrdV1Client{c} +} + +func setConfigDefaults(config *rest.Config) error { + gv := v1.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 *CgroupnotifycrdV1Client) RESTClient() rest.Interface { + if c == nil { + return nil + } + return c.restClient +} diff --git a/pkg/cgroupClient/clientset/versioned/typed/cgroupnotifycrd/v1/doc.go b/pkg/cgroupClient/clientset/versioned/typed/cgroupnotifycrd/v1/doc.go new file mode 100644 index 00000000..3af5d054 --- /dev/null +++ b/pkg/cgroupClient/clientset/versioned/typed/cgroupnotifycrd/v1/doc.go @@ -0,0 +1,20 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +// This package has the automatically generated typed clients. +package v1 diff --git a/pkg/cgroupClient/clientset/versioned/typed/cgroupnotifycrd/v1/fake/doc.go b/pkg/cgroupClient/clientset/versioned/typed/cgroupnotifycrd/v1/fake/doc.go new file mode 100644 index 00000000..16f44399 --- /dev/null +++ b/pkg/cgroupClient/clientset/versioned/typed/cgroupnotifycrd/v1/fake/doc.go @@ -0,0 +1,20 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +// Package fake has the automatically generated clients. +package fake diff --git a/pkg/cgroupClient/clientset/versioned/typed/cgroupnotifycrd/v1/fake/fake_cgroupnotifycrd.go b/pkg/cgroupClient/clientset/versioned/typed/cgroupnotifycrd/v1/fake/fake_cgroupnotifycrd.go new file mode 100644 index 00000000..a94308b7 --- /dev/null +++ b/pkg/cgroupClient/clientset/versioned/typed/cgroupnotifycrd/v1/fake/fake_cgroupnotifycrd.go @@ -0,0 +1,142 @@ +/* +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" + + cgroupnotifycrdv1 "github.com/tencent/caelus/pkg/apis/cgroupnotifycrd/v1" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + labels "k8s.io/apimachinery/pkg/labels" + schema "k8s.io/apimachinery/pkg/runtime/schema" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + testing "k8s.io/client-go/testing" +) + +// FakeCgroupNotifyCrds implements CgroupNotifyCrdInterface +type FakeCgroupNotifyCrds struct { + Fake *FakeCgroupnotifycrdV1 + ns string +} + +var cgroupnotifycrdsResource = schema.GroupVersionResource{Group: "cgroupnotifycrd", Version: "v1", Resource: "cgroupnotifycrds"} + +var cgroupnotifycrdsKind = schema.GroupVersionKind{Group: "cgroupnotifycrd", Version: "v1", Kind: "CgroupNotifyCrd"} + +// Get takes name of the cgroupNotifyCrd, and returns the corresponding cgroupNotifyCrd object, and an error if there is any. +func (c *FakeCgroupNotifyCrds) Get(ctx context.Context, name string, options v1.GetOptions) (result *cgroupnotifycrdv1.CgroupNotifyCrd, err error) { + obj, err := c.Fake. + Invokes(testing.NewGetAction(cgroupnotifycrdsResource, c.ns, name), &cgroupnotifycrdv1.CgroupNotifyCrd{}) + + if obj == nil { + return nil, err + } + return obj.(*cgroupnotifycrdv1.CgroupNotifyCrd), err +} + +// List takes label and field selectors, and returns the list of CgroupNotifyCrds that match those selectors. +func (c *FakeCgroupNotifyCrds) List(ctx context.Context, opts v1.ListOptions) (result *cgroupnotifycrdv1.CgroupNotifyCrdList, err error) { + obj, err := c.Fake. + Invokes(testing.NewListAction(cgroupnotifycrdsResource, cgroupnotifycrdsKind, c.ns, opts), &cgroupnotifycrdv1.CgroupNotifyCrdList{}) + + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &cgroupnotifycrdv1.CgroupNotifyCrdList{ListMeta: obj.(*cgroupnotifycrdv1.CgroupNotifyCrdList).ListMeta} + for _, item := range obj.(*cgroupnotifycrdv1.CgroupNotifyCrdList).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 cgroupNotifyCrds. +func (c *FakeCgroupNotifyCrds) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { + return c.Fake. + InvokesWatch(testing.NewWatchAction(cgroupnotifycrdsResource, c.ns, opts)) + +} + +// Create takes the representation of a cgroupNotifyCrd and creates it. Returns the server's representation of the cgroupNotifyCrd, and an error, if there is any. +func (c *FakeCgroupNotifyCrds) Create(ctx context.Context, cgroupNotifyCrd *cgroupnotifycrdv1.CgroupNotifyCrd, opts v1.CreateOptions) (result *cgroupnotifycrdv1.CgroupNotifyCrd, err error) { + obj, err := c.Fake. + Invokes(testing.NewCreateAction(cgroupnotifycrdsResource, c.ns, cgroupNotifyCrd), &cgroupnotifycrdv1.CgroupNotifyCrd{}) + + if obj == nil { + return nil, err + } + return obj.(*cgroupnotifycrdv1.CgroupNotifyCrd), err +} + +// Update takes the representation of a cgroupNotifyCrd and updates it. Returns the server's representation of the cgroupNotifyCrd, and an error, if there is any. +func (c *FakeCgroupNotifyCrds) Update(ctx context.Context, cgroupNotifyCrd *cgroupnotifycrdv1.CgroupNotifyCrd, opts v1.UpdateOptions) (result *cgroupnotifycrdv1.CgroupNotifyCrd, err error) { + obj, err := c.Fake. + Invokes(testing.NewUpdateAction(cgroupnotifycrdsResource, c.ns, cgroupNotifyCrd), &cgroupnotifycrdv1.CgroupNotifyCrd{}) + + if obj == nil { + return nil, err + } + return obj.(*cgroupnotifycrdv1.CgroupNotifyCrd), 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 *FakeCgroupNotifyCrds) UpdateStatus(ctx context.Context, cgroupNotifyCrd *cgroupnotifycrdv1.CgroupNotifyCrd, opts v1.UpdateOptions) (*cgroupnotifycrdv1.CgroupNotifyCrd, error) { + obj, err := c.Fake. + Invokes(testing.NewUpdateSubresourceAction(cgroupnotifycrdsResource, "status", c.ns, cgroupNotifyCrd), &cgroupnotifycrdv1.CgroupNotifyCrd{}) + + if obj == nil { + return nil, err + } + return obj.(*cgroupnotifycrdv1.CgroupNotifyCrd), err +} + +// Delete takes name of the cgroupNotifyCrd and deletes it. Returns an error if one occurs. +func (c *FakeCgroupNotifyCrds) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { + _, err := c.Fake. + Invokes(testing.NewDeleteActionWithOptions(cgroupnotifycrdsResource, c.ns, name, opts), &cgroupnotifycrdv1.CgroupNotifyCrd{}) + + return err +} + +// DeleteCollection deletes a collection of objects. +func (c *FakeCgroupNotifyCrds) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { + action := testing.NewDeleteCollectionAction(cgroupnotifycrdsResource, c.ns, listOpts) + + _, err := c.Fake.Invokes(action, &cgroupnotifycrdv1.CgroupNotifyCrdList{}) + return err +} + +// Patch applies the patch and returns the patched cgroupNotifyCrd. +func (c *FakeCgroupNotifyCrds) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *cgroupnotifycrdv1.CgroupNotifyCrd, err error) { + obj, err := c.Fake. + Invokes(testing.NewPatchSubresourceAction(cgroupnotifycrdsResource, c.ns, name, pt, data, subresources...), &cgroupnotifycrdv1.CgroupNotifyCrd{}) + + if obj == nil { + return nil, err + } + return obj.(*cgroupnotifycrdv1.CgroupNotifyCrd), err +} diff --git a/pkg/cgroupClient/clientset/versioned/typed/cgroupnotifycrd/v1/fake/fake_cgroupnotifycrd_client.go b/pkg/cgroupClient/clientset/versioned/typed/cgroupnotifycrd/v1/fake/fake_cgroupnotifycrd_client.go new file mode 100644 index 00000000..036f1f0b --- /dev/null +++ b/pkg/cgroupClient/clientset/versioned/typed/cgroupnotifycrd/v1/fake/fake_cgroupnotifycrd_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 ( + v1 "github.com/tencent/caelus/pkg/cgroupClient/clientset/versioned/typed/cgroupnotifycrd/v1" + rest "k8s.io/client-go/rest" + testing "k8s.io/client-go/testing" +) + +type FakeCgroupnotifycrdV1 struct { + *testing.Fake +} + +func (c *FakeCgroupnotifycrdV1) CgroupNotifyCrds(namespace string) v1.CgroupNotifyCrdInterface { + return &FakeCgroupNotifyCrds{c, namespace} +} + +// RESTClient returns a RESTClient that is used to communicate +// with API server by this client implementation. +func (c *FakeCgroupnotifycrdV1) RESTClient() rest.Interface { + var ret *rest.RESTClient + return ret +} diff --git a/pkg/cgroupClient/clientset/versioned/typed/cgroupnotifycrd/v1/generated_expansion.go b/pkg/cgroupClient/clientset/versioned/typed/cgroupnotifycrd/v1/generated_expansion.go new file mode 100644 index 00000000..3d114c4b --- /dev/null +++ b/pkg/cgroupClient/clientset/versioned/typed/cgroupnotifycrd/v1/generated_expansion.go @@ -0,0 +1,21 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +package v1 + +type CgroupNotifyCrdExpansion interface{} diff --git a/pkg/cgroupClient/informers/externalversions/cgroupnotifycrd/interface.go b/pkg/cgroupClient/informers/externalversions/cgroupnotifycrd/interface.go new file mode 100644 index 00000000..71312a4b --- /dev/null +++ b/pkg/cgroupClient/informers/externalversions/cgroupnotifycrd/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 cgroupnotifycrd + +import ( + v1 "github.com/tencent/caelus/pkg/cgroupClient/informers/externalversions/cgroupnotifycrd/v1" + internalinterfaces "github.com/tencent/caelus/pkg/cgroupClient/informers/externalversions/internalinterfaces" +) + +// Interface provides access to each of this group's versions. +type Interface interface { + // V1 provides access to shared informers for resources in V1. + V1() v1.Interface +} + +type group struct { + factory internalinterfaces.SharedInformerFactory + namespace string + tweakListOptions internalinterfaces.TweakListOptionsFunc +} + +// New returns a new Interface. +func New(f internalinterfaces.SharedInformerFactory, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) Interface { + return &group{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} +} + +// V1 returns a new v1.Interface. +func (g *group) V1() v1.Interface { + return v1.New(g.factory, g.namespace, g.tweakListOptions) +} diff --git a/pkg/cgroupClient/informers/externalversions/cgroupnotifycrd/v1/cgroupnotifycrd.go b/pkg/cgroupClient/informers/externalversions/cgroupnotifycrd/v1/cgroupnotifycrd.go new file mode 100644 index 00000000..4177efdb --- /dev/null +++ b/pkg/cgroupClient/informers/externalversions/cgroupnotifycrd/v1/cgroupnotifycrd.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 v1 + +import ( + "context" + time "time" + + cgroupnotifycrdv1 "github.com/tencent/caelus/pkg/apis/cgroupnotifycrd/v1" + versioned "github.com/tencent/caelus/pkg/cgroupClient/clientset/versioned" + internalinterfaces "github.com/tencent/caelus/pkg/cgroupClient/informers/externalversions/internalinterfaces" + v1 "github.com/tencent/caelus/pkg/cgroupClient/listers/cgroupnotifycrd/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + watch "k8s.io/apimachinery/pkg/watch" + cache "k8s.io/client-go/tools/cache" +) + +// CgroupNotifyCrdInformer provides access to a shared informer and lister for +// CgroupNotifyCrds. +type CgroupNotifyCrdInformer interface { + Informer() cache.SharedIndexInformer + Lister() v1.CgroupNotifyCrdLister +} + +type cgroupNotifyCrdInformer struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc + namespace string +} + +// NewCgroupNotifyCrdInformer constructs a new informer for CgroupNotifyCrd 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 NewCgroupNotifyCrdInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return NewFilteredCgroupNotifyCrdInformer(client, namespace, resyncPeriod, indexers, nil) +} + +// NewFilteredCgroupNotifyCrdInformer constructs a new informer for CgroupNotifyCrd 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 NewFilteredCgroupNotifyCrdInformer(client versioned.Interface, namespace string, 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.CgroupnotifycrdV1().CgroupNotifyCrds(namespace).List(context.TODO(), options) + }, + WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.CgroupnotifycrdV1().CgroupNotifyCrds(namespace).Watch(context.TODO(), options) + }, + }, + &cgroupnotifycrdv1.CgroupNotifyCrd{}, + resyncPeriod, + indexers, + ) +} + +func (f *cgroupNotifyCrdInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewFilteredCgroupNotifyCrdInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) +} + +func (f *cgroupNotifyCrdInformer) Informer() cache.SharedIndexInformer { + return f.factory.InformerFor(&cgroupnotifycrdv1.CgroupNotifyCrd{}, f.defaultInformer) +} + +func (f *cgroupNotifyCrdInformer) Lister() v1.CgroupNotifyCrdLister { + return v1.NewCgroupNotifyCrdLister(f.Informer().GetIndexer()) +} diff --git a/pkg/cgroupClient/informers/externalversions/cgroupnotifycrd/v1/interface.go b/pkg/cgroupClient/informers/externalversions/cgroupnotifycrd/v1/interface.go new file mode 100644 index 00000000..52a0f430 --- /dev/null +++ b/pkg/cgroupClient/informers/externalversions/cgroupnotifycrd/v1/interface.go @@ -0,0 +1,45 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by informer-gen. DO NOT EDIT. + +package v1 + +import ( + internalinterfaces "github.com/tencent/caelus/pkg/cgroupClient/informers/externalversions/internalinterfaces" +) + +// Interface provides access to all the informers in this group version. +type Interface interface { + // CgroupNotifyCrds returns a CgroupNotifyCrdInformer. + CgroupNotifyCrds() CgroupNotifyCrdInformer +} + +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} +} + +// CgroupNotifyCrds returns a CgroupNotifyCrdInformer. +func (v *version) CgroupNotifyCrds() CgroupNotifyCrdInformer { + return &cgroupNotifyCrdInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} +} diff --git a/pkg/cgroupClient/informers/externalversions/factory.go b/pkg/cgroupClient/informers/externalversions/factory.go new file mode 100644 index 00000000..4b86108c --- /dev/null +++ b/pkg/cgroupClient/informers/externalversions/factory.go @@ -0,0 +1,180 @@ +/* +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" + + versioned "github.com/tencent/caelus/pkg/cgroupClient/clientset/versioned" + cgroupnotifycrd "github.com/tencent/caelus/pkg/cgroupClient/informers/externalversions/cgroupnotifycrd" + internalinterfaces "github.com/tencent/caelus/pkg/cgroupClient/informers/externalversions/internalinterfaces" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + schema "k8s.io/apimachinery/pkg/runtime/schema" + cache "k8s.io/client-go/tools/cache" +) + +// SharedInformerOption defines the functional option type for SharedInformerFactory. +type SharedInformerOption func(*sharedInformerFactory) *sharedInformerFactory + +type sharedInformerFactory struct { + client versioned.Interface + namespace string + tweakListOptions internalinterfaces.TweakListOptionsFunc + lock sync.Mutex + defaultResync time.Duration + customResync map[reflect.Type]time.Duration + + 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 +} + +// 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 +} + +// Start initializes all requested informers. +func (f *sharedInformerFactory) Start(stopCh <-chan struct{}) { + f.lock.Lock() + defer f.lock.Unlock() + + for informerType, informer := range f.informers { + if !f.startedInformers[informerType] { + go informer.Run(stopCh) + f.startedInformers[informerType] = true + } + } +} + +// WaitForCacheSync waits for all started informers' cache were synced. +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. +type SharedInformerFactory interface { + internalinterfaces.SharedInformerFactory + ForResource(resource schema.GroupVersionResource) (GenericInformer, error) + WaitForCacheSync(stopCh <-chan struct{}) map[reflect.Type]bool + + Cgroupnotifycrd() cgroupnotifycrd.Interface +} + +func (f *sharedInformerFactory) Cgroupnotifycrd() cgroupnotifycrd.Interface { + return cgroupnotifycrd.New(f, f.namespace, f.tweakListOptions) +} diff --git a/pkg/cgroupClient/informers/externalversions/generic.go b/pkg/cgroupClient/informers/externalversions/generic.go new file mode 100644 index 00000000..4a4f0604 --- /dev/null +++ b/pkg/cgroupClient/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" + + v1 "github.com/tencent/caelus/pkg/apis/cgroupnotifycrd/v1" + schema "k8s.io/apimachinery/pkg/runtime/schema" + cache "k8s.io/client-go/tools/cache" +) + +// GenericInformer is type of SharedIndexInformer which will locate and delegate to other +// sharedInformers based on type +type GenericInformer interface { + Informer() cache.SharedIndexInformer + Lister() cache.GenericLister +} + +type genericInformer struct { + informer cache.SharedIndexInformer + resource schema.GroupResource +} + +// Informer returns the SharedIndexInformer. +func (f *genericInformer) Informer() cache.SharedIndexInformer { + return f.informer +} + +// Lister returns the GenericLister. +func (f *genericInformer) Lister() cache.GenericLister { + return cache.NewGenericLister(f.Informer().GetIndexer(), f.resource) +} + +// ForResource gives generic access to a shared informer of the matching type +// TODO extend this to unknown resources with a client pool +func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource) (GenericInformer, error) { + switch resource { + // Group=cgroupnotifycrd, Version=v1 + case v1.SchemeGroupVersion.WithResource("cgroupnotifycrds"): + return &genericInformer{resource: resource.GroupResource(), informer: f.Cgroupnotifycrd().V1().CgroupNotifyCrds().Informer()}, nil + + } + + return nil, fmt.Errorf("no informer found for %v", resource) +} diff --git a/pkg/cgroupClient/informers/externalversions/internalinterfaces/factory_interfaces.go b/pkg/cgroupClient/informers/externalversions/internalinterfaces/factory_interfaces.go new file mode 100644 index 00000000..6b38c474 --- /dev/null +++ b/pkg/cgroupClient/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" + + versioned "github.com/tencent/caelus/pkg/cgroupClient/clientset/versioned" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + cache "k8s.io/client-go/tools/cache" +) + +// NewInformerFunc takes versioned.Interface and time.Duration to return a SharedIndexInformer. +type NewInformerFunc func(versioned.Interface, time.Duration) cache.SharedIndexInformer + +// SharedInformerFactory a small interface to allow for adding an informer without an import cycle +type SharedInformerFactory interface { + Start(stopCh <-chan struct{}) + InformerFor(obj runtime.Object, newFunc NewInformerFunc) cache.SharedIndexInformer +} + +// TweakListOptionsFunc is a function that transforms a v1.ListOptions. +type TweakListOptionsFunc func(*v1.ListOptions) diff --git a/pkg/cgroupClient/listers/cgroupnotifycrd/v1/cgroupnotifycrd.go b/pkg/cgroupClient/listers/cgroupnotifycrd/v1/cgroupnotifycrd.go new file mode 100644 index 00000000..a9c32375 --- /dev/null +++ b/pkg/cgroupClient/listers/cgroupnotifycrd/v1/cgroupnotifycrd.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 v1 + +import ( + v1 "github.com/tencent/caelus/pkg/apis/cgroupnotifycrd/v1" + "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/tools/cache" +) + +// CgroupNotifyCrdLister helps list CgroupNotifyCrds. +// All objects returned here must be treated as read-only. +type CgroupNotifyCrdLister interface { + // List lists all CgroupNotifyCrds in the indexer. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*v1.CgroupNotifyCrd, err error) + // CgroupNotifyCrds returns an object that can list and get CgroupNotifyCrds. + CgroupNotifyCrds(namespace string) CgroupNotifyCrdNamespaceLister + CgroupNotifyCrdListerExpansion +} + +// cgroupNotifyCrdLister implements the CgroupNotifyCrdLister interface. +type cgroupNotifyCrdLister struct { + indexer cache.Indexer +} + +// NewCgroupNotifyCrdLister returns a new CgroupNotifyCrdLister. +func NewCgroupNotifyCrdLister(indexer cache.Indexer) CgroupNotifyCrdLister { + return &cgroupNotifyCrdLister{indexer: indexer} +} + +// List lists all CgroupNotifyCrds in the indexer. +func (s *cgroupNotifyCrdLister) List(selector labels.Selector) (ret []*v1.CgroupNotifyCrd, err error) { + err = cache.ListAll(s.indexer, selector, func(m interface{}) { + ret = append(ret, m.(*v1.CgroupNotifyCrd)) + }) + return ret, err +} + +// CgroupNotifyCrds returns an object that can list and get CgroupNotifyCrds. +func (s *cgroupNotifyCrdLister) CgroupNotifyCrds(namespace string) CgroupNotifyCrdNamespaceLister { + return cgroupNotifyCrdNamespaceLister{indexer: s.indexer, namespace: namespace} +} + +// CgroupNotifyCrdNamespaceLister helps list and get CgroupNotifyCrds. +// All objects returned here must be treated as read-only. +type CgroupNotifyCrdNamespaceLister interface { + // List lists all CgroupNotifyCrds in the indexer for a given namespace. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*v1.CgroupNotifyCrd, err error) + // Get retrieves the CgroupNotifyCrd from the indexer for a given namespace and name. + // Objects returned here must be treated as read-only. + Get(name string) (*v1.CgroupNotifyCrd, error) + CgroupNotifyCrdNamespaceListerExpansion +} + +// cgroupNotifyCrdNamespaceLister implements the CgroupNotifyCrdNamespaceLister +// interface. +type cgroupNotifyCrdNamespaceLister struct { + indexer cache.Indexer + namespace string +} + +// List lists all CgroupNotifyCrds in the indexer for a given namespace. +func (s cgroupNotifyCrdNamespaceLister) List(selector labels.Selector) (ret []*v1.CgroupNotifyCrd, err error) { + err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { + ret = append(ret, m.(*v1.CgroupNotifyCrd)) + }) + return ret, err +} + +// Get retrieves the CgroupNotifyCrd from the indexer for a given namespace and name. +func (s cgroupNotifyCrdNamespaceLister) Get(name string) (*v1.CgroupNotifyCrd, error) { + obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) + if err != nil { + return nil, err + } + if !exists { + return nil, errors.NewNotFound(v1.Resource("cgroupnotifycrd"), name) + } + return obj.(*v1.CgroupNotifyCrd), nil +} diff --git a/pkg/cgroupClient/listers/cgroupnotifycrd/v1/expansion_generated.go b/pkg/cgroupClient/listers/cgroupnotifycrd/v1/expansion_generated.go new file mode 100644 index 00000000..278e31de --- /dev/null +++ b/pkg/cgroupClient/listers/cgroupnotifycrd/v1/expansion_generated.go @@ -0,0 +1,27 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by lister-gen. DO NOT EDIT. + +package v1 + +// CgroupNotifyCrdListerExpansion allows custom methods to be added to +// CgroupNotifyCrdLister. +type CgroupNotifyCrdListerExpansion interface{} + +// CgroupNotifyCrdNamespaceListerExpansion allows custom methods to be added to +// CgroupNotifyCrdNamespaceLister. +type CgroupNotifyCrdNamespaceListerExpansion interface{} From f20ea6356f589747c97610d95434e01d33023381 Mon Sep 17 00:00:00 2001 From: yanxiaoqi932 Date: Fri, 15 Mar 2024 15:29:00 +0800 Subject: [PATCH 09/59] merge init-framework --- go.mod | 1 + go.sum | 2 ++ pkg/caelus/healthcheck/health_check.go | 49 +++----------------------- 3 files changed, 8 insertions(+), 44 deletions(-) diff --git a/go.mod b/go.mod index e5e51ff4..9b103cea 100644 --- a/go.mod +++ b/go.mod @@ -104,6 +104,7 @@ 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/klog v1.0.0 // indirect k8s.io/kube-openapi v0.0.0-20221012153701-172d655c2280 // indirect moul.io/http2curl v1.0.0 // indirect sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 // indirect diff --git a/go.sum b/go.sum index ee0843cb..8a596d0a 100644 --- a/go.sum +++ b/go.sum @@ -885,6 +885,8 @@ k8s.io/component-base v0.26.0/go.mod h1:lqHwlfV1/haa14F/Z5Zizk5QmzaVf23nQzCwVOQp k8s.io/gengo v0.0.0-20210813121822-485abfe95c7c/go.mod h1:FiNAH4ZV3gBg2Kwh89tzAEV2be7d5xI0vBa/VySYy3E= k8s.io/gengo v0.0.0-20211129171323-c02415ce4185/go.mod h1:FiNAH4ZV3gBg2Kwh89tzAEV2be7d5xI0vBa/VySYy3E= k8s.io/klog v0.3.0/go.mod h1:Gq+BEi5rUBO/HRz0bTSXDUcqjScdoY3a9IHpCEIOOfk= +k8s.io/klog v1.0.0 h1:Pt+yjF5aB1xDSVbau4VsWe+dQNzA0qv1LlXdC2dF6Q8= +k8s.io/klog v1.0.0/go.mod h1:4Bi6QPql/J/LkTDqv7R/cd3hPo4k2DG6Ptcz060Ez5I= k8s.io/klog/v2 v2.0.0/go.mod h1:PBfzABfn139FHAV07az/IF9Wp1bkk3vpT2XSJ76fSDE= k8s.io/klog/v2 v2.2.0/go.mod h1:Od+F08eJP+W3HUb4pSrPpgp9DGU4GzlpG/TmITuYh/Y= k8s.io/klog/v2 v2.9.0/go.mod h1:hy9LJ/NvuK+iVyP4Ehqva4HxZG/oXyIS3n3Jmire4Ec= diff --git a/pkg/caelus/healthcheck/health_check.go b/pkg/caelus/healthcheck/health_check.go index 8524b6a1..7bf46a77 100644 --- a/pkg/caelus/healthcheck/health_check.go +++ b/pkg/caelus/healthcheck/health_check.go @@ -18,19 +18,11 @@ package health import ( "context" "fmt" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "strings" - "github.com/tencent/caelus/pkg/caelus/healthcheck/cgroupnotify" - "crypto/md5" - "encoding/hex" - "io" - "os" - "path/filepath" + notify "github.com/tencent/caelus/pkg/caelus/healthcheck/cgroupnotify" - "github.com/fsnotify/fsnotify" cgroupCrd "github.com/tencent/caelus/pkg/apis/cgroupnotifycrd/v1" - notify "github.com/tencent/caelus/pkg/caelus/healthcheck/cgroupnotify" "github.com/tencent/caelus/pkg/caelus/healthcheck/conflict" "github.com/tencent/caelus/pkg/caelus/healthcheck/rulecheck" "github.com/tencent/caelus/pkg/caelus/qos" @@ -43,6 +35,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" clientset "k8s.io/client-go/kubernetes" "k8s.io/client-go/tools/cache" + "k8s.io/klog" ) const ( @@ -267,6 +260,8 @@ func (h *manager) isLabelMatched(labels map[string]string) (bool, error) { } } return false, nil +} + func (h *manager) OnAddCgropNotify(obj interface{}) { h.updateCgroupConfig(obj, false) h.updateCgroupNotifier() @@ -282,33 +277,6 @@ func (h *manager) OnDeleteCgropNotify(obj interface{}) { h.updateCgroupNotifier() } -func (h *manager) updateRulecheck() { - -} - -func (h *manager) updateCgroupNotifier() { - -} - -func (h *manager) HasNode(cgroupCrd *cgroupCrd.CgroupNotifyCrd) (bool, error) { - nodeSelector := cgroupCrd.Spec.NodeSelector - nodes, err := h.k8sClient.CoreV1().Nodes().List(context.TODO(), metav1.ListOptions{ - LabelSelector: metav1.FormatLabelSelector(&nodeSelector), - }) - if err != nil { - return false, err - } - - found := false - for _, n := range nodes.Items { - if n.Name == util.NodeName() { - found = true - break - } - } - return found, nil -} - func (h *manager) CgroupCrddeepCopy(cgroupCrd *cgroupCrd.CgroupNotifyCrd) { pressures := make([]types.MemoryPressureNotifyConfig, 0) for _, p := range cgroupCrd.Spec.MemoryCgroup.Pressures { @@ -329,6 +297,7 @@ func (h *manager) CgroupCrddeepCopy(cgroupCrd *cgroupCrd.CgroupNotifyCrd) { } h.config.CgroupNotify.MemoryCgroup.Pressures = pressures h.config.CgroupNotify.MemoryCgroup.Usages = usages + h.config.CgroupNotify.Labels = cgroupCrd.Spec.NodeSelector.MatchLabels } func (h *manager) updateCgroupConfig(obj interface{}, isDelete bool) { @@ -339,14 +308,6 @@ func (h *manager) updateCgroupConfig(obj interface{}, isDelete bool) { klog.Error("get cgroupNotifyCrd failed") return } - found, err := h.HasNode(cgroupCrd) - if err != nil { - klog.Error("get Nodes failed: %v", err) - return - } - if !found { - return - } if isDelete { h.config.CgroupNotify = types.NotifyConfig{} } else { From 740428f7f1c698e104130212870fc3d3b651050b Mon Sep 17 00:00:00 2001 From: baowj Date: Fri, 15 Mar 2024 17:06:47 +0800 Subject: [PATCH 10/59] Update rulecheck CRD 1.update rulecheck CRD 2.add informer to the manager 3.add rule check update func Signed-off-by: baowj --- cmd/caelus/app/server.go | 3 +- cmd/caelus/context/context.go | 21 ++-- pkg/apis/caelus/v1/rulecheck_types.go | 8 +- pkg/apis/caelus/v1/zz_generated.deepcopy.go | 9 +- pkg/caelus/healthcheck/health_check.go | 122 +++++++++++++++++--- pkg/caelus/types/health_check.go | 8 +- 6 files changed, 128 insertions(+), 43 deletions(-) diff --git a/cmd/caelus/app/server.go b/cmd/caelus/app/server.go index b9443577..32a58f3d 100644 --- a/cmd/caelus/app/server.go +++ b/cmd/caelus/app/server.go @@ -248,10 +248,11 @@ func (o *options) initModules(caelus *types.CaelusConfig, ctx *context.CaelusCon // healthCheckManager = health.NewHealthManager(types.InitHealthCheckConfigFunc(&caelus.Metrics.Node, // &caelus.Predicts[0].ReserveResource), stStore, resourceManager, qosManager, // conflictMn, podInformer, xxInformer1, xxInformer2, kubeClient) + ruleCheckInformer := ctx.GetCaelusFactory().Caelus().V1().RuleChecks().Informer() cgroupFactory := ctx.GetCgroupNotifyFactory() cgroupNotifyInformer := cgroupFactory.Cgroupnotifycrd().V1().CgroupNotifyCrds() healthCheckManager = health.NewHealthManager(stStore, resourceManager, qosManager, - conflictMn, podInformer, cgroupNotifyInformer, ctx.GetKubeClient()) + conflictMn, podInformer, ruleCheckInformer, cgroupNotifyInformer, ctx.GetKubeClient()) modules = append(modules, healthCheckManager) return modules diff --git a/cmd/caelus/context/context.go b/cmd/caelus/context/context.go index 945cd637..12acb60c 100644 --- a/cmd/caelus/context/context.go +++ b/cmd/caelus/context/context.go @@ -44,10 +44,9 @@ type CaelusContext struct { caelusClient caelusclient.Interface cgroupNotifyClient cgroupclient.Interface nodeFactory, podFactory informers.SharedInformerFactory - ruleCheckFactory caelusinformers.SharedInformerFactory + caelusFactory caelusinformers.SharedInformerFactory cgroupNotifyFactory cgroupInformers.SharedInformerFactory // TODO add xxx informers - } const ( @@ -139,18 +138,18 @@ func (c *CaelusContext) GetPodFactory() informers.SharedInformerFactory { return c.podFactory } -// GetRuleCheckFactory returns ruleCheck factory -func (c *CaelusContext) GetRuleCheckFactory() caelusinformers.SharedInformerFactory { - if c.ruleCheckFactory == nil { - c.ruleCheckFactory = caelusinformers.NewSharedInformerFactoryWithOptions(c.GetCaelusClient(), informerSyncPeriod, +// GetCaelusFactory returns ruleCheck factory +func (c *CaelusContext) GetCaelusFactory() caelusinformers.SharedInformerFactory { + if c.caelusFactory == nil { + c.caelusFactory = caelusinformers.NewSharedInformerFactoryWithOptions(c.GetCaelusClient(), informerSyncPeriod, caelusinformers.WithTweakListOptions(func(options *metav1.ListOptions) { options.FieldSelector = fields.OneTermEqualSelector(nodeNameField, c.NodeName).String() })) } - return c.ruleCheckFactory + return c.caelusFactory } -// GetRuleCheckFactory returns cgroupnotify factory +// GetCaelusFactory returns cgroupnotify factory func (c *CaelusContext) GetCgroupNotifyFactory() cgroupInformers.SharedInformerFactory { if c.cgroupNotifyFactory == nil { c.cgroupNotifyFactory = cgroupInformers.NewSharedInformerFactoryWithOptions(c.GetCgroupNotifyClient(), informerSyncPeriod, @@ -189,9 +188,9 @@ func (c *CaelusContext) Run(stop <-chan struct{}) { c.nodeFactory.Start(stop) c.nodeFactory.WaitForCacheSync(stop) } - if c.ruleCheckFactory != nil { - c.ruleCheckFactory.Start(stop) - c.ruleCheckFactory.WaitForCacheSync(stop) + if c.caelusFactory != nil { + c.caelusFactory.Start(stop) + c.caelusFactory.WaitForCacheSync(stop) } if c.cgroupNotifyFactory != nil { c.cgroupNotifyFactory.Start(stop) diff --git a/pkg/apis/caelus/v1/rulecheck_types.go b/pkg/apis/caelus/v1/rulecheck_types.go index b58becfc..5a21d1a7 100644 --- a/pkg/apis/caelus/v1/rulecheck_types.go +++ b/pkg/apis/caelus/v1/rulecheck_types.go @@ -45,10 +45,10 @@ type RuleCheck struct { // RuleCheckSpec is the spec for a RuleCheck resource type RuleCheckSpec struct { - NodeSelector map[string]string `json:"nodeSelector"` - - Type RuleCheckType `json:"type"` - Metrics []string `json:"metrics"` + Name string `json:"name"` + NodeSelector metav1.LabelSelector `json:"nodeSelector"` + Type RuleCheckType `json:"type"` + Metrics []string `json:"metrics"` // CheckInterval describes the interval to trigger detection CheckInterval *times.Duration `json:"checkInterval"` // HandleInterval describes the interval to handle conflicts after detecting abnormal result diff --git a/pkg/apis/caelus/v1/zz_generated.deepcopy.go b/pkg/apis/caelus/v1/zz_generated.deepcopy.go index 3061a3cd..dd906d63 100644 --- a/pkg/apis/caelus/v1/zz_generated.deepcopy.go +++ b/pkg/apis/caelus/v1/zz_generated.deepcopy.go @@ -23,7 +23,6 @@ import ( json "encoding/json" times "github.com/tencent/caelus/pkg/util/times" - runtime "k8s.io/apimachinery/pkg/runtime" ) @@ -150,13 +149,7 @@ func (in *RuleCheckList) DeepCopyObject() runtime.Object { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *RuleCheckSpec) DeepCopyInto(out *RuleCheckSpec) { *out = *in - if in.NodeSelector != nil { - in, out := &in.NodeSelector, &out.NodeSelector - *out = make(map[string]string, len(*in)) - for key, val := range *in { - (*out)[key] = val - } - } + in.NodeSelector.DeepCopyInto(&out.NodeSelector) if in.Metrics != nil { in, out := &in.Metrics, &out.Metrics *out = make([]string, len(*in)) diff --git a/pkg/caelus/healthcheck/health_check.go b/pkg/caelus/healthcheck/health_check.go index 7bf46a77..264e682f 100644 --- a/pkg/caelus/healthcheck/health_check.go +++ b/pkg/caelus/healthcheck/health_check.go @@ -18,11 +18,12 @@ package health import ( "context" "fmt" + "sort" "strings" - notify "github.com/tencent/caelus/pkg/caelus/healthcheck/cgroupnotify" - + v1 "github.com/tencent/caelus/pkg/apis/caelus/v1" cgroupCrd "github.com/tencent/caelus/pkg/apis/cgroupnotifycrd/v1" + notify "github.com/tencent/caelus/pkg/caelus/healthcheck/cgroupnotify" "github.com/tencent/caelus/pkg/caelus/healthcheck/conflict" "github.com/tencent/caelus/pkg/caelus/healthcheck/rulecheck" "github.com/tencent/caelus/pkg/caelus/qos" @@ -31,6 +32,7 @@ import ( "github.com/tencent/caelus/pkg/caelus/types" "github.com/tencent/caelus/pkg/caelus/util" cgroupInformer "github.com/tencent/caelus/pkg/cgroupClient/informers/externalversions/cgroupnotifycrd/v1" + caelusclient "github.com/tencent/caelus/pkg/generated/clientset/versioned" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" clientset "k8s.io/client-go/kubernetes" @@ -53,24 +55,24 @@ type manager struct { config *types.HealthCheckConfig ruleChecker *rulecheck.Manager // support linux kernel PSI, now just memory event - cgroupNotifier notify.ResourceNotify - stStore statestore.StateStore - resource resource.Interface - qosManager qos.Manager - conflictMn conflict.Manager - podInformer cache.SharedIndexInformer - configHash string - globalStopCh <-chan struct{} - // xxxInformer1 - cgroupInformer cgroupInformer.CgroupNotifyCrdInformer - // xxxInformer2 - k8sClient clientset.Interface + cgroupNotifier notify.ResourceNotify + stStore statestore.StateStore + resource resource.Interface + qosManager qos.Manager + conflictMn conflict.Manager + podInformer cache.SharedIndexInformer + configHash string + globalStopCh <-chan struct{} + ruleCheckInformer cache.SharedIndexInformer + caelusClient caelusclient.Clientset + cgroupInformer cgroupInformer.CgroupNotifyCrdInformer + k8sClient clientset.Interface } // NewHealthManager create a new health check manager func NewHealthManager(stStore statestore.StateStore, resource resource.Interface, qosManager qos.Manager, conflictMn conflict.Manager, - podInformer cache.SharedIndexInformer, cgroupInformer cgroupInformer.CgroupNotifyCrdInformer, + podInformer cache.SharedIndexInformer, ruleCheckInformer cache.SharedIndexInformer, cgroupInformer cgroupInformer.CgroupNotifyCrdInformer, k8sClient clientset.Interface) Manager { // TODO add the informer enent func @@ -83,7 +85,17 @@ func NewHealthManager(stStore statestore.StateStore, podInformer: podInformer, k8sClient: k8sClient, // add informer - cgroupInformer: cgroupInformer, + ruleCheckInformer: ruleCheckInformer, + cgroupInformer: cgroupInformer, + } + + _, err := hm.ruleCheckInformer.AddEventHandler(cache.ResourceEventHandlerFuncs{ + AddFunc: nil, + UpdateFunc: nil, + DeleteFunc: nil, + }) + if err != nil { + return nil } hm.cgroupInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{ @@ -314,3 +326,81 @@ func (h *manager) updateCgroupConfig(obj interface{}, isDelete bool) { h.CgroupCrddeepCopy(cgroupCrd) } } + +// update local RuleCheck +func (h *manager) updateRuleCheckConfig() error { + ctx := context.Background() + list, err := h.caelusClient.CaelusV1().RuleChecks("caelus-system").List(ctx, metav1.ListOptions{}) + if err != nil { + return err + } + ruleChecks := list.Items + sort.Slice(ruleChecks, func(i, j int) bool { + return ruleChecks[i].CreationTimestamp.Time.After(ruleChecks[i].CreationTimestamp.Time) + }) + + m := map[string]struct{}{} + appRuleChecks := []*types.RuleCheckConfig{} + nodeRuleChecks := []*types.RuleCheckConfig{} + containerRuleChecks := []*types.RuleCheckConfig{} + for _, k8sRuleCheck := range ruleChecks { + name := string(k8sRuleCheck.Spec.Type) + ":" + k8sRuleCheck.Spec.Name + if _, ok := m[name]; ok { + continue + } + ruleCheck := &types.RuleCheckConfig{} + convertK8sRuleCheck(&k8sRuleCheck, ruleCheck) + switch k8sRuleCheck.Spec.Type { + case v1.AppType: + appRuleChecks = append(appRuleChecks, ruleCheck) + case v1.NodeType: + nodeRuleChecks = append(nodeRuleChecks, ruleCheck) + case v1.ContainerType: + containerRuleChecks = append(containerRuleChecks, ruleCheck) + } + } + h.config.RuleCheck.AppRules = appRuleChecks + h.config.RuleCheck.NodeRules = nodeRuleChecks + h.config.RuleCheck.ContainerRules = containerRuleChecks + return nil +} + +// convert v1.RuleCheck struct to types.RuleCheckConfig struct +func convertK8sRuleCheck(k8sRuleCheck *v1.RuleCheck, ruleCheck *types.RuleCheckConfig) { + convertRules := func(k8sRules []*v1.DetectActionRules) []*types.DetectActionConfig { + rules := make([]*types.DetectActionConfig, 0, len(k8sRuleCheck.Spec.Rules)) + for _, k8sRule := range k8sRules { + rule := &types.DetectActionConfig{ + Detects: make([]*types.DetectConfig, 0, len(k8sRule.Detects)), + Actions: make([]*types.ActionConfig, 0, len(k8sRule.Actions)), + } + for _, detect := range k8sRule.Detects { + rule.Detects = append(rule.Detects, &types.DetectConfig{ + Name: detect.Name, + ArgsStr: detect.Args, + Args: nil, + }) + } + for _, action := range k8sRule.Actions { + rule.Actions = append(rule.Actions, &types.ActionConfig{ + Name: action.Name, + ArgsStr: action.Args, + Args: nil, + }) + } + rules = append(rules, rule) + } + return rules + } + + ruleCheck.Rules = convertRules(k8sRuleCheck.Spec.Rules) + ruleCheck.RecoverRules = convertRules(k8sRuleCheck.Spec.RecoverRules) + + ruleCheck.Name = k8sRuleCheck.Name + ruleCheck.Metrics = k8sRuleCheck.Spec.Metrics + ruleCheck.CheckInterval = *k8sRuleCheck.Spec.CheckInterval + + ruleCheck.RecoverInterval = *k8sRuleCheck.Spec.RecoverInterval + ruleCheck.HandleInterval = *k8sRuleCheck.Spec.HandleInterval + ruleCheck.NodeSelector = k8sRuleCheck.Spec.NodeSelector +} diff --git a/pkg/caelus/types/health_check.go b/pkg/caelus/types/health_check.go index ff1aead8..a868cfc2 100644 --- a/pkg/caelus/types/health_check.go +++ b/pkg/caelus/types/health_check.go @@ -25,6 +25,7 @@ import ( "github.com/tencent/caelus/pkg/caelus/util/machine" "github.com/tencent/caelus/pkg/util/times" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/sets" "k8s.io/klog/v2" ) @@ -106,9 +107,10 @@ type RuleCheck struct { // RuleCheckConfig define the rule config type RuleCheckConfig struct { - Name string `json:"name"` - Metrics []string `json:"metrics"` - Labels map[string]string `json:"labels"` + Name string `json:"name"` + NodeSelector v1.LabelSelector `json:"node_selector"` + Metrics []string `json:"metrics"` + Labels map[string]string `json:"labels"` // CheckInterval describes the interval to trigger detection CheckInterval times.Duration `json:"check_interval"` // HandleInterval describes the interval to handle conflicts after detecting abnormal result From dba1937dfabed43fc3225c20a0aa8301836f9606 Mon Sep 17 00:00:00 2001 From: wang-mask <2018091609006@std.uestc.edu.cn> Date: Sat, 16 Mar 2024 11:18:49 +0800 Subject: [PATCH 11/59] add nodeinformer and fix cgroupinformer Signed-off-by: wang-mask <2018091609006@std.uestc.edu.cn> --- cmd/caelus/app/server.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cmd/caelus/app/server.go b/cmd/caelus/app/server.go index 32a58f3d..8ccc8148 100644 --- a/cmd/caelus/app/server.go +++ b/cmd/caelus/app/server.go @@ -248,11 +248,11 @@ func (o *options) initModules(caelus *types.CaelusConfig, ctx *context.CaelusCon // healthCheckManager = health.NewHealthManager(types.InitHealthCheckConfigFunc(&caelus.Metrics.Node, // &caelus.Predicts[0].ReserveResource), stStore, resourceManager, qosManager, // conflictMn, podInformer, xxInformer1, xxInformer2, kubeClient) + nodeInformer := ctx.GetNodeFactory().Core().V1().Nodes().Informer() ruleCheckInformer := ctx.GetCaelusFactory().Caelus().V1().RuleChecks().Informer() - cgroupFactory := ctx.GetCgroupNotifyFactory() - cgroupNotifyInformer := cgroupFactory.Cgroupnotifycrd().V1().CgroupNotifyCrds() + cgroupNotifyInformer := ctx.GetCgroupNotifyFactory().Cgroupnotifycrd().V1().CgroupNotifyCrds() healthCheckManager = health.NewHealthManager(stStore, resourceManager, qosManager, - conflictMn, podInformer, ruleCheckInformer, cgroupNotifyInformer, ctx.GetKubeClient()) + conflictMn, podInformer, nodeInformer, ruleCheckInformer, cgroupNotifyInformer, ctx.GetKubeClient()) modules = append(modules, healthCheckManager) return modules From cecf7575e5789a1b7dc491f88f91b92f91dcd9d8 Mon Sep 17 00:00:00 2001 From: wang-mask <2018091609006@std.uestc.edu.cn> Date: Sat, 16 Mar 2024 11:19:25 +0800 Subject: [PATCH 12/59] init the process framework Signed-off-by: wang-mask <2018091609006@std.uestc.edu.cn> --- pkg/caelus/healthcheck/health_check.go | 105 ++++++++++++++++++++++--- 1 file changed, 92 insertions(+), 13 deletions(-) diff --git a/pkg/caelus/healthcheck/health_check.go b/pkg/caelus/healthcheck/health_check.go index 264e682f..341ce911 100644 --- a/pkg/caelus/healthcheck/health_check.go +++ b/pkg/caelus/healthcheck/health_check.go @@ -37,11 +37,14 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" clientset "k8s.io/client-go/kubernetes" "k8s.io/client-go/tools/cache" + "k8s.io/client-go/util/workqueue" "k8s.io/klog" ) const ( checkConfigFile = "/etc/caelus/rules.json" + ruleCheck = "RuleCheck" + cgroupNotify = "CgroupNotify" ) // Manager is the interface for handling health check @@ -61,6 +64,8 @@ type manager struct { qosManager qos.Manager conflictMn conflict.Manager podInformer cache.SharedIndexInformer + nodeInformer cache.SharedIndexInformer + workqueue workqueue.RateLimitingInterface configHash string globalStopCh <-chan struct{} ruleCheckInformer cache.SharedIndexInformer @@ -72,36 +77,61 @@ type manager struct { // NewHealthManager create a new health check manager func NewHealthManager(stStore statestore.StateStore, resource resource.Interface, qosManager qos.Manager, conflictMn conflict.Manager, - podInformer cache.SharedIndexInformer, ruleCheckInformer cache.SharedIndexInformer, cgroupInformer cgroupInformer.CgroupNotifyCrdInformer, + podInformer cache.SharedIndexInformer, nodeInformer cache.SharedIndexInformer, ruleCheckInformer cache.SharedIndexInformer, cgroupInformer cgroupInformer.CgroupNotifyCrdInformer, k8sClient clientset.Interface) Manager { // TODO add the informer enent func hm := &manager{ - stStore: stStore, - resource: resource, - qosManager: qosManager, - conflictMn: conflictMn, - podInformer: podInformer, - k8sClient: k8sClient, + stStore: stStore, + resource: resource, + qosManager: qosManager, + conflictMn: conflictMn, + podInformer: podInformer, + nodeInformer: nodeInformer, + workqueue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "health-check-queue"), + k8sClient: k8sClient, // add informer ruleCheckInformer: ruleCheckInformer, cgroupInformer: cgroupInformer, } _, err := hm.ruleCheckInformer.AddEventHandler(cache.ResourceEventHandlerFuncs{ - AddFunc: nil, - UpdateFunc: nil, - DeleteFunc: nil, + AddFunc: func(obj interface{}) { + hm.eventFunc([]string{ruleCheck}) + }, + UpdateFunc: func(oldObj, newObj interface{}) { + hm.eventFunc([]string{ruleCheck}) + }, + DeleteFunc: func(obj interface{}) { + hm.eventFunc([]string{ruleCheck}) + }, }) if err != nil { return nil } + hm.nodeInformer.AddEventHandler(cache.ResourceEventHandlerFuncs{ + AddFunc: func(obj interface{}) { + hm.eventFunc([]string{ruleCheck, cgroupNotify}) + }, + UpdateFunc: func(oldObj, newObj interface{}) { + hm.eventFunc([]string{ruleCheck, cgroupNotify}) + }, + DeleteFunc: func(obj interface{}) { + hm.eventFunc([]string{ruleCheck, cgroupNotify}) + }, + }) hm.cgroupInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{ - AddFunc: hm.OnAddCgropNotify, - UpdateFunc: hm.OnUpdateCgropNotify, - DeleteFunc: hm.OnDeleteCgropNotify, + AddFunc: func(obj interface{}) { + hm.eventFunc([]string{cgroupNotify}) + }, + UpdateFunc: func(oldObj, newObj interface{}) { + hm.eventFunc([]string{cgroupNotify}) + }, + DeleteFunc: func(obj interface{}) { + hm.eventFunc([]string{cgroupNotify}) + }, }) return hm @@ -112,6 +142,14 @@ func (h *manager) Name() string { return "ModuleHealthCheck" } +func(h *manager) eventFunc(crds string[])func(obj interface{}){ + return func(obj interface{}){ + for crd := range crds{ + h.workqueue.Add(crd) + } + } +} + //// reload rule check config dynamically without restarting the agent //func (h *manager) reload() { // reload, hash, config := h.checkNeedReload(checkConfigFile) @@ -163,6 +201,47 @@ func (h *manager) Name() string { func (h *manager) Run(stop <-chan struct{}) { // the function is running in the informer evnet func h.globalStopCh = stop + go h.runWorker(stop) +} + +func (h *manager) runWorker() { + for h.processNextWorkItem() { + } +} + +func (h *manager) processNextWorkItem() bool { + select { + case <-h.globalStopCh: + h.workqueue.ShutDown() + return false + default: + } + obj, shutdown := h.workqueue.Get() + + if shutdown { + return false + } + + key, ok := obj.(string) + if !ok { + h.workqueue.Forget(obj) + h.workqueue.Done(obj) + klog.Errorf("Health check queue item expects string but got %#v", obj) + return true + } + + if err := h.syncHandler(key); err != nil { + h.workqueue.AddRateLimited(key) + return true + } + + h.workqueue.Done(obj) + return true +} + +func (h *manager) syncHandler(key string) error { + + return nil } //// configWatcher support reload rule check config dynamically, no need to restart the agent From a80bc987146e55fb4c25ce6abd2a49d41c7fb9b9 Mon Sep 17 00:00:00 2001 From: wang-mask <2018091609006@std.uestc.edu.cn> Date: Sat, 16 Mar 2024 11:21:09 +0800 Subject: [PATCH 13/59] fix []string type Signed-off-by: wang-mask <2018091609006@std.uestc.edu.cn> --- pkg/caelus/healthcheck/health_check.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/pkg/caelus/healthcheck/health_check.go b/pkg/caelus/healthcheck/health_check.go index 341ce911..0c70e818 100644 --- a/pkg/caelus/healthcheck/health_check.go +++ b/pkg/caelus/healthcheck/health_check.go @@ -43,8 +43,8 @@ import ( const ( checkConfigFile = "/etc/caelus/rules.json" - ruleCheck = "RuleCheck" - cgroupNotify = "CgroupNotify" + ruleCheck = "RuleCheck" + cgroupNotify = "CgroupNotify" ) // Manager is the interface for handling health check @@ -97,7 +97,7 @@ func NewHealthManager(stStore statestore.StateStore, } _, err := hm.ruleCheckInformer.AddEventHandler(cache.ResourceEventHandlerFuncs{ - AddFunc: func(obj interface{}) { + AddFunc: func(obj interface{}) { hm.eventFunc([]string{ruleCheck}) }, UpdateFunc: func(oldObj, newObj interface{}) { @@ -111,7 +111,7 @@ func NewHealthManager(stStore statestore.StateStore, return nil } hm.nodeInformer.AddEventHandler(cache.ResourceEventHandlerFuncs{ - AddFunc: func(obj interface{}) { + AddFunc: func(obj interface{}) { hm.eventFunc([]string{ruleCheck, cgroupNotify}) }, UpdateFunc: func(oldObj, newObj interface{}) { @@ -123,7 +123,7 @@ func NewHealthManager(stStore statestore.StateStore, }) hm.cgroupInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{ - AddFunc: func(obj interface{}) { + AddFunc: func(obj interface{}) { hm.eventFunc([]string{cgroupNotify}) }, UpdateFunc: func(oldObj, newObj interface{}) { @@ -142,9 +142,9 @@ func (h *manager) Name() string { return "ModuleHealthCheck" } -func(h *manager) eventFunc(crds string[])func(obj interface{}){ - return func(obj interface{}){ - for crd := range crds{ +func (h *manager) eventFunc(crds []string) func(obj interface{}) { + return func(obj interface{}) { + for crd := range crds { h.workqueue.Add(crd) } } From cb0d5828a067daa0b80c94719375b5e92ecd57a6 Mon Sep 17 00:00:00 2001 From: wang-mask <2018091609006@std.uestc.edu.cn> Date: Sun, 17 Mar 2024 11:43:17 +0800 Subject: [PATCH 14/59] add node event --- pkg/caelus/healthcheck/health_check.go | 157 +++++++------------------ 1 file changed, 40 insertions(+), 117 deletions(-) diff --git a/pkg/caelus/healthcheck/health_check.go b/pkg/caelus/healthcheck/health_check.go index 0c70e818..32d524a4 100644 --- a/pkg/caelus/healthcheck/health_check.go +++ b/pkg/caelus/healthcheck/health_check.go @@ -17,10 +17,6 @@ package health import ( "context" - "fmt" - "sort" - "strings" - v1 "github.com/tencent/caelus/pkg/apis/caelus/v1" cgroupCrd "github.com/tencent/caelus/pkg/apis/cgroupnotifycrd/v1" notify "github.com/tencent/caelus/pkg/caelus/healthcheck/cgroupnotify" @@ -33,8 +29,12 @@ import ( "github.com/tencent/caelus/pkg/caelus/util" cgroupInformer "github.com/tencent/caelus/pkg/cgroupClient/informers/externalversions/cgroupnotifycrd/v1" caelusclient "github.com/tencent/caelus/pkg/generated/clientset/versioned" + "reflect" + "sort" + corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + informerv1 "k8s.io/client-go/informers/core/v1" clientset "k8s.io/client-go/kubernetes" "k8s.io/client-go/tools/cache" "k8s.io/client-go/util/workqueue" @@ -64,7 +64,7 @@ type manager struct { qosManager qos.Manager conflictMn conflict.Manager podInformer cache.SharedIndexInformer - nodeInformer cache.SharedIndexInformer + nodeInformer informerv1.NodeInformer workqueue workqueue.RateLimitingInterface configHash string globalStopCh <-chan struct{} @@ -77,7 +77,7 @@ type manager struct { // NewHealthManager create a new health check manager func NewHealthManager(stStore statestore.StateStore, resource resource.Interface, qosManager qos.Manager, conflictMn conflict.Manager, - podInformer cache.SharedIndexInformer, nodeInformer cache.SharedIndexInformer, ruleCheckInformer cache.SharedIndexInformer, cgroupInformer cgroupInformer.CgroupNotifyCrdInformer, + podInformer cache.SharedIndexInformer, nodeInformer informerv1.NodeInformer, ruleCheckInformer cache.SharedIndexInformer, cgroupInformer cgroupInformer.CgroupNotifyCrdInformer, k8sClient clientset.Interface) Manager { // TODO add the informer enent func @@ -110,15 +110,11 @@ func NewHealthManager(stStore statestore.StateStore, if err != nil { return nil } - hm.nodeInformer.AddEventHandler(cache.ResourceEventHandlerFuncs{ - AddFunc: func(obj interface{}) { - hm.eventFunc([]string{ruleCheck, cgroupNotify}) - }, + hm.nodeInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{ UpdateFunc: func(oldObj, newObj interface{}) { - hm.eventFunc([]string{ruleCheck, cgroupNotify}) - }, - DeleteFunc: func(obj interface{}) { - hm.eventFunc([]string{ruleCheck, cgroupNotify}) + if isLocalEventAndLabelChanged(oldObj, newObj) { + hm.eventFunc([]string{ruleCheck, cgroupNotify}) + } }, }) @@ -150,58 +146,11 @@ func (h *manager) eventFunc(crds []string) func(obj interface{}) { } } -//// reload rule check config dynamically without restarting the agent -//func (h *manager) reload() { -// reload, hash, config := h.checkNeedReload(checkConfigFile) -// if !reload { -// return -// } -// h.configHash = hash -// h.ruleChecker.Stop() -// h.cgroupNotifier.Stop() -// h.config = config -// h.ruleChecker = rulecheck.NewManager(config.RuleCheck, h.stStore, h.resource, h.qosManager, h.conflictMn, -// h.podInformer, config.PredictReserved) -// h.cgroupNotifier = notify.NewNotifyManager(&config.CgroupNotify, h.resource) -// go h.ruleChecker.Run(h.globalStopCh) -// go h.cgroupNotifier.Run(h.globalStopCh) -//} - -//// checkNeedReload checks if the config file is changed -//func (h *manager) checkNeedReload(configFile string) (bool, string, *types.HealthCheckConfig) { -// hash, err := hashFile(configFile) -// if err != nil { -// klog.Errorf("failed hash config file: %v", err) -// return false, "", nil -// } -// if hash == h.configHash { -// return false, "", nil -// } -// config, err := h.configUpdateFunc(configFile) -// if err != nil { -// klog.Fatalf("failed init health check config: %v", err) -// } -// if len(config.RuleNodes) != 0 { -// found := false -// for _, no := range config.RuleNodes { -// if no == util.NodeIP() { -// found = true -// break -// } -// } -// if !found { -// return false, "", nil -// } -// } -// -// return true, hash, config -//} - // Run start checking health func (h *manager) Run(stop <-chan struct{}) { // the function is running in the informer evnet func h.globalStopCh = stop - go h.runWorker(stop) + go h.runWorker() } func (h *manager) runWorker() { @@ -244,48 +193,9 @@ func (h *manager) syncHandler(key string) error { return nil } -//// configWatcher support reload rule check config dynamically, no need to restart the agent -//func (h *manager) configWatcher(stop <-chan struct{}) { -// w, err := fsnotify.NewWatcher() -// if err != nil { -// klog.Fatalf("failed init fsnotify watcher: %v", err) -// } -// defer w.Close() -// err = w.Add(filepath.Dir(checkConfigFile)) -// if err != nil { -// klog.Fatalf("failed add dir watcher(%s): %v", filepath.Dir(checkConfigFile), err) -// } -// for { -// select { -// case <-w.Events: -// h.reload() -// case err := <-w.Errors: -// klog.Errorf("fsnotify error: %v", err) -// case <-stop: -// return -// } -// } -//} -// -//// hashFile generate hash code for the file -//func hashFile(filePath string) (string, error) { -// file, err := os.Open(filePath) -// if err != nil { -// return "", err -// } -// defer file.Close() -// hash := md5.New() -// if _, err = io.Copy(hash, file); err != nil { -// return "", err -// } -// h := hash.Sum(nil)[:16] -// hs := hex.EncodeToString(h) -// return hs, nil -//} - // updateRuleCheck update the ruleChecker by the config -func (h *manager) updateRuleCheck() error { - matched, err := h.isLabelMatched(h.config.CgroupNotify.Labels) +func (h *manager) reRunRuleCheck() error { + matched, err := h.isLabelMatchedLocalNode(h.config.CgroupNotify.Labels) if err != nil { return err } @@ -307,8 +217,8 @@ func (h *manager) updateRuleCheck() error { } // updateCgroupNotifier update the cgroupNotifier by the config -func (h *manager) updateCgroupNotifier() error { - matched, err := h.isLabelMatched(h.config.CgroupNotify.Labels) +func (h *manager) reRunCgroupNotifier() error { + matched, err := h.isLabelMatchedLocalNode(h.config.CgroupNotify.Labels) if err != nil { return err } @@ -331,26 +241,21 @@ func (h *manager) updateCgroupNotifier() error { } // isLabelMatched determines whether the labels match this node -func (h *manager) isLabelMatched(labels map[string]string) (bool, error) { +func (h *manager) isLabelMatchedLocalNode(labels map[string]string) (bool, error) { if len(labels) == 0 { return true, nil } - selectors := make([]string, len(labels)) - index := 0 - for key, val := range labels { - selectors[index] = fmt.Sprintf("%s=%s", key, val) - index += 1 - } - nodes, err := h.k8sClient.CoreV1().Nodes().List(context.TODO(), metav1.ListOptions{LabelSelector: strings.Join(selectors, ",")}) + + node, err := h.nodeInformer.Lister().Get(util.NodeName()) if err != nil { return false, err } - for _, node := range nodes.Items { - if node.Name == util.NodeName() { - return true, nil + for key, val := range labels { + if val != node.Labels[key] { + return false, nil } } - return false, nil + return true, nil } func (h *manager) OnAddCgropNotify(obj interface{}) { @@ -483,3 +388,21 @@ func convertK8sRuleCheck(k8sRuleCheck *v1.RuleCheck, ruleCheck *types.RuleCheckC ruleCheck.HandleInterval = *k8sRuleCheck.Spec.HandleInterval ruleCheck.NodeSelector = k8sRuleCheck.Spec.NodeSelector } + +// determine whether this event happened in local node and label changed +func isLocalEventAndLabelChanged(oldObj, newObj interface{}) bool { + old, ok := oldObj.(*corev1.Node) + if !ok { + return false + } + new, ok := newObj.(*corev1.Node) + if !ok { + return false + } + + if new.Name != util.NodeName() { + return false + } + + return !reflect.DeepEqual(old.Labels, new.Labels) +} From e8afda4056eb0eb8cfd18faffb4cd53eafdacaab Mon Sep 17 00:00:00 2001 From: wang-mask <2018091609006@std.uestc.edu.cn> Date: Sun, 17 Mar 2024 11:43:39 +0800 Subject: [PATCH 15/59] update informer --- cmd/caelus/app/server.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/caelus/app/server.go b/cmd/caelus/app/server.go index 8ccc8148..31a53ff8 100644 --- a/cmd/caelus/app/server.go +++ b/cmd/caelus/app/server.go @@ -248,7 +248,7 @@ func (o *options) initModules(caelus *types.CaelusConfig, ctx *context.CaelusCon // healthCheckManager = health.NewHealthManager(types.InitHealthCheckConfigFunc(&caelus.Metrics.Node, // &caelus.Predicts[0].ReserveResource), stStore, resourceManager, qosManager, // conflictMn, podInformer, xxInformer1, xxInformer2, kubeClient) - nodeInformer := ctx.GetNodeFactory().Core().V1().Nodes().Informer() + nodeInformer := ctx.GetNodeFactory().Core().V1().Nodes() ruleCheckInformer := ctx.GetCaelusFactory().Caelus().V1().RuleChecks().Informer() cgroupNotifyInformer := ctx.GetCgroupNotifyFactory().Cgroupnotifycrd().V1().CgroupNotifyCrds() healthCheckManager = health.NewHealthManager(stStore, resourceManager, qosManager, From b96582487c9212fc0e98212d1427e09c778f4288 Mon Sep 17 00:00:00 2001 From: baowj Date: Mon, 18 Mar 2024 10:43:08 +0800 Subject: [PATCH 16/59] add priority to rulecheck crd 1.add priority to rulecheck crd 2.fix updateRuleCheckConfig bug Signed-off-by: baowj --- pkg/apis/caelus/v1/rulecheck_types.go | 1 + pkg/apis/caelus/v1/zz_generated.deepcopy.go | 5 +++++ pkg/caelus/healthcheck/health_check.go | 1 + 3 files changed, 7 insertions(+) diff --git a/pkg/apis/caelus/v1/rulecheck_types.go b/pkg/apis/caelus/v1/rulecheck_types.go index 5a21d1a7..bab9e311 100644 --- a/pkg/apis/caelus/v1/rulecheck_types.go +++ b/pkg/apis/caelus/v1/rulecheck_types.go @@ -47,6 +47,7 @@ type RuleCheck struct { type RuleCheckSpec struct { Name string `json:"name"` NodeSelector metav1.LabelSelector `json:"nodeSelector"` + Priority *int32 `json:"priority"` Type RuleCheckType `json:"type"` Metrics []string `json:"metrics"` // CheckInterval describes the interval to trigger detection diff --git a/pkg/apis/caelus/v1/zz_generated.deepcopy.go b/pkg/apis/caelus/v1/zz_generated.deepcopy.go index dd906d63..77824405 100644 --- a/pkg/apis/caelus/v1/zz_generated.deepcopy.go +++ b/pkg/apis/caelus/v1/zz_generated.deepcopy.go @@ -150,6 +150,11 @@ func (in *RuleCheckList) DeepCopyObject() runtime.Object { func (in *RuleCheckSpec) DeepCopyInto(out *RuleCheckSpec) { *out = *in in.NodeSelector.DeepCopyInto(&out.NodeSelector) + if in.Priority != nil { + in, out := &in.Priority, &out.Priority + *out = new(int32) + **out = **in + } if in.Metrics != nil { in, out := &in.Metrics, &out.Metrics *out = make([]string, len(*in)) diff --git a/pkg/caelus/healthcheck/health_check.go b/pkg/caelus/healthcheck/health_check.go index 264e682f..50561e74 100644 --- a/pkg/caelus/healthcheck/health_check.go +++ b/pkg/caelus/healthcheck/health_check.go @@ -348,6 +348,7 @@ func (h *manager) updateRuleCheckConfig() error { if _, ok := m[name]; ok { continue } + m[name] = struct{}{} ruleCheck := &types.RuleCheckConfig{} convertK8sRuleCheck(&k8sRuleCheck, ruleCheck) switch k8sRuleCheck.Spec.Type { From 1c0fe51cdccbeb8eb399b22835cd5ffbca97b178 Mon Sep 17 00:00:00 2001 From: baowj Date: Mon, 18 Mar 2024 11:28:50 +0800 Subject: [PATCH 17/59] update updateRuleCheckConfig func Signed-off-by: baowj --- cmd/caelus/app/server.go | 2 +- pkg/caelus/healthcheck/health_check.go | 31 +++++++++++++++----------- pkg/caelus/types/types.go | 4 +++- 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/cmd/caelus/app/server.go b/cmd/caelus/app/server.go index 31a53ff8..8de50e28 100644 --- a/cmd/caelus/app/server.go +++ b/cmd/caelus/app/server.go @@ -249,7 +249,7 @@ func (o *options) initModules(caelus *types.CaelusConfig, ctx *context.CaelusCon // &caelus.Predicts[0].ReserveResource), stStore, resourceManager, qosManager, // conflictMn, podInformer, xxInformer1, xxInformer2, kubeClient) nodeInformer := ctx.GetNodeFactory().Core().V1().Nodes() - ruleCheckInformer := ctx.GetCaelusFactory().Caelus().V1().RuleChecks().Informer() + ruleCheckInformer := ctx.GetCaelusFactory().Caelus().V1().RuleChecks() cgroupNotifyInformer := ctx.GetCgroupNotifyFactory().Cgroupnotifycrd().V1().CgroupNotifyCrds() healthCheckManager = health.NewHealthManager(stStore, resourceManager, qosManager, conflictMn, podInformer, nodeInformer, ruleCheckInformer, cgroupNotifyInformer, ctx.GetKubeClient()) diff --git a/pkg/caelus/healthcheck/health_check.go b/pkg/caelus/healthcheck/health_check.go index a79be7d2..f8bee91a 100644 --- a/pkg/caelus/healthcheck/health_check.go +++ b/pkg/caelus/healthcheck/health_check.go @@ -16,7 +16,9 @@ package health import ( - "context" + "reflect" + "sort" + v1 "github.com/tencent/caelus/pkg/apis/caelus/v1" cgroupCrd "github.com/tencent/caelus/pkg/apis/cgroupnotifycrd/v1" notify "github.com/tencent/caelus/pkg/caelus/healthcheck/cgroupnotify" @@ -28,12 +30,11 @@ import ( "github.com/tencent/caelus/pkg/caelus/types" "github.com/tencent/caelus/pkg/caelus/util" cgroupInformer "github.com/tencent/caelus/pkg/cgroupClient/informers/externalversions/cgroupnotifycrd/v1" - caelusclient "github.com/tencent/caelus/pkg/generated/clientset/versioned" - "reflect" - "sort" + caelusv1 "github.com/tencent/caelus/pkg/generated/informers/externalversions/caelus/v1" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + labels2 "k8s.io/apimachinery/pkg/labels" informerv1 "k8s.io/client-go/informers/core/v1" clientset "k8s.io/client-go/kubernetes" "k8s.io/client-go/tools/cache" @@ -68,8 +69,7 @@ type manager struct { workqueue workqueue.RateLimitingInterface configHash string globalStopCh <-chan struct{} - ruleCheckInformer cache.SharedIndexInformer - caelusClient caelusclient.Clientset + ruleCheckInformer caelusv1.RuleCheckInformer cgroupInformer cgroupInformer.CgroupNotifyCrdInformer k8sClient clientset.Interface } @@ -77,7 +77,7 @@ type manager struct { // NewHealthManager create a new health check manager func NewHealthManager(stStore statestore.StateStore, resource resource.Interface, qosManager qos.Manager, conflictMn conflict.Manager, - podInformer cache.SharedIndexInformer, nodeInformer informerv1.NodeInformer, ruleCheckInformer cache.SharedIndexInformer, cgroupInformer cgroupInformer.CgroupNotifyCrdInformer, + podInformer cache.SharedIndexInformer, nodeInformer informerv1.NodeInformer, ruleCheckInformer caelusv1.RuleCheckInformer, cgroupInformer cgroupInformer.CgroupNotifyCrdInformer, k8sClient clientset.Interface) Manager { // TODO add the informer enent func @@ -96,7 +96,7 @@ func NewHealthManager(stStore statestore.StateStore, cgroupInformer: cgroupInformer, } - _, err := hm.ruleCheckInformer.AddEventHandler(cache.ResourceEventHandlerFuncs{ + _, err := hm.ruleCheckInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{ AddFunc: func(obj interface{}) { hm.eventFunc([]string{ruleCheck}) }, @@ -313,14 +313,16 @@ func (h *manager) updateCgroupConfig(obj interface{}, isDelete bool) { // update local RuleCheck func (h *manager) updateRuleCheckConfig() error { - ctx := context.Background() - list, err := h.caelusClient.CaelusV1().RuleChecks("caelus-system").List(ctx, metav1.ListOptions{}) + ruleChecks, err := h.ruleCheckInformer.Lister().RuleChecks(types.CaelusNamespace).List(labels2.SelectorFromSet(nil)) if err != nil { return err } - ruleChecks := list.Items sort.Slice(ruleChecks, func(i, j int) bool { - return ruleChecks[i].CreationTimestamp.Time.After(ruleChecks[i].CreationTimestamp.Time) + if *(ruleChecks[i].Spec.Priority) == *(ruleChecks[j].Spec.Priority) { + return ruleChecks[i].CreationTimestamp.Time.After(ruleChecks[i].CreationTimestamp.Time) + } else { + return *(ruleChecks[i].Spec.Priority) > *(ruleChecks[j].Spec.Priority) + } }) m := map[string]struct{}{} @@ -328,13 +330,16 @@ func (h *manager) updateRuleCheckConfig() error { nodeRuleChecks := []*types.RuleCheckConfig{} containerRuleChecks := []*types.RuleCheckConfig{} for _, k8sRuleCheck := range ruleChecks { + if ok, err := h.isLabelMatchedLocalNode(k8sRuleCheck.Spec.NodeSelector.MatchLabels); err != nil || !ok { + continue + } name := string(k8sRuleCheck.Spec.Type) + ":" + k8sRuleCheck.Spec.Name if _, ok := m[name]; ok { continue } m[name] = struct{}{} ruleCheck := &types.RuleCheckConfig{} - convertK8sRuleCheck(&k8sRuleCheck, ruleCheck) + convertK8sRuleCheck(k8sRuleCheck, ruleCheck) switch k8sRuleCheck.Spec.Type { case v1.AppType: appRuleChecks = append(appRuleChecks, ruleCheck) diff --git a/pkg/caelus/types/types.go b/pkg/caelus/types/types.go index 3cd4a89a..d0c0d4c0 100644 --- a/pkg/caelus/types/types.go +++ b/pkg/caelus/types/types.go @@ -31,7 +31,7 @@ import ( "github.com/tencent/caelus/pkg/caelus/util/cgroup" "github.com/tencent/caelus/pkg/util/times" - "k8s.io/api/core/v1" + v1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/util/sets" "k8s.io/klog/v2" ) @@ -40,6 +40,8 @@ import ( type MetricKind string const ( + // Namespace + CaelusNamespace = "caelus-system" // TaskType OnlineTypeOnK8s = "k8s" OnlineTypeOnLocal = "local" From 03b03b53a68acabdebbca9e50f6859410f45c5d9 Mon Sep 17 00:00:00 2001 From: wang-mask <2018091609006@std.uestc.edu.cn> Date: Mon, 18 Mar 2024 16:36:35 +0800 Subject: [PATCH 18/59] delete comment --- cmd/caelus/app/server.go | 6 +----- cmd/caelus/context/context.go | 3 --- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/cmd/caelus/app/server.go b/cmd/caelus/app/server.go index 8de50e28..a9190065 100644 --- a/cmd/caelus/app/server.go +++ b/cmd/caelus/app/server.go @@ -244,15 +244,11 @@ func (o *options) initModules(caelus *types.CaelusConfig, ctx *context.CaelusCon o.ApiOption.loadStatsMetric(metrics.StatsMetricDiskQuota, diskquotaManager) } // health check manager - // xxInformer := ctx.GetxxxFactory() - // healthCheckManager = health.NewHealthManager(types.InitHealthCheckConfigFunc(&caelus.Metrics.Node, - // &caelus.Predicts[0].ReserveResource), stStore, resourceManager, qosManager, - // conflictMn, podInformer, xxInformer1, xxInformer2, kubeClient) nodeInformer := ctx.GetNodeFactory().Core().V1().Nodes() ruleCheckInformer := ctx.GetCaelusFactory().Caelus().V1().RuleChecks() cgroupNotifyInformer := ctx.GetCgroupNotifyFactory().Cgroupnotifycrd().V1().CgroupNotifyCrds() healthCheckManager = health.NewHealthManager(stStore, resourceManager, qosManager, - conflictMn, podInformer, nodeInformer, ruleCheckInformer, cgroupNotifyInformer, ctx.GetKubeClient()) + conflictMn, podInformer, nodeInformer, ruleCheckInformer, cgroupNotifyInformer) modules = append(modules, healthCheckManager) return modules diff --git a/cmd/caelus/context/context.go b/cmd/caelus/context/context.go index 12acb60c..f48bd591 100644 --- a/cmd/caelus/context/context.go +++ b/cmd/caelus/context/context.go @@ -171,8 +171,6 @@ func (c *CaelusContext) GetNodeFactory() informers.SharedInformerFactory { return c.nodeFactory } -// TODO add GetxxxxFactory returns xxx factory - // Name module name func (c *CaelusContext) Name() string { return "ModuleContext" @@ -196,5 +194,4 @@ func (c *CaelusContext) Run(stop <-chan struct{}) { c.cgroupNotifyFactory.Start(stop) c.cgroupNotifyFactory.WaitForCacheSync(stop) } - // TODO run xx informers } From fe1b1a9f56a152ec3458416a6ac76e2526a30fbe Mon Sep 17 00:00:00 2001 From: wang-mask <2018091609006@std.uestc.edu.cn> Date: Mon, 18 Mar 2024 16:37:04 +0800 Subject: [PATCH 19/59] delete rwmutux --- pkg/caelus/healthcheck/rulecheck/rule_check.go | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/pkg/caelus/healthcheck/rulecheck/rule_check.go b/pkg/caelus/healthcheck/rulecheck/rule_check.go index f907d10f..38ee51c3 100644 --- a/pkg/caelus/healthcheck/rulecheck/rule_check.go +++ b/pkg/caelus/healthcheck/rulecheck/rule_check.go @@ -45,8 +45,7 @@ type Manager struct { checkers []ruleChecker dispatcher *dispatcher.Dispatcher - stopCh chan struct{} - rwMutex sync.RWMutex + stopCh chan struct{} } // NewManager return a new rule check manager @@ -79,7 +78,6 @@ func (r *Manager) Run(stopCh <-chan struct{}) { return default: } - r.rwMutex.RLock() wg := sync.WaitGroup{} finalAC := &action.ActionResult{ UnscheduleMap: make(map[string]bool), @@ -100,7 +98,6 @@ func (r *Manager) Run(stopCh <-chan struct{}) { }() } wg.Wait() - r.rwMutex.RUnlock() // no need dispatch result when action is useless if actionResultAvailable(finalAC) { @@ -131,16 +128,3 @@ func actionResultAvailable(ac *action.ActionResult) bool { return false } - -func (r *Manager) UpdateManager(config types.RuleCheck, stStore statestore.StateStore, podInformer cache.SharedIndexInformer, - predictReserved *types.Resource) { - r.rwMutex.Lock() - defer r.rwMutex.Unlock() - - var checkers []ruleChecker - checkers = append(checkers, newContainerHealthChecker(stStore, podInformer, config.ContainerRules)) - checkers = append(checkers, newNodeHealthChecker(stStore, predictReserved, config.NodeRules)) - checkers = append(checkers, newAppHealthChecker(stStore, config.AppRules)) - - r.checkers = checkers -} From 517511a1db5d86751619f16d4da35ff6b7c4bf51 Mon Sep 17 00:00:00 2001 From: wang-mask <2018091609006@std.uestc.edu.cn> Date: Mon, 18 Mar 2024 16:37:47 +0800 Subject: [PATCH 20/59] update the framework and filter the event --- pkg/caelus/healthcheck/health_check.go | 204 +++++++++++++------------ 1 file changed, 110 insertions(+), 94 deletions(-) diff --git a/pkg/caelus/healthcheck/health_check.go b/pkg/caelus/healthcheck/health_check.go index f8bee91a..1fa56083 100644 --- a/pkg/caelus/healthcheck/health_check.go +++ b/pkg/caelus/healthcheck/health_check.go @@ -36,7 +36,6 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" labels2 "k8s.io/apimachinery/pkg/labels" informerv1 "k8s.io/client-go/informers/core/v1" - clientset "k8s.io/client-go/kubernetes" "k8s.io/client-go/tools/cache" "k8s.io/client-go/util/workqueue" "k8s.io/klog" @@ -66,69 +65,75 @@ type manager struct { conflictMn conflict.Manager podInformer cache.SharedIndexInformer nodeInformer informerv1.NodeInformer + ruleCheckInformer caelusv1.RuleCheckInformer + cgroupInformer cgroupInformer.CgroupNotifyCrdInformer workqueue workqueue.RateLimitingInterface configHash string globalStopCh <-chan struct{} - ruleCheckInformer caelusv1.RuleCheckInformer - cgroupInformer cgroupInformer.CgroupNotifyCrdInformer - k8sClient clientset.Interface } // NewHealthManager create a new health check manager func NewHealthManager(stStore statestore.StateStore, resource resource.Interface, qosManager qos.Manager, conflictMn conflict.Manager, - podInformer cache.SharedIndexInformer, nodeInformer informerv1.NodeInformer, ruleCheckInformer caelusv1.RuleCheckInformer, cgroupInformer cgroupInformer.CgroupNotifyCrdInformer, - k8sClient clientset.Interface) Manager { - - // TODO add the informer enent func + podInformer cache.SharedIndexInformer, nodeInformer informerv1.NodeInformer, + ruleCheckInformer caelusv1.RuleCheckInformer, cgroupInformer cgroupInformer.CgroupNotifyCrdInformer) Manager { hm := &manager{ - stStore: stStore, - resource: resource, - qosManager: qosManager, - conflictMn: conflictMn, - podInformer: podInformer, - nodeInformer: nodeInformer, - workqueue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "health-check-queue"), - k8sClient: k8sClient, - // add informer + stStore: stStore, + resource: resource, + qosManager: qosManager, + conflictMn: conflictMn, + podInformer: podInformer, + nodeInformer: nodeInformer, + workqueue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "health-check-queue"), ruleCheckInformer: ruleCheckInformer, cgroupInformer: cgroupInformer, } _, err := hm.ruleCheckInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{ AddFunc: func(obj interface{}) { - hm.eventFunc([]string{ruleCheck}) + hm.eventFunc([]interface{}{obj}, ruleCheck) }, UpdateFunc: func(oldObj, newObj interface{}) { - hm.eventFunc([]string{ruleCheck}) + hm.eventFunc([]interface{}{oldObj, newObj}, ruleCheck) }, DeleteFunc: func(obj interface{}) { - hm.eventFunc([]string{ruleCheck}) + hm.eventFunc([]interface{}{obj}, ruleCheck) }, }) if err != nil { + klog.Error("Failed to add RuleCheck event func", err) return nil } - hm.nodeInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{ + + _, err = hm.nodeInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{ UpdateFunc: func(oldObj, newObj interface{}) { - if isLocalEventAndLabelChanged(oldObj, newObj) { - hm.eventFunc([]string{ruleCheck, cgroupNotify}) + if isLocalNodeEventAndLabelChanged(oldObj, newObj) { + hm.workqueue.Add(cgroupNotify) + hm.workqueue.Add(ruleCheck) } }, }) + if err != nil { + klog.Error("Failed to add Node event func", err) + return nil + } - hm.cgroupInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{ + _, err = hm.cgroupInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{ AddFunc: func(obj interface{}) { - hm.eventFunc([]string{cgroupNotify}) + hm.eventFunc([]interface{}{obj}, cgroupNotify) }, UpdateFunc: func(oldObj, newObj interface{}) { - hm.eventFunc([]string{cgroupNotify}) + hm.eventFunc([]interface{}{oldObj, newObj}, cgroupNotify) }, DeleteFunc: func(obj interface{}) { - hm.eventFunc([]string{cgroupNotify}) + hm.eventFunc([]interface{}{obj}, cgroupNotify) }, }) + if err != nil { + klog.Error("Failed to add CgroupNotify event func", err) + return nil + } return hm } @@ -138,11 +143,10 @@ func (h *manager) Name() string { return "ModuleHealthCheck" } -func (h *manager) eventFunc(crds []string) func(obj interface{}) { - return func(obj interface{}) { - for crd := range crds { - h.workqueue.Add(crd) - } +// filter the event affects local node and add cr type to the queue +func (h *manager) eventFunc(crs []interface{}, crd string) { + if h.isAffectingLocalNode(crs) { + h.workqueue.Add(crd) } } @@ -150,6 +154,11 @@ func (h *manager) eventFunc(crds []string) func(obj interface{}) { func (h *manager) Run(stop <-chan struct{}) { // the function is running in the informer evnet func h.globalStopCh = stop + + // init the ruleCheck and cgroupNotify for new node + h.workqueue.Add(cgroupNotify) + h.workqueue.Add(ruleCheck) + go h.runWorker() } @@ -180,8 +189,7 @@ func (h *manager) processNextWorkItem() bool { } if err := h.syncHandler(key); err != nil { - h.workqueue.AddRateLimited(key) - return true + h.workqueue.Add(key) } h.workqueue.Done(obj) @@ -189,73 +197,47 @@ func (h *manager) processNextWorkItem() bool { } func (h *manager) syncHandler(key string) error { - - return nil -} - -// updateRuleCheck update the ruleChecker by the config -func (h *manager) reRunRuleCheck() error { - matched, err := h.isLabelMatchedLocalNode(h.config.CgroupNotify.Labels) - if err != nil { - return err - } - - if matched { - if h.ruleChecker == nil { - h.ruleChecker = rulecheck.NewManager(h.config.RuleCheck, h.stStore, h.resource, h.qosManager, h.conflictMn, h.podInformer, h.config.PredictReserved) - h.ruleChecker.Run(h.globalStopCh) - } else { - h.ruleChecker.UpdateManager(h.config.RuleCheck, h.stStore, h.podInformer, h.config.PredictReserved) - } - } else { - if h.ruleChecker != nil { - h.ruleChecker.Stop() - h.ruleChecker = nil + if key == ruleCheck { + err := h.updateRuleCheckConfig() + if err != nil { + return err } + h.reRunRuleCheck() + } else if key == cgroupNotify { + //err := h.updateCgroupConfig() + //if err != nil{ + // return err + //} + //h.reRunCgroupNotifier() } + return nil } -// updateCgroupNotifier update the cgroupNotifier by the config -func (h *manager) reRunCgroupNotifier() error { - matched, err := h.isLabelMatchedLocalNode(h.config.CgroupNotify.Labels) - if err != nil { - return err +// reRunRuleCheck update and rerun the ruleChecker by the config +func (h *manager) reRunRuleCheck() { + if h.ruleChecker != nil { + h.ruleChecker.Stop() } - if matched { - if h.cgroupNotifier != nil { - // in case the cgroupNotifier is not enabled in last update - h.cgroupNotifier.Stop() - } - h.cgroupNotifier = notify.NewNotifyManager(&h.config.CgroupNotify, h.resource) - go h.cgroupNotifier.Run(h.globalStopCh) - } else { - if h.cgroupNotifier != nil { - // if the labels does not match this node, stop the cgroupNotifier - h.cgroupNotifier.Stop() - h.cgroupNotifier = nil - } + h.ruleChecker = rulecheck.NewManager(h.config.RuleCheck, h.stStore, h.resource, h.qosManager, h.conflictMn, h.podInformer, h.config.PredictReserved) + + if h.ruleChecker != nil { + go h.ruleChecker.Run(h.globalStopCh) } - return nil } -// isLabelMatched determines whether the labels match this node -func (h *manager) isLabelMatchedLocalNode(labels map[string]string) (bool, error) { - if len(labels) == 0 { - return true, nil +// reRunCgroupNotifier update and rerun the cgroupNotifier by the config +func (h *manager) reRunCgroupNotifier() { + if h.cgroupNotifier != nil { + h.cgroupNotifier.Stop() } - node, err := h.nodeInformer.Lister().Get(util.NodeName()) - if err != nil { - return false, err - } - for key, val := range labels { - if val != node.Labels[key] { - return false, nil - } + h.cgroupNotifier = notify.NewNotifyManager(&h.config.CgroupNotify, h.resource) + + if h.cgroupNotifier != nil { + go h.cgroupNotifier.Run(h.globalStopCh) } - return true, nil } func (h *manager) OnAddCgropNotify(obj interface{}) { @@ -395,20 +377,54 @@ func convertK8sRuleCheck(k8sRuleCheck *v1.RuleCheck, ruleCheck *types.RuleCheckC ruleCheck.NodeSelector = k8sRuleCheck.Spec.NodeSelector } -// determine whether this event happened in local node and label changed -func isLocalEventAndLabelChanged(oldObj, newObj interface{}) bool { - old, ok := oldObj.(*corev1.Node) +// determine whether this cr event impacts this node +func (h *manager) isAffectingLocalNode(objs []interface{}) bool { + for _, obj := range objs { + if cgroupCr, ok := obj.(cgroupCrd.CgroupNotifyCrd); ok { + if matched, err := h.isLabelMatchedLocalNode(cgroupCr.Labels); matched || err != nil { + return true + } + } else if ruleCheckCr, ok := obj.(v1.RuleCheck); ok { + if matched, err := h.isLabelMatchedLocalNode(ruleCheckCr.Labels); matched || err != nil { + return true + } + } + } + return false +} + +// isLabelMatched determines whether the labels match this node +func (h *manager) isLabelMatchedLocalNode(labels map[string]string) (bool, error) { + if len(labels) == 0 { + return true, nil + } + + node, err := h.nodeInformer.Lister().Get(util.NodeName()) + if err != nil { + return false, err + } + for key, val := range labels { + if val != node.Labels[key] { + return false, nil + } + } + return true, nil +} + +// determine whether this node event happened in local node and label changed +func isLocalNodeEventAndLabelChanged(oldObj, newObj interface{}) bool { + oldCr, ok := oldObj.(*corev1.Node) if !ok { return false } - new, ok := newObj.(*corev1.Node) + newCr, ok := newObj.(*corev1.Node) if !ok { return false } - if new.Name != util.NodeName() { + if newCr.Name != util.NodeName() { return false } - return !reflect.DeepEqual(old.Labels, new.Labels) + return !reflect.DeepEqual(oldCr.Labels, newCr.Labels) } From e20e919f730a79685b8c93876617f4143a67855e Mon Sep 17 00:00:00 2001 From: wang-mask <2018091609006@std.uestc.edu.cn> Date: Mon, 18 Mar 2024 20:10:15 +0800 Subject: [PATCH 21/59] add init the manager --- pkg/caelus/healthcheck/health_check.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkg/caelus/healthcheck/health_check.go b/pkg/caelus/healthcheck/health_check.go index 1fa56083..410dbbb9 100644 --- a/pkg/caelus/healthcheck/health_check.go +++ b/pkg/caelus/healthcheck/health_check.go @@ -78,7 +78,11 @@ func NewHealthManager(stStore statestore.StateStore, podInformer cache.SharedIndexInformer, nodeInformer informerv1.NodeInformer, ruleCheckInformer caelusv1.RuleCheckInformer, cgroupInformer cgroupInformer.CgroupNotifyCrdInformer) Manager { + config := &types.HealthCheckConfig{} hm := &manager{ + config: config, + ruleChecker: rulecheck.NewManager(config.RuleCheck, stStore, resource, qosManager, conflictMn, podInformer, config.PredictReserved), + cgroupNotifier: notify.NewNotifyManager(&config.CgroupNotify, resource), stStore: stStore, resource: resource, qosManager: qosManager, From abd5b72bc5cd44ca5173e2532d55a541dab14a63 Mon Sep 17 00:00:00 2001 From: baowj Date: Mon, 18 Mar 2024 20:46:17 +0800 Subject: [PATCH 22/59] add rulecheck rbac Signed-off-by: baowj --- ...nt.caelus.io_rulechecks.yaml => caelus.io_rulechecks.yaml} | 4 ++-- hack/yaml/caelus.yaml | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) rename config/crd/bases/{tencent.caelus.io_rulechecks.yaml => caelus.io_rulechecks.yaml} (99%) diff --git a/config/crd/bases/tencent.caelus.io_rulechecks.yaml b/config/crd/bases/caelus.io_rulechecks.yaml similarity index 99% rename from config/crd/bases/tencent.caelus.io_rulechecks.yaml rename to config/crd/bases/caelus.io_rulechecks.yaml index 41bd1cdd..f6bc2ebf 100644 --- a/config/crd/bases/tencent.caelus.io_rulechecks.yaml +++ b/config/crd/bases/caelus.io_rulechecks.yaml @@ -4,9 +4,9 @@ kind: CustomResourceDefinition metadata: annotations: controller-gen.kubebuilder.io/version: v0.14.0 - name: rulechecks.caelus.io.tencent + name: rulechecks.caelus.io spec: - group: caelus.io.tencent + group: caelus.io. names: kind: RuleCheck listKind: RuleCheckList diff --git a/hack/yaml/caelus.yaml b/hack/yaml/caelus.yaml index 97fcefa1..bd5b0d1f 100644 --- a/hack/yaml/caelus.yaml +++ b/hack/yaml/caelus.yaml @@ -20,6 +20,10 @@ rules: - apiGroups: [""] resources: ["pods/eviction"] verbs: ["create"] + - apiGroups: ["caelus.io"] + resources: + - rulechecks + verbs: ["list", "watch", "get", "update", "delete"] --- apiVersion: rbac.authorization.k8s.io/v1beta1 kind: ClusterRoleBinding From f409ab8c97dcaa7350039ff142bf213f05acf293 Mon Sep 17 00:00:00 2001 From: baowj Date: Mon, 18 Mar 2024 20:46:47 +0800 Subject: [PATCH 23/59] init empty HealthCheckConfig Signed-off-by: baowj --- pkg/caelus/healthcheck/health_check.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/caelus/healthcheck/health_check.go b/pkg/caelus/healthcheck/health_check.go index 1fa56083..1424fcc4 100644 --- a/pkg/caelus/healthcheck/health_check.go +++ b/pkg/caelus/healthcheck/health_check.go @@ -88,6 +88,7 @@ func NewHealthManager(stStore statestore.StateStore, workqueue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "health-check-queue"), ruleCheckInformer: ruleCheckInformer, cgroupInformer: cgroupInformer, + config: &types.HealthCheckConfig{}, } _, err := hm.ruleCheckInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{ From 666ac6c5c35e4de0f6bb81fefcbcbff028761256 Mon Sep 17 00:00:00 2001 From: baowj Date: Tue, 19 Mar 2024 15:00:22 +0800 Subject: [PATCH 24/59] fix rulecheck CRD yaml bug. Signed-off-by: baowj --- config/crd/bases/caelus.io_rulechecks.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/crd/bases/caelus.io_rulechecks.yaml b/config/crd/bases/caelus.io_rulechecks.yaml index f6bc2ebf..d23efa45 100644 --- a/config/crd/bases/caelus.io_rulechecks.yaml +++ b/config/crd/bases/caelus.io_rulechecks.yaml @@ -6,7 +6,7 @@ metadata: controller-gen.kubebuilder.io/version: v0.14.0 name: rulechecks.caelus.io spec: - group: caelus.io. + group: caelus.io names: kind: RuleCheck listKind: RuleCheckList From 9fa6cb7bc5ae9c87e5f7211f03f97b9c0c6449ac Mon Sep 17 00:00:00 2001 From: baowj Date: Tue, 19 Mar 2024 19:09:53 +0800 Subject: [PATCH 25/59] fix rulecheck nil bug. Signed-off-by: baowj --- pkg/caelus/healthcheck/health_check.go | 9 +++++++-- pkg/caelus/healthcheck/rulecheck/rule_check.go | 14 ++++++++++---- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/pkg/caelus/healthcheck/health_check.go b/pkg/caelus/healthcheck/health_check.go index 3cc8bf6b..e6dfcad3 100644 --- a/pkg/caelus/healthcheck/health_check.go +++ b/pkg/caelus/healthcheck/health_check.go @@ -78,7 +78,13 @@ func NewHealthManager(stStore statestore.StateStore, podInformer cache.SharedIndexInformer, nodeInformer informerv1.NodeInformer, ruleCheckInformer caelusv1.RuleCheckInformer, cgroupInformer cgroupInformer.CgroupNotifyCrdInformer) Manager { - config := &types.HealthCheckConfig{} + config := &types.HealthCheckConfig{ + RuleCheck: types.RuleCheck{ + ContainerRules: []*types.RuleCheckConfig{}, + NodeRules: []*types.RuleCheckConfig{}, + AppRules: []*types.RuleCheckConfig{}, + }, + } hm := &manager{ config: config, ruleChecker: rulecheck.NewManager(config.RuleCheck, stStore, resource, qosManager, conflictMn, podInformer, config.PredictReserved), @@ -92,7 +98,6 @@ func NewHealthManager(stStore statestore.StateStore, workqueue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "health-check-queue"), ruleCheckInformer: ruleCheckInformer, cgroupInformer: cgroupInformer, - config: &types.HealthCheckConfig{}, } _, err := hm.ruleCheckInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{ diff --git a/pkg/caelus/healthcheck/rulecheck/rule_check.go b/pkg/caelus/healthcheck/rulecheck/rule_check.go index 38ee51c3..94fed44d 100644 --- a/pkg/caelus/healthcheck/rulecheck/rule_check.go +++ b/pkg/caelus/healthcheck/rulecheck/rule_check.go @@ -27,7 +27,7 @@ import ( "github.com/tencent/caelus/pkg/caelus/statestore" "github.com/tencent/caelus/pkg/caelus/types" - "k8s.io/api/core/v1" + v1 "k8s.io/api/core/v1" "k8s.io/client-go/tools/cache" "k8s.io/klog/v2" ) @@ -53,9 +53,15 @@ func NewManager(config types.RuleCheck, stStore statestore.StateStore, resource qosManager qos.Manager, conflictMn conflict.Manager, podInformer cache.SharedIndexInformer, predictReserved *types.Resource) *Manager { var checkers []ruleChecker - checkers = append(checkers, newContainerHealthChecker(stStore, podInformer, config.ContainerRules)) - checkers = append(checkers, newNodeHealthChecker(stStore, predictReserved, config.NodeRules)) - checkers = append(checkers, newAppHealthChecker(stStore, config.AppRules)) + if len(config.ContainerRules) > 0 { + checkers = append(checkers, newContainerHealthChecker(stStore, podInformer, config.ContainerRules)) + } + if len(config.NodeRules) > 0 { + checkers = append(checkers, newNodeHealthChecker(stStore, predictReserved, config.NodeRules)) + } + if len(config.AppRules) > 0 { + checkers = append(checkers, newAppHealthChecker(stStore, config.AppRules)) + } return &Manager{ // default global loop check interval From 159e7cb23664b6712fe8410ae32f309c991d5e10 Mon Sep 17 00:00:00 2001 From: baowj Date: Tue, 19 Mar 2024 20:17:17 +0800 Subject: [PATCH 26/59] fix group version error. Signed-off-by: baowj --- pkg/apis/caelus/v1/register.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/apis/caelus/v1/register.go b/pkg/apis/caelus/v1/register.go index 563e55b3..87243168 100644 --- a/pkg/apis/caelus/v1/register.go +++ b/pkg/apis/caelus/v1/register.go @@ -22,7 +22,7 @@ import ( ) // SchemeGroupVersion is group version used to register these objects -var SchemeGroupVersion = schema.GroupVersion{Group: "caelus", Version: "v1"} +var SchemeGroupVersion = schema.GroupVersion{Group: "caelus.io", Version: "v1"} // Kind takes an unqualified kind and returns back a Group qualified GroupKind func Kind(kind string) schema.GroupKind { From acaf1ba06a9e0dca6a0a4d1685f0b77c82c41bbe Mon Sep 17 00:00:00 2001 From: baowj Date: Wed, 20 Mar 2024 11:07:21 +0800 Subject: [PATCH 27/59] update RuleCheck DetectAction Args type Signed-off-by: baowj --- config/crd/bases/caelus.io_rulechecks.yaml | 96 ++++++++++++--------- pkg/apis/caelus/v1/rulecheck_types.go | 6 +- pkg/apis/caelus/v1/zz_generated.deepcopy.go | 11 +-- pkg/caelus/healthcheck/health_check.go | 4 +- 4 files changed, 62 insertions(+), 55 deletions(-) diff --git a/config/crd/bases/caelus.io_rulechecks.yaml b/config/crd/bases/caelus.io_rulechecks.yaml index d23efa45..54e610f4 100644 --- a/config/crd/bases/caelus.io_rulechecks.yaml +++ b/config/crd/bases/caelus.io_rulechecks.yaml @@ -17,7 +17,7 @@ spec: - name: v1 schema: openAPIV3Schema: - description: RuleCheck is the Schema for the rulechecks API + description: RuleCheck is a specification for a RuleCheck resource properties: apiVersion: description: |- @@ -37,7 +37,7 @@ spec: metadata: type: object spec: - description: RuleCheckSpec defines the desired state of RuleCheck + description: RuleCheckSpec is the spec for a RuleCheck resource properties: checkInterval: description: CheckInterval describes the interval to trigger detection @@ -52,13 +52,58 @@ spec: items: type: string type: array + name: + type: string nodeSelector: - additionalProperties: - type: string description: |- - INSERT ADDITIONAL SPEC FIELDS - desired state of cluster - Important: Run "make" to regenerate code after modifying this file + A label selector is a label query over a set of resources. The result of matchLabels and + matchExpressions are ANDed. An empty label selector matches all objects. A null + label selector matches no objects. + properties: + matchExpressions: + description: matchExpressions is a list of label selector requirements. + The requirements are ANDed. + items: + description: |- + A label selector requirement is a selector that contains values, a key, and an operator that + relates the key and values. + properties: + key: + description: key is the label key that the selector applies + to. + type: string + operator: + description: |- + operator represents a key's relationship to a set of values. + Valid operators are In, NotIn, Exists and DoesNotExist. + type: string + values: + description: |- + values is an array of string values. If the operator is In or NotIn, + the values array must be non-empty. If the operator is Exists or DoesNotExist, + the values array must be empty. This array is replaced during a strategic + merge patch. + items: + type: string + type: array + required: + - key + - operator + type: object + type: array + matchLabels: + additionalProperties: + type: string + description: |- + matchLabels is a map of {key,value} pairs. A single {key,value} in the matchLabels + map is equivalent to an element of matchExpressions, whose key field is "key", the + operator is "In", and the values array contains only "value". The requirements are ANDed. + type: object type: object + x-kubernetes-map-type: atomic + priority: + format: int32 + type: integer recoverInterval: description: RecoverInterval describes the interval to recover conflicts after detecting normal result @@ -73,11 +118,6 @@ spec: description: DetectAction define detector config properties: args: - description: |- - RawMessage is a raw encoded JSON value. - It implements Marshaler and Unmarshaler and can - be used to delay JSON decoding or precompute a JSON encoding. - format: byte type: string name: type: string @@ -91,11 +131,6 @@ spec: description: DetectAction define detector config properties: args: - description: |- - RawMessage is a raw encoded JSON value. - It implements Marshaler and Unmarshaler and can - be used to delay JSON decoding or precompute a JSON encoding. - format: byte type: string name: type: string @@ -104,9 +139,6 @@ spec: - name type: object type: array - required: - - actions - - detects type: object type: array rules: @@ -118,11 +150,6 @@ spec: description: DetectAction define detector config properties: args: - description: |- - RawMessage is a raw encoded JSON value. - It implements Marshaler and Unmarshaler and can - be used to delay JSON decoding or precompute a JSON encoding. - format: byte type: string name: type: string @@ -136,11 +163,6 @@ spec: description: DetectAction define detector config properties: args: - description: |- - RawMessage is a raw encoded JSON value. - It implements Marshaler and Unmarshaler and can - be used to delay JSON decoding or precompute a JSON encoding. - format: byte type: string name: type: string @@ -149,31 +171,25 @@ spec: - name type: object type: array - required: - - actions - - detects type: object type: array type: - enum: - - app - - node - - container type: string required: - checkInterval - handleInterval - metrics - - nodeSelector + - name + - priority - recoverInterval - rules - type type: object status: - description: RuleCheckStatus defines the observed state of RuleCheck + description: RuleCheckStatus is the status for a RuleCheck resource type: object + required: + - spec type: object served: true storage: true - subresources: - status: {} diff --git a/pkg/apis/caelus/v1/rulecheck_types.go b/pkg/apis/caelus/v1/rulecheck_types.go index bab9e311..4e2f0138 100644 --- a/pkg/apis/caelus/v1/rulecheck_types.go +++ b/pkg/apis/caelus/v1/rulecheck_types.go @@ -16,8 +16,6 @@ package v1 import ( - "encoding/json" - "github.com/tencent/caelus/pkg/util/times" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -69,8 +67,8 @@ type DetectActionRules struct { // DetectAction define detector config type DetectAction struct { - Name string `json:"name"` - Args json.RawMessage `json:"args"` + Name string `json:"name"` + Args string `json:"args"` } // RuleCheckStatus is the status for a RuleCheck resource diff --git a/pkg/apis/caelus/v1/zz_generated.deepcopy.go b/pkg/apis/caelus/v1/zz_generated.deepcopy.go index 77824405..01cd4d5a 100644 --- a/pkg/apis/caelus/v1/zz_generated.deepcopy.go +++ b/pkg/apis/caelus/v1/zz_generated.deepcopy.go @@ -20,8 +20,6 @@ package v1 import ( - json "encoding/json" - times "github.com/tencent/caelus/pkg/util/times" runtime "k8s.io/apimachinery/pkg/runtime" ) @@ -29,11 +27,6 @@ import ( // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *DetectAction) DeepCopyInto(out *DetectAction) { *out = *in - if in.Args != nil { - in, out := &in.Args, &out.Args - *out = make(json.RawMessage, len(*in)) - copy(*out, *in) - } return } @@ -57,7 +50,7 @@ func (in *DetectActionRules) DeepCopyInto(out *DetectActionRules) { if (*in)[i] != nil { in, out := &(*in)[i], &(*out)[i] *out = new(DetectAction) - (*in).DeepCopyInto(*out) + **out = **in } } } @@ -68,7 +61,7 @@ func (in *DetectActionRules) DeepCopyInto(out *DetectActionRules) { if (*in)[i] != nil { in, out := &(*in)[i], &(*out)[i] *out = new(DetectAction) - (*in).DeepCopyInto(*out) + **out = **in } } } diff --git a/pkg/caelus/healthcheck/health_check.go b/pkg/caelus/healthcheck/health_check.go index e6dfcad3..c3c2bb0c 100644 --- a/pkg/caelus/healthcheck/health_check.go +++ b/pkg/caelus/healthcheck/health_check.go @@ -359,14 +359,14 @@ func convertK8sRuleCheck(k8sRuleCheck *v1.RuleCheck, ruleCheck *types.RuleCheckC for _, detect := range k8sRule.Detects { rule.Detects = append(rule.Detects, &types.DetectConfig{ Name: detect.Name, - ArgsStr: detect.Args, + ArgsStr: []byte(detect.Args), Args: nil, }) } for _, action := range k8sRule.Actions { rule.Actions = append(rule.Actions, &types.ActionConfig{ Name: action.Name, - ArgsStr: action.Args, + ArgsStr: []byte(action.Args), Args: nil, }) } From 1772e83390685f804914ed9f4a8dc353042165be Mon Sep 17 00:00:00 2001 From: baowj Date: Wed, 20 Mar 2024 19:40:39 +0800 Subject: [PATCH 28/59] add RuleCheckAvailableFunc func Signed-off-by: baowj --- cmd/caelus/app/server.go | 4 +- cmd/caelus/context/context.go | 5 +-- pkg/caelus/healthcheck/health_check.go | 59 ++++++++++++++------------ pkg/caelus/types/health_check.go | 6 +++ 4 files changed, 42 insertions(+), 32 deletions(-) diff --git a/cmd/caelus/app/server.go b/cmd/caelus/app/server.go index a9190065..303bc6f0 100644 --- a/cmd/caelus/app/server.go +++ b/cmd/caelus/app/server.go @@ -247,8 +247,10 @@ func (o *options) initModules(caelus *types.CaelusConfig, ctx *context.CaelusCon nodeInformer := ctx.GetNodeFactory().Core().V1().Nodes() ruleCheckInformer := ctx.GetCaelusFactory().Caelus().V1().RuleChecks() cgroupNotifyInformer := ctx.GetCgroupNotifyFactory().Cgroupnotifycrd().V1().CgroupNotifyCrds() + f := types.RuleCheckAvailableFunc(&caelus.Metrics.Node, &caelus.Predicts[0].ReserveResource) healthCheckManager = health.NewHealthManager(stStore, resourceManager, qosManager, - conflictMn, podInformer, nodeInformer, ruleCheckInformer, cgroupNotifyInformer) + conflictMn, podInformer, nodeInformer, ruleCheckInformer, cgroupNotifyInformer, + &caelus.Predicts[0].ReserveResource, f) modules = append(modules, healthCheckManager) return modules diff --git a/cmd/caelus/context/context.go b/cmd/caelus/context/context.go index f48bd591..e9ebaf0e 100644 --- a/cmd/caelus/context/context.go +++ b/cmd/caelus/context/context.go @@ -141,10 +141,7 @@ func (c *CaelusContext) GetPodFactory() informers.SharedInformerFactory { // GetCaelusFactory returns ruleCheck factory func (c *CaelusContext) GetCaelusFactory() caelusinformers.SharedInformerFactory { if c.caelusFactory == nil { - c.caelusFactory = caelusinformers.NewSharedInformerFactoryWithOptions(c.GetCaelusClient(), informerSyncPeriod, - caelusinformers.WithTweakListOptions(func(options *metav1.ListOptions) { - options.FieldSelector = fields.OneTermEqualSelector(nodeNameField, c.NodeName).String() - })) + c.caelusFactory = caelusinformers.NewSharedInformerFactoryWithOptions(c.GetCaelusClient(), informerSyncPeriod) } return c.caelusFactory } diff --git a/pkg/caelus/healthcheck/health_check.go b/pkg/caelus/healthcheck/health_check.go index c3c2bb0c..fcf5cc33 100644 --- a/pkg/caelus/healthcheck/health_check.go +++ b/pkg/caelus/healthcheck/health_check.go @@ -58,25 +58,27 @@ type manager struct { config *types.HealthCheckConfig ruleChecker *rulecheck.Manager // support linux kernel PSI, now just memory event - cgroupNotifier notify.ResourceNotify - stStore statestore.StateStore - resource resource.Interface - qosManager qos.Manager - conflictMn conflict.Manager - podInformer cache.SharedIndexInformer - nodeInformer informerv1.NodeInformer - ruleCheckInformer caelusv1.RuleCheckInformer - cgroupInformer cgroupInformer.CgroupNotifyCrdInformer - workqueue workqueue.RateLimitingInterface - configHash string - globalStopCh <-chan struct{} + cgroupNotifier notify.ResourceNotify + stStore statestore.StateStore + resource resource.Interface + qosManager qos.Manager + conflictMn conflict.Manager + podInformer cache.SharedIndexInformer + nodeInformer informerv1.NodeInformer + ruleCheckInformer caelusv1.RuleCheckInformer + cgroupInformer cgroupInformer.CgroupNotifyCrdInformer + workqueue workqueue.RateLimitingInterface + configHash string + globalStopCh <-chan struct{} + ruleCheckAvailableFunc func(ruleCheck *types.RuleCheckConfig) } // NewHealthManager create a new health check manager func NewHealthManager(stStore statestore.StateStore, resource resource.Interface, qosManager qos.Manager, conflictMn conflict.Manager, podInformer cache.SharedIndexInformer, nodeInformer informerv1.NodeInformer, - ruleCheckInformer caelusv1.RuleCheckInformer, cgroupInformer cgroupInformer.CgroupNotifyCrdInformer) Manager { + ruleCheckInformer caelusv1.RuleCheckInformer, cgroupInformer cgroupInformer.CgroupNotifyCrdInformer, + resourceType *types.Resource, ruleCheckAvailableFunc func(ruleCheck *types.RuleCheckConfig)) Manager { config := &types.HealthCheckConfig{ RuleCheck: types.RuleCheck{ @@ -84,20 +86,22 @@ func NewHealthManager(stStore statestore.StateStore, NodeRules: []*types.RuleCheckConfig{}, AppRules: []*types.RuleCheckConfig{}, }, + PredictReserved: resourceType, } hm := &manager{ - config: config, - ruleChecker: rulecheck.NewManager(config.RuleCheck, stStore, resource, qosManager, conflictMn, podInformer, config.PredictReserved), - cgroupNotifier: notify.NewNotifyManager(&config.CgroupNotify, resource), - stStore: stStore, - resource: resource, - qosManager: qosManager, - conflictMn: conflictMn, - podInformer: podInformer, - nodeInformer: nodeInformer, - workqueue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "health-check-queue"), - ruleCheckInformer: ruleCheckInformer, - cgroupInformer: cgroupInformer, + config: config, + ruleChecker: rulecheck.NewManager(config.RuleCheck, stStore, resource, qosManager, conflictMn, podInformer, config.PredictReserved), + cgroupNotifier: notify.NewNotifyManager(&config.CgroupNotify, resource), + stStore: stStore, + resource: resource, + qosManager: qosManager, + conflictMn: conflictMn, + podInformer: podInformer, + nodeInformer: nodeInformer, + workqueue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "health-check-queue"), + ruleCheckInformer: ruleCheckInformer, + cgroupInformer: cgroupInformer, + ruleCheckAvailableFunc: ruleCheckAvailableFunc, } _, err := hm.ruleCheckInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{ @@ -331,7 +335,7 @@ func (h *manager) updateRuleCheckConfig() error { } m[name] = struct{}{} ruleCheck := &types.RuleCheckConfig{} - convertK8sRuleCheck(k8sRuleCheck, ruleCheck) + h.convertK8sRuleCheck(k8sRuleCheck, ruleCheck) switch k8sRuleCheck.Spec.Type { case v1.AppType: appRuleChecks = append(appRuleChecks, ruleCheck) @@ -348,7 +352,7 @@ func (h *manager) updateRuleCheckConfig() error { } // convert v1.RuleCheck struct to types.RuleCheckConfig struct -func convertK8sRuleCheck(k8sRuleCheck *v1.RuleCheck, ruleCheck *types.RuleCheckConfig) { +func (h *manager) convertK8sRuleCheck(k8sRuleCheck *v1.RuleCheck, ruleCheck *types.RuleCheckConfig) { convertRules := func(k8sRules []*v1.DetectActionRules) []*types.DetectActionConfig { rules := make([]*types.DetectActionConfig, 0, len(k8sRuleCheck.Spec.Rules)) for _, k8sRule := range k8sRules { @@ -385,6 +389,7 @@ func convertK8sRuleCheck(k8sRuleCheck *v1.RuleCheck, ruleCheck *types.RuleCheckC ruleCheck.RecoverInterval = *k8sRuleCheck.Spec.RecoverInterval ruleCheck.HandleInterval = *k8sRuleCheck.Spec.HandleInterval ruleCheck.NodeSelector = k8sRuleCheck.Spec.NodeSelector + h.ruleCheckAvailableFunc(ruleCheck) } // determine whether this cr event impacts this node diff --git a/pkg/caelus/types/health_check.go b/pkg/caelus/types/health_check.go index a868cfc2..deadf2ac 100644 --- a/pkg/caelus/types/health_check.go +++ b/pkg/caelus/types/health_check.go @@ -201,6 +201,12 @@ func InitHealthCheckConfigFunc(nodeMetrics *MetricsNodeConfig, } } +func RuleCheckAvailableFunc(nodeMetrics *MetricsNodeConfig, predictReserve *Resource) func(ruleCheck *RuleCheckConfig) { + return func(ruleCheck *RuleCheckConfig) { + ruleCheckAvailable(ruleCheck, nodeMetrics, predictReserve) + } +} + func ruleCheckAvailable(ruleCheck *RuleCheckConfig, nodeMetrics *MetricsNodeConfig, predictReserve *Resource) { if ruleCheck == nil { return From 7ad6ad39fe65556f31b0e27504119a7d58622d3e Mon Sep 17 00:00:00 2001 From: baowj Date: Wed, 20 Mar 2024 19:50:59 +0800 Subject: [PATCH 29/59] update rulecheck crd nodeselector type Signed-off-by: baowj --- config/crd/bases/caelus.io_rulechecks.yaml | 47 +-------------------- pkg/apis/caelus/v1/rulecheck_types.go | 10 ++--- pkg/apis/caelus/v1/zz_generated.deepcopy.go | 8 +++- pkg/caelus/types/health_check.go | 3 +- 4 files changed, 15 insertions(+), 53 deletions(-) diff --git a/config/crd/bases/caelus.io_rulechecks.yaml b/config/crd/bases/caelus.io_rulechecks.yaml index 54e610f4..be9dc221 100644 --- a/config/crd/bases/caelus.io_rulechecks.yaml +++ b/config/crd/bases/caelus.io_rulechecks.yaml @@ -55,52 +55,9 @@ spec: name: type: string nodeSelector: - description: |- - A label selector is a label query over a set of resources. The result of matchLabels and - matchExpressions are ANDed. An empty label selector matches all objects. A null - label selector matches no objects. - properties: - matchExpressions: - description: matchExpressions is a list of label selector requirements. - The requirements are ANDed. - items: - description: |- - A label selector requirement is a selector that contains values, a key, and an operator that - relates the key and values. - properties: - key: - description: key is the label key that the selector applies - to. - type: string - operator: - description: |- - operator represents a key's relationship to a set of values. - Valid operators are In, NotIn, Exists and DoesNotExist. - type: string - values: - description: |- - values is an array of string values. If the operator is In or NotIn, - the values array must be non-empty. If the operator is Exists or DoesNotExist, - the values array must be empty. This array is replaced during a strategic - merge patch. - items: - type: string - type: array - required: - - key - - operator - type: object - type: array - matchLabels: - additionalProperties: - type: string - description: |- - matchLabels is a map of {key,value} pairs. A single {key,value} in the matchLabels - map is equivalent to an element of matchExpressions, whose key field is "key", the - operator is "In", and the values array contains only "value". The requirements are ANDed. - type: object + additionalProperties: + type: string type: object - x-kubernetes-map-type: atomic priority: format: int32 type: integer diff --git a/pkg/apis/caelus/v1/rulecheck_types.go b/pkg/apis/caelus/v1/rulecheck_types.go index 4e2f0138..d91c955b 100644 --- a/pkg/apis/caelus/v1/rulecheck_types.go +++ b/pkg/apis/caelus/v1/rulecheck_types.go @@ -43,11 +43,11 @@ type RuleCheck struct { // RuleCheckSpec is the spec for a RuleCheck resource type RuleCheckSpec struct { - Name string `json:"name"` - NodeSelector metav1.LabelSelector `json:"nodeSelector"` - Priority *int32 `json:"priority"` - Type RuleCheckType `json:"type"` - Metrics []string `json:"metrics"` + Name string `json:"name"` + NodeSelector map[string]string `json:"nodeSelector"` + Priority *int32 `json:"priority"` + Type RuleCheckType `json:"type"` + Metrics []string `json:"metrics"` // CheckInterval describes the interval to trigger detection CheckInterval *times.Duration `json:"checkInterval"` // HandleInterval describes the interval to handle conflicts after detecting abnormal result diff --git a/pkg/apis/caelus/v1/zz_generated.deepcopy.go b/pkg/apis/caelus/v1/zz_generated.deepcopy.go index 01cd4d5a..9fa06477 100644 --- a/pkg/apis/caelus/v1/zz_generated.deepcopy.go +++ b/pkg/apis/caelus/v1/zz_generated.deepcopy.go @@ -142,7 +142,13 @@ func (in *RuleCheckList) DeepCopyObject() runtime.Object { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *RuleCheckSpec) DeepCopyInto(out *RuleCheckSpec) { *out = *in - in.NodeSelector.DeepCopyInto(&out.NodeSelector) + if in.NodeSelector != nil { + in, out := &in.NodeSelector, &out.NodeSelector + *out = make(map[string]string, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } if in.Priority != nil { in, out := &in.Priority, &out.Priority *out = new(int32) diff --git a/pkg/caelus/types/health_check.go b/pkg/caelus/types/health_check.go index deadf2ac..2264a326 100644 --- a/pkg/caelus/types/health_check.go +++ b/pkg/caelus/types/health_check.go @@ -25,7 +25,6 @@ import ( "github.com/tencent/caelus/pkg/caelus/util/machine" "github.com/tencent/caelus/pkg/util/times" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/sets" "k8s.io/klog/v2" ) @@ -108,7 +107,7 @@ type RuleCheck struct { // RuleCheckConfig define the rule config type RuleCheckConfig struct { Name string `json:"name"` - NodeSelector v1.LabelSelector `json:"node_selector"` + NodeSelector map[string]string `json:"node_selector"` Metrics []string `json:"metrics"` Labels map[string]string `json:"labels"` // CheckInterval describes the interval to trigger detection From 85899745a95468ce430b91eccec01114d0a3e6ad Mon Sep 17 00:00:00 2001 From: wang-mask <2018091609006@std.uestc.edu.cn> Date: Wed, 20 Mar 2024 19:54:47 +0800 Subject: [PATCH 30/59] fix tyep to *type and change label to nodeselector --- pkg/caelus/healthcheck/health_check.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/pkg/caelus/healthcheck/health_check.go b/pkg/caelus/healthcheck/health_check.go index fcf5cc33..e53d75f4 100644 --- a/pkg/caelus/healthcheck/health_check.go +++ b/pkg/caelus/healthcheck/health_check.go @@ -211,6 +211,7 @@ func (h *manager) processNextWorkItem() bool { } func (h *manager) syncHandler(key string) error { + klog.Infof("---- Start syncHandler %v: %v", key, *h.config) if key == ruleCheck { err := h.updateRuleCheckConfig() if err != nil { @@ -225,6 +226,7 @@ func (h *manager) syncHandler(key string) error { //h.reRunCgroupNotifier() } + klog.Infof("---- After syncHandler %v: %v", key, *h.config) return nil } @@ -256,17 +258,17 @@ func (h *manager) reRunCgroupNotifier() { func (h *manager) OnAddCgropNotify(obj interface{}) { h.updateCgroupConfig(obj, false) - h.updateCgroupNotifier() + h.reRunCgroupNotifier() } func (h *manager) OnUpdateCgropNotify(oldObj, newObj interface{}) { h.updateCgroupConfig(newObj, false) - h.updateCgroupNotifier() + h.reRunCgroupNotifier() } func (h *manager) OnDeleteCgropNotify(obj interface{}) { h.updateCgroupConfig(obj, true) - h.updateCgroupNotifier() + h.reRunCgroupNotifier() } func (h *manager) CgroupCrddeepCopy(cgroupCrd *cgroupCrd.CgroupNotifyCrd) { @@ -395,12 +397,12 @@ func (h *manager) convertK8sRuleCheck(k8sRuleCheck *v1.RuleCheck, ruleCheck *typ // determine whether this cr event impacts this node func (h *manager) isAffectingLocalNode(objs []interface{}) bool { for _, obj := range objs { - if cgroupCr, ok := obj.(cgroupCrd.CgroupNotifyCrd); ok { - if matched, err := h.isLabelMatchedLocalNode(cgroupCr.Labels); matched || err != nil { + if cgroupCr, ok := obj.(*cgroupCrd.CgroupNotifyCrd); ok { + if matched, err := h.isLabelMatchedLocalNode(cgroupCr.Spec.NodeSelector); matched || err != nil { return true } - } else if ruleCheckCr, ok := obj.(v1.RuleCheck); ok { - if matched, err := h.isLabelMatchedLocalNode(ruleCheckCr.Labels); matched || err != nil { + } else if ruleCheckCr, ok := obj.(*v1.RuleCheck); ok { + if matched, err := h.isLabelMatchedLocalNode(ruleCheckCr.Spec.NodeSelector); matched || err != nil { return true } } From 6cf0ddaf7d6eb2e17de77a0c8a2e47de9ab61740 Mon Sep 17 00:00:00 2001 From: wang-mask <2018091609006@std.uestc.edu.cn> Date: Wed, 20 Mar 2024 21:13:04 +0800 Subject: [PATCH 31/59] fix Signed-off-by: wang-mask <2018091609006@std.uestc.edu.cn> --- pkg/caelus/healthcheck/health_check.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/caelus/healthcheck/health_check.go b/pkg/caelus/healthcheck/health_check.go index e53d75f4..a3e8e58f 100644 --- a/pkg/caelus/healthcheck/health_check.go +++ b/pkg/caelus/healthcheck/health_check.go @@ -328,7 +328,7 @@ func (h *manager) updateRuleCheckConfig() error { nodeRuleChecks := []*types.RuleCheckConfig{} containerRuleChecks := []*types.RuleCheckConfig{} for _, k8sRuleCheck := range ruleChecks { - if ok, err := h.isLabelMatchedLocalNode(k8sRuleCheck.Spec.NodeSelector.MatchLabels); err != nil || !ok { + if ok, err := h.isLabelMatchedLocalNode(k8sRuleCheck.Spec.NodeSelector); err != nil || !ok { continue } name := string(k8sRuleCheck.Spec.Type) + ":" + k8sRuleCheck.Spec.Name @@ -398,7 +398,7 @@ func (h *manager) convertK8sRuleCheck(k8sRuleCheck *v1.RuleCheck, ruleCheck *typ func (h *manager) isAffectingLocalNode(objs []interface{}) bool { for _, obj := range objs { if cgroupCr, ok := obj.(*cgroupCrd.CgroupNotifyCrd); ok { - if matched, err := h.isLabelMatchedLocalNode(cgroupCr.Spec.NodeSelector); matched || err != nil { + if matched, err := h.isLabelMatchedLocalNode(cgroupCr.Spec.NodeSelector.MatchLabels); matched || err != nil { return true } } else if ruleCheckCr, ok := obj.(*v1.RuleCheck); ok { From 3bf08724185e0666c07858f4171bb1e1118c3434 Mon Sep 17 00:00:00 2001 From: wang-mask <2018091609006@std.uestc.edu.cn> Date: Thu, 21 Mar 2024 10:37:55 +0800 Subject: [PATCH 32/59] update SyncPeriod to 0 Signed-off-by: wang-mask <2018091609006@std.uestc.edu.cn> --- cmd/caelus/context/context.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/caelus/context/context.go b/cmd/caelus/context/context.go index e9ebaf0e..2b783b20 100644 --- a/cmd/caelus/context/context.go +++ b/cmd/caelus/context/context.go @@ -141,7 +141,7 @@ func (c *CaelusContext) GetPodFactory() informers.SharedInformerFactory { // GetCaelusFactory returns ruleCheck factory func (c *CaelusContext) GetCaelusFactory() caelusinformers.SharedInformerFactory { if c.caelusFactory == nil { - c.caelusFactory = caelusinformers.NewSharedInformerFactoryWithOptions(c.GetCaelusClient(), informerSyncPeriod) + c.caelusFactory = caelusinformers.NewSharedInformerFactoryWithOptions(c.GetCaelusClient(), 0) } return c.caelusFactory } From 98117b80ff4b0e4e44ce7b8dbf9a711da0895834 Mon Sep 17 00:00:00 2001 From: wang-mask <2018091609006@std.uestc.edu.cn> Date: Thu, 21 Mar 2024 10:39:04 +0800 Subject: [PATCH 33/59] add func to function parameters Signed-off-by: wang-mask <2018091609006@std.uestc.edu.cn> --- cmd/caelus/app/server.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cmd/caelus/app/server.go b/cmd/caelus/app/server.go index 303bc6f0..47a76ca8 100644 --- a/cmd/caelus/app/server.go +++ b/cmd/caelus/app/server.go @@ -247,10 +247,10 @@ func (o *options) initModules(caelus *types.CaelusConfig, ctx *context.CaelusCon nodeInformer := ctx.GetNodeFactory().Core().V1().Nodes() ruleCheckInformer := ctx.GetCaelusFactory().Caelus().V1().RuleChecks() cgroupNotifyInformer := ctx.GetCgroupNotifyFactory().Cgroupnotifycrd().V1().CgroupNotifyCrds() - f := types.RuleCheckAvailableFunc(&caelus.Metrics.Node, &caelus.Predicts[0].ReserveResource) - healthCheckManager = health.NewHealthManager(stStore, resourceManager, qosManager, - conflictMn, podInformer, nodeInformer, ruleCheckInformer, cgroupNotifyInformer, - &caelus.Predicts[0].ReserveResource, f) + + healthCheckManager = health.NewHealthManager(stStore, resourceManager, qosManager, conflictMn, podInformer, + nodeInformer, ruleCheckInformer, cgroupNotifyInformer, &caelus.Predicts[0].ReserveResource, + types.RuleCheckAvailableFunc(&caelus.Metrics.Node, &caelus.Predicts[0].ReserveResource)) modules = append(modules, healthCheckManager) return modules From 3633c8eb9e1d6a8c43114d312652465d663e782a Mon Sep 17 00:00:00 2001 From: baowj Date: Thu, 21 Mar 2024 14:50:15 +0800 Subject: [PATCH 34/59] fix updateRuleCheckConfig bug Signed-off-by: baowj --- pkg/caelus/healthcheck/health_check.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/caelus/healthcheck/health_check.go b/pkg/caelus/healthcheck/health_check.go index a3e8e58f..e33373c6 100644 --- a/pkg/caelus/healthcheck/health_check.go +++ b/pkg/caelus/healthcheck/health_check.go @@ -317,7 +317,7 @@ func (h *manager) updateRuleCheckConfig() error { } sort.Slice(ruleChecks, func(i, j int) bool { if *(ruleChecks[i].Spec.Priority) == *(ruleChecks[j].Spec.Priority) { - return ruleChecks[i].CreationTimestamp.Time.After(ruleChecks[i].CreationTimestamp.Time) + return ruleChecks[i].CreationTimestamp.Time.After(ruleChecks[j].CreationTimestamp.Time) } else { return *(ruleChecks[i].Spec.Priority) > *(ruleChecks[j].Spec.Priority) } From e7c1cb99bd6c85999550535943ace54ae5ef617e Mon Sep 17 00:00:00 2001 From: baowj Date: Thu, 21 Mar 2024 14:53:17 +0800 Subject: [PATCH 35/59] add register.go Signed-off-by: baowj --- pkg/apis/caelus/register.go | 5 +++++ pkg/apis/caelus/v1/register.go | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 pkg/apis/caelus/register.go diff --git a/pkg/apis/caelus/register.go b/pkg/apis/caelus/register.go new file mode 100644 index 00000000..5246cfb0 --- /dev/null +++ b/pkg/apis/caelus/register.go @@ -0,0 +1,5 @@ +package caelus + +const ( + GroupName = "caelus.io" +) diff --git a/pkg/apis/caelus/v1/register.go b/pkg/apis/caelus/v1/register.go index 87243168..94d23d4a 100644 --- a/pkg/apis/caelus/v1/register.go +++ b/pkg/apis/caelus/v1/register.go @@ -16,13 +16,14 @@ package v1 import ( + "github.com/tencent/caelus/pkg/apis/caelus" 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: "caelus.io", Version: "v1"} +var SchemeGroupVersion = schema.GroupVersion{Group: caelus.GroupName, Version: "v1"} // Kind takes an unqualified kind and returns back a Group qualified GroupKind func Kind(kind string) schema.GroupKind { From 2864a9b0edab84c4a87beaa6628cc85b2fc64175 Mon Sep 17 00:00:00 2001 From: yanxiaoqi932 Date: Thu, 21 Mar 2024 18:18:05 +0800 Subject: [PATCH 36/59] cgroupnotify merge --- cmd/caelus/app/server.go | 2 +- cmd/caelus/context/context.go | 19 +- go.mod | 14 +- go.sum | 17 +- .../v1/cgroupnotify_types.go} | 27 +-- pkg/apis/caelus/v1/register.go | 2 + pkg/apis/caelus/v1/zz_generated.deepcopy.go | 206 ++++++++++++++++-- pkg/apis/cgroupnotifycrd/register.go | 5 - pkg/apis/cgroupnotifycrd/v1/doc.go | 4 - pkg/apis/cgroupnotifycrd/v1/register.go | 39 ---- .../v1/zz_generated.deepcopy.go | 193 ---------------- pkg/caelus/healthcheck/health_check.go | 94 ++++---- .../clientset/versioned/clientset.go | 117 ---------- pkg/cgroupClient/clientset/versioned/doc.go | 20 -- .../versioned/fake/clientset_generated.go | 85 -------- .../clientset/versioned/fake/doc.go | 20 -- .../clientset/versioned/fake/register.go | 56 ----- .../clientset/versioned/scheme/doc.go | 20 -- .../clientset/versioned/scheme/register.go | 56 ----- .../cgroupnotifycrd/v1/cgroupnotifycrd.go | 195 ----------------- .../v1/cgroupnotifycrd_client.go | 107 --------- .../versioned/typed/cgroupnotifycrd/v1/doc.go | 20 -- .../typed/cgroupnotifycrd/v1/fake/doc.go | 20 -- .../v1/fake/fake_cgroupnotifycrd.go | 142 ------------ .../v1/fake/fake_cgroupnotifycrd_client.go | 40 ---- .../cgroupnotifycrd/v1/generated_expansion.go | 21 -- .../cgroupnotifycrd/interface.go | 46 ---- .../cgroupnotifycrd/v1/cgroupnotifycrd.go | 90 -------- .../cgroupnotifycrd/v1/interface.go | 45 ---- .../informers/externalversions/factory.go | 180 --------------- .../informers/externalversions/generic.go | 62 ------ .../internalinterfaces/factory_interfaces.go | 40 ---- .../cgroupnotifycrd/v1/cgroupnotifycrd.go | 99 --------- .../cgroupnotifycrd/v1/expansion_generated.go | 27 --- .../clientset/versioned/clientset.go | 32 ++- pkg/generated/clientset/versioned/doc.go | 28 +-- .../versioned/fake/clientset_generated.go | 28 +-- pkg/generated/clientset/versioned/fake/doc.go | 28 +-- .../clientset/versioned/fake/register.go | 28 +-- .../clientset/versioned/scheme/doc.go | 28 +-- .../clientset/versioned/scheme/register.go | 28 +-- .../typed/caelus/v1/caelus_client.go | 33 +-- .../versioned/typed/caelus/v1/cgroupnotify.go | 195 +++++++++++++++++ .../versioned/typed/caelus/v1/doc.go | 28 +-- .../versioned/typed/caelus/v1/fake/doc.go | 28 +-- .../caelus/v1/fake/fake_caelus_client.go | 32 +-- .../typed/caelus/v1/fake/fake_cgroupnotify.go | 142 ++++++++++++ .../typed/caelus/v1/fake/fake_rulecheck.go | 28 +-- .../typed/caelus/v1/generated_expansion.go | 30 +-- .../versioned/typed/caelus/v1/rulecheck.go | 28 +-- .../externalversions/caelus/interface.go | 28 +-- .../caelus/v1/cgroupnotify.go | 90 ++++++++ .../externalversions/caelus/v1/interface.go | 35 +-- .../externalversions/caelus/v1/rulecheck.go | 28 +-- .../informers/externalversions/factory.go | 28 +-- .../informers/externalversions/generic.go | 30 +-- .../internalinterfaces/factory_interfaces.go | 28 +-- .../listers/caelus/v1/cgroupnotify.go | 99 +++++++++ .../listers/caelus/v1/expansion_generated.go | 36 +-- pkg/generated/listers/caelus/v1/rulecheck.go | 28 +-- 60 files changed, 1176 insertions(+), 2128 deletions(-) rename pkg/apis/{cgroupnotifycrd/v1/types.go => caelus/v1/cgroupnotify_types.go} (67%) delete mode 100644 pkg/apis/cgroupnotifycrd/register.go delete mode 100644 pkg/apis/cgroupnotifycrd/v1/doc.go delete mode 100644 pkg/apis/cgroupnotifycrd/v1/register.go delete mode 100644 pkg/apis/cgroupnotifycrd/v1/zz_generated.deepcopy.go delete mode 100644 pkg/cgroupClient/clientset/versioned/clientset.go delete mode 100644 pkg/cgroupClient/clientset/versioned/doc.go delete mode 100644 pkg/cgroupClient/clientset/versioned/fake/clientset_generated.go delete mode 100644 pkg/cgroupClient/clientset/versioned/fake/doc.go delete mode 100644 pkg/cgroupClient/clientset/versioned/fake/register.go delete mode 100644 pkg/cgroupClient/clientset/versioned/scheme/doc.go delete mode 100644 pkg/cgroupClient/clientset/versioned/scheme/register.go delete mode 100644 pkg/cgroupClient/clientset/versioned/typed/cgroupnotifycrd/v1/cgroupnotifycrd.go delete mode 100644 pkg/cgroupClient/clientset/versioned/typed/cgroupnotifycrd/v1/cgroupnotifycrd_client.go delete mode 100644 pkg/cgroupClient/clientset/versioned/typed/cgroupnotifycrd/v1/doc.go delete mode 100644 pkg/cgroupClient/clientset/versioned/typed/cgroupnotifycrd/v1/fake/doc.go delete mode 100644 pkg/cgroupClient/clientset/versioned/typed/cgroupnotifycrd/v1/fake/fake_cgroupnotifycrd.go delete mode 100644 pkg/cgroupClient/clientset/versioned/typed/cgroupnotifycrd/v1/fake/fake_cgroupnotifycrd_client.go delete mode 100644 pkg/cgroupClient/clientset/versioned/typed/cgroupnotifycrd/v1/generated_expansion.go delete mode 100644 pkg/cgroupClient/informers/externalversions/cgroupnotifycrd/interface.go delete mode 100644 pkg/cgroupClient/informers/externalversions/cgroupnotifycrd/v1/cgroupnotifycrd.go delete mode 100644 pkg/cgroupClient/informers/externalversions/cgroupnotifycrd/v1/interface.go delete mode 100644 pkg/cgroupClient/informers/externalversions/factory.go delete mode 100644 pkg/cgroupClient/informers/externalversions/generic.go delete mode 100644 pkg/cgroupClient/informers/externalversions/internalinterfaces/factory_interfaces.go delete mode 100644 pkg/cgroupClient/listers/cgroupnotifycrd/v1/cgroupnotifycrd.go delete mode 100644 pkg/cgroupClient/listers/cgroupnotifycrd/v1/expansion_generated.go create mode 100644 pkg/generated/clientset/versioned/typed/caelus/v1/cgroupnotify.go create mode 100644 pkg/generated/clientset/versioned/typed/caelus/v1/fake/fake_cgroupnotify.go create mode 100644 pkg/generated/informers/externalversions/caelus/v1/cgroupnotify.go create mode 100644 pkg/generated/listers/caelus/v1/cgroupnotify.go diff --git a/cmd/caelus/app/server.go b/cmd/caelus/app/server.go index 47a76ca8..a78fd02e 100644 --- a/cmd/caelus/app/server.go +++ b/cmd/caelus/app/server.go @@ -246,7 +246,7 @@ func (o *options) initModules(caelus *types.CaelusConfig, ctx *context.CaelusCon // health check manager nodeInformer := ctx.GetNodeFactory().Core().V1().Nodes() ruleCheckInformer := ctx.GetCaelusFactory().Caelus().V1().RuleChecks() - cgroupNotifyInformer := ctx.GetCgroupNotifyFactory().Cgroupnotifycrd().V1().CgroupNotifyCrds() + cgroupNotifyInformer := ctx.GetCgroupNotifyFactory().Caelus().V1().CgroupNotifies() healthCheckManager = health.NewHealthManager(stStore, resourceManager, qosManager, conflictMn, podInformer, nodeInformer, ruleCheckInformer, cgroupNotifyInformer, &caelus.Predicts[0].ReserveResource, diff --git a/cmd/caelus/context/context.go b/cmd/caelus/context/context.go index 2b783b20..33c56263 100644 --- a/cmd/caelus/context/context.go +++ b/cmd/caelus/context/context.go @@ -18,9 +18,6 @@ package context import ( "time" - cgroupclient "github.com/tencent/caelus/pkg/cgroupClient/clientset/versioned" - cgroupfake "github.com/tencent/caelus/pkg/cgroupClient/clientset/versioned/fake" - cgroupInformers "github.com/tencent/caelus/pkg/cgroupClient/informers/externalversions" caelusclient "github.com/tencent/caelus/pkg/generated/clientset/versioned" caelusfake "github.com/tencent/caelus/pkg/generated/clientset/versioned/fake" caelusinformers "github.com/tencent/caelus/pkg/generated/informers/externalversions" @@ -42,10 +39,10 @@ type CaelusContext struct { NodeName string kubeClient clientset.Interface caelusClient caelusclient.Interface - cgroupNotifyClient cgroupclient.Interface + cgroupNotifyClient caelusclient.Interface nodeFactory, podFactory informers.SharedInformerFactory caelusFactory caelusinformers.SharedInformerFactory - cgroupNotifyFactory cgroupInformers.SharedInformerFactory + cgroupNotifyFactory caelusinformers.SharedInformerFactory // TODO add xxx informers } @@ -99,9 +96,9 @@ func (c *CaelusContext) lazyInit() { klog.Warning(err) klog.Warning("fall back to creating fake caelus-client") // create a fake client to test caelus without k8s - c.cgroupNotifyClient = cgroupfake.NewSimpleClientset() + c.cgroupNotifyClient = caelusfake.NewSimpleClientset() } else { - c.cgroupNotifyClient = cgroupclient.NewForConfigOrDie(kubeconfig) + c.cgroupNotifyClient = caelusclient.NewForConfigOrDie(kubeconfig) } } } @@ -119,7 +116,7 @@ func (c *CaelusContext) GetCaelusClient() caelusclient.Interface { } // GetCaelusClient returns CgroupNotify client -func (c *CaelusContext) GetCgroupNotifyClient() cgroupclient.Interface { +func (c *CaelusContext) GetCgroupNotifyClient() caelusclient.Interface { c.lazyInit() return c.cgroupNotifyClient } @@ -147,10 +144,10 @@ func (c *CaelusContext) GetCaelusFactory() caelusinformers.SharedInformerFactory } // GetCaelusFactory returns cgroupnotify factory -func (c *CaelusContext) GetCgroupNotifyFactory() cgroupInformers.SharedInformerFactory { +func (c *CaelusContext) GetCgroupNotifyFactory() caelusinformers.SharedInformerFactory { if c.cgroupNotifyFactory == nil { - c.cgroupNotifyFactory = cgroupInformers.NewSharedInformerFactoryWithOptions(c.GetCgroupNotifyClient(), informerSyncPeriod, - cgroupInformers.WithTweakListOptions(func(options *metav1.ListOptions) { + c.cgroupNotifyFactory = caelusinformers.NewSharedInformerFactoryWithOptions(c.GetCgroupNotifyClient(), informerSyncPeriod, + caelusinformers.WithTweakListOptions(func(options *metav1.ListOptions) { options.FieldSelector = fields.OneTermEqualSelector(nodeNameField, c.NodeName).String() })) } diff --git a/go.mod b/go.mod index 9b103cea..f22ae86a 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,6 @@ require ( github.com/docker/engine-api v0.4.0 github.com/emicklei/go-restful v2.9.5+incompatible github.com/fatih/structs v1.1.0 - github.com/fsnotify/fsnotify v1.6.0 github.com/google/cadvisor v0.46.0 github.com/guillermo/go.procmeminfo v0.0.0-20131127224636-be4355a9fb0e github.com/json-iterator/go v1.1.12 @@ -22,7 +21,7 @@ require ( github.com/spf13/cobra v1.6.0 github.com/spf13/pflag v1.0.5 github.com/vishvananda/netlink v1.1.1-0.20200915183220-339a215d6544 - golang.org/x/net v0.3.1-0.20221206200815-1e63c2f08a10 + golang.org/x/net v0.8.0 golang.org/x/sys v0.6.0 gotest.tools v2.2.0+incompatible k8s.io/api v0.26.0 @@ -30,7 +29,9 @@ require ( k8s.io/apiserver v0.26.0 k8s.io/autoscaler/vertical-pod-autoscaler v0.10.0 k8s.io/client-go v0.26.0 + k8s.io/code-generator v0.29.3 k8s.io/component-base v0.26.0 + k8s.io/klog v1.0.0 k8s.io/klog/v2 v2.80.1 k8s.io/kubernetes v1.26.0 k8s.io/utils v0.0.0-20221107191617-1a15be271d1d @@ -56,6 +57,7 @@ require ( github.com/emicklei/go-restful/v3 v3.9.0 // indirect github.com/euank/go-kmsg-parser v2.0.0+incompatible // indirect github.com/evanphx/json-patch v4.12.0+incompatible // indirect + github.com/fsnotify/fsnotify v1.6.0 // indirect github.com/go-logr/logr v1.2.3 // indirect github.com/go-ole/go-ole v1.2.4 // indirect github.com/go-openapi/jsonpointer v0.19.5 // indirect @@ -95,16 +97,18 @@ require ( github.com/stretchr/testify v1.8.0 // indirect github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635 // indirect github.com/vishvananda/netns v0.0.0-20200728191858-db3c7e526aae // indirect + golang.org/x/mod v0.9.0 // indirect golang.org/x/oauth2 v0.0.0-20220223155221-ee480838109b // indirect - golang.org/x/term v0.3.0 // indirect - golang.org/x/text v0.5.0 // indirect + golang.org/x/term v0.6.0 // indirect + golang.org/x/text v0.8.0 // indirect golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 // indirect + golang.org/x/tools v0.7.0 // indirect google.golang.org/appengine v1.6.7 // indirect google.golang.org/protobuf v1.28.1 // indirect 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/klog v1.0.0 // indirect + k8s.io/gengo v0.0.0-20220902162205-c0856e24416d // indirect k8s.io/kube-openapi v0.0.0-20221012153701-172d655c2280 // indirect moul.io/http2curl v1.0.0 // indirect sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 // indirect diff --git a/go.sum b/go.sum index 8a596d0a..8d08cd3f 100644 --- a/go.sum +++ b/go.sum @@ -531,6 +531,8 @@ golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3/go.mod h1:3p9vT2HGsQu2K1YbXdKPJLVgG5VJdoTa1poYQBtP1AY= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= +golang.org/x/mod v0.9.0 h1:KENHtAZL2y3NLMYZeHY9DW8HW8V+kQyJsY/V9JlKvCs= +golang.org/x/mod v0.9.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -572,8 +574,9 @@ golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qx golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= -golang.org/x/net v0.3.1-0.20221206200815-1e63c2f08a10 h1:Frnccbp+ok2GkUS2tC84yAq/U9Vg+0sIO7aRL3T4Xnc= golang.org/x/net v0.3.1-0.20221206200815-1e63c2f08a10/go.mod h1:MBQ8lrhLObU/6UmLb4fmbmk5OcyYmqtbGd/9yIeKjEE= +golang.org/x/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ= +golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -596,6 +599,7 @@ golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o= golang.org/x/sys v0.0.0-20160601133225-076b54675315/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -667,8 +671,9 @@ golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/term v0.3.0 h1:qoo4akIqOcDME5bhc/NgxUdovd6BSS2uMsVjB56q1xI= golang.org/x/term v0.3.0/go.mod h1:q750SLmJuPmVoN1blW3UFBPREJfb1KmY3vwxfr+nFDA= +golang.org/x/term v0.6.0 h1:clScbb1cHjoCkyRbWwBEUZ5H/tIFu5TAXIqaZD0Gcjw= +golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -677,8 +682,9 @@ golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.5.0 h1:OLmvp0KP+FVG99Ct/qFiL/Fhk4zp4QQnZ7b2U+5piUM= golang.org/x/text v0.5.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.8.0 h1:57P1ETyNKtuIjB4SRd15iJxuhj8Gc416Y78H3qgMh68= +golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= @@ -734,6 +740,8 @@ golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.10-0.20220218145154-897bd77cd717/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E= golang.org/x/tools v0.1.10/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +golang.org/x/tools v0.7.0 h1:W4OVu8VVOaIO0yzWMNdepAulS7YfoS3Zabrm8DOXXU4= +golang.org/x/tools v0.7.0/go.mod h1:4pg6aUX35JBAogB10C9AtvVL+qowtN4pT3CGSQex14s= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -879,11 +887,14 @@ k8s.io/autoscaler/vertical-pod-autoscaler v0.10.0 h1:mSO9phIinHH3bRuXQkHMIA2uJ4i k8s.io/autoscaler/vertical-pod-autoscaler v0.10.0/go.mod h1:sOm4JDB+0ZrrqFuscsbWL5KoFMMJuOrN1NE/6ulmYNA= k8s.io/client-go v0.26.0 h1:lT1D3OfO+wIi9UFolCrifbjUUgu7CpLca0AD8ghRLI8= k8s.io/client-go v0.26.0/go.mod h1:I2Sh57A79EQsDmn7F7ASpmru1cceh3ocVT9KlX2jEZg= +k8s.io/code-generator v0.24.2-rc.0 h1:YJ84GfXEa+pyes7haYF2aljlK6wj79qAPQTR1Dbg1tc= k8s.io/code-generator v0.24.2-rc.0/go.mod h1:dpVhs00hTuTdTY6jvVxvTFCk6gSMrtfRydbhZwHI15w= k8s.io/component-base v0.26.0 h1:0IkChOCohtDHttmKuz+EP3j3+qKmV55rM9gIFTXA7Vs= k8s.io/component-base v0.26.0/go.mod h1:lqHwlfV1/haa14F/Z5Zizk5QmzaVf23nQzCwVOQpfC8= k8s.io/gengo v0.0.0-20210813121822-485abfe95c7c/go.mod h1:FiNAH4ZV3gBg2Kwh89tzAEV2be7d5xI0vBa/VySYy3E= k8s.io/gengo v0.0.0-20211129171323-c02415ce4185/go.mod h1:FiNAH4ZV3gBg2Kwh89tzAEV2be7d5xI0vBa/VySYy3E= +k8s.io/gengo v0.0.0-20220902162205-c0856e24416d h1:U9tB195lKdzwqicbJvyJeOXV7Klv+wNAWENRnXEGi08= +k8s.io/gengo v0.0.0-20220902162205-c0856e24416d/go.mod h1:FiNAH4ZV3gBg2Kwh89tzAEV2be7d5xI0vBa/VySYy3E= k8s.io/klog v0.3.0/go.mod h1:Gq+BEi5rUBO/HRz0bTSXDUcqjScdoY3a9IHpCEIOOfk= k8s.io/klog v1.0.0 h1:Pt+yjF5aB1xDSVbau4VsWe+dQNzA0qv1LlXdC2dF6Q8= k8s.io/klog v1.0.0/go.mod h1:4Bi6QPql/J/LkTDqv7R/cd3hPo4k2DG6Ptcz060Ez5I= diff --git a/pkg/apis/cgroupnotifycrd/v1/types.go b/pkg/apis/caelus/v1/cgroupnotify_types.go similarity index 67% rename from pkg/apis/cgroupnotifycrd/v1/types.go rename to pkg/apis/caelus/v1/cgroupnotify_types.go index b489e82e..d75a39ce 100644 --- a/pkg/apis/cgroupnotifycrd/v1/types.go +++ b/pkg/apis/caelus/v1/cgroupnotify_types.go @@ -9,19 +9,20 @@ import ( // +genclient // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object -// CgroupNotifyCrd is a specification for a CgroupNotifyCrd resource -type CgroupNotifyCrd struct { +// CgroupNotify is a specification for a CgroupNotify resource +type CgroupNotify struct { metav1.TypeMeta `json:",inline"` metav1.ObjectMeta `json:"metadata,omitempty"` - Spec CgroupNotifyCrdSpec `json:"spec"` - Status CgroupNotifyCrdStatus `json:"status"` + Spec CgroupNotifySpec `json:"spec"` + Status CgroupNotifyStatus `json:"status"` } -// CgroupNotifyCrdSpec is the spec for a CgroupNotifyCrd resource -type CgroupNotifyCrdSpec struct { - MemoryCgroup MemoryNotifyConfig `json:"memory_cgroup"` - NodeSelector metav1.LabelSelector `json:"nodeSelector"` +// CgroupNotifySpec is the spec for a CgroupNotify resource +type CgroupNotifySpec struct { + MemoryCgroup MemoryNotifyConfig `json:"memory_cgroup"` + NodeSelector map[string]string `json:"nodeSelector"` + Priority *int32 `json:"priority"` } // MemoryNotifyConfig describe memory cgroup notify @@ -49,17 +50,17 @@ type MemoryUsageNotifyConfig struct { Duration times.Duration `json:"duration"` } -// CgroupNotifyCrdStatus is the status for a CgroupNotifyCrd resource -type CgroupNotifyCrdStatus struct { +// CgroupNotifyStatus is the status for a CgroupNotify resource +type CgroupNotifyStatus struct { AvailableReplicas int32 `json:"availableReplicas"` } // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object -// CgroupNotifyCrdList is a list of CgroupNotifyCrd resources -type CgroupNotifyCrdList struct { +// CgroupNotifyList is a list of CgroupNotify resources +type CgroupNotifyList struct { metav1.TypeMeta `json:",inline"` metav1.ListMeta `json:"metadata"` - Items []CgroupNotifyCrd `json:"items"` + Items []CgroupNotify `json:"items"` } diff --git a/pkg/apis/caelus/v1/register.go b/pkg/apis/caelus/v1/register.go index 94d23d4a..1ce75746 100644 --- a/pkg/apis/caelus/v1/register.go +++ b/pkg/apis/caelus/v1/register.go @@ -47,6 +47,8 @@ func addKnownTypes(scheme *runtime.Scheme) error { scheme.AddKnownTypes(SchemeGroupVersion, &RuleCheck{}, &RuleCheckList{}, + &CgroupNotify{}, + &CgroupNotifyList{}, ) metav1.AddToGroupVersion(scheme, SchemeGroupVersion) return nil diff --git a/pkg/apis/caelus/v1/zz_generated.deepcopy.go b/pkg/apis/caelus/v1/zz_generated.deepcopy.go index 9fa06477..05f0abc5 100644 --- a/pkg/apis/caelus/v1/zz_generated.deepcopy.go +++ b/pkg/apis/caelus/v1/zz_generated.deepcopy.go @@ -2,19 +2,21 @@ // +build !ignore_autogenerated /* - * Copyright (c) 2021 THL A29 Limited, a Tencent company. - * - * 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. - */ +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 v1 @@ -24,6 +26,112 @@ 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 *CgroupNotify) DeepCopyInto(out *CgroupNotify) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) + out.Status = in.Status + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CgroupNotify. +func (in *CgroupNotify) DeepCopy() *CgroupNotify { + if in == nil { + return nil + } + out := new(CgroupNotify) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *CgroupNotify) 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 *CgroupNotifyList) DeepCopyInto(out *CgroupNotifyList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]CgroupNotify, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CgroupNotifyList. +func (in *CgroupNotifyList) DeepCopy() *CgroupNotifyList { + if in == nil { + return nil + } + out := new(CgroupNotifyList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *CgroupNotifyList) 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 *CgroupNotifySpec) DeepCopyInto(out *CgroupNotifySpec) { + *out = *in + in.MemoryCgroup.DeepCopyInto(&out.MemoryCgroup) + if in.NodeSelector != nil { + in, out := &in.NodeSelector, &out.NodeSelector + *out = make(map[string]string, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } + if in.Priority != nil { + in, out := &in.Priority, &out.Priority + *out = new(int32) + **out = **in + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CgroupNotifySpec. +func (in *CgroupNotifySpec) DeepCopy() *CgroupNotifySpec { + if in == nil { + return nil + } + out := new(CgroupNotifySpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *CgroupNotifyStatus) DeepCopyInto(out *CgroupNotifyStatus) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CgroupNotifyStatus. +func (in *CgroupNotifyStatus) DeepCopy() *CgroupNotifyStatus { + if in == nil { + return nil + } + out := new(CgroupNotifyStatus) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *DetectAction) DeepCopyInto(out *DetectAction) { *out = *in @@ -78,6 +186,78 @@ func (in *DetectActionRules) DeepCopy() *DetectActionRules { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *MemoryNotifyConfig) DeepCopyInto(out *MemoryNotifyConfig) { + *out = *in + if in.Pressures != nil { + in, out := &in.Pressures, &out.Pressures + *out = make([]MemoryPressureNotifyConfig, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + if in.Usages != nil { + in, out := &in.Usages, &out.Usages + *out = make([]MemoryUsageNotifyConfig, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MemoryNotifyConfig. +func (in *MemoryNotifyConfig) DeepCopy() *MemoryNotifyConfig { + if in == nil { + return nil + } + out := new(MemoryNotifyConfig) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *MemoryPressureNotifyConfig) DeepCopyInto(out *MemoryPressureNotifyConfig) { + *out = *in + if in.Cgroups != nil { + in, out := &in.Cgroups, &out.Cgroups + *out = make([]string, len(*in)) + copy(*out, *in) + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MemoryPressureNotifyConfig. +func (in *MemoryPressureNotifyConfig) DeepCopy() *MemoryPressureNotifyConfig { + if in == nil { + return nil + } + out := new(MemoryPressureNotifyConfig) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *MemoryUsageNotifyConfig) DeepCopyInto(out *MemoryUsageNotifyConfig) { + *out = *in + if in.Cgroups != nil { + in, out := &in.Cgroups, &out.Cgroups + *out = make([]string, len(*in)) + copy(*out, *in) + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MemoryUsageNotifyConfig. +func (in *MemoryUsageNotifyConfig) DeepCopy() *MemoryUsageNotifyConfig { + if in == nil { + return nil + } + out := new(MemoryUsageNotifyConfig) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *RuleCheck) DeepCopyInto(out *RuleCheck) { *out = *in diff --git a/pkg/apis/cgroupnotifycrd/register.go b/pkg/apis/cgroupnotifycrd/register.go deleted file mode 100644 index b9d699da..00000000 --- a/pkg/apis/cgroupnotifycrd/register.go +++ /dev/null @@ -1,5 +0,0 @@ -package cgroupnotifycontroller - -const ( - GroupName = "cgroupnotifycrd" -) diff --git a/pkg/apis/cgroupnotifycrd/v1/doc.go b/pkg/apis/cgroupnotifycrd/v1/doc.go deleted file mode 100644 index 37249499..00000000 --- a/pkg/apis/cgroupnotifycrd/v1/doc.go +++ /dev/null @@ -1,4 +0,0 @@ -// +k8s:deepcopy-gen=package -// +groupName=cgroupnotifycrd - -package v1 diff --git a/pkg/apis/cgroupnotifycrd/v1/register.go b/pkg/apis/cgroupnotifycrd/v1/register.go deleted file mode 100644 index d52efa84..00000000 --- a/pkg/apis/cgroupnotifycrd/v1/register.go +++ /dev/null @@ -1,39 +0,0 @@ -package v1 - -import ( - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/schema" - - cgroupnotifycontroller "github.com/tencent/caelus/pkg/apis/cgroupnotifycrd" -) - -// SchemeGroupVersion is group version used to register these objects -var SchemeGroupVersion = schema.GroupVersion{Group: cgroupnotifycontroller.GroupName, Version: "v1"} - -// Kind takes an unqualified kind and returns back a Group qualified GroupKind -func Kind(kind string) schema.GroupKind { - return SchemeGroupVersion.WithKind(kind).GroupKind() -} - -// 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, - &CgroupNotifyCrd{}, - &CgroupNotifyCrdList{}, - ) - metav1.AddToGroupVersion(scheme, SchemeGroupVersion) - return nil -} diff --git a/pkg/apis/cgroupnotifycrd/v1/zz_generated.deepcopy.go b/pkg/apis/cgroupnotifycrd/v1/zz_generated.deepcopy.go deleted file mode 100644 index 4edbef8c..00000000 --- a/pkg/apis/cgroupnotifycrd/v1/zz_generated.deepcopy.go +++ /dev/null @@ -1,193 +0,0 @@ -//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 v1 - -import ( - runtime "k8s.io/apimachinery/pkg/runtime" -) - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *CgroupNotifyCrd) DeepCopyInto(out *CgroupNotifyCrd) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - in.Spec.DeepCopyInto(&out.Spec) - out.Status = in.Status - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CgroupNotifyCrd. -func (in *CgroupNotifyCrd) DeepCopy() *CgroupNotifyCrd { - if in == nil { - return nil - } - out := new(CgroupNotifyCrd) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *CgroupNotifyCrd) 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 *CgroupNotifyCrdList) DeepCopyInto(out *CgroupNotifyCrdList) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ListMeta.DeepCopyInto(&out.ListMeta) - if in.Items != nil { - in, out := &in.Items, &out.Items - *out = make([]CgroupNotifyCrd, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CgroupNotifyCrdList. -func (in *CgroupNotifyCrdList) DeepCopy() *CgroupNotifyCrdList { - if in == nil { - return nil - } - out := new(CgroupNotifyCrdList) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *CgroupNotifyCrdList) 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 *CgroupNotifyCrdSpec) DeepCopyInto(out *CgroupNotifyCrdSpec) { - *out = *in - in.MemoryCgroup.DeepCopyInto(&out.MemoryCgroup) - in.NodeSelector.DeepCopyInto(&out.NodeSelector) - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CgroupNotifyCrdSpec. -func (in *CgroupNotifyCrdSpec) DeepCopy() *CgroupNotifyCrdSpec { - if in == nil { - return nil - } - out := new(CgroupNotifyCrdSpec) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *CgroupNotifyCrdStatus) DeepCopyInto(out *CgroupNotifyCrdStatus) { - *out = *in - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CgroupNotifyCrdStatus. -func (in *CgroupNotifyCrdStatus) DeepCopy() *CgroupNotifyCrdStatus { - if in == nil { - return nil - } - out := new(CgroupNotifyCrdStatus) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *MemoryNotifyConfig) DeepCopyInto(out *MemoryNotifyConfig) { - *out = *in - if in.Pressures != nil { - in, out := &in.Pressures, &out.Pressures - *out = make([]MemoryPressureNotifyConfig, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } - if in.Usages != nil { - in, out := &in.Usages, &out.Usages - *out = make([]MemoryUsageNotifyConfig, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MemoryNotifyConfig. -func (in *MemoryNotifyConfig) DeepCopy() *MemoryNotifyConfig { - if in == nil { - return nil - } - out := new(MemoryNotifyConfig) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *MemoryPressureNotifyConfig) DeepCopyInto(out *MemoryPressureNotifyConfig) { - *out = *in - if in.Cgroups != nil { - in, out := &in.Cgroups, &out.Cgroups - *out = make([]string, len(*in)) - copy(*out, *in) - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MemoryPressureNotifyConfig. -func (in *MemoryPressureNotifyConfig) DeepCopy() *MemoryPressureNotifyConfig { - if in == nil { - return nil - } - out := new(MemoryPressureNotifyConfig) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *MemoryUsageNotifyConfig) DeepCopyInto(out *MemoryUsageNotifyConfig) { - *out = *in - if in.Cgroups != nil { - in, out := &in.Cgroups, &out.Cgroups - *out = make([]string, len(*in)) - copy(*out, *in) - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MemoryUsageNotifyConfig. -func (in *MemoryUsageNotifyConfig) DeepCopy() *MemoryUsageNotifyConfig { - if in == nil { - return nil - } - out := new(MemoryUsageNotifyConfig) - in.DeepCopyInto(out) - return out -} diff --git a/pkg/caelus/healthcheck/health_check.go b/pkg/caelus/healthcheck/health_check.go index e33373c6..427b17d8 100644 --- a/pkg/caelus/healthcheck/health_check.go +++ b/pkg/caelus/healthcheck/health_check.go @@ -20,7 +20,6 @@ import ( "sort" v1 "github.com/tencent/caelus/pkg/apis/caelus/v1" - cgroupCrd "github.com/tencent/caelus/pkg/apis/cgroupnotifycrd/v1" notify "github.com/tencent/caelus/pkg/caelus/healthcheck/cgroupnotify" "github.com/tencent/caelus/pkg/caelus/healthcheck/conflict" "github.com/tencent/caelus/pkg/caelus/healthcheck/rulecheck" @@ -29,11 +28,9 @@ import ( "github.com/tencent/caelus/pkg/caelus/statestore" "github.com/tencent/caelus/pkg/caelus/types" "github.com/tencent/caelus/pkg/caelus/util" - cgroupInformer "github.com/tencent/caelus/pkg/cgroupClient/informers/externalversions/cgroupnotifycrd/v1" caelusv1 "github.com/tencent/caelus/pkg/generated/informers/externalversions/caelus/v1" corev1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" labels2 "k8s.io/apimachinery/pkg/labels" informerv1 "k8s.io/client-go/informers/core/v1" "k8s.io/client-go/tools/cache" @@ -66,7 +63,7 @@ type manager struct { podInformer cache.SharedIndexInformer nodeInformer informerv1.NodeInformer ruleCheckInformer caelusv1.RuleCheckInformer - cgroupInformer cgroupInformer.CgroupNotifyCrdInformer + cgroupInformer caelusv1.CgroupNotifyInformer workqueue workqueue.RateLimitingInterface configHash string globalStopCh <-chan struct{} @@ -77,7 +74,7 @@ type manager struct { func NewHealthManager(stStore statestore.StateStore, resource resource.Interface, qosManager qos.Manager, conflictMn conflict.Manager, podInformer cache.SharedIndexInformer, nodeInformer informerv1.NodeInformer, - ruleCheckInformer caelusv1.RuleCheckInformer, cgroupInformer cgroupInformer.CgroupNotifyCrdInformer, + ruleCheckInformer caelusv1.RuleCheckInformer, cgroupInformer caelusv1.CgroupNotifyInformer, resourceType *types.Resource, ruleCheckAvailableFunc func(ruleCheck *types.RuleCheckConfig)) Manager { config := &types.HealthCheckConfig{ @@ -219,11 +216,11 @@ func (h *manager) syncHandler(key string) error { } h.reRunRuleCheck() } else if key == cgroupNotify { - //err := h.updateCgroupConfig() - //if err != nil{ - // return err - //} - //h.reRunCgroupNotifier() + err := h.updateCgroupNotifyConfig() + if err != nil { + return err + } + h.reRunCgroupNotifier() } klog.Infof("---- After syncHandler %v: %v", key, *h.config) @@ -256,24 +253,9 @@ func (h *manager) reRunCgroupNotifier() { } } -func (h *manager) OnAddCgropNotify(obj interface{}) { - h.updateCgroupConfig(obj, false) - h.reRunCgroupNotifier() -} - -func (h *manager) OnUpdateCgropNotify(oldObj, newObj interface{}) { - h.updateCgroupConfig(newObj, false) - h.reRunCgroupNotifier() -} - -func (h *manager) OnDeleteCgropNotify(obj interface{}) { - h.updateCgroupConfig(obj, true) - h.reRunCgroupNotifier() -} - -func (h *manager) CgroupCrddeepCopy(cgroupCrd *cgroupCrd.CgroupNotifyCrd) { +func (h *manager) convertK8sCgroupNotify(k8sCgroupNotify *v1.CgroupNotify, cgroupNotify *types.NotifyConfig) { pressures := make([]types.MemoryPressureNotifyConfig, 0) - for _, p := range cgroupCrd.Spec.MemoryCgroup.Pressures { + for _, p := range k8sCgroupNotify.Spec.MemoryCgroup.Pressures { newP := types.MemoryPressureNotifyConfig{} newP.Cgroups = p.Cgroups newP.Count = p.Count @@ -282,33 +264,59 @@ func (h *manager) CgroupCrddeepCopy(cgroupCrd *cgroupCrd.CgroupNotifyCrd) { pressures = append(pressures, newP) } usages := make([]types.MemoryUsageNotifyConfig, 0) - for _, u := range cgroupCrd.Spec.MemoryCgroup.Usages { + for _, u := range k8sCgroupNotify.Spec.MemoryCgroup.Usages { newU := types.MemoryUsageNotifyConfig{} newU.Cgroups = u.Cgroups newU.Duration = u.Duration newU.MarginMb = u.MarginMb usages = append(usages, newU) } - h.config.CgroupNotify.MemoryCgroup.Pressures = pressures - h.config.CgroupNotify.MemoryCgroup.Usages = usages - h.config.CgroupNotify.Labels = cgroupCrd.Spec.NodeSelector.MatchLabels + cgroupNotify.MemoryCgroup.Pressures = pressures + cgroupNotify.MemoryCgroup.Usages = usages + cgroupNotify.Labels = k8sCgroupNotify.Spec.NodeSelector } -func (h *manager) updateCgroupConfig(obj interface{}, isDelete bool) { - object := obj.(metav1.Object) - ownerRef := metav1.GetControllerOf(object) - cgroupCrd, err := h.cgroupInformer.Lister().CgroupNotifyCrds(object.GetNamespace()).Get(ownerRef.Name) - if err != nil { - klog.Error("get cgroupNotifyCrd failed") - return +func (h *manager) mergeCgroupNotify(baseCgNotify, nextCgNotify *types.NotifyConfig) { + if len(baseCgNotify.Labels) == 0 { + baseCgNotify.Labels = nextCgNotify.Labels } - if isDelete { - h.config.CgroupNotify = types.NotifyConfig{} + if baseCgNotify.MemoryCgroup == nil { + baseCgNotify.MemoryCgroup = nextCgNotify.MemoryCgroup } else { - h.CgroupCrddeepCopy(cgroupCrd) + if len(baseCgNotify.MemoryCgroup.Pressures) == 0 { + baseCgNotify.MemoryCgroup.Pressures = nextCgNotify.MemoryCgroup.Pressures + } + if len(baseCgNotify.MemoryCgroup.Usages) == 0 { + baseCgNotify.MemoryCgroup.Usages = nextCgNotify.MemoryCgroup.Usages + } } } +func (h *manager) updateCgroupNotifyConfig() error { + cgroupNotifiers, err := h.cgroupInformer.Lister().CgroupNotifies(types.CaelusNamespace).List(labels2.SelectorFromSet(nil)) + if err != nil { + return err + } + sort.Slice(cgroupNotifiers, func(i, j int) bool { + if *(cgroupNotifiers[i].Spec.Priority) == *(cgroupNotifiers[j].Spec.Priority) { + return cgroupNotifiers[i].CreationTimestamp.After(cgroupNotifiers[j].CreationTimestamp.Time) + } else { + return *(cgroupNotifiers[i].Spec.Priority) > *(cgroupNotifiers[j].Spec.Priority) + } + }) + baseCgroupNotify := &types.NotifyConfig{} + for _, k8sCgroupNotify := range cgroupNotifiers { + if ok, err := h.isLabelMatchedLocalNode(k8sCgroupNotify.Spec.NodeSelector); err != nil || !ok { + continue + } + cgroupNotify := &types.NotifyConfig{} + h.convertK8sCgroupNotify(k8sCgroupNotify, cgroupNotify) + h.mergeCgroupNotify(baseCgroupNotify, cgroupNotify) + } + h.config.CgroupNotify = *baseCgroupNotify + return nil +} + // update local RuleCheck func (h *manager) updateRuleCheckConfig() error { ruleChecks, err := h.ruleCheckInformer.Lister().RuleChecks(types.CaelusNamespace).List(labels2.SelectorFromSet(nil)) @@ -397,8 +405,8 @@ func (h *manager) convertK8sRuleCheck(k8sRuleCheck *v1.RuleCheck, ruleCheck *typ // determine whether this cr event impacts this node func (h *manager) isAffectingLocalNode(objs []interface{}) bool { for _, obj := range objs { - if cgroupCr, ok := obj.(*cgroupCrd.CgroupNotifyCrd); ok { - if matched, err := h.isLabelMatchedLocalNode(cgroupCr.Spec.NodeSelector.MatchLabels); matched || err != nil { + if cgroupCr, ok := obj.(*v1.CgroupNotify); ok { + if matched, err := h.isLabelMatchedLocalNode(cgroupCr.Spec.NodeSelector); matched || err != nil { return true } } else if ruleCheckCr, ok := obj.(*v1.RuleCheck); ok { diff --git a/pkg/cgroupClient/clientset/versioned/clientset.go b/pkg/cgroupClient/clientset/versioned/clientset.go deleted file mode 100644 index 6c47b9bb..00000000 --- a/pkg/cgroupClient/clientset/versioned/clientset.go +++ /dev/null @@ -1,117 +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 versioned - -import ( - "fmt" - "net/http" - - cgroupnotifycrdv1 "github.com/tencent/caelus/pkg/cgroupClient/clientset/versioned/typed/cgroupnotifycrd/v1" - discovery "k8s.io/client-go/discovery" - rest "k8s.io/client-go/rest" - flowcontrol "k8s.io/client-go/util/flowcontrol" -) - -type Interface interface { - Discovery() discovery.DiscoveryInterface - CgroupnotifycrdV1() cgroupnotifycrdv1.CgroupnotifycrdV1Interface -} - -// Clientset contains the clients for groups. Each group has exactly one -// version included in a Clientset. -type Clientset struct { - *discovery.DiscoveryClient - cgroupnotifycrdV1 *cgroupnotifycrdv1.CgroupnotifycrdV1Client -} - -// CgroupnotifycrdV1 retrieves the CgroupnotifycrdV1Client -func (c *Clientset) CgroupnotifycrdV1() cgroupnotifycrdv1.CgroupnotifycrdV1Interface { - return c.cgroupnotifycrdV1 -} - -// 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 - - // 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.cgroupnotifycrdV1, err = cgroupnotifycrdv1.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.cgroupnotifycrdV1 = cgroupnotifycrdv1.New(c) - - cs.DiscoveryClient = discovery.NewDiscoveryClient(c) - return &cs -} diff --git a/pkg/cgroupClient/clientset/versioned/doc.go b/pkg/cgroupClient/clientset/versioned/doc.go deleted file mode 100644 index 41721ca5..00000000 --- a/pkg/cgroupClient/clientset/versioned/doc.go +++ /dev/null @@ -1,20 +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. - -// This package has the automatically generated clientset. -package versioned diff --git a/pkg/cgroupClient/clientset/versioned/fake/clientset_generated.go b/pkg/cgroupClient/clientset/versioned/fake/clientset_generated.go deleted file mode 100644 index 8f7e9ea4..00000000 --- a/pkg/cgroupClient/clientset/versioned/fake/clientset_generated.go +++ /dev/null @@ -1,85 +0,0 @@ -/* -Copyright The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by client-gen. DO NOT EDIT. - -package fake - -import ( - clientset "github.com/tencent/caelus/pkg/cgroupClient/clientset/versioned" - cgroupnotifycrdv1 "github.com/tencent/caelus/pkg/cgroupClient/clientset/versioned/typed/cgroupnotifycrd/v1" - fakecgroupnotifycrdv1 "github.com/tencent/caelus/pkg/cgroupClient/clientset/versioned/typed/cgroupnotifycrd/v1/fake" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/discovery" - fakediscovery "k8s.io/client-go/discovery/fake" - "k8s.io/client-go/testing" -) - -// NewSimpleClientset returns a clientset that will respond with the provided objects. -// It's backed by a very simple object tracker that processes creates, updates and deletions as-is, -// without applying any validations and/or defaults. It shouldn't be considered a replacement -// for a real clientset and is mostly useful in simple unit tests. -func NewSimpleClientset(objects ...runtime.Object) *Clientset { - o := testing.NewObjectTracker(scheme, codecs.UniversalDecoder()) - for _, obj := range objects { - if err := o.Add(obj); err != nil { - panic(err) - } - } - - cs := &Clientset{tracker: o} - cs.discovery = &fakediscovery.FakeDiscovery{Fake: &cs.Fake} - cs.AddReactor("*", "*", testing.ObjectReaction(o)) - cs.AddWatchReactor("*", func(action testing.Action) (handled bool, ret watch.Interface, err error) { - gvr := action.GetResource() - ns := action.GetNamespace() - watch, err := o.Watch(gvr, ns) - if err != nil { - return false, nil, err - } - return true, watch, nil - }) - - return cs -} - -// Clientset implements clientset.Interface. Meant to be embedded into a -// struct to get a default implementation. This makes faking out just the method -// you want to test easier. -type Clientset struct { - testing.Fake - discovery *fakediscovery.FakeDiscovery - tracker testing.ObjectTracker -} - -func (c *Clientset) Discovery() discovery.DiscoveryInterface { - return c.discovery -} - -func (c *Clientset) Tracker() testing.ObjectTracker { - return c.tracker -} - -var ( - _ clientset.Interface = &Clientset{} - _ testing.FakeClient = &Clientset{} -) - -// CgroupnotifycrdV1 retrieves the CgroupnotifycrdV1Client -func (c *Clientset) CgroupnotifycrdV1() cgroupnotifycrdv1.CgroupnotifycrdV1Interface { - return &fakecgroupnotifycrdv1.FakeCgroupnotifycrdV1{Fake: &c.Fake} -} diff --git a/pkg/cgroupClient/clientset/versioned/fake/doc.go b/pkg/cgroupClient/clientset/versioned/fake/doc.go deleted file mode 100644 index 9b99e716..00000000 --- a/pkg/cgroupClient/clientset/versioned/fake/doc.go +++ /dev/null @@ -1,20 +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. - -// This package has the automatically generated fake clientset. -package fake diff --git a/pkg/cgroupClient/clientset/versioned/fake/register.go b/pkg/cgroupClient/clientset/versioned/fake/register.go deleted file mode 100644 index bd2f297c..00000000 --- a/pkg/cgroupClient/clientset/versioned/fake/register.go +++ /dev/null @@ -1,56 +0,0 @@ -/* -Copyright The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by client-gen. DO NOT EDIT. - -package fake - -import ( - cgroupnotifycrdv1 "github.com/tencent/caelus/pkg/apis/cgroupnotifycrd/v1" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - runtime "k8s.io/apimachinery/pkg/runtime" - schema "k8s.io/apimachinery/pkg/runtime/schema" - serializer "k8s.io/apimachinery/pkg/runtime/serializer" - utilruntime "k8s.io/apimachinery/pkg/util/runtime" -) - -var scheme = runtime.NewScheme() -var codecs = serializer.NewCodecFactory(scheme) - -var localSchemeBuilder = runtime.SchemeBuilder{ - cgroupnotifycrdv1.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/cgroupClient/clientset/versioned/scheme/doc.go b/pkg/cgroupClient/clientset/versioned/scheme/doc.go deleted file mode 100644 index 7dc37561..00000000 --- a/pkg/cgroupClient/clientset/versioned/scheme/doc.go +++ /dev/null @@ -1,20 +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. - -// This package contains the scheme of the automatically generated clientset. -package scheme diff --git a/pkg/cgroupClient/clientset/versioned/scheme/register.go b/pkg/cgroupClient/clientset/versioned/scheme/register.go deleted file mode 100644 index b25da229..00000000 --- a/pkg/cgroupClient/clientset/versioned/scheme/register.go +++ /dev/null @@ -1,56 +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 scheme - -import ( - cgroupnotifycrdv1 "github.com/tencent/caelus/pkg/apis/cgroupnotifycrd/v1" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - runtime "k8s.io/apimachinery/pkg/runtime" - schema "k8s.io/apimachinery/pkg/runtime/schema" - serializer "k8s.io/apimachinery/pkg/runtime/serializer" - utilruntime "k8s.io/apimachinery/pkg/util/runtime" -) - -var Scheme = runtime.NewScheme() -var Codecs = serializer.NewCodecFactory(Scheme) -var ParameterCodec = runtime.NewParameterCodec(Scheme) -var localSchemeBuilder = runtime.SchemeBuilder{ - cgroupnotifycrdv1.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/cgroupClient/clientset/versioned/typed/cgroupnotifycrd/v1/cgroupnotifycrd.go b/pkg/cgroupClient/clientset/versioned/typed/cgroupnotifycrd/v1/cgroupnotifycrd.go deleted file mode 100644 index 63f75d71..00000000 --- a/pkg/cgroupClient/clientset/versioned/typed/cgroupnotifycrd/v1/cgroupnotifycrd.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 v1 - -import ( - "context" - "time" - - v1 "github.com/tencent/caelus/pkg/apis/cgroupnotifycrd/v1" - scheme "github.com/tencent/caelus/pkg/cgroupClient/clientset/versioned/scheme" - metav1 "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" -) - -// CgroupNotifyCrdsGetter has a method to return a CgroupNotifyCrdInterface. -// A group's client should implement this interface. -type CgroupNotifyCrdsGetter interface { - CgroupNotifyCrds(namespace string) CgroupNotifyCrdInterface -} - -// CgroupNotifyCrdInterface has methods to work with CgroupNotifyCrd resources. -type CgroupNotifyCrdInterface interface { - Create(ctx context.Context, cgroupNotifyCrd *v1.CgroupNotifyCrd, opts metav1.CreateOptions) (*v1.CgroupNotifyCrd, error) - Update(ctx context.Context, cgroupNotifyCrd *v1.CgroupNotifyCrd, opts metav1.UpdateOptions) (*v1.CgroupNotifyCrd, error) - UpdateStatus(ctx context.Context, cgroupNotifyCrd *v1.CgroupNotifyCrd, opts metav1.UpdateOptions) (*v1.CgroupNotifyCrd, 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.CgroupNotifyCrd, error) - List(ctx context.Context, opts metav1.ListOptions) (*v1.CgroupNotifyCrdList, 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.CgroupNotifyCrd, err error) - CgroupNotifyCrdExpansion -} - -// cgroupNotifyCrds implements CgroupNotifyCrdInterface -type cgroupNotifyCrds struct { - client rest.Interface - ns string -} - -// newCgroupNotifyCrds returns a CgroupNotifyCrds -func newCgroupNotifyCrds(c *CgroupnotifycrdV1Client, namespace string) *cgroupNotifyCrds { - return &cgroupNotifyCrds{ - client: c.RESTClient(), - ns: namespace, - } -} - -// Get takes name of the cgroupNotifyCrd, and returns the corresponding cgroupNotifyCrd object, and an error if there is any. -func (c *cgroupNotifyCrds) Get(ctx context.Context, name string, options metav1.GetOptions) (result *v1.CgroupNotifyCrd, err error) { - result = &v1.CgroupNotifyCrd{} - err = c.client.Get(). - Namespace(c.ns). - Resource("cgroupnotifycrds"). - Name(name). - VersionedParams(&options, scheme.ParameterCodec). - Do(ctx). - Into(result) - return -} - -// List takes label and field selectors, and returns the list of CgroupNotifyCrds that match those selectors. -func (c *cgroupNotifyCrds) List(ctx context.Context, opts metav1.ListOptions) (result *v1.CgroupNotifyCrdList, err error) { - var timeout time.Duration - if opts.TimeoutSeconds != nil { - timeout = time.Duration(*opts.TimeoutSeconds) * time.Second - } - result = &v1.CgroupNotifyCrdList{} - err = c.client.Get(). - Namespace(c.ns). - Resource("cgroupnotifycrds"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Do(ctx). - Into(result) - return -} - -// Watch returns a watch.Interface that watches the requested cgroupNotifyCrds. -func (c *cgroupNotifyCrds) 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(). - Namespace(c.ns). - Resource("cgroupnotifycrds"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Watch(ctx) -} - -// Create takes the representation of a cgroupNotifyCrd and creates it. Returns the server's representation of the cgroupNotifyCrd, and an error, if there is any. -func (c *cgroupNotifyCrds) Create(ctx context.Context, cgroupNotifyCrd *v1.CgroupNotifyCrd, opts metav1.CreateOptions) (result *v1.CgroupNotifyCrd, err error) { - result = &v1.CgroupNotifyCrd{} - err = c.client.Post(). - Namespace(c.ns). - Resource("cgroupnotifycrds"). - VersionedParams(&opts, scheme.ParameterCodec). - Body(cgroupNotifyCrd). - Do(ctx). - Into(result) - return -} - -// Update takes the representation of a cgroupNotifyCrd and updates it. Returns the server's representation of the cgroupNotifyCrd, and an error, if there is any. -func (c *cgroupNotifyCrds) Update(ctx context.Context, cgroupNotifyCrd *v1.CgroupNotifyCrd, opts metav1.UpdateOptions) (result *v1.CgroupNotifyCrd, err error) { - result = &v1.CgroupNotifyCrd{} - err = c.client.Put(). - Namespace(c.ns). - Resource("cgroupnotifycrds"). - Name(cgroupNotifyCrd.Name). - VersionedParams(&opts, scheme.ParameterCodec). - Body(cgroupNotifyCrd). - 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 *cgroupNotifyCrds) UpdateStatus(ctx context.Context, cgroupNotifyCrd *v1.CgroupNotifyCrd, opts metav1.UpdateOptions) (result *v1.CgroupNotifyCrd, err error) { - result = &v1.CgroupNotifyCrd{} - err = c.client.Put(). - Namespace(c.ns). - Resource("cgroupnotifycrds"). - Name(cgroupNotifyCrd.Name). - SubResource("status"). - VersionedParams(&opts, scheme.ParameterCodec). - Body(cgroupNotifyCrd). - Do(ctx). - Into(result) - return -} - -// Delete takes name of the cgroupNotifyCrd and deletes it. Returns an error if one occurs. -func (c *cgroupNotifyCrds) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { - return c.client.Delete(). - Namespace(c.ns). - Resource("cgroupnotifycrds"). - Name(name). - Body(&opts). - Do(ctx). - Error() -} - -// DeleteCollection deletes a collection of objects. -func (c *cgroupNotifyCrds) 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(). - Namespace(c.ns). - Resource("cgroupnotifycrds"). - VersionedParams(&listOpts, scheme.ParameterCodec). - Timeout(timeout). - Body(&opts). - Do(ctx). - Error() -} - -// Patch applies the patch and returns the patched cgroupNotifyCrd. -func (c *cgroupNotifyCrds) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.CgroupNotifyCrd, err error) { - result = &v1.CgroupNotifyCrd{} - err = c.client.Patch(pt). - Namespace(c.ns). - Resource("cgroupnotifycrds"). - Name(name). - SubResource(subresources...). - VersionedParams(&opts, scheme.ParameterCodec). - Body(data). - Do(ctx). - Into(result) - return -} diff --git a/pkg/cgroupClient/clientset/versioned/typed/cgroupnotifycrd/v1/cgroupnotifycrd_client.go b/pkg/cgroupClient/clientset/versioned/typed/cgroupnotifycrd/v1/cgroupnotifycrd_client.go deleted file mode 100644 index ff573199..00000000 --- a/pkg/cgroupClient/clientset/versioned/typed/cgroupnotifycrd/v1/cgroupnotifycrd_client.go +++ /dev/null @@ -1,107 +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 v1 - -import ( - "net/http" - - v1 "github.com/tencent/caelus/pkg/apis/cgroupnotifycrd/v1" - "github.com/tencent/caelus/pkg/cgroupClient/clientset/versioned/scheme" - rest "k8s.io/client-go/rest" -) - -type CgroupnotifycrdV1Interface interface { - RESTClient() rest.Interface - CgroupNotifyCrdsGetter -} - -// CgroupnotifycrdV1Client is used to interact with features provided by the cgroupnotifycrd group. -type CgroupnotifycrdV1Client struct { - restClient rest.Interface -} - -func (c *CgroupnotifycrdV1Client) CgroupNotifyCrds(namespace string) CgroupNotifyCrdInterface { - return newCgroupNotifyCrds(c, namespace) -} - -// NewForConfig creates a new CgroupnotifycrdV1Client for the given config. -// NewForConfig is equivalent to NewForConfigAndClient(c, httpClient), -// where httpClient was generated with rest.HTTPClientFor(c). -func NewForConfig(c *rest.Config) (*CgroupnotifycrdV1Client, 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 CgroupnotifycrdV1Client 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) (*CgroupnotifycrdV1Client, 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 &CgroupnotifycrdV1Client{client}, nil -} - -// NewForConfigOrDie creates a new CgroupnotifycrdV1Client for the given config and -// panics if there is an error in the config. -func NewForConfigOrDie(c *rest.Config) *CgroupnotifycrdV1Client { - client, err := NewForConfig(c) - if err != nil { - panic(err) - } - return client -} - -// New creates a new CgroupnotifycrdV1Client for the given RESTClient. -func New(c rest.Interface) *CgroupnotifycrdV1Client { - return &CgroupnotifycrdV1Client{c} -} - -func setConfigDefaults(config *rest.Config) error { - gv := v1.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 *CgroupnotifycrdV1Client) RESTClient() rest.Interface { - if c == nil { - return nil - } - return c.restClient -} diff --git a/pkg/cgroupClient/clientset/versioned/typed/cgroupnotifycrd/v1/doc.go b/pkg/cgroupClient/clientset/versioned/typed/cgroupnotifycrd/v1/doc.go deleted file mode 100644 index 3af5d054..00000000 --- a/pkg/cgroupClient/clientset/versioned/typed/cgroupnotifycrd/v1/doc.go +++ /dev/null @@ -1,20 +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. - -// This package has the automatically generated typed clients. -package v1 diff --git a/pkg/cgroupClient/clientset/versioned/typed/cgroupnotifycrd/v1/fake/doc.go b/pkg/cgroupClient/clientset/versioned/typed/cgroupnotifycrd/v1/fake/doc.go deleted file mode 100644 index 16f44399..00000000 --- a/pkg/cgroupClient/clientset/versioned/typed/cgroupnotifycrd/v1/fake/doc.go +++ /dev/null @@ -1,20 +0,0 @@ -/* -Copyright The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by client-gen. DO NOT EDIT. - -// Package fake has the automatically generated clients. -package fake diff --git a/pkg/cgroupClient/clientset/versioned/typed/cgroupnotifycrd/v1/fake/fake_cgroupnotifycrd.go b/pkg/cgroupClient/clientset/versioned/typed/cgroupnotifycrd/v1/fake/fake_cgroupnotifycrd.go deleted file mode 100644 index a94308b7..00000000 --- a/pkg/cgroupClient/clientset/versioned/typed/cgroupnotifycrd/v1/fake/fake_cgroupnotifycrd.go +++ /dev/null @@ -1,142 +0,0 @@ -/* -Copyright The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by client-gen. DO NOT EDIT. - -package fake - -import ( - "context" - - cgroupnotifycrdv1 "github.com/tencent/caelus/pkg/apis/cgroupnotifycrd/v1" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - labels "k8s.io/apimachinery/pkg/labels" - schema "k8s.io/apimachinery/pkg/runtime/schema" - types "k8s.io/apimachinery/pkg/types" - watch "k8s.io/apimachinery/pkg/watch" - testing "k8s.io/client-go/testing" -) - -// FakeCgroupNotifyCrds implements CgroupNotifyCrdInterface -type FakeCgroupNotifyCrds struct { - Fake *FakeCgroupnotifycrdV1 - ns string -} - -var cgroupnotifycrdsResource = schema.GroupVersionResource{Group: "cgroupnotifycrd", Version: "v1", Resource: "cgroupnotifycrds"} - -var cgroupnotifycrdsKind = schema.GroupVersionKind{Group: "cgroupnotifycrd", Version: "v1", Kind: "CgroupNotifyCrd"} - -// Get takes name of the cgroupNotifyCrd, and returns the corresponding cgroupNotifyCrd object, and an error if there is any. -func (c *FakeCgroupNotifyCrds) Get(ctx context.Context, name string, options v1.GetOptions) (result *cgroupnotifycrdv1.CgroupNotifyCrd, err error) { - obj, err := c.Fake. - Invokes(testing.NewGetAction(cgroupnotifycrdsResource, c.ns, name), &cgroupnotifycrdv1.CgroupNotifyCrd{}) - - if obj == nil { - return nil, err - } - return obj.(*cgroupnotifycrdv1.CgroupNotifyCrd), err -} - -// List takes label and field selectors, and returns the list of CgroupNotifyCrds that match those selectors. -func (c *FakeCgroupNotifyCrds) List(ctx context.Context, opts v1.ListOptions) (result *cgroupnotifycrdv1.CgroupNotifyCrdList, err error) { - obj, err := c.Fake. - Invokes(testing.NewListAction(cgroupnotifycrdsResource, cgroupnotifycrdsKind, c.ns, opts), &cgroupnotifycrdv1.CgroupNotifyCrdList{}) - - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &cgroupnotifycrdv1.CgroupNotifyCrdList{ListMeta: obj.(*cgroupnotifycrdv1.CgroupNotifyCrdList).ListMeta} - for _, item := range obj.(*cgroupnotifycrdv1.CgroupNotifyCrdList).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 cgroupNotifyCrds. -func (c *FakeCgroupNotifyCrds) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { - return c.Fake. - InvokesWatch(testing.NewWatchAction(cgroupnotifycrdsResource, c.ns, opts)) - -} - -// Create takes the representation of a cgroupNotifyCrd and creates it. Returns the server's representation of the cgroupNotifyCrd, and an error, if there is any. -func (c *FakeCgroupNotifyCrds) Create(ctx context.Context, cgroupNotifyCrd *cgroupnotifycrdv1.CgroupNotifyCrd, opts v1.CreateOptions) (result *cgroupnotifycrdv1.CgroupNotifyCrd, err error) { - obj, err := c.Fake. - Invokes(testing.NewCreateAction(cgroupnotifycrdsResource, c.ns, cgroupNotifyCrd), &cgroupnotifycrdv1.CgroupNotifyCrd{}) - - if obj == nil { - return nil, err - } - return obj.(*cgroupnotifycrdv1.CgroupNotifyCrd), err -} - -// Update takes the representation of a cgroupNotifyCrd and updates it. Returns the server's representation of the cgroupNotifyCrd, and an error, if there is any. -func (c *FakeCgroupNotifyCrds) Update(ctx context.Context, cgroupNotifyCrd *cgroupnotifycrdv1.CgroupNotifyCrd, opts v1.UpdateOptions) (result *cgroupnotifycrdv1.CgroupNotifyCrd, err error) { - obj, err := c.Fake. - Invokes(testing.NewUpdateAction(cgroupnotifycrdsResource, c.ns, cgroupNotifyCrd), &cgroupnotifycrdv1.CgroupNotifyCrd{}) - - if obj == nil { - return nil, err - } - return obj.(*cgroupnotifycrdv1.CgroupNotifyCrd), 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 *FakeCgroupNotifyCrds) UpdateStatus(ctx context.Context, cgroupNotifyCrd *cgroupnotifycrdv1.CgroupNotifyCrd, opts v1.UpdateOptions) (*cgroupnotifycrdv1.CgroupNotifyCrd, error) { - obj, err := c.Fake. - Invokes(testing.NewUpdateSubresourceAction(cgroupnotifycrdsResource, "status", c.ns, cgroupNotifyCrd), &cgroupnotifycrdv1.CgroupNotifyCrd{}) - - if obj == nil { - return nil, err - } - return obj.(*cgroupnotifycrdv1.CgroupNotifyCrd), err -} - -// Delete takes name of the cgroupNotifyCrd and deletes it. Returns an error if one occurs. -func (c *FakeCgroupNotifyCrds) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { - _, err := c.Fake. - Invokes(testing.NewDeleteActionWithOptions(cgroupnotifycrdsResource, c.ns, name, opts), &cgroupnotifycrdv1.CgroupNotifyCrd{}) - - return err -} - -// DeleteCollection deletes a collection of objects. -func (c *FakeCgroupNotifyCrds) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { - action := testing.NewDeleteCollectionAction(cgroupnotifycrdsResource, c.ns, listOpts) - - _, err := c.Fake.Invokes(action, &cgroupnotifycrdv1.CgroupNotifyCrdList{}) - return err -} - -// Patch applies the patch and returns the patched cgroupNotifyCrd. -func (c *FakeCgroupNotifyCrds) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *cgroupnotifycrdv1.CgroupNotifyCrd, err error) { - obj, err := c.Fake. - Invokes(testing.NewPatchSubresourceAction(cgroupnotifycrdsResource, c.ns, name, pt, data, subresources...), &cgroupnotifycrdv1.CgroupNotifyCrd{}) - - if obj == nil { - return nil, err - } - return obj.(*cgroupnotifycrdv1.CgroupNotifyCrd), err -} diff --git a/pkg/cgroupClient/clientset/versioned/typed/cgroupnotifycrd/v1/fake/fake_cgroupnotifycrd_client.go b/pkg/cgroupClient/clientset/versioned/typed/cgroupnotifycrd/v1/fake/fake_cgroupnotifycrd_client.go deleted file mode 100644 index 036f1f0b..00000000 --- a/pkg/cgroupClient/clientset/versioned/typed/cgroupnotifycrd/v1/fake/fake_cgroupnotifycrd_client.go +++ /dev/null @@ -1,40 +0,0 @@ -/* -Copyright The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by client-gen. DO NOT EDIT. - -package fake - -import ( - v1 "github.com/tencent/caelus/pkg/cgroupClient/clientset/versioned/typed/cgroupnotifycrd/v1" - rest "k8s.io/client-go/rest" - testing "k8s.io/client-go/testing" -) - -type FakeCgroupnotifycrdV1 struct { - *testing.Fake -} - -func (c *FakeCgroupnotifycrdV1) CgroupNotifyCrds(namespace string) v1.CgroupNotifyCrdInterface { - return &FakeCgroupNotifyCrds{c, namespace} -} - -// RESTClient returns a RESTClient that is used to communicate -// with API server by this client implementation. -func (c *FakeCgroupnotifycrdV1) RESTClient() rest.Interface { - var ret *rest.RESTClient - return ret -} diff --git a/pkg/cgroupClient/clientset/versioned/typed/cgroupnotifycrd/v1/generated_expansion.go b/pkg/cgroupClient/clientset/versioned/typed/cgroupnotifycrd/v1/generated_expansion.go deleted file mode 100644 index 3d114c4b..00000000 --- a/pkg/cgroupClient/clientset/versioned/typed/cgroupnotifycrd/v1/generated_expansion.go +++ /dev/null @@ -1,21 +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 v1 - -type CgroupNotifyCrdExpansion interface{} diff --git a/pkg/cgroupClient/informers/externalversions/cgroupnotifycrd/interface.go b/pkg/cgroupClient/informers/externalversions/cgroupnotifycrd/interface.go deleted file mode 100644 index 71312a4b..00000000 --- a/pkg/cgroupClient/informers/externalversions/cgroupnotifycrd/interface.go +++ /dev/null @@ -1,46 +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 cgroupnotifycrd - -import ( - v1 "github.com/tencent/caelus/pkg/cgroupClient/informers/externalversions/cgroupnotifycrd/v1" - internalinterfaces "github.com/tencent/caelus/pkg/cgroupClient/informers/externalversions/internalinterfaces" -) - -// Interface provides access to each of this group's versions. -type Interface interface { - // V1 provides access to shared informers for resources in V1. - V1() v1.Interface -} - -type group struct { - factory internalinterfaces.SharedInformerFactory - namespace string - tweakListOptions internalinterfaces.TweakListOptionsFunc -} - -// New returns a new Interface. -func New(f internalinterfaces.SharedInformerFactory, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) Interface { - return &group{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} -} - -// V1 returns a new v1.Interface. -func (g *group) V1() v1.Interface { - return v1.New(g.factory, g.namespace, g.tweakListOptions) -} diff --git a/pkg/cgroupClient/informers/externalversions/cgroupnotifycrd/v1/cgroupnotifycrd.go b/pkg/cgroupClient/informers/externalversions/cgroupnotifycrd/v1/cgroupnotifycrd.go deleted file mode 100644 index 4177efdb..00000000 --- a/pkg/cgroupClient/informers/externalversions/cgroupnotifycrd/v1/cgroupnotifycrd.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 v1 - -import ( - "context" - time "time" - - cgroupnotifycrdv1 "github.com/tencent/caelus/pkg/apis/cgroupnotifycrd/v1" - versioned "github.com/tencent/caelus/pkg/cgroupClient/clientset/versioned" - internalinterfaces "github.com/tencent/caelus/pkg/cgroupClient/informers/externalversions/internalinterfaces" - v1 "github.com/tencent/caelus/pkg/cgroupClient/listers/cgroupnotifycrd/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - runtime "k8s.io/apimachinery/pkg/runtime" - watch "k8s.io/apimachinery/pkg/watch" - cache "k8s.io/client-go/tools/cache" -) - -// CgroupNotifyCrdInformer provides access to a shared informer and lister for -// CgroupNotifyCrds. -type CgroupNotifyCrdInformer interface { - Informer() cache.SharedIndexInformer - Lister() v1.CgroupNotifyCrdLister -} - -type cgroupNotifyCrdInformer struct { - factory internalinterfaces.SharedInformerFactory - tweakListOptions internalinterfaces.TweakListOptionsFunc - namespace string -} - -// NewCgroupNotifyCrdInformer constructs a new informer for CgroupNotifyCrd 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 NewCgroupNotifyCrdInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { - return NewFilteredCgroupNotifyCrdInformer(client, namespace, resyncPeriod, indexers, nil) -} - -// NewFilteredCgroupNotifyCrdInformer constructs a new informer for CgroupNotifyCrd 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 NewFilteredCgroupNotifyCrdInformer(client versioned.Interface, namespace string, 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.CgroupnotifycrdV1().CgroupNotifyCrds(namespace).List(context.TODO(), options) - }, - WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { - if tweakListOptions != nil { - tweakListOptions(&options) - } - return client.CgroupnotifycrdV1().CgroupNotifyCrds(namespace).Watch(context.TODO(), options) - }, - }, - &cgroupnotifycrdv1.CgroupNotifyCrd{}, - resyncPeriod, - indexers, - ) -} - -func (f *cgroupNotifyCrdInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { - return NewFilteredCgroupNotifyCrdInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) -} - -func (f *cgroupNotifyCrdInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&cgroupnotifycrdv1.CgroupNotifyCrd{}, f.defaultInformer) -} - -func (f *cgroupNotifyCrdInformer) Lister() v1.CgroupNotifyCrdLister { - return v1.NewCgroupNotifyCrdLister(f.Informer().GetIndexer()) -} diff --git a/pkg/cgroupClient/informers/externalversions/cgroupnotifycrd/v1/interface.go b/pkg/cgroupClient/informers/externalversions/cgroupnotifycrd/v1/interface.go deleted file mode 100644 index 52a0f430..00000000 --- a/pkg/cgroupClient/informers/externalversions/cgroupnotifycrd/v1/interface.go +++ /dev/null @@ -1,45 +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 v1 - -import ( - internalinterfaces "github.com/tencent/caelus/pkg/cgroupClient/informers/externalversions/internalinterfaces" -) - -// Interface provides access to all the informers in this group version. -type Interface interface { - // CgroupNotifyCrds returns a CgroupNotifyCrdInformer. - CgroupNotifyCrds() CgroupNotifyCrdInformer -} - -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} -} - -// CgroupNotifyCrds returns a CgroupNotifyCrdInformer. -func (v *version) CgroupNotifyCrds() CgroupNotifyCrdInformer { - return &cgroupNotifyCrdInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} -} diff --git a/pkg/cgroupClient/informers/externalversions/factory.go b/pkg/cgroupClient/informers/externalversions/factory.go deleted file mode 100644 index 4b86108c..00000000 --- a/pkg/cgroupClient/informers/externalversions/factory.go +++ /dev/null @@ -1,180 +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 externalversions - -import ( - reflect "reflect" - sync "sync" - time "time" - - versioned "github.com/tencent/caelus/pkg/cgroupClient/clientset/versioned" - cgroupnotifycrd "github.com/tencent/caelus/pkg/cgroupClient/informers/externalversions/cgroupnotifycrd" - internalinterfaces "github.com/tencent/caelus/pkg/cgroupClient/informers/externalversions/internalinterfaces" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - runtime "k8s.io/apimachinery/pkg/runtime" - schema "k8s.io/apimachinery/pkg/runtime/schema" - cache "k8s.io/client-go/tools/cache" -) - -// SharedInformerOption defines the functional option type for SharedInformerFactory. -type SharedInformerOption func(*sharedInformerFactory) *sharedInformerFactory - -type sharedInformerFactory struct { - client versioned.Interface - namespace string - tweakListOptions internalinterfaces.TweakListOptionsFunc - lock sync.Mutex - defaultResync time.Duration - customResync map[reflect.Type]time.Duration - - 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 -} - -// 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 -} - -// Start initializes all requested informers. -func (f *sharedInformerFactory) Start(stopCh <-chan struct{}) { - f.lock.Lock() - defer f.lock.Unlock() - - for informerType, informer := range f.informers { - if !f.startedInformers[informerType] { - go informer.Run(stopCh) - f.startedInformers[informerType] = true - } - } -} - -// WaitForCacheSync waits for all started informers' cache were synced. -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. -type SharedInformerFactory interface { - internalinterfaces.SharedInformerFactory - ForResource(resource schema.GroupVersionResource) (GenericInformer, error) - WaitForCacheSync(stopCh <-chan struct{}) map[reflect.Type]bool - - Cgroupnotifycrd() cgroupnotifycrd.Interface -} - -func (f *sharedInformerFactory) Cgroupnotifycrd() cgroupnotifycrd.Interface { - return cgroupnotifycrd.New(f, f.namespace, f.tweakListOptions) -} diff --git a/pkg/cgroupClient/informers/externalversions/generic.go b/pkg/cgroupClient/informers/externalversions/generic.go deleted file mode 100644 index 4a4f0604..00000000 --- a/pkg/cgroupClient/informers/externalversions/generic.go +++ /dev/null @@ -1,62 +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 externalversions - -import ( - "fmt" - - v1 "github.com/tencent/caelus/pkg/apis/cgroupnotifycrd/v1" - schema "k8s.io/apimachinery/pkg/runtime/schema" - cache "k8s.io/client-go/tools/cache" -) - -// GenericInformer is type of SharedIndexInformer which will locate and delegate to other -// sharedInformers based on type -type GenericInformer interface { - Informer() cache.SharedIndexInformer - Lister() cache.GenericLister -} - -type genericInformer struct { - informer cache.SharedIndexInformer - resource schema.GroupResource -} - -// Informer returns the SharedIndexInformer. -func (f *genericInformer) Informer() cache.SharedIndexInformer { - return f.informer -} - -// Lister returns the GenericLister. -func (f *genericInformer) Lister() cache.GenericLister { - return cache.NewGenericLister(f.Informer().GetIndexer(), f.resource) -} - -// ForResource gives generic access to a shared informer of the matching type -// TODO extend this to unknown resources with a client pool -func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource) (GenericInformer, error) { - switch resource { - // Group=cgroupnotifycrd, Version=v1 - case v1.SchemeGroupVersion.WithResource("cgroupnotifycrds"): - return &genericInformer{resource: resource.GroupResource(), informer: f.Cgroupnotifycrd().V1().CgroupNotifyCrds().Informer()}, nil - - } - - return nil, fmt.Errorf("no informer found for %v", resource) -} diff --git a/pkg/cgroupClient/informers/externalversions/internalinterfaces/factory_interfaces.go b/pkg/cgroupClient/informers/externalversions/internalinterfaces/factory_interfaces.go deleted file mode 100644 index 6b38c474..00000000 --- a/pkg/cgroupClient/informers/externalversions/internalinterfaces/factory_interfaces.go +++ /dev/null @@ -1,40 +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 internalinterfaces - -import ( - time "time" - - versioned "github.com/tencent/caelus/pkg/cgroupClient/clientset/versioned" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - runtime "k8s.io/apimachinery/pkg/runtime" - cache "k8s.io/client-go/tools/cache" -) - -// NewInformerFunc takes versioned.Interface and time.Duration to return a SharedIndexInformer. -type NewInformerFunc func(versioned.Interface, time.Duration) cache.SharedIndexInformer - -// SharedInformerFactory a small interface to allow for adding an informer without an import cycle -type SharedInformerFactory interface { - Start(stopCh <-chan struct{}) - InformerFor(obj runtime.Object, newFunc NewInformerFunc) cache.SharedIndexInformer -} - -// TweakListOptionsFunc is a function that transforms a v1.ListOptions. -type TweakListOptionsFunc func(*v1.ListOptions) diff --git a/pkg/cgroupClient/listers/cgroupnotifycrd/v1/cgroupnotifycrd.go b/pkg/cgroupClient/listers/cgroupnotifycrd/v1/cgroupnotifycrd.go deleted file mode 100644 index a9c32375..00000000 --- a/pkg/cgroupClient/listers/cgroupnotifycrd/v1/cgroupnotifycrd.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 v1 - -import ( - v1 "github.com/tencent/caelus/pkg/apis/cgroupnotifycrd/v1" - "k8s.io/apimachinery/pkg/api/errors" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/client-go/tools/cache" -) - -// CgroupNotifyCrdLister helps list CgroupNotifyCrds. -// All objects returned here must be treated as read-only. -type CgroupNotifyCrdLister interface { - // List lists all CgroupNotifyCrds in the indexer. - // Objects returned here must be treated as read-only. - List(selector labels.Selector) (ret []*v1.CgroupNotifyCrd, err error) - // CgroupNotifyCrds returns an object that can list and get CgroupNotifyCrds. - CgroupNotifyCrds(namespace string) CgroupNotifyCrdNamespaceLister - CgroupNotifyCrdListerExpansion -} - -// cgroupNotifyCrdLister implements the CgroupNotifyCrdLister interface. -type cgroupNotifyCrdLister struct { - indexer cache.Indexer -} - -// NewCgroupNotifyCrdLister returns a new CgroupNotifyCrdLister. -func NewCgroupNotifyCrdLister(indexer cache.Indexer) CgroupNotifyCrdLister { - return &cgroupNotifyCrdLister{indexer: indexer} -} - -// List lists all CgroupNotifyCrds in the indexer. -func (s *cgroupNotifyCrdLister) List(selector labels.Selector) (ret []*v1.CgroupNotifyCrd, err error) { - err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*v1.CgroupNotifyCrd)) - }) - return ret, err -} - -// CgroupNotifyCrds returns an object that can list and get CgroupNotifyCrds. -func (s *cgroupNotifyCrdLister) CgroupNotifyCrds(namespace string) CgroupNotifyCrdNamespaceLister { - return cgroupNotifyCrdNamespaceLister{indexer: s.indexer, namespace: namespace} -} - -// CgroupNotifyCrdNamespaceLister helps list and get CgroupNotifyCrds. -// All objects returned here must be treated as read-only. -type CgroupNotifyCrdNamespaceLister interface { - // List lists all CgroupNotifyCrds in the indexer for a given namespace. - // Objects returned here must be treated as read-only. - List(selector labels.Selector) (ret []*v1.CgroupNotifyCrd, err error) - // Get retrieves the CgroupNotifyCrd from the indexer for a given namespace and name. - // Objects returned here must be treated as read-only. - Get(name string) (*v1.CgroupNotifyCrd, error) - CgroupNotifyCrdNamespaceListerExpansion -} - -// cgroupNotifyCrdNamespaceLister implements the CgroupNotifyCrdNamespaceLister -// interface. -type cgroupNotifyCrdNamespaceLister struct { - indexer cache.Indexer - namespace string -} - -// List lists all CgroupNotifyCrds in the indexer for a given namespace. -func (s cgroupNotifyCrdNamespaceLister) List(selector labels.Selector) (ret []*v1.CgroupNotifyCrd, err error) { - err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { - ret = append(ret, m.(*v1.CgroupNotifyCrd)) - }) - return ret, err -} - -// Get retrieves the CgroupNotifyCrd from the indexer for a given namespace and name. -func (s cgroupNotifyCrdNamespaceLister) Get(name string) (*v1.CgroupNotifyCrd, error) { - obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(v1.Resource("cgroupnotifycrd"), name) - } - return obj.(*v1.CgroupNotifyCrd), nil -} diff --git a/pkg/cgroupClient/listers/cgroupnotifycrd/v1/expansion_generated.go b/pkg/cgroupClient/listers/cgroupnotifycrd/v1/expansion_generated.go deleted file mode 100644 index 278e31de..00000000 --- a/pkg/cgroupClient/listers/cgroupnotifycrd/v1/expansion_generated.go +++ /dev/null @@ -1,27 +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 v1 - -// CgroupNotifyCrdListerExpansion allows custom methods to be added to -// CgroupNotifyCrdLister. -type CgroupNotifyCrdListerExpansion interface{} - -// CgroupNotifyCrdNamespaceListerExpansion allows custom methods to be added to -// CgroupNotifyCrdNamespaceLister. -type CgroupNotifyCrdNamespaceListerExpansion interface{} diff --git a/pkg/generated/clientset/versioned/clientset.go b/pkg/generated/clientset/versioned/clientset.go index e5de8b2e..82ad164f 100644 --- a/pkg/generated/clientset/versioned/clientset.go +++ b/pkg/generated/clientset/versioned/clientset.go @@ -1,17 +1,19 @@ /* - * Copyright (c) 2021 THL A29 Limited, a Tencent company. - * - * 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. - */ +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 @@ -59,10 +61,6 @@ func (c *Clientset) Discovery() discovery.DiscoveryInterface { 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 { diff --git a/pkg/generated/clientset/versioned/doc.go b/pkg/generated/clientset/versioned/doc.go index 8eb91c9a..41721ca5 100644 --- a/pkg/generated/clientset/versioned/doc.go +++ b/pkg/generated/clientset/versioned/doc.go @@ -1,17 +1,19 @@ /* - * Copyright (c) 2021 THL A29 Limited, a Tencent company. - * - * 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. - */ +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 clientset. diff --git a/pkg/generated/clientset/versioned/fake/clientset_generated.go b/pkg/generated/clientset/versioned/fake/clientset_generated.go index 96390304..8467e949 100644 --- a/pkg/generated/clientset/versioned/fake/clientset_generated.go +++ b/pkg/generated/clientset/versioned/fake/clientset_generated.go @@ -1,17 +1,19 @@ /* - * Copyright (c) 2021 THL A29 Limited, a Tencent company. - * - * 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. - */ +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 diff --git a/pkg/generated/clientset/versioned/fake/doc.go b/pkg/generated/clientset/versioned/fake/doc.go index c8a212b7..9b99e716 100644 --- a/pkg/generated/clientset/versioned/fake/doc.go +++ b/pkg/generated/clientset/versioned/fake/doc.go @@ -1,17 +1,19 @@ /* - * Copyright (c) 2021 THL A29 Limited, a Tencent company. - * - * 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. - */ +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. diff --git a/pkg/generated/clientset/versioned/fake/register.go b/pkg/generated/clientset/versioned/fake/register.go index 6f6f1cec..4aa0c1e7 100644 --- a/pkg/generated/clientset/versioned/fake/register.go +++ b/pkg/generated/clientset/versioned/fake/register.go @@ -1,17 +1,19 @@ /* - * Copyright (c) 2021 THL A29 Limited, a Tencent company. - * - * 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. - */ +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 diff --git a/pkg/generated/clientset/versioned/scheme/doc.go b/pkg/generated/clientset/versioned/scheme/doc.go index d5857dc0..7dc37561 100644 --- a/pkg/generated/clientset/versioned/scheme/doc.go +++ b/pkg/generated/clientset/versioned/scheme/doc.go @@ -1,17 +1,19 @@ /* - * Copyright (c) 2021 THL A29 Limited, a Tencent company. - * - * 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. - */ +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. diff --git a/pkg/generated/clientset/versioned/scheme/register.go b/pkg/generated/clientset/versioned/scheme/register.go index ea028ec2..7b98c39d 100644 --- a/pkg/generated/clientset/versioned/scheme/register.go +++ b/pkg/generated/clientset/versioned/scheme/register.go @@ -1,17 +1,19 @@ /* - * Copyright (c) 2021 THL A29 Limited, a Tencent company. - * - * 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. - */ +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 diff --git a/pkg/generated/clientset/versioned/typed/caelus/v1/caelus_client.go b/pkg/generated/clientset/versioned/typed/caelus/v1/caelus_client.go index be5877ad..0b7d000c 100644 --- a/pkg/generated/clientset/versioned/typed/caelus/v1/caelus_client.go +++ b/pkg/generated/clientset/versioned/typed/caelus/v1/caelus_client.go @@ -1,17 +1,19 @@ /* - * Copyright (c) 2021 THL A29 Limited, a Tencent company. - * - * 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. - */ +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + // Code generated by client-gen. DO NOT EDIT. package v1 @@ -26,6 +28,7 @@ import ( type CaelusV1Interface interface { RESTClient() rest.Interface + CgroupNotifiesGetter RuleChecksGetter } @@ -34,6 +37,10 @@ type CaelusV1Client struct { restClient rest.Interface } +func (c *CaelusV1Client) CgroupNotifies(namespace string) CgroupNotifyInterface { + return newCgroupNotifies(c, namespace) +} + func (c *CaelusV1Client) RuleChecks(namespace string) RuleCheckInterface { return newRuleChecks(c, namespace) } diff --git a/pkg/generated/clientset/versioned/typed/caelus/v1/cgroupnotify.go b/pkg/generated/clientset/versioned/typed/caelus/v1/cgroupnotify.go new file mode 100644 index 00000000..c40084ee --- /dev/null +++ b/pkg/generated/clientset/versioned/typed/caelus/v1/cgroupnotify.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 v1 + +import ( + "context" + "time" + + v1 "github.com/tencent/caelus/pkg/apis/caelus/v1" + scheme "github.com/tencent/caelus/pkg/generated/clientset/versioned/scheme" + metav1 "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" +) + +// CgroupNotifiesGetter has a method to return a CgroupNotifyInterface. +// A group's client should implement this interface. +type CgroupNotifiesGetter interface { + CgroupNotifies(namespace string) CgroupNotifyInterface +} + +// CgroupNotifyInterface has methods to work with CgroupNotify resources. +type CgroupNotifyInterface interface { + Create(ctx context.Context, cgroupNotify *v1.CgroupNotify, opts metav1.CreateOptions) (*v1.CgroupNotify, error) + Update(ctx context.Context, cgroupNotify *v1.CgroupNotify, opts metav1.UpdateOptions) (*v1.CgroupNotify, error) + UpdateStatus(ctx context.Context, cgroupNotify *v1.CgroupNotify, opts metav1.UpdateOptions) (*v1.CgroupNotify, 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.CgroupNotify, error) + List(ctx context.Context, opts metav1.ListOptions) (*v1.CgroupNotifyList, 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.CgroupNotify, err error) + CgroupNotifyExpansion +} + +// cgroupNotifies implements CgroupNotifyInterface +type cgroupNotifies struct { + client rest.Interface + ns string +} + +// newCgroupNotifies returns a CgroupNotifies +func newCgroupNotifies(c *CaelusV1Client, namespace string) *cgroupNotifies { + return &cgroupNotifies{ + client: c.RESTClient(), + ns: namespace, + } +} + +// Get takes name of the cgroupNotify, and returns the corresponding cgroupNotify object, and an error if there is any. +func (c *cgroupNotifies) Get(ctx context.Context, name string, options metav1.GetOptions) (result *v1.CgroupNotify, err error) { + result = &v1.CgroupNotify{} + err = c.client.Get(). + Namespace(c.ns). + Resource("cgroupnotifies"). + Name(name). + VersionedParams(&options, scheme.ParameterCodec). + Do(ctx). + Into(result) + return +} + +// List takes label and field selectors, and returns the list of CgroupNotifies that match those selectors. +func (c *cgroupNotifies) List(ctx context.Context, opts metav1.ListOptions) (result *v1.CgroupNotifyList, err error) { + var timeout time.Duration + if opts.TimeoutSeconds != nil { + timeout = time.Duration(*opts.TimeoutSeconds) * time.Second + } + result = &v1.CgroupNotifyList{} + err = c.client.Get(). + Namespace(c.ns). + Resource("cgroupnotifies"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Do(ctx). + Into(result) + return +} + +// Watch returns a watch.Interface that watches the requested cgroupNotifies. +func (c *cgroupNotifies) 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(). + Namespace(c.ns). + Resource("cgroupnotifies"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Watch(ctx) +} + +// Create takes the representation of a cgroupNotify and creates it. Returns the server's representation of the cgroupNotify, and an error, if there is any. +func (c *cgroupNotifies) Create(ctx context.Context, cgroupNotify *v1.CgroupNotify, opts metav1.CreateOptions) (result *v1.CgroupNotify, err error) { + result = &v1.CgroupNotify{} + err = c.client.Post(). + Namespace(c.ns). + Resource("cgroupnotifies"). + VersionedParams(&opts, scheme.ParameterCodec). + Body(cgroupNotify). + Do(ctx). + Into(result) + return +} + +// Update takes the representation of a cgroupNotify and updates it. Returns the server's representation of the cgroupNotify, and an error, if there is any. +func (c *cgroupNotifies) Update(ctx context.Context, cgroupNotify *v1.CgroupNotify, opts metav1.UpdateOptions) (result *v1.CgroupNotify, err error) { + result = &v1.CgroupNotify{} + err = c.client.Put(). + Namespace(c.ns). + Resource("cgroupnotifies"). + Name(cgroupNotify.Name). + VersionedParams(&opts, scheme.ParameterCodec). + Body(cgroupNotify). + 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 *cgroupNotifies) UpdateStatus(ctx context.Context, cgroupNotify *v1.CgroupNotify, opts metav1.UpdateOptions) (result *v1.CgroupNotify, err error) { + result = &v1.CgroupNotify{} + err = c.client.Put(). + Namespace(c.ns). + Resource("cgroupnotifies"). + Name(cgroupNotify.Name). + SubResource("status"). + VersionedParams(&opts, scheme.ParameterCodec). + Body(cgroupNotify). + Do(ctx). + Into(result) + return +} + +// Delete takes name of the cgroupNotify and deletes it. Returns an error if one occurs. +func (c *cgroupNotifies) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error { + return c.client.Delete(). + Namespace(c.ns). + Resource("cgroupnotifies"). + Name(name). + Body(&opts). + Do(ctx). + Error() +} + +// DeleteCollection deletes a collection of objects. +func (c *cgroupNotifies) 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(). + Namespace(c.ns). + Resource("cgroupnotifies"). + VersionedParams(&listOpts, scheme.ParameterCodec). + Timeout(timeout). + Body(&opts). + Do(ctx). + Error() +} + +// Patch applies the patch and returns the patched cgroupNotify. +func (c *cgroupNotifies) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.CgroupNotify, err error) { + result = &v1.CgroupNotify{} + err = c.client.Patch(pt). + Namespace(c.ns). + Resource("cgroupnotifies"). + Name(name). + SubResource(subresources...). + VersionedParams(&opts, scheme.ParameterCodec). + Body(data). + Do(ctx). + Into(result) + return +} diff --git a/pkg/generated/clientset/versioned/typed/caelus/v1/doc.go b/pkg/generated/clientset/versioned/typed/caelus/v1/doc.go index dd003f29..3af5d054 100644 --- a/pkg/generated/clientset/versioned/typed/caelus/v1/doc.go +++ b/pkg/generated/clientset/versioned/typed/caelus/v1/doc.go @@ -1,17 +1,19 @@ /* - * Copyright (c) 2021 THL A29 Limited, a Tencent company. - * - * 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. - */ +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. diff --git a/pkg/generated/clientset/versioned/typed/caelus/v1/fake/doc.go b/pkg/generated/clientset/versioned/typed/caelus/v1/fake/doc.go index 12074a52..16f44399 100644 --- a/pkg/generated/clientset/versioned/typed/caelus/v1/fake/doc.go +++ b/pkg/generated/clientset/versioned/typed/caelus/v1/fake/doc.go @@ -1,17 +1,19 @@ /* - * Copyright (c) 2021 THL A29 Limited, a Tencent company. - * - * 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. - */ +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. diff --git a/pkg/generated/clientset/versioned/typed/caelus/v1/fake/fake_caelus_client.go b/pkg/generated/clientset/versioned/typed/caelus/v1/fake/fake_caelus_client.go index 6bca9267..b3a2a5f5 100644 --- a/pkg/generated/clientset/versioned/typed/caelus/v1/fake/fake_caelus_client.go +++ b/pkg/generated/clientset/versioned/typed/caelus/v1/fake/fake_caelus_client.go @@ -1,17 +1,19 @@ /* - * Copyright (c) 2021 THL A29 Limited, a Tencent company. - * - * 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. - */ +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 @@ -26,6 +28,10 @@ type FakeCaelusV1 struct { *testing.Fake } +func (c *FakeCaelusV1) CgroupNotifies(namespace string) v1.CgroupNotifyInterface { + return &FakeCgroupNotifies{c, namespace} +} + func (c *FakeCaelusV1) RuleChecks(namespace string) v1.RuleCheckInterface { return &FakeRuleChecks{c, namespace} } diff --git a/pkg/generated/clientset/versioned/typed/caelus/v1/fake/fake_cgroupnotify.go b/pkg/generated/clientset/versioned/typed/caelus/v1/fake/fake_cgroupnotify.go new file mode 100644 index 00000000..572b051a --- /dev/null +++ b/pkg/generated/clientset/versioned/typed/caelus/v1/fake/fake_cgroupnotify.go @@ -0,0 +1,142 @@ +/* +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" + + caelusv1 "github.com/tencent/caelus/pkg/apis/caelus/v1" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + labels "k8s.io/apimachinery/pkg/labels" + schema "k8s.io/apimachinery/pkg/runtime/schema" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + testing "k8s.io/client-go/testing" +) + +// FakeCgroupNotifies implements CgroupNotifyInterface +type FakeCgroupNotifies struct { + Fake *FakeCaelusV1 + ns string +} + +var cgroupnotifiesResource = schema.GroupVersionResource{Group: "caelus", Version: "v1", Resource: "cgroupnotifies"} + +var cgroupnotifiesKind = schema.GroupVersionKind{Group: "caelus", Version: "v1", Kind: "CgroupNotify"} + +// Get takes name of the cgroupNotify, and returns the corresponding cgroupNotify object, and an error if there is any. +func (c *FakeCgroupNotifies) Get(ctx context.Context, name string, options v1.GetOptions) (result *caelusv1.CgroupNotify, err error) { + obj, err := c.Fake. + Invokes(testing.NewGetAction(cgroupnotifiesResource, c.ns, name), &caelusv1.CgroupNotify{}) + + if obj == nil { + return nil, err + } + return obj.(*caelusv1.CgroupNotify), err +} + +// List takes label and field selectors, and returns the list of CgroupNotifies that match those selectors. +func (c *FakeCgroupNotifies) List(ctx context.Context, opts v1.ListOptions) (result *caelusv1.CgroupNotifyList, err error) { + obj, err := c.Fake. + Invokes(testing.NewListAction(cgroupnotifiesResource, cgroupnotifiesKind, c.ns, opts), &caelusv1.CgroupNotifyList{}) + + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &caelusv1.CgroupNotifyList{ListMeta: obj.(*caelusv1.CgroupNotifyList).ListMeta} + for _, item := range obj.(*caelusv1.CgroupNotifyList).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 cgroupNotifies. +func (c *FakeCgroupNotifies) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { + return c.Fake. + InvokesWatch(testing.NewWatchAction(cgroupnotifiesResource, c.ns, opts)) + +} + +// Create takes the representation of a cgroupNotify and creates it. Returns the server's representation of the cgroupNotify, and an error, if there is any. +func (c *FakeCgroupNotifies) Create(ctx context.Context, cgroupNotify *caelusv1.CgroupNotify, opts v1.CreateOptions) (result *caelusv1.CgroupNotify, err error) { + obj, err := c.Fake. + Invokes(testing.NewCreateAction(cgroupnotifiesResource, c.ns, cgroupNotify), &caelusv1.CgroupNotify{}) + + if obj == nil { + return nil, err + } + return obj.(*caelusv1.CgroupNotify), err +} + +// Update takes the representation of a cgroupNotify and updates it. Returns the server's representation of the cgroupNotify, and an error, if there is any. +func (c *FakeCgroupNotifies) Update(ctx context.Context, cgroupNotify *caelusv1.CgroupNotify, opts v1.UpdateOptions) (result *caelusv1.CgroupNotify, err error) { + obj, err := c.Fake. + Invokes(testing.NewUpdateAction(cgroupnotifiesResource, c.ns, cgroupNotify), &caelusv1.CgroupNotify{}) + + if obj == nil { + return nil, err + } + return obj.(*caelusv1.CgroupNotify), 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 *FakeCgroupNotifies) UpdateStatus(ctx context.Context, cgroupNotify *caelusv1.CgroupNotify, opts v1.UpdateOptions) (*caelusv1.CgroupNotify, error) { + obj, err := c.Fake. + Invokes(testing.NewUpdateSubresourceAction(cgroupnotifiesResource, "status", c.ns, cgroupNotify), &caelusv1.CgroupNotify{}) + + if obj == nil { + return nil, err + } + return obj.(*caelusv1.CgroupNotify), err +} + +// Delete takes name of the cgroupNotify and deletes it. Returns an error if one occurs. +func (c *FakeCgroupNotifies) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { + _, err := c.Fake. + Invokes(testing.NewDeleteActionWithOptions(cgroupnotifiesResource, c.ns, name, opts), &caelusv1.CgroupNotify{}) + + return err +} + +// DeleteCollection deletes a collection of objects. +func (c *FakeCgroupNotifies) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { + action := testing.NewDeleteCollectionAction(cgroupnotifiesResource, c.ns, listOpts) + + _, err := c.Fake.Invokes(action, &caelusv1.CgroupNotifyList{}) + return err +} + +// Patch applies the patch and returns the patched cgroupNotify. +func (c *FakeCgroupNotifies) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *caelusv1.CgroupNotify, err error) { + obj, err := c.Fake. + Invokes(testing.NewPatchSubresourceAction(cgroupnotifiesResource, c.ns, name, pt, data, subresources...), &caelusv1.CgroupNotify{}) + + if obj == nil { + return nil, err + } + return obj.(*caelusv1.CgroupNotify), err +} diff --git a/pkg/generated/clientset/versioned/typed/caelus/v1/fake/fake_rulecheck.go b/pkg/generated/clientset/versioned/typed/caelus/v1/fake/fake_rulecheck.go index 66ca961d..9cff02f5 100644 --- a/pkg/generated/clientset/versioned/typed/caelus/v1/fake/fake_rulecheck.go +++ b/pkg/generated/clientset/versioned/typed/caelus/v1/fake/fake_rulecheck.go @@ -1,17 +1,19 @@ /* - * Copyright (c) 2021 THL A29 Limited, a Tencent company. - * - * 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. - */ +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 diff --git a/pkg/generated/clientset/versioned/typed/caelus/v1/generated_expansion.go b/pkg/generated/clientset/versioned/typed/caelus/v1/generated_expansion.go index d25a65c6..8736e9d5 100644 --- a/pkg/generated/clientset/versioned/typed/caelus/v1/generated_expansion.go +++ b/pkg/generated/clientset/versioned/typed/caelus/v1/generated_expansion.go @@ -1,19 +1,23 @@ /* - * Copyright (c) 2021 THL A29 Limited, a Tencent company. - * - * 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. - */ +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + // Code generated by client-gen. DO NOT EDIT. package v1 +type CgroupNotifyExpansion interface{} + type RuleCheckExpansion interface{} diff --git a/pkg/generated/clientset/versioned/typed/caelus/v1/rulecheck.go b/pkg/generated/clientset/versioned/typed/caelus/v1/rulecheck.go index 087d8966..d5b3f785 100644 --- a/pkg/generated/clientset/versioned/typed/caelus/v1/rulecheck.go +++ b/pkg/generated/clientset/versioned/typed/caelus/v1/rulecheck.go @@ -1,17 +1,19 @@ /* - * Copyright (c) 2021 THL A29 Limited, a Tencent company. - * - * 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. - */ +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + // Code generated by client-gen. DO NOT EDIT. package v1 diff --git a/pkg/generated/informers/externalversions/caelus/interface.go b/pkg/generated/informers/externalversions/caelus/interface.go index fc3afb4a..a19e58f5 100644 --- a/pkg/generated/informers/externalversions/caelus/interface.go +++ b/pkg/generated/informers/externalversions/caelus/interface.go @@ -1,17 +1,19 @@ /* - * Copyright (c) 2021 THL A29 Limited, a Tencent company. - * - * 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. - */ +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 caelus diff --git a/pkg/generated/informers/externalversions/caelus/v1/cgroupnotify.go b/pkg/generated/informers/externalversions/caelus/v1/cgroupnotify.go new file mode 100644 index 00000000..1d48b431 --- /dev/null +++ b/pkg/generated/informers/externalversions/caelus/v1/cgroupnotify.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 v1 + +import ( + "context" + time "time" + + caelusv1 "github.com/tencent/caelus/pkg/apis/caelus/v1" + versioned "github.com/tencent/caelus/pkg/generated/clientset/versioned" + internalinterfaces "github.com/tencent/caelus/pkg/generated/informers/externalversions/internalinterfaces" + v1 "github.com/tencent/caelus/pkg/generated/listers/caelus/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + watch "k8s.io/apimachinery/pkg/watch" + cache "k8s.io/client-go/tools/cache" +) + +// CgroupNotifyInformer provides access to a shared informer and lister for +// CgroupNotifies. +type CgroupNotifyInformer interface { + Informer() cache.SharedIndexInformer + Lister() v1.CgroupNotifyLister +} + +type cgroupNotifyInformer struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc + namespace string +} + +// NewCgroupNotifyInformer constructs a new informer for CgroupNotify 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 NewCgroupNotifyInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return NewFilteredCgroupNotifyInformer(client, namespace, resyncPeriod, indexers, nil) +} + +// NewFilteredCgroupNotifyInformer constructs a new informer for CgroupNotify 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 NewFilteredCgroupNotifyInformer(client versioned.Interface, namespace string, 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.CaelusV1().CgroupNotifies(namespace).List(context.TODO(), options) + }, + WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.CaelusV1().CgroupNotifies(namespace).Watch(context.TODO(), options) + }, + }, + &caelusv1.CgroupNotify{}, + resyncPeriod, + indexers, + ) +} + +func (f *cgroupNotifyInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewFilteredCgroupNotifyInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) +} + +func (f *cgroupNotifyInformer) Informer() cache.SharedIndexInformer { + return f.factory.InformerFor(&caelusv1.CgroupNotify{}, f.defaultInformer) +} + +func (f *cgroupNotifyInformer) Lister() v1.CgroupNotifyLister { + return v1.NewCgroupNotifyLister(f.Informer().GetIndexer()) +} diff --git a/pkg/generated/informers/externalversions/caelus/v1/interface.go b/pkg/generated/informers/externalversions/caelus/v1/interface.go index c76140d2..83c91454 100644 --- a/pkg/generated/informers/externalversions/caelus/v1/interface.go +++ b/pkg/generated/informers/externalversions/caelus/v1/interface.go @@ -1,17 +1,19 @@ /* - * Copyright (c) 2021 THL A29 Limited, a Tencent company. - * - * 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. - */ +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + // Code generated by informer-gen. DO NOT EDIT. package v1 @@ -22,6 +24,8 @@ import ( // Interface provides access to all the informers in this group version. type Interface interface { + // CgroupNotifies returns a CgroupNotifyInformer. + CgroupNotifies() CgroupNotifyInformer // RuleChecks returns a RuleCheckInformer. RuleChecks() RuleCheckInformer } @@ -37,6 +41,11 @@ func New(f internalinterfaces.SharedInformerFactory, namespace string, tweakList return &version{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} } +// CgroupNotifies returns a CgroupNotifyInformer. +func (v *version) CgroupNotifies() CgroupNotifyInformer { + return &cgroupNotifyInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} +} + // RuleChecks returns a RuleCheckInformer. func (v *version) RuleChecks() RuleCheckInformer { return &ruleCheckInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} diff --git a/pkg/generated/informers/externalversions/caelus/v1/rulecheck.go b/pkg/generated/informers/externalversions/caelus/v1/rulecheck.go index 9c7b7fa7..32e85f5d 100644 --- a/pkg/generated/informers/externalversions/caelus/v1/rulecheck.go +++ b/pkg/generated/informers/externalversions/caelus/v1/rulecheck.go @@ -1,17 +1,19 @@ /* - * Copyright (c) 2021 THL A29 Limited, a Tencent company. - * - * 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. - */ +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + // Code generated by informer-gen. DO NOT EDIT. package v1 diff --git a/pkg/generated/informers/externalversions/factory.go b/pkg/generated/informers/externalversions/factory.go index 240dc7fa..abbc9085 100644 --- a/pkg/generated/informers/externalversions/factory.go +++ b/pkg/generated/informers/externalversions/factory.go @@ -1,17 +1,19 @@ /* - * Copyright (c) 2021 THL A29 Limited, a Tencent company. - * - * 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. - */ +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 diff --git a/pkg/generated/informers/externalversions/generic.go b/pkg/generated/informers/externalversions/generic.go index 7a5a210f..4fc257f9 100644 --- a/pkg/generated/informers/externalversions/generic.go +++ b/pkg/generated/informers/externalversions/generic.go @@ -1,17 +1,19 @@ /* - * Copyright (c) 2021 THL A29 Limited, a Tencent company. - * - * 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. - */ +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 @@ -51,6 +53,8 @@ func (f *genericInformer) Lister() cache.GenericLister { func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource) (GenericInformer, error) { switch resource { // Group=caelus, Version=v1 + case v1.SchemeGroupVersion.WithResource("cgroupnotifies"): + return &genericInformer{resource: resource.GroupResource(), informer: f.Caelus().V1().CgroupNotifies().Informer()}, nil case v1.SchemeGroupVersion.WithResource("rulechecks"): return &genericInformer{resource: resource.GroupResource(), informer: f.Caelus().V1().RuleChecks().Informer()}, nil diff --git a/pkg/generated/informers/externalversions/internalinterfaces/factory_interfaces.go b/pkg/generated/informers/externalversions/internalinterfaces/factory_interfaces.go index 8865fb04..5060968a 100644 --- a/pkg/generated/informers/externalversions/internalinterfaces/factory_interfaces.go +++ b/pkg/generated/informers/externalversions/internalinterfaces/factory_interfaces.go @@ -1,17 +1,19 @@ /* - * Copyright (c) 2021 THL A29 Limited, a Tencent company. - * - * 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. - */ +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 diff --git a/pkg/generated/listers/caelus/v1/cgroupnotify.go b/pkg/generated/listers/caelus/v1/cgroupnotify.go new file mode 100644 index 00000000..decf1337 --- /dev/null +++ b/pkg/generated/listers/caelus/v1/cgroupnotify.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 v1 + +import ( + v1 "github.com/tencent/caelus/pkg/apis/caelus/v1" + "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/tools/cache" +) + +// CgroupNotifyLister helps list CgroupNotifies. +// All objects returned here must be treated as read-only. +type CgroupNotifyLister interface { + // List lists all CgroupNotifies in the indexer. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*v1.CgroupNotify, err error) + // CgroupNotifies returns an object that can list and get CgroupNotifies. + CgroupNotifies(namespace string) CgroupNotifyNamespaceLister + CgroupNotifyListerExpansion +} + +// cgroupNotifyLister implements the CgroupNotifyLister interface. +type cgroupNotifyLister struct { + indexer cache.Indexer +} + +// NewCgroupNotifyLister returns a new CgroupNotifyLister. +func NewCgroupNotifyLister(indexer cache.Indexer) CgroupNotifyLister { + return &cgroupNotifyLister{indexer: indexer} +} + +// List lists all CgroupNotifies in the indexer. +func (s *cgroupNotifyLister) List(selector labels.Selector) (ret []*v1.CgroupNotify, err error) { + err = cache.ListAll(s.indexer, selector, func(m interface{}) { + ret = append(ret, m.(*v1.CgroupNotify)) + }) + return ret, err +} + +// CgroupNotifies returns an object that can list and get CgroupNotifies. +func (s *cgroupNotifyLister) CgroupNotifies(namespace string) CgroupNotifyNamespaceLister { + return cgroupNotifyNamespaceLister{indexer: s.indexer, namespace: namespace} +} + +// CgroupNotifyNamespaceLister helps list and get CgroupNotifies. +// All objects returned here must be treated as read-only. +type CgroupNotifyNamespaceLister interface { + // List lists all CgroupNotifies in the indexer for a given namespace. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*v1.CgroupNotify, err error) + // Get retrieves the CgroupNotify from the indexer for a given namespace and name. + // Objects returned here must be treated as read-only. + Get(name string) (*v1.CgroupNotify, error) + CgroupNotifyNamespaceListerExpansion +} + +// cgroupNotifyNamespaceLister implements the CgroupNotifyNamespaceLister +// interface. +type cgroupNotifyNamespaceLister struct { + indexer cache.Indexer + namespace string +} + +// List lists all CgroupNotifies in the indexer for a given namespace. +func (s cgroupNotifyNamespaceLister) List(selector labels.Selector) (ret []*v1.CgroupNotify, err error) { + err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { + ret = append(ret, m.(*v1.CgroupNotify)) + }) + return ret, err +} + +// Get retrieves the CgroupNotify from the indexer for a given namespace and name. +func (s cgroupNotifyNamespaceLister) Get(name string) (*v1.CgroupNotify, error) { + obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) + if err != nil { + return nil, err + } + if !exists { + return nil, errors.NewNotFound(v1.Resource("cgroupnotify"), name) + } + return obj.(*v1.CgroupNotify), nil +} diff --git a/pkg/generated/listers/caelus/v1/expansion_generated.go b/pkg/generated/listers/caelus/v1/expansion_generated.go index 11f1e75d..bfca4459 100644 --- a/pkg/generated/listers/caelus/v1/expansion_generated.go +++ b/pkg/generated/listers/caelus/v1/expansion_generated.go @@ -1,21 +1,31 @@ /* - * Copyright (c) 2021 THL A29 Limited, a Tencent company. - * - * 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. - */ +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + // Code generated by lister-gen. DO NOT EDIT. package v1 +// CgroupNotifyListerExpansion allows custom methods to be added to +// CgroupNotifyLister. +type CgroupNotifyListerExpansion interface{} + +// CgroupNotifyNamespaceListerExpansion allows custom methods to be added to +// CgroupNotifyNamespaceLister. +type CgroupNotifyNamespaceListerExpansion interface{} + // RuleCheckListerExpansion allows custom methods to be added to // RuleCheckLister. type RuleCheckListerExpansion interface{} diff --git a/pkg/generated/listers/caelus/v1/rulecheck.go b/pkg/generated/listers/caelus/v1/rulecheck.go index f9e5c68b..298ee12c 100644 --- a/pkg/generated/listers/caelus/v1/rulecheck.go +++ b/pkg/generated/listers/caelus/v1/rulecheck.go @@ -1,17 +1,19 @@ /* - * Copyright (c) 2021 THL A29 Limited, a Tencent company. - * - * 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. - */ +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + // Code generated by lister-gen. DO NOT EDIT. package v1 From e1e7a8044e0e719f55711328b133dcfea0085835 Mon Sep 17 00:00:00 2001 From: yanxiaoqi932 Date: Thu, 21 Mar 2024 20:23:45 +0800 Subject: [PATCH 37/59] add cgroupnotifies.yaml --- .../crd/bases/caelus.io_cgroupnotifies.yaml | 122 ++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 config/crd/bases/caelus.io_cgroupnotifies.yaml diff --git a/config/crd/bases/caelus.io_cgroupnotifies.yaml b/config/crd/bases/caelus.io_cgroupnotifies.yaml new file mode 100644 index 00000000..294b3f09 --- /dev/null +++ b/config/crd/bases/caelus.io_cgroupnotifies.yaml @@ -0,0 +1,122 @@ +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: v0.14.0 + name: cgroupnotifies.caelus.io +spec: + group: caelus.io + names: + kind: CgroupNotify + listKind: CgroupNotifyList + plural: cgroupnotifies + singular: cgroupnotify + scope: Namespaced + versions: + - name: v1 + schema: + openAPIV3Schema: + description: CgroupNotify is a specification for a CgroupNotify resource + properties: + apiVersion: + description: |- + APIVersion defines the versioned schema of this representation of an object. + Servers should convert recognized schemas to the latest internal value, and + may reject unrecognized values. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources + type: string + kind: + description: |- + Kind is a string value representing the REST resource this object represents. + Servers may infer this from the endpoint the client submits requests to. + Cannot be updated. + In CamelCase. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds + type: string + metadata: + type: object + spec: + description: CgroupNotifySpec is the spec for a CgroupNotify resource + properties: + memory_cgroup: + description: MemoryNotifyConfig describe memory cgroup notify + properties: + pressures: + items: + description: MemoryPressureNotifyConfig describe memory.pressure_level + notify data + properties: + cgroups: + items: + type: string + type: array + count: + description: assign event number in the duration time + type: integer + duration: + description: assign time duration the pressure has kept + format: int64 + type: integer + pressure_level: + type: string + required: + - cgroups + - count + - duration + - pressure_level + type: object + type: array + usages: + items: + description: MemoryUsageNotifyConfig describe memory.usage_in_bytes + notify data + properties: + cgroups: + items: + type: string + type: array + duration: + description: when to handle event after receiving event + format: int64 + type: integer + margin_mb: + description: the distance between limit and threshold + type: integer + required: + - cgroups + - duration + - margin_mb + type: object + type: array + required: + - pressures + - usages + type: object + nodeSelector: + additionalProperties: + type: string + type: object + priority: + format: int32 + type: integer + required: + - memory_cgroup + - nodeSelector + - priority + type: object + status: + description: CgroupNotifyStatus is the status for a CgroupNotify resource + properties: + availableReplicas: + format: int32 + type: integer + required: + - availableReplicas + type: object + required: + - spec + - status + type: object + served: true + storage: true From 682f6c79a9e7d86b256d5e73eab6b55a16a2efbf Mon Sep 17 00:00:00 2001 From: baowj Date: Fri, 22 Mar 2024 11:30:26 +0800 Subject: [PATCH 38/59] update rulecheck priority type to int32 Signed-off-by: baowj --- pkg/apis/caelus/v1/rulecheck_types.go | 3 +- pkg/apis/caelus/v1/zz_generated.deepcopy.go | 33 ++++++++----------- pkg/caelus/healthcheck/health_check.go | 4 +-- .../clientset/versioned/clientset.go | 32 +++++++++--------- pkg/generated/clientset/versioned/doc.go | 28 ++++++++-------- .../versioned/fake/clientset_generated.go | 28 ++++++++-------- pkg/generated/clientset/versioned/fake/doc.go | 28 ++++++++-------- .../clientset/versioned/fake/register.go | 28 ++++++++-------- .../clientset/versioned/scheme/doc.go | 28 ++++++++-------- .../clientset/versioned/scheme/register.go | 28 ++++++++-------- .../typed/caelus/v1/caelus_client.go | 28 ++++++++-------- .../versioned/typed/caelus/v1/cgroupnotify.go | 28 ++++++++-------- .../versioned/typed/caelus/v1/doc.go | 28 ++++++++-------- .../versioned/typed/caelus/v1/fake/doc.go | 28 ++++++++-------- .../caelus/v1/fake/fake_caelus_client.go | 28 ++++++++-------- .../typed/caelus/v1/fake/fake_cgroupnotify.go | 28 ++++++++-------- .../typed/caelus/v1/fake/fake_rulecheck.go | 28 ++++++++-------- .../typed/caelus/v1/generated_expansion.go | 28 ++++++++-------- .../versioned/typed/caelus/v1/rulecheck.go | 28 ++++++++-------- .../externalversions/caelus/interface.go | 28 ++++++++-------- .../caelus/v1/cgroupnotify.go | 28 ++++++++-------- .../externalversions/caelus/v1/interface.go | 28 ++++++++-------- .../externalversions/caelus/v1/rulecheck.go | 28 ++++++++-------- .../informers/externalversions/factory.go | 28 ++++++++-------- .../informers/externalversions/generic.go | 28 ++++++++-------- .../internalinterfaces/factory_interfaces.go | 28 ++++++++-------- .../listers/caelus/v1/cgroupnotify.go | 28 ++++++++-------- .../listers/caelus/v1/expansion_generated.go | 28 ++++++++-------- pkg/generated/listers/caelus/v1/rulecheck.go | 28 ++++++++-------- 29 files changed, 359 insertions(+), 413 deletions(-) diff --git a/pkg/apis/caelus/v1/rulecheck_types.go b/pkg/apis/caelus/v1/rulecheck_types.go index d91c955b..5bafadc6 100644 --- a/pkg/apis/caelus/v1/rulecheck_types.go +++ b/pkg/apis/caelus/v1/rulecheck_types.go @@ -45,9 +45,10 @@ type RuleCheck struct { type RuleCheckSpec struct { Name string `json:"name"` NodeSelector map[string]string `json:"nodeSelector"` - Priority *int32 `json:"priority"` + Priority int32 `json:"priority"` Type RuleCheckType `json:"type"` Metrics []string `json:"metrics"` + // CheckInterval describes the interval to trigger detection CheckInterval *times.Duration `json:"checkInterval"` // HandleInterval describes the interval to handle conflicts after detecting abnormal result diff --git a/pkg/apis/caelus/v1/zz_generated.deepcopy.go b/pkg/apis/caelus/v1/zz_generated.deepcopy.go index 05f0abc5..943030d1 100644 --- a/pkg/apis/caelus/v1/zz_generated.deepcopy.go +++ b/pkg/apis/caelus/v1/zz_generated.deepcopy.go @@ -2,21 +2,19 @@ // +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. -*/ - + * Copyright (c) 2021 THL A29 Limited, a Tencent company. + * + * 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 v1 @@ -329,11 +327,6 @@ func (in *RuleCheckSpec) DeepCopyInto(out *RuleCheckSpec) { (*out)[key] = val } } - if in.Priority != nil { - in, out := &in.Priority, &out.Priority - *out = new(int32) - **out = **in - } if in.Metrics != nil { in, out := &in.Metrics, &out.Metrics *out = make([]string, len(*in)) diff --git a/pkg/caelus/healthcheck/health_check.go b/pkg/caelus/healthcheck/health_check.go index 427b17d8..68f329ac 100644 --- a/pkg/caelus/healthcheck/health_check.go +++ b/pkg/caelus/healthcheck/health_check.go @@ -324,10 +324,10 @@ func (h *manager) updateRuleCheckConfig() error { return err } sort.Slice(ruleChecks, func(i, j int) bool { - if *(ruleChecks[i].Spec.Priority) == *(ruleChecks[j].Spec.Priority) { + if ruleChecks[i].Spec.Priority == ruleChecks[j].Spec.Priority { return ruleChecks[i].CreationTimestamp.Time.After(ruleChecks[j].CreationTimestamp.Time) } else { - return *(ruleChecks[i].Spec.Priority) > *(ruleChecks[j].Spec.Priority) + return ruleChecks[i].Spec.Priority > ruleChecks[j].Spec.Priority } }) diff --git a/pkg/generated/clientset/versioned/clientset.go b/pkg/generated/clientset/versioned/clientset.go index 82ad164f..e5de8b2e 100644 --- a/pkg/generated/clientset/versioned/clientset.go +++ b/pkg/generated/clientset/versioned/clientset.go @@ -1,19 +1,17 @@ /* -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. -*/ - + * Copyright (c) 2021 THL A29 Limited, a Tencent company. + * + * 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 @@ -61,6 +59,10 @@ func (c *Clientset) Discovery() discovery.DiscoveryInterface { 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 { diff --git a/pkg/generated/clientset/versioned/doc.go b/pkg/generated/clientset/versioned/doc.go index 41721ca5..8eb91c9a 100644 --- a/pkg/generated/clientset/versioned/doc.go +++ b/pkg/generated/clientset/versioned/doc.go @@ -1,19 +1,17 @@ /* -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. -*/ - + * Copyright (c) 2021 THL A29 Limited, a Tencent company. + * + * 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 clientset. diff --git a/pkg/generated/clientset/versioned/fake/clientset_generated.go b/pkg/generated/clientset/versioned/fake/clientset_generated.go index 8467e949..96390304 100644 --- a/pkg/generated/clientset/versioned/fake/clientset_generated.go +++ b/pkg/generated/clientset/versioned/fake/clientset_generated.go @@ -1,19 +1,17 @@ /* -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. -*/ - + * Copyright (c) 2021 THL A29 Limited, a Tencent company. + * + * 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 diff --git a/pkg/generated/clientset/versioned/fake/doc.go b/pkg/generated/clientset/versioned/fake/doc.go index 9b99e716..c8a212b7 100644 --- a/pkg/generated/clientset/versioned/fake/doc.go +++ b/pkg/generated/clientset/versioned/fake/doc.go @@ -1,19 +1,17 @@ /* -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. -*/ - + * Copyright (c) 2021 THL A29 Limited, a Tencent company. + * + * 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. diff --git a/pkg/generated/clientset/versioned/fake/register.go b/pkg/generated/clientset/versioned/fake/register.go index 4aa0c1e7..6f6f1cec 100644 --- a/pkg/generated/clientset/versioned/fake/register.go +++ b/pkg/generated/clientset/versioned/fake/register.go @@ -1,19 +1,17 @@ /* -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. -*/ - + * Copyright (c) 2021 THL A29 Limited, a Tencent company. + * + * 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 diff --git a/pkg/generated/clientset/versioned/scheme/doc.go b/pkg/generated/clientset/versioned/scheme/doc.go index 7dc37561..d5857dc0 100644 --- a/pkg/generated/clientset/versioned/scheme/doc.go +++ b/pkg/generated/clientset/versioned/scheme/doc.go @@ -1,19 +1,17 @@ /* -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. -*/ - + * Copyright (c) 2021 THL A29 Limited, a Tencent company. + * + * 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. diff --git a/pkg/generated/clientset/versioned/scheme/register.go b/pkg/generated/clientset/versioned/scheme/register.go index 7b98c39d..ea028ec2 100644 --- a/pkg/generated/clientset/versioned/scheme/register.go +++ b/pkg/generated/clientset/versioned/scheme/register.go @@ -1,19 +1,17 @@ /* -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. -*/ - + * Copyright (c) 2021 THL A29 Limited, a Tencent company. + * + * 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 diff --git a/pkg/generated/clientset/versioned/typed/caelus/v1/caelus_client.go b/pkg/generated/clientset/versioned/typed/caelus/v1/caelus_client.go index 0b7d000c..069118ef 100644 --- a/pkg/generated/clientset/versioned/typed/caelus/v1/caelus_client.go +++ b/pkg/generated/clientset/versioned/typed/caelus/v1/caelus_client.go @@ -1,19 +1,17 @@ /* -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. -*/ - + * Copyright (c) 2021 THL A29 Limited, a Tencent company. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * + * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ // Code generated by client-gen. DO NOT EDIT. package v1 diff --git a/pkg/generated/clientset/versioned/typed/caelus/v1/cgroupnotify.go b/pkg/generated/clientset/versioned/typed/caelus/v1/cgroupnotify.go index c40084ee..a805ccaf 100644 --- a/pkg/generated/clientset/versioned/typed/caelus/v1/cgroupnotify.go +++ b/pkg/generated/clientset/versioned/typed/caelus/v1/cgroupnotify.go @@ -1,19 +1,17 @@ /* -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. -*/ - + * Copyright (c) 2021 THL A29 Limited, a Tencent company. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * + * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ // Code generated by client-gen. DO NOT EDIT. package v1 diff --git a/pkg/generated/clientset/versioned/typed/caelus/v1/doc.go b/pkg/generated/clientset/versioned/typed/caelus/v1/doc.go index 3af5d054..dd003f29 100644 --- a/pkg/generated/clientset/versioned/typed/caelus/v1/doc.go +++ b/pkg/generated/clientset/versioned/typed/caelus/v1/doc.go @@ -1,19 +1,17 @@ /* -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. -*/ - + * Copyright (c) 2021 THL A29 Limited, a Tencent company. + * + * 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. diff --git a/pkg/generated/clientset/versioned/typed/caelus/v1/fake/doc.go b/pkg/generated/clientset/versioned/typed/caelus/v1/fake/doc.go index 16f44399..12074a52 100644 --- a/pkg/generated/clientset/versioned/typed/caelus/v1/fake/doc.go +++ b/pkg/generated/clientset/versioned/typed/caelus/v1/fake/doc.go @@ -1,19 +1,17 @@ /* -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. -*/ - + * Copyright (c) 2021 THL A29 Limited, a Tencent company. + * + * 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. diff --git a/pkg/generated/clientset/versioned/typed/caelus/v1/fake/fake_caelus_client.go b/pkg/generated/clientset/versioned/typed/caelus/v1/fake/fake_caelus_client.go index b3a2a5f5..1c2593f2 100644 --- a/pkg/generated/clientset/versioned/typed/caelus/v1/fake/fake_caelus_client.go +++ b/pkg/generated/clientset/versioned/typed/caelus/v1/fake/fake_caelus_client.go @@ -1,19 +1,17 @@ /* -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. -*/ - + * Copyright (c) 2021 THL A29 Limited, a Tencent company. + * + * 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 diff --git a/pkg/generated/clientset/versioned/typed/caelus/v1/fake/fake_cgroupnotify.go b/pkg/generated/clientset/versioned/typed/caelus/v1/fake/fake_cgroupnotify.go index 572b051a..a33540dc 100644 --- a/pkg/generated/clientset/versioned/typed/caelus/v1/fake/fake_cgroupnotify.go +++ b/pkg/generated/clientset/versioned/typed/caelus/v1/fake/fake_cgroupnotify.go @@ -1,19 +1,17 @@ /* -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. -*/ - + * Copyright (c) 2021 THL A29 Limited, a Tencent company. + * + * 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 diff --git a/pkg/generated/clientset/versioned/typed/caelus/v1/fake/fake_rulecheck.go b/pkg/generated/clientset/versioned/typed/caelus/v1/fake/fake_rulecheck.go index 9cff02f5..66ca961d 100644 --- a/pkg/generated/clientset/versioned/typed/caelus/v1/fake/fake_rulecheck.go +++ b/pkg/generated/clientset/versioned/typed/caelus/v1/fake/fake_rulecheck.go @@ -1,19 +1,17 @@ /* -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. -*/ - + * Copyright (c) 2021 THL A29 Limited, a Tencent company. + * + * 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 diff --git a/pkg/generated/clientset/versioned/typed/caelus/v1/generated_expansion.go b/pkg/generated/clientset/versioned/typed/caelus/v1/generated_expansion.go index 8736e9d5..a514b4aa 100644 --- a/pkg/generated/clientset/versioned/typed/caelus/v1/generated_expansion.go +++ b/pkg/generated/clientset/versioned/typed/caelus/v1/generated_expansion.go @@ -1,19 +1,17 @@ /* -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. -*/ - + * Copyright (c) 2021 THL A29 Limited, a Tencent company. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * + * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ // Code generated by client-gen. DO NOT EDIT. package v1 diff --git a/pkg/generated/clientset/versioned/typed/caelus/v1/rulecheck.go b/pkg/generated/clientset/versioned/typed/caelus/v1/rulecheck.go index d5b3f785..087d8966 100644 --- a/pkg/generated/clientset/versioned/typed/caelus/v1/rulecheck.go +++ b/pkg/generated/clientset/versioned/typed/caelus/v1/rulecheck.go @@ -1,19 +1,17 @@ /* -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. -*/ - + * Copyright (c) 2021 THL A29 Limited, a Tencent company. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * + * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ // Code generated by client-gen. DO NOT EDIT. package v1 diff --git a/pkg/generated/informers/externalversions/caelus/interface.go b/pkg/generated/informers/externalversions/caelus/interface.go index a19e58f5..fc3afb4a 100644 --- a/pkg/generated/informers/externalversions/caelus/interface.go +++ b/pkg/generated/informers/externalversions/caelus/interface.go @@ -1,19 +1,17 @@ /* -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. -*/ - + * Copyright (c) 2021 THL A29 Limited, a Tencent company. + * + * 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 caelus diff --git a/pkg/generated/informers/externalversions/caelus/v1/cgroupnotify.go b/pkg/generated/informers/externalversions/caelus/v1/cgroupnotify.go index 1d48b431..84578f95 100644 --- a/pkg/generated/informers/externalversions/caelus/v1/cgroupnotify.go +++ b/pkg/generated/informers/externalversions/caelus/v1/cgroupnotify.go @@ -1,19 +1,17 @@ /* -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. -*/ - + * Copyright (c) 2021 THL A29 Limited, a Tencent company. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * + * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ // Code generated by informer-gen. DO NOT EDIT. package v1 diff --git a/pkg/generated/informers/externalversions/caelus/v1/interface.go b/pkg/generated/informers/externalversions/caelus/v1/interface.go index 83c91454..fbcca98a 100644 --- a/pkg/generated/informers/externalversions/caelus/v1/interface.go +++ b/pkg/generated/informers/externalversions/caelus/v1/interface.go @@ -1,19 +1,17 @@ /* -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. -*/ - + * Copyright (c) 2021 THL A29 Limited, a Tencent company. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * + * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ // Code generated by informer-gen. DO NOT EDIT. package v1 diff --git a/pkg/generated/informers/externalversions/caelus/v1/rulecheck.go b/pkg/generated/informers/externalversions/caelus/v1/rulecheck.go index 32e85f5d..9c7b7fa7 100644 --- a/pkg/generated/informers/externalversions/caelus/v1/rulecheck.go +++ b/pkg/generated/informers/externalversions/caelus/v1/rulecheck.go @@ -1,19 +1,17 @@ /* -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. -*/ - + * Copyright (c) 2021 THL A29 Limited, a Tencent company. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * + * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ // Code generated by informer-gen. DO NOT EDIT. package v1 diff --git a/pkg/generated/informers/externalversions/factory.go b/pkg/generated/informers/externalversions/factory.go index abbc9085..240dc7fa 100644 --- a/pkg/generated/informers/externalversions/factory.go +++ b/pkg/generated/informers/externalversions/factory.go @@ -1,19 +1,17 @@ /* -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. -*/ - + * Copyright (c) 2021 THL A29 Limited, a Tencent company. + * + * 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 diff --git a/pkg/generated/informers/externalversions/generic.go b/pkg/generated/informers/externalversions/generic.go index 4fc257f9..d7f27e6f 100644 --- a/pkg/generated/informers/externalversions/generic.go +++ b/pkg/generated/informers/externalversions/generic.go @@ -1,19 +1,17 @@ /* -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. -*/ - + * Copyright (c) 2021 THL A29 Limited, a Tencent company. + * + * 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 diff --git a/pkg/generated/informers/externalversions/internalinterfaces/factory_interfaces.go b/pkg/generated/informers/externalversions/internalinterfaces/factory_interfaces.go index 5060968a..8865fb04 100644 --- a/pkg/generated/informers/externalversions/internalinterfaces/factory_interfaces.go +++ b/pkg/generated/informers/externalversions/internalinterfaces/factory_interfaces.go @@ -1,19 +1,17 @@ /* -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. -*/ - + * Copyright (c) 2021 THL A29 Limited, a Tencent company. + * + * 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 diff --git a/pkg/generated/listers/caelus/v1/cgroupnotify.go b/pkg/generated/listers/caelus/v1/cgroupnotify.go index decf1337..7043f632 100644 --- a/pkg/generated/listers/caelus/v1/cgroupnotify.go +++ b/pkg/generated/listers/caelus/v1/cgroupnotify.go @@ -1,19 +1,17 @@ /* -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. -*/ - + * Copyright (c) 2021 THL A29 Limited, a Tencent company. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * + * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ // Code generated by lister-gen. DO NOT EDIT. package v1 diff --git a/pkg/generated/listers/caelus/v1/expansion_generated.go b/pkg/generated/listers/caelus/v1/expansion_generated.go index bfca4459..16786650 100644 --- a/pkg/generated/listers/caelus/v1/expansion_generated.go +++ b/pkg/generated/listers/caelus/v1/expansion_generated.go @@ -1,19 +1,17 @@ /* -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. -*/ - + * Copyright (c) 2021 THL A29 Limited, a Tencent company. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * + * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ // Code generated by lister-gen. DO NOT EDIT. package v1 diff --git a/pkg/generated/listers/caelus/v1/rulecheck.go b/pkg/generated/listers/caelus/v1/rulecheck.go index 298ee12c..f9e5c68b 100644 --- a/pkg/generated/listers/caelus/v1/rulecheck.go +++ b/pkg/generated/listers/caelus/v1/rulecheck.go @@ -1,19 +1,17 @@ /* -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. -*/ - + * Copyright (c) 2021 THL A29 Limited, a Tencent company. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * + * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ // Code generated by lister-gen. DO NOT EDIT. package v1 From ffe844532916e8dc72dbe567b3997d4bbfb55eaa Mon Sep 17 00:00:00 2001 From: baowj Date: Fri, 22 Mar 2024 14:54:44 +0800 Subject: [PATCH 39/59] move crd yaml files to hack/yaml/caelus.yaml Signed-off-by: baowj --- .../crd/bases/caelus.io_cgroupnotifies.yaml | 122 -------- config/crd/bases/caelus.io_rulechecks.yaml | 152 ---------- hack/yaml/caelus.yaml | 274 ++++++++++++++++++ 3 files changed, 274 insertions(+), 274 deletions(-) delete mode 100644 config/crd/bases/caelus.io_cgroupnotifies.yaml delete mode 100644 config/crd/bases/caelus.io_rulechecks.yaml diff --git a/config/crd/bases/caelus.io_cgroupnotifies.yaml b/config/crd/bases/caelus.io_cgroupnotifies.yaml deleted file mode 100644 index 294b3f09..00000000 --- a/config/crd/bases/caelus.io_cgroupnotifies.yaml +++ /dev/null @@ -1,122 +0,0 @@ ---- -apiVersion: apiextensions.k8s.io/v1 -kind: CustomResourceDefinition -metadata: - annotations: - controller-gen.kubebuilder.io/version: v0.14.0 - name: cgroupnotifies.caelus.io -spec: - group: caelus.io - names: - kind: CgroupNotify - listKind: CgroupNotifyList - plural: cgroupnotifies - singular: cgroupnotify - scope: Namespaced - versions: - - name: v1 - schema: - openAPIV3Schema: - description: CgroupNotify is a specification for a CgroupNotify resource - properties: - apiVersion: - description: |- - APIVersion defines the versioned schema of this representation of an object. - Servers should convert recognized schemas to the latest internal value, and - may reject unrecognized values. - More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources - type: string - kind: - description: |- - Kind is a string value representing the REST resource this object represents. - Servers may infer this from the endpoint the client submits requests to. - Cannot be updated. - In CamelCase. - More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds - type: string - metadata: - type: object - spec: - description: CgroupNotifySpec is the spec for a CgroupNotify resource - properties: - memory_cgroup: - description: MemoryNotifyConfig describe memory cgroup notify - properties: - pressures: - items: - description: MemoryPressureNotifyConfig describe memory.pressure_level - notify data - properties: - cgroups: - items: - type: string - type: array - count: - description: assign event number in the duration time - type: integer - duration: - description: assign time duration the pressure has kept - format: int64 - type: integer - pressure_level: - type: string - required: - - cgroups - - count - - duration - - pressure_level - type: object - type: array - usages: - items: - description: MemoryUsageNotifyConfig describe memory.usage_in_bytes - notify data - properties: - cgroups: - items: - type: string - type: array - duration: - description: when to handle event after receiving event - format: int64 - type: integer - margin_mb: - description: the distance between limit and threshold - type: integer - required: - - cgroups - - duration - - margin_mb - type: object - type: array - required: - - pressures - - usages - type: object - nodeSelector: - additionalProperties: - type: string - type: object - priority: - format: int32 - type: integer - required: - - memory_cgroup - - nodeSelector - - priority - type: object - status: - description: CgroupNotifyStatus is the status for a CgroupNotify resource - properties: - availableReplicas: - format: int32 - type: integer - required: - - availableReplicas - type: object - required: - - spec - - status - type: object - served: true - storage: true diff --git a/config/crd/bases/caelus.io_rulechecks.yaml b/config/crd/bases/caelus.io_rulechecks.yaml deleted file mode 100644 index be9dc221..00000000 --- a/config/crd/bases/caelus.io_rulechecks.yaml +++ /dev/null @@ -1,152 +0,0 @@ ---- -apiVersion: apiextensions.k8s.io/v1 -kind: CustomResourceDefinition -metadata: - annotations: - controller-gen.kubebuilder.io/version: v0.14.0 - name: rulechecks.caelus.io -spec: - group: caelus.io - names: - kind: RuleCheck - listKind: RuleCheckList - plural: rulechecks - singular: rulecheck - scope: Namespaced - versions: - - name: v1 - schema: - openAPIV3Schema: - description: RuleCheck is a specification for a RuleCheck resource - properties: - apiVersion: - description: |- - APIVersion defines the versioned schema of this representation of an object. - Servers should convert recognized schemas to the latest internal value, and - may reject unrecognized values. - More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources - type: string - kind: - description: |- - Kind is a string value representing the REST resource this object represents. - Servers may infer this from the endpoint the client submits requests to. - Cannot be updated. - In CamelCase. - More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds - type: string - metadata: - type: object - spec: - description: RuleCheckSpec is the spec for a RuleCheck resource - properties: - checkInterval: - description: CheckInterval describes the interval to trigger detection - format: int64 - type: integer - handleInterval: - description: HandleInterval describes the interval to handle conflicts - after detecting abnormal result - format: int64 - type: integer - metrics: - items: - type: string - type: array - name: - type: string - nodeSelector: - additionalProperties: - type: string - type: object - priority: - format: int32 - type: integer - recoverInterval: - description: RecoverInterval describes the interval to recover conflicts - after detecting normal result - format: int64 - type: integer - recoverRules: - items: - description: DetectActionRules define detectors and actions - properties: - actions: - items: - description: DetectAction define detector config - properties: - args: - type: string - name: - type: string - required: - - args - - name - type: object - type: array - detects: - items: - description: DetectAction define detector config - properties: - args: - type: string - name: - type: string - required: - - args - - name - type: object - type: array - type: object - type: array - rules: - items: - description: DetectActionRules define detectors and actions - properties: - actions: - items: - description: DetectAction define detector config - properties: - args: - type: string - name: - type: string - required: - - args - - name - type: object - type: array - detects: - items: - description: DetectAction define detector config - properties: - args: - type: string - name: - type: string - required: - - args - - name - type: object - type: array - type: object - type: array - type: - type: string - required: - - checkInterval - - handleInterval - - metrics - - name - - priority - - recoverInterval - - rules - - type - type: object - status: - description: RuleCheckStatus is the status for a RuleCheck resource - type: object - required: - - spec - type: object - served: true - storage: true diff --git a/hack/yaml/caelus.yaml b/hack/yaml/caelus.yaml index bd5b0d1f..5ad2804d 100644 --- a/hack/yaml/caelus.yaml +++ b/hack/yaml/caelus.yaml @@ -1,3 +1,277 @@ +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: v0.14.0 + name: rulechecks.caelus.io +spec: + group: caelus.io + names: + kind: RuleCheck + listKind: RuleCheckList + plural: rulechecks + singular: rulecheck + scope: Cluster + versions: + - name: v1 + schema: + openAPIV3Schema: + description: RuleCheck is a specification for a RuleCheck resource + properties: + apiVersion: + description: |- + APIVersion defines the versioned schema of this representation of an object. + Servers should convert recognized schemas to the latest internal value, and + may reject unrecognized values. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources + type: string + kind: + description: |- + Kind is a string value representing the REST resource this object represents. + Servers may infer this from the endpoint the client submits requests to. + Cannot be updated. + In CamelCase. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds + type: string + metadata: + type: object + spec: + description: RuleCheckSpec is the spec for a RuleCheck resource + properties: + checkInterval: + description: CheckInterval describes the interval to trigger detection + format: int64 + type: integer + handleInterval: + description: HandleInterval describes the interval to handle conflicts + after detecting abnormal result + format: int64 + type: integer + metrics: + items: + type: string + type: array + name: + type: string + nodeSelector: + additionalProperties: + type: string + type: object + priority: + format: int32 + type: integer + recoverInterval: + description: RecoverInterval describes the interval to recover conflicts + after detecting normal result + format: int64 + type: integer + recoverRules: + items: + description: DetectActionRules define detectors and actions + properties: + actions: + items: + description: DetectAction define detector config + properties: + args: + type: string + name: + type: string + required: + - args + - name + type: object + type: array + detects: + items: + description: DetectAction define detector config + properties: + args: + type: string + name: + type: string + required: + - args + - name + type: object + type: array + type: object + type: array + rules: + items: + description: DetectActionRules define detectors and actions + properties: + actions: + items: + description: DetectAction define detector config + properties: + args: + type: string + name: + type: string + required: + - args + - name + type: object + type: array + detects: + items: + description: DetectAction define detector config + properties: + args: + type: string + name: + type: string + required: + - args + - name + type: object + type: array + type: object + type: array + type: + type: string + required: + - checkInterval + - handleInterval + - metrics + - name + - priority + - recoverInterval + - rules + - type + type: object + status: + description: RuleCheckStatus is the status for a RuleCheck resource + type: object + required: + - spec + type: object + served: true + storage: true +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: v0.14.0 + name: cgroupnotifies.caelus.io +spec: + group: caelus.io + names: + kind: CgroupNotify + listKind: CgroupNotifyList + plural: cgroupnotifies + singular: cgroupnotify + scope: Cluster + versions: + - name: v1 + schema: + openAPIV3Schema: + description: CgroupNotify is a specification for a CgroupNotify resource + properties: + apiVersion: + description: |- + APIVersion defines the versioned schema of this representation of an object. + Servers should convert recognized schemas to the latest internal value, and + may reject unrecognized values. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources + type: string + kind: + description: |- + Kind is a string value representing the REST resource this object represents. + Servers may infer this from the endpoint the client submits requests to. + Cannot be updated. + In CamelCase. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds + type: string + metadata: + type: object + spec: + description: CgroupNotifySpec is the spec for a CgroupNotify resource + properties: + memory_cgroup: + description: MemoryNotifyConfig describe memory cgroup notify + properties: + pressures: + items: + description: MemoryPressureNotifyConfig describe memory.pressure_level + notify data + properties: + cgroups: + items: + type: string + type: array + count: + description: assign event number in the duration time + type: integer + duration: + description: assign time duration the pressure has kept + format: int64 + type: integer + pressure_level: + type: string + required: + - cgroups + - count + - duration + - pressure_level + type: object + type: array + usages: + items: + description: MemoryUsageNotifyConfig describe memory.usage_in_bytes + notify data + properties: + cgroups: + items: + type: string + type: array + duration: + description: when to handle event after receiving event + format: int64 + type: integer + margin_mb: + description: the distance between limit and threshold + type: integer + required: + - cgroups + - duration + - margin_mb + type: object + type: array + required: + - pressures + - usages + type: object + nodeSelector: + additionalProperties: + type: string + type: object + priority: + format: int32 + type: integer + required: + - memory_cgroup + - nodeSelector + - priority + type: object + status: + description: CgroupNotifyStatus is the status for a CgroupNotify resource + properties: + availableReplicas: + format: int32 + type: integer + required: + - availableReplicas + type: object + required: + - spec + - status + type: object + served: true + storage: true +--- apiVersion: v1 kind: ServiceAccount metadata: From 577e5f163491eb4269666d83d08903213999ee47 Mon Sep 17 00:00:00 2001 From: baowj Date: Fri, 22 Mar 2024 15:25:26 +0800 Subject: [PATCH 40/59] merge rulecheck & cgroupnotify informer factory Signed-off-by: baowj --- cmd/caelus/app/server.go | 2 +- cmd/caelus/context/context.go | 39 ----------------------------------- 2 files changed, 1 insertion(+), 40 deletions(-) diff --git a/cmd/caelus/app/server.go b/cmd/caelus/app/server.go index a78fd02e..24f7e35c 100644 --- a/cmd/caelus/app/server.go +++ b/cmd/caelus/app/server.go @@ -246,7 +246,7 @@ func (o *options) initModules(caelus *types.CaelusConfig, ctx *context.CaelusCon // health check manager nodeInformer := ctx.GetNodeFactory().Core().V1().Nodes() ruleCheckInformer := ctx.GetCaelusFactory().Caelus().V1().RuleChecks() - cgroupNotifyInformer := ctx.GetCgroupNotifyFactory().Caelus().V1().CgroupNotifies() + cgroupNotifyInformer := ctx.GetCaelusFactory().Caelus().V1().CgroupNotifies() healthCheckManager = health.NewHealthManager(stStore, resourceManager, qosManager, conflictMn, podInformer, nodeInformer, ruleCheckInformer, cgroupNotifyInformer, &caelus.Predicts[0].ReserveResource, diff --git a/cmd/caelus/context/context.go b/cmd/caelus/context/context.go index 33c56263..081f476d 100644 --- a/cmd/caelus/context/context.go +++ b/cmd/caelus/context/context.go @@ -39,10 +39,8 @@ type CaelusContext struct { NodeName string kubeClient clientset.Interface caelusClient caelusclient.Interface - cgroupNotifyClient caelusclient.Interface nodeFactory, podFactory informers.SharedInformerFactory caelusFactory caelusinformers.SharedInformerFactory - cgroupNotifyFactory caelusinformers.SharedInformerFactory // TODO add xxx informers } @@ -85,22 +83,6 @@ func (c *CaelusContext) lazyInit() { c.caelusClient = caelusclient.NewForConfigOrDie(kubeconfig) } } - - // init cgroupnotifycrd client - if c.cgroupNotifyClient == nil { - err = nil - if kubeconfig == nil { - kubeconfig, err = clientcmd.BuildConfigFromFlags(c.Master, c.Kubeconfig) - } - if err != nil { - klog.Warning(err) - klog.Warning("fall back to creating fake caelus-client") - // create a fake client to test caelus without k8s - c.cgroupNotifyClient = caelusfake.NewSimpleClientset() - } else { - c.cgroupNotifyClient = caelusclient.NewForConfigOrDie(kubeconfig) - } - } } // GetKubeClient returns k8s client @@ -115,12 +97,6 @@ func (c *CaelusContext) GetCaelusClient() caelusclient.Interface { return c.caelusClient } -// GetCaelusClient returns CgroupNotify client -func (c *CaelusContext) GetCgroupNotifyClient() caelusclient.Interface { - c.lazyInit() - return c.cgroupNotifyClient -} - // GetPodFactory returns pod factory func (c *CaelusContext) GetPodFactory() informers.SharedInformerFactory { if c.podFactory == nil { @@ -143,17 +119,6 @@ func (c *CaelusContext) GetCaelusFactory() caelusinformers.SharedInformerFactory return c.caelusFactory } -// GetCaelusFactory returns cgroupnotify factory -func (c *CaelusContext) GetCgroupNotifyFactory() caelusinformers.SharedInformerFactory { - if c.cgroupNotifyFactory == nil { - c.cgroupNotifyFactory = caelusinformers.NewSharedInformerFactoryWithOptions(c.GetCgroupNotifyClient(), informerSyncPeriod, - caelusinformers.WithTweakListOptions(func(options *metav1.ListOptions) { - options.FieldSelector = fields.OneTermEqualSelector(nodeNameField, c.NodeName).String() - })) - } - return c.cgroupNotifyFactory -} - // GetNodeFactory returns node factory func (c *CaelusContext) GetNodeFactory() informers.SharedInformerFactory { if c.nodeFactory == nil { @@ -184,8 +149,4 @@ func (c *CaelusContext) Run(stop <-chan struct{}) { c.caelusFactory.Start(stop) c.caelusFactory.WaitForCacheSync(stop) } - if c.cgroupNotifyFactory != nil { - c.cgroupNotifyFactory.Start(stop) - c.cgroupNotifyFactory.WaitForCacheSync(stop) - } } From 56d1a4f8669b2a8920426abedba9aa9bb9b85e8d Mon Sep 17 00:00:00 2001 From: baowj Date: Sun, 24 Mar 2024 16:08:35 +0800 Subject: [PATCH 41/59] list all namespaces Signed-off-by: baowj --- pkg/caelus/healthcheck/health_check.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/caelus/healthcheck/health_check.go b/pkg/caelus/healthcheck/health_check.go index 68f329ac..e4192e91 100644 --- a/pkg/caelus/healthcheck/health_check.go +++ b/pkg/caelus/healthcheck/health_check.go @@ -293,7 +293,7 @@ func (h *manager) mergeCgroupNotify(baseCgNotify, nextCgNotify *types.NotifyConf } func (h *manager) updateCgroupNotifyConfig() error { - cgroupNotifiers, err := h.cgroupInformer.Lister().CgroupNotifies(types.CaelusNamespace).List(labels2.SelectorFromSet(nil)) + cgroupNotifiers, err := h.cgroupInformer.Lister().CgroupNotifies(corev1.NamespaceAll).List(labels2.Everything()) if err != nil { return err } @@ -319,7 +319,7 @@ func (h *manager) updateCgroupNotifyConfig() error { // update local RuleCheck func (h *manager) updateRuleCheckConfig() error { - ruleChecks, err := h.ruleCheckInformer.Lister().RuleChecks(types.CaelusNamespace).List(labels2.SelectorFromSet(nil)) + ruleChecks, err := h.ruleCheckInformer.Lister().RuleChecks(corev1.NamespaceAll).List(labels2.Everything()) if err != nil { return err } From d269658cc24505f1bfa06f492c1e205935e99bc2 Mon Sep 17 00:00:00 2001 From: yanxiaoqi932 Date: Tue, 26 Mar 2024 19:42:18 +0800 Subject: [PATCH 42/59] modify priority type from *int to int --- pkg/apis/caelus/v1/cgroupnotify_types.go | 2 +- pkg/apis/caelus/v1/zz_generated.deepcopy.go | 33 +++++++++---------- pkg/caelus/healthcheck/health_check.go | 5 ++- .../clientset/versioned/clientset.go | 32 +++++++++--------- pkg/generated/clientset/versioned/doc.go | 28 ++++++++-------- .../versioned/fake/clientset_generated.go | 28 ++++++++-------- pkg/generated/clientset/versioned/fake/doc.go | 28 ++++++++-------- .../clientset/versioned/fake/register.go | 28 ++++++++-------- .../clientset/versioned/scheme/doc.go | 28 ++++++++-------- .../clientset/versioned/scheme/register.go | 28 ++++++++-------- .../typed/caelus/v1/caelus_client.go | 28 ++++++++-------- .../versioned/typed/caelus/v1/cgroupnotify.go | 28 ++++++++-------- .../versioned/typed/caelus/v1/doc.go | 28 ++++++++-------- .../versioned/typed/caelus/v1/fake/doc.go | 28 ++++++++-------- .../caelus/v1/fake/fake_caelus_client.go | 28 ++++++++-------- .../typed/caelus/v1/fake/fake_cgroupnotify.go | 28 ++++++++-------- .../typed/caelus/v1/fake/fake_rulecheck.go | 28 ++++++++-------- .../typed/caelus/v1/generated_expansion.go | 28 ++++++++-------- .../versioned/typed/caelus/v1/rulecheck.go | 28 ++++++++-------- .../externalversions/caelus/interface.go | 28 ++++++++-------- .../caelus/v1/cgroupnotify.go | 28 ++++++++-------- .../externalversions/caelus/v1/interface.go | 28 ++++++++-------- .../externalversions/caelus/v1/rulecheck.go | 28 ++++++++-------- .../informers/externalversions/factory.go | 28 ++++++++-------- .../informers/externalversions/generic.go | 28 ++++++++-------- .../internalinterfaces/factory_interfaces.go | 28 ++++++++-------- .../listers/caelus/v1/cgroupnotify.go | 28 ++++++++-------- .../listers/caelus/v1/expansion_generated.go | 28 ++++++++-------- pkg/generated/listers/caelus/v1/rulecheck.go | 28 ++++++++-------- 29 files changed, 408 insertions(+), 364 deletions(-) diff --git a/pkg/apis/caelus/v1/cgroupnotify_types.go b/pkg/apis/caelus/v1/cgroupnotify_types.go index d75a39ce..f6fd3bdc 100644 --- a/pkg/apis/caelus/v1/cgroupnotify_types.go +++ b/pkg/apis/caelus/v1/cgroupnotify_types.go @@ -22,7 +22,7 @@ type CgroupNotify struct { type CgroupNotifySpec struct { MemoryCgroup MemoryNotifyConfig `json:"memory_cgroup"` NodeSelector map[string]string `json:"nodeSelector"` - Priority *int32 `json:"priority"` + Priority int32 `json:"priority"` } // MemoryNotifyConfig describe memory cgroup notify diff --git a/pkg/apis/caelus/v1/zz_generated.deepcopy.go b/pkg/apis/caelus/v1/zz_generated.deepcopy.go index 943030d1..5bf4169d 100644 --- a/pkg/apis/caelus/v1/zz_generated.deepcopy.go +++ b/pkg/apis/caelus/v1/zz_generated.deepcopy.go @@ -2,19 +2,21 @@ // +build !ignore_autogenerated /* - * Copyright (c) 2021 THL A29 Limited, a Tencent company. - * - * 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. - */ +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 v1 @@ -96,11 +98,6 @@ func (in *CgroupNotifySpec) DeepCopyInto(out *CgroupNotifySpec) { (*out)[key] = val } } - if in.Priority != nil { - in, out := &in.Priority, &out.Priority - *out = new(int32) - **out = **in - } return } diff --git a/pkg/caelus/healthcheck/health_check.go b/pkg/caelus/healthcheck/health_check.go index e4192e91..68812056 100644 --- a/pkg/caelus/healthcheck/health_check.go +++ b/pkg/caelus/healthcheck/health_check.go @@ -65,7 +65,6 @@ type manager struct { ruleCheckInformer caelusv1.RuleCheckInformer cgroupInformer caelusv1.CgroupNotifyInformer workqueue workqueue.RateLimitingInterface - configHash string globalStopCh <-chan struct{} ruleCheckAvailableFunc func(ruleCheck *types.RuleCheckConfig) } @@ -298,10 +297,10 @@ func (h *manager) updateCgroupNotifyConfig() error { return err } sort.Slice(cgroupNotifiers, func(i, j int) bool { - if *(cgroupNotifiers[i].Spec.Priority) == *(cgroupNotifiers[j].Spec.Priority) { + if cgroupNotifiers[i].Spec.Priority == cgroupNotifiers[j].Spec.Priority { return cgroupNotifiers[i].CreationTimestamp.After(cgroupNotifiers[j].CreationTimestamp.Time) } else { - return *(cgroupNotifiers[i].Spec.Priority) > *(cgroupNotifiers[j].Spec.Priority) + return cgroupNotifiers[i].Spec.Priority > cgroupNotifiers[j].Spec.Priority } }) baseCgroupNotify := &types.NotifyConfig{} diff --git a/pkg/generated/clientset/versioned/clientset.go b/pkg/generated/clientset/versioned/clientset.go index e5de8b2e..82ad164f 100644 --- a/pkg/generated/clientset/versioned/clientset.go +++ b/pkg/generated/clientset/versioned/clientset.go @@ -1,17 +1,19 @@ /* - * Copyright (c) 2021 THL A29 Limited, a Tencent company. - * - * 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. - */ +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 @@ -59,10 +61,6 @@ func (c *Clientset) Discovery() discovery.DiscoveryInterface { 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 { diff --git a/pkg/generated/clientset/versioned/doc.go b/pkg/generated/clientset/versioned/doc.go index 8eb91c9a..41721ca5 100644 --- a/pkg/generated/clientset/versioned/doc.go +++ b/pkg/generated/clientset/versioned/doc.go @@ -1,17 +1,19 @@ /* - * Copyright (c) 2021 THL A29 Limited, a Tencent company. - * - * 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. - */ +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 clientset. diff --git a/pkg/generated/clientset/versioned/fake/clientset_generated.go b/pkg/generated/clientset/versioned/fake/clientset_generated.go index 96390304..8467e949 100644 --- a/pkg/generated/clientset/versioned/fake/clientset_generated.go +++ b/pkg/generated/clientset/versioned/fake/clientset_generated.go @@ -1,17 +1,19 @@ /* - * Copyright (c) 2021 THL A29 Limited, a Tencent company. - * - * 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. - */ +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 diff --git a/pkg/generated/clientset/versioned/fake/doc.go b/pkg/generated/clientset/versioned/fake/doc.go index c8a212b7..9b99e716 100644 --- a/pkg/generated/clientset/versioned/fake/doc.go +++ b/pkg/generated/clientset/versioned/fake/doc.go @@ -1,17 +1,19 @@ /* - * Copyright (c) 2021 THL A29 Limited, a Tencent company. - * - * 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. - */ +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. diff --git a/pkg/generated/clientset/versioned/fake/register.go b/pkg/generated/clientset/versioned/fake/register.go index 6f6f1cec..4aa0c1e7 100644 --- a/pkg/generated/clientset/versioned/fake/register.go +++ b/pkg/generated/clientset/versioned/fake/register.go @@ -1,17 +1,19 @@ /* - * Copyright (c) 2021 THL A29 Limited, a Tencent company. - * - * 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. - */ +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 diff --git a/pkg/generated/clientset/versioned/scheme/doc.go b/pkg/generated/clientset/versioned/scheme/doc.go index d5857dc0..7dc37561 100644 --- a/pkg/generated/clientset/versioned/scheme/doc.go +++ b/pkg/generated/clientset/versioned/scheme/doc.go @@ -1,17 +1,19 @@ /* - * Copyright (c) 2021 THL A29 Limited, a Tencent company. - * - * 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. - */ +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. diff --git a/pkg/generated/clientset/versioned/scheme/register.go b/pkg/generated/clientset/versioned/scheme/register.go index ea028ec2..7b98c39d 100644 --- a/pkg/generated/clientset/versioned/scheme/register.go +++ b/pkg/generated/clientset/versioned/scheme/register.go @@ -1,17 +1,19 @@ /* - * Copyright (c) 2021 THL A29 Limited, a Tencent company. - * - * 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. - */ +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 diff --git a/pkg/generated/clientset/versioned/typed/caelus/v1/caelus_client.go b/pkg/generated/clientset/versioned/typed/caelus/v1/caelus_client.go index 069118ef..0b7d000c 100644 --- a/pkg/generated/clientset/versioned/typed/caelus/v1/caelus_client.go +++ b/pkg/generated/clientset/versioned/typed/caelus/v1/caelus_client.go @@ -1,17 +1,19 @@ /* - * Copyright (c) 2021 THL A29 Limited, a Tencent company. - * - * 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. - */ +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + // Code generated by client-gen. DO NOT EDIT. package v1 diff --git a/pkg/generated/clientset/versioned/typed/caelus/v1/cgroupnotify.go b/pkg/generated/clientset/versioned/typed/caelus/v1/cgroupnotify.go index a805ccaf..c40084ee 100644 --- a/pkg/generated/clientset/versioned/typed/caelus/v1/cgroupnotify.go +++ b/pkg/generated/clientset/versioned/typed/caelus/v1/cgroupnotify.go @@ -1,17 +1,19 @@ /* - * Copyright (c) 2021 THL A29 Limited, a Tencent company. - * - * 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. - */ +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + // Code generated by client-gen. DO NOT EDIT. package v1 diff --git a/pkg/generated/clientset/versioned/typed/caelus/v1/doc.go b/pkg/generated/clientset/versioned/typed/caelus/v1/doc.go index dd003f29..3af5d054 100644 --- a/pkg/generated/clientset/versioned/typed/caelus/v1/doc.go +++ b/pkg/generated/clientset/versioned/typed/caelus/v1/doc.go @@ -1,17 +1,19 @@ /* - * Copyright (c) 2021 THL A29 Limited, a Tencent company. - * - * 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. - */ +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. diff --git a/pkg/generated/clientset/versioned/typed/caelus/v1/fake/doc.go b/pkg/generated/clientset/versioned/typed/caelus/v1/fake/doc.go index 12074a52..16f44399 100644 --- a/pkg/generated/clientset/versioned/typed/caelus/v1/fake/doc.go +++ b/pkg/generated/clientset/versioned/typed/caelus/v1/fake/doc.go @@ -1,17 +1,19 @@ /* - * Copyright (c) 2021 THL A29 Limited, a Tencent company. - * - * 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. - */ +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. diff --git a/pkg/generated/clientset/versioned/typed/caelus/v1/fake/fake_caelus_client.go b/pkg/generated/clientset/versioned/typed/caelus/v1/fake/fake_caelus_client.go index 1c2593f2..b3a2a5f5 100644 --- a/pkg/generated/clientset/versioned/typed/caelus/v1/fake/fake_caelus_client.go +++ b/pkg/generated/clientset/versioned/typed/caelus/v1/fake/fake_caelus_client.go @@ -1,17 +1,19 @@ /* - * Copyright (c) 2021 THL A29 Limited, a Tencent company. - * - * 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. - */ +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 diff --git a/pkg/generated/clientset/versioned/typed/caelus/v1/fake/fake_cgroupnotify.go b/pkg/generated/clientset/versioned/typed/caelus/v1/fake/fake_cgroupnotify.go index a33540dc..572b051a 100644 --- a/pkg/generated/clientset/versioned/typed/caelus/v1/fake/fake_cgroupnotify.go +++ b/pkg/generated/clientset/versioned/typed/caelus/v1/fake/fake_cgroupnotify.go @@ -1,17 +1,19 @@ /* - * Copyright (c) 2021 THL A29 Limited, a Tencent company. - * - * 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. - */ +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 diff --git a/pkg/generated/clientset/versioned/typed/caelus/v1/fake/fake_rulecheck.go b/pkg/generated/clientset/versioned/typed/caelus/v1/fake/fake_rulecheck.go index 66ca961d..9cff02f5 100644 --- a/pkg/generated/clientset/versioned/typed/caelus/v1/fake/fake_rulecheck.go +++ b/pkg/generated/clientset/versioned/typed/caelus/v1/fake/fake_rulecheck.go @@ -1,17 +1,19 @@ /* - * Copyright (c) 2021 THL A29 Limited, a Tencent company. - * - * 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. - */ +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 diff --git a/pkg/generated/clientset/versioned/typed/caelus/v1/generated_expansion.go b/pkg/generated/clientset/versioned/typed/caelus/v1/generated_expansion.go index a514b4aa..8736e9d5 100644 --- a/pkg/generated/clientset/versioned/typed/caelus/v1/generated_expansion.go +++ b/pkg/generated/clientset/versioned/typed/caelus/v1/generated_expansion.go @@ -1,17 +1,19 @@ /* - * Copyright (c) 2021 THL A29 Limited, a Tencent company. - * - * 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. - */ +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + // Code generated by client-gen. DO NOT EDIT. package v1 diff --git a/pkg/generated/clientset/versioned/typed/caelus/v1/rulecheck.go b/pkg/generated/clientset/versioned/typed/caelus/v1/rulecheck.go index 087d8966..d5b3f785 100644 --- a/pkg/generated/clientset/versioned/typed/caelus/v1/rulecheck.go +++ b/pkg/generated/clientset/versioned/typed/caelus/v1/rulecheck.go @@ -1,17 +1,19 @@ /* - * Copyright (c) 2021 THL A29 Limited, a Tencent company. - * - * 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. - */ +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + // Code generated by client-gen. DO NOT EDIT. package v1 diff --git a/pkg/generated/informers/externalversions/caelus/interface.go b/pkg/generated/informers/externalversions/caelus/interface.go index fc3afb4a..a19e58f5 100644 --- a/pkg/generated/informers/externalversions/caelus/interface.go +++ b/pkg/generated/informers/externalversions/caelus/interface.go @@ -1,17 +1,19 @@ /* - * Copyright (c) 2021 THL A29 Limited, a Tencent company. - * - * 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. - */ +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 caelus diff --git a/pkg/generated/informers/externalversions/caelus/v1/cgroupnotify.go b/pkg/generated/informers/externalversions/caelus/v1/cgroupnotify.go index 84578f95..1d48b431 100644 --- a/pkg/generated/informers/externalversions/caelus/v1/cgroupnotify.go +++ b/pkg/generated/informers/externalversions/caelus/v1/cgroupnotify.go @@ -1,17 +1,19 @@ /* - * Copyright (c) 2021 THL A29 Limited, a Tencent company. - * - * 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. - */ +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + // Code generated by informer-gen. DO NOT EDIT. package v1 diff --git a/pkg/generated/informers/externalversions/caelus/v1/interface.go b/pkg/generated/informers/externalversions/caelus/v1/interface.go index fbcca98a..83c91454 100644 --- a/pkg/generated/informers/externalversions/caelus/v1/interface.go +++ b/pkg/generated/informers/externalversions/caelus/v1/interface.go @@ -1,17 +1,19 @@ /* - * Copyright (c) 2021 THL A29 Limited, a Tencent company. - * - * 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. - */ +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + // Code generated by informer-gen. DO NOT EDIT. package v1 diff --git a/pkg/generated/informers/externalversions/caelus/v1/rulecheck.go b/pkg/generated/informers/externalversions/caelus/v1/rulecheck.go index 9c7b7fa7..32e85f5d 100644 --- a/pkg/generated/informers/externalversions/caelus/v1/rulecheck.go +++ b/pkg/generated/informers/externalversions/caelus/v1/rulecheck.go @@ -1,17 +1,19 @@ /* - * Copyright (c) 2021 THL A29 Limited, a Tencent company. - * - * 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. - */ +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + // Code generated by informer-gen. DO NOT EDIT. package v1 diff --git a/pkg/generated/informers/externalversions/factory.go b/pkg/generated/informers/externalversions/factory.go index 240dc7fa..abbc9085 100644 --- a/pkg/generated/informers/externalversions/factory.go +++ b/pkg/generated/informers/externalversions/factory.go @@ -1,17 +1,19 @@ /* - * Copyright (c) 2021 THL A29 Limited, a Tencent company. - * - * 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. - */ +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 diff --git a/pkg/generated/informers/externalversions/generic.go b/pkg/generated/informers/externalversions/generic.go index d7f27e6f..4fc257f9 100644 --- a/pkg/generated/informers/externalversions/generic.go +++ b/pkg/generated/informers/externalversions/generic.go @@ -1,17 +1,19 @@ /* - * Copyright (c) 2021 THL A29 Limited, a Tencent company. - * - * 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. - */ +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 diff --git a/pkg/generated/informers/externalversions/internalinterfaces/factory_interfaces.go b/pkg/generated/informers/externalversions/internalinterfaces/factory_interfaces.go index 8865fb04..5060968a 100644 --- a/pkg/generated/informers/externalversions/internalinterfaces/factory_interfaces.go +++ b/pkg/generated/informers/externalversions/internalinterfaces/factory_interfaces.go @@ -1,17 +1,19 @@ /* - * Copyright (c) 2021 THL A29 Limited, a Tencent company. - * - * 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. - */ +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 diff --git a/pkg/generated/listers/caelus/v1/cgroupnotify.go b/pkg/generated/listers/caelus/v1/cgroupnotify.go index 7043f632..decf1337 100644 --- a/pkg/generated/listers/caelus/v1/cgroupnotify.go +++ b/pkg/generated/listers/caelus/v1/cgroupnotify.go @@ -1,17 +1,19 @@ /* - * Copyright (c) 2021 THL A29 Limited, a Tencent company. - * - * 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. - */ +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + // Code generated by lister-gen. DO NOT EDIT. package v1 diff --git a/pkg/generated/listers/caelus/v1/expansion_generated.go b/pkg/generated/listers/caelus/v1/expansion_generated.go index 16786650..bfca4459 100644 --- a/pkg/generated/listers/caelus/v1/expansion_generated.go +++ b/pkg/generated/listers/caelus/v1/expansion_generated.go @@ -1,17 +1,19 @@ /* - * Copyright (c) 2021 THL A29 Limited, a Tencent company. - * - * 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. - */ +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + // Code generated by lister-gen. DO NOT EDIT. package v1 diff --git a/pkg/generated/listers/caelus/v1/rulecheck.go b/pkg/generated/listers/caelus/v1/rulecheck.go index f9e5c68b..298ee12c 100644 --- a/pkg/generated/listers/caelus/v1/rulecheck.go +++ b/pkg/generated/listers/caelus/v1/rulecheck.go @@ -1,17 +1,19 @@ /* - * Copyright (c) 2021 THL A29 Limited, a Tencent company. - * - * 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. - */ +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + // Code generated by lister-gen. DO NOT EDIT. package v1 From 41844133ab6280ef128618cdbdd123a21ed343c2 Mon Sep 17 00:00:00 2001 From: baowj Date: Wed, 27 Mar 2024 11:31:01 +0800 Subject: [PATCH 43/59] update readme Signed-off-by: baowj --- doc/rules.md | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 70 insertions(+), 2 deletions(-) diff --git a/doc/rules.md b/doc/rules.md index 4faf469f..e3d9c6fa 100644 --- a/doc/rules.md +++ b/doc/rules.md @@ -103,7 +103,7 @@ type NodeCpu struct { ... } ``` - Node rules example: + Node rules json example: ```json { "name": "cpu", @@ -145,6 +145,46 @@ type NodeCpu struct { ] } ``` +Node rules yaml example: +```yaml +apiVersion: caelus.io/v1 +kind: RuleCheck +metadata: + name: caelus-test1 + namespace: caelus-system +spec: + name: cpu + priority: 90 + nodeSelector: + disktype: "ssd" + type: node + metrics: + - cpu_avg + checkInterval: 10 + handleInterval: 10 + recoverInterval: 15 + rules: + - detects: + - name: expression + args: |- + { + "expression": "auto", + "warning_count": 10, + "warning_duration": "10s" + } + - actions: + - name: adjust + args: |- + { + "resources": [ + { + "step": "1000m" + }] + } + - name: schedule + args: |- + {} +``` ### Container rules Container rules describe how to detect metrics of container level, the supported metrics could be found from @@ -158,7 +198,7 @@ type CgroupStats struct { } ``` - Container rules example: + Container rules json example: ```json { "metrics": [ @@ -181,6 +221,34 @@ type CgroupStats struct { ] } ``` + +Container rules yaml example: +```yaml +apiVersion: caelus.io/v1 +kind: RuleCheck +metadata: + name: caelus-test2 + namespace: caelus-system +spec: + name: cpu + priority: 90 + nodeSelector: + disktype: "ssd" + type: container + metrics: + - nr_cpu_throttled + checkInterval: 5 + handleInterval: 10 + recoverInterval: 15 + rules: + - detects: + - name: expression + args: | + { + "expression": "nr_cpu_throttled > 0" + } +``` + ### App rules App rules describe how to detect metrics of app level, the metrics are provided by users themselves, in the way of executable command or http server, the example as flowing: From 0f8b4729eeb0de565dc90c00a46bb0c9dd082fea Mon Sep 17 00:00:00 2001 From: baowj Date: Wed, 27 Mar 2024 11:32:20 +0800 Subject: [PATCH 44/59] fix rulecheck time interval bug Signed-off-by: baowj --- pkg/caelus/healthcheck/health_check.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pkg/caelus/healthcheck/health_check.go b/pkg/caelus/healthcheck/health_check.go index 68812056..5a7bc361 100644 --- a/pkg/caelus/healthcheck/health_check.go +++ b/pkg/caelus/healthcheck/health_check.go @@ -18,6 +18,7 @@ package health import ( "reflect" "sort" + "time" v1 "github.com/tencent/caelus/pkg/apis/caelus/v1" notify "github.com/tencent/caelus/pkg/caelus/healthcheck/cgroupnotify" @@ -29,6 +30,7 @@ import ( "github.com/tencent/caelus/pkg/caelus/types" "github.com/tencent/caelus/pkg/caelus/util" caelusv1 "github.com/tencent/caelus/pkg/generated/informers/externalversions/caelus/v1" + "github.com/tencent/caelus/pkg/util/times" corev1 "k8s.io/api/core/v1" labels2 "k8s.io/apimachinery/pkg/labels" @@ -393,10 +395,10 @@ func (h *manager) convertK8sRuleCheck(k8sRuleCheck *v1.RuleCheck, ruleCheck *typ ruleCheck.Name = k8sRuleCheck.Name ruleCheck.Metrics = k8sRuleCheck.Spec.Metrics - ruleCheck.CheckInterval = *k8sRuleCheck.Spec.CheckInterval - ruleCheck.RecoverInterval = *k8sRuleCheck.Spec.RecoverInterval - ruleCheck.HandleInterval = *k8sRuleCheck.Spec.HandleInterval + ruleCheck.CheckInterval = *k8sRuleCheck.Spec.CheckInterval * times.Duration(time.Second) + ruleCheck.RecoverInterval = *k8sRuleCheck.Spec.RecoverInterval * times.Duration(time.Second) + ruleCheck.HandleInterval = *k8sRuleCheck.Spec.HandleInterval * times.Duration(time.Second) ruleCheck.NodeSelector = k8sRuleCheck.Spec.NodeSelector h.ruleCheckAvailableFunc(ruleCheck) } From af2b07841532a9b3e53786c2a50538be338a9dae Mon Sep 17 00:00:00 2001 From: yanxiaoqi932 Date: Thu, 28 Mar 2024 00:54:01 +0800 Subject: [PATCH 45/59] set status nil --- hack/yaml/caelus.yaml | 206 +++++++++++------------ pkg/apis/caelus/v1/cgroupnotify_types.go | 1 - 2 files changed, 100 insertions(+), 107 deletions(-) diff --git a/hack/yaml/caelus.yaml b/hack/yaml/caelus.yaml index 5ad2804d..4bf15375 100644 --- a/hack/yaml/caelus.yaml +++ b/hack/yaml/caelus.yaml @@ -163,114 +163,108 @@ spec: listKind: CgroupNotifyList plural: cgroupnotifies singular: cgroupnotify - scope: Cluster + scope: Namespaced versions: - - name: v1 - schema: - openAPIV3Schema: - description: CgroupNotify is a specification for a CgroupNotify resource - properties: - apiVersion: - description: |- - APIVersion defines the versioned schema of this representation of an object. - Servers should convert recognized schemas to the latest internal value, and - may reject unrecognized values. - More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources - type: string - kind: - description: |- - Kind is a string value representing the REST resource this object represents. - Servers may infer this from the endpoint the client submits requests to. - Cannot be updated. - In CamelCase. - More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds - type: string - metadata: - type: object - spec: - description: CgroupNotifySpec is the spec for a CgroupNotify resource - properties: - memory_cgroup: - description: MemoryNotifyConfig describe memory cgroup notify - properties: - pressures: - items: - description: MemoryPressureNotifyConfig describe memory.pressure_level - notify data - properties: - cgroups: - items: - type: string - type: array - count: - description: assign event number in the duration time - type: integer - duration: - description: assign time duration the pressure has kept - format: int64 - type: integer - pressure_level: + - name: v1 + schema: + openAPIV3Schema: + description: CgroupNotify is a specification for a CgroupNotify resource + properties: + apiVersion: + description: |- + APIVersion defines the versioned schema of this representation of an object. + Servers should convert recognized schemas to the latest internal value, and + may reject unrecognized values. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources + type: string + kind: + description: |- + Kind is a string value representing the REST resource this object represents. + Servers may infer this from the endpoint the client submits requests to. + Cannot be updated. + In CamelCase. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds + type: string + metadata: + type: object + spec: + description: CgroupNotifySpec is the spec for a CgroupNotify resource + properties: + memory_cgroup: + description: MemoryNotifyConfig describe memory cgroup notify + properties: + pressures: + items: + description: MemoryPressureNotifyConfig describe memory.pressure_level + notify data + properties: + cgroups: + items: type: string - required: - - cgroups - - count - - duration - - pressure_level - type: object - type: array - usages: - items: - description: MemoryUsageNotifyConfig describe memory.usage_in_bytes - notify data - properties: - cgroups: - items: - type: string - type: array - duration: - description: when to handle event after receiving event - format: int64 - type: integer - margin_mb: - description: the distance between limit and threshold - type: integer - required: - - cgroups - - duration - - margin_mb - type: object - type: array - required: - - pressures - - usages - type: object - nodeSelector: - additionalProperties: - type: string - type: object - priority: - format: int32 - type: integer - required: - - memory_cgroup - - nodeSelector - - priority - type: object - status: - description: CgroupNotifyStatus is the status for a CgroupNotify resource - properties: - availableReplicas: - format: int32 - type: integer - required: - - availableReplicas - type: object - required: - - spec - - status - type: object - served: true - storage: true + type: array + count: + description: assign event number in the duration time + type: integer + duration: + description: assign time duration the pressure has kept + format: int64 + type: integer + pressure_level: + type: string + required: + - cgroups + - count + - duration + - pressure_level + type: object + type: array + usages: + items: + description: MemoryUsageNotifyConfig describe memory.usage_in_bytes + notify data + properties: + cgroups: + items: + type: string + type: array + duration: + description: when to handle event after receiving event + format: int64 + type: integer + margin_mb: + description: the distance between limit and threshold + type: integer + required: + - cgroups + - duration + - margin_mb + type: object + type: array + required: + - pressures + - usages + type: object + nodeSelector: + additionalProperties: + type: string + type: object + priority: + format: int32 + type: integer + required: + - memory_cgroup + - nodeSelector + - priority + type: object + status: + description: CgroupNotifyStatus is the status for a CgroupNotify resource + type: object + required: + - spec + - status + type: object + served: true + storage: true --- apiVersion: v1 kind: ServiceAccount diff --git a/pkg/apis/caelus/v1/cgroupnotify_types.go b/pkg/apis/caelus/v1/cgroupnotify_types.go index f6fd3bdc..b19051e3 100644 --- a/pkg/apis/caelus/v1/cgroupnotify_types.go +++ b/pkg/apis/caelus/v1/cgroupnotify_types.go @@ -52,7 +52,6 @@ type MemoryUsageNotifyConfig struct { // CgroupNotifyStatus is the status for a CgroupNotify resource type CgroupNotifyStatus struct { - AvailableReplicas int32 `json:"availableReplicas"` } // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object From 9f4d6bf3033590dc10bfb0a4113658e5ab3d0a55 Mon Sep 17 00:00:00 2001 From: yanxiaoqi932 Date: Thu, 28 Mar 2024 12:34:02 +0800 Subject: [PATCH 46/59] modify rbac and rules.md --- cgroup.yaml | 20 ++++++++++++++++++++ doc/rules.md | 24 ++++++++++++++++++++++++ hack/yaml/caelus.yaml | 1 + pkg/caelus/healthcheck/health_check.go | 4 ++-- 4 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 cgroup.yaml diff --git a/cgroup.yaml b/cgroup.yaml new file mode 100644 index 00000000..643c830b --- /dev/null +++ b/cgroup.yaml @@ -0,0 +1,20 @@ +apiVersion: caelus.io/v1 +kind: CgroupNotify +metadata: + name: caelus-test1 + namespace: kube-system +spec: + priority: 90 + nodeSelector: + type: "memory" + memory_cgroup: + pressures: + - cgroups: ["/kubepods/offline"] + pressure_level: "low" + duration: 3 + count: 2 + usages: + - cgroups: ["/kubepods/offline/test"] + margin_mb: 2048 + duration: 60000 +status: {} diff --git a/doc/rules.md b/doc/rules.md index e3d9c6fa..562d43e4 100644 --- a/doc/rules.md +++ b/doc/rules.md @@ -404,3 +404,27 @@ spec: ] } ``` + +Memory cgroup event yaml example: +```yaml +apiVersion: caelus.io/v1 +kind: CgroupNotify +metadata: + name: caelus-test1 + namespace: kube-system +spec: + priority: 90 + nodeSelector: + type: "memory" + memory_cgroup: + pressures: + - cgroups: ["/kubepods/offline"] + pressure_level: "low" + duration: 3 + count: 2 + usages: + - cgroups: ["/kubepods/offline/test"] + margin_mb: 2048 + duration: 60000 +status: {} +``` \ No newline at end of file diff --git a/hack/yaml/caelus.yaml b/hack/yaml/caelus.yaml index 4bf15375..8ce1f529 100644 --- a/hack/yaml/caelus.yaml +++ b/hack/yaml/caelus.yaml @@ -291,6 +291,7 @@ rules: - apiGroups: ["caelus.io"] resources: - rulechecks + - cgroupnotifies verbs: ["list", "watch", "get", "update", "delete"] --- apiVersion: rbac.authorization.k8s.io/v1beta1 diff --git a/pkg/caelus/healthcheck/health_check.go b/pkg/caelus/healthcheck/health_check.go index 5a7bc361..a7230a22 100644 --- a/pkg/caelus/healthcheck/health_check.go +++ b/pkg/caelus/healthcheck/health_check.go @@ -260,7 +260,7 @@ func (h *manager) convertK8sCgroupNotify(k8sCgroupNotify *v1.CgroupNotify, cgrou newP := types.MemoryPressureNotifyConfig{} newP.Cgroups = p.Cgroups newP.Count = p.Count - newP.Duration = p.Duration + newP.Duration = p.Duration * times.Duration(time.Millisecond) newP.PressureLevel = p.PressureLevel pressures = append(pressures, newP) } @@ -268,7 +268,7 @@ func (h *manager) convertK8sCgroupNotify(k8sCgroupNotify *v1.CgroupNotify, cgrou for _, u := range k8sCgroupNotify.Spec.MemoryCgroup.Usages { newU := types.MemoryUsageNotifyConfig{} newU.Cgroups = u.Cgroups - newU.Duration = u.Duration + newU.Duration = u.Duration * times.Duration(time.Millisecond) newU.MarginMb = u.MarginMb usages = append(usages, newU) } From 0b4449c8e720da883feedddc31129c7c0deb9723 Mon Sep 17 00:00:00 2001 From: yanxiaoqi932 Date: Thu, 28 Mar 2024 14:20:54 +0800 Subject: [PATCH 47/59] modify: delete cgroup.yaml --- cgroup.yaml | 20 -------------------- 1 file changed, 20 deletions(-) delete mode 100644 cgroup.yaml diff --git a/cgroup.yaml b/cgroup.yaml deleted file mode 100644 index 643c830b..00000000 --- a/cgroup.yaml +++ /dev/null @@ -1,20 +0,0 @@ -apiVersion: caelus.io/v1 -kind: CgroupNotify -metadata: - name: caelus-test1 - namespace: kube-system -spec: - priority: 90 - nodeSelector: - type: "memory" - memory_cgroup: - pressures: - - cgroups: ["/kubepods/offline"] - pressure_level: "low" - duration: 3 - count: 2 - usages: - - cgroups: ["/kubepods/offline/test"] - margin_mb: 2048 - duration: 60000 -status: {} From 0a1f803b2c37b7dd6f4789d7f50df5da86ffd708 Mon Sep 17 00:00:00 2001 From: baowj Date: Thu, 28 Mar 2024 15:01:57 +0800 Subject: [PATCH 48/59] make rulecheck priority optional Signed-off-by: baowj --- hack/yaml/caelus.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/hack/yaml/caelus.yaml b/hack/yaml/caelus.yaml index 8ce1f529..be9d27dd 100644 --- a/hack/yaml/caelus.yaml +++ b/hack/yaml/caelus.yaml @@ -136,7 +136,6 @@ spec: - handleInterval - metrics - name - - priority - recoverInterval - rules - type From 1d371a61d5019e693621b3a150f4dc2574bbbd0c Mon Sep 17 00:00:00 2001 From: yanxiaoqi932 Date: Thu, 28 Mar 2024 16:03:09 +0800 Subject: [PATCH 49/59] add omitempty and modify nil pointer bug --- hack/yaml/caelus.yaml | 7 ++----- pkg/caelus/healthcheck/health_check.go | 9 ++++++++- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/hack/yaml/caelus.yaml b/hack/yaml/caelus.yaml index be9d27dd..463923d5 100644 --- a/hack/yaml/caelus.yaml +++ b/hack/yaml/caelus.yaml @@ -154,9 +154,9 @@ kind: CustomResourceDefinition metadata: annotations: controller-gen.kubebuilder.io/version: v0.14.0 - name: cgroupnotifies.caelus.io + name: cgroupnotifies.caelus.io.caelus.io spec: - group: caelus.io + group: caelus.io.caelus.io names: kind: CgroupNotify listKind: CgroupNotifyList @@ -252,15 +252,12 @@ spec: type: integer required: - memory_cgroup - - nodeSelector - - priority type: object status: description: CgroupNotifyStatus is the status for a CgroupNotify resource type: object required: - spec - - status type: object served: true storage: true diff --git a/pkg/caelus/healthcheck/health_check.go b/pkg/caelus/healthcheck/health_check.go index a7230a22..598e0f57 100644 --- a/pkg/caelus/healthcheck/health_check.go +++ b/pkg/caelus/healthcheck/health_check.go @@ -305,7 +305,14 @@ func (h *manager) updateCgroupNotifyConfig() error { return cgroupNotifiers[i].Spec.Priority > cgroupNotifiers[j].Spec.Priority } }) - baseCgroupNotify := &types.NotifyConfig{} + + memoryconfig := &types.MemoryNotifyConfig{ + Pressures: make([]types.MemoryPressureNotifyConfig, 0), + Usages: make([]types.MemoryUsageNotifyConfig, 0), + } + baseCgroupNotify := &types.NotifyConfig{ + MemoryCgroup: memoryconfig, + } for _, k8sCgroupNotify := range cgroupNotifiers { if ok, err := h.isLabelMatchedLocalNode(k8sCgroupNotify.Spec.NodeSelector); err != nil || !ok { continue From 9e593bd27db9fcd548f4252e059bfebde459b0fc Mon Sep 17 00:00:00 2001 From: yanxiaoqi932 Date: Thu, 28 Mar 2024 16:04:22 +0800 Subject: [PATCH 50/59] add omitempty --- pkg/apis/caelus/v1/cgroupnotify_types.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/apis/caelus/v1/cgroupnotify_types.go b/pkg/apis/caelus/v1/cgroupnotify_types.go index b19051e3..3ba5f5ec 100644 --- a/pkg/apis/caelus/v1/cgroupnotify_types.go +++ b/pkg/apis/caelus/v1/cgroupnotify_types.go @@ -15,14 +15,14 @@ type CgroupNotify struct { metav1.ObjectMeta `json:"metadata,omitempty"` Spec CgroupNotifySpec `json:"spec"` - Status CgroupNotifyStatus `json:"status"` + Status CgroupNotifyStatus `json:"status,omitempty"` } // CgroupNotifySpec is the spec for a CgroupNotify resource type CgroupNotifySpec struct { MemoryCgroup MemoryNotifyConfig `json:"memory_cgroup"` - NodeSelector map[string]string `json:"nodeSelector"` - Priority int32 `json:"priority"` + NodeSelector map[string]string `json:"nodeSelector,omitempty"` + Priority int32 `json:"priority,omitempty"` } // MemoryNotifyConfig describe memory cgroup notify From e3b68562c26d3aea5a221d305c1f5c8f25e72603 Mon Sep 17 00:00:00 2001 From: yanxiaoqi932 Date: Thu, 28 Mar 2024 16:11:56 +0800 Subject: [PATCH 51/59] modify newMemoryNotifyConfig --- pkg/caelus/healthcheck/health_check.go | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/pkg/caelus/healthcheck/health_check.go b/pkg/caelus/healthcheck/health_check.go index 598e0f57..d4910e2b 100644 --- a/pkg/caelus/healthcheck/health_check.go +++ b/pkg/caelus/healthcheck/health_check.go @@ -293,6 +293,17 @@ func (h *manager) mergeCgroupNotify(baseCgNotify, nextCgNotify *types.NotifyConf } } +func newMemoryNotifyConfig() *types.NotifyConfig { + memoryconfig := &types.MemoryNotifyConfig{ + Pressures: make([]types.MemoryPressureNotifyConfig, 0), + Usages: make([]types.MemoryUsageNotifyConfig, 0), + } + cgroupNotify := &types.NotifyConfig{ + MemoryCgroup: memoryconfig, + } + return cgroupNotify +} + func (h *manager) updateCgroupNotifyConfig() error { cgroupNotifiers, err := h.cgroupInformer.Lister().CgroupNotifies(corev1.NamespaceAll).List(labels2.Everything()) if err != nil { @@ -306,18 +317,12 @@ func (h *manager) updateCgroupNotifyConfig() error { } }) - memoryconfig := &types.MemoryNotifyConfig{ - Pressures: make([]types.MemoryPressureNotifyConfig, 0), - Usages: make([]types.MemoryUsageNotifyConfig, 0), - } - baseCgroupNotify := &types.NotifyConfig{ - MemoryCgroup: memoryconfig, - } + baseCgroupNotify := newMemoryNotifyConfig() for _, k8sCgroupNotify := range cgroupNotifiers { if ok, err := h.isLabelMatchedLocalNode(k8sCgroupNotify.Spec.NodeSelector); err != nil || !ok { continue } - cgroupNotify := &types.NotifyConfig{} + cgroupNotify := newMemoryNotifyConfig() h.convertK8sCgroupNotify(k8sCgroupNotify, cgroupNotify) h.mergeCgroupNotify(baseCgroupNotify, cgroupNotify) } From 369227b139a65648a8cde8c55a13c6872ec51e55 Mon Sep 17 00:00:00 2001 From: yanxiaoqi932 Date: Thu, 28 Mar 2024 16:20:12 +0800 Subject: [PATCH 52/59] modify caelus.yaml --- hack/yaml/caelus.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hack/yaml/caelus.yaml b/hack/yaml/caelus.yaml index 463923d5..7999795b 100644 --- a/hack/yaml/caelus.yaml +++ b/hack/yaml/caelus.yaml @@ -154,9 +154,9 @@ kind: CustomResourceDefinition metadata: annotations: controller-gen.kubebuilder.io/version: v0.14.0 - name: cgroupnotifies.caelus.io.caelus.io + name: cgroupnotifies.caelus.io spec: - group: caelus.io.caelus.io + group: caelus.io names: kind: CgroupNotify listKind: CgroupNotifyList From ce1e5ca2ee8e1f33aa5fcefe712b87374619c427 Mon Sep 17 00:00:00 2001 From: yanxiaoqi932 Date: Thu, 28 Mar 2024 22:56:22 +0800 Subject: [PATCH 53/59] rulecheck omitempty --- pkg/apis/caelus/v1/rulecheck_types.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/apis/caelus/v1/rulecheck_types.go b/pkg/apis/caelus/v1/rulecheck_types.go index 5bafadc6..c775c17a 100644 --- a/pkg/apis/caelus/v1/rulecheck_types.go +++ b/pkg/apis/caelus/v1/rulecheck_types.go @@ -38,14 +38,14 @@ type RuleCheck struct { metav1.ObjectMeta `json:"metadata,omitempty"` Spec RuleCheckSpec `json:"spec"` - Status RuleCheckStatus `json:"status"` + Status RuleCheckStatus `json:"status,omitempty"` } // RuleCheckSpec is the spec for a RuleCheck resource type RuleCheckSpec struct { Name string `json:"name"` - NodeSelector map[string]string `json:"nodeSelector"` - Priority int32 `json:"priority"` + NodeSelector map[string]string `json:"nodeSelector,omitempty"` + Priority int32 `json:"priority,omitempty"` Type RuleCheckType `json:"type"` Metrics []string `json:"metrics"` From 9ee903f7ae7b06fafbf4b9fb915345d569ad268c Mon Sep 17 00:00:00 2001 From: wang-mask <2018091609006@std.uestc.edu.cn> Date: Fri, 29 Mar 2024 10:14:35 +0800 Subject: [PATCH 54/59] add error info Signed-off-by: wang-mask <2018091609006@std.uestc.edu.cn> --- pkg/caelus/healthcheck/health_check.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pkg/caelus/healthcheck/health_check.go b/pkg/caelus/healthcheck/health_check.go index d4910e2b..2f318794 100644 --- a/pkg/caelus/healthcheck/health_check.go +++ b/pkg/caelus/healthcheck/health_check.go @@ -86,6 +86,7 @@ func NewHealthManager(stStore statestore.StateStore, }, PredictReserved: resourceType, } + hm := &manager{ config: config, ruleChecker: rulecheck.NewManager(config.RuleCheck, stStore, resource, qosManager, conflictMn, podInformer, config.PredictReserved), @@ -201,6 +202,7 @@ func (h *manager) processNextWorkItem() bool { } if err := h.syncHandler(key); err != nil { + klog.Error("Health check module failed to handle ", key, err) h.workqueue.Add(key) } @@ -209,7 +211,7 @@ func (h *manager) processNextWorkItem() bool { } func (h *manager) syncHandler(key string) error { - klog.Infof("---- Start syncHandler %v: %v", key, *h.config) + klog.Infof("Start syncHandler %v", key) if key == ruleCheck { err := h.updateRuleCheckConfig() if err != nil { @@ -224,7 +226,7 @@ func (h *manager) syncHandler(key string) error { h.reRunCgroupNotifier() } - klog.Infof("---- After syncHandler %v: %v", key, *h.config) + klog.Infof("After syncHandler %v: %v") return nil } From abd97d17ee1006ae035db6ec408a947fae168860 Mon Sep 17 00:00:00 2001 From: wang-mask <2018091609006@std.uestc.edu.cn> Date: Fri, 29 Mar 2024 11:32:07 +0800 Subject: [PATCH 55/59] update readme Signed-off-by: wang-mask <2018091609006@std.uestc.edu.cn> --- doc/rules.md | 8 +-- pkg/caelus/healthcheck/health_check_test.go | 57 --------------------- 2 files changed, 5 insertions(+), 60 deletions(-) delete mode 100644 pkg/caelus/healthcheck/health_check_test.go diff --git a/doc/rules.md b/doc/rules.md index 562d43e4..25ad0ab5 100644 --- a/doc/rules.md +++ b/doc/rules.md @@ -1,9 +1,12 @@ # Detection configuration - Caelus dynamically checks abnormalities of various metrics based on [rules.json](../hack/config/rules.json), such as CPU + Caelus dynamically checks abnormalities of various metrics based on CRDs of `RuleCheck` and `CgroupNotify` + , such as CPU usage or online latency, to make sure online jobs run normally. Batch jobs will be throttled or even killed if interference detected. - This document describes how to configure [rules.json](../hack/config/rules.json) + This document describes how to configure these CRDs. + + > **Attention**: Multiple `RuleCheck` or `CgroupNotify` can exist in a cluster, and they will be merged based on the set priority and creation time. ## 1.Rules Rules are used to assign the algorithm to check if the timed metrics have significant fluctuations, such as EWMA, @@ -426,5 +429,4 @@ spec: - cgroups: ["/kubepods/offline/test"] margin_mb: 2048 duration: 60000 -status: {} ``` \ No newline at end of file diff --git a/pkg/caelus/healthcheck/health_check_test.go b/pkg/caelus/healthcheck/health_check_test.go deleted file mode 100644 index c53411dc..00000000 --- a/pkg/caelus/healthcheck/health_check_test.go +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2021 THL A29 Limited, a Tencent company. - * - * 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 health - -import ( - "io/ioutil" - "os" - "testing" - - "github.com/tencent/caelus/pkg/caelus/types" - "github.com/tencent/caelus/pkg/caelus/util" -) - -var ( - testNodeName = "testNode" - testHash = "9589f334c6f4987fc5ddb8e0ac1c096b" -) - -// TestNeedReload test if the rule config need to reload -func TestNeedReload(t *testing.T) { - configFile := "/tmp/testing" - err := ioutil.WriteFile(configFile, []byte("just testing"), 0644) - if err != nil { - t.Skipf("creating testing file %s err: %v", configFile, err) - } - defer os.Remove(configFile) - - healthManager := &manager{ - configHash: "123", - configUpdateFunc: func(string) (*types.HealthCheckConfig, error) { - return &types.HealthCheckConfig{ - Disable: false, - RuleNodes: []string{testNodeName}, - }, nil - }, - } - - util.SetNodeIP(testNodeName) - reload, hash, _ := healthManager.checkNeedReload(configFile) - if !reload || hash != testHash { - t.Fatalf("health check manager reload not expected, got reload:%v, hash:%s, expect reload:true, hash:%s", - reload, hash, testHash) - } -} From 9d881fbfe57802ddc07b29bb1dd798ac6dfa910c Mon Sep 17 00:00:00 2001 From: wang-mask <2018091609006@std.uestc.edu.cn> Date: Fri, 29 Mar 2024 11:32:36 +0800 Subject: [PATCH 56/59] update role v1beta1 to v1 Signed-off-by: wang-mask <2018091609006@std.uestc.edu.cn> --- hack/yaml/caelus.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hack/yaml/caelus.yaml b/hack/yaml/caelus.yaml index 7999795b..64386d1d 100644 --- a/hack/yaml/caelus.yaml +++ b/hack/yaml/caelus.yaml @@ -268,7 +268,7 @@ metadata: name: caelus namespace: kube-system --- -apiVersion: rbac.authorization.k8s.io/v1beta1 +apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: labels: @@ -290,7 +290,7 @@ rules: - cgroupnotifies verbs: ["list", "watch", "get", "update", "delete"] --- -apiVersion: rbac.authorization.k8s.io/v1beta1 +apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: annotations: From 89b8a1c1167876b9fcfd730d5eebc464c7979917 Mon Sep 17 00:00:00 2001 From: baowj Date: Fri, 29 Mar 2024 12:43:39 +0800 Subject: [PATCH 57/59] remove rulecheck config labels and useless unit test. Signed-off-by: baowj --- pkg/caelus/healthcheck/health_check_test.go | 41 --------------------- pkg/caelus/types/health_check.go | 2 +- 2 files changed, 1 insertion(+), 42 deletions(-) diff --git a/pkg/caelus/healthcheck/health_check_test.go b/pkg/caelus/healthcheck/health_check_test.go index c53411dc..09923e07 100644 --- a/pkg/caelus/healthcheck/health_check_test.go +++ b/pkg/caelus/healthcheck/health_check_test.go @@ -14,44 +14,3 @@ */ package health - -import ( - "io/ioutil" - "os" - "testing" - - "github.com/tencent/caelus/pkg/caelus/types" - "github.com/tencent/caelus/pkg/caelus/util" -) - -var ( - testNodeName = "testNode" - testHash = "9589f334c6f4987fc5ddb8e0ac1c096b" -) - -// TestNeedReload test if the rule config need to reload -func TestNeedReload(t *testing.T) { - configFile := "/tmp/testing" - err := ioutil.WriteFile(configFile, []byte("just testing"), 0644) - if err != nil { - t.Skipf("creating testing file %s err: %v", configFile, err) - } - defer os.Remove(configFile) - - healthManager := &manager{ - configHash: "123", - configUpdateFunc: func(string) (*types.HealthCheckConfig, error) { - return &types.HealthCheckConfig{ - Disable: false, - RuleNodes: []string{testNodeName}, - }, nil - }, - } - - util.SetNodeIP(testNodeName) - reload, hash, _ := healthManager.checkNeedReload(configFile) - if !reload || hash != testHash { - t.Fatalf("health check manager reload not expected, got reload:%v, hash:%s, expect reload:true, hash:%s", - reload, hash, testHash) - } -} diff --git a/pkg/caelus/types/health_check.go b/pkg/caelus/types/health_check.go index 2264a326..8862fb23 100644 --- a/pkg/caelus/types/health_check.go +++ b/pkg/caelus/types/health_check.go @@ -109,7 +109,7 @@ type RuleCheckConfig struct { Name string `json:"name"` NodeSelector map[string]string `json:"node_selector"` Metrics []string `json:"metrics"` - Labels map[string]string `json:"labels"` + // CheckInterval describes the interval to trigger detection CheckInterval times.Duration `json:"check_interval"` // HandleInterval describes the interval to handle conflicts after detecting abnormal result From ff5b80080b2a34d987348b8643ec7c1520d42aa3 Mon Sep 17 00:00:00 2001 From: yanxiaoqi932 Date: Fri, 29 Mar 2024 12:58:18 +0800 Subject: [PATCH 58/59] delete types.NotifyConfig.Labels --- pkg/caelus/healthcheck/health_check.go | 4 ---- pkg/caelus/types/health_check.go | 1 - 2 files changed, 5 deletions(-) diff --git a/pkg/caelus/healthcheck/health_check.go b/pkg/caelus/healthcheck/health_check.go index d4910e2b..a3024d3d 100644 --- a/pkg/caelus/healthcheck/health_check.go +++ b/pkg/caelus/healthcheck/health_check.go @@ -274,13 +274,9 @@ func (h *manager) convertK8sCgroupNotify(k8sCgroupNotify *v1.CgroupNotify, cgrou } cgroupNotify.MemoryCgroup.Pressures = pressures cgroupNotify.MemoryCgroup.Usages = usages - cgroupNotify.Labels = k8sCgroupNotify.Spec.NodeSelector } func (h *manager) mergeCgroupNotify(baseCgNotify, nextCgNotify *types.NotifyConfig) { - if len(baseCgNotify.Labels) == 0 { - baseCgNotify.Labels = nextCgNotify.Labels - } if baseCgNotify.MemoryCgroup == nil { baseCgNotify.MemoryCgroup = nextCgNotify.MemoryCgroup } else { diff --git a/pkg/caelus/types/health_check.go b/pkg/caelus/types/health_check.go index 8862fb23..82fba6bd 100644 --- a/pkg/caelus/types/health_check.go +++ b/pkg/caelus/types/health_check.go @@ -143,7 +143,6 @@ type ActionConfig struct { // NotifyConfig monitor resource by kernel notify type NotifyConfig struct { MemoryCgroup *MemoryNotifyConfig `json:"memory_cgroup"` - Labels map[string]string `json:"labels"` } // MemoryNotifyConfig describe memory cgroup notify From 2e52e7d56eb1906a45bf2fbdbe134004ed1b2e82 Mon Sep 17 00:00:00 2001 From: wang-mask <2018091609006@std.uestc.edu.cn> Date: Mon, 1 Apr 2024 15:31:43 +0800 Subject: [PATCH 59/59] delete TODO comment Signed-off-by: wang-mask <2018091609006@std.uestc.edu.cn> --- cmd/caelus/context/context.go | 1 - 1 file changed, 1 deletion(-) diff --git a/cmd/caelus/context/context.go b/cmd/caelus/context/context.go index 081f476d..448093d0 100644 --- a/cmd/caelus/context/context.go +++ b/cmd/caelus/context/context.go @@ -41,7 +41,6 @@ type CaelusContext struct { caelusClient caelusclient.Interface nodeFactory, podFactory informers.SharedInformerFactory caelusFactory caelusinformers.SharedInformerFactory - // TODO add xxx informers } const (