Skip to content

Commit

Permalink
feat(resource-recommend): add resource recommend controller
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhangsongLee committed Feb 24, 2024
1 parent d0d9365 commit ca0cb72
Show file tree
Hide file tree
Showing 69 changed files with 10,068 additions and 65 deletions.
50 changes: 50 additions & 0 deletions cmd/katalyst-controller/app/controller/resourcerecommender.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
Copyright 2022 The Katalyst Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package controller

import (
"context"

"k8s.io/klog/v2"

katalyst "github.com/kubewharf/katalyst-core/cmd/base"
"github.com/kubewharf/katalyst-core/pkg/config"
"github.com/kubewharf/katalyst-core/pkg/controller/resource-recommend/controller"
)

const (
ResourceRecommenderControllerName = "resourcerecommender"
)

func StartResourceRecommenderController(
ctx context.Context,
_ *katalyst.GenericContext,
conf *config.Configuration,
_ interface{},
_ string,
) (bool, error) {
resourceRecommenderController, err := controller.NewResourceRecommenderController(ctx,
conf.GenericConfiguration,
conf.ControllersConfiguration.ResourceRecommenderConfig)
if err != nil {
klog.Errorf("failed to new ResourceRecommender controller")
return false, err
}

go resourceRecommenderController.Run()
return true, nil
}
1 change: 1 addition & 0 deletions cmd/katalyst-controller/app/enablecontrollers.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func init() {
controllerInitializers.Store(controller.MonitorControllerName, ControllerStarter{Starter: controller.StartMonitorController})
controllerInitializers.Store(controller.OvercommitControllerName, ControllerStarter{Starter: controller.StartOvercommitController})
controllerInitializers.Store(controller.TideControllerName, ControllerStarter{Starter: controller.StartTideController})
controllerInitializers.Store(controller.ResourceRecommenderControllerName, ControllerStarter{Starter: controller.StartResourceRecommenderController})
}

// RegisterControllerInitializer is used to register user-defined controllers
Expand Down
16 changes: 10 additions & 6 deletions cmd/katalyst-controller/app/options/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,18 @@ type ControllersOptions struct {
*LifeCycleOptions
*MonitorOptions
*OvercommitOptions
*ResourceRecommenderOptions
}

func NewControllersOptions() *ControllersOptions {
return &ControllersOptions{
VPAOptions: NewVPAOptions(),
KCCOptions: NewKCCOptions(),
SPDOptions: NewSPDOptions(),
LifeCycleOptions: NewLifeCycleOptions(),
MonitorOptions: NewMonitorOptions(),
OvercommitOptions: NewOvercommitOptions(),
VPAOptions: NewVPAOptions(),
KCCOptions: NewKCCOptions(),
SPDOptions: NewSPDOptions(),
LifeCycleOptions: NewLifeCycleOptions(),
MonitorOptions: NewMonitorOptions(),
OvercommitOptions: NewOvercommitOptions(),
ResourceRecommenderOptions: NewResourceRecommenderOptions(),
}
}

Expand All @@ -50,6 +52,7 @@ func (o *ControllersOptions) AddFlags(fss *cliflag.NamedFlagSets) {
o.LifeCycleOptions.AddFlags(fss)
o.MonitorOptions.AddFlags(fss)
o.OvercommitOptions.AddFlags(fss)
o.ResourceRecommenderOptions.AddFlags(fss)
}

// ApplyTo fills up config with options
Expand All @@ -62,6 +65,7 @@ func (o *ControllersOptions) ApplyTo(c *controllerconfig.ControllersConfiguratio
errList = append(errList, o.LifeCycleOptions.ApplyTo(c.LifeCycleConfig))
errList = append(errList, o.MonitorOptions.ApplyTo(c.MonitorConfig))
errList = append(errList, o.OvercommitOptions.ApplyTo(c.OvercommitConfig))
errList = append(errList, o.ResourceRecommenderOptions.ApplyTo(c.ResourceRecommenderConfig))
return errors.NewAggregate(errList)
}

Expand Down
100 changes: 100 additions & 0 deletions cmd/katalyst-controller/app/options/resourcerecommender.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
Copyright 2022 The Katalyst Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package options

import (
"time"

cliflag "k8s.io/component-base/cli/flag"

"github.com/kubewharf/katalyst-core/pkg/config/controller"
"github.com/kubewharf/katalyst-core/pkg/controller/resource-recommend/datasource/prometheus"
)

type ResourceRecommenderOptions struct {
OOMRecordMaxNumber int `desc:"max number for oom record"`

HealthProbeBindPort string `desc:"The port the health probe binds to."`
MetricsBindPort string `desc:"The port the metric endpoint binds to."`

// available datasource: prom
DataSource []string
// DataSourcePromConfig is the prometheus datasource config
DataSourcePromConfig prometheus.PromConfig

// LogVerbosityLevel to specify log verbosity level. (The default level is 4)
// Set it to something larger than 4 if more detailed logs are needed.
LogVerbosityLevel string
}

// NewResourceRecommenderOptions creates a new Options with a default config.
func NewResourceRecommenderOptions() *ResourceRecommenderOptions {
return &ResourceRecommenderOptions{
OOMRecordMaxNumber: 5000,
HealthProbeBindPort: "8080",
MetricsBindPort: "8081",
DataSource: []string{"prom"},
DataSourcePromConfig: prometheus.PromConfig{
KeepAlive: 60 * time.Second,
Timeout: 3 * time.Minute,
BRateLimit: false,
MaxPointsLimitPerTimeSeries: 11000,
},
LogVerbosityLevel: "4",
}
}

// AddFlags adds flags to the specified FlagSet
func (o *ResourceRecommenderOptions) AddFlags(fss *cliflag.NamedFlagSets) {
fs := fss.FlagSet("resource-recommend")

fs.StringVar(&o.LogVerbosityLevel, "v", "4", "log verbosity level. The default level is 4. Set it to something larger than 4 if more detailed logs are needed")
fs.IntVar(&o.OOMRecordMaxNumber, "oom-record-max-number", 5000, "Max number for oom records to store in configmap")

fs.StringVar(&o.HealthProbeBindPort, "health-probe-bind-port", "8080", "The port the health probe binds to.")
fs.StringVar(&o.MetricsBindPort, "metrics-bind-port", "8081", "The port the metric endpoint binds to.")

fs.StringSliceVar(&o.DataSource, "datasource", []string{"prom"}, "available datasource: prom")
fs.StringVar(&o.DataSourcePromConfig.Auth.Type, "prometheus-auth-type", "", "prometheus auth type")
fs.StringVar(&o.DataSourcePromConfig.Address, "prometheus-address", "", "prometheus address")
fs.StringVar(&o.DataSourcePromConfig.Auth.Username, "prometheus-auth-username", "", "prometheus auth username")
fs.StringVar(&o.DataSourcePromConfig.Auth.Password, "prometheus-auth-password", "", "prometheus auth password")
fs.StringVar(&o.DataSourcePromConfig.Auth.BearerToken, "prometheus-auth-bearertoken", "", "prometheus auth bearertoken")
fs.DurationVar(&o.DataSourcePromConfig.KeepAlive, "prometheus-keepalive", 60*time.Second, "prometheus keep alive")
fs.DurationVar(&o.DataSourcePromConfig.Timeout, "prometheus-timeout", 3*time.Minute, "prometheus timeout")
fs.BoolVar(&o.DataSourcePromConfig.BRateLimit, "prometheus-bratelimit", false, "prometheus bratelimit")
fs.IntVar(&o.DataSourcePromConfig.MaxPointsLimitPerTimeSeries, "prometheus-maxpoints", 11000, "prometheus max points limit per time series")

}

func (o *ResourceRecommenderOptions) ApplyTo(c *controller.ResourceRecommenderConfig) error {
c.OOMRecordMaxNumber = o.OOMRecordMaxNumber
c.HealthProbeBindPort = o.HealthProbeBindPort
c.MetricsBindPort = o.MetricsBindPort
c.DataSource = o.DataSource
c.DataSourcePromConfig = o.DataSourcePromConfig
c.LogVerbosityLevel = o.LogVerbosityLevel
return nil
}

func (o *ResourceRecommenderOptions) Config() (*controller.ResourceRecommenderConfig, error) {
c := &controller.ResourceRecommenderConfig{}
if err := o.ApplyTo(c); err != nil {
return nil, err
}
return c, nil
}
57 changes: 30 additions & 27 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,43 +12,47 @@ require (
github.com/gogo/protobuf v1.3.2
github.com/golang/protobuf v1.5.2
github.com/google/cadvisor v0.44.2
github.com/google/uuid v1.3.0
github.com/kubewharf/katalyst-api v0.4.1-0.20240222122824-be538f641f58
github.com/montanaflynn/stats v0.7.1
github.com/opencontainers/runc v1.1.6
github.com/opencontainers/selinux v1.10.0
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.12.1
github.com/prometheus/client_model v0.2.0
github.com/prometheus/common v0.32.1
github.com/prometheus/client_golang v1.14.0
github.com/prometheus/client_model v0.3.0
github.com/prometheus/common v0.37.0
github.com/slok/kubewebhook v0.11.0
github.com/spf13/cobra v1.4.0
github.com/spf13/cobra v1.6.0
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.8.1
github.com/vishvananda/netns v0.0.0-20200728191858-db3c7e526aae
github.com/volcengine/volc-sdk-golang v1.0.71
go.opentelemetry.io/otel v0.20.0
go.opentelemetry.io/otel/exporters/metric/prometheus v0.20.0
go.opentelemetry.io/otel/metric v0.20.0
go.opentelemetry.io/otel/sdk v0.20.0
go.opentelemetry.io/otel/sdk/export/metric v0.20.0
go.opentelemetry.io/otel/sdk/metric v0.20.0
go.uber.org/atomic v1.7.0
go.uber.org/atomic v1.9.0
golang.org/x/sys v0.7.0
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8
gonum.org/v1/gonum v0.6.2
gonum.org/v1/gonum v0.8.2
google.golang.org/grpc v1.51.0
k8s.io/api v0.24.16
k8s.io/apimachinery v0.24.16
gopkg.in/yaml.v3 v3.0.1
k8s.io/api v0.26.1
k8s.io/apimachinery v0.26.1
k8s.io/apiserver v0.24.16
k8s.io/autoscaler/cluster-autoscaler v0.0.0-20231010095923-8a61add71154
k8s.io/client-go v0.24.16
k8s.io/component-base v0.24.16
k8s.io/autoscaler/vertical-pod-autoscaler v1.0.0
k8s.io/client-go v0.26.1
k8s.io/component-base v0.25.0
k8s.io/component-helpers v0.24.16
k8s.io/cri-api v0.24.6
k8s.io/klog/v2 v2.80.1
k8s.io/kube-aggregator v0.24.6
k8s.io/kubelet v0.24.6
k8s.io/kubernetes v1.24.16
k8s.io/metrics v0.24.6
k8s.io/metrics v0.25.0
k8s.io/utils v0.0.0-20221108210102-8e77b1f39fe2
sigs.k8s.io/controller-runtime v0.11.2
sigs.k8s.io/custom-metrics-apiserver v1.24.0
Expand All @@ -60,10 +64,9 @@ require (
github.com/Microsoft/go-winio v0.4.17 // indirect
github.com/NYTimes/gziphandler v1.1.1 // indirect
github.com/OneOfOne/xxhash v1.2.5 // indirect
github.com/PuerkitoBio/purell v1.1.1 // indirect
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/blang/semver/v4 v4.0.0 // indirect
github.com/cenkalti/backoff/v4 v4.1.2 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/coreos/go-semver v0.3.0 // indirect
github.com/coreos/go-systemd/v22 v22.3.2 // indirect
Expand All @@ -76,23 +79,22 @@ require (
github.com/felixge/httpsnoop v1.0.1 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.0 // indirect
github.com/go-openapi/swag v0.19.15 // indirect
github.com/godbus/dbus/v5 v5.0.6 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/google/gnostic v0.6.9 // indirect
github.com/google/go-cmp v0.5.8 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect
github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect
github.com/imdario/mergo v0.3.12 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.0.1 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/jpillora/backoff v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/mailru/easyjson v0.7.6 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.2 // indirect
github.com/mistifyio/go-zfs v2.1.2-0.20190413222219-f784269be439+incompatible // indirect
github.com/moby/spdystream v0.2.0 // indirect
github.com/moby/sys/mountinfo v0.6.0 // indirect
Expand All @@ -105,8 +107,9 @@ require (
github.com/opencontainers/runtime-spec v1.0.3-0.20210326190908-1c3f411f0417 // indirect
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/procfs v0.7.3 // indirect
github.com/sirupsen/logrus v1.8.1 // indirect
github.com/prometheus/procfs v0.8.0 // indirect
github.com/sirupsen/logrus v1.9.0 // indirect
github.com/stretchr/objx v0.5.0 // indirect
go.etcd.io/etcd/api/v3 v3.5.4 // indirect
go.etcd.io/etcd/client/pkg/v3 v3.5.4 // indirect
go.etcd.io/etcd/client/v3 v3.5.4 // indirect
Expand All @@ -116,27 +119,27 @@ require (
go.opentelemetry.io/otel/exporters/otlp v0.20.0 // indirect
go.opentelemetry.io/otel/trace v0.20.0 // indirect
go.opentelemetry.io/proto/otlp v0.7.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
go.uber.org/multierr v1.7.0 // indirect
go.uber.org/zap v1.19.1 // indirect
golang.org/x/crypto v0.0.0-20220926161630-eccd6366d1be // indirect
golang.org/x/net v0.9.0 // indirect
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8 // indirect
golang.org/x/oauth2 v0.0.0-20220223155221-ee480838109b // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/term v0.7.0 // indirect
golang.org/x/text v0.9.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.2.0 // indirect
gomodules.xyz/jsonpatch/v3 v3.0.1 // indirect
gomodules.xyz/orderedmap v0.1.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20220502173005-c8bf987b8c21 // indirect
google.golang.org/protobuf v1.28.0 // indirect
gopkg.in/check.v1 v1.0.0-20200902074654-038fdea0a05b // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/apiextensions-apiserver v0.24.2 // indirect
k8s.io/cloud-provider v0.24.16 // indirect
k8s.io/csi-translation-lib v0.24.16 // indirect
k8s.io/kube-openapi v0.0.0-20220803162953-67bda5d908f1 // indirect
k8s.io/kube-openapi v0.0.0-20221012153701-172d655c2280 // indirect
k8s.io/kube-scheduler v0.24.6 // indirect
k8s.io/mount-utils v0.24.16 // indirect
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.0.37 // indirect
Expand Down
Loading

0 comments on commit ca0cb72

Please sign in to comment.