Skip to content

Commit

Permalink
feat: observe cnr numa exclusive anomaly metric
Browse files Browse the repository at this point in the history
Signed-off-by: zhy76 <958474674@qq.com>
  • Loading branch information
zhy76 committed Aug 24, 2023
1 parent 8238e25 commit 2923fcf
Show file tree
Hide file tree
Showing 15 changed files with 802 additions and 13 deletions.
60 changes: 60 additions & 0 deletions cmd/katalyst-controller/app/controller/cnr.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
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"

katalystbase "github.com/kubewharf/katalyst-core/cmd/base"
"github.com/kubewharf/katalyst-core/pkg/config"
"github.com/kubewharf/katalyst-core/pkg/controller/cnr"
)

const (
CNRControllerName = "cnr"
)

func StartCNRController(ctx context.Context, controlCtx *katalystbase.GenericContext,
conf *config.Configuration, _ interface{}, _ string) (bool, error) {
var (
cnrController *cnr.CNRController
err error
)

if conf.CNRConfig.EnableCNR {
cnrController, err = cnr.NewCNRController(ctx,
conf.GenericConfiguration,
conf.GenericControllerConfiguration,
controlCtx.Client,
controlCtx.KubeInformerFactory.Core().V1().Pods(),
controlCtx.InternalInformerFactory.Node().V1alpha1().CustomNodeResources(),
controlCtx.EmitterPool.GetDefaultMetricsEmitter(),
)
if err != nil {
klog.Errorf("failed to new CNR controller")
return false, err
}
}

if cnrController != nil {
go cnrController.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 @@ -51,6 +51,7 @@ func init() {
controllerInitializers.Store(controller.KCCControllerName, ControllerStarter{Starter: controller.StartKCCController})
controllerInitializers.Store(controller.SPDControllerName, ControllerStarter{Starter: controller.StartSPDController})
controllerInitializers.Store(controller.LifeCycleControllerName, ControllerStarter{Starter: controller.StartLifeCycleController})
controllerInitializers.Store(controller.CNRControllerName, ControllerStarter{Starter: controller.StartCNRController})
}

// RegisterControllerInitializer is used to register user-defined controllers
Expand Down
56 changes: 56 additions & 0 deletions cmd/katalyst-controller/app/options/cnr.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
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 (
cliflag "k8s.io/component-base/cli/flag"

"github.com/kubewharf/katalyst-core/pkg/config/controller"
)

type CNROptions struct {
// EnableCNR is a flag to enable CNR controller
EnableCNR bool
}

func NewCNROptions() *CNROptions {
return &CNROptions{
EnableCNR: true,
}
}

// AddFlags adds flags to the specified FlagSet.
func (o *CNROptions) AddFlags(fss *cliflag.NamedFlagSets) {
fs := fss.FlagSet("cnr")

fs.BoolVar(&o.EnableCNR, "cnr-enable", o.EnableCNR,
"whether to enable the cnr controller")
}

// ApplyTo fills up config with options
func (o *CNROptions) ApplyTo(c *controller.CNRConfig) error {
c.EnableCNR = o.EnableCNR
return nil
}

func (o *CNROptions) Config() (*controller.CNRConfig, error) {
c := controller.NewCNRConfig()
if err := o.ApplyTo(c); err != nil {
return nil, err
}
return c, nil
}
4 changes: 4 additions & 0 deletions cmd/katalyst-controller/app/options/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type ControllersOptions struct {
*KCCOptions
*SPDOptions
*LifeCycleOptions
*CNROptions
}

func NewControllersOptions() *ControllersOptions {
Expand All @@ -36,6 +37,7 @@ func NewControllersOptions() *ControllersOptions {
KCCOptions: NewKCCOptions(),
SPDOptions: NewSPDOptions(),
LifeCycleOptions: NewLifeCycleOptions(),
CNROptions: NewCNROptions(),
}
}

Expand All @@ -44,6 +46,7 @@ func (o *ControllersOptions) AddFlags(fss *cliflag.NamedFlagSets) {
o.KCCOptions.AddFlags(fss)
o.SPDOptions.AddFlags(fss)
o.LifeCycleOptions.AddFlags(fss)
o.CNROptions.AddFlags(fss)
}

// ApplyTo fills up config with options
Expand All @@ -54,6 +57,7 @@ func (o *ControllersOptions) ApplyTo(c *controllerconfig.ControllersConfiguratio
errList = append(errList, o.KCCOptions.ApplyTo(c.KCCConfig))
errList = append(errList, o.SPDOptions.ApplyTo(c.SPDConfig))
errList = append(errList, o.LifeCycleOptions.ApplyTo(c.LifeCycleConfig))
errList = append(errList, o.CNROptions.ApplyTo(c.CNRConfig))
return errors.NewAggregate(errList)
}

Expand Down
11 changes: 6 additions & 5 deletions pkg/agent/qrm-plugins/advisorsvc/advisor_svc.pb.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,19 @@ package advisorsvc
import (
context "context"
fmt "fmt"
io "io"
math "math"
math_bits "math/bits"
reflect "reflect"
strings "strings"

_ "github.com/gogo/protobuf/gogoproto"
proto "github.com/gogo/protobuf/proto"
github_com_gogo_protobuf_sortkeys "github.com/gogo/protobuf/sortkeys"
grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"
io "io"
v1alpha1 "k8s.io/kubelet/pkg/apis/resourceplugin/v1alpha1"
math "math"
math_bits "math/bits"
reflect "reflect"
strings "strings"
)

// Reference imports to suppress errors if they are not otherwise used.
Expand Down
14 changes: 8 additions & 6 deletions pkg/agent/qrm-plugins/cpu/dynamicpolicy/cpuadvisor/cpu.pb.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,21 @@ package cpuadvisor
import (
context "context"
fmt "fmt"
io "io"
math "math"
math_bits "math/bits"
reflect "reflect"
strings "strings"

_ "github.com/gogo/protobuf/gogoproto"
proto "github.com/gogo/protobuf/proto"
github_com_gogo_protobuf_sortkeys "github.com/gogo/protobuf/sortkeys"
advisorsvc "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/advisorsvc"
grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"
io "io"
_ "k8s.io/kubelet/pkg/apis/resourceplugin/v1alpha1"
math "math"
math_bits "math/bits"
reflect "reflect"
strings "strings"

advisorsvc "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/advisorsvc"
)

// Reference imports to suppress errors if they are not otherwise used.
Expand Down

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

26 changes: 26 additions & 0 deletions pkg/config/controller/cnr.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
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

type CNRConfig struct {
// EnableCNR is a flag to enable CNR controller
EnableCNR bool
}

func NewCNRConfig() *CNRConfig {
return &CNRConfig{}
}
2 changes: 2 additions & 0 deletions pkg/config/controller/controller_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type ControllersConfiguration struct {
*KCCConfig
*SPDConfig
*LifeCycleConfig
*CNRConfig
}

func NewGenericControllerConfiguration() *GenericControllerConfiguration {
Expand All @@ -58,5 +59,6 @@ func NewControllersConfiguration() *ControllersConfiguration {
KCCConfig: NewKCCConfig(),
SPDConfig: NewSPDConfig(),
LifeCycleConfig: NewLifeCycleConfig(),
CNRConfig: NewCNRConfig(),
}
}
Loading

0 comments on commit 2923fcf

Please sign in to comment.