Skip to content

Conversation

@ajcaldera1
Copy link

Description of your changes

This change checks the state of the connection limit for a Postgres role prior to mutating it. The previous behavior would blindly fire the ALTER ROLE CONNECTION LIMIT -1 even if there was no change. Added test to verify connection limit settings were being properly mutated. Corrected a couple of instances of kubectl being referenced in the tests that caused them to fail, replaced with shell variable ${KUBECTL}.

Fixes #194

I have:

  • Read and followed Crossplane's contribution process.
  • Run make reviewable to ensure this PR is ready for review.

How has this code been tested

Added test to e2e suite to verify the connection limit and review Postgres logs to ensure that no statement had been fired when it was unnecessary.

@chlunde
Copy link
Collaborator

chlunde commented May 27, 2025

@ajcaldera1 Awesome, looking forward to this! Could you squash or rebase it, and make sure you've added DCO for your commit? At the moment the button to run CI is not enabled, I suspect it is related to the fact that this contains 24 commits with many merged 😄

@chlunde chlunde self-requested a review May 27, 2025 19:33
dependabot bot and others added 7 commits May 28, 2025 15:30
…trib#232)

Bumps google.golang.org/protobuf from 1.31.0 to 1.33.0.

---
updated-dependencies:
- dependency-name: google.golang.org/protobuf
  dependency-version: 1.33.0
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Signed-off-by: Alan Caldera <30800723+ajcaldera1@users.noreply.github.com>
* fix: enable management policies

Signed-off-by: Jesús Fernández <7312236+fernandezcuesta@users.noreply.github.com>

* fix: linter

Signed-off-by: Jesús Fernández <7312236+fernandezcuesta@users.noreply.github.com>

* chore: offload lint changes to crossplane-contrib#216

Signed-off-by: Jesús Fernández <7312236+fernandezcuesta@users.noreply.github.com>

* chore: revert changes as per peer review

Signed-off-by: Jesús Fernández <7312236+fernandezcuesta@users.noreply.github.com>

---------

Signed-off-by: Jesús Fernández <7312236+fernandezcuesta@users.noreply.github.com>
Signed-off-by: Alan Caldera <30800723+ajcaldera1@users.noreply.github.com>
…#236)

* chore: remove duplicate entry of golangci version

Signed-off-by: Jesús Fernández <7312236+fernandezcuesta@users.noreply.github.com>

* chore: bump up versions for crossplane 1.20

Signed-off-by: Jesús Fernández <7312236+fernandezcuesta@users.noreply.github.com>

* chore: restore changes

Signed-off-by: Jesús Fernández <7312236+fernandezcuesta@users.noreply.github.com>

---------

Signed-off-by: Jesús Fernández <7312236+fernandezcuesta@users.noreply.github.com>
Signed-off-by: Alan Caldera <30800723+ajcaldera1@users.noreply.github.com>
…e before mutating it. This will help cut down the number of ALTER ROLE statements that would otherwise needlessly fire for each role.

Signed-off-by: Alan Caldera <30800723+ajcaldera1@users.noreply.github.com>
…on of kubectl.

Signed-off-by: Alan Caldera <30800723+ajcaldera1@users.noreply.github.com>
Signed-off-by: Alan Caldera <30800723+ajcaldera1@users.noreply.github.com>
Signed-off-by: Alan Caldera <30800723+ajcaldera1@users.noreply.github.com>
Signed-off-by: Alan Caldera <30800723+ajcaldera1@users.noreply.github.com>
Signed-off-by: Alan Caldera <30800723+ajcaldera1@users.noreply.github.com>
Signed-off-by: Alan Caldera <30800723+ajcaldera1@users.noreply.github.com>
}
}

// openDB returns a new database connection
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you do this in a separate PR?

Would rather have many smaller PRs which focus on one feature, thanks!

if cl != nil {
newCl := cr.Spec.ForProvider.ConnectionLimit
currCl := cr.Status.AtProvider.ConnectionLimit
if (newCl != nil && currCl != nil) && (int64(*currCl) != int64(*newCl)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why the three casts to int64? Could we simply drop then?

Comment on lines +411 to +413
newCl := cr.Spec.ForProvider.ConnectionLimit
currCl := cr.Status.AtProvider.ConnectionLimit
if (newCl != nil && currCl != nil) && (int64(*currCl) != int64(*newCl)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

The default here is unlimited, represented as -1?

Could we do this instead, or do you see any issues with this?

Suggested change
newCl := cr.Spec.ForProvider.ConnectionLimit
currCl := cr.Status.AtProvider.ConnectionLimit
if (newCl != nil && currCl != nil) && (int64(*currCl) != int64(*newCl)) {
newCl := ptr.Deref(cr.Spec.ForProvider.ConnectionLimit, -1)
currCl := ptr.Deref(cr.Status.AtProvider.ConnectionLimit, -1)
if currCl != newCl {

Copy link
Collaborator

Choose a reason for hiding this comment

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

Don't you also need this ptr.Deref-ing in

func upToDate(observed *v1alpha1.RoleParameters, desired *v1alpha1.RoleParameters) bool {
	if observed.ConnectionLimit != desired.ConnectionLimit {
		return false
	}

to

func upToDate(observed *v1alpha1.RoleParameters, desired *v1alpha1.RoleParameters) bool {
	if ptr.Deref(observed.ConnectionLimit, -1) != ptr.Deref(desired.ConnectionLimit, -1) {
		return false
	}

Could you add some tests for Observe or upToDate covering this case?

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.

Role provider should examine state of ConnectionLimit before applying

3 participants