Skip to content

Commit 29d4745

Browse files
authored
Merge pull request #651 from luomingmeng/dev/spd-add-enable-namespaces-config
spd fetcher add config for enable service profile namespaces
2 parents c6f9ea9 + acb9724 commit 29d4745

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

cmd/katalyst-agent/app/options/metaserver/metaserver.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ type MetaServerOptions struct {
7373
ConfigCheckpointGraceTime time.Duration
7474

7575
// configurations for spd
76+
ServiceProfileEnableNamespaces []string
7677
ServiceProfileSkipCorruptionError bool
7778
ServiceProfileCacheTTL time.Duration
7879
SPDGetFromRemote bool
@@ -104,6 +105,7 @@ func NewMetaServerOptions() *MetaServerOptions {
104105
ConfigSkipFailedInitialization: defaultConfigSkipFailedInitialization,
105106
ConfigCheckpointGraceTime: defaultConfigCheckpointGraceTime,
106107

108+
ServiceProfileEnableNamespaces: []string{"*"},
107109
ServiceProfileSkipCorruptionError: defaultServiceProfileSkipCorruptionError,
108110
ServiceProfileCacheTTL: defaultServiceProfileCacheTTL,
109111
SPDGetFromRemote: defaultSPDGetFromRemote,
@@ -132,6 +134,8 @@ func (o *MetaServerOptions) AddFlags(fss *cliflag.NamedFlagSets) {
132134
fs.BoolVar(&o.EnableCNCFetcher, "enable-cnc-fetcher", o.EnableCNCFetcher,
133135
"Whether to enable cnc fetcher")
134136

137+
fs.StringSliceVar(&o.ServiceProfileEnableNamespaces, "service-profile-enable-namespaces", o.ServiceProfileEnableNamespaces,
138+
"Comma-separated list of namespaces where service profiles are enabled, default is all namespaces")
135139
fs.DurationVar(&o.ConfigCacheTTL, "config-cache-ttl", o.ConfigCacheTTL,
136140
"The ttl of katalyst custom config loader cache remote config")
137141
fs.BoolVar(&o.ConfigDisableDynamic, "config-disable-dynamic", o.ConfigDisableDynamic,
@@ -176,6 +180,7 @@ func (o *MetaServerOptions) ApplyTo(c *metaserver.MetaServerConfiguration) error
176180
c.ConfigSkipFailedInitialization = o.ConfigSkipFailedInitialization
177181
c.ConfigCheckpointGraceTime = o.ConfigCheckpointGraceTime
178182

183+
c.ServiceProfileEnableNamespaces = o.ServiceProfileEnableNamespaces
179184
c.ServiceProfileSkipCorruptionError = o.ServiceProfileSkipCorruptionError
180185
c.ServiceProfileCacheTTL = o.ServiceProfileCacheTTL
181186
c.SPDGetFromRemote = o.SPDGetFromRemote

pkg/config/agent/metaserver/spd.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ type SPDConfiguration struct {
2222
ServiceProfileSkipCorruptionError bool
2323
ServiceProfileCacheTTL time.Duration
2424
SPDGetFromRemote bool
25+
ServiceProfileEnableNamespaces []string
2526
}
2627

2728
func NewSPDConfiguration() *SPDConfiguration {

pkg/metaserver/spd/fetcher.go

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ type spdFetcher struct {
8888
checkpointManager checkpointmanager.CheckpointManager
8989
getPodSPDNameFunc GetPodSPDNameFunc
9090

91+
serviceProfileEnableNamespaces []string
92+
9193
// spdCache is a cache of namespace/name to current target spd
9294
spdCache *Cache
9395
}
@@ -102,12 +104,13 @@ func NewSPDFetcher(clientSet *client.GenericClientSet, emitter metrics.MetricEmi
102104
}
103105

104106
m := &spdFetcher{
105-
started: atomic.NewBool(false),
106-
client: clientSet,
107-
emitter: emitter,
108-
checkpointManager: checkpointManager,
109-
cncFetcher: cncFetcher,
110-
spdGetFromRemote: conf.SPDGetFromRemote,
107+
started: atomic.NewBool(false),
108+
client: clientSet,
109+
emitter: emitter,
110+
checkpointManager: checkpointManager,
111+
cncFetcher: cncFetcher,
112+
spdGetFromRemote: conf.SPDGetFromRemote,
113+
serviceProfileEnableNamespaces: conf.ServiceProfileEnableNamespaces,
111114
}
112115

113116
m.getPodSPDNameFunc = util.GetPodSPDName
@@ -127,7 +130,12 @@ func (s *spdFetcher) GetSPD(ctx context.Context, podMeta metav1.ObjectMeta) (*wo
127130
return nil, errors.NewNotFound(workloadapis.Resource(workloadapis.ResourceNameServiceProfileDescriptors), fmt.Sprintf("for pod(%v/%v)", podMeta.Namespace, podMeta.Name))
128131
}
129132

130-
return s.getSPDByNamespaceName(ctx, podMeta.GetNamespace(), spdName)
133+
spdNamespace := podMeta.GetNamespace()
134+
if !general.IsNameEnabled(spdNamespace, nil, s.serviceProfileEnableNamespaces) {
135+
return nil, errors.NewNotFound(workloadapis.Resource(workloadapis.ResourceNameServiceProfileDescriptors), fmt.Sprintf("for pod(%v/%v)", podMeta.Namespace, podMeta.Name))
136+
}
137+
138+
return s.getSPDByNamespaceName(ctx, spdNamespace, spdName)
131139
}
132140

133141
// SetGetPodSPDNameFunc set get spd name function to override default getPodSPDNameFunc before started

0 commit comments

Comments
 (0)