-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: remove state model to pkg apis/core/v1 and stateStorage interfa…
…ce to pkg state
- Loading branch information
Showing
4 changed files
with
82 additions
and
214 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package v1 | ||
|
||
import ( | ||
"time" | ||
|
||
"kusionstack.io/kusion/pkg/version" | ||
) | ||
|
||
// State is a record of an operation's result. It is a mapping between resources in KCL and the actual infra | ||
// resource and often used as a datasource for 3-way merge/diff in operations like Apply or Preview. | ||
type State struct { | ||
// State ID | ||
ID int64 `json:"id" yaml:"id"` | ||
|
||
// Project name | ||
Project string `json:"project" yaml:"project"` | ||
|
||
// Stack name | ||
Stack string `json:"stack" yaml:"stack"` | ||
|
||
// Workspace name | ||
Workspace string `json:"workspace" yaml:"workspace"` | ||
|
||
// State version | ||
Version int `json:"version" yaml:"version"` | ||
|
||
// KusionVersion represents the Kusion's version when this State is created | ||
KusionVersion string `json:"kusionVersion" yaml:"kusionVersion"` | ||
|
||
// Serial is an auto-increase number that represents how many times this State is modified | ||
Serial uint64 `json:"serial" yaml:"serial"` | ||
|
||
// Operator represents the person who triggered this operation | ||
Operator string `json:"operator,omitempty" yaml:"operator,omitempty"` | ||
|
||
// Resources records all resources in this operation | ||
Resources Resources `json:"resources" yaml:"resources"` | ||
|
||
// CreateTime is the time State is created | ||
CreateTime time.Time `json:"createTime" yaml:"createTime"` | ||
|
||
// ModifiedTime is the time State is modified each time | ||
ModifiedTime time.Time `json:"modifiedTime,omitempty" yaml:"modifiedTime"` | ||
} | ||
|
||
func NewState() *State { | ||
s := &State{ | ||
KusionVersion: version.ReleaseVersion(), | ||
Version: 1, | ||
Resources: []Resource{}, | ||
} | ||
return s | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package state | ||
|
||
import ( | ||
v1 "kusionstack.io/kusion/pkg/apis/core/v1" | ||
) | ||
|
||
// Storage represents the set of methods to manipulate State in a specified storage. | ||
type Storage interface { | ||
// Get returns the latest state, if the state does not exist, return nil. | ||
Get() (*v1.State, error) | ||
|
||
// Apply updates the state if already exists, or create a new state. | ||
Apply(state *v1.State) error | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.