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
274 changes: 240 additions & 34 deletions cli/module_build.go

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions cli/module_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"math"
"os"
"os/exec"
"path"
"path/filepath"
"regexp"
"runtime"
Expand Down Expand Up @@ -1079,7 +1078,6 @@ func (c *viamClient) downloadModuleAction(ctx *cli.Context, flags downloadModule
return "", fmt.Errorf("version %s not found in versions for module", requestedVersion)
}
}
infof(ctx.App.ErrWriter, "found version %s", ver.Version)
if len(ver.Files) == 0 {
return "", fmt.Errorf("version %s has 0 files uploaded", ver.Version)
}
Expand All @@ -1105,7 +1103,6 @@ func (c *viamClient) downloadModuleAction(ctx *cli.Context, flags downloadModule
return "", err
}
destName := strings.ReplaceAll(moduleID, ":", "-")
infof(ctx.App.ErrWriter, "saving to %s", path.Join(flags.Destination, fullVersion, destName+".tar.gz"))
return downloadPackageFromURL(ctx.Context, c.authFlow.httpClient,
flags.Destination, destName,
fullVersion, pkg.Package.Url, c.conf.Auth,
Expand Down
22 changes: 11 additions & 11 deletions cli/module_reload.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,11 @@ func (c *viamClient) addResourceFromModule(
}

// addShellService adds a shell service to the services slice if missing. Mutates part.RobotConfig.
func addShellService(c *cli.Context, vc *viamClient, part *apppb.RobotPart, wait bool) error {
// Returns (wasAdded, error) where wasAdded indicates if the shell service was newly added.
func addShellService(c *cli.Context, vc *viamClient, logger logging.Logger, part *apppb.RobotPart, wait bool) (bool, error) {
args, err := getGlobalArgs(c)
if err != nil {
return err
return false, err
}
partMap := part.RobotConfig.AsMap()
if _, ok := partMap["services"]; !ok {
Expand All @@ -126,37 +127,36 @@ func addShellService(c *cli.Context, vc *viamClient, part *apppb.RobotPart, wait
return service["type"] == "shell" || service["api"] == "rdk:service:shell"
}) {
debugf(c.App.Writer, args.Debug, "shell service found on target machine, not installing")
return nil
return false, nil
}
services = append(services, ResourceMap{"name": "shell", "api": "rdk:service:shell"})
asAny, _ := rutils.MapOver(services, func(service ResourceMap) (any, error) { //nolint:errcheck
return map[string]any(service), nil
})
partMap["services"] = asAny
if err := writeBackConfig(part, partMap); err != nil {
return err
return false, err
}
infof(c.App.Writer, "installing shell service on target machine for file transfer")
if err := vc.updateRobotPart(part, partMap); err != nil {
return err
return false, err
}
if !wait {
return nil
return true, nil
}
// note: we wait up to 11 seconds; that's the 10 second default Cloud.RefreshInterval plus padding.
// If we don't wait, the reload command will usually fail on first run.
for i := 0; i < 11; i++ {
time.Sleep(time.Second)
_, closeClient, err := vc.connectToShellServiceFqdn(part.Fqdn, args.Debug, logging.NewLogger("shellsvc"))
_, closeClient, err := vc.connectToShellServiceFqdn(part.Fqdn, args.Debug, logger)
if err == nil {
goutils.UncheckedError(closeClient(c.Context))
return nil
return true, nil
}
if !errors.Is(err, errNoShellService) {
return err
return false, err
}
}
return errors.New("timed out waiting for shell service to start")
return false, errors.New("timed out waiting for shell service to start")
}

// writeBackConfig mutates part.RobotConfig with an edited config; this is necessary so that changes
Expand Down
4 changes: 2 additions & 2 deletions cli/module_reload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func TestFullReloadFlow(t *testing.T) {
t.Run("addShellService", func(t *testing.T) {
t.Run("addsServiceWhenMissing", func(t *testing.T) {
part, _ := vc.getRobotPart("id")
err := addShellService(cCtx, vc, part.Part, false)
_, err := addShellService(cCtx, vc, logging.NewTestLogger(t), part.Part, false)
test.That(t, err, test.ShouldBeNil)
services, ok := part.Part.RobotConfig.AsMap()["services"].([]any)
test.That(t, ok, test.ShouldBeTrue)
Expand Down Expand Up @@ -127,7 +127,7 @@ func TestFullReloadFlow(t *testing.T) {
)

part, _ := vc2.getRobotPart("id")
err = addShellService(cCtx2, vc2, part.Part, false)
_, err = addShellService(cCtx2, vc2, logging.NewTestLogger(t), part.Part, false)
test.That(t, err, test.ShouldBeNil)
services, ok := part.Part.RobotConfig.AsMap()["services"].([]any)
test.That(t, ok, test.ShouldBeTrue)
Expand Down
Loading
Loading