Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions api/v1alpha1/fields.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
package v1alpha1

type SqlHostEndpoint struct {
// Host of the sql server. This can be either dns or ip
Host string `json:"host,omitempty"`

// Port to use when connecting to the sql server
Port int `json:"port,omitempty"`
}

type SqlCredentials struct {
// Username for the sql user
Username string `json:"username,omitempty"`
Expand Down
5 changes: 1 addition & 4 deletions api/v1alpha1/sqlhost_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ type SqlHostSpec struct {
Engine EngineType `json:"engine"`

// Endpoint to manage
Endpoint SqlHostEndpoint `json:"endpoint"`

// Credentials to use when connecting to the endpoint
Credentials SqlCredentials `json:"credentials"`
DSN string `json:"dsn"`
}

// +kubebuilder:validation:Enum=Mysql
Expand Down
17 changes: 0 additions & 17 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 3 additions & 21 deletions charts/sql-operator/crds/crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -252,34 +252,16 @@ spec:
spec:
description: SqlHostSpec defines the desired state of SqlHost
properties:
credentials:
description: Credentials to use when connecting to the endpoint
properties:
password:
description: Password for the sql user
type: string
username:
description: Username for the sql user
type: string
type: object
endpoint:
dsn:
description: Endpoint to manage
properties:
host:
description: Host of the sql server. This can be either dns or ip
type: string
port:
description: Port to use when connecting to the sql server
type: integer
type: object
type: string
engine:
description: Engine of the external endpoint (like Mysql)
enum:
- Mysql
type: string
required:
- credentials
- endpoint
- dsn
- engine
type: object
status:
Expand Down
24 changes: 3 additions & 21 deletions config/crd/bases/stenic.io_sqlhosts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,34 +32,16 @@ spec:
spec:
description: SqlHostSpec defines the desired state of SqlHost
properties:
credentials:
description: Credentials to use when connecting to the endpoint
properties:
password:
description: Password for the sql user
type: string
username:
description: Username for the sql user
type: string
type: object
endpoint:
dsn:
description: Endpoint to manage
properties:
host:
description: Host of the sql server. This can be either dns or ip
type: string
port:
description: Port to use when connecting to the sql server
type: integer
type: object
type: string
engine:
description: Engine of the external endpoint (like Mysql)
enum:
- Mysql
type: string
required:
- credentials
- endpoint
- dsn
- engine
type: object
status:
Expand Down
7 changes: 1 addition & 6 deletions config/samples/_v1alpha1_sqlhost.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,4 @@ metadata:
name: sqlhost-sample
spec:
engine: Mysql
endpoint:
host: 192.168.23.82
port: 3306
credentials:
username: sqloperator
password: sqloperator
dsn: "sqloperator:sqloperator@tcp(192.168.23.82:3306)/"
9 changes: 1 addition & 8 deletions controllers/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,7 @@ var _ = Describe("Sql-operator", func() {
},
Spec: v1alpha1.SqlHostSpec{
Engine: "Mysql",
Endpoint: steniciov1alpha1.SqlHostEndpoint{
Host: "127.0.0.1",
Port: 3306,
},
Credentials: steniciov1alpha1.SqlCredentials{
Username: "username",
Password: "password",
},
DSN: "username:password@tcp(127.0.0.1:3306)/",
},
}

Expand Down
9 changes: 1 addition & 8 deletions drivers/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,7 @@ type MySqlDriver struct {
}

func (d *MySqlDriver) connect() (*sql.DB, error) {
dsn := fmt.Sprintf(
"%s:%s@tcp(%s:%d)/",
d.Host.Spec.Credentials.Username,
d.Host.Spec.Credentials.Password,
d.Host.Spec.Endpoint.Host,
d.Host.Spec.Endpoint.Port,
)
db, err := sql.Open("mysql", dsn)
db, err := sql.Open("mysql", d.Host.Spec.DSN)
if err == nil {
db.SetConnMaxLifetime(time.Minute * 1)
db.SetMaxIdleConns(0)
Expand Down
7 changes: 1 addition & 6 deletions examples/sqlhost-mysql.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,4 @@ metadata:
name: sample-host
spec:
engine: Mysql
endpoint:
host: test-db-mariadb.sql-operator-testdb
port: 3306
credentials:
username: root
password: n0tS3cur3
dsn: "root:n0tS3cur3@tcp(test-db-mariadb.sql-operator-testdb:3306)/"