Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions cmd/katalyst-agent/app/options/reporter/reporter_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const (
type GenericReporterOptions struct {
CollectInterval time.Duration
InnerPlugins []string
AgentReporters []string
RefreshLatestCNRPeriod time.Duration
DefaultCNRLabels map[string]string
}
Expand All @@ -43,6 +44,7 @@ type GenericReporterOptions struct {
func NewGenericReporterOptions() *GenericReporterOptions {
return &GenericReporterOptions{
InnerPlugins: []string{"*"},
AgentReporters: []string{"*"},
CollectInterval: defaultCollectInterval,
RefreshLatestCNRPeriod: defaultRefreshLatestCNRPeriod,
DefaultCNRLabels: make(map[string]string),
Expand All @@ -61,6 +63,9 @@ func (o *GenericReporterOptions) AddFlags(fss *cliflag.NamedFlagSets) {
fs.StringSliceVar(&o.InnerPlugins, "reporter-plugins", o.InnerPlugins, fmt.Sprintf(""+
"A list of reporter plugins to enable. '*' enables all on-by-default reporter plugins, 'foo' enables the reporter plugin "+
"named 'foo', '-foo' disables the reporter plugin named 'foo'"))
fs.StringSliceVar(&o.AgentReporters, "agent-reporters", o.AgentReporters, fmt.Sprintf(""+
"A list of agent reporters to enable. '*' enables all on-by-default reporters, 'foo' enables the reporter "+
"named 'foo', '-foo' disables the reporter named 'foo'"))
fs.StringToStringVar(&o.DefaultCNRLabels, "default-cnr-labels", o.DefaultCNRLabels,
"the default labels of cnr created by agent, this config must be consistent with the label-selector in katalyst-controller.")
}
Expand All @@ -69,6 +74,7 @@ func (o *GenericReporterOptions) AddFlags(fss *cliflag.NamedFlagSets) {
func (o *GenericReporterOptions) ApplyTo(c *reporterconfig.GenericReporterConfiguration) error {
c.CollectInterval = o.CollectInterval
c.InnerPlugins = o.InnerPlugins
c.AgentReporters = o.AgentReporters
c.RefreshLatestCNRPeriod = o.RefreshLatestCNRPeriod
c.DefaultCNRLabels = o.DefaultCNRLabels
return nil
Expand Down
12 changes: 11 additions & 1 deletion pkg/agent/resourcemanager/reporter/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ import (

v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/errors"
"k8s.io/klog/v2"

"github.com/kubewharf/katalyst-api/pkg/protocol/reporterplugin/v1alpha1"
"github.com/kubewharf/katalyst-core/pkg/client"
"github.com/kubewharf/katalyst-core/pkg/config"
"github.com/kubewharf/katalyst-core/pkg/metaserver"
"github.com/kubewharf/katalyst-core/pkg/metrics"
"github.com/kubewharf/katalyst-core/pkg/util/general"
)

// Manager indicates the way that resources are updated, and it
Expand Down Expand Up @@ -95,7 +97,8 @@ func (r *managerImpl) PushContents(ctx context.Context, responses map[string]*v1
for gvk, fields := range reportFieldsByGVK {
u, ok := r.reporters[gvk]
if !ok || u == nil {
return fmt.Errorf("reporter of gvk %s not found", gvk)
klog.Warningf("reporter of gvk %s not found", gvk)
continue
}

sort.SliceStable(fields, func(i, j int) bool {
Expand Down Expand Up @@ -123,6 +126,13 @@ func (r *managerImpl) getReporter(genericClient *client.GenericClientSet, metaSe
) error {
var errList []error
for gvk, f := range initializers {
if conf != nil && conf.GenericReporterConfiguration != nil {
if !general.IsNameEnabled(gvk.Kind, nil, conf.GenericReporterConfiguration.AgentReporters) {
klog.Infof("reporter %q is disabled", gvk.Kind)
continue
}
}

reporter, err := f(genericClient, metaServer, emitter, conf)
if err != nil {
errList = append(errList, err)
Expand Down
27 changes: 27 additions & 0 deletions pkg/agent/resourcemanager/reporter/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,33 @@ func Test_managerImpl_PushContents(t *testing.T) {
},
wantErr: false,
},
{
name: "test-2",
fields: fields{
conf: generateTestConfiguration(t),
reporters: map[v1.GroupVersionKind]Reporter{},
},
args: args{
ctx: context.TODO(),
responses: map[string]*v1alpha1.GetReportContentResponse{
"agent-2": {
Content: []*v1alpha1.ReportContent{
{
GroupVersionKind: &testGroupVersionKindFirst,
Field: []*v1alpha1.ReportField{
{
FieldType: v1alpha1.FieldType_Spec,
FieldName: "fieldName_b",
Value: []byte("Value_b"),
},
},
},
},
},
},
},
wantErr: false,
},
}
for _, tt := range tests {
tt := tt
Expand Down
3 changes: 3 additions & 0 deletions pkg/config/agent/reporter/reporter_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ type GenericReporterConfiguration struct {
// first item for a particular name wins
InnerPlugins []string

// AgentReporters is the list of agent reporters to enable or disable
AgentReporters []string

RefreshLatestCNRPeriod time.Duration

// DefaultCNRLabels is the labels for CNR created by reporter
Expand Down
Loading