Skip to content

Commit

Permalink
fix(convert): fixed panic in resource limits conversion (#15)
Browse files Browse the repository at this point in the history
Signed-off-by: Ben Meier <[email protected]>
  • Loading branch information
astromechza authored May 30, 2024
1 parent e675f96 commit f2a3559
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions internal/convert/container_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ func convertContainerResources(resources *scoretypes.ContainerResources) (coreV1
if err != nil {
return out, errors.Wrap(err, "requests: failed to convert")
}
}
if resources.Limits != nil {
out.Limits, err = buildResourceList(resources.Limits)
if err != nil {
return out, errors.Wrap(err, "limits: failed to convert")
Expand Down
14 changes: 14 additions & 0 deletions internal/convert/container_resources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,17 @@ func Test_convertContainerResources_nominal(t *testing.T) {
},
}, rl)
}

func Test_convertContainerResources_partial(t *testing.T) {
rl, err := convertContainerResources(&scoretypes.ContainerResources{
Limits: &scoretypes.ResourcesLimits{
Memory: internal.Ref("20Mi"),
},
})
assert.NoError(t, err)
assert.Equal(t, coreV1.ResourceRequirements{
Limits: map[coreV1.ResourceName]resource.Quantity{
"memory": resource.MustParse("20Mi"),
},
}, rl)
}

0 comments on commit f2a3559

Please sign in to comment.