mirror of
https://github.com/coreos/prometheus-operator.git
synced 2026-02-05 06:45:27 +01:00
Merge pull request #5993 from simonpasquier/optimize-metadata-informers
feat: optimize memory usage of secret/configmap informers
This commit is contained in:
3
bundle.yaml
generated
3
bundle.yaml
generated
@@ -42082,6 +42082,9 @@ spec:
|
||||
- args:
|
||||
- --kubelet-service=kube-system/kubelet
|
||||
- --prometheus-config-reloader=quay.io/prometheus-operator/prometheus-config-reloader:v0.69.1
|
||||
env:
|
||||
- name: GOGC
|
||||
value: "30"
|
||||
image: quay.io/prometheus-operator/prometheus-operator:v0.69.1
|
||||
name: prometheus-operator
|
||||
ports:
|
||||
|
||||
@@ -27,6 +27,9 @@ spec:
|
||||
- args:
|
||||
- --kubelet-service=kube-system/kubelet
|
||||
- --prometheus-config-reloader=quay.io/prometheus-operator/prometheus-config-reloader:v0.69.1
|
||||
env:
|
||||
- name: GOGC
|
||||
value: "30"
|
||||
image: quay.io/prometheus-operator/prometheus-operator:v0.69.1
|
||||
name: prometheus-operator
|
||||
ports:
|
||||
|
||||
@@ -10,6 +10,7 @@ local defaults = {
|
||||
requests: { cpu: '', memory: '' },
|
||||
},
|
||||
enableReloaderProbes: false,
|
||||
goGC: '30',
|
||||
port: 8080,
|
||||
resources: {
|
||||
limits: { cpu: '200m', memory: '200Mi' },
|
||||
@@ -168,6 +169,7 @@ function(params) {
|
||||
name: 'http',
|
||||
}],
|
||||
resources: po.config.resources,
|
||||
env: [{ name: 'GOGC', value: po.config.goGC }],
|
||||
securityContext: {
|
||||
allowPrivilegeEscalation: false,
|
||||
readOnlyRootFilesystem: true,
|
||||
|
||||
@@ -221,7 +221,7 @@ func (c *Operator) bootstrap(ctx context.Context) error {
|
||||
return fmt.Errorf("can not parse secrets selector value: %w", err)
|
||||
}
|
||||
|
||||
c.secrInfs, err = informers.NewInformersForResource(
|
||||
c.secrInfs, err = informers.NewInformersForResourceWithTransform(
|
||||
informers.NewMetadataInformerFactory(
|
||||
c.config.Namespaces.AlertmanagerConfigAllowList,
|
||||
c.config.Namespaces.DenyList,
|
||||
@@ -232,6 +232,7 @@ func (c *Operator) bootstrap(ctx context.Context) error {
|
||||
},
|
||||
),
|
||||
v1.SchemeGroupVersion.WithResource("secrets"),
|
||||
informers.PartialObjectMetadataStrip,
|
||||
)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error creating secret informers: %w", err)
|
||||
|
||||
@@ -56,6 +56,10 @@ type ForResource struct {
|
||||
// It takes a namespace aware informer factory, wrapped in a FactoriesForNamespaces interface
|
||||
// that is able to instantiate an informer for a given namespace.
|
||||
func NewInformersForResource(ifs FactoriesForNamespaces, resource schema.GroupVersionResource) (*ForResource, error) {
|
||||
return NewInformersForResourceWithTransform(ifs, resource, nil)
|
||||
}
|
||||
|
||||
func NewInformersForResourceWithTransform(ifs FactoriesForNamespaces, resource schema.GroupVersionResource, handler cache.TransformFunc) (*ForResource, error) {
|
||||
namespaces := ifs.Namespaces().UnsortedList()
|
||||
sort.Strings(namespaces)
|
||||
|
||||
@@ -66,6 +70,11 @@ func NewInformersForResource(ifs FactoriesForNamespaces, resource schema.GroupVe
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error getting informer in namespace %q for resource %v: %w", ns, resource, err)
|
||||
}
|
||||
if handler != nil {
|
||||
if err := informer.Informer().SetTransform(handler); err != nil {
|
||||
return nil, fmt.Errorf("error setting transform in namespace %q for resource %v: %w", ns, resource, err)
|
||||
}
|
||||
}
|
||||
informers = append(informers, informer)
|
||||
}
|
||||
|
||||
@@ -74,6 +83,27 @@ func NewInformersForResource(ifs FactoriesForNamespaces, resource schema.GroupVe
|
||||
}, nil
|
||||
}
|
||||
|
||||
// PartialObjectMetadataStrip removes the following fields from PartialObjectMetadata objects:
|
||||
// * Annotations
|
||||
// * Labels
|
||||
// * ManagedFields
|
||||
// * Finalizers
|
||||
// * OwnerReferences
|
||||
func PartialObjectMetadataStrip(obj interface{}) (interface{}, error) {
|
||||
partialMeta, ok := obj.(*v1.PartialObjectMetadata)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("internal error: cannot cast object %#+v to PartialObjectMetadata", obj)
|
||||
}
|
||||
|
||||
partialMeta.Annotations = nil
|
||||
partialMeta.Labels = nil
|
||||
partialMeta.ManagedFields = nil
|
||||
partialMeta.Finalizers = nil
|
||||
partialMeta.OwnerReferences = nil
|
||||
|
||||
return partialMeta, nil
|
||||
}
|
||||
|
||||
// Start starts all underlying informers, passing the given stop channel to each of them.
|
||||
func (w *ForResource) Start(stopCh <-chan struct{}) {
|
||||
for _, i := range w.informers {
|
||||
|
||||
@@ -220,7 +220,7 @@ func New(ctx context.Context, restConfig *rest.Config, conf operator.Config, log
|
||||
}
|
||||
}
|
||||
|
||||
c.cmapInfs, err = informers.NewInformersForResource(
|
||||
c.cmapInfs, err = informers.NewInformersForResourceWithTransform(
|
||||
informers.NewMetadataInformerFactory(
|
||||
c.config.Namespaces.PrometheusAllowList,
|
||||
c.config.Namespaces.DenyList,
|
||||
@@ -231,12 +231,13 @@ func New(ctx context.Context, restConfig *rest.Config, conf operator.Config, log
|
||||
},
|
||||
),
|
||||
v1.SchemeGroupVersion.WithResource(string(v1.ResourceConfigMaps)),
|
||||
informers.PartialObjectMetadataStrip,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error creating configmap informers: %w", err)
|
||||
}
|
||||
|
||||
c.secrInfs, err = informers.NewInformersForResource(
|
||||
c.secrInfs, err = informers.NewInformersForResourceWithTransform(
|
||||
informers.NewMetadataInformerFactory(
|
||||
c.config.Namespaces.PrometheusAllowList,
|
||||
c.config.Namespaces.DenyList,
|
||||
@@ -247,6 +248,7 @@ func New(ctx context.Context, restConfig *rest.Config, conf operator.Config, log
|
||||
},
|
||||
),
|
||||
v1.SchemeGroupVersion.WithResource(string(v1.ResourceSecrets)),
|
||||
informers.PartialObjectMetadataStrip,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error creating secrets informers: %w", err)
|
||||
|
||||
@@ -58,6 +58,7 @@ type Operator struct {
|
||||
kclient kubernetes.Interface
|
||||
mdClient metadata.Interface
|
||||
mclient monitoringclient.Interface
|
||||
|
||||
logger log.Logger
|
||||
accessor *operator.Accessor
|
||||
|
||||
@@ -272,7 +273,7 @@ func New(ctx context.Context, restConfig *rest.Config, conf operator.Config, log
|
||||
return nil, fmt.Errorf("error creating prometheusrule informers: %w", err)
|
||||
}
|
||||
|
||||
c.cmapInfs, err = informers.NewInformersForResource(
|
||||
c.cmapInfs, err = informers.NewInformersForResourceWithTransform(
|
||||
informers.NewMetadataInformerFactory(
|
||||
c.config.Namespaces.PrometheusAllowList,
|
||||
c.config.Namespaces.DenyList,
|
||||
@@ -283,12 +284,13 @@ func New(ctx context.Context, restConfig *rest.Config, conf operator.Config, log
|
||||
},
|
||||
),
|
||||
v1.SchemeGroupVersion.WithResource(string(v1.ResourceConfigMaps)),
|
||||
informers.PartialObjectMetadataStrip,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error creating configmap informers: %w", err)
|
||||
}
|
||||
|
||||
c.secrInfs, err = informers.NewInformersForResource(
|
||||
c.secrInfs, err = informers.NewInformersForResourceWithTransform(
|
||||
informers.NewMetadataInformerFactory(
|
||||
c.config.Namespaces.PrometheusAllowList,
|
||||
c.config.Namespaces.DenyList,
|
||||
@@ -299,6 +301,7 @@ func New(ctx context.Context, restConfig *rest.Config, conf operator.Config, log
|
||||
},
|
||||
),
|
||||
v1.SchemeGroupVersion.WithResource(string(v1.ResourceSecrets)),
|
||||
informers.PartialObjectMetadataStrip,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error creating secrets informers: %w", err)
|
||||
|
||||
Reference in New Issue
Block a user