Skip to content
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
13 changes: 9 additions & 4 deletions pkg/cmd/preview/preview.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,12 +240,17 @@ func (o *PreviewOptions) Run() error {
return err
}

// return immediately if no resource found in stack
if spec == nil || len(spec.Resources) == 0 {
if spec == nil {
if o.Output != jsonOutput {
fmt.Println(pretty.GreenBold("\nNo resource found in this stack."))
fmt.Println(pretty.YellowBold("\nSpec is nil. Treating as empty spec."))
}
spec = &apiv1.Spec{}
}

if len(spec.Resources) == 0 {
if o.Output != jsonOutput {
fmt.Println(pretty.YellowBold("\nNo resources found in the spec."))
}
return nil
}

// compute state
Expand Down
12 changes: 7 additions & 5 deletions pkg/server/manager/stack/execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,13 @@ func (m *StackManager) PreviewStack(ctx context.Context, params *StackRequestPar
return nil, err
}

// return immediately if no resource found in stack
// todo: if there is no resource, should still do diff job; for now, if output is json format, there is no hint
if sp == nil || len(sp.Resources) == 0 {
logutil.LogToAll(logger, runLogger, "Info", "No resource change found in this stack...")
return nil, nil
// Treat nil spec as empty and continue with diff
if sp == nil {
logutil.LogToAll(logger, runLogger, "Warn", "Generated spec is nil, treating as empty spec...")
sp = &apiv1.Spec{}
}
if len(sp.Resources) == 0 {
logutil.LogToAll(logger, runLogger, "Info", "No resources found in spec. Proceeding with full diff.")
}

// Preview
Expand Down
Loading