-
Notifications
You must be signed in to change notification settings - Fork 24
improve cd ls output and cd teardown error handling #1914
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
Changes from all commits
5331e5d
c4aaa7b
adf4a12
62ef442
120fd02
bbc4569
6bb195e
5382961
d3d1ae8
3c45fe2
e2d6c0f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ import ( | |
|
|
||
| "github.com/DefangLabs/defang/src/pkg" | ||
| "github.com/DefangLabs/defang/src/pkg/cli/client" | ||
| "github.com/DefangLabs/defang/src/pkg/cli/client/byoc/state" | ||
| "github.com/DefangLabs/defang/src/pkg/cli/compose" | ||
| "github.com/DefangLabs/defang/src/pkg/dns" | ||
| "github.com/DefangLabs/defang/src/pkg/stacks" | ||
|
|
@@ -28,7 +29,7 @@ func (mp ErrMultipleProjects) Error() string { | |
|
|
||
| type ProjectBackend interface { | ||
| CdCommand(context.Context, client.CdCommandRequest) (types.ETag, error) | ||
| CdList(context.Context, bool) (iter.Seq[string], error) | ||
| CdList(context.Context, bool) (iter.Seq[state.Info], error) | ||
| GetPrivateDomain(projectName string) string | ||
| GetProjectUpdate(context.Context, string) (*defangv1.ProjectUpdate, error) | ||
| } | ||
|
|
@@ -101,9 +102,8 @@ func (b *ByocBaseClient) RemoteProjectName(ctx context.Context) (string, error) | |
| return "", fmt.Errorf("no cloud projects found: %w", err) | ||
| } | ||
| var projectNames []string | ||
| for name := range stacks { | ||
| projectName := strings.Split(name, "/")[0] // Remove the stack name | ||
| projectNames = append(projectNames, projectName) | ||
| for stack := range stacks { | ||
| projectNames = append(projectNames, stack.Project) | ||
| } | ||
|
Comment on lines
+105
to
107
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Deduplicate project names to avoid false “multiple projects” errors. If multiple stacks exist for the same project, the current logic will append duplicates and trigger 🔧 Suggested fix import (
"context"
"errors"
"fmt"
"iter"
+ "sort"
"strings"
@@
var projectNames []string
- for stack := range stacks {
- projectNames = append(projectNames, stack.Project)
- }
+ projectSet := map[string]struct{}{}
+ for stack := range stacks {
+ projectSet[stack.Project] = struct{}{}
+ }
+ projectNames = make([]string, 0, len(projectSet))
+ for name := range projectSet {
+ projectNames = append(projectNames, name)
+ }
+ sort.Strings(projectNames)🤖 Prompt for AI Agents
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is true, but unrelated to our changes here. I'll handle separately.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
🧠 Learnings used
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done: #1918
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
🧠 Learnings used |
||
|
|
||
| if len(projectNames) == 0 { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,7 @@ import ( | |
| "github.com/DefangLabs/defang/src/pkg" | ||
| "github.com/DefangLabs/defang/src/pkg/cli/client" | ||
| "github.com/DefangLabs/defang/src/pkg/cli/client/byoc" | ||
| "github.com/DefangLabs/defang/src/pkg/cli/client/byoc/state" | ||
| "github.com/DefangLabs/defang/src/pkg/cli/compose" | ||
| "github.com/DefangLabs/defang/src/pkg/clouds/gcp" | ||
| "github.com/DefangLabs/defang/src/pkg/dns" | ||
|
|
@@ -276,7 +277,7 @@ func (o gcpObj) Size() int64 { | |
| return o.obj.Size | ||
| } | ||
|
|
||
| func (b *ByocGcp) CdList(ctx context.Context, _allRegions bool) (iter.Seq[string], error) { | ||
| func (b *ByocGcp) CdList(ctx context.Context, _allRegions bool) (iter.Seq[state.Info], error) { | ||
| bucketName, err := b.driver.GetBucketWithPrefix(ctx, DefangCDProjectName) | ||
| if err != nil { | ||
| return nil, annotateGcpError(err) | ||
|
|
@@ -296,21 +297,28 @@ func (b *ByocGcp) CdList(ctx context.Context, _allRegions bool) (iter.Seq[string | |
| if err != nil { | ||
| return nil, annotateGcpError(err) | ||
| } | ||
| return func(yield func(string) bool) { | ||
| return func(yield func(state.Info) bool) { | ||
| for obj, err := range seq { | ||
| if err != nil { | ||
| term.Debugf("Error listing object in bucket %s: %v", bucketName, annotateGcpError(err)) | ||
| continue | ||
| } | ||
| stack, err := byoc.ParsePulumiStateFile(ctx, gcpObj{obj}, bucketName, objLoader) | ||
| st, err := state.ParsePulumiStateFile(ctx, gcpObj{obj}, bucketName, objLoader) | ||
| if err != nil { | ||
| term.Debugf("Skipping %q in bucket %s: %v", obj.Name, bucketName, annotateGcpError(err)) | ||
| continue | ||
| } | ||
| if stack != nil { | ||
| if !yield(stack.String()) { | ||
| break | ||
| } | ||
| if st == nil { | ||
| continue | ||
| } | ||
jordanstephens marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| stack := state.Info{ | ||
| Stack: st.Name, | ||
| Project: st.Project, | ||
| Workspace: string(st.Workspace), | ||
| Region: b.driver.GetRegion(), | ||
| } | ||
| if !yield(stack) { | ||
| break | ||
| } | ||
| } | ||
| }, nil | ||
|
|
@@ -786,6 +794,7 @@ func LogEntriesToString(logEntries []*loggingpb.LogEntry) string { | |
| } | ||
|
|
||
| func (b *ByocGcp) TearDownCD(ctx context.Context) error { | ||
| // term.Warn("Deleting Defang CD; currently existing stacks or configs will not be deleted, but they will be orphaned and they will need to be cleaned up manually") | ||
| // FIXME: implement | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's possible there's really nothing to do here. @edwardrf thoughts? |
||
| return client.ErrNotImplemented("GCP TearDown") | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.