diff --git a/pkg/apis/workspace/types.go b/pkg/apis/workspace/types.go deleted file mode 100644 index eea7e852..00000000 --- a/pkg/apis/workspace/types.go +++ /dev/null @@ -1,187 +0,0 @@ -package workspace - -const ( - DefaultBlock = "default" - ProjectSelectorField = "projectSelector" - - BackendLocal = "local" - BackendMysql = "mysql" - BackendOss = "oss" - BackendS3 = "s3" - EnvBackendMysqlPassword = "KUSION_BACKEND_MYSQL_PASSWORD" - EnvAwsAccessKeyID = "AWS_ACCESS_KEY_ID" - EnvAwsSecretAccessKey = "AWS_SECRET_ACCESS_KEY" - EnvAwsDefaultRegion = "AWS_DEFAULT_REGION" - EnvAwsRegion = "AWS_REGION" - EnvOssAccessKeyID = "OSS_ACCESS_KEY_ID" - EnvOssAccessKeySecret = "OSS_ACCESS_KEY_SECRET" - DefaultMysqlPort = 3306 -) - -// Workspace is a logical concept representing a target that stacks will be deployed to. -// Workspace is managed by platform engineers, which contains a set of configurations -// that application developers do not want or should not concern, and is reused by multiple -// stacks belonging to different projects. -type Workspace struct { - // Name identifies a Workspace uniquely. - Name string `yaml:"-" json:"-"` - - // Modules are the configs of a set of modules. - Modules ModuleConfigs `yaml:"modules,omitempty" json:"modules,omitempty"` - - // Runtimes are the configs of a set of runtimes. - Runtimes *RuntimeConfigs `yaml:"runtimes,omitempty" json:"runtimes,omitempty"` - - // Backends are the configs of a set of backends. - Backends *BackendConfigs `yaml:"backends,omitempty" json:"backends,omitempty"` -} - -// ModuleConfigs is a set of multiple ModuleConfig, whose key is the module name. -type ModuleConfigs map[string]*ModuleConfig - -// ModuleConfig is the config of a module, which contains a default and several patcher blocks. -// -// The default block's key is "default", and value is the module inputs. The patcher blocks' keys -// are the patcher names, which are just block identifiers without specific meaning, but must -// not be "default". Besides module inputs, patcher block's value also contains a field named -// "projectSelector", whose value is a slice containing the project names that use the patcher -// configs. A project can only be assigned in a patcher's "projectSelector" field, the assignment -// in multiple patchers is not allowed. For a project, if not specified in the patcher block's -// "projectSelector" field, the default config will be used. -// -// Take the ModuleConfig of "database" for an example, which is shown as below: -// -// config := ModuleConfig { -// "default": { -// "type": "aws", -// "version": "5.7", -// "instanceType": "db.t3.micro", -// }, -// "smallClass": { -// "instanceType": "db.t3.small", -// "projectSelector": []string{"foo", "bar"}, -// }, -// } -type ModuleConfig struct { - // Default is default block of the module config. - Default GenericConfig `yaml:"default" json:"default"` - - // ModulePatcherConfigs are the patcher blocks of the module config. - ModulePatcherConfigs `yaml:",inline,omitempty" json:",inline,omitempty"` -} - -// ModulePatcherConfigs is a group of ModulePatcherConfig. -type ModulePatcherConfigs map[string]*ModulePatcherConfig - -// ModulePatcherConfig is a patcher block of the module config. -type ModulePatcherConfig struct { - // GenericConfig contains the module configs. - GenericConfig `yaml:",inline" json:",inline"` - - // ProjectSelector contains the selected projects. - ProjectSelector []string `yaml:"projectSelector" json:"projectSelector"` -} - -// RuntimeConfigs contains a set of runtime config. -type RuntimeConfigs struct { - // Kubernetes contains the config to access a kubernetes cluster. - Kubernetes *KubernetesConfig `yaml:"kubernetes,omitempty" json:"kubernetes,omitempty"` - - // Terraform contains the config of multiple terraform providers. - Terraform TerraformConfig `yaml:"terraform,omitempty" json:"terraform,omitempty"` -} - -// KubernetesConfig contains config to access a kubernetes cluster. -type KubernetesConfig struct { - // KubeConfig is the path of the kubeconfig file. - KubeConfig string `yaml:"kubeConfig" json:"kubeConfig"` -} - -// TerraformConfig contains the config of multiple terraform provider config, whose key is -// the provider name. -type TerraformConfig map[string]*ProviderConfig - -// ProviderConfig contains the full configurations of a specified provider. It is the combination -// of the specified provider's config in blocks "terraform/required_providers" and "providers" in -// terraform hcl file, where the former is described by fields Source and Version, and the latter -// is described by GenericConfig cause different provider has different config. -type ProviderConfig struct { - // Source of the provider. - Source string `yaml:"source" json:"source"` - - // Version of the provider. - Version string `yaml:"version" json:"version"` - - // GenericConfig is used to describe the config of a specified terraform provider. - GenericConfig `yaml:",inline,omitempty" json:",inline,omitempty"` -} - -// BackendConfigs contains config of the backend, which is used to store state, etc. Only one kind -// backend can be configured. -type BackendConfigs struct { - // Local is the backend using local file system. - Local *LocalFileConfig `yaml:"local,omitempty" json:"local,omitempty"` - - // Mysql is the backend using mysql database. - Mysql *MysqlConfig `yaml:"mysql,omitempty" json:"mysql,omitempty"` - - // Oss is the backend using OSS. - Oss *OssConfig `yaml:"oss,omitempty" json:"oss,omitempty"` - - // S3 is the backend using S3. - S3 *S3Config `yaml:"s3,omitempty" json:"s3,omitempty"` -} - -// LocalFileConfig contains the config of using local file system as backend. Now there is no configuration -// item for local file. -type LocalFileConfig struct{} - -// MysqlConfig contains the config of using mysql database as backend. -type MysqlConfig 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 DefaultMysqlPort. - Port *int `yaml:"port,omitempty" json:"port,omitempty"` -} - -// OssConfig contains the config of using OSS as backend. -type OssConfig struct { - GenericObjectStorageConfig `yaml:",inline" json:",inline"` // OSS asks for non-empty endpoint -} - -// S3Config contains the config of using S3 as backend. -type S3Config struct { - GenericObjectStorageConfig `yaml:",inline" json:",inline"` - - // Region of S3. - Region string `yaml:"region,omitempty" json:"region,omitempty"` -} - -// GenericObjectStorageConfig contains generic configs which can be reused by OssConfig and S3Config. -type GenericObjectStorageConfig struct { - // Endpoint of the object storage service. - Endpoint string `yaml:"endpoint,omitempty" json:"endpoint,omitempty"` - - // AccessKeyID of the object storage service. - AccessKeyID string `yaml:"accessKeyID,omitempty" json:"accessKeyID,omitempty"` - - // AccessKeySecret of the object storage service. - AccessKeySecret string `yaml:"accessKeySecret,omitempty" json:"accessKeySecret,omitempty"` - - // Bucket of the object storage service. - Bucket string `yaml:"bucket" json:"bucket"` -} - -// GenericConfig is a generic model to describe config which shields the difference among multiple concrete -// models. GenericConfig is designed for extensibility, used for module, terraform runtime config, etc. -type GenericConfig map[string]any diff --git a/pkg/cmd/build/builders/appconfig_builder.go b/pkg/cmd/build/builders/appconfig_builder.go index 85cc8656..b7d3dda9 100644 --- a/pkg/cmd/build/builders/appconfig_builder.go +++ b/pkg/cmd/build/builders/appconfig_builder.go @@ -1,10 +1,10 @@ package builders import ( + "kusionstack.io/kusion/pkg/apis/core/v1" "kusionstack.io/kusion/pkg/apis/intent" "kusionstack.io/kusion/pkg/apis/project" "kusionstack.io/kusion/pkg/apis/stack" - "kusionstack.io/kusion/pkg/apis/workspace" "kusionstack.io/kusion/pkg/modules" "kusionstack.io/kusion/pkg/modules/generators" "kusionstack.io/kusion/pkg/modules/inputs" @@ -12,7 +12,7 @@ import ( type AppsConfigBuilder struct { Apps map[string]inputs.AppConfiguration - Workspace *workspace.Workspace + Workspace *v1.Workspace } func (acg *AppsConfigBuilder) Build( diff --git a/pkg/cmd/build/builders/appconfig_builder_test.go b/pkg/cmd/build/builders/appconfig_builder_test.go index 24d11c7f..257db5a4 100644 --- a/pkg/cmd/build/builders/appconfig_builder_test.go +++ b/pkg/cmd/build/builders/appconfig_builder_test.go @@ -5,9 +5,9 @@ import ( "github.com/stretchr/testify/assert" + "kusionstack.io/kusion/pkg/apis/core/v1" "kusionstack.io/kusion/pkg/apis/project" "kusionstack.io/kusion/pkg/apis/stack" - "kusionstack.io/kusion/pkg/apis/workspace" appmodel "kusionstack.io/kusion/pkg/modules/inputs" "kusionstack.io/kusion/pkg/modules/inputs/workload" "kusionstack.io/kusion/pkg/modules/inputs/workload/network" @@ -50,19 +50,19 @@ func buildMockApp() (string, *appmodel.AppConfiguration) { } } -func buildMockWorkspace() *workspace.Workspace { - return &workspace.Workspace{ +func buildMockWorkspace() *v1.Workspace { + return &v1.Workspace{ Name: "test", - Modules: workspace.ModuleConfigs{ + Modules: v1.ModuleConfigs{ "database": { - Default: workspace.GenericConfig{ + Default: v1.GenericConfig{ "type": "aws", "version": "5.7", "instanceType": "db.t3.micro", }, - ModulePatcherConfigs: workspace.ModulePatcherConfigs{ + ModulePatcherConfigs: v1.ModulePatcherConfigs{ "smallClass": { - GenericConfig: workspace.GenericConfig{ + GenericConfig: v1.GenericConfig{ "instanceType": "db.t3.small", }, ProjectSelector: []string{"foo", "bar"}, @@ -70,18 +70,18 @@ func buildMockWorkspace() *workspace.Workspace { }, }, "port": { - Default: workspace.GenericConfig{ + Default: v1.GenericConfig{ "type": "aws", }, }, }, - Runtimes: &workspace.RuntimeConfigs{ - Kubernetes: &workspace.KubernetesConfig{ + Runtimes: &v1.RuntimeConfigs{ + Kubernetes: &v1.KubernetesConfig{ KubeConfig: "/etc/kubeconfig.yaml", }, }, - Backends: &workspace.BackendConfigs{ - Local: &workspace.LocalFileConfig{}, + Backends: &v1.BackendConfigs{ + Local: &v1.LocalFileConfig{}, }, } } diff --git a/pkg/cmd/build/util_test.go b/pkg/cmd/build/util_test.go index 75b9aa42..e54ca9ea 100644 --- a/pkg/cmd/build/util_test.go +++ b/pkg/cmd/build/util_test.go @@ -10,10 +10,10 @@ import ( "github.com/stretchr/testify/require" kclgo "kcl-lang.io/kcl-go" + "kusionstack.io/kusion/pkg/apis/core/v1" "kusionstack.io/kusion/pkg/apis/intent" "kusionstack.io/kusion/pkg/apis/project" "kusionstack.io/kusion/pkg/apis/stack" - workspaceapi "kusionstack.io/kusion/pkg/apis/workspace" "kusionstack.io/kusion/pkg/cmd/build/builders" "kusionstack.io/kusion/pkg/cmd/build/builders/kcl" appconfigmodel "kusionstack.io/kusion/pkg/modules/inputs" @@ -121,18 +121,18 @@ resources: }, } - ws = &workspaceapi.Workspace{ + ws = &v1.Workspace{ Name: "default", - Modules: workspaceapi.ModuleConfigs{ + Modules: v1.ModuleConfigs{ "database": { - Default: workspaceapi.GenericConfig{ + Default: v1.GenericConfig{ "type": "aws", "version": "5.7", "instanceType": "db.t3.micro", }, - ModulePatcherConfigs: workspaceapi.ModulePatcherConfigs{ + ModulePatcherConfigs: v1.ModulePatcherConfigs{ "smallClass": { - GenericConfig: workspaceapi.GenericConfig{ + GenericConfig: v1.GenericConfig{ "instanceType": "db.t3.small", }, ProjectSelector: []string{"foo", "bar"}, @@ -140,18 +140,18 @@ resources: }, }, "port": { - Default: workspaceapi.GenericConfig{ + Default: v1.GenericConfig{ "type": "aws", }, }, }, - Runtimes: &workspaceapi.RuntimeConfigs{ - Kubernetes: &workspaceapi.KubernetesConfig{ + Runtimes: &v1.RuntimeConfigs{ + Kubernetes: &v1.KubernetesConfig{ KubeConfig: "/etc/kubeconfig.yaml", }, }, - Backends: &workspaceapi.BackendConfigs{ - Local: &workspaceapi.LocalFileConfig{}, + Backends: &v1.BackendConfigs{ + Local: &v1.LocalFileConfig{}, }, } ) diff --git a/pkg/engine/backend/config.go b/pkg/engine/backend/config.go index c2d4b0d6..21e7c6c9 100644 --- a/pkg/engine/backend/config.go +++ b/pkg/engine/backend/config.go @@ -6,7 +6,7 @@ import ( "github.com/zclconf/go-cty/cty/gocty" - workspaceapi "kusionstack.io/kusion/pkg/apis/workspace" + "kusionstack.io/kusion/pkg/apis/core/v1" backendinit "kusionstack.io/kusion/pkg/engine/backend/init" "kusionstack.io/kusion/pkg/engine/states" "kusionstack.io/kusion/pkg/engine/states/local" @@ -20,7 +20,7 @@ type StateStorageConfig struct { } // NewConfig news a StateStorageConfig from workspace BackendConfigs, BackendOptions and environment variables. -func NewConfig(workDir string, configs *workspaceapi.BackendConfigs, opts *BackendOptions) (*StateStorageConfig, error) { +func NewConfig(workDir string, configs *v1.BackendConfigs, opts *BackendOptions) (*StateStorageConfig, error) { var config, overrideConfig *StateStorageConfig config = convertWorkspaceBackendConfig(workDir, configs) if opts != nil && !opts.IsEmpty() { @@ -41,7 +41,7 @@ func NewConfig(workDir string, configs *workspaceapi.BackendConfigs, opts *Backe // NewDefaultStateStorageConfig news the default state storage which uses local backend. func NewDefaultStateStorageConfig(workDir string) *StateStorageConfig { return &StateStorageConfig{ - Type: workspaceapi.BackendLocal, + Type: v1.BackendLocal, Config: map[string]any{ "path": path.Join(workDir, local.KusionStateFileFile), }, @@ -68,13 +68,13 @@ func (c *StateStorageConfig) NewStateStorage() (states.StateStorage, error) { } // convertWorkspaceBackendConfig converts workspace backend config to StateStorageConfig. -func convertWorkspaceBackendConfig(workDir string, configs *workspaceapi.BackendConfigs) *StateStorageConfig { +func convertWorkspaceBackendConfig(workDir string, configs *v1.BackendConfigs) *StateStorageConfig { name := workspace.GetBackendName(configs) var config map[string]any switch name { - case workspaceapi.BackendLocal: + case v1.BackendLocal: config = NewDefaultStateStorageConfig(workDir).Config - case workspaceapi.BackendMysql: + case v1.BackendMysql: config = map[string]any{ "dbName": configs.Mysql.DBName, "user": configs.Mysql.User, @@ -82,14 +82,14 @@ func convertWorkspaceBackendConfig(workDir string, configs *workspaceapi.Backend "host": configs.Mysql.Host, "port": *configs.Mysql.Port, } - case workspaceapi.BackendOss: + case v1.BackendOss: config = map[string]any{ "endpoint": configs.Oss.Endpoint, "bucket": configs.Oss.Bucket, "accessKeyID": configs.Oss.AccessKeyID, "accessKeySecret": configs.Oss.AccessKeySecret, } - case workspaceapi.BackendS3: + case v1.BackendS3: config = map[string]any{ "endpoint": configs.S3.Endpoint, "bucket": configs.S3.Bucket, @@ -108,12 +108,12 @@ func convertWorkspaceBackendConfig(workDir string, configs *workspaceapi.Backend func getEnvBackendConfig(backendType string) map[string]any { config := make(map[string]any) switch backendType { - case workspaceapi.BackendMysql: + case v1.BackendMysql: password := workspace.GetMysqlPasswordFromEnv() if password != "" { config["password"] = password } - case workspaceapi.BackendOss: + case v1.BackendOss: accessKeyID, accessKeySecret := workspace.GetOssSensitiveDataFromEnv() if accessKeyID != "" { config["accessKeyID"] = accessKeyID @@ -121,7 +121,7 @@ func getEnvBackendConfig(backendType string) map[string]any { if accessKeySecret != "" { config["accessKeySecret"] = accessKeySecret } - case workspaceapi.BackendS3: + case v1.BackendS3: accessKeyID, accessKeySecret, region := workspace.GetS3SensitiveDataFromEnv() if accessKeyID != "" { config["accessKeyID"] = accessKeyID diff --git a/pkg/engine/backend/config_test.go b/pkg/engine/backend/config_test.go index f0d4571f..2d01e84d 100644 --- a/pkg/engine/backend/config_test.go +++ b/pkg/engine/backend/config_test.go @@ -7,7 +7,7 @@ import ( "github.com/stretchr/testify/assert" - "kusionstack.io/kusion/pkg/apis/workspace" + "kusionstack.io/kusion/pkg/apis/core/v1" "kusionstack.io/kusion/pkg/engine/states" "kusionstack.io/kusion/pkg/engine/states/local" ) @@ -18,7 +18,7 @@ func TestNewConfig(t *testing.T) { name string success bool workDir string - configs *workspace.BackendConfigs + configs *v1.BackendConfigs opts *BackendOptions setEnvFunc, unSetEnvFunc func() expectedConfig *StateStorageConfig @@ -32,7 +32,7 @@ func TestNewConfig(t *testing.T) { setEnvFunc: nil, unSetEnvFunc: nil, expectedConfig: &StateStorageConfig{ - Type: workspace.BackendLocal, + Type: v1.BackendLocal, Config: map[string]any{ "path": "/test_project/test_stack/kusion_state.yaml", }, @@ -42,8 +42,8 @@ func TestNewConfig(t *testing.T) { name: "empty backend options", success: true, workDir: "/testProject/testStack", - configs: &workspace.BackendConfigs{ - Mysql: &workspace.MysqlConfig{ + configs: &v1.BackendConfigs{ + Mysql: &v1.MysqlConfig{ DBName: "kusion_db", User: "kusion", Password: "do_not_recommend", @@ -53,13 +53,13 @@ func TestNewConfig(t *testing.T) { }, opts: &BackendOptions{}, setEnvFunc: func() { - _ = os.Setenv(workspace.EnvBackendMysqlPassword, "kusion_password") + _ = os.Setenv(v1.EnvBackendMysqlPassword, "kusion_password") }, unSetEnvFunc: func() { - _ = os.Unsetenv(workspace.EnvBackendMysqlPassword) + _ = os.Unsetenv(v1.EnvBackendMysqlPassword) }, expectedConfig: &StateStorageConfig{ - Type: workspace.BackendMysql, + Type: v1.BackendMysql, Config: map[string]any{ "dbName": "kusion_db", "user": "kusion", @@ -73,8 +73,8 @@ func TestNewConfig(t *testing.T) { name: "backend options override", success: true, workDir: "/testProject/testStack", - configs: &workspace.BackendConfigs{ - Mysql: &workspace.MysqlConfig{ + configs: &v1.BackendConfigs{ + Mysql: &v1.MysqlConfig{ DBName: "kusion_db", User: "kusion", Host: "127.0.0.1", @@ -82,21 +82,21 @@ func TestNewConfig(t *testing.T) { }, }, opts: &BackendOptions{ - Type: workspace.BackendS3, + Type: v1.BackendS3, Config: []string{"region=ua-east-2", "bucket=kusion_bucket"}, }, setEnvFunc: func() { - _ = os.Setenv(workspace.EnvAwsRegion, "ua-east-1") - _ = os.Setenv(workspace.EnvAwsAccessKeyID, "aws_ak_id") - _ = os.Setenv(workspace.EnvAwsSecretAccessKey, "aws_ak_secret") + _ = os.Setenv(v1.EnvAwsRegion, "ua-east-1") + _ = os.Setenv(v1.EnvAwsAccessKeyID, "aws_ak_id") + _ = os.Setenv(v1.EnvAwsSecretAccessKey, "aws_ak_secret") }, unSetEnvFunc: func() { - _ = os.Unsetenv(workspace.EnvAwsDefaultRegion) - _ = os.Unsetenv(workspace.EnvOssAccessKeyID) - _ = os.Unsetenv(workspace.EnvAwsSecretAccessKey) + _ = os.Unsetenv(v1.EnvAwsDefaultRegion) + _ = os.Unsetenv(v1.EnvOssAccessKeyID) + _ = os.Unsetenv(v1.EnvAwsSecretAccessKey) }, expectedConfig: &StateStorageConfig{ - Type: workspace.BackendS3, + Type: v1.BackendS3, Config: map[string]any{ "region": "ua-east-2", "accessKeyID": "aws_ak_id", @@ -133,7 +133,7 @@ func TestStateStorageConfig_NewStateStorage(t *testing.T) { name: "local state storage", success: true, config: &StateStorageConfig{ - Type: workspace.BackendLocal, + Type: v1.BackendLocal, Config: map[string]any{ "path": "/test_project/test_stack/kusion_state.yaml", }, @@ -163,9 +163,9 @@ func TestMergeConfig(t *testing.T) { }{ { name: "empty override config", - backendType: workspace.BackendLocal, + backendType: v1.BackendLocal, config: &StateStorageConfig{ - Type: workspace.BackendLocal, + Type: v1.BackendLocal, Config: map[string]any{ "path": "/test_project/test_stack/kusion_state.yaml", }, @@ -173,7 +173,7 @@ func TestMergeConfig(t *testing.T) { overrideConfig: nil, envConfig: nil, mergedConfig: &StateStorageConfig{ - Type: workspace.BackendLocal, + Type: v1.BackendLocal, Config: map[string]any{ "path": "/test_project/test_stack/kusion_state.yaml", }, @@ -181,9 +181,9 @@ func TestMergeConfig(t *testing.T) { }, { name: "same type override config", - backendType: workspace.BackendMysql, + backendType: v1.BackendMysql, config: &StateStorageConfig{ - Type: workspace.BackendMysql, + Type: v1.BackendMysql, Config: map[string]any{ "dbName": "kusion_db", "user": "kusion", @@ -192,7 +192,7 @@ func TestMergeConfig(t *testing.T) { }, }, overrideConfig: &StateStorageConfig{ - Type: workspace.BackendMysql, + Type: v1.BackendMysql, Config: map[string]any{ "dbName": "new_kusion_db", "user": "new_kusion", @@ -202,7 +202,7 @@ func TestMergeConfig(t *testing.T) { "password": "new_kusion_password", }, mergedConfig: &StateStorageConfig{ - Type: workspace.BackendMysql, + Type: v1.BackendMysql, Config: map[string]any{ "dbName": "new_kusion_db", "user": "new_kusion", @@ -214,9 +214,9 @@ func TestMergeConfig(t *testing.T) { }, { name: "different type override config", - backendType: workspace.BackendOss, + backendType: v1.BackendOss, config: &StateStorageConfig{ - Type: workspace.BackendMysql, + Type: v1.BackendMysql, Config: map[string]any{ "dbName": "kusion_db", "user": "kusion", @@ -225,7 +225,7 @@ func TestMergeConfig(t *testing.T) { }, }, overrideConfig: &StateStorageConfig{ - Type: workspace.BackendOss, + Type: v1.BackendOss, Config: map[string]any{ "endpoint": "oss-cn-hangzhou.aliyuncs.com", "bucket": "kusion_test", @@ -238,7 +238,7 @@ func TestMergeConfig(t *testing.T) { "accessKeySecret": "kusion_test_env", }, mergedConfig: &StateStorageConfig{ - Type: workspace.BackendOss, + Type: v1.BackendOss, Config: map[string]any{ "endpoint": "oss-cn-hangzhou.aliyuncs.com", "bucket": "kusion_test", diff --git a/pkg/engine/backend/init/init.go b/pkg/engine/backend/init/init.go index dfabec34..00554f89 100644 --- a/pkg/engine/backend/init/init.go +++ b/pkg/engine/backend/init/init.go @@ -1,7 +1,7 @@ package init import ( - "kusionstack.io/kusion/pkg/apis/workspace" + "kusionstack.io/kusion/pkg/apis/core/v1" "kusionstack.io/kusion/pkg/engine/states" "kusionstack.io/kusion/pkg/engine/states/local" "kusionstack.io/kusion/pkg/engine/states/remote/http" @@ -16,11 +16,11 @@ var backends map[string]func() states.Backend // init backends map with all support backend func init() { backends = map[string]func() states.Backend{ - workspace.BackendLocal: local.NewLocalBackend, - workspace.BackendMysql: mysql.NewMysqlBackend, - workspace.BackendOss: oss.NewOssBackend, - workspace.BackendS3: s3.NewS3Backend, - "http": http.NewHTTPBackend, + v1.BackendLocal: local.NewLocalBackend, + v1.BackendMysql: mysql.NewMysqlBackend, + v1.BackendOss: oss.NewOssBackend, + v1.BackendS3: s3.NewS3Backend, + "http": http.NewHTTPBackend, } } diff --git a/pkg/engine/backend/options.go b/pkg/engine/backend/options.go index cf8b77d5..0a26f41e 100644 --- a/pkg/engine/backend/options.go +++ b/pkg/engine/backend/options.go @@ -8,7 +8,7 @@ import ( "github.com/spf13/cobra" "github.com/zclconf/go-cty/cty" - "kusionstack.io/kusion/pkg/apis/workspace" + "kusionstack.io/kusion/pkg/apis/core/v1" backendinit "kusionstack.io/kusion/pkg/engine/backend/init" "kusionstack.io/kusion/pkg/util/i18n" ) @@ -101,7 +101,7 @@ func validBackendConfig(config *StateStorageConfig, schema cty.Type) error { return fmt.Errorf("%w: %s", ErrUnsupportedBackendConfigItem, k) } } - if config.Type == workspace.BackendLocal && len(config.Config) != 0 { + if config.Type == v1.BackendLocal && len(config.Config) != 0 { return fmt.Errorf("%w for backend local", ErrNotSupportBackendConfig) } return nil diff --git a/pkg/engine/backend/options_test.go b/pkg/engine/backend/options_test.go index 9f6e5523..24ae8fe8 100644 --- a/pkg/engine/backend/options_test.go +++ b/pkg/engine/backend/options_test.go @@ -5,7 +5,7 @@ import ( "github.com/stretchr/testify/assert" - "kusionstack.io/kusion/pkg/apis/workspace" + "kusionstack.io/kusion/pkg/apis/core/v1" _ "kusionstack.io/kusion/pkg/engine/backend/init" ) @@ -19,7 +19,7 @@ func TestBackendOptions_Validate(t *testing.T) { name: "valid backend options", success: true, opts: &BackendOptions{ - Type: workspace.BackendMysql, + Type: v1.BackendMysql, Config: []string{ "dbName=kusion_db", "user=kusion", diff --git a/pkg/engine/backend/util.go b/pkg/engine/backend/util.go index 8ff7fa46..e7893112 100644 --- a/pkg/engine/backend/util.go +++ b/pkg/engine/backend/util.go @@ -3,21 +3,21 @@ package backend import ( "fmt" + "kusionstack.io/kusion/pkg/apis/core/v1" "kusionstack.io/kusion/pkg/apis/stack" - workspaceapi "kusionstack.io/kusion/pkg/apis/workspace" "kusionstack.io/kusion/pkg/engine/states" "kusionstack.io/kusion/pkg/workspace" ) // NewStateStorage news a StateStorage by configs of workspace, cli backend options, and environment variables. func NewStateStorage(stack *stack.Stack, opts *BackendOptions) (states.StateStorage, error) { - var backendConfigs *workspaceapi.BackendConfigs + var backendConfigs *v1.BackendConfigs wsOperator, err := workspace.NewValidDefaultOperator() if err != nil { return nil, fmt.Errorf("new default workspace opearator failed, %w", err) } if wsOperator.WorkspaceExist(stack.Name) { - var ws *workspaceapi.Workspace + var ws *v1.Workspace ws, err = wsOperator.GetWorkspace(stack.Name) if err != nil { return nil, fmt.Errorf("get config of workspace %s failed, %w", stack.Name, err) diff --git a/pkg/engine/backend/util_test.go b/pkg/engine/backend/util_test.go index fa9c551c..13817e98 100644 --- a/pkg/engine/backend/util_test.go +++ b/pkg/engine/backend/util_test.go @@ -9,8 +9,8 @@ import ( "github.com/bytedance/mockey" "github.com/stretchr/testify/assert" + "kusionstack.io/kusion/pkg/apis/core/v1" "kusionstack.io/kusion/pkg/apis/stack" - "kusionstack.io/kusion/pkg/apis/workspace" "kusionstack.io/kusion/pkg/util/kfile" ) @@ -48,14 +48,14 @@ func Test_NewStateStorage(t *testing.T) { stack: mockStack("s3_backend_ws"), opts: &BackendOptions{}, setEnvFunc: func() { - _ = os.Setenv(workspace.EnvAwsRegion, "ua-east-2") - _ = os.Setenv(workspace.EnvAwsAccessKeyID, "aws_ak_id") - _ = os.Setenv(workspace.EnvAwsSecretAccessKey, "aws_ak_secret") + _ = os.Setenv(v1.EnvAwsRegion, "ua-east-2") + _ = os.Setenv(v1.EnvAwsAccessKeyID, "aws_ak_id") + _ = os.Setenv(v1.EnvAwsSecretAccessKey, "aws_ak_secret") }, unsetEnvFunc: func() { - _ = os.Unsetenv(workspace.EnvAwsDefaultRegion) - _ = os.Unsetenv(workspace.EnvOssAccessKeyID) - _ = os.Unsetenv(workspace.EnvAwsSecretAccessKey) + _ = os.Unsetenv(v1.EnvAwsDefaultRegion) + _ = os.Unsetenv(v1.EnvOssAccessKeyID) + _ = os.Unsetenv(v1.EnvAwsSecretAccessKey) }, }, { diff --git a/pkg/modules/generators/app_configurations_generator.go b/pkg/modules/generators/app_configurations_generator.go index 13fb3216..01ae09c6 100644 --- a/pkg/modules/generators/app_configurations_generator.go +++ b/pkg/modules/generators/app_configurations_generator.go @@ -4,10 +4,10 @@ import ( "errors" "fmt" + "kusionstack.io/kusion/pkg/apis/core/v1" "kusionstack.io/kusion/pkg/apis/intent" "kusionstack.io/kusion/pkg/apis/project" "kusionstack.io/kusion/pkg/apis/stack" - workspaceapi "kusionstack.io/kusion/pkg/apis/workspace" "kusionstack.io/kusion/pkg/modules" accessories "kusionstack.io/kusion/pkg/modules/generators/accessories/database" "kusionstack.io/kusion/pkg/modules/generators/monitoring" @@ -24,7 +24,7 @@ type appConfigurationGenerator struct { stack *stack.Stack appName string app *inputs.AppConfiguration - ws *workspaceapi.Workspace + ws *v1.Workspace } func NewAppConfigurationGenerator( @@ -32,7 +32,7 @@ func NewAppConfigurationGenerator( stack *stack.Stack, appName string, app *inputs.AppConfiguration, - ws *workspaceapi.Workspace, + ws *v1.Workspace, ) (modules.Generator, error) { if len(project.Name) == 0 { return nil, fmt.Errorf("project name must not be empty") @@ -67,7 +67,7 @@ func NewAppConfigurationGeneratorFunc( stack *stack.Stack, appName string, app *inputs.AppConfiguration, - ws *workspaceapi.Workspace, + ws *v1.Workspace, ) modules.NewGeneratorFunc { return func() (modules.Generator, error) { return NewAppConfigurationGenerator(project, stack, appName, app, ws) diff --git a/pkg/modules/generators/app_configurations_generator_test.go b/pkg/modules/generators/app_configurations_generator_test.go index c9c49d9f..749e936a 100644 --- a/pkg/modules/generators/app_configurations_generator_test.go +++ b/pkg/modules/generators/app_configurations_generator_test.go @@ -5,10 +5,10 @@ import ( "github.com/stretchr/testify/assert" + "kusionstack.io/kusion/pkg/apis/core/v1" "kusionstack.io/kusion/pkg/apis/intent" "kusionstack.io/kusion/pkg/apis/project" "kusionstack.io/kusion/pkg/apis/stack" - "kusionstack.io/kusion/pkg/apis/workspace" appmodel "kusionstack.io/kusion/pkg/modules/inputs" "kusionstack.io/kusion/pkg/modules/inputs/workload" "kusionstack.io/kusion/pkg/modules/inputs/workload/network" @@ -95,19 +95,19 @@ func buildMockApp() (string, *appmodel.AppConfiguration) { } } -func buildMockWorkspace() *workspace.Workspace { - return &workspace.Workspace{ +func buildMockWorkspace() *v1.Workspace { + return &v1.Workspace{ Name: "test", - Modules: workspace.ModuleConfigs{ + Modules: v1.ModuleConfigs{ "database": { - Default: workspace.GenericConfig{ + Default: v1.GenericConfig{ "type": "aws", "version": "5.7", "instanceType": "db.t3.micro", }, - ModulePatcherConfigs: workspace.ModulePatcherConfigs{ + ModulePatcherConfigs: v1.ModulePatcherConfigs{ "smallClass": { - GenericConfig: workspace.GenericConfig{ + GenericConfig: v1.GenericConfig{ "instanceType": "db.t3.small", }, ProjectSelector: []string{"foo", "bar"}, @@ -115,18 +115,18 @@ func buildMockWorkspace() *workspace.Workspace { }, }, "port": { - Default: workspace.GenericConfig{ + Default: v1.GenericConfig{ "type": "aws", }, }, }, - Runtimes: &workspace.RuntimeConfigs{ - Kubernetes: &workspace.KubernetesConfig{ + Runtimes: &v1.RuntimeConfigs{ + Kubernetes: &v1.KubernetesConfig{ KubeConfig: "/etc/kubeconfig.yaml", }, }, - Backends: &workspace.BackendConfigs{ - Local: &workspace.LocalFileConfig{}, + Backends: &v1.BackendConfigs{ + Local: &v1.LocalFileConfig{}, }, } } diff --git a/pkg/modules/generators/namespace_generator.go b/pkg/modules/generators/namespace_generator.go index 0117363a..a8f19d0b 100644 --- a/pkg/modules/generators/namespace_generator.go +++ b/pkg/modules/generators/namespace_generator.go @@ -3,21 +3,21 @@ package generators import ( "fmt" - v1 "k8s.io/api/core/v1" + corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + apiv1 "kusionstack.io/kusion/pkg/apis/core/v1" "kusionstack.io/kusion/pkg/apis/intent" - workspaceapi "kusionstack.io/kusion/pkg/apis/workspace" "kusionstack.io/kusion/pkg/modules" "kusionstack.io/kusion/pkg/workspace" ) type namespaceGenerator struct { projectName string - moduleInputs map[string]workspaceapi.GenericConfig + moduleInputs map[string]apiv1.GenericConfig } -func NewNamespaceGenerator(projectName string, ws *workspaceapi.Workspace) (modules.Generator, error) { +func NewNamespaceGenerator(projectName string, ws *apiv1.Workspace) (modules.Generator, error) { if len(projectName) == 0 { return nil, fmt.Errorf("project name must not be empty") } @@ -32,7 +32,7 @@ func NewNamespaceGenerator(projectName string, ws *workspaceapi.Workspace) (modu }, nil } -func NewNamespaceGeneratorFunc(projectName string, workspace *workspaceapi.Workspace) modules.NewGeneratorFunc { +func NewNamespaceGeneratorFunc(projectName string, workspace *apiv1.Workspace) modules.NewGeneratorFunc { return func() (modules.Generator, error) { return NewNamespaceGenerator(projectName, workspace) } @@ -43,10 +43,10 @@ func (g *namespaceGenerator) Generate(i *intent.Intent) error { i.Resources = make(intent.Resources, 0) } - ns := &v1.Namespace{ + ns := &corev1.Namespace{ TypeMeta: metav1.TypeMeta{ Kind: "Namespace", - APIVersion: v1.SchemeGroupVersion.String(), + APIVersion: corev1.SchemeGroupVersion.String(), }, ObjectMeta: metav1.ObjectMeta{Name: g.getName(g.projectName)}, } diff --git a/pkg/modules/generators/namespace_generator_test.go b/pkg/modules/generators/namespace_generator_test.go index 511aecf5..679cb7e2 100644 --- a/pkg/modules/generators/namespace_generator_test.go +++ b/pkg/modules/generators/namespace_generator_test.go @@ -5,14 +5,14 @@ import ( "github.com/stretchr/testify/require" + "kusionstack.io/kusion/pkg/apis/core/v1" "kusionstack.io/kusion/pkg/apis/intent" - "kusionstack.io/kusion/pkg/apis/workspace" ) func Test_namespaceGenerator_Generate(t *testing.T) { type fields struct { projectName string - moduleInputs map[string]workspace.GenericConfig + moduleInputs map[string]v1.GenericConfig } type args struct { intent *intent.Intent @@ -60,7 +60,7 @@ func Test_namespaceGenerator_Generate(t *testing.T) { name: "customize_namespace", fields: fields{ projectName: "beep", - moduleInputs: map[string]workspace.GenericConfig{ + moduleInputs: map[string]v1.GenericConfig{ "namespace": { "name": "foo", }, @@ -97,7 +97,7 @@ func Test_namespaceGenerator_Generate(t *testing.T) { name: "mismatch_module_input", fields: fields{ projectName: "beep", - moduleInputs: map[string]workspace.GenericConfig{ + moduleInputs: map[string]v1.GenericConfig{ "namespace": { "type": "foo", }, diff --git a/pkg/modules/util.go b/pkg/modules/util.go index ae6b38a4..cab3bc78 100644 --- a/pkg/modules/util.go +++ b/pkg/modules/util.go @@ -7,8 +7,8 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" + apiv1 "kusionstack.io/kusion/pkg/apis/core/v1" "kusionstack.io/kusion/pkg/apis/intent" - workspaceapi "kusionstack.io/kusion/pkg/apis/workspace" "kusionstack.io/kusion/pkg/modules/inputs" "kusionstack.io/kusion/pkg/workspace" ) @@ -218,7 +218,7 @@ func PatchResource[T any](resources map[string][]*intent.Resource, gvk string, p // AddKubeConfigIf adds kubeConfig from workspace to extensions of Kubernetes type resource in intent. // If there is already has kubeConfig in extensions, use the kubeConfig in extensions. -func AddKubeConfigIf(i *intent.Intent, ws *workspaceapi.Workspace) { +func AddKubeConfigIf(i *intent.Intent, ws *apiv1.Workspace) { config, err := workspace.GetKubernetesConfig(ws.Runtimes) if errors.Is(err, workspace.ErrEmptyRuntimeConfigs) || errors.Is(err, workspace.ErrEmptyKubernetesConfig) { return diff --git a/pkg/modules/util_test.go b/pkg/modules/util_test.go index 7a9c014c..5eb24c75 100644 --- a/pkg/modules/util_test.go +++ b/pkg/modules/util_test.go @@ -7,8 +7,8 @@ import ( corev1 "k8s.io/api/core/v1" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + apiv1 "kusionstack.io/kusion/pkg/apis/core/v1" "kusionstack.io/kusion/pkg/apis/intent" - workspaceapi "kusionstack.io/kusion/pkg/apis/workspace" ) type mockGenerator struct { @@ -256,13 +256,13 @@ func TestPatchResource(t *testing.T) { func TestAddKubeConfigIf(t *testing.T) { testcases := []struct { name string - ws *workspaceapi.Workspace + ws *apiv1.Workspace i *intent.Intent expectedIntent *intent.Intent }{ { name: "empty workspace runtime config", - ws: &workspaceapi.Workspace{Name: "dev"}, + ws: &apiv1.Workspace{Name: "dev"}, i: &intent.Intent{ Resources: intent.Resources{ { @@ -290,10 +290,10 @@ func TestAddKubeConfigIf(t *testing.T) { }, { name: "empty kubeConfig in workspace", - ws: &workspaceapi.Workspace{ + ws: &apiv1.Workspace{ Name: "dev", - Runtimes: &workspaceapi.RuntimeConfigs{ - Kubernetes: &workspaceapi.KubernetesConfig{}, + Runtimes: &apiv1.RuntimeConfigs{ + Kubernetes: &apiv1.KubernetesConfig{}, }, }, i: &intent.Intent{ @@ -323,10 +323,10 @@ func TestAddKubeConfigIf(t *testing.T) { }, { name: "add kubeConfig", - ws: &workspaceapi.Workspace{ + ws: &apiv1.Workspace{ Name: "dev", - Runtimes: &workspaceapi.RuntimeConfigs{ - Kubernetes: &workspaceapi.KubernetesConfig{ + Runtimes: &apiv1.RuntimeConfigs{ + Kubernetes: &apiv1.KubernetesConfig{ KubeConfig: "/etc/kubeConfig.yaml", }, }, diff --git a/pkg/workspace/operator.go b/pkg/workspace/operator.go index cc40f078..ef2d2387 100644 --- a/pkg/workspace/operator.go +++ b/pkg/workspace/operator.go @@ -9,7 +9,7 @@ import ( yaml "gopkg.in/yaml.v3" - "kusionstack.io/kusion/pkg/apis/workspace" + "kusionstack.io/kusion/pkg/apis/core/v1" "kusionstack.io/kusion/pkg/util/kfile" ) @@ -38,7 +38,7 @@ func CheckWorkspaceExistenceByDefaultOperator(name string) (bool, error) { } // GetWorkspaceByDefaultOperator gets a workspace by default operator. -func GetWorkspaceByDefaultOperator(name string) (*workspace.Workspace, error) { +func GetWorkspaceByDefaultOperator(name string) (*v1.Workspace, error) { operator, err := NewValidDefaultOperator() if err != nil { return nil, err @@ -56,7 +56,7 @@ func GetWorkspaceNamesByDefaultOperator() ([]string, error) { } // CreateWorkspaceByDefaultOperator creates a workspace by default operator. -func CreateWorkspaceByDefaultOperator(ws *workspace.Workspace) error { +func CreateWorkspaceByDefaultOperator(ws *v1.Workspace) error { operator, err := NewValidDefaultOperator() if err != nil { return err @@ -65,7 +65,7 @@ func CreateWorkspaceByDefaultOperator(ws *workspace.Workspace) error { } // UpdateWorkspaceByDefaultOperator updates a workspace by default operator. -func UpdateWorkspaceByDefaultOperator(ws *workspace.Workspace) error { +func UpdateWorkspaceByDefaultOperator(ws *v1.Workspace) error { operator, err := NewValidDefaultOperator() if err != nil { return err @@ -168,7 +168,7 @@ func (o *Operator) GetWorkspaceNames() ([]string, error) { } // GetWorkspace gets the workspace by name. The validity of the returned workspace is not guaranteed. -func (o *Operator) GetWorkspace(name string) (*workspace.Workspace, error) { +func (o *Operator) GetWorkspace(name string) (*v1.Workspace, error) { if name == "" { return nil, ErrEmptyWorkspaceName } @@ -179,7 +179,7 @@ func (o *Operator) GetWorkspace(name string) (*workspace.Workspace, error) { return nil, fmt.Errorf("read workspace file failed: %w", err) } - ws := &workspace.Workspace{} + ws := &v1.Workspace{} if err = yaml.Unmarshal(content, ws); err != nil { return nil, fmt.Errorf("yaml unmarshal failed: %w", err) } @@ -188,7 +188,7 @@ func (o *Operator) GetWorkspace(name string) (*workspace.Workspace, error) { } // CreateWorkspace creates a workspace. The validation of workspace should be done before creating. -func (o *Operator) CreateWorkspace(ws *workspace.Workspace) error { +func (o *Operator) CreateWorkspace(ws *v1.Workspace) error { if ws == nil { return ErrEmptyWorkspace } @@ -201,7 +201,7 @@ func (o *Operator) CreateWorkspace(ws *workspace.Workspace) error { } // UpdateWorkspace updates a workspace.The validation of workspace should be done before updating. -func (o *Operator) UpdateWorkspace(ws *workspace.Workspace) error { +func (o *Operator) UpdateWorkspace(ws *v1.Workspace) error { if ws == nil { return ErrEmptyWorkspace } @@ -241,7 +241,7 @@ func (o *Operator) getWorkspaceFiles() ([]os.DirEntry, error) { return files, nil } -func (o *Operator) writeWorkspaceFile(ws *workspace.Workspace) error { +func (o *Operator) writeWorkspaceFile(ws *v1.Workspace) error { content, err := yaml.Marshal(ws) if err != nil { return fmt.Errorf("yaml marshal workspace failed: %w", err) diff --git a/pkg/workspace/operator_test.go b/pkg/workspace/operator_test.go index ec809c9b..2be98a6a 100644 --- a/pkg/workspace/operator_test.go +++ b/pkg/workspace/operator_test.go @@ -8,7 +8,7 @@ import ( "github.com/bytedance/mockey" "github.com/stretchr/testify/assert" - "kusionstack.io/kusion/pkg/apis/workspace" + "kusionstack.io/kusion/pkg/apis/core/v1" "kusionstack.io/kusion/pkg/util/kfile" ) @@ -141,7 +141,7 @@ func TestOperator_CreateWorkspace(t *testing.T) { name string success bool operator *Operator - ws *workspace.Workspace + ws *v1.Workspace }{ { name: "create workspace successfully", @@ -173,7 +173,7 @@ func TestOperator_UpdateWorkspace(t *testing.T) { name string success bool operator *Operator - ws *workspace.Workspace + ws *v1.Workspace }{ { name: "update workspace successfully", diff --git a/pkg/workspace/util.go b/pkg/workspace/util.go index d88a3ee4..ad356f6d 100644 --- a/pkg/workspace/util.go +++ b/pkg/workspace/util.go @@ -5,7 +5,7 @@ import ( "fmt" "os" - "kusionstack.io/kusion/pkg/apis/workspace" + "kusionstack.io/kusion/pkg/apis/core/v1" ) var ( @@ -21,11 +21,11 @@ var ( // CompleteWorkspace sets the workspace name and default value of unset item, should be called after ValidateWorkspace. // The config items set as environment variables are not got by CompleteWorkspace. -func CompleteWorkspace(ws *workspace.Workspace, name string) { +func CompleteWorkspace(ws *v1.Workspace, name string) { if ws.Name != "" { ws.Name = name } - if ws.Backends != nil && GetBackendName(ws.Backends) == workspace.BackendMysql { + if ws.Backends != nil && GetBackendName(ws.Backends) == v1.BackendMysql { CompleteMysqlConfig(ws.Backends.Mysql) } } @@ -33,7 +33,7 @@ func CompleteWorkspace(ws *workspace.Workspace, name string) { // GetProjectModuleConfigs returns the module configs of a specified project, whose key is the module name, // should be called after ValidateModuleConfigs. // If got empty module configs, ErrEmptyProjectModuleConfigs will get returned. -func GetProjectModuleConfigs(configs workspace.ModuleConfigs, projectName string) (map[string]workspace.GenericConfig, error) { +func GetProjectModuleConfigs(configs v1.ModuleConfigs, projectName string) (map[string]v1.GenericConfig, error) { if len(configs) == 0 { return nil, ErrEmptyModuleConfigs } @@ -41,7 +41,7 @@ func GetProjectModuleConfigs(configs workspace.ModuleConfigs, projectName string return nil, ErrEmptyProjectName } - projectCfgs := make(map[string]workspace.GenericConfig) + projectCfgs := make(map[string]v1.GenericConfig) for name, cfg := range configs { projectCfg, err := getProjectModuleConfig(cfg, projectName) if errors.Is(err, ErrEmptyProjectModuleConfig) { @@ -64,7 +64,7 @@ func GetProjectModuleConfigs(configs workspace.ModuleConfigs, projectName string // GetProjectModuleConfig returns the module config of a specified project, should be called after // ValidateModuleConfig. // If got empty module config, ErrEmptyProjectModuleConfig will get returned. -func GetProjectModuleConfig(config *workspace.ModuleConfig, projectName string) (workspace.GenericConfig, error) { +func GetProjectModuleConfig(config *v1.ModuleConfig, projectName string) (v1.GenericConfig, error) { if config == nil { return nil, ErrEmptyModuleConfig } @@ -77,14 +77,14 @@ func GetProjectModuleConfig(config *workspace.ModuleConfig, projectName string) // getProjectModuleConfig gets the module config of a specified project without checking the correctness // of project name. -func getProjectModuleConfig(config *workspace.ModuleConfig, projectName string) (workspace.GenericConfig, error) { +func getProjectModuleConfig(config *v1.ModuleConfig, projectName string) (v1.GenericConfig, error) { projectCfg := config.Default if len(projectCfg) == 0 { - projectCfg = make(workspace.GenericConfig) + projectCfg = make(v1.GenericConfig) } for name, cfg := range config.ModulePatcherConfigs { - if name == workspace.DefaultBlock { + if name == v1.DefaultBlock { continue } // check the project is assigned in the block or not. @@ -97,7 +97,7 @@ func getProjectModuleConfig(config *workspace.ModuleConfig, projectName string) } if contain { for k, v := range cfg.GenericConfig { - if k == workspace.ProjectSelectorField { + if k == v1.ProjectSelectorField { continue } projectCfg[k] = v @@ -115,7 +115,7 @@ func getProjectModuleConfig(config *workspace.ModuleConfig, projectName string) // GetKubernetesConfig returns kubernetes config from runtime config, should be called after // ValidateRuntimeConfigs. // If got empty kubernetes config, ErrEmptyKubernetesConfig will get returned. -func GetKubernetesConfig(configs *workspace.RuntimeConfigs) (*workspace.KubernetesConfig, error) { +func GetKubernetesConfig(configs *v1.RuntimeConfigs) (*v1.KubernetesConfig, error) { if configs == nil { return nil, ErrEmptyRuntimeConfigs } @@ -128,7 +128,7 @@ func GetKubernetesConfig(configs *workspace.RuntimeConfigs) (*workspace.Kubernet // GetTerraformConfig returns terraform config from runtime config, should be called after // ValidateRuntimeConfigs. // If got empty terraform config, ErrEmptyTerraformConfig will get returned. -func GetTerraformConfig(configs *workspace.RuntimeConfigs) (workspace.TerraformConfig, error) { +func GetTerraformConfig(configs *v1.RuntimeConfigs) (v1.TerraformConfig, error) { if configs == nil { return nil, ErrEmptyRuntimeConfigs } @@ -141,7 +141,7 @@ func GetTerraformConfig(configs *workspace.RuntimeConfigs) (workspace.TerraformC // GetProviderConfig returns the specified terraform provider config from runtime config, should be called // after ValidateRuntimeConfigs. // If got empty terraform config, ErrEmptyTerraformProviderConfig will get returned. -func GetProviderConfig(configs *workspace.RuntimeConfigs, providerName string) (*workspace.ProviderConfig, error) { +func GetProviderConfig(configs *v1.RuntimeConfigs, providerName string) (*v1.ProviderConfig, error) { if providerName == "" { return nil, ErrEmptyTerraformProviderName } @@ -159,54 +159,54 @@ func GetProviderConfig(configs *workspace.RuntimeConfigs, providerName string) ( // GetBackendName returns the backend name that is configured in BackendConfigs, should be called after // ValidateBackendConfigs. -func GetBackendName(configs *workspace.BackendConfigs) string { +func GetBackendName(configs *v1.BackendConfigs) string { if configs == nil { - return workspace.BackendLocal + return v1.BackendLocal } if configs.Local != nil { - return workspace.BackendLocal + return v1.BackendLocal } if configs.Mysql != nil { - return workspace.BackendMysql + return v1.BackendMysql } if configs.Oss != nil { - return workspace.BackendOss + return v1.BackendOss } if configs.S3 != nil { - return workspace.BackendS3 + return v1.BackendS3 } - return workspace.BackendLocal + return v1.BackendLocal } // GetMysqlPasswordFromEnv returns mysql password set by environment variables. func GetMysqlPasswordFromEnv() string { - return os.Getenv(workspace.EnvBackendMysqlPassword) + return os.Getenv(v1.EnvBackendMysqlPassword) } // GetOssSensitiveDataFromEnv returns oss accessKeyID, accessKeySecret set by environment variables. func GetOssSensitiveDataFromEnv() (string, string) { - return os.Getenv(workspace.EnvOssAccessKeyID), os.Getenv(workspace.EnvOssAccessKeySecret) + return os.Getenv(v1.EnvOssAccessKeyID), os.Getenv(v1.EnvOssAccessKeySecret) } // GetS3SensitiveDataFromEnv returns s3 accessKeyID, accessKeySecret, region set by environment variables. func GetS3SensitiveDataFromEnv() (string, string, string) { - region := os.Getenv(workspace.EnvAwsRegion) + region := os.Getenv(v1.EnvAwsRegion) if region == "" { - region = os.Getenv(workspace.EnvAwsDefaultRegion) + region = os.Getenv(v1.EnvAwsDefaultRegion) } - return os.Getenv(workspace.EnvAwsAccessKeyID), os.Getenv(workspace.EnvAwsSecretAccessKey), region + return os.Getenv(v1.EnvAwsAccessKeyID), os.Getenv(v1.EnvAwsSecretAccessKey), region } // CompleteMysqlConfig sets default value of mysql config if not set. -func CompleteMysqlConfig(config *workspace.MysqlConfig) { +func CompleteMysqlConfig(config *v1.MysqlConfig) { if config.Port == nil { - port := workspace.DefaultMysqlPort + port := v1.DefaultMysqlPort config.Port = &port } } // CompleteWholeMysqlConfig constructs the whole mysql config by environment variables if set. -func CompleteWholeMysqlConfig(config *workspace.MysqlConfig) { +func CompleteWholeMysqlConfig(config *v1.MysqlConfig) { password := GetMysqlPasswordFromEnv() if password != "" { config.Password = password @@ -214,7 +214,7 @@ func CompleteWholeMysqlConfig(config *workspace.MysqlConfig) { } // CompleteWholeOssConfig constructs the whole oss config by environment variables if set. -func CompleteWholeOssConfig(config *workspace.OssConfig) { +func CompleteWholeOssConfig(config *v1.OssConfig) { accessKeyID, accessKeySecret := GetOssSensitiveDataFromEnv() if accessKeyID != "" { config.AccessKeyID = accessKeyID @@ -225,7 +225,7 @@ func CompleteWholeOssConfig(config *workspace.OssConfig) { } // CompleteWholeS3Config constructs the whole s3 config by environment variables if set. -func CompleteWholeS3Config(config *workspace.S3Config) { +func CompleteWholeS3Config(config *v1.S3Config) { accessKeyID, accessKeySecret, region := GetS3SensitiveDataFromEnv() if accessKeyID != "" { config.AccessKeyID = accessKeyID diff --git a/pkg/workspace/util_test.go b/pkg/workspace/util_test.go index fc151834..e21d9fca 100644 --- a/pkg/workspace/util_test.go +++ b/pkg/workspace/util_test.go @@ -5,7 +5,7 @@ import ( "github.com/stretchr/testify/assert" - "kusionstack.io/kusion/pkg/apis/workspace" + "kusionstack.io/kusion/pkg/apis/core/v1" ) func Test_GetProjectModuleConfigs(t *testing.T) { @@ -13,14 +13,14 @@ func Test_GetProjectModuleConfigs(t *testing.T) { name string success bool projectName string - projectConfigs map[string]workspace.GenericConfig - moduleConfigs workspace.ModuleConfigs + projectConfigs map[string]v1.GenericConfig + moduleConfigs v1.ModuleConfigs }{ { name: "successfully get project module configs", success: true, projectName: "foo", - projectConfigs: map[string]workspace.GenericConfig{ + projectConfigs: map[string]v1.GenericConfig{ "database": { "type": "aws", "version": "5.7", @@ -48,14 +48,14 @@ func Test_GetProjectModuleConfig(t *testing.T) { name string success bool projectName string - projectConfig workspace.GenericConfig - moduleConfig *workspace.ModuleConfig + projectConfig v1.GenericConfig + moduleConfig *v1.ModuleConfig }{ { name: "successfully get default project module config", success: true, projectName: "baz", - projectConfig: workspace.GenericConfig{ + projectConfig: v1.GenericConfig{ "type": "aws", "version": "5.7", "instanceType": "db.t3.micro", @@ -66,7 +66,7 @@ func Test_GetProjectModuleConfig(t *testing.T) { name: "successfully get override project module config", success: true, projectName: "foo", - projectConfig: workspace.GenericConfig{ + projectConfig: v1.GenericConfig{ "type": "aws", "version": "5.7", "instanceType": "db.t3.small", @@ -95,8 +95,8 @@ func Test_GetKubernetesConfig(t *testing.T) { testcases := []struct { name string success bool - kubernetesConfig *workspace.KubernetesConfig - runtimeConfigs *workspace.RuntimeConfigs + kubernetesConfig *v1.KubernetesConfig + runtimeConfigs *v1.RuntimeConfigs }{ { name: "successfully get kubernetes config", @@ -120,17 +120,17 @@ func Test_GetTerraformProviderConfig(t *testing.T) { name string success bool providerName string - providerConfig *workspace.ProviderConfig - runtimeConfigs *workspace.RuntimeConfigs + providerConfig *v1.ProviderConfig + runtimeConfigs *v1.RuntimeConfigs }{ { name: "successfully get terraform provider config", success: true, providerName: "aws", - providerConfig: &workspace.ProviderConfig{ + providerConfig: &v1.ProviderConfig{ Source: "hashicorp/aws", Version: "1.0.4", - GenericConfig: workspace.GenericConfig{ + GenericConfig: v1.GenericConfig{ "region": "us-east-1", }, }, diff --git a/pkg/workspace/validation.go b/pkg/workspace/validation.go index 5afdc7ed..7d537028 100644 --- a/pkg/workspace/validation.go +++ b/pkg/workspace/validation.go @@ -4,7 +4,7 @@ import ( "errors" "fmt" - "kusionstack.io/kusion/pkg/apis/workspace" + "kusionstack.io/kusion/pkg/apis/core/v1" ) var ( @@ -44,7 +44,7 @@ var ( // ValidateWorkspace is used to validate the workspace get or set in the storage, and does not validate the // config which can get from environment variables, such as access key id in backend configs. -func ValidateWorkspace(ws *workspace.Workspace) error { +func ValidateWorkspace(ws *v1.Workspace) error { if ws.Name == "" { return ErrEmptyWorkspaceName } @@ -67,7 +67,7 @@ func ValidateWorkspace(ws *workspace.Workspace) error { } // ValidateModuleConfigs validates the moduleConfigs is valid or not. -func ValidateModuleConfigs(configs workspace.ModuleConfigs) error { +func ValidateModuleConfigs(configs v1.ModuleConfigs) error { for name, cfg := range configs { if name == "" { return ErrEmptyModuleName @@ -84,7 +84,7 @@ func ValidateModuleConfigs(configs workspace.ModuleConfigs) error { } // ValidateModuleConfig is used to validate the moduleConfig is valid or not. -func ValidateModuleConfig(config *workspace.ModuleConfig) error { +func ValidateModuleConfig(config *v1.ModuleConfig) error { if err := ValidateModuleDefaultConfig(config.Default); err != nil { return err } @@ -94,17 +94,17 @@ func ValidateModuleConfig(config *workspace.ModuleConfig) error { return nil } -func ValidateModuleDefaultConfig(config workspace.GenericConfig) error { +func ValidateModuleDefaultConfig(config v1.GenericConfig) error { if len(config) == 0 { - return fmt.Errorf("%w, block name: %s", ErrEmptyModuleConfigBlock, workspace.DefaultBlock) + return fmt.Errorf("%w, block name: %s", ErrEmptyModuleConfigBlock, v1.DefaultBlock) } - if _, ok := config[workspace.ProjectSelectorField]; ok { + if _, ok := config[v1.ProjectSelectorField]; ok { return ErrNotEmptyModuleConfigProjectSelector } return nil } -func ValidateModulePatcherConfigs(config workspace.ModulePatcherConfigs) error { +func ValidateModulePatcherConfigs(config v1.ModulePatcherConfigs) error { // allProjects is used to inspect if there are repeated projects in projectSelector // field or not. allProjects := make(map[string]string) @@ -114,7 +114,7 @@ func ValidateModulePatcherConfigs(config workspace.ModulePatcherConfigs) error { return ErrEmptyModuleConfigPatcherBlockName // name of patcher block must not be default. - case workspace.DefaultBlock: + case v1.DefaultBlock: return ErrInvalidModuleConfigPatcherBlockName // repeated projects in different patcher blocks are not allowed. @@ -152,7 +152,7 @@ func ValidateModulePatcherConfigs(config workspace.ModulePatcherConfigs) error { } // ValidateRuntimeConfigs is used to validate the runtimeConfigs is valid or not. -func ValidateRuntimeConfigs(configs *workspace.RuntimeConfigs) error { +func ValidateRuntimeConfigs(configs *v1.RuntimeConfigs) error { if configs.Kubernetes != nil { if err := ValidateKubernetesConfig(configs.Kubernetes); err != nil { return err @@ -167,7 +167,7 @@ func ValidateRuntimeConfigs(configs *workspace.RuntimeConfigs) error { } // ValidateKubernetesConfig is used to validate the kubernetesConfig is valid or not. -func ValidateKubernetesConfig(config *workspace.KubernetesConfig) error { +func ValidateKubernetesConfig(config *v1.KubernetesConfig) error { if config.KubeConfig == "" { return ErrEmptyKubeConfig } @@ -175,7 +175,7 @@ func ValidateKubernetesConfig(config *workspace.KubernetesConfig) error { } // ValidateTerraformConfig is used to validate the terraformConfig is valid or not. -func ValidateTerraformConfig(config workspace.TerraformConfig) error { +func ValidateTerraformConfig(config v1.TerraformConfig) error { for name, cfg := range config { if name == "" { return ErrEmptyTerraformProviderName @@ -191,7 +191,7 @@ func ValidateTerraformConfig(config workspace.TerraformConfig) error { } // ValidateProviderConfig is used to validate the providerConfig is valid or not. -func ValidateProviderConfig(config *workspace.ProviderConfig) error { +func ValidateProviderConfig(config *v1.ProviderConfig) error { if config.Source == "" { return ErrEmptyTerraformProviderSource } @@ -211,7 +211,7 @@ func ValidateProviderConfig(config *workspace.ProviderConfig) error { // ValidateBackendConfigs is used to validate backendConfigs is valid or not, and does not validate the // configs which can get from environment variables, such as access key id, etc. -func ValidateBackendConfigs(configs *workspace.BackendConfigs) error { +func ValidateBackendConfigs(configs *v1.BackendConfigs) error { if configureMoreThanOneBackend(configs) { return ErrMultipleBackends } @@ -223,13 +223,13 @@ func ValidateBackendConfigs(configs *workspace.BackendConfigs) error { } if configs.Oss != nil { if err := ValidateGenericObjectStorageConfig(&configs.Oss.GenericObjectStorageConfig); err != nil { - return fmt.Errorf("%w of %s", err, workspace.BackendOss) + return fmt.Errorf("%w of %s", err, v1.BackendOss) } return nil } if configs.S3 != nil { if err := ValidateGenericObjectStorageConfig(&configs.S3.GenericObjectStorageConfig); err != nil { - return fmt.Errorf("%w of %s", err, workspace.BackendS3) + return fmt.Errorf("%w of %s", err, v1.BackendS3) } return nil } @@ -237,7 +237,7 @@ func ValidateBackendConfigs(configs *workspace.BackendConfigs) error { } // configureMoreThanOneBackend checks whether there are more than one backend configured. -func configureMoreThanOneBackend(configs *workspace.BackendConfigs) bool { +func configureMoreThanOneBackend(configs *v1.BackendConfigs) bool { // configCondition returns: 1, if the backend configured or not; 2, if configured more than one backend. configCondition := func(configured bool, hasNewConfig bool) (bool, bool) { return configured || hasNewConfig, configured && hasNewConfig @@ -258,7 +258,7 @@ func configureMoreThanOneBackend(configs *workspace.BackendConfigs) bool { } // ValidateMysqlConfig is used to validate mysqlConfig is valid or not. -func ValidateMysqlConfig(config *workspace.MysqlConfig) error { +func ValidateMysqlConfig(config *v1.MysqlConfig) error { if config.DBName == "" { return ErrEmptyMysqlDBName } @@ -276,7 +276,7 @@ func ValidateMysqlConfig(config *workspace.MysqlConfig) error { // ValidateGenericObjectStorageConfig is used to validate ossConfig and s3Config is valid or not, where the // sensitive data items set as environment variables are not included. -func ValidateGenericObjectStorageConfig(config *workspace.GenericObjectStorageConfig) error { +func ValidateGenericObjectStorageConfig(config *v1.GenericObjectStorageConfig) error { if config.Bucket == "" { return ErrEmptyBucket } @@ -285,9 +285,9 @@ func ValidateGenericObjectStorageConfig(config *workspace.GenericObjectStorageCo // ValidateWholeOssConfig is used to validate ossConfig is valid or not, where all the items are included. // If valid, the config contains all valid items to new an oss client. -func ValidateWholeOssConfig(config *workspace.OssConfig) error { +func ValidateWholeOssConfig(config *v1.OssConfig) error { if err := validateWholeGenericObjectStorageConfig(&config.GenericObjectStorageConfig); err != nil { - return fmt.Errorf("%w of %s", err, workspace.BackendOss) + return fmt.Errorf("%w of %s", err, v1.BackendOss) } if config.Endpoint == "" { return ErrEmptyOssEndpoint @@ -297,9 +297,9 @@ func ValidateWholeOssConfig(config *workspace.OssConfig) error { // ValidateWholeS3Config is used to validate s3Config is valid or not, where all the items are included. // If valid, the config contains all valid items to new a s3 client. -func ValidateWholeS3Config(config *workspace.S3Config) error { +func ValidateWholeS3Config(config *v1.S3Config) error { if err := validateWholeGenericObjectStorageConfig(&config.GenericObjectStorageConfig); err != nil { - return fmt.Errorf("%w of %s", err, workspace.BackendS3) + return fmt.Errorf("%w of %s", err, v1.BackendS3) } if config.Region == "" { return ErrEmptyS3Region @@ -307,7 +307,7 @@ func ValidateWholeS3Config(config *workspace.S3Config) error { return nil } -func validateWholeGenericObjectStorageConfig(config *workspace.GenericObjectStorageConfig) error { +func validateWholeGenericObjectStorageConfig(config *v1.GenericObjectStorageConfig) error { if err := ValidateGenericObjectStorageConfig(config); err != nil { return err } diff --git a/pkg/workspace/validation_test.go b/pkg/workspace/validation_test.go index 5f5994f4..f8dae81a 100644 --- a/pkg/workspace/validation_test.go +++ b/pkg/workspace/validation_test.go @@ -5,11 +5,11 @@ import ( "github.com/stretchr/testify/assert" - "kusionstack.io/kusion/pkg/apis/workspace" + "kusionstack.io/kusion/pkg/apis/core/v1" ) -func mockValidWorkspace(name string) *workspace.Workspace { - return &workspace.Workspace{ +func mockValidWorkspace(name string) *v1.Workspace { + return &v1.Workspace{ Name: name, Modules: mockValidModuleConfigs(), Runtimes: mockValidRuntimeConfigs(), @@ -17,17 +17,17 @@ func mockValidWorkspace(name string) *workspace.Workspace { } } -func mockValidModuleConfigs() map[string]*workspace.ModuleConfig { - return map[string]*workspace.ModuleConfig{ +func mockValidModuleConfigs() map[string]*v1.ModuleConfig { + return map[string]*v1.ModuleConfig{ "database": { - Default: workspace.GenericConfig{ + Default: v1.GenericConfig{ "type": "aws", "version": "5.7", "instanceType": "db.t3.micro", }, - ModulePatcherConfigs: workspace.ModulePatcherConfigs{ + ModulePatcherConfigs: v1.ModulePatcherConfigs{ "smallClass": { - GenericConfig: workspace.GenericConfig{ + GenericConfig: v1.GenericConfig{ "instanceType": "db.t3.small", }, ProjectSelector: []string{"foo", "bar"}, @@ -35,20 +35,20 @@ func mockValidModuleConfigs() map[string]*workspace.ModuleConfig { }, }, "port": { - Default: workspace.GenericConfig{ + Default: v1.GenericConfig{ "type": "aws", }, }, } } -func mockInvalidModuleConfigs() map[string]workspace.ModuleConfig { - return map[string]workspace.ModuleConfig{ +func mockInvalidModuleConfigs() map[string]v1.ModuleConfig { + return map[string]v1.ModuleConfig{ "empty default block": { - Default: workspace.GenericConfig{}, + Default: v1.GenericConfig{}, }, "not empty projectSelector in default block": { - Default: workspace.GenericConfig{ + Default: v1.GenericConfig{ "type": "aws", "version": "5.7", "instanceType": "db.t3.micro", @@ -56,14 +56,14 @@ func mockInvalidModuleConfigs() map[string]workspace.ModuleConfig { }, }, "empty patcher block name": { - Default: workspace.GenericConfig{ + Default: v1.GenericConfig{ "type": "aws", "version": "5.7", "instanceType": "db.t3.micro", }, - ModulePatcherConfigs: workspace.ModulePatcherConfigs{ + ModulePatcherConfigs: v1.ModulePatcherConfigs{ "": { - GenericConfig: workspace.GenericConfig{ + GenericConfig: v1.GenericConfig{ "instanceType": "db.t3.small", }, ProjectSelector: []string{"foo", "bar"}, @@ -71,50 +71,50 @@ func mockInvalidModuleConfigs() map[string]workspace.ModuleConfig { }, }, "empty patcher block": { - Default: workspace.GenericConfig{ + Default: v1.GenericConfig{ "type": "aws", "version": "5.7", "instanceType": "db.t3.micro", }, - ModulePatcherConfigs: workspace.ModulePatcherConfigs{ + ModulePatcherConfigs: v1.ModulePatcherConfigs{ "smallClass": nil, }, }, "empty config in patcher block": { - Default: workspace.GenericConfig{ + Default: v1.GenericConfig{ "type": "aws", "version": "5.7", "instanceType": "db.t3.micro", }, - ModulePatcherConfigs: workspace.ModulePatcherConfigs{ + ModulePatcherConfigs: v1.ModulePatcherConfigs{ "smallClass": { ProjectSelector: []string{"foo", "bar"}, }, }, }, "empty project selector in patcher block": { - Default: workspace.GenericConfig{ + Default: v1.GenericConfig{ "type": "aws", "version": "5.7", "instanceType": "db.t3.micro", }, - ModulePatcherConfigs: workspace.ModulePatcherConfigs{ + ModulePatcherConfigs: v1.ModulePatcherConfigs{ "smallClass": { - GenericConfig: workspace.GenericConfig{ + GenericConfig: v1.GenericConfig{ "instanceType": "db.t3.small", }, }, }, }, "empty project name": { - Default: workspace.GenericConfig{ + Default: v1.GenericConfig{ "type": "aws", "version": "5.7", "instanceType": "db.t3.micro", }, - ModulePatcherConfigs: workspace.ModulePatcherConfigs{ + ModulePatcherConfigs: v1.ModulePatcherConfigs{ "smallClass": { - GenericConfig: workspace.GenericConfig{ + GenericConfig: v1.GenericConfig{ "instanceType": "db.t3.small", }, ProjectSelector: []string{"", "bar"}, @@ -122,14 +122,14 @@ func mockInvalidModuleConfigs() map[string]workspace.ModuleConfig { }, }, "repeated projects in one patcher block": { - Default: workspace.GenericConfig{ + Default: v1.GenericConfig{ "type": "aws", "version": "5.7", "instanceType": "db.t3.micro", }, - ModulePatcherConfigs: workspace.ModulePatcherConfigs{ + ModulePatcherConfigs: v1.ModulePatcherConfigs{ "smallClass": { - GenericConfig: workspace.GenericConfig{ + GenericConfig: v1.GenericConfig{ "instanceType": "db.t3.small", }, ProjectSelector: []string{"foo", "foo"}, @@ -137,20 +137,20 @@ func mockInvalidModuleConfigs() map[string]workspace.ModuleConfig { }, }, "repeated projects in multiple patcher blocks": { - Default: workspace.GenericConfig{ + Default: v1.GenericConfig{ "type": "aws", "version": "5.7", "instanceType": "db.t3.micro", }, - ModulePatcherConfigs: workspace.ModulePatcherConfigs{ + ModulePatcherConfigs: v1.ModulePatcherConfigs{ "smallClass": { - GenericConfig: workspace.GenericConfig{ + GenericConfig: v1.GenericConfig{ "instanceType": "db.t3.small", }, ProjectSelector: []string{"foo", "bar"}, }, "largeClass": { - GenericConfig: workspace.GenericConfig{ + GenericConfig: v1.GenericConfig{ "instanceType": "db.t3.large", }, ProjectSelector: []string{"foo"}, @@ -160,54 +160,54 @@ func mockInvalidModuleConfigs() map[string]workspace.ModuleConfig { } } -func mockValidRuntimeConfigs() *workspace.RuntimeConfigs { - return &workspace.RuntimeConfigs{ +func mockValidRuntimeConfigs() *v1.RuntimeConfigs { + return &v1.RuntimeConfigs{ Kubernetes: mockValidKubernetesConfig(), Terraform: mockValidTerraformConfig(), } } -func mockValidKubernetesConfig() *workspace.KubernetesConfig { - return &workspace.KubernetesConfig{ +func mockValidKubernetesConfig() *v1.KubernetesConfig { + return &v1.KubernetesConfig{ KubeConfig: "/etc/kubeconfig.yaml", } } -func mockValidTerraformConfig() workspace.TerraformConfig { - return workspace.TerraformConfig{ +func mockValidTerraformConfig() v1.TerraformConfig { + return v1.TerraformConfig{ "aws": { Source: "hashicorp/aws", Version: "1.0.4", - GenericConfig: workspace.GenericConfig{ + GenericConfig: v1.GenericConfig{ "region": "us-east-1", }, }, } } -func mockValidBackendConfigs() *workspace.BackendConfigs { - return &workspace.BackendConfigs{ - Local: &workspace.LocalFileConfig{}, +func mockValidBackendConfigs() *v1.BackendConfigs { + return &v1.BackendConfigs{ + Local: &v1.LocalFileConfig{}, } } -func mockValidMysqlConfig() *workspace.MysqlConfig { - return &workspace.MysqlConfig{ +func mockValidMysqlConfig() *v1.MysqlConfig { + return &v1.MysqlConfig{ DBName: "kusion_db", User: "kusion", Host: "127.0.0.1", } } -func mockValidGenericObjectStorageConfig() *workspace.GenericObjectStorageConfig { - return &workspace.GenericObjectStorageConfig{ +func mockValidGenericObjectStorageConfig() *v1.GenericObjectStorageConfig { + return &v1.GenericObjectStorageConfig{ Bucket: "kusion_bucket", } } -func mockValidCompletedOssConfig() *workspace.OssConfig { - return &workspace.OssConfig{ - GenericObjectStorageConfig: workspace.GenericObjectStorageConfig{ +func mockValidCompletedOssConfig() *v1.OssConfig { + return &v1.OssConfig{ + GenericObjectStorageConfig: v1.GenericObjectStorageConfig{ Endpoint: "http://oss-cn-hangzhou.aliyuncs.com", AccessKeyID: "fake-access-key-id", AccessKeySecret: "fake-access-key-secret", @@ -216,9 +216,9 @@ func mockValidCompletedOssConfig() *workspace.OssConfig { } } -func mockValidCompletedS3Config() *workspace.S3Config { - return &workspace.S3Config{ - GenericObjectStorageConfig: workspace.GenericObjectStorageConfig{ +func mockValidCompletedS3Config() *v1.S3Config { + return &v1.S3Config{ + GenericObjectStorageConfig: v1.GenericObjectStorageConfig{ AccessKeyID: "fake-access-key-id", AccessKeySecret: "fake-access-key-secret", Bucket: "kusion_bucket", @@ -231,7 +231,7 @@ func TestValidateWorkspace(t *testing.T) { testcases := []struct { name string success bool - workspace *workspace.Workspace + workspace *v1.Workspace }{ { name: "valid workspace", @@ -241,7 +241,7 @@ func TestValidateWorkspace(t *testing.T) { { name: "invalid workspace empty name", success: false, - workspace: &workspace.Workspace{}, + workspace: &v1.Workspace{}, }, } @@ -257,7 +257,7 @@ func TestValidateModuleConfigs(t *testing.T) { testcases := []struct { name string success bool - moduleConfigs workspace.ModuleConfigs + moduleConfigs v1.ModuleConfigs }{ { name: "valid module configs", @@ -267,14 +267,14 @@ func TestValidateModuleConfigs(t *testing.T) { { name: "invalid module configs empty module name", success: false, - moduleConfigs: workspace.ModuleConfigs{ + moduleConfigs: v1.ModuleConfigs{ "": mockValidModuleConfigs()["database"], }, }, { name: "invalid module configs empty module config", success: false, - moduleConfigs: workspace.ModuleConfigs{ + moduleConfigs: v1.ModuleConfigs{ "database": nil, }, }, @@ -292,7 +292,7 @@ func TestValidateModuleConfig(t *testing.T) { testcases := []struct { name string success bool - moduleConfig workspace.ModuleConfig + moduleConfig v1.ModuleConfig }{ { name: "valid module config", @@ -304,7 +304,7 @@ func TestValidateModuleConfig(t *testing.T) { testcases = append(testcases, struct { name string success bool - moduleConfig workspace.ModuleConfig + moduleConfig v1.ModuleConfig }{ name: "invalid module config " + desc, success: false, @@ -324,7 +324,7 @@ func TestValidateRuntimeConfigs(t *testing.T) { testcases := []struct { name string success bool - runtimeConfigs *workspace.RuntimeConfigs + runtimeConfigs *v1.RuntimeConfigs }{ { name: "valid runtime configs", @@ -345,7 +345,7 @@ func TestValidateKubernetesConfig(t *testing.T) { testcases := []struct { name string success bool - kubernetesConfig *workspace.KubernetesConfig + kubernetesConfig *v1.KubernetesConfig }{ { name: "valid kubernetes config", @@ -355,7 +355,7 @@ func TestValidateKubernetesConfig(t *testing.T) { { name: "invalid kubernetes config empty kubeconfig", success: false, - kubernetesConfig: &workspace.KubernetesConfig{}, + kubernetesConfig: &v1.KubernetesConfig{}, }, } @@ -371,7 +371,7 @@ func TestValidateTerraformConfig(t *testing.T) { testcases := []struct { name string success bool - terraformConfig workspace.TerraformConfig + terraformConfig v1.TerraformConfig }{ { name: "valid terraform config", @@ -381,11 +381,11 @@ func TestValidateTerraformConfig(t *testing.T) { { name: "invalid terraform config empty provider name", success: false, - terraformConfig: workspace.TerraformConfig{ + terraformConfig: v1.TerraformConfig{ "": { Source: "hashicorp/aws", Version: "1.0.4", - GenericConfig: workspace.GenericConfig{ + GenericConfig: v1.GenericConfig{ "region": "us-east-1", }, }, @@ -394,18 +394,18 @@ func TestValidateTerraformConfig(t *testing.T) { { name: "invalid terraform config empty provider config", success: false, - terraformConfig: workspace.TerraformConfig{ + terraformConfig: v1.TerraformConfig{ "aws": nil, }, }, { name: "invalid terraform config empty provider source", success: false, - terraformConfig: workspace.TerraformConfig{ + terraformConfig: v1.TerraformConfig{ "aws": { Source: "", Version: "1.0.4", - GenericConfig: workspace.GenericConfig{ + GenericConfig: v1.GenericConfig{ "region": "us-east-1", }, }, @@ -414,11 +414,11 @@ func TestValidateTerraformConfig(t *testing.T) { { name: "invalid terraform config empty provider version", success: false, - terraformConfig: workspace.TerraformConfig{ + terraformConfig: v1.TerraformConfig{ "aws": { Source: "hashicorp/aws", Version: "", - GenericConfig: workspace.GenericConfig{ + GenericConfig: v1.GenericConfig{ "region": "us-east-1", }, }, @@ -427,11 +427,11 @@ func TestValidateTerraformConfig(t *testing.T) { { name: "invalid terraform config empty provider config key", success: false, - terraformConfig: workspace.TerraformConfig{ + terraformConfig: v1.TerraformConfig{ "aws": { Source: "hashicorp/aws", Version: "1.0.4", - GenericConfig: workspace.GenericConfig{ + GenericConfig: v1.GenericConfig{ "": "us-east-1", }, }, @@ -440,11 +440,11 @@ func TestValidateTerraformConfig(t *testing.T) { { name: "invalid terraform config empty provider config value", success: false, - terraformConfig: workspace.TerraformConfig{ + terraformConfig: v1.TerraformConfig{ "aws": { Source: "hashicorp/aws", Version: "1.0.4", - GenericConfig: workspace.GenericConfig{ + GenericConfig: v1.GenericConfig{ "region": nil, }, }, @@ -464,7 +464,7 @@ func TestValidateBackendConfigs(t *testing.T) { testcases := []struct { name string success bool - backendConfigs *workspace.BackendConfigs + backendConfigs *v1.BackendConfigs }{ { name: "valid backend configs", @@ -474,9 +474,9 @@ func TestValidateBackendConfigs(t *testing.T) { { name: "invalid backend configs multiple backends", success: false, - backendConfigs: &workspace.BackendConfigs{ - Local: &workspace.LocalFileConfig{}, - Mysql: &workspace.MysqlConfig{ + backendConfigs: &v1.BackendConfigs{ + Local: &v1.LocalFileConfig{}, + Mysql: &v1.MysqlConfig{ DBName: "test", }, }, @@ -496,7 +496,7 @@ func TestValidateMysqlConfig(t *testing.T) { testcases := []struct { name string success bool - mysqlConfig *workspace.MysqlConfig + mysqlConfig *v1.MysqlConfig }{ { name: "valid mysql config", @@ -506,7 +506,7 @@ func TestValidateMysqlConfig(t *testing.T) { { name: "invalid mysql config empty dbName", success: false, - mysqlConfig: &workspace.MysqlConfig{ + mysqlConfig: &v1.MysqlConfig{ DBName: "", User: "kusion", Host: "127.0.0.1", @@ -515,7 +515,7 @@ func TestValidateMysqlConfig(t *testing.T) { { name: "invalid mysql config empty user", success: false, - mysqlConfig: &workspace.MysqlConfig{ + mysqlConfig: &v1.MysqlConfig{ DBName: "kusion_db", User: "", Host: "127.0.0.1", @@ -524,7 +524,7 @@ func TestValidateMysqlConfig(t *testing.T) { { name: "invalid mysql config empty host", success: false, - mysqlConfig: &workspace.MysqlConfig{ + mysqlConfig: &v1.MysqlConfig{ DBName: "kusion_db", User: "kusion", Host: "", @@ -533,7 +533,7 @@ func TestValidateMysqlConfig(t *testing.T) { { name: "invalid mysql config invalid port", success: false, - mysqlConfig: &workspace.MysqlConfig{ + mysqlConfig: &v1.MysqlConfig{ DBName: "kusion_db", User: "kusion", Host: "127.0.0.1", @@ -554,7 +554,7 @@ func TestValidateValidateGenericObjectStorageConfig(t *testing.T) { testcases := []struct { name string success bool - config *workspace.GenericObjectStorageConfig + config *v1.GenericObjectStorageConfig }{ { name: "valid generic object storage config", @@ -564,7 +564,7 @@ func TestValidateValidateGenericObjectStorageConfig(t *testing.T) { { name: "invalid generic object storage config empty bucket", success: false, - config: &workspace.GenericObjectStorageConfig{}, + config: &v1.GenericObjectStorageConfig{}, }, } @@ -580,7 +580,7 @@ func TestValidateWholeOssConfig(t *testing.T) { testcases := []struct { name string success bool - ossConfig *workspace.OssConfig + ossConfig *v1.OssConfig }{ { name: "valid oss config", @@ -590,8 +590,8 @@ func TestValidateWholeOssConfig(t *testing.T) { { name: "invalid oss config empty endpoint", success: false, - ossConfig: &workspace.OssConfig{ - GenericObjectStorageConfig: workspace.GenericObjectStorageConfig{ + ossConfig: &v1.OssConfig{ + GenericObjectStorageConfig: v1.GenericObjectStorageConfig{ Endpoint: "", AccessKeyID: "fake-access-key-id", AccessKeySecret: "fake-access-key-secret", @@ -602,8 +602,8 @@ func TestValidateWholeOssConfig(t *testing.T) { { name: "invalid oss config empty access key id", success: false, - ossConfig: &workspace.OssConfig{ - GenericObjectStorageConfig: workspace.GenericObjectStorageConfig{ + ossConfig: &v1.OssConfig{ + GenericObjectStorageConfig: v1.GenericObjectStorageConfig{ Endpoint: "http://oss-cn-hangzhou.aliyuncs.com", AccessKeyID: "", AccessKeySecret: "fake-access-key-secret", @@ -614,8 +614,8 @@ func TestValidateWholeOssConfig(t *testing.T) { { name: "invalid oss config empty access key secret", success: false, - ossConfig: &workspace.OssConfig{ - GenericObjectStorageConfig: workspace.GenericObjectStorageConfig{ + ossConfig: &v1.OssConfig{ + GenericObjectStorageConfig: v1.GenericObjectStorageConfig{ Endpoint: "http://oss-cn-hangzhou.aliyuncs.com", AccessKeyID: "fake-access-key-id", AccessKeySecret: "", @@ -637,7 +637,7 @@ func TestValidateWholeS3Config(t *testing.T) { testcases := []struct { name string success bool - s3Config *workspace.S3Config + s3Config *v1.S3Config }{ { name: "valid s3 config", @@ -647,8 +647,8 @@ func TestValidateWholeS3Config(t *testing.T) { { name: "invalid s3 config empty region", success: false, - s3Config: &workspace.S3Config{ - GenericObjectStorageConfig: workspace.GenericObjectStorageConfig{ + s3Config: &v1.S3Config{ + GenericObjectStorageConfig: v1.GenericObjectStorageConfig{ AccessKeyID: "fake-access-key-id", AccessKeySecret: "fake-access-key-secret", Bucket: "kusion_bucket", diff --git a/test/e2e/e2e_suite_test.go b/test/e2e/e2e_suite_test.go index aabce5cd..762cac0f 100644 --- a/test/e2e/e2e_suite_test.go +++ b/test/e2e/e2e_suite_test.go @@ -8,7 +8,7 @@ import ( "github.com/onsi/ginkgo/v2" "github.com/onsi/gomega" - workspaceapi "kusionstack.io/kusion/pkg/apis/workspace" + "kusionstack.io/kusion/pkg/apis/core/v1" "kusionstack.io/kusion/pkg/workspace" ) @@ -83,18 +83,18 @@ func createSampleWorkspace() error { if err != nil { return err } - ws := &workspaceapi.Workspace{ + ws := &v1.Workspace{ Name: "dev", - Modules: workspaceapi.ModuleConfigs{ + Modules: v1.ModuleConfigs{ "database": { - Default: workspaceapi.GenericConfig{ + Default: v1.GenericConfig{ "type": "aws", "version": "5.7", "instanceType": "db.t3.micro", }, - ModulePatcherConfigs: workspaceapi.ModulePatcherConfigs{ + ModulePatcherConfigs: v1.ModulePatcherConfigs{ "smallClass": { - GenericConfig: workspaceapi.GenericConfig{ + GenericConfig: v1.GenericConfig{ "instanceType": "db.t3.small", }, ProjectSelector: []string{"foo", "bar"}, @@ -102,7 +102,7 @@ func createSampleWorkspace() error { }, }, "port": { - Default: workspaceapi.GenericConfig{ + Default: v1.GenericConfig{ "type": "aws", }, },