Skip to content

Commit 2473893

Browse files
committed
feat: detect self update using the container sm-plugin type
1 parent 9712b48 commit 2473893

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

.goreleaser.yaml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,6 @@ nfpms:
107107
dst: /etc/tedge/sm-plugins/container-group
108108
type: symlink
109109

110-
# apk only (used for self updates)
111-
- src: /usr/bin/tedge-container
112-
dst: /etc/tedge/sm-plugins/self
113-
type: symlink
114-
packager: apk
115-
116110
# Config
117111
- src: ./packaging/config.toml
118112
dst: /etc/tedge/plugins/tedge-container-plugin.toml

cli/self/check.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,14 @@ func (c *CheckCommand) RunE(cmd *cobra.Command, args []string) error {
106106
match.ContainerName = item.Name
107107
match.Image = item.Version
108108
includesSelfUpdate = true
109-
break
109+
} else if item.Action == SoftwareManagementActionRemove {
110+
return cli.ExitCodeError{
111+
Code: ExitError,
112+
Err: fmt.Errorf("tedge's own container cannot be removed. name=%s, version=%s, containerId=%s", item.Name, item.Version, selfContainerID),
113+
Silent: true,
114+
}
110115
}
111116
}
112-
break
113117
} else if module.Type == SoftwareManagementTypeContainer {
114118
// container update
115119
// Filter non self-updated modules
@@ -119,7 +123,11 @@ func (c *CheckCommand) RunE(cmd *cobra.Command, args []string) error {
119123
if selfContainerName == item.Name {
120124
if item.Action == SoftwareManagementActionRemove {
121125
// Protect against the user deleting the tedge container itself
122-
return fmt.Errorf("tedge's own container cannot be removed. name=%s, version=%s, containerId=%s", item.Name, item.Version, selfContainerID)
126+
return cli.ExitCodeError{
127+
Code: ExitError,
128+
Err: fmt.Errorf("tedge's own container cannot be removed. name=%s, version=%s, containerId=%s", item.Name, item.Version, selfContainerID),
129+
Silent: true,
130+
}
123131
} else if item.Action == SoftwareManagementActionInstall {
124132
// install
125133
match.ContainerName = item.Name

tests/self.robot

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ Test Tags docker podman
1010

1111
*** Test Cases ***
1212

13-
Self Update Is Present
13+
Self Update Is Present Using Self Type
14+
${output}= DeviceLibrary.Execute Command cmd=tedge-container self check '[{"type":"self","modules":[{"name":"tedge","action":"install","version":"123"}]},{"type":"container","modules":[{"name":"foo","version":"bar:1.0.0","action":"install"}]}]' --container tedge strip=${True}
15+
Should Contain ${output} {"containerName":"tedge","image":"123","updateList":[{"type":"container","modules":[{"name":"foo","version":"bar:1.0.0","action":"install"}]}]}
16+
17+
Self Update Is Present Using Container Type
1418
${output}= DeviceLibrary.Execute Command cmd=tedge-container self check '[{"type":"container","modules":[{"name":"tedge","action":"install","version":"123"},{"name":"foo","action":"install","version":"bar:latest","url":"https://foobar.com/example"}]}]' --container tedge strip=${True}
1519
Should Contain ${output} {"containerName":"tedge","image":"123","updateList":[{"type":"container","modules":[{"name":"foo","version":"bar:latest","url":"https://foobar.com/example","action":"install"}]}]}
1620

0 commit comments

Comments
 (0)