kong-pongo icon indicating copy to clipboard operation
kong-pongo copied to clipboard

Incorrect KONG_PG_HOST resolution

Open Apxdono opened this issue 3 years ago • 3 comments

Issue When developing plugins using kong-pongo and cloning even a https://github.com/Kong/kong-plugin.git it's impossible to run tests with pongo run in Linux systems (details below). Run command simply fails with:

[----------] Running tests from /kong-plugin/spec/myplugin/02-integration_spec.lua
./spec/helpers.lua:194: [PostgreSQL error] failed to retrieve PostgreSQL server_version_num: host or service not provided, or not known

above error fails on db connector initiation

Root cause In docker-compose.yml kong is starting with KONG_PG_HOST=${SERVICE_NETWORK_NAME}_postgres_1.${SERVICE_NETWORK_NAME}, which relies on SERVICE_NETWORK_NAME. Unfortunately this way of building PG hostname seems to be inconsistent and postgres image that is started has different network aliases (on my PC):

## From docker inspect <postgres container>
"Networks": {
                "pongo-b4a16ef9": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": [
                        "pongo-b4a16ef9-postgres-1",
                        "postgres",
                        "4e04f8f1cb22"
                    ],
                    "NetworkID": "7cf615e6a60c43ca2f5d736a89a66cfe3224788495afd9ac6ee4c7feaf85d6c4",
                    "EndpointID": "521cb698afbb52fba452668a5afd5d97cc379c7a8a523af3c400a9666742c932",
                    "Gateway": "172.19.0.1",
                    "IPAddress": "172.19.0.2",
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "02:42:ac:13:00:02",
                    "DriverOpts": null
                }
            }

As you can see usual compose things like _1.networkname sometimes do not apply, which result in slightly different hostname of PG container.

Proposed fix The easiest of the bunch is setting an env variable, which would force an alias for PG container and KONG_PG_HOST env variable, removing the issue altogether. Default value can be still calculated (if no env variable was passed) by pongo executable before actual docker-compose runs.

System info

OS: Arch Linux x86_64 
Kernel: 5.16.9-arch1-1 
Shell: bash 5.1.16 
DE: Plasma 5.24.1 
WM: KWin 
Terminal: yakuake 
Docker version: 20.10.12, build e91ed5707e

If any extra info is required, just ask me to add it

Apxdono avatar Feb 17 '22 17:02 Apxdono

thx for the report. Mind sending a PR for the proposed fix?

Tieske avatar Feb 17 '22 20:02 Tieske

Sure, I'll make one on this weekend.

Apxdono avatar Feb 18 '22 00:02 Apxdono

@Tieske I've filed a PR #260 with proposed fix (and a small extra enhancement).

I noticed similar issue with Cassandra (and fixed it as well in PR).

I assume similar issue might happen with other containers listed in compose, like Redis for instance. Didn't have a chance to test it thus I can only speculate at this point.

Apxdono avatar Feb 19 '22 20:02 Apxdono

pr was merged long ago. closing this.

Tieske avatar Feb 07 '24 12:02 Tieske