chore: add pprof server to operator and sidecar

We add the pprof server to the operator and the sidecar, to avoid any
conflict with the CloudNativePG operator and clusters we use the port
6061

Closes #421

Signed-off-by: Jonathan Gonzalez V. <jonathan.gonzalez@enterprisedb.com>
This commit is contained in:
Jonathan Gonzalez V. 2025-06-24 12:42:21 +02:00
parent a225902a36
commit b7b62f1cb4
No known key found for this signature in database
GPG Key ID: 43CDEF0A73A51CC5
7 changed files with 18 additions and 1 deletions

View File

@ -40,6 +40,7 @@ func NewCmd() *cobra.Command {
_ = viper.BindEnv("spool-directory", "SPOOL_DIRECTORY") _ = viper.BindEnv("spool-directory", "SPOOL_DIRECTORY")
_ = viper.BindEnv("custom-cnpg-group", "CUSTOM_CNPG_GROUP") _ = viper.BindEnv("custom-cnpg-group", "CUSTOM_CNPG_GROUP")
_ = viper.BindEnv("custom-cnpg-version", "CUSTOM_CNPG_VERSIONXS") _ = viper.BindEnv("custom-cnpg-version", "CUSTOM_CNPG_VERSIONXS")
_ = viper.BindEnv("pprof-server", "PLUGIN_PPROF_SERVER")
return cmd return cmd
} }

View File

@ -84,5 +84,7 @@ func NewCmd() *cobra.Command {
_ = viper.BindEnv("sidecar-image", "SIDECAR_IMAGE") _ = viper.BindEnv("sidecar-image", "SIDECAR_IMAGE")
_ = viper.BindEnv("pprof-server", "PPROF_SERVER")
return cmd return cmd
} }

View File

@ -44,6 +44,7 @@ func Start(ctx context.Context) error {
}, },
}, },
}, },
PprofBindAddress: viper.GetString("pprof-server"),
} }
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), controllerOptions) mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), controllerOptions)

View File

@ -332,7 +332,13 @@ func reconcilePodSpec(
} }
sidecarTemplate.RestartPolicy = ptr.To(corev1.ContainerRestartPolicyAlways) sidecarTemplate.RestartPolicy = ptr.To(corev1.ContainerRestartPolicyAlways)
sidecarTemplate.Resources = config.resources sidecarTemplate.Resources = config.resources
sidecarTemplate.Ports = []corev1.ContainerPort{
{
Name: "pprof",
ContainerPort: 6061,
Protocol: corev1.ProtocolTCP,
},
}
// merge the main container envs if they aren't already set // merge the main container envs if they aren't already set
for _, container := range spec.Containers { for _, container := range spec.Containers {
if container.Name == mainContainerName { if container.Name == mainContainerName {

View File

@ -104,6 +104,7 @@ func Start(ctx context.Context) error {
Metrics: metricsServerOptions, Metrics: metricsServerOptions,
WebhookServer: webhookServer, WebhookServer: webhookServer,
HealthProbeBindAddress: viper.GetString("health-probe-bind-address"), HealthProbeBindAddress: viper.GetString("health-probe-bind-address"),
PprofBindAddress: viper.GetString("pprof-server"),
LeaderElection: viper.GetBool("leader-elect"), LeaderElection: viper.GetBool("leader-elect"),
LeaderElectionID: "822e3f5c.cnpg.io", LeaderElectionID: "822e3f5c.cnpg.io",
// LeaderElectionReleaseOnCancel defines if the leader should step down voluntarily // LeaderElectionReleaseOnCancel defines if the leader should step down voluntarily

View File

@ -27,6 +27,9 @@ spec:
ports: ports:
- containerPort: 9090 - containerPort: 9090
protocol: TCP protocol: TCP
- containerPort: 6060
protocol: TCP
name: "pprof"
env: env:
- name: SIDECAR_IMAGE - name: SIDECAR_IMAGE
valueFrom: valueFrom:

View File

@ -932,6 +932,9 @@ spec:
ports: ports:
- containerPort: 9090 - containerPort: 9090
protocol: TCP protocol: TCP
- containerPort: 6060
name: pprof
protocol: TCP
readinessProbe: readinessProbe:
initialDelaySeconds: 10 initialDelaySeconds: 10
periodSeconds: 10 periodSeconds: 10