Skip to content

fix(monitoring): guard against nil pointer in pooler PodMonitor template#841

Open
philippemnoel wants to merge 2 commits intocloudnative-pg:mainfrom
paradedb:fix/pooler-podmonitor-nil-pointer
Open

fix(monitoring): guard against nil pointer in pooler PodMonitor template#841
philippemnoel wants to merge 2 commits intocloudnative-pg:mainfrom
paradedb:fix/pooler-podmonitor-nil-pointer

Conversation

@philippemnoel
Copy link
Contributor

Summary

  • Fixes nil pointer panic in podmonitor-pooler.yaml when a pooler defines monitoring.enabled: true without a podMonitor sub-key
  • Go templates evaluate all arguments to and before calling the function, so .monitoring.podMonitor.enabled is evaluated even when .monitoring.podMonitor is nil, causing a nil pointer panic
  • Replaces the single and check with nested if blocks so .monitoring.podMonitor.enabled is only evaluated when .monitoring.podMonitor is confirmed non-nil

How to reproduce

Define a pooler with monitoring enabled but without a podMonitor key:

poolers:
  - name: rw
    type: rw
    instances: 3
    poolMode: transaction
    parameters:
      max_client_conn: "1000"
      default_pool_size: "25"
    monitoring:
      enabled: true

This produces:

Error: template: cluster/templates/podmonitor-pooler.yaml:3:54: executing "cluster/templates/podmonitor-pooler.yaml" at <.monitoring.podMonitor.enabled>: nil pointer evaluating interface {}.enabled

When a pooler defines `monitoring.enabled: true` without a `podMonitor`
sub-key, the template panics with a nil pointer error because Go
templates evaluate all arguments to `and` before calling the function.

Replace the single `and` chain with nested `if` blocks so that
`.monitoring.podMonitor.enabled` is only evaluated when
`.monitoring.podMonitor` is confirmed to be non-nil.

Signed-off-by: Philippe Noël <philippemnoel@gmail.com>
Without asserting on status.readyInstances, the Chainsaw test can pass
the Cluster assertion before all instances are ready, causing subsequent
steps to fail intermittently.

Signed-off-by: Philippe Noël <philippemnoel@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant