Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: mysql and postgres modules #64

Merged
merged 1 commit into from
Apr 25, 2024
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
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
Loading