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

device: Add services command for seeing info about services running on a device #2525

Closed
wants to merge 1 commit into from

Conversation

myarmolinsky
Copy link
Member

@myarmolinsky myarmolinsky commented Aug 29, 2022

device: Add services command for seeing info about services running on a device

Change-type: minor
Signed-off-by: Matthew Yarmolinsky matthew-timothy@balena.io

Ex. output (ran on a BoB device):

NAME             STATUS  RELEASE                          ID
admin            Running 809e9f87824da8ce0c6e283e8db2161d 152276024
api              Running 809e9f87824da8ce0c6e283e8db2161d 152276025
builder          Running 809e9f87824da8ce0c6e283e8db2161d 152276026
delta            Running 809e9f87824da8ce0c6e283e8db2161d 152276027
devices          Running 809e9f87824da8ce0c6e283e8db2161d 152276028
git              Running 809e9f87824da8ce0c6e283e8db2161d 152276029
img              Running 809e9f87824da8ce0c6e283e8db2161d 152276030
registry         Running 809e9f87824da8ce0c6e283e8db2161d 152276031
registry-cache   Running 809e9f87824da8ce0c6e283e8db2161d 152276032
registry-proxy   Running 809e9f87824da8ce0c6e283e8db2161d 152276033
ui               Running 809e9f87824da8ce0c6e283e8db2161d 152276034
vpn              Running 809e9f87824da8ce0c6e283e8db2161d 152276035
db               Running 809e9f87824da8ce0c6e283e8db2161d 152276036
haproxy-exporter Running 809e9f87824da8ce0c6e283e8db2161d 152276037
s3               Running 809e9f87824da8ce0c6e283e8db2161d 152276038
redis            Running 809e9f87824da8ce0c6e283e8db2161d 152276039
sentry           Running 809e9f87824da8ce0c6e283e8db2161d 152276040
pg-exporter      Running 809e9f87824da8ce0c6e283e8db2161d 152276041
redis-exporter   Running 809e9f87824da8ce0c6e283e8db2161d 152276042
monitor          Running 809e9f87824da8ce0c6e283e8db2161d 152276043
alertmanager     Running 809e9f87824da8ce0c6e283e8db2161d 152276044
loki             Running 809e9f87824da8ce0c6e283e8db2161d 152276045
logshipper       Running 809e9f87824da8ce0c6e283e8db2161d 152276046
vector           Running 809e9f87824da8ce0c6e283e8db2161d 152276047
netdata          Running 809e9f87824da8ce0c6e283e8db2161d 152276048
wifi-connect     Running 809e9f87824da8ce0c6e283e8db2161d 152276049
haproxy          Running 809e9f87824da8ce0c6e283e8db2161d 152276050
haproxy-sidecar  Running 809e9f87824da8ce0c6e283e8db2161d 152276051
mdns             Running 809e9f87824da8ce0c6e283e8db2161d 152276052
cert-manager     Running 809e9f87824da8ce0c6e283e8db2161d 152276053
balena-ca        Running 809e9f87824da8ce0c6e283e8db2161d 152276054
sideshow-bob     Running 809e9f87824da8ce0c6e283e8db2161d 152276055
test-bob         Running 809e9f87824da8ce0c6e283e8db2161d 152276056
autohat          Running 809e9f87824da8ce0c6e283e8db2161d 152276057
tag-sidecar      exited  809e9f87824da8ce0c6e283e8db2161d 152276058
ssm-agent        Running 809e9f87824da8ce0c6e283e8db2161d 152276059

Please check the CONTRIBUTING.md file for relevant information and some
guidance. Keep in mind that the CLI is a cross-platform application that runs
on Windows, macOS and Linux. Tests will be automatically run by balena CI on
all three operating systems, but this will only help if you have added test
code that exercises the modified or added feature code.

Note that each commit message (currently only the first line) will be
automatically copied to the CHANGELOG.md file, so try writing it in a way
that describes the feature or fix for CLI users.

If there isn't a linked issue or if the linked issue doesn't quite match the
PR, please add a PR description to explain its purpose or the features that it
implements. Adding PR comments to blocks of code that aren't self explanatory
usually helps with the review process.

If the PR introduces security considerations or affects the development, build
or release process, please be sure to highlight this in the PR description.

Thank you very much for your contribution!

@ghost
Copy link

ghost commented Aug 29, 2022

An error occurred whilst building your landr site preview:

{
  "name": "Error",
  "message": "Command failed with code undefined: /usr/src/app/node_modules/gatsby/cli.js build",
  "stack": "Error: Command failed with code undefined: /usr/src/app/node_modules/gatsby/cli.js build\n    at Object.exports.run (/usr/src/app/lib/build-runner.js:257:11)\n    at async build (/usr/src/app/bot/index.js:132:19)\n    at async /usr/src/app/bot/index.js:210:25\n    at async Promise.all (index 0)\n    at async middleware (/usr/src/app/node_modules/@octokit/webhooks/dist-node/index.js:355:5)"
}

@20k-ultra
Copy link
Contributor

@myarmolinsky the problem #1759 is outlining (albeit, not entirely clear) is that if you want to SSH into a device's containers you need to perform a few steps to get the right info.

In the output of balena scan we can see my device is running 2 containers but if I want to spawn a shell into them I cannot since I don't know them. I'd have to SSH to the host than ask the engine the services running than shell into the container from the host.

$ balena scan
Scanning for local balenaOS devices... Reporting scan results
- 
  host:          balena.local
  address:       10.0.0.79
  osVariant:     development
  dockerInfo: 
    Containers:        2
    ContainersRunning: 2
    ContainersPaused:  0
    ContainersStopped: 0
    Images:            3
    Driver:            overlay2
    SystemTime:        2022-08-31T23:35:28.691341632Z
    KernelVersion:     5.10.95-v8
    OperatingSystem:   balenaOS 2.99.27
    Architecture:      aarch64
  dockerVersion: 
    Version:    20.10.17
    ApiVersion: 1.41

the desired result is for balena scan to tell you the name of the containers so after scanning you can just ssh into it like so..

$ balena scan
Scanning for local balenaOS devices... Reporting scan results
- 
  host:          balena.local
  address:       10.0.0.79
  osVariant:     development
  dockerInfo: 
    Containers:        2 [balena-supervisor, grocy]
    ContainersRunning: 2
    ContainersPaused:  0
    ContainersStopped: 0
...

$ balena ssh 10.0.0.79 grocy
root@06d7100e6255:/#

@20k-ultra
Copy link
Contributor

The feature you've implemented here is still useful since someone can ask the device what services it has if you know the UUID.

@myarmolinsky myarmolinsky requested review from chrisys and removed request for 20k-ultra September 2, 2022 12:14
Comment on lines +74 to +85
device.image_install?.map((imageInstall) => {
const newImageInstall: AugmentedImageInstall = { ...imageInstall };
newImageInstall.name = getExpandedProp(
getExpandedProp(imageInstall.image, 'is_a_build_of__service')!,
'service_name',
);
newImageInstall.release = getExpandedProp(
imageInstall.is_provided_by__release,
'commit',
);
return newImageInstall;
}),
Copy link
Member

Choose a reason for hiding this comment

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

Since the UI already does render such a list, how about doing it in a similar way by using the device.current_services?
I would assume that this should be the first thing the check and then move any additional common code into the SDK itself.

Other than that, LGTM code-wise.

Suggested change
device.image_install?.map((imageInstall) => {
const newImageInstall: AugmentedImageInstall = { ...imageInstall };
newImageInstall.name = getExpandedProp(
getExpandedProp(imageInstall.image, 'is_a_build_of__service')!,
'service_name',
);
newImageInstall.release = getExpandedProp(
imageInstall.is_provided_by__release,
'commit',
);
return newImageInstall;
}),
Object.entries(device.current_services).flatMap(([serviceName, containers]) => {
return containers.map((container) => ({
...container,
name: serviceName,
release: container.commit,
});
}),

@ab77 ab77 force-pushed the add-device-services-command branch 2 times, most recently from 2ec92cd to c23138d Compare November 15, 2022 17:26
… on a device

Change-type: minor
Signed-off-by: Matthew Yarmolinsky <matthew-timothy@balena.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants