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
2 changes: 1 addition & 1 deletion cmd/internal/agentcontainer/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ func (cmd *DaemonCmd) Run(c *cobra.Command, args []string) error {
}

ctx, stop := signal.NotifyContext(c.Context(), os.Interrupt, syscall.SIGTERM)
defer stop()

g, ctx := errgroup.WithContext(ctx)
var tasksStarted bool
Expand Down Expand Up @@ -136,6 +135,7 @@ func (cmd *DaemonCmd) Run(c *cobra.Command, args []string) error {
}

err := g.Wait()
stop() // Restore default signal handling before exiting.
if err != nil {
log.Errorf("daemon error: %v", err)
os.Exit(1)
Expand Down
7 changes: 4 additions & 3 deletions cmd/internal/sh.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,12 @@ func NewShellCmd() *cobra.Command {
}

func (cmd *ShellCommand) Run(ctx context.Context, args []string) error {
if cmd.Command == "" && len(args) == 0 {
switch {
case cmd.Command == "" && len(args) == 0:
return nil
} else if cmd.Command != "" && len(args) > 0 {
case cmd.Command != "" && len(args) > 0:
return fmt.Errorf("either use -c or provide a script file")
} else if len(args) > 1 {
case len(args) > 1:
return fmt.Errorf("only a single script file can be used")
}

Expand Down
23 changes: 14 additions & 9 deletions cmd/pro/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -872,11 +872,12 @@ func (cmd *StartCmd) runInDocker(ctx context.Context, name string) (string, erro
args = append(args, cmd.DockerArgs...)

// set image
if cmd.DockerImage != "" {
switch {
case cmd.DockerImage != "":
args = append(args, cmd.DockerImage)
} else if cmd.Version != "" {
case cmd.Version != "":
args = append(args, "ghcr.io/devsy-org/devsy-pro:"+strings.TrimPrefix(cmd.Version, "v"))
} else {
default:
args = append(args, "ghcr.io/devsy-org/devsy-pro:latest")
}

Expand Down Expand Up @@ -955,14 +956,15 @@ func (cmd *StartCmd) findLoftContainer(
runningContainerID := ""
for _, containerID := range arr {
containerState, err := cmd.inspectContainer(ctx, containerID)
if err != nil {
switch {
case err != nil:
return "", err
} else if onlyRunning && strings.ToLower(containerState.State.Status) != "running" {
case onlyRunning && strings.ToLower(containerState.State.Status) != "running":
err = cmd.removeContainer(ctx, containerID)
if err != nil {
return "", err
}
} else {
default:
runningContainerID = containerID
}
}
Expand Down Expand Up @@ -1772,9 +1774,10 @@ func ensureAdminPassword(
}

admin, err := loftClient.StorageV1().Users().Get(ctx, "admin", metav1.GetOptions{})
if err != nil && !kerrors.IsNotFound(err) {
switch {
case err != nil && !kerrors.IsNotFound(err):
return false, err
} else if admin == nil {
case admin == nil:
admin, err = loftClient.StorageV1().Users().Create(ctx, &storagev1.User{
ObjectMeta: metav1.ObjectMeta{
Name: "admin",
Expand All @@ -1794,7 +1797,9 @@ func ensureAdminPassword(
if err != nil {
return false, err
}
} else if admin.Spec.PasswordRef == nil || admin.Spec.PasswordRef.SecretName == "" || admin.Spec.PasswordRef.SecretNamespace == "" {
case admin.Spec.PasswordRef == nil ||
admin.Spec.PasswordRef.SecretName == "" ||
admin.Spec.PasswordRef.SecretNamespace == "":
return false, nil
}

Expand Down
12 changes: 6 additions & 6 deletions e2e/framework/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,22 @@ func NewDefaultFramework(path string) *Framework {
binName := "devsy-"
switch runtime.GOOS {
case "darwin":
binName = binName + "darwin-"
binName += "darwin-"
case "linux":
binName = binName + "linux-"
binName += "linux-"
case "windows":
binName = binName + "windows-"
binName += "windows-"
}

switch runtime.GOARCH {
case "amd64":
binName = binName + "amd64"
binName += "amd64"
case "arm64":
binName = binName + "arm64"
binName += "arm64"
}

if runtime.GOOS == "windows" {
binName = binName + ".exe"
binName += ".exe"
}

return &Framework{DevsyBinDir: path, DevsyBinName: binName}
Expand Down
15 changes: 7 additions & 8 deletions e2e/framework/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,21 +82,20 @@ func createTempDir(baseDir string) (string, error) {
var dir string
var err error

if os.Getenv("GITHUB_ACTIONS") == "true" {
switch {
case os.Getenv("GITHUB_ACTIONS") == "true":
runnerTemp := os.Getenv("RUNNER_TEMP")
if runnerTemp != "" {
dir, err = os.MkdirTemp(runnerTemp, "temp-*")
} else {
dir, err = os.MkdirTemp("", "temp-*")
}
} else if os.Getenv("ACT") == "true" {
case os.Getenv("ACT") == "true":
dir, err = os.MkdirTemp("/tmp", "temp-*")
} else {
if baseDir == "" {
dir, err = os.MkdirTemp("", "temp-*")
} else {
dir, err = os.MkdirTemp(baseDir, "temp-*")
}
case baseDir == "":
dir, err = os.MkdirTemp("", "temp-*")
default:
dir, err = os.MkdirTemp(baseDir, "temp-*")
}

if err != nil {
Expand Down
7 changes: 4 additions & 3 deletions pkg/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,13 @@ func ReadAgentWorkspaceInfo(
// check if we need to become root
log.Debug("checking if root privileges are required")
shouldExit, err := rerunAsRoot(workspaceInfo)
if err != nil {
switch {
case err != nil:
return false, nil, fmt.Errorf("rerun as root: %w", err)
} else if shouldExit {
case shouldExit:
log.Debug("rerunning as root, exiting current process")
return true, nil, nil
} else if workspaceInfo == nil {
case workspaceInfo == nil:
log.Debug("no workspace info available and not rerunning as root")
return false, nil, ErrFindAgentHomeDir
}
Expand Down
23 changes: 12 additions & 11 deletions pkg/agent/tunnelserver/tunnelserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"io"
"os"
"path/filepath"
"slices"
"strings"

"github.com/devsy-org/api/pkg/devsy"
Expand Down Expand Up @@ -40,13 +41,13 @@ func RunServicesServer(
workspace *provider2.Workspace,
options ...Option,
) error {
opts := append(options, []Option{
options = append(options,
WithForwarder(forwarder),
WithAllowGitCredentials(allowGitCredentials),
WithAllowDockerCredentials(allowDockerCredentials),
WithWorkspace(workspace),
}...)
tunnelServ := New(opts...)
)
tunnelServ := New(options...)

return tunnelServ.Run(ctx, reader, writer)
}
Expand All @@ -59,12 +60,12 @@ func RunUpServer(
workspace *provider2.Workspace,
options ...Option,
) (*config.Result, error) {
opts := append(options, []Option{
options = append(options,
WithWorkspace(workspace),
WithAllowGitCredentials(allowGitCredentials),
WithAllowDockerCredentials(allowDockerCredentials),
}...)
tunnelServ := New(opts...)
)
tunnelServ := New(options...)

return tunnelServ.RunWithResult(ctx, reader, writer)
}
Expand All @@ -77,13 +78,13 @@ func RunSetupServer(
mounts []*config.Mount,
options ...Option,
) (*config.Result, error) {
opts := append(options, []Option{
options = append(options,
WithMounts(mounts),
WithAllowGitCredentials(allowGitCredentials),
WithAllowDockerCredentials(allowDockerCredentials),
WithAllowKubeConfig(true),
}...)
tunnelServ := New(opts...)
)
tunnelServ := New(options...)
tunnelServ.allowPlatformOptions = true

return tunnelServ.RunWithResult(ctx, reader, writer)
Expand Down Expand Up @@ -267,9 +268,9 @@ func (t *tunnelServer) GitCredentials(
}

if t.platformOptions != nil && t.platformOptions.Enabled {
gitHttpCredentials := append(
gitHttpCredentials := slices.Concat(
t.platformOptions.UserCredentials.GitHttp,
t.platformOptions.ProjectCredentials.GitHttp...)
t.platformOptions.ProjectCredentials.GitHttp)
if len(gitHttpCredentials) > 0 {
if len(gitHttpCredentials) == 1 {
credentials.Username = gitHttpCredentials[0].User
Expand Down
7 changes: 4 additions & 3 deletions pkg/client/clientimplementation/daemonclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,16 @@ func (c *client) CheckWorkspaceReachable(ctx context.Context) error {
}
}

if getWorkspaceErr != nil {
switch {
case getWorkspaceErr != nil:
return fmt.Errorf("couldn't get workspace: %w", getWorkspaceErr)
} else if instance.Status.Phase != storagev1.InstanceReady {
case instance.Status.Phase != storagev1.InstanceReady:
return fmt.Errorf(
"workspace is %q, run `devsy workspace up %s` to start it again",
instance.Status.Phase,
c.workspace.ID,
)
} else if instance.Status.LastWorkspaceStatus != storagev1.WorkspaceStatusRunning {
case instance.Status.LastWorkspaceStatus != storagev1.WorkspaceStatusRunning:
return fmt.Errorf(
"workspace is %q, run `devsy workspace up %s` to start it again",
instance.Status.LastWorkspaceStatus,
Expand Down
7 changes: 4 additions & 3 deletions pkg/client/clientimplementation/daemonclient/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,12 @@ func (c *client) Delete(ctx context.Context, opt clientpkg.DeleteOptions) error
ManagementV1().
DevsyWorkspaceInstances(workspace.Namespace).
Get(ctx, workspace.Name, metav1.GetOptions{})
if kerrors.IsNotFound(err) {
switch {
case kerrors.IsNotFound(err):
return true, nil
} else if err != nil {
case err != nil:
return false, fmt.Errorf("error getting workspace: %w", err)
} else if workspaceInstance.DeletionTimestamp == nil {
case workspaceInstance.DeletionTimestamp == nil:
// this can occur if the workspace is already deleted and was recreated
return true, nil
}
Expand Down
7 changes: 4 additions & 3 deletions pkg/client/clientimplementation/daemonclient/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,12 @@ func waitTaskDone(
}, builders.ParameterCodec).
Do(ctx).
Into(tasks)
if err != nil {
switch {
case err != nil:
return nil, fmt.Errorf("error getting up result: %w", err)
} else if len(tasks.Tasks) == 0 || tasks.Tasks[0].Result == nil {
case len(tasks.Tasks) == 0 || tasks.Tasks[0].Result == nil:
return nil, fmt.Errorf("up result not found")
} else if len(tasks.Tasks) > 1 {
case len(tasks.Tasks) > 1:
return nil, fmt.Errorf("multiple up results found")
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/devcontainer/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,15 @@ type DevContainerConfigBase struct {
// The path of the workspace folder inside the container.
WorkspaceFolder string `json:"workspaceFolder,omitempty"`

// DEPRECATED: Use 'customizations/vscode/settings' instead
// Deprecated: Use 'customizations/vscode/settings' instead
// Machine specific settings that should be copied into the container. These are only copied when connecting to the container for the first time, rebuilding the container then triggers it again.
Settings map[string]any `json:"settings,omitempty"`

// DEPRECATED: Use 'customizations/vscode/extensions' instead
// Deprecated: Use 'customizations/vscode/extensions' instead
// An array of extensions that should be installed into the container.
Extensions []string `json:"extensions,omitempty"`

// DEPRECATED: Use 'customizations/vscode/devPort' instead
// Deprecated: Use 'customizations/vscode/devPort' instead
// The port VS Code can use to connect to its backend.
DevPort int `json:"devPort,omitempty"`

Expand Down
7 changes: 4 additions & 3 deletions pkg/devcontainer/prebuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,12 @@ func (r *runner) Build(ctx context.Context, options provider.BuildOptions) (stri

// prebuild already exists
var prebuildImage string
if options.Repository != "" {
switch {
case options.Repository != "":
prebuildImage = options.Repository + ":" + buildInfo.PrebuildHash
} else if prebuildRepo != "" {
case prebuildRepo != "":
prebuildImage = prebuildRepo + ":" + buildInfo.PrebuildHash
} else {
default:
prebuildImage = build.GetImageName(r.localWorkspaceFolder, buildInfo.PrebuildHash)
}

Expand Down
7 changes: 4 additions & 3 deletions pkg/driver/kubernetes/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,17 @@ func (k *KubernetesDriver) runContainer(
if k.options.WorkspaceVolumeMount != "" {
// Ensure workspace volume mount option is parent or same dir as workspace mount
rel, err := filepath.Rel(k.options.WorkspaceVolumeMount, mount.Target)
if err != nil {
switch {
case err != nil:
log.Warnf("Relative filepath: %v", err)
} else if strings.HasPrefix(rel, "..") {
case strings.HasPrefix(rel, ".."):
log.Warnf(
"Workspace volume mount needs to be the same as the workspace mount or a parent, skipping option. "+
"WorkspaceVolumeMount: %s, MountTarget: %s",
k.options.WorkspaceVolumeMount,
mount.Target,
)
} else {
default:
mount.Target = k.options.WorkspaceVolumeMount
log.Debugf("Using workspace volume mount: %s", k.options.WorkspaceVolumeMount)
}
Expand Down
7 changes: 4 additions & 3 deletions pkg/ide/ideparse/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,12 @@ func RefreshIDEOptions(
) (*provider.Workspace, error) {
ide = strings.ToLower(ide)
if ide == "" {
if workspace.IDE.Name != "" {
switch {
case workspace.IDE.Name != "":
ide = workspace.IDE.Name
} else if devsyConfig.Current().DefaultIDE != "" {
case devsyConfig.Current().DefaultIDE != "":
ide = devsyConfig.Current().DefaultIDE
} else {
default:
ide = detect()
}
}
Expand Down
7 changes: 4 additions & 3 deletions pkg/inject/inject.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,11 +319,12 @@ func readLine(reader io.Reader) (string, error) {
str := ""
for {
n, err := reader.Read(buf)
if err != nil {
switch {
case err != nil:
return "", err
} else if n == 0 {
case n == 0:
continue
} else if buf[0] == '\n' {
case buf[0] == '\n':
return str, nil
}

Expand Down
Loading
Loading