Skip to content

Conversation

benjaminjb
Copy link
Contributor

This PR adds validation for v1 pgBouncer so that the logfile must either be in /tmp or one of the attached additional volumes.

This PR also adds validation for v1beta1 that restricts the number of global config settings and requires a '.log' suffix on the logfile. (This may be reverted in the future as we are learning towards validation in v1 and documentation in v1beta1.)

This PR also fixes an error in the OTEL setup around a custom logfile.

Checklist:

  • Have you added an explanation of what your changes do and why you'd like them to be included?
  • Have you updated or added documentation for the change, as applicable?
  • Have you tested your changes on all related environments with successful results, as applicable?
    • Have you added automated tests?

Type of Changes:

  • New feature
  • Bug fix
  • Documentation
  • Testing enhancement
  • Other

What is the current behavior (link to any open issues here)?

What is the new behavior (if this is a feature change)?

  • Breaking change (fix or feature that would cause existing functionality to change)

BREAKING: A cluster with more than 50 configs on pgbouncer or a logfile that didn't end in .log would be rejected by the API now.

Other Information:
Issues: [PGO-2565]

collector.AddToPod(ctx, inCluster.Spec.Instrumentation, inCluster.Spec.ImagePullPolicy, inConfigMap,
template, []corev1.VolumeMount{configVolumeMount}, string(inSecret.Data["pgbouncer-password"]),
[]string{naming.PGBouncerLogPath}, true, true)
[]string{logPath}, true, true)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missed this in an earlier PR re: OTEL handling user-set logfiles.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch.

Comment on lines +31 to +32
// +kubebuilder:validation:XValidation:rule=`!has(self.logfile) || self.logfile.endsWith('.log')`,message=`logfile config must end with '.log'`
// +kubebuilder:validation:MaxProperties=50
Copy link
Contributor Author

@benjaminjb benjaminjb Sep 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do we feel about adding these two validations/exclusions here to v1beta1?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻 These new rules/criteria seem fine to me.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed 👍

Comment on lines +145 to +148
assert.NilError(t, features.SetFromMap(map[string]bool{
feature.OpenTelemetryLogs: true,
feature.OpenTelemetryMetrics: true,
}))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 to setting it here since nothing happens until instrumentation is in the spec

Comment on lines +31 to +32
// +kubebuilder:validation:XValidation:rule=`!has(self.logfile) || self.logfile.endsWith('.log')`,message=`logfile config must end with '.log'`
// +kubebuilder:validation:MaxProperties=50
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻 These new rules/criteria seem fine to me.

benjaminjb and others added 4 commits September 11, 2025 16:54
This PR adds validation for v1 pgBouncer so that the logfile
must either be in /tmp or one of the attached additional volumes.

This PR also adds validation for v1beta1 that restricts the number
of global config settings and requires a '.log' suffix on the
logfile. (This may be reverted in the future as we are learning
towards validation in v1 and documentation in v1beta1.)

This PR also fixes an error in the OTEL setup around a custom
logfile.

Issues: [PGO-2565]
k8s 1.28 cannot handle the .? validation we wanted to use
in CEL, so this PR uses a less complex version.
5.8+ has k8s 1.30 for its floor; OCP is 4.14 (k8s 1.27)
but 4.16 (k8s 1.29) works with this CEL.
…ypes.go

Co-authored-by: Chris Bandy <bandy.chris@gmail.com>
@benjaminjb benjaminjb force-pushed the benjb/pgbouncer-log-validation branch from 2c08ff5 to 746c906 Compare September 11, 2025 21:55
Copy link
Contributor

@dsessler7 dsessler7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

// More info: https://www.pgbouncer.org/config.html
// ---
// # Logging
// +kubebuilder:validation:XValidation:rule=`!has(self.logfile) || self.logfile.endsWith('.log')`,message=`logfile config must end with '.log'`
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// +kubebuilder:validation:XValidation:rule=`!has(self.logfile) || self.logfile.endsWith('.log')`,message=`logfile config must end with '.log'`
// +kubebuilder:validation:XValidation:rule=`self.?logfile.endsWith('.log')orValue(true)`,message=`logfile config must end with '.log'`

Is something like this more legible?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, that doesn't work:

compilation failed: ERROR: <input>:1:23: found no matching overload for 'endsWith' applied to 'optional_type(string).(string)'")

But this works:

self.?logfile.orValue("").endsWith('.log')

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

meh, for just one step, I'll do without the "?"

@benjaminjb benjaminjb merged commit 743dc39 into CrunchyData:main Sep 15, 2025
19 checks passed
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.

3 participants