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

fix bugs to parse oci specs #23

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
58 changes: 33 additions & 25 deletions generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,13 @@ func modify(spec *specs.LinuxSpec, rspec *specs.LinuxRuntimeSpec, context *cli.C
spec.Platform.Arch = context.String("arch")
spec.Process.Cwd = context.String("cwd")
spec.Process.Terminal = context.Bool("terminal")
rspec.Linux.CgroupsPath = context.String("cgroupspath")
cgroupspath := context.String("cgroupspath")
rspec.Linux.CgroupsPath = &cgroupspath
rspec.Linux.ApparmorProfile = context.String("apparmor")
rspec.Linux.Resources.DisableOOMKiller = context.Bool("disableoomiller")
rspec.Linux.Resources.Pids.Limit = int64(context.Int("pids"))
disableoomiller := context.Bool("disableoomiller")
rspec.Linux.Resources.DisableOOMKiller = &disableoomiller
pids := int64(context.Int("pids"))
rspec.Linux.Resources.Pids.Limit = &pids
rspec.Linux.Resources.Network.ClassID = context.String("networkid")

for i, a := range context.StringSlice("args") {
Expand Down Expand Up @@ -236,21 +239,23 @@ func addBlockIO(spec *specs.LinuxSpec, rspec *specs.LinuxRuntimeSpec, context *c
if context.Int("blockio-weight") > 1000 || context.Int("blockio-weight") < 10 {
return fmt.Errorf("blockio-weight range is from 10 to 1000")
}
rspec.Linux.Resources.BlockIO.Weight = uint16(context.Int("blockio-weight"))
blkioweight := uint16(context.Int("blockio-weight"))
rspec.Linux.Resources.BlockIO.Weight = &blkioweight
}

if context.Int("blockio-leafweight") != 0 {
if context.Int("blockio-leafweight") > 1000 || context.Int("blockio-leafweight") < 10 {
return fmt.Errorf("blockio-leafweight range is from 10 to 1000")
}
rspec.Linux.Resources.BlockIO.LeafWeight = uint16(context.Int("blockio-leafweight"))
blkioleafweight := uint16(context.Int("blockio-leafweight"))
rspec.Linux.Resources.BlockIO.LeafWeight = &blkioleafweight
}
for _, trbds := range context.StringSlice("throttlereadbpsdevice") {
trbd := strings.Split(trbds, ":")
if len(trbd) == 2 {
fmt.Println("trbd=" + trbd[0])
blockIODevicestr := trbd[0]
rate, err := strconv.Atoi(trbd[1])
rate, err := strconv.ParseUint(trbd[1], 10, 64)
b := strings.Split(blockIODevicestr, ",")
if err != nil {
return err
Expand All @@ -264,7 +269,7 @@ func addBlockIO(spec *specs.LinuxSpec, rspec *specs.LinuxRuntimeSpec, context *c
// td := specs.ThrottleDevice{Rate: uint64(rate)}
// td.blockIODevice.Major = int64(major)
// td.blockIODevice.Minor = int64(minor)
td := specs.ThrottleDevice{Rate: uint64(rate)}
td := specs.ThrottleDevice{Rate: &rate}
rspec.Linux.Resources.BlockIO.ThrottleReadBpsDevice = append(rspec.Linux.Resources.BlockIO.ThrottleReadBpsDevice, &td)
} else {
return fmt.Errorf("throttlereadbpsdevice error: %s", blockIODevicestr)
Expand Down Expand Up @@ -314,11 +319,11 @@ func addHugepageLimit(spec *specs.LinuxSpec, rspec *specs.LinuxRuntimeSpec, cont
for _, hpls := range context.StringSlice("hugepagelimit") {
hpl := strings.Split(hpls, ":")
if len(hpl) == 2 {
limits, err := strconv.Atoi(hpl[1])
limits, err := strconv.ParseUint(hpl[1], 10, 64)
if err != nil {
return err
}
hp := specs.HugepageLimit{hpl[0], uint64(limits)}
hp := specs.HugepageLimit{&hpl[0], &limits}
rspec.Linux.Resources.HugepageLimits = append(rspec.Linux.Resources.HugepageLimits, hp)
} else {
return fmt.Errorf("hugepagelimit error: %s", hpls)
Expand All @@ -334,16 +339,18 @@ func setResourceCPU(spec *specs.LinuxSpec, rspec *specs.LinuxRuntimeSpec, contex
}
cpu := strings.Split(cpustr, ":")
if len(cpu) == 7 {
shares, err := strconv.Atoi(cpu[0])
quota, err := strconv.Atoi(cpu[1])
period, err := strconv.Atoi(cpu[2])
realtimeruntime, err := strconv.Atoi(cpu[3])
realtimeperiod, err := strconv.Atoi(cpu[4])
shares, err := strconv.ParseUint(cpu[0], 10, 64)
quota, err := strconv.ParseUint(cpu[1], 10, 64)
period, err := strconv.ParseUint(cpu[2], 10, 64)
realtimeruntime, err := strconv.ParseUint(cpu[3], 10, 64)
realtimeperiod, err := strconv.ParseUint(cpu[4], 10, 64)
if err != nil {
return err
}
cpustruct := specs.CPU{uint64(shares), uint64(quota), uint64(period), uint64(realtimeruntime), uint64(realtimeperiod), cpu[5], cpu[6]}
rspec.Linux.Resources.CPU = cpustruct
cpus := cpu[5]
mems := cpu[6]
cpustruct := specs.CPU{&shares, &quota, &period, &realtimeruntime, &realtimeperiod, &cpus, &mems}
rspec.Linux.Resources.CPU = &cpustruct
} else {
return fmt.Errorf("cpu error: %s", cpustr)
}
Expand All @@ -357,16 +364,17 @@ func setResourceMemory(spec *specs.LinuxSpec, rspec *specs.LinuxRuntimeSpec, con
}
mem := strings.Split(mems, ":")
if len(mem) == 5 {
limit, err := strconv.Atoi(mem[0])
reservation, err := strconv.Atoi(mem[1])
swap, err := strconv.Atoi(mem[2])
kernel, err := strconv.Atoi(mem[3])
swapniess, err := strconv.Atoi(mem[4])
limit, err := strconv.ParseUint(mem[0], 10, 64)
reservation, err := strconv.ParseUint(mem[1], 10, 64)
swap, err := strconv.ParseUint(mem[2], 10, 64)
kernel, err := strconv.ParseUint(mem[3], 10, 64)
kerneltcp, err := strconv.ParseUint(mem[4], 10, 64)
swapniess, err := strconv.ParseUint(mem[5], 10, 64)
if err != nil {
return err
}
memorystruct := specs.Memory{uint64(limit), uint64(reservation), uint64(swap), uint64(kernel), uint64(swapniess)}
rspec.Linux.Resources.Memory = memorystruct
memorystruct := specs.Memory{&limit, &reservation, &swap, &kernel, &kerneltcp, &swapniess}
rspec.Linux.Resources.Memory = &memorystruct
} else {
return fmt.Errorf("memory error: %s", mems)
}
Expand Down Expand Up @@ -971,8 +979,8 @@ func getDefaultTemplate() (specs.LinuxSpec, specs.LinuxRuntimeSpec) {
},
},
Resources: &specs.Resources{
Memory: specs.Memory{
Swappiness: 1,
Memory: &specs.Memory{
Swappiness: nil,
},
},
},

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Mashimiao about the swappiness ,there is a discussion in specs opencontainers/runtime-spec#279 , we can refer to that PR and decide how to fix it

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, agree with @wangkirin, @Mashimiao can you fixed it? Or any other suggestion will be welcomed.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zenlinTechnofreak, @wangkirin I read opencontainers/runtime-spec#279 and related pulls. I think the possible and suitable fix is to set Swappiness with nil, as follows:
Resources: &specs.Resources{ Memory: &specs.Memory{ Swappiness: nil, }, },
Do you agree?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Mashimiao Yes, but we'd better to keep '-1' util the PR have merged into specs, thus to keep runnable of the ocitool with master of specs.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I'm a little confused
opencontainers/runtime-spec#233 has been merged and opencontainers/runtime-spec#279 just fixed document. If we did not change '-1', we can't compile octtool with master of specs.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Mashimiao Sorry, My meaning is runc have not changed yet, if we change '-1', we could not debug OCT with runc, so my suggestion is waiting util runc have been updated.
reference:
section 'OCI Container JSON Format' in https://github.com/opencontainers/runc/blob/master/README.md

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks 👍

Expand Down