Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PostgreSQL scaler uses username instead of port number in 2.5.0 #2430

Closed
tsndqst opened this issue Jan 2, 2022 · 3 comments · Fixed by #2432
Closed

PostgreSQL scaler uses username instead of port number in 2.5.0 #2430

tsndqst opened this issue Jan 2, 2022 · 3 comments · Fixed by #2432
Labels
bug Something isn't working

Comments

@tsndqst
Copy link
Contributor

tsndqst commented Jan 2, 2022

Report

The postgreSQL_scaler fails to start up with an error similar to the following:

error establishing postgreSQL connection: dial tcp: address tcp/username: unknown port

#2114 broke the Postgresql scaler. The userName argument overwrites the port argument.

Compare the GetFromAuthOrMeta calls for port and userName. They both set meta.port so it ends up being set to userName not `port.

meta.port, err = GetFromAuthOrMeta(config, "port")
with
meta.port, err = GetFromAuthOrMeta(config, "userName")

Expected Behavior

The Postgresql port number is not overwritten by the username value.

Actual Behavior

The username attribute is used in place of the port number. The username value isn't set at all.

Steps to Reproduce the Problem

  1. Create a postgresql scaler using a connection configuration similar to the one in the documentation https://keda.sh/docs/2.5/scalers/postgresql/#trigger-specification
  2. Watch the operator logs when the scaler stats up. Notice that the scaler attempts to use the username as the port number when connecting to the DB.

Logs from KEDA operator

2022-01-02T20:08:10.467Z        ERROR   scalehandler    error resolving auth params     {"scalerIndex": 0, "object": {"apiVersion": "keda.sh/v1alpha1", "kind": "ScaledObject", "namespace": "default", "name": "pg-scaler"}, "trigger": 0, "error": "error establishing postgreSQL connection: dial tcp: address tcp/username: unknown port"}
github.com/kedacore/keda/v2/controllers/keda.(*ScaledObjectReconciler).getScaledObjectMetricSpecs
        /workspace/controllers/keda/hpa.go:163
github.com/kedacore/keda/v2/controllers/keda.(*ScaledObjectReconciler).newHPAForScaledObject
        /workspace/controllers/keda/hpa.go:63
github.com/kedacore/keda/v2/controllers/keda.(*ScaledObjectReconciler).updateHPAIfNeeded
        /workspace/controllers/keda/hpa.go:124
github.com/kedacore/keda/v2/controllers/keda.(*ScaledObjectReconciler).ensureHPAForScaledObjectExists
        /workspace/controllers/keda/scaledobject_controller.go:376
github.com/kedacore/keda/v2/controllers/keda.(*ScaledObjectReconciler).reconcileScaledObject
        /workspace/controllers/keda/scaledobject_controller.go:228
github.com/kedacore/keda/v2/controllers/keda.(*ScaledObjectReconciler).Reconcile
        /workspace/controllers/keda/scaledobject_controller.go:179
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Reconcile
        /go/pkg/mod/sigs.k8s.io/controller-runtime@v0.10.3/pkg/internal/controller/controller.go:114
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).reconcileHandler
        /go/pkg/mod/sigs.k8s.io/controller-runtime@v0.10.3/pkg/internal/controller/controller.go:311
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).processNextWorkItem
        /go/pkg/mod/sigs.k8s.io/controller-runtime@v0.10.3/pkg/internal/controller/controller.go:266
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Start.func2.2
        /go/pkg/mod/sigs.k8s.io/controller-runtime@v0.10.3/pkg/internal/controller/controller.go:227

KEDA Version

2.5.0

Kubernetes Version

1.21

Platform

Other

Scaler Details

PostgreSQL

Anything else?

2.4.0 works as expected.

@tsndqst tsndqst added the bug Something isn't working label Jan 2, 2022
@zroubalik
Copy link
Member

@tsndqst good catch, thx. Are you wiling to open a PR with the fix?

@tsndqst
Copy link
Contributor Author

tsndqst commented Jan 3, 2022

@zroubalik I created a PR but I don't know Go data structures well enough to come up with a test.

@zroubalik
Copy link
Member

@tsndqst I think that it is fine, no need to add a test for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants