Skip to content

Commit

Permalink
feat: add configs in the workspace mod definition
Browse files Browse the repository at this point in the history
  • Loading branch information
SparkYuan committed Apr 24, 2024
1 parent e77a5fd commit 28c395d
Show file tree
Hide file tree
Showing 12 changed files with 314 additions and 240 deletions.
17 changes: 13 additions & 4 deletions pkg/apis/api.kusion.io/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ type Workspace struct {
}

// ModuleConfigs is a set of multiple ModuleConfig, whose key is the module name.
// The module name format is "source@version".
type ModuleConfigs map[string]*ModuleConfig

// GenericConfig is a generic model to describe config which shields the difference among multiple concrete
Expand All @@ -113,9 +112,11 @@ type GenericConfig map[string]any
// 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:
// Take the ModuleConfig of "mysql" for an example, which is shown as below:
//
// config := ModuleConfig {
// config := ModuleConfig {
// "path": "ghcr.io/kusionstack/mysql"
// "version": "0.1.0"
// "default": {
// "type": "aws",
// "version": "5.7",
Expand All @@ -127,9 +128,17 @@ type GenericConfig map[string]any
// },
// }
type ModuleConfig struct {
// Path is the path of the module. It can be a local path or a remote URL
Path string `yaml:"path" json:"path"`
// Version is the version of the module.
Version string `yaml:"version" json:"version"`
// Configs contains all levels of module configs
Configs Configs `yaml:"configs" json:"configs"`
}

type Configs 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"`
}
Expand Down
30 changes: 17 additions & 13 deletions pkg/cmd/workspace/util/testdata/valid_ws.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
modules:
database:
default:
instanceType: db.t3.micro
type: aws
version: "5.7"
smallClass:
projectSelector:
- foo
- bar
instanceType: db.t3.small
port:
default:
type: aws
mysql:
path: ghcr.io/kusionstack/mysql
version: 0.1.0
configs:
default:
instanceType: db.t3.micro
type: aws
version: '5.7'
smallClass:
projectSelector:
- foo
- bar
instanceType: db.t3.small
network:
configs:
default:
type: aws
runtimes:
kubernetes:
kubeConfig: /etc/kubeconfig.yaml
Expand Down
42 changes: 25 additions & 17 deletions pkg/modules/generators/app_configurations_generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,29 +184,37 @@ func buildMockWorkspace(namespace string) *v1.Workspace {
return &v1.Workspace{
Name: "test",
Modules: v1.ModuleConfigs{
"kusionstack/database@v0.1": {
Default: v1.GenericConfig{
"type": "aws",
"version": "5.7",
"instanceType": "db.t3.micro",
},
ModulePatcherConfigs: v1.ModulePatcherConfigs{
"smallClass": {
GenericConfig: v1.GenericConfig{
"instanceType": "db.t3.small",
"mysql": &v1.ModuleConfig{
Path: "kusionstack.io/mysql",
Version: "v1.0.0",
Configs: v1.Configs{
Default: v1.GenericConfig{
"type": "aws",
"version": "5.7",
"instanceType": "db.t3.micro",
},
ModulePatcherConfigs: v1.ModulePatcherConfigs{
"smallClass": {
GenericConfig: v1.GenericConfig{
"instanceType": "db.t3.small",
},
ProjectSelector: []string{"foo", "bar"},
},
ProjectSelector: []string{"foo", "bar"},
},
},
},
"port": {
Default: v1.GenericConfig{
"type": "aws",
"port": &v1.ModuleConfig{
Configs: v1.Configs{
Default: v1.GenericConfig{
"type": "aws",
},
},
},
"namespace": {
Default: v1.GenericConfig{
"name": namespace,
"namespace": &v1.ModuleConfig{
Configs: v1.Configs{
Default: v1.GenericConfig{
"name": namespace,
},
},
},
},
Expand Down
78 changes: 44 additions & 34 deletions pkg/workspace/storages/local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,30 @@ func mockWorkspace(name string) *v1.Workspace {
return &v1.Workspace{
Name: name,
Modules: map[string]*v1.ModuleConfig{
"database": {
Default: v1.GenericConfig{
"type": "aws",
"version": "5.7",
"instanceType": "db.t3.micro",
},
ModulePatcherConfigs: v1.ModulePatcherConfigs{
"smallClass": {
GenericConfig: v1.GenericConfig{
"instanceType": "db.t3.small",
"mysql": {
Path: "ghcr.io/kusionstack/mysql",
Version: "0.1.0",
Configs: v1.Configs{
Default: v1.GenericConfig{
"type": "aws",
"version": "5.7",
"instanceType": "db.t3.micro",
},
ModulePatcherConfigs: v1.ModulePatcherConfigs{
"smallClass": {
GenericConfig: v1.GenericConfig{
"instanceType": "db.t3.small",
},
ProjectSelector: []string{"foo", "bar"},
},
ProjectSelector: []string{"foo", "bar"},
},
},
},
"port": {
Default: v1.GenericConfig{
"type": "aws",
"network": {
Configs: v1.Configs{
Default: v1.GenericConfig{
"type": "aws",
},
},
},
},
Expand All @@ -60,27 +66,31 @@ func mockWorkspace(name string) *v1.Workspace {
func mockWorkspaceContent() string {
return `
modules:
database:
default:
instanceType: db.t3.micro
type: aws
version: "5.7"
smallClass:
projectSelector:
- foo
- bar
instanceType: db.t3.small
port:
default:
type: aws
mysql:
path: ghcr.io/kusionstack/mysql
version: 0.1.0
configs:
default:
instanceType: db.t3.micro
type: aws
version: '5.7'
smallClass:
projectSelector:
- foo
- bar
instanceType: db.t3.small
network:
configs:
default:
type: aws
runtimes:
kubernetes:
kubeConfig: /etc/kubeconfig.yaml
terraform:
aws:
source: hashicorp/aws
version: 1.0.4
region: us-east-1
kubernetes:
kubeConfig: /etc/kubeconfig.yaml
terraform:
aws:
source: hashicorp/aws
version: 1.0.4
region: us-east-1
`
}

Expand Down
32 changes: 19 additions & 13 deletions pkg/workspace/storages/testdata/for_delete_workspaces/dev.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
modules:
database:
default:
instanceType: db.t3.micro
type: aws
version: "5.7"
smallClass:
projectSelector:
- foo
- bar
instanceType: db.t3.small
port:
default:
type: aws
mysql:
path: ghcr.io/kusionstack/mysql
version: 0.1.0
configs:
default:
instanceType: db.t3.micro
type: aws
version: "5.7"
smallClass:
projectSelector:
- foo
- bar
instanceType: db.t3.small
network:
path: ""
version: ""
configs:
default:
type: aws
runtimes:
kubernetes:
kubeConfig: /etc/kubeconfig.yaml
Expand Down
44 changes: 24 additions & 20 deletions pkg/workspace/storages/testdata/for_set_current_workspaces/dev.yaml
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
modules:
database:
default:
instanceType: db.t3.micro
type: aws
version: "5.7"
smallClass:
projectSelector:
- foo
- bar
instanceType: db.t3.small
port:
default:
type: aws
mysql:
path: ghcr.io/kusionstack/mysql
version: 0.1.0
configs:
default:
instanceType: db.t3.micro
type: aws
version: '5.7'
smallClass:
projectSelector:
- foo
- bar
instanceType: db.t3.small
network:
configs:
default:
type: aws
runtimes:
kubernetes:
kubeConfig: /etc/kubeconfig.yaml
terraform:
aws:
source: hashicorp/aws
version: 1.0.4
region: us-east-1
kubernetes:
kubeConfig: /etc/kubeconfig.yaml
terraform:
aws:
source: hashicorp/aws
version: 1.0.4
region: us-east-1
44 changes: 24 additions & 20 deletions pkg/workspace/storages/testdata/workspaces/dev.yaml
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
modules:
database:
default:
instanceType: db.t3.micro
type: aws
version: "5.7"
smallClass:
projectSelector:
- foo
- bar
instanceType: db.t3.small
port:
default:
type: aws
mysql:
path: ghcr.io/kusionstack/mysql
version: 0.1.0
configs:
default:
instanceType: db.t3.micro
type: aws
version: '5.7'
smallClass:
projectSelector:
- foo
- bar
instanceType: db.t3.small
network:
configs:
default:
type: aws
runtimes:
kubernetes:
kubeConfig: /etc/kubeconfig.yaml
terraform:
aws:
source: hashicorp/aws
version: 1.0.4
region: us-east-1
kubernetes:
kubeConfig: /etc/kubeconfig.yaml
terraform:
aws:
source: hashicorp/aws
version: 1.0.4
region: us-east-1
Loading

0 comments on commit 28c395d

Please sign in to comment.