Skip to content

Commit c9472fc

Browse files
chenxi-seuwaynepeking348
authored andcommitted
fix(agent): fix cnr residue when node deletion
1 parent f95397d commit c9472fc

File tree

4 files changed

+14
-2
lines changed

4 files changed

+14
-2
lines changed

cmd/katalyst-agent/app/options/reporter/reporter_base.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ type GenericReporterOptions struct {
3636
CollectInterval time.Duration
3737
InnerPlugins []string
3838
RefreshLatestCNRPeriod time.Duration
39+
DefaultCNRLabels map[string]string
3940
}
4041

4142
// NewGenericReporterOptions creates a new Options with a default config.
@@ -44,6 +45,7 @@ func NewGenericReporterOptions() *GenericReporterOptions {
4445
InnerPlugins: []string{"*"},
4546
CollectInterval: defaultCollectInterval,
4647
RefreshLatestCNRPeriod: defaultRefreshLatestCNRPeriod,
48+
DefaultCNRLabels: make(map[string]string),
4749
}
4850
}
4951

@@ -59,13 +61,16 @@ func (o *GenericReporterOptions) AddFlags(fss *cliflag.NamedFlagSets) {
5961
fs.StringSliceVar(&o.InnerPlugins, "reporter-plugins", o.InnerPlugins, fmt.Sprintf(""+
6062
"A list of reporter plugins to enable. '*' enables all on-by-default reporter plugins, 'foo' enables the reporter plugin "+
6163
"named 'foo', '-foo' disables the reporter plugin named 'foo'"))
64+
fs.StringToStringVar(&o.DefaultCNRLabels, "default-cnr-labels", o.DefaultCNRLabels,
65+
"the default labels of cnr created by agent, this config must be consistent with the label-selector in katalyst-controller.")
6266
}
6367

6468
// ApplyTo fills up config with options
6569
func (o *GenericReporterOptions) ApplyTo(c *reporterconfig.GenericReporterConfiguration) error {
6670
c.CollectInterval = o.CollectInterval
6771
c.InnerPlugins = o.InnerPlugins
6872
c.RefreshLatestCNRPeriod = o.RefreshLatestCNRPeriod
73+
c.DefaultCNRLabels = o.DefaultCNRLabels
6974
return nil
7075
}
7176

pkg/agent/resourcemanager/reporter/cnr/cnrreporter.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ const (
6161
type cnrReporterImpl struct {
6262
cnrName string
6363

64+
// defaultLabels contains the default config for CNR created by reporter
65+
defaultLabels map[string]string
6466
// latestUpdatedCNR is used as an in-memory cache for CNR;
6567
// whenever CNR info is needed, get from this cache firstly
6668
latestUpdatedCNR *nodev1alpha1.CustomNodeResource
@@ -83,6 +85,7 @@ func NewCNRReporter(genericClient *client.GenericClientSet, metaServer *metaserv
8385
c := &cnrReporterImpl{
8486
cnrName: conf.NodeName,
8587
refreshLatestCNRPeriod: conf.RefreshLatestCNRPeriod,
88+
defaultLabels: conf.DefaultCNRLabels,
8689
notifiers: make(map[string]metaservercnr.CNRNotifier),
8790
emitter: emitter,
8891
client: genericClient.InternalClient,
@@ -337,7 +340,8 @@ func (c *cnrReporterImpl) resetCNRIfNeeded(err error) bool {
337340
func (c *cnrReporterImpl) defaultCNR() *nodev1alpha1.CustomNodeResource {
338341
return &nodev1alpha1.CustomNodeResource{
339342
ObjectMeta: metav1.ObjectMeta{
340-
Name: c.cnrName,
343+
Name: c.cnrName,
344+
Labels: c.defaultLabels,
341345
},
342346
}
343347
}

pkg/config/agent/reporter/reporter_base.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ type GenericReporterConfiguration struct {
3131
InnerPlugins []string
3232

3333
RefreshLatestCNRPeriod time.Duration
34+
35+
// DefaultCNRLabels is the labels for CNR created by reporter
36+
DefaultCNRLabels map[string]string
3437
}
3538

3639
type ReporterPluginsConfiguration struct {

pkg/controller/lifecycle/cnr.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ func (cl *CNRLifecycle) updateOrCreateCNR(node *corev1.Node) error {
320320
}
321321

322322
newCNR := cnr.DeepCopy()
323-
newCNR.Labels = node.Labels
323+
newCNR.Labels = general.MergeMap(newCNR.Labels, node.Labels)
324324
setCNROwnerReference(newCNR, node)
325325
if apiequality.Semantic.DeepEqual(newCNR, cnr) {
326326
return nil

0 commit comments

Comments
 (0)