Skip to content

Commit

Permalink
feat: operator 使用 metainformer 优化内存 --story=120658522 (#613)
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjiandongx authored Nov 13, 2024
1 parent 99c5b8b commit 74d605d
Show file tree
Hide file tree
Showing 13 changed files with 329 additions and 1,642 deletions.
46 changes: 8 additions & 38 deletions pkg/collector/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/TencentBlueKing/bkmonitor-datalink/pkg/utils v0.0.0-00010101000000-000000000000
github.com/apache/thrift v0.16.0
github.com/buraksezer/consistent v0.10.0
github.com/bytedance/sonic v1.11.2
github.com/bytedance/sonic v1.12.3
github.com/cespare/xxhash/v2 v2.2.0
github.com/elastic/beats v7.1.1+incompatible
github.com/elastic/go-ucfg v0.7.0
Expand Down Expand Up @@ -58,17 +58,17 @@ require (

require (
github.com/Shopify/sarama v1.32.0 // indirect
github.com/Tencent/bk-bcs/bcs-scenarios/kourse v0.0.0-20220914032224-06b1bd3358bc // indirect
github.com/aead/chacha20 v0.0.0-20180709150244-8b13a72661da // indirect
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 // indirect
github.com/armon/go-metrics v0.3.10 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/boltdb/bolt v1.3.1 // indirect
github.com/bytedance/sonic/loader v0.2.0 // indirect
github.com/cenkalti/backoff v2.2.1+incompatible // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/census-instrumentation/opencensus-proto v0.4.1 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect
github.com/chenzhuoyu/iasm v0.9.0 // indirect
github.com/cloudwego/base64x v0.1.4 // indirect
github.com/cloudwego/iasm v0.2.0 // indirect
github.com/containerd/cgroups v1.0.3 // indirect
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
Expand Down Expand Up @@ -183,48 +183,18 @@ require (
k8s.io/component-base v0.25.0 // indirect
k8s.io/klog/v2 v2.100.1 // indirect
k8s.io/kube-openapi v0.0.0-20230525220651-2546d827e515 // indirect
k8s.io/kubernetes v0.0.0-00010101000000-000000000000 // indirect
k8s.io/utils v0.0.0-20230711102312-30195339c3c7 // indirect
sigs.k8s.io/controller-runtime v0.12.3 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.3.0 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)

replace github.com/elastic/beats v7.1.1+incompatible => github.com/TencentBlueKing/beats v7.1.15-bk+incompatible

replace github.com/TencentBlueKing/bkmonitor-datalink/pkg/utils => ../utils

replace github.com/TencentBlueKing/bkmonitor-datalink/pkg/libgse => ../libgse

replace github.com/TencentBlueKing/bkmonitor-datalink/pkg/operator => ../operator

replace (
github.com/TencentBlueKing/bkmonitor-datalink/pkg/libgse => ../libgse
github.com/TencentBlueKing/bkmonitor-datalink/pkg/operator => ../operator
github.com/TencentBlueKing/bkmonitor-datalink/pkg/utils => ../utils
github.com/elastic/beats v7.1.1+incompatible => github.com/TencentBlueKing/beats v7.1.15-bk+incompatible
// A replace directive is needed for github.com/prometheus/prometheus to ensure running against the latest version of prometheus.
github.com/prometheus/prometheus => github.com/prometheus/prometheus v0.38.0
k8s.io/api => k8s.io/api v0.25.0
k8s.io/apiextensions-apiserver => k8s.io/apiextensions-apiserver v0.25.0
k8s.io/apimachinery => k8s.io/apimachinery v0.25.0
k8s.io/apiserver => k8s.io/apiserver v0.25.0
k8s.io/cli-runtime => k8s.io/cli-runtime v0.25.0
k8s.io/client-go => k8s.io/client-go v0.25.0
k8s.io/cloud-provider => k8s.io/cloud-provider v0.25.0
k8s.io/cluster-bootstrap => k8s.io/cluster-bootstrap v0.25.0
k8s.io/code-generator => k8s.io/code-generator v0.25.0
k8s.io/component-base => k8s.io/component-base v0.25.0
k8s.io/component-helpers => k8s.io/component-helpers v0.25.0
k8s.io/controller-manager => k8s.io/controller-manager v0.25.0
k8s.io/cri-api => k8s.io/cri-api v0.25.0
k8s.io/csi-translation-lib => k8s.io/csi-translation-lib v0.25.0
k8s.io/kube-aggregator => k8s.io/kube-aggregator v0.25.0
k8s.io/kube-controller-manager => k8s.io/kube-controller-manager v0.25.0
k8s.io/kube-proxy => k8s.io/kube-proxy v0.25.0
k8s.io/kube-scheduler => k8s.io/kube-scheduler v0.25.0
k8s.io/kubectl => k8s.io/kubectl v0.25.0
k8s.io/kubelet => k8s.io/kubelet v0.25.0
k8s.io/kubernetes => k8s.io/kubernetes v1.20.0
k8s.io/legacy-cloud-providers => k8s.io/legacy-cloud-providers v0.25.0
k8s.io/metrics => k8s.io/metrics v0.25.0
k8s.io/mount-utils => k8s.io/mount-utils v0.25.0
k8s.io/sample-apiserver => k8s.io/sample-apiserver v0.25.0
)
731 changes: 22 additions & 709 deletions pkg/collector/go.sum

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions pkg/operator/client/clientset/versioned/clientset.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

79 changes: 75 additions & 4 deletions pkg/operator/client/informers/externalversions/factory.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 10 additions & 11 deletions pkg/operator/common/k8sutils/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"fmt"
"strings"

tkexversiond "github.com/Tencent/bk-bcs/bcs-scenarios/kourse/pkg/client/clientset/versioned"
promversioned "github.com/prometheus-operator/prometheus-operator/pkg/client/versioned"
"github.com/prometheus-operator/prometheus-operator/pkg/k8sutil"
"github.com/prometheus-operator/prometheus-operator/pkg/operator"
Expand All @@ -25,6 +24,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
clientv1 "k8s.io/client-go/kubernetes/typed/core/v1"
"k8s.io/client-go/metadata"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/cache"
"k8s.io/client-go/util/retry"
Expand All @@ -46,6 +46,15 @@ func NewK8SClient(host string, tlsConfig *rest.TLSClientConfig) (kubernetes.Inte
return kubernetes.NewForConfig(cfg)
}

func NewMetadataClient(host string, tlsConfig *rest.TLSClientConfig) (metadata.Interface, error) {
cfg, err := k8sutil.NewClusterConfig(host, tlsConfig.Insecure, tlsConfig)
if err != nil {
return nil, err
}
cfg.ContentType = contentTypeProtobuf
return metadata.NewForConfig(cfg)
}

func NewK8SClientInsecure() (kubernetes.Interface, error) {
cfg, err := k8sutil.NewClusterConfig("", true, nil)
if err != nil {
Expand Down Expand Up @@ -75,16 +84,6 @@ func NewBKClient(host string, tlsConfig *rest.TLSClientConfig) (bkversioned.Inte
return bkversioned.NewForConfig(cfg)
}

// NewTkexClient 操作 GameStatefulSet/GameDeployment CRD
func NewTkexClient(host string, tlsConfig *rest.TLSClientConfig) (tkexversiond.Interface, error) {
cfg, err := k8sutil.NewClusterConfig(host, tlsConfig.Insecure, tlsConfig)
if err != nil {
return nil, err
}
cfg.ContentType = contentTypeProtobuf
return tkexversiond.NewForConfig(cfg)
}

func WaitForNamedCacheSync(ctx context.Context, controllerName string, inf cache.SharedIndexInformer) bool {
return operator.WaitForNamedCacheSync(ctx, controllerName, logx.New(controllerName), inf)
}
Expand Down
43 changes: 7 additions & 36 deletions pkg/operator/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ module github.com/TencentBlueKing/bkmonitor-datalink/pkg/operator
go 1.21

require (
github.com/blang/semver/v4 v4.0.0
github.com/cespare/xxhash/v2 v2.2.0
github.com/elastic/beats v7.1.1+incompatible
github.com/ghodss/yaml v1.0.0
github.com/go-kit/log v0.2.1
github.com/gorilla/mux v1.8.0
github.com/goware/urlx v0.3.1
github.com/kylelemons/godebug v1.1.0
Expand All @@ -17,28 +21,21 @@ require (
github.com/prometheus/prometheus v1.99.0
github.com/spf13/cobra v1.4.0
github.com/stretchr/testify v1.8.4
github.com/valyala/bytebufferpool v1.0.0
go.uber.org/automaxprocs v1.5.2
gopkg.in/yaml.v2 v2.4.0
k8s.io/api v0.27.3
k8s.io/apimachinery v0.27.3
k8s.io/client-go v0.27.3
k8s.io/code-generator v0.27.3
)

require (
github.com/Tencent/bk-bcs/bcs-scenarios/kourse v0.0.0-20220914032224-06b1bd3358bc
github.com/TencentBlueKing/bkmonitor-datalink/pkg/libgse v0.0.0-00010101000000-000000000000
github.com/TencentBlueKing/bkmonitor-datalink/pkg/utils v0.0.0-00010101000000-000000000000
github.com/blang/semver/v4 v4.0.0
github.com/cespare/xxhash/v2 v2.2.0
github.com/ghodss/yaml v1.0.0
github.com/go-kit/log v0.2.1
github.com/valyala/bytebufferpool v1.0.0
k8s.io/code-generator v0.25.0
)

require (
cloud.google.com/go/compute v1.22.0 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
github.com/PuerkitoBio/purell v1.1.1 // indirect
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
github.com/Shopify/sarama v1.27.1 // indirect
Expand Down Expand Up @@ -175,10 +172,9 @@ require (
howett.net/plist v0.0.0-20181124034731-591f970eefbb // indirect
k8s.io/apiextensions-apiserver v0.25.0 // indirect
k8s.io/component-base v0.25.0 // indirect
k8s.io/gengo v0.0.0-20211129171323-c02415ce4185 // indirect
k8s.io/gengo v0.0.0-20220902162205-c0856e24416d // indirect
k8s.io/klog/v2 v2.100.1 // indirect
k8s.io/kube-openapi v0.0.0-20230525220651-2546d827e515 // indirect
k8s.io/kubernetes v0.0.0-00010101000000-000000000000 // indirect
k8s.io/utils v0.0.0-20230711102312-30195339c3c7 // indirect
sigs.k8s.io/controller-runtime v0.12.3 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
Expand All @@ -192,29 +188,4 @@ replace (
github.com/elastic/beats v7.1.1+incompatible => github.com/TencentBlueKing/beats v7.1.17-bk+incompatible
// A replace directive is needed for github.com/prometheus/prometheus to ensure running against the latest version of prometheus.
github.com/prometheus/prometheus => github.com/prometheus/prometheus v0.40.0
k8s.io/api => k8s.io/api v0.25.0
k8s.io/apiextensions-apiserver => k8s.io/apiextensions-apiserver v0.25.0
k8s.io/apimachinery => k8s.io/apimachinery v0.25.0
k8s.io/apiserver => k8s.io/apiserver v0.25.0
k8s.io/cli-runtime => k8s.io/cli-runtime v0.25.0
k8s.io/client-go => k8s.io/client-go v0.25.0
k8s.io/cloud-provider => k8s.io/cloud-provider v0.25.0
k8s.io/cluster-bootstrap => k8s.io/cluster-bootstrap v0.25.0
k8s.io/code-generator => k8s.io/code-generator v0.25.0
k8s.io/component-base => k8s.io/component-base v0.25.0
k8s.io/component-helpers => k8s.io/component-helpers v0.25.0
k8s.io/controller-manager => k8s.io/controller-manager v0.25.0
k8s.io/cri-api => k8s.io/cri-api v0.25.0
k8s.io/csi-translation-lib => k8s.io/csi-translation-lib v0.25.0
k8s.io/kube-aggregator => k8s.io/kube-aggregator v0.25.0
k8s.io/kube-controller-manager => k8s.io/kube-controller-manager v0.25.0
k8s.io/kube-proxy => k8s.io/kube-proxy v0.25.0
k8s.io/kube-scheduler => k8s.io/kube-scheduler v0.25.0
k8s.io/kubectl => k8s.io/kubectl v0.25.0
k8s.io/kubelet => k8s.io/kubelet v0.25.0
k8s.io/kubernetes => k8s.io/kubernetes v1.20.0
k8s.io/legacy-cloud-providers => k8s.io/legacy-cloud-providers v0.25.0
k8s.io/metrics => k8s.io/metrics v0.25.0
k8s.io/mount-utils => k8s.io/mount-utils v0.25.0
k8s.io/sample-apiserver => k8s.io/sample-apiserver v0.25.0
)
Loading

0 comments on commit 74d605d

Please sign in to comment.