Skip to content

Commit

Permalink
fix: mysql and postgres modules (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
liu-hm19 authored Apr 25, 2024
1 parent b3935da commit 7c5e7b3
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 13 deletions.
2 changes: 1 addition & 1 deletion modules/mysql/example/dev/main.k
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import kam.v1.app_configuration as ac
import kam.v1.workload as wl
import kam.v1.workload.container as c
import network as n
import mysql.mysql
import mysql.mysql

quickstart: ac.AppConfiguration {
workload: wl.Service {
Expand Down
10 changes: 9 additions & 1 deletion modules/mysql/src/local_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,20 @@ func (mysql *MySQL) generateLocalDeployment(request *module.GeneratorRequest) (*
func (mysql *MySQL) generateLocalPodSpec(_ *module.GeneratorRequest) (v1.PodSpec, error) {
image := dbEngine + ":" + mysql.Version
secretName := mysql.DatabaseName + localSecretSuffix

var portName string
if len(mysql.DatabaseName) > 15 {
portName = mysql.DatabaseName[:15]
} else {
portName = mysql.DatabaseName
}
ports := []v1.ContainerPort{
{
Name: mysql.DatabaseName,
Name: portName,
ContainerPort: int32(3306),
},
}

volumes := []v1.Volume{
{
Name: mysql.DatabaseName,
Expand Down
13 changes: 8 additions & 5 deletions modules/mysql/src/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,31 +110,34 @@ func (mysql *MySQL) Generate(_ context.Context, request *module.GeneratorRequest
// Generate the MySQL intance resources based on the type and the cloud provider config.
var resources []apiv1.Resource
var patchers []apiv1.Patcher
var providerType string
switch strings.ToLower(mysql.Type) {
case LocalDBType:
resources, patchers, err = mysql.GenerateLocalResources(request)
case CloudDBType:
providerType, err := GetCloudProviderType(request.PlatformModuleConfig)
providerType, err = GetCloudProviderType(request.PlatformModuleConfig)
if err != nil {
return nil, err
}

switch strings.ToLower(providerType) {
case "aws":
resources, patchers, err = mysql.GenerateAWSResources(request)
if err != nil {
return nil, err
}
case "alicloud":
resources, patchers, err = mysql.GenerateAlicloudResources(request)
if err != nil {
return nil, err
}
default:
return nil, fmt.Errorf("unsupported cloud provider type: %s", providerType)
}
default:
return nil, fmt.Errorf("unsupported mysql type: %s", mysql.Type)
}

if err != nil {
return nil, err
}

return &module.GeneratorResponse{
Resources: resources,
Patchers: patchers,
Expand Down
10 changes: 9 additions & 1 deletion modules/postgres/src/local_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,20 @@ func (postgres *PostgreSQL) generateLocalDeployment(request *module.GeneratorReq
func (postgres *PostgreSQL) generateLocalPodSpec(_ *module.GeneratorRequest) (v1.PodSpec, error) {
image := dbEngine + ":" + postgres.Version
secretName := postgres.DatabaseName + localSecretSuffix

var portName string
if len(postgres.DatabaseName) > 15 {
portName = postgres.DatabaseName[:15]
} else {
portName = postgres.DatabaseName
}
ports := []v1.ContainerPort{
{
Name: postgres.DatabaseName,
Name: portName,
ContainerPort: int32(5432),
},
}

volumes := []v1.Volume{
{
Name: postgres.DatabaseName,
Expand Down
13 changes: 8 additions & 5 deletions modules/postgres/src/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,31 +112,34 @@ func (postgres *PostgreSQL) Generate(_ context.Context, request *module.Generato
// Generate the PostgreSQL intance resources based on the type and the cloud provider config.
var resources []apiv1.Resource
var patchers []apiv1.Patcher
var providerType string
switch strings.ToLower(postgres.Type) {
case LocalDBType:
resources, patchers, err = postgres.GenerateLocalResources(request)
case CloudDBType:
providerType, err := GetCloudProviderType(request.PlatformModuleConfig)
providerType, err = GetCloudProviderType(request.PlatformModuleConfig)
if err != nil {
return nil, err
}

switch strings.ToLower(providerType) {
case "aws":
resources, patchers, err = postgres.GenerateAWSResources(request)
if err != nil {
return nil, err
}
case "alicloud":
resources, patchers, err = postgres.GenerateAlicloudResources(request)
if err != nil {
return nil, err
}
default:
return nil, fmt.Errorf("unsupported cloud provider type: %s", providerType)
}
default:
return nil, fmt.Errorf("unsupported postgres type: %s", postgres.Type)
}

if err != nil {
return nil, err
}

return &module.GeneratorResponse{
Resources: resources,
Patchers: patchers,
Expand Down

0 comments on commit 7c5e7b3

Please sign in to comment.