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

Installing/updating configuration files via the containers update agent. #232

Closed
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 9 additions & 1 deletion containerm/updateagent/to_containers.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ package updateagent
import (
"strconv"
"time"
"os"

ctrtypes "github.com/eclipse-kanto/container-management/containerm/containers/types"
"github.com/eclipse-kanto/container-management/containerm/log"
Expand Down Expand Up @@ -66,7 +67,14 @@ func toContainer(component *types.ComponentWithConfig) (*ctrtypes.Container, err
case keyHost:
extraHosts = append(extraHosts, keyValuePair.Value)
case keyMount:
mountPoint, err := util.ParseMountPoint(keyValuePair.Value)
mountPoint, configInfo, err := util.ParseMountPoint(keyValuePair.Value)
if len(configInfo) != 0 {
err :=os.WriteFile(mountPoint.Source+"/"+component.ID+"_config.json", configInfo, 0755)
saurav-madhusoodanan marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
log.WarnErr(err, "Error writing to file.")
//add case where file is not written properly.
saurav-madhusoodanan marked this conversation as resolved.
Show resolved Hide resolved
}
}
if err != nil {
log.WarnErr(err, "Ignoring invalid mount point")
} else {
Expand Down
30 changes: 24 additions & 6 deletions containerm/util/containers_parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"net"
"strconv"
"strings"
"encoding/base64"

"github.com/eclipse-kanto/container-management/containerm/containers/types"
"github.com/eclipse-kanto/container-management/containerm/log"
Expand Down Expand Up @@ -73,7 +74,7 @@ func ParseDeviceMapping(device string) (*types.DeviceMapping, error) {
func ParseMountPoints(mps []string) ([]types.MountPoint, error) {
var mountPoints []types.MountPoint
for _, mp := range mps {
mount, err := ParseMountPoint(mp)
mount, _, err := ParseMountPoint(mp)
if err != nil {
return nil, err
}
Expand All @@ -83,25 +84,42 @@ func ParseMountPoints(mps []string) ([]types.MountPoint, error) {
}

// ParseMountPoint converts a single string representation of a container's mount to a structured MountPoint instance.
// Format: source:destination[:propagation_mode].
// Format: source:destination[:propagation_mode]:encoded_config_file_information.
saurav-madhusoodanan marked this conversation as resolved.
Show resolved Hide resolved
// If the propagation mode parameter is omitted, rprivate will be set by default.
// Available propagation modes are: rprivate, private, rshared, shared, rslave, slave.
func ParseMountPoint(mp string) (*types.MountPoint, error) {
func ParseMountPoint(mp string) (*types.MountPoint, []byte, error) {
mount := strings.Split(strings.TrimSpace(mp), ":")
if len(mount) < 2 || len(mount) > 3 {
return nil, log.NewErrorf("Incorrect number of parameters of the mount point %s", mp)
if len(mount) < 2 || len(mount) > 4 {
return nil, []byte(""), log.NewErrorf("Incorrect number of parameters of the mount point %s", mp)
saurav-madhusoodanan marked this conversation as resolved.
Show resolved Hide resolved
}
mountPoint := &types.MountPoint{
Destination: mount[1],
Source: mount[0],
}
var configInfo []byte
var err error
if len(mount) == 2 {
// if propagation mode is omitted, "rprivate" is set as default
mountPoint.PropagationMode = types.RPrivatePropagationMode
} else if len(mount) == 3 {
// if the lenght of mount is 3, figure out which part was omitted and proceed accordingly.
if mount[2] == types.RPrivatePropagationMode || mount[2] == types.PrivatePropagationMode || mount[2] == types.RSharedPropagationMode || mount[2] == types.SharedPropagationMode || mount[2] == types.RSlavePropagationMode || mount[2] == types.SlavePropagationMode {
mountPoint.PropagationMode = mount[2]
} else {
mountPoint.PropagationMode = types.RPrivatePropagationMode
configInfo, err = base64.StdEncoding.DecodeString(mount[2])
if err != nil {
log.Fatal("error:", err)
saurav-madhusoodanan marked this conversation as resolved.
Show resolved Hide resolved
}
}
} else {
mountPoint.PropagationMode = mount[2]
configInfo, err = base64.StdEncoding.DecodeString(mount[3])
if err != nil {
log.Fatal("error:", err)
}
}
return mountPoint, nil
return mountPoint, configInfo, nil
}

// ParsePortMappings converts string representations of container's port mappings to structured PortMapping instances.
Expand Down
4 changes: 2 additions & 2 deletions containerm/util/containers_parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,11 @@ func TestParseMountPoints(t *testing.T) {

t.Log(testCase.inputString)

res, err := ParseMountPoint(testCase.inputString)
res, _, err := ParseMountPoint(testCase.inputString)
testutil.AssertNil(t, err)
testutil.AssertEqual(t, testCase.expectedMount, res)

res, err = ParseMountPoint(MountPointToString(res))
res, _, err = ParseMountPoint(MountPointToString(res))
testutil.AssertNil(t, err)
testutil.AssertEqual(t, testCase.expectedMount, res)

Expand Down
Loading