Skip to content

Commit

Permalink
Merge pull request #651 from luomingmeng/dev/spd-add-enable-namespace…
Browse files Browse the repository at this point in the history
…s-config

spd fetcher add config for enable service profile namespaces
  • Loading branch information
luomingmeng authored Jul 16, 2024
2 parents c6f9ea9 + acb9724 commit 29d4745
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
5 changes: 5 additions & 0 deletions cmd/katalyst-agent/app/options/metaserver/metaserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ type MetaServerOptions struct {
ConfigCheckpointGraceTime time.Duration

// configurations for spd
ServiceProfileEnableNamespaces []string
ServiceProfileSkipCorruptionError bool
ServiceProfileCacheTTL time.Duration
SPDGetFromRemote bool
Expand Down Expand Up @@ -104,6 +105,7 @@ func NewMetaServerOptions() *MetaServerOptions {
ConfigSkipFailedInitialization: defaultConfigSkipFailedInitialization,
ConfigCheckpointGraceTime: defaultConfigCheckpointGraceTime,

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

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

c.ServiceProfileEnableNamespaces = o.ServiceProfileEnableNamespaces
c.ServiceProfileSkipCorruptionError = o.ServiceProfileSkipCorruptionError
c.ServiceProfileCacheTTL = o.ServiceProfileCacheTTL
c.SPDGetFromRemote = o.SPDGetFromRemote
Expand Down
1 change: 1 addition & 0 deletions pkg/config/agent/metaserver/spd.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type SPDConfiguration struct {
ServiceProfileSkipCorruptionError bool
ServiceProfileCacheTTL time.Duration
SPDGetFromRemote bool
ServiceProfileEnableNamespaces []string
}

func NewSPDConfiguration() *SPDConfiguration {
Expand Down
22 changes: 15 additions & 7 deletions pkg/metaserver/spd/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ type spdFetcher struct {
checkpointManager checkpointmanager.CheckpointManager
getPodSPDNameFunc GetPodSPDNameFunc

serviceProfileEnableNamespaces []string

// spdCache is a cache of namespace/name to current target spd
spdCache *Cache
}
Expand All @@ -102,12 +104,13 @@ func NewSPDFetcher(clientSet *client.GenericClientSet, emitter metrics.MetricEmi
}

m := &spdFetcher{
started: atomic.NewBool(false),
client: clientSet,
emitter: emitter,
checkpointManager: checkpointManager,
cncFetcher: cncFetcher,
spdGetFromRemote: conf.SPDGetFromRemote,
started: atomic.NewBool(false),
client: clientSet,
emitter: emitter,
checkpointManager: checkpointManager,
cncFetcher: cncFetcher,
spdGetFromRemote: conf.SPDGetFromRemote,
serviceProfileEnableNamespaces: conf.ServiceProfileEnableNamespaces,
}

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

return s.getSPDByNamespaceName(ctx, podMeta.GetNamespace(), spdName)
spdNamespace := podMeta.GetNamespace()
if !general.IsNameEnabled(spdNamespace, nil, s.serviceProfileEnableNamespaces) {
return nil, errors.NewNotFound(workloadapis.Resource(workloadapis.ResourceNameServiceProfileDescriptors), fmt.Sprintf("for pod(%v/%v)", podMeta.Namespace, podMeta.Name))
}

return s.getSPDByNamespaceName(ctx, spdNamespace, spdName)
}

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

0 comments on commit 29d4745

Please sign in to comment.