Skip to content

Commit

Permalink
Merge pull request #370 from Microsoft/jjh/annotations2
Browse files Browse the repository at this point in the history
Fix panic
  • Loading branch information
jterry75 authored Nov 9, 2018
2 parents 02bd684 + 102a6f0 commit 4f64a59
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions cmd/runhcs/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,53 +390,53 @@ func createContainer(cfg *containerConfig) (_ *container, err error) {

// Cater for fields that can be configured via OCI annotations
if v, ok := cfg.Spec.Annotations[annotationAllowOverCommit]; ok {
var allowOvercommit *bool
yes := true
no := false
switch strings.ToLower(v) {
case "true":
*allowOvercommit = true
opts.AllowOvercommit = &yes
case "false":
*allowOvercommit = false
opts.AllowOvercommit = &no
default:
return nil, fmt.Errorf("annotation %s must be true or false", annotationAllowOverCommit)
}
opts.AllowOvercommit = allowOvercommit
}

if v, ok := cfg.Spec.Annotations[annotationEnableDeferredCommit]; ok {
var enableDeferredCommit *bool
yes := true
no := false
switch strings.ToLower(v) {
case "true":
*enableDeferredCommit = true
opts.EnableDeferredCommit = &yes
case "false":
*enableDeferredCommit = false
opts.EnableDeferredCommit = &no
default:
return nil, fmt.Errorf("annotation %s must be true or false", annotationEnableDeferredCommit)
}
opts.EnableDeferredCommit = enableDeferredCommit
}

if v, ok := cfg.Spec.Annotations[annotationVPMemCount]; ok {
var (
countu uint64
counti *uint32
counti uint32
err error
)
if countu, err = strconv.ParseUint(v, 10, 32); err != nil {
return nil, fmt.Errorf("annotation %s could not be parsed: %s", annotationVPMemCount, err)
}
*counti = uint32(countu)
opts.VPMemDeviceCount = counti
counti = uint32(countu)
opts.VPMemDeviceCount = &counti
}

if v, ok := cfg.Spec.Annotations[annotationVPMemSize]; ok {
var (
countu *uint64
countu uint64
err error
)
if *countu, err = strconv.ParseUint(v, 10, 64); err != nil {
if countu, err = strconv.ParseUint(v, 10, 64); err != nil {
return nil, fmt.Errorf("annotation %s could not be parsed: %s", annotationVPMemSize, err)
}
opts.VPMemSizeBytes = countu
opts.VPMemSizeBytes = &countu
}

shim, err := c.startVMShim(cfg.VMLogFile, opts)
Expand Down

0 comments on commit 4f64a59

Please sign in to comment.