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

feat: do not support mysql backend anymore #1100

Merged
merged 1 commit into from
May 7, 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
62 changes: 7 additions & 55 deletions pkg/apis/internal.kusion.io/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,11 +332,6 @@ const (
BackendType = "type"
BackendConfigItems = "configs"
BackendLocalPath = "path"
BackendMysqlDBName = "dbName"
BackendMysqlUser = "user"
BackendMysqlPassword = "password"
BackendMysqlHost = "host"
BackendMysqlPort = "port"
BackendGenericOssEndpoint = "endpoint"
BackendGenericOssAK = "accessKeyID"
BackendGenericOssSK = "accessKeySecret"
Expand All @@ -345,19 +340,15 @@ const (
BackendS3Region = "region"

BackendTypeLocal = "local"
BackendTypeMysql = "mysql"
BackendTypeOss = "oss"
BackendTypeS3 = "s3"

EnvBackendMysqlPassword = "KUSION_BACKEND_MYSQL_PASSWORD"
EnvOssAccessKeyID = "OSS_ACCESS_KEY_ID"
EnvOssAccessKeySecret = "OSS_ACCESS_KEY_SECRET"
EnvAwsAccessKeyID = "AWS_ACCESS_KEY_ID"
EnvAwsSecretAccessKey = "AWS_SECRET_ACCESS_KEY"
EnvAwsDefaultRegion = "AWS_DEFAULT_REGION"
EnvAwsRegion = "AWS_REGION"

DefaultMysqlPort = 3306
EnvOssAccessKeyID = "OSS_ACCESS_KEY_ID"
EnvOssAccessKeySecret = "OSS_ACCESS_KEY_SECRET"
EnvAwsAccessKeyID = "AWS_ACCESS_KEY_ID"
EnvAwsSecretAccessKey = "AWS_SECRET_ACCESS_KEY"
EnvAwsDefaultRegion = "AWS_DEFAULT_REGION"
EnvAwsRegion = "AWS_REGION"
)

// BackendConfigs contains the configuration of multiple backends and the current backend.
Expand All @@ -371,7 +362,7 @@ type BackendConfigs struct {

// BackendConfig contains the type and configs of a backend, which is used to store Spec, State and Workspace.
type BackendConfig struct {
// Type is the backend type, supports BackendTypeLocal, BackendTypeMysql, BackendTypeOss, BackendTypeS3.
// Type is the backend type, supports BackendTypeLocal, BackendTypeOss, BackendTypeS3.
Type string `yaml:"type,omitempty" json:"type,omitempty"`

// Configs contains config items of the backend, whose keys differ from different backend types.
Expand All @@ -385,25 +376,6 @@ type BackendLocalConfig struct {
Path string `yaml:"path,omitempty" json:"path,omitempty"`
}

// BackendMysqlConfig contains the config of using mysql database as backend, which can be converted
// from BackendConfig if Type is BackendMysqlConfig.
type BackendMysqlConfig struct {
// DBName is the database name.
DBName string `yaml:"dbName" json:"dbName"`

// User of the database.
User string `yaml:"user" json:"user"`

// Password of the database.
Password string `yaml:"password,omitempty" json:"password,omitempty"`

// Host of the database.
Host string `yaml:"host" json:"host"`

// Port of the database. If not set, then it will be set to DeprecatedDefaultMysqlPort.
Port int `yaml:"port,omitempty" json:"port,omitempty"`
}

// BackendOssConfig contains the config of using OSS as backend, which can be converted from BackendConfig
// if Type is BackendOssConfig.
type BackendOssConfig struct {
Expand Down Expand Up @@ -450,26 +422,6 @@ func (b *BackendConfig) ToLocalBackend() *BackendLocalConfig {
}
}

// ToMysqlBackend converts BackendConfig to structured BackendMysqlConfig, works only when the Type
// is BackendTypeMysql, and the Configs are with correct type, or return nil.
func (b *BackendConfig) ToMysqlBackend() *BackendMysqlConfig {
if b.Type != BackendTypeMysql {
return nil
}
dbName, _ := b.Configs[BackendMysqlDBName].(string)
user, _ := b.Configs[BackendMysqlUser].(string)
password, _ := b.Configs[BackendMysqlPassword].(string)
host, _ := b.Configs[BackendMysqlHost].(string)
port, _ := b.Configs[BackendMysqlPort].(int)
return &BackendMysqlConfig{
DBName: dbName,
User: user,
Password: password,
Host: host,
Port: port,
}
}

// ToOssBackend converts BackendConfig to structured BackendOssConfig, works only when the Type is
// BackendTypeOss, and the Configs are with correct type, or return nil.
func (b *BackendConfig) ToOssBackend() *BackendOssConfig {
Expand Down
10 changes: 0 additions & 10 deletions pkg/backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,6 @@ func NewBackend(name string) (Backend, error) {
return nil, fmt.Errorf("complete local config failed, %w", err)
}
return storages.NewLocalStorage(bkConfig), nil
case v1.BackendTypeMysql:
bkConfig := bkCfg.ToMysqlBackend()
storages.CompleteMysqlConfig(bkConfig)
if err = storages.ValidateMysqlConfig(bkConfig); err != nil {
return nil, fmt.Errorf("invalid config of backend %s, %w", name, err)
}
storage, err = storages.NewMysqlStorage(bkConfig)
if err != nil {
return nil, fmt.Errorf("new mysql storage of backend %s failed, %w", name, err)
}
case v1.BackendTypeOss:
bkConfig := bkCfg.ToOssBackend()
storages.CompleteOssConfig(bkConfig)
Expand Down
28 changes: 0 additions & 28 deletions pkg/backend/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,6 @@ func mockConfig() *v1.Config {
v1.BackendLocalPath: "/etc",
},
},
"pre": {
Type: v1.BackendTypeMysql,
Configs: map[string]any{
v1.BackendMysqlDBName: "kusion",
v1.BackendMysqlUser: "kk",
v1.BackendMysqlHost: "127.0.0.1",
v1.BackendMysqlPort: 3306,
},
},
"staging": {
Type: v1.BackendTypeOss,
Configs: map[string]any{
Expand All @@ -60,7 +51,6 @@ func mockCompleteLocalStorage() {

func mockNewStorage() {
mockey.Mock(storages.NewLocalStorage).Return(&storages.LocalStorage{}).Build()
mockey.Mock(storages.NewMysqlStorage).Return(&storages.MysqlStorage{}, nil).Build()
mockey.Mock(storages.NewOssStorage).Return(&storages.OssStorage{}, nil).Build()
mockey.Mock(storages.NewS3Storage).Return(&storages.S3Storage{}, nil).Build()
}
Expand All @@ -86,14 +76,6 @@ func TestNewBackend(t *testing.T) {
bkName: "",
storage: &storages.LocalStorage{},
},
{
name: "new current backend",
success: true,
cfg: mockConfig(),
envs: nil,
bkName: "",
storage: &storages.MysqlStorage{},
},
{
name: "new local backend",
success: true,
Expand All @@ -110,16 +92,6 @@ func TestNewBackend(t *testing.T) {
bkName: "dev",
storage: &storages.LocalStorage{},
},
{
name: "new mysql backend",
success: true,
cfg: mockConfig(),
envs: map[string]string{
v1.EnvBackendMysqlPassword: "fake-password",
},
bkName: "pre",
storage: &storages.MysqlStorage{},
},
{
name: "new oss backend",
success: true,
Expand Down
12 changes: 0 additions & 12 deletions pkg/backend/storages/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,6 @@ func CompleteLocalConfig(config *v1.BackendLocalConfig) error {
return nil
}

// CompleteMysqlConfig sets default value of port if not set, which is 3306, and fulfills password from environment
// variables if set.
func CompleteMysqlConfig(config *v1.BackendMysqlConfig) {
if config.Port == 0 {
config.Port = v1.DefaultMysqlPort
}
password := os.Getenv(v1.EnvBackendMysqlPassword)
if password != "" {
config.Password = password
}
}

// CompleteOssConfig fulfills the whole oss config from environment variables if set.
func CompleteOssConfig(config *v1.BackendOssConfig) {
accessKeyID := os.Getenv(v1.EnvOssAccessKeyID)
Expand Down
38 changes: 0 additions & 38 deletions pkg/backend/storages/completion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,44 +42,6 @@ func TestCompleteLocalConfig(t *testing.T) {
}
}

func TestCompleteMysqlConfig(t *testing.T) {
testcases := []struct {
name string
config *v1.BackendMysqlConfig
envs map[string]string
completeConfig *v1.BackendMysqlConfig
}{
{
name: "complete mysql config",
config: &v1.BackendMysqlConfig{
DBName: "kusion",
User: "kk",
Host: "127.0.0.1",
},
envs: map[string]string{
v1.EnvBackendMysqlPassword: "fake-password",
},
completeConfig: &v1.BackendMysqlConfig{
DBName: "kusion",
User: "kk",
Host: "127.0.0.1",
Port: 3306,
Password: "fake-password",
},
},
}

for _, tc := range testcases {
t.Run(tc.name, func(t *testing.T) {
for k, v := range tc.envs {
_ = os.Setenv(k, v)
}
CompleteMysqlConfig(tc.config)
assert.Equal(t, tc.completeConfig, tc.config)
})
}
}

func TestCompleteOssConfig(t *testing.T) {
testcases := []struct {
name string
Expand Down
49 changes: 0 additions & 49 deletions pkg/backend/storages/mysql.go

This file was deleted.

99 changes: 0 additions & 99 deletions pkg/backend/storages/mysql_test.go

This file was deleted.

Loading
Loading