Skip to content

Commit

Permalink
fix(internal:controller:postgresql:postgresqlengineconfiguration): Ch…
Browse files Browse the repository at this point in the history
…ange default port for pg bouncer
  • Loading branch information
oxyno-zeta committed Feb 29, 2024
1 parent c60353b commit 463aea1
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import (
const (
PGECRequeueDelayErrorNumberSeconds = 5
DefaultPGPort = 5432
DefaultBouncerPort = 6432
)

// PostgresqlEngineConfigurationReconciler reconciles a PostgresqlEngineConfiguration object.
Expand Down Expand Up @@ -311,7 +312,7 @@ func (*PostgresqlEngineConfigurationReconciler) addDefaultValues(instance *postg
if instance.Spec.UserConnections.BouncerConnection != nil {
// Check port
if instance.Spec.UserConnections.BouncerConnection.Port == 0 {
instance.Spec.UserConnections.BouncerConnection.Port = DefaultPGPort
instance.Spec.UserConnections.BouncerConnection.Port = DefaultBouncerPort
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ var _ = Describe("PostgresqlEngineConfiguration tests", func() {
UserConnections: &postgresqlv1alpha1.UserConnections{
BouncerConnection: &postgresqlv1alpha1.GenericUserConnection{
Host: "localhost",
Port: 5432,
Port: 5433,
URIArgs: "sslmode=disable",
},
},
Expand Down Expand Up @@ -424,7 +424,91 @@ var _ = Describe("PostgresqlEngineConfiguration tests", func() {
Expect(updatedPgec.Spec.UserConnections.PrimaryConnection.Port).To(BeEquivalentTo(5432))
Expect(updatedPgec.Spec.UserConnections.PrimaryConnection.URIArgs).To(BeEquivalentTo("sslmode=disable"))
Expect(updatedPgec.Spec.UserConnections.BouncerConnection.Host).To(BeEquivalentTo("localhost"))
Expect(updatedPgec.Spec.UserConnections.BouncerConnection.Port).To(BeEquivalentTo(5432))
Expect(updatedPgec.Spec.UserConnections.BouncerConnection.Port).To(BeEquivalentTo(5433))
Expect(updatedPgec.Spec.UserConnections.BouncerConnection.URIArgs).To(BeEquivalentTo("sslmode=disable"))
})

It("should be ok to create it with only bouncer user connections without port", func() {
// Create secret
sec := setupPGECSecret()

// Get secret to be sure
Eventually(
func() error {
return k8sClient.Get(ctx, types.NamespacedName{
Name: sec.Name,
Namespace: sec.Namespace,
}, sec)
},
generalEventuallyTimeout,
generalEventuallyInterval,
).
Should(Succeed())

// Create pgec
prov := &postgresqlv1alpha1.PostgresqlEngineConfiguration{
ObjectMeta: v1.ObjectMeta{
Name: pgecName,
Namespace: pgecNamespace,
},
Spec: postgresqlv1alpha1.PostgresqlEngineConfigurationSpec{
Provider: "",
Host: "localhost",
Port: 5432,
URIArgs: "sslmode=disable",
DefaultDatabase: "postgres",
CheckInterval: "30s",
SecretName: pgecSecretName,
UserConnections: &postgresqlv1alpha1.UserConnections{
BouncerConnection: &postgresqlv1alpha1.GenericUserConnection{
Host: "localhost",
URIArgs: "sslmode=disable",
},
},
},
}

// Create pgec
Expect(k8sClient.Create(ctx, prov)).Should(Succeed())

updatedPgec := &postgresqlv1alpha1.PostgresqlEngineConfiguration{}
// Get updated pgec
Eventually(
func() error {
err := k8sClient.Get(ctx, types.NamespacedName{
Name: pgecName,
Namespace: pgecNamespace,
}, updatedPgec)
// Check error
if err != nil {
return err
}

// Check if status hasn't been updated
if updatedPgec.Status.Phase == postgresqlv1alpha1.EngineNoPhase {
return errors.New("pgec hasn't been updated by operator")
}

return nil
},
generalEventuallyTimeout,
generalEventuallyInterval,
).
Should(Succeed())

// Checks
Expect(updatedPgec.Status.Ready).To(BeTrue())
Expect(updatedPgec.Status.Phase).To(BeEquivalentTo(postgresqlv1alpha1.EngineValidatedPhase))
Expect(updatedPgec.Status.LastValidatedTime).NotTo(BeEquivalentTo(""))
Expect(updatedPgec.Status.Message).To(BeEquivalentTo(""))
Expect(updatedPgec.Spec.CheckInterval).To(BeEquivalentTo("30s"))
Expect(updatedPgec.Spec.Port).To(BeEquivalentTo(5432))
Expect(updatedPgec.Spec.DefaultDatabase).To(BeEquivalentTo("postgres"))
Expect(updatedPgec.Spec.UserConnections.PrimaryConnection.Host).To(BeEquivalentTo("localhost"))
Expect(updatedPgec.Spec.UserConnections.PrimaryConnection.Port).To(BeEquivalentTo(5432))
Expect(updatedPgec.Spec.UserConnections.PrimaryConnection.URIArgs).To(BeEquivalentTo("sslmode=disable"))
Expect(updatedPgec.Spec.UserConnections.BouncerConnection.Host).To(BeEquivalentTo("localhost"))
Expect(updatedPgec.Spec.UserConnections.BouncerConnection.Port).To(BeEquivalentTo(6432))
Expect(updatedPgec.Spec.UserConnections.BouncerConnection.URIArgs).To(BeEquivalentTo("sslmode=disable"))
})

Expand Down

0 comments on commit 463aea1

Please sign in to comment.