Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
annotations: Add annotations for runtime config
Browse files Browse the repository at this point in the history
Additional annotations added to customise runtime configuration.

Signed-off-by: Archana Shinde <[email protected]>
  • Loading branch information
amshinde committed Oct 3, 2019
1 parent afb91c2 commit 5b78a8a
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
20 changes: 20 additions & 0 deletions virtcontainers/pkg/annotations/annotations.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,26 @@ const (
BlockDeviceCacheNoflush = kataAnnotHypervisorPrefix + "block_device_cache_noflush"
)

const (
kataAnnotRuntimePrefix = kataConfAnnotationsPrefix + "runtime."

// DisableGuestSeccomp is a sandbox annotation that determines if seccomp should be applied inside guest.
DisableGuestSeccomp = kataAnnotRuntimePrefix + "disable_guest_seccomp"

// SandboxCgroupOnly is a sandbox annotation that determines if kata processes are managed only in sandbox cgroup.
SandboxCgroupOnly = kataAnnotRuntimePrefix + "sandbox_cgroup_only"

// Experimental is a sandbox annotation that determines if experimental features enabled.
Experimental = kataAnnotRuntimePrefix + "experimental"

// InterNetworkModel is a sandbox annotaion that determines how the VM should be connected to the
//the container network interface.
InterNetworkModel = kataAnnotRuntimePrefix + "internetworking_model"

// DisableNewNetNs is a sandbox annotation that determines if create a netns for hypervisor process.
DisableNewNetNs = kataAnnotRuntimePrefix + "disable_new_netns"
)

const (
kataAnnotAgentPrefix = kataConfAnnotationsPrefix + "agent."

Expand Down
56 changes: 56 additions & 0 deletions virtcontainers/pkg/oci/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,10 @@ func addAnnotations(ocispec specs.Spec, config *vc.SandboxConfig) error {
return err
}

if err := addRuntimeConfigOverrides(ocispec, config); err != nil {
return err
}

if err := addAgentConfigOverrides(ocispec, config); err != nil {
return err
}
Expand Down Expand Up @@ -657,6 +661,58 @@ func addHypervisporVirtioFsOverrides(ocispec specs.Spec, sbConfig *vc.SandboxCon
return nil
}

func addRuntimeConfigOverrides(ocispec specs.Spec, sbConfig *vc.SandboxConfig) error {
if value, ok := ocispec.Annotations[vcAnnotations.DisableGuestSeccomp]; ok {
disableGuestSeccomp, err := strconv.ParseBool(value)
if err != nil {
return fmt.Errorf("Error parsing annotation for disable_guest_seccomp: Please specify boolean value 'true|false'")
}

sbConfig.DisableGuestSeccomp = disableGuestSeccomp
}

if value, ok := ocispec.Annotations[vcAnnotations.SandboxCgroupOnly]; ok {
sandboxCgroupOnly, err := strconv.ParseBool(value)
if err != nil {
return fmt.Errorf("Error parsing annotation for sandbox_cgroup_only: Please specify boolean value 'true|false'")
}

sbConfig.SandboxCgroupOnly = sandboxCgroupOnly
}

if value, ok := ocispec.Annotations[vcAnnotations.Experimental]; ok {
features := strings.Split(value, " ")
sbConfig.Experimental = []exp.Feature{}

for _, f := range features {
feature := exp.Get(f)
if feature == nil {
return fmt.Errorf("Unsupported experimental feature %s specified in annotation %v", f, vcAnnotations.Experimental)
}
sbConfig.Experimental = append(sbConfig.Experimental, *feature)
}
}

if value, ok := ocispec.Annotations[vcAnnotations.DisableNewNetNs]; ok {
disableNewNetNs, err := strconv.ParseBool(value)
if err != nil {
return fmt.Errorf("Error parsing annotation for experimental: Please specify boolean value 'true|false'")
}
sbConfig.NetworkConfig.DisableNewNetNs = disableNewNetNs
}

if value, ok := ocispec.Annotations[vcAnnotations.InterNetworkModel]; ok {
runtimeConfig := RuntimeConfig{}
if err := runtimeConfig.InterNetworkModel.SetModel(value); err != nil {
return fmt.Errorf("Unknown network model specified in annotation %s", vcAnnotations.InterNetworkModel)
}

sbConfig.NetworkConfig.InterworkingModel = runtimeConfig.InterNetworkModel
}

return nil
}

func addAgentConfigOverrides(ocispec specs.Spec, config *vc.SandboxConfig) error {
if value, ok := ocispec.Annotations[vcAnnotations.KernelModules]; ok {
if c, ok := config.AgentConfig.(vc.KataAgentConfig); ok {
Expand Down

0 comments on commit 5b78a8a

Please sign in to comment.