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: state backend using workspace, and upgrade of state #669

Merged
merged 1 commit into from
Dec 14, 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
4 changes: 0 additions & 4 deletions pkg/apis/project/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"github.com/pterm/pterm"

"kusionstack.io/kusion/pkg/apis/stack"
"kusionstack.io/kusion/pkg/engine/backend"
"kusionstack.io/kusion/pkg/log"
)

Expand Down Expand Up @@ -50,9 +49,6 @@ type Configuration struct {
// Tenant name
Tenant string `json:"tenant,omitempty" yaml:"tenant,omitempty"`

// Backend storage config
Backend *backend.Storage `json:"backend,omitempty" yaml:"backend,omitempty"`

// SpecGenerator configs
Generator *GeneratorConfig `json:"generator,omitempty" yaml:"generator,omitempty"`

Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/apply/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ func (o *Options) Run() error {
return nil
}

// Get state storage from backend config to manage state
stateStorage, err := backend.BackendFromConfig(project.Backend, o.BackendOps, o.WorkDir)
// Get state storage from cli backend options, environment variables, workspace backend configs
stateStorage, err := backend.NewStateStorage(stack, &o.BackendOptions)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/apply/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func newSA(name string) intent.Resource {
}

func Test_apply(t *testing.T) {
stateStorage := &local.FileSystemState{Path: filepath.Join("", local.KusionState)}
stateStorage := &local.FileSystemState{Path: filepath.Join("", local.KusionStateFileFile)}
mockey.PatchConvey("dry run", t, func() {
planResources := &intent.Intent{Resources: []intent.Resource{sa1}}
order := &opsmodels.ChangeOrder{
Expand Down
16 changes: 12 additions & 4 deletions pkg/cmd/destroy/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type Options struct {
Operator string
Yes bool
Detail bool
backend.BackendOps
backend.BackendOptions
}

func NewDestroyOptions() *Options {
Expand All @@ -42,7 +42,15 @@ func (o *Options) Complete(args []string) {
}

func (o *Options) Validate() error {
return o.Options.Validate()
if err := o.Options.Validate(); err != nil {
return err
}
if !o.BackendOptions.IsEmpty() {
if err := o.BackendOptions.Validate(); err != nil {
return err
}
}
return nil
}

func (o *Options) Run() error {
Expand All @@ -54,8 +62,8 @@ func (o *Options) Run() error {
return err
}

// Get stateStorage from backend config to manage state
stateStorage, err := backend.BackendFromConfig(project.Backend, o.BackendOps, o.WorkDir)
// Get state storage from cli backend options, environment variables, workspace backend configs
stateStorage, err := backend.NewStateStorage(stack, &o.BackendOptions)
if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/cmd/destroy/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func Test_preview(t *testing.T) {
mockOperationPreview()

o := NewDestroyOptions()
stateStorage := &local.FileSystemState{Path: filepath.Join(o.WorkDir, local.KusionState)}
stateStorage := &local.FileSystemState{Path: filepath.Join(o.WorkDir, local.KusionStateFileFile)}
_, err := o.preview(&intent.Intent{Resources: []intent.Resource{sa1}}, p, s, stateStorage)
assert.Nil(t, err)
})
Expand Down Expand Up @@ -217,7 +217,7 @@ func Test_destroy(t *testing.T) {
}
changes := opsmodels.NewChanges(p, s, order)

stateStorage := &local.FileSystemState{Path: filepath.Join(o.WorkDir, local.KusionState)}
stateStorage := &local.FileSystemState{Path: filepath.Join(o.WorkDir, local.KusionStateFileFile)}

err := o.destroy(planResources, changes, stateStorage)
assert.Nil(t, err)
Expand All @@ -239,7 +239,7 @@ func Test_destroy(t *testing.T) {
},
}
changes := opsmodels.NewChanges(p, s, order)
stateStorage := &local.FileSystemState{Path: filepath.Join(o.WorkDir, local.KusionState)}
stateStorage := &local.FileSystemState{Path: filepath.Join(o.WorkDir, local.KusionStateFileFile)}

err := o.destroy(planResources, changes, stateStorage)
assert.NotNil(t, err)
Expand Down
11 changes: 8 additions & 3 deletions pkg/cmd/preview/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const jsonOutput = "json"
type Options struct {
build.Options
Flags
backend.BackendOps
backend.BackendOptions
}

type Flags struct {
Expand Down Expand Up @@ -62,6 +62,11 @@ func (o *Options) Validate() error {
if err := o.ValidateIntentFile(); err != nil {
return err
}
if !o.BackendOptions.IsEmpty() {
if err := o.BackendOptions.Validate(); err != nil {
return err
}
}
return nil
}

Expand Down Expand Up @@ -152,8 +157,8 @@ func (o *Options) Run() error {
return nil
}

// Get state storage from backend config to manage state
stateStorage, err := backend.BackendFromConfig(project.Backend, o.BackendOps, o.WorkDir)
// Get state storage from cli backend options, environment variables, workspace backend configs
stateStorage, err := backend.NewStateStorage(stack, &o.BackendOptions)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/preview/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ var (
)

func Test_preview(t *testing.T) {
stateStorage := &local.FileSystemState{Path: filepath.Join("", local.KusionState)}
stateStorage := &local.FileSystemState{Path: filepath.Join("", local.KusionStateFileFile)}
t.Run("preview success", func(t *testing.T) {
m := mockOperationPreview()
defer m.UnPatch()
Expand Down
127 changes: 0 additions & 127 deletions pkg/engine/backend/backend.go

This file was deleted.

Loading
Loading