Skip to content
Open
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
27 changes: 16 additions & 11 deletions cmd/atelet/oci.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,21 @@ func prepareOCIDirectory(ctx context.Context, pullCache *memorypullcache.MemoryP
}
envVars = append(envVars, env...)

ociSpec := &specs.Spec{
ociSpec := buildSpec(args, envVars, annotations, netns, actorTemplateNamespace, actorTemplateName, actorID, containerName)
ociSpecBytes, err := json.MarshalIndent(ociSpec, "", " ")
if err != nil {
return fmt.Errorf("while marshaling OCI spec: %w", err)
}
specPath := path.Join(bundlePath, "config.json")
if err := os.WriteFile(specPath, ociSpecBytes, 0o600); err != nil {
return fmt.Errorf("while writing OCI spec: %w", err)
}

return nil
}

func buildSpec(args, envVars []string, annotations map[string]string, netns, actorTemplateNamespace, actorTemplateName, actorID, containerName string) *specs.Spec {
return &specs.Spec{
Process: &specs.Process{
User: specs.User{
UID: 0,
Expand Down Expand Up @@ -142,6 +156,7 @@ func prepareOCIDirectory(ctx context.Context, pullCache *memorypullcache.MemoryP
},
},
Linux: &specs.Linux{
CgroupsPath: path.Join("actors", actorTemplateNamespace, actorTemplateName, actorID, containerName),
Namespaces: []specs.LinuxNamespace{
{
Type: "pid",
Expand All @@ -163,16 +178,6 @@ func prepareOCIDirectory(ctx context.Context, pullCache *memorypullcache.MemoryP
},
Annotations: annotations,
}
ociSpecBytes, err := json.MarshalIndent(ociSpec, "", " ")
if err != nil {
return fmt.Errorf("while marshaling OCI spec: %w", err)
}
specPath := path.Join(bundlePath, "config.json")
if err := os.WriteFile(specPath, ociSpecBytes, 0o600); err != nil {
return fmt.Errorf("while writing OCI spec: %w", err)
}

return nil
}

func validateTarName(name string) (cleaned string, skip bool, err error) {
Expand Down
18 changes: 18 additions & 0 deletions cmd/atelet/oci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -450,3 +450,21 @@ func TestUntar_TruncatedArchive(t *testing.T) {
t.Errorf("error = %v, want it to surface the underlying tar/copy error", err)
}
}

func TestBuildSpec(t *testing.T) {
spec := buildSpec(
[]string{"/bin/sh"},
[]string{"PATH=/usr/bin"},
map[string]string{"k": "v"},
"/var/run/netns/foo",
"actorTemplateNamespace",
"actorTemplateName",
"actorID",
"123",
)

wantCgroups := "actors/actorTemplateNamespace/actorTemplateName/actorID/123"
if got := spec.Linux.CgroupsPath; got != wantCgroups {
t.Errorf("Linux.CgroupsPath = %q, want %q", got, wantCgroups)
}
}