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

fix: empty resources in stack will generate panic #177

Merged
merged 4 commits into from
Nov 28, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ require (
gopkg.in/natefinch/lumberjack.v2 v2.0.0
gopkg.in/src-d/go-git.v4 v4.13.1
gopkg.in/yaml.v2 v2.4.0
gopkg.in/yaml.v3 v3.0.0
gopkg.in/yaml.v3 v3.0.1
k8s.io/api v0.24.2
k8s.io/apimachinery v0.24.2
k8s.io/client-go v10.0.0+incompatible
Expand Down
3 changes: 2 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1433,8 +1433,9 @@ gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20220512140231-539c8e751b99/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0 h1:hjy8E9ON/egN1tAYqKb61G10WtihqetD4sz2H+8nIeA=
gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gotest.tools/v3 v3.0.2/go.mod h1:3SzNCllyD9/Y+b5r9JIKQ474KzkZyqLqEfYqMsX94Bk=
gotest.tools/v3 v3.0.3 h1:4AuOwCGf4lLR9u3YOe2awrHygurzhO/HeQ6laiA6Sx0=
gotest.tools/v3 v3.0.3/go.mod h1:Z7Lb0S5l+klDB31fvDQX8ss/FlKDxtlFlw3Oa8Ymbl8=
Expand Down
8 changes: 8 additions & 0 deletions pkg/kusionctl/cmd/apply/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"kusionstack.io/kusion/pkg/log"
"kusionstack.io/kusion/pkg/projectstack"
"kusionstack.io/kusion/pkg/status"
"kusionstack.io/kusion/pkg/util/pretty"
)

// ApplyOptions defines flags for the `apply` command
Expand Down Expand Up @@ -73,6 +74,13 @@ func (o *ApplyOptions) Run() error {
sp.Fail()
return err
}

// return immediately if no resource found in stack
if planResources == nil || len(planResources.Resources) == 0 {
fmt.Println(pretty.GreenBold("\nNo resource found in this stack."))
return nil
}

sp.Success() // Resolve spinner with success message.
pterm.Println()

Expand Down
15 changes: 15 additions & 0 deletions pkg/kusionctl/cmd/preview/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"kusionstack.io/kusion/pkg/log"
"kusionstack.io/kusion/pkg/projectstack"
"kusionstack.io/kusion/pkg/status"
"kusionstack.io/kusion/pkg/util/pretty"
)

type PreviewOptions struct {
Expand Down Expand Up @@ -63,10 +64,24 @@ func (o *PreviewOptions) Run() error {

// Get compile result
planResources, sp, err := compile.CompileWithSpinner(o.WorkDir, o.Filenames, o.Settings, o.Arguments, o.Overrides, stack)

// return immediately if no resource found in stack
if planResources == nil || len(planResources.Resources) == 0 {
fmt.Println(pretty.GreenBold("\nNo resource found in this stack."))
return nil
}

if err != nil {
sp.Fail()
return err
}

// return immediately if no resource found in stack
if planResources == nil || len(planResources.Resources) == 0 {
SparkYuan marked this conversation as resolved.
Show resolved Hide resolved
fmt.Println(pretty.GreenBold("\nNo resource found in this stack."))
return nil
}

sp.Success() // Resolve spinner with success message.
pterm.Println()

Expand Down