loft-sh / vcluster

vCluster - Create fully functional virtual Kubernetes clusters - Each vcluster runs inside a namespace of the underlying k8s cluster. It's cheaper than creating separate full-blown clusters and it offers better multi-tenancy and isolation than regular namespaces.
https://www.vcluster.com
Apache License 2.0
6.93k stars 428 forks source link

`dbName` with slash doesn't work #2152

Closed lucasfcnunes closed 1 month ago

lucasfcnunes commented 2 months ago

What happened?

Trying to use as dbName in the DSN:

# ...
syncer 2024-09-17 22:51:36    INFO    commandwriter/commandwriter.go:126    Starting k3s v1.30.2+k3s1 (aa4794b3)    {"component": "vcluster", "component": "k3s", "time": "2024-09-17T22:51:36Z", "level": "info"}
syncer 2024-09-17 22:51:36    INFO    commandwriter/commandwriter.go:126    starting kubernetes: preparing server: creating storage endpoint: building kine: invalid DSN: did you forget to escape a param value?    {"component": "vcluster", "component": "k3s", "time": "2024-09-17T22:51:36Z", "level": "fatal"}
syncer 2024-09-17 22:51:36    INFO    setup/initialize.go:165    Error running k3s: exit status 1    {"component": "vcluster"}
# ...
syncer 2024-09-17 23:25:13    INFO    commandwriter/commandwriter.go:126    Starting k3s v1.30.2+k3s1 (aa4794b3)    {"component": "vcluster", "component": "k3s", "time": "2024-09-17T23:25:13Z", "level": "info"}
syncer 2024-09-17 23:25:13    INFO    commandwriter/commandwriter.go:126    failed to check existence of database vcluster%2Fdev, going to attempt create: Error 1049 (HY000): database not found: vcluster%2Fdev    {"component": "vcluster", "component": "k3s", "time": "2024-09-17T23:25:13Z", "level": "warning"}
syncer 2024-09-17 23:25:13    INFO    commandwriter/commandwriter.go:126    starting kubernetes: preparing server: creating storage endpoint: building kine: Error 1105 (HY000): syntax error at position 40 near 'vcluster'    {"component": "vcluster", "component": "k3s", "time": "2024-09-17T23:25:13Z", "level": "fatal"}
syncer 2024-09-17 23:25:13    INFO    setup/initialize.go:165    Error running k3s: exit status 1    {"component": "vcluster"}

What did you expect to happen?

I expected to see Vcluster creating and using the database/schema with a slash in its name.

How can we reproduce it (as minimally and precisely as possible)?

  1. docker run --rm -e MYSQL_ROOT_PASSWORD=root -p 3306:3306 mysql:8.0.33
  2. controlPlane:
    distro:
    k3s:
      enabled: true
    backingStore:
    database:
      external:
        enabled: true
        dataSource: mysql://root:root@tcp(localhost:3306)/vcluster/dev
        # OR
        # dataSource: mysql://root:root@tcp(localhost:3306)/vcluster%2Fdev
  3. Get the error

-- PS: MySQL does support the following DDL:

create database `vcluster/dev`;

Anything else we need to know?

Host cluster Kubernetes version

```console $ kubectl version Client Version: v1.31.0 Kustomize Version: v5.4.2 Server Version: v1.30.3-gke.1639000 ```

vcluster version

```console $ vcluster --version vcluster version 0.20.0 ```

VCluster Config

```yaml controlPlane: distro: k3s: enabled: true backingStore: database: external: enabled: true dataSource: mysql://root:root@tcp(localhost:3306)/vcluster/dev # OR # dataSource: mysql://root:root@tcp(localhost:3306)/vcluster%2Fdev ```
mayooot commented 2 months ago

@lucasfcnunes I spent an afternoon trying to verify this issue, and try to change k3s.go but to no avail.

Finally I noticed that the version of go-sql-driver used by k3s is v1.17, go.mod but theschema/branch mode needs to use v1.8.0.

I tried to submit a pr to k3s to upgrade the go-sql-driver version, after which vcluster should be back to normal.

lucasfcnunes commented 2 months ago

@mayooot, I noticed that operators in dbName weren't being scaped too so https://github.com/k3s-io/kine/pull/322 seems to be needed too.

deniseschannon commented 2 months ago

If those get fixed in k3s, let us know what version it's fixed in and then we can get the latest versions of k3s and kine and we can then update it.

Have you tried using the default vanilla k8s version? Or is there a specific reason why you must run k3s?

FabianKramm commented 1 month ago

@lucasfcnunes seems like we only need to update kine now to make this work. I'll create a PR for this.

lucasfcnunes commented 1 month ago

@FabianKramm it's not completed on MySQL.

lucasfcnunes commented 1 month ago

The next kine release should fix it for MySQL too.

lucasfcnunes commented 1 month ago

Have you tried using the default vanilla k8s version? Or is there a specific reason why you must run k3s?

@deniseschannon I will take some time try the default one. I'm assuming k3s will be faster and use less resources to bootstrap that's why I'm going for it.