Skip to content

Commit

Permalink
Fix memory value assignment when passing constraints on OCI flex inst…
Browse files Browse the repository at this point in the history
…ances
  • Loading branch information
nvinuesa committed Oct 3, 2023
1 parent 7c938cd commit aaff68a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
2 changes: 1 addition & 1 deletion provider/oci/environ.go
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ func ensureShapeConfig(
// VM.Standard.A1.Flex, if we set 2 Ocpus OCI will set 12GB of
// memory (default is 6GB per core).
if constraints.HasMem() {
mem := float32(*constraints.Mem)
mem := float32(*constraints.Mem / 1024)
instanceDetails.ShapeConfig.MemoryInGBs = &mem
}
}
Expand Down
4 changes: 2 additions & 2 deletions provider/oci/environ_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (s *environSuite) TestEnsureShapeConfig(c *gc.C) {
maxMem: makeUint64Pointer(512 * 1024),
cpuCores: 1,
mem: 1024,
constraints: "mem=64",
constraints: "mem=64G",
want: &ociCore.LaunchInstanceShapeConfigDetails{
Ocpus: makeFloat32Pointer(float32(instances.MinCpuCores)),
MemoryInGBs: makeFloat32Pointer(64),
Expand All @@ -90,7 +90,7 @@ func (s *environSuite) TestEnsureShapeConfig(c *gc.C) {
maxMem: makeUint64Pointer(512 * 1024),
cpuCores: 1,
mem: 1024,
constraints: "cores=31 mem=64",
constraints: "cores=31 mem=64G",
want: &ociCore.LaunchInstanceShapeConfigDetails{
Ocpus: makeFloat32Pointer(31),
MemoryInGBs: makeFloat32Pointer(64),
Expand Down
16 changes: 6 additions & 10 deletions provider/oci/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,17 +334,13 @@ func instanceTypes(cli ComputeClient, compartmentID, imageID *string) ([]instanc
// OcpuOptions will not be nil and they indicate the maximum
// and minimum values. We assign the max memory and cpu cores
// values to the instance type in that case.
if val.MemoryOptions != nil {
if val.MemoryOptions.MaxInGBs != nil {
maxMem := uint64(*val.MemoryOptions.MaxInGBs) * 1024
newType.MaxMem = &maxMem
}
if val.MemoryOptions != nil && val.MemoryOptions.MaxInGBs != nil {
maxMem := uint64(*val.MemoryOptions.MaxInGBs) * 1024
newType.MaxMem = &maxMem
}
if val.OcpuOptions != nil {
if val.OcpuOptions.Max != nil {
maxCpuCores := uint64(*val.OcpuOptions.Max)
newType.MaxCpuCores = &maxCpuCores
}
if val.OcpuOptions != nil && val.OcpuOptions.Max != nil {
maxCpuCores := uint64(*val.OcpuOptions.Max)
newType.MaxCpuCores = &maxCpuCores
}
types = append(types, newType)
}
Expand Down

0 comments on commit aaff68a

Please sign in to comment.