mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-07-19 09:16:29 +00:00
Merge pull request #1802 from ijc25/metadata-simple-content
Metadata fix + a simpler file content option
This commit is contained in:
commit
54479cb917
@ -29,10 +29,7 @@ For example, the following userdata file:
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"foo" : {
|
"foo" : {
|
||||||
"bar" : {
|
"bar" : "foobar",
|
||||||
"perm": "0644",
|
|
||||||
"content": "foobar"
|
|
||||||
},
|
|
||||||
"baz" : {
|
"baz" : {
|
||||||
"perm": "0600",
|
"perm": "0600",
|
||||||
"content": "bar"
|
"content": "bar"
|
||||||
@ -47,6 +44,16 @@ will generate the following files:
|
|||||||
/var/config/foo/baz
|
/var/config/foo/baz
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Each file can either be:
|
||||||
|
|
||||||
|
- a simple string (as for `foo/bar` above) in which case the file will
|
||||||
|
be created with the given contents and read/write (but not execute)
|
||||||
|
permissions for user and read permissions for group and everyone else (in octal format `0644`).
|
||||||
|
- a map (as for `ssh/sshd_config` and `foo/baz` above) with the
|
||||||
|
following mandatory keys:
|
||||||
|
- `content`: the contents of the file.
|
||||||
|
- `perm`: the permissions to create the file with.
|
||||||
|
|
||||||
This hierarchy can then be used by individual containers, who can bind
|
This hierarchy can then be used by individual containers, who can bind
|
||||||
mount the config sub-directory into their namespace where it is
|
mount the config sub-directory into their namespace where it is
|
||||||
needed.
|
needed.
|
||||||
|
@ -167,11 +167,11 @@ func processUserData(data []byte) error {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
for f, i := range files {
|
for f, i := range files {
|
||||||
fi := i.(map[string]interface{})
|
p := uint64(0644)
|
||||||
if !ok {
|
var c string
|
||||||
log.Printf("Could convert JSON for items: %s", i)
|
|
||||||
continue
|
switch fi := i.(type) {
|
||||||
}
|
case map[string]interface{}:
|
||||||
if _, ok := fi["perm"]; !ok {
|
if _, ok := fi["perm"]; !ok {
|
||||||
log.Printf("No permission provided %s:%s", f, fi)
|
log.Printf("No permission provided %s:%s", f, fi)
|
||||||
continue
|
continue
|
||||||
@ -180,12 +180,18 @@ func processUserData(data []byte) error {
|
|||||||
log.Printf("No content provided %s:%s", f, fi)
|
log.Printf("No content provided %s:%s", f, fi)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
c := fi["content"].(string)
|
c = fi["content"].(string)
|
||||||
p, err := strconv.ParseUint(fi["perm"].(string), 8, 32)
|
if p, err = strconv.ParseUint(fi["perm"].(string), 8, 32); err != nil {
|
||||||
if err != nil {
|
|
||||||
log.Printf("Failed to parse permission %s: %s", fi, err)
|
log.Printf("Failed to parse permission %s: %s", fi, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
case string:
|
||||||
|
c = fi
|
||||||
|
default:
|
||||||
|
log.Printf("Couldn't convert JSON for items: %s", i)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
if err := ioutil.WriteFile(path.Join(dir, f), []byte(c), os.FileMode(p)); err != nil {
|
if err := ioutil.WriteFile(path.Join(dir, f), []byte(c), os.FileMode(p)); err != nil {
|
||||||
log.Printf("Failed to write %s/%s: %s", dir, f, err)
|
log.Printf("Failed to write %s/%s: %s", dir, f, err)
|
||||||
continue
|
continue
|
||||||
|
Loading…
Reference in New Issue
Block a user