2
votes

I'm trying to install the Cloud MySQL Proxy on a Dataproc cluster with the initialization-action given as an example here. I removed all the hive-metadata part because I don't need it. The proxy is installed but I can't connect to my instance. The created cloud-sql-proxy.service file looks fine:

> cat /usr/lib/systemd/system/cloud-sql-proxy.service 
[Unit]
Description=Google Cloud SQL Proxy
After=local-fs.target network-online.target
After=google.service
Before=shutdown.target

[Service]
Type=simple
ExecStart=/usr/local/bin/cloud_sql_proxy   -dir=/var/run/cloud_sql_proxy    -instances_metadata=attributes/additional-cloud-sql-instances

[Install]
WantedBy=multi-user.target

Also, if I try to get the value of attributes/additional-cloud-sql-instances it looks fine:

> /usr/share/google/get_metadata_value attributes/additional-cloud-sql-instances
> myproject-12345:europe-west1:my-db-instance=tcp:3333

Yet I can't connect to the instance. When I stop the service and start it again I see an error message:

> /usr/local/bin/cloud_sql_proxy -dir=/var/run/cloud_sql_proxy -instances_metadata=attributes/additional-cloud-sql-instances
2017/07/03 09:23:44 Ready for new connections
2017/07/03 09:23:44 Error on receiving new instances from metadata: metadata: GCE metadata "attributes/additional-cloud-sql-instances" not defined

Am I doing something wrong? In the meantime I can get this to work by using -instances=myproject-12345:europe-west1:my-db-instance=tcp:3333 instead of using the metadata key, but I wonder why it doesn't work as provided in the example.

1

1 Answers

3
votes

There's a subtle difference in how the Cloud SQL proxy interprets flags and how get_metadata_value interprets its input.

When using get_metadata_value, the attribute to read is assumed to be relative to

http://metadata.google.internal/computeMetadata/v1/instance/

while in the case of the Cloud SQL proxy, all paths should be relative to:

http://metadata.google.internal/computeMetadata/v1/

So if you're intention is to have the Cloud SQL proxy read instance metadata, pass in:

-instances_metadata=instance/attributes/additional-cloud-sql-instances