/
spec_annotations.go
41 lines (32 loc) · 1.13 KB
/
spec_annotations.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package mgr
import (
"context"
"strconv"
"github.com/alibaba/pouch/pkg/log"
specs "github.com/opencontainers/runtime-spec/specs-go"
)
// setupAnnotations extracts other related options from HostConfig and locate them in spec's annotations which will be dealt by vendored runc.
func setupAnnotations(ctx context.Context, c *Container, s *specs.Spec) error {
if s.Annotations == nil {
s.Annotations = make(map[string]string)
}
r := c.HostConfig.Resources
if r.MemoryWmarkRatio != nil {
s.Annotations["__memory_wmark_ratio"] = strconv.FormatInt(*r.MemoryWmarkRatio, 10)
}
if r.MemoryExtra != nil {
s.Annotations["__memory_extra_in_bytes"] = strconv.FormatInt(*r.MemoryExtra, 10)
}
s.Annotations["__memory_force_empty_ctl"] = strconv.FormatInt(r.MemoryForceEmptyCtl, 10)
s.Annotations["__schedule_latency_switch"] = strconv.FormatInt(r.ScheLatSwitch, 10)
// add additional spec annotations
annotations := c.Config.SpecAnnotation
for k, v := range annotations {
if _, exist := s.Annotations[k]; exist {
log.With(nil).Warnf("Duplicate spec annotation: %s=%s", k, v)
continue
}
s.Annotations[k] = v
}
return nil
}