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: add workspace domain model #639

Merged
merged 2 commits into from
Nov 30, 2023
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
15 changes: 15 additions & 0 deletions pkg/apis/workspace/backends.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package workspace

// BackendConfigs contains config of the backend, which is used to store state, etc. Only one kind
// backend can be configured.
// todo: add more backends declared in pkg/engine/states
type BackendConfigs struct {
// Local is backend to use local file system.
Local LocalBackend `yaml:"local,omitempty" json:"local,omitempty"`
}

// LocalBackend contains the config of using local file system as backend.
type LocalBackend struct {
// Path is place to store state, etc.
Path string `yaml:"path" json:"path"`
}
15 changes: 15 additions & 0 deletions pkg/apis/workspace/modules.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package workspace

// 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.
type ModuleConfig map[string]GenericConfig
healthjyk marked this conversation as resolved.
Show resolved Hide resolved
20 changes: 20 additions & 0 deletions pkg/apis/workspace/runtimes.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package workspace

// RuntimeConfigs contains a set of runtime config.
type RuntimeConfigs struct {
// Kubernetes contains the config to access a kubernetes cluster.
Kubernetes KubernetesRuntime `yaml:"kubernetes,omitempty" json:"kubernetes,omitempty"`

// Terraform contains the config of multiple terraform providers.
Terraform TerraformRuntime `yaml:"terraform,omitempty" json:"terraform,omitempty"`
}

// KubernetesRuntime contains config to access a kubernetes cluster.
type KubernetesRuntime struct {
// KubeConfig is the path of the kubeconfig file.
KubeConfig string `yaml:"kubeConfig" json:"kubeConfig"`
}

// TerraformRuntime contains the config of multiple terraform provider config, whose key is
// the provider name.
type TerraformRuntime map[string]GenericConfig
23 changes: 23 additions & 0 deletions pkg/apis/workspace/workspace.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package workspace

// 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:"-"`
healthjyk marked this conversation as resolved.
Show resolved Hide resolved

// 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"`
}

// 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
Loading