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

Allow region change #997

Merged
merged 2 commits into from
Aug 21, 2024
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
7 changes: 4 additions & 3 deletions cmd/klotho/dependencies.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import (
"context"
"errors"
"fmt"
"github.com/klothoplatform/klotho/pkg/logging"
"os"
"os/exec"
"path/filepath"
"runtime"

"github.com/klothoplatform/klotho/pkg/logging"
gordon-klotho marked this conversation as resolved.
Show resolved Hide resolved

pulumi "github.com/pulumi/pulumi/sdk/v3"
"github.com/pulumi/pulumi/sdk/v3/go/auto"
)
Expand Down Expand Up @@ -95,8 +96,8 @@ func installPulumi(ctx context.Context) error {
}

func isDockerInstalled() bool {
// Check if docker is installed
cmd := exec.Command("docker", "--version")
// Check if docker is installed and the daemon is running
cmd := exec.Command("docker", "ps")
gordon-klotho marked this conversation as resolved.
Show resolved Hide resolved
err := cmd.Run()
return err == nil
}
Expand Down
2 changes: 0 additions & 2 deletions cmd/klotho/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (

var upConfig struct {
stateDir string
region string
debugMode string
debugPort int
}
Expand All @@ -33,7 +32,6 @@ func newUpCmd() *cobra.Command {
}
flags := upCommand.Flags()
flags.StringVar(&upConfig.stateDir, "state-directory", "", "State directory")
flags.StringVarP(&upConfig.region, "region", "r", "us-west-2", "AWS region")
flags.StringVar(&upConfig.debugMode, "debug", "", "Debug mode")
flags.IntVar(&upConfig.debugPort, "debug-port", 5678, "Language Host Debug port")
return upCommand
Expand Down
10 changes: 9 additions & 1 deletion pkg/k2/orchestration/orchestrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,15 @@ func (o *Orchestrator) resolveInitialState(ir *model.ApplicationEnvironment) (ma

// Check for default region mismatch
if state.DefaultRegion != ir.DefaultRegion {
return nil, fmt.Errorf("default region mismatch: %s != %s", state.DefaultRegion, ir.DefaultRegion)
deployed := make(map[string]model.ConstructStatus)
for k, v := range state.Constructs {
if model.IsDeletable(v.Status) {
deployed[k] = v.Status
}
}
if len(deployed) > 0 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we may need to couple this with deleting the old pulumi state

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not too familiar with how state works, this should just be mostly the same as it was before. Can you explain a bit more what you mean and why it should delete old pulumi state?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, and it may not be pulumi state necessarily (it may be klotho2 state referencing non-existent resources since we never clear that file). We've seen cases where changing region and redeploying causes deploy time errors about vpcs etc. I was thinking we could start with modifying state to clear this out and see if that's enough.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changing region and redeploying causes deploy time errors

This should only happen if the klotho / pulumi state is out of sync with AWS, right? Since this checks whether any resources are destroyable before allowing the region swap. Any resource that was deployed and not properly cleaned up would still be in a destroyable state I'd think. If not, that sounds like there's a bug somewhere.

If that's that case, for the purposes of this PR, I'm leaning to it being out of scope and we should cut a new card for it.

return nil, fmt.Errorf("cannot change region (%s -> %s) with deployed resources: %v", state.DefaultRegion, ir.DefaultRegion, deployed)
}
}

// Check for schema version mismatch
Expand Down
Loading