Skip to content
This repository has been archived by the owner on Mar 16, 2024. It is now read-only.

Commit

Permalink
fix: resolved offerings: prioritize -m over Acornfile (#2415) (#2416)
Browse files Browse the repository at this point in the history
Signed-off-by: Grant Linville <[email protected]>
  • Loading branch information
g-linville authored Jan 16, 2024
1 parent 626278e commit 1142dab
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pkg/controller/resolvedofferings/computeclass.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ func resolveComputeClass(req router.Request, appInstance *v1.AppInstance, config

if appInstance.Spec.Memory[name] != nil { // runtime-level overrides from the user
memory = appInstance.Spec.Memory[name]
} else if container.Memory != nil { // defaults in the acorn image
memory = container.Memory
} else if appInstance.Spec.Memory[""] != nil { // runtime-level overrides from the user for all containers in the app
memory = appInstance.Spec.Memory[""]
} else if container.Memory != nil { // defaults in the acorn image
memory = container.Memory
} else if cc != nil { // defaults from compute class
parsedMemory, err := computeclasses.ParseComputeClassMemory(cc.Memory)
if err != nil {
Expand Down
4 changes: 4 additions & 0 deletions pkg/controller/resolvedofferings/computeclass_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,7 @@ func TestAcornfileOverrideComputeClass(t *testing.T) {
func TestUserOverrideComputeClass(t *testing.T) {
tester.DefaultTest(t, scheme.Scheme, "testdata/computeclass/user-override-compute-class", Calculate)
}

func TestWithAcornfileMemoryAndSpecOverride(t *testing.T) {
tester.DefaultTest(t, scheme.Scheme, "testdata/computeclass/with-acornfile-memory-and-spec-override", Calculate)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
kind: ProjectInstance
apiVersion: internal.acorn.io/v1
metadata:
name: app-namespace
spec: {}
status:
defaultRegion: local
supportedRegions:
- local
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
`apiVersion: internal.acorn.io/v1
kind: AppInstance
metadata:
creationTimestamp: null
name: app-name
namespace: app-namespace
uid: 1234567890abcdef
spec:
image: test
memory:
"": 3145728
status:
appImage:
buildContext: {}
id: test
imageData: {}
vcs: {}
appSpec:
containers:
oneimage:
build:
context: .
dockerfile: Dockerfile
image: image-name
memory: 1048576
metrics: {}
ports:
- port: 80
protocol: http
targetPort: 81
probes: null
sidecars:
left:
image: foo
metrics: {}
ports:
- port: 90
protocol: tcp
targetPort: 91
probes: null
appStatus: {}
columns: {}
conditions:
reason: Success
status: "True"
success: true
type: resolved-offerings
defaults: {}
namespace: app-created-namespace
observedGeneration: 1
resolvedOfferings:
containers:
"":
memory: 3145728
left:
memory: 3145728
oneimage:
memory: 3145728
region: local
staged:
appImage:
buildContext: {}
imageData: {}
vcs: {}
summary: {}
`
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
kind: AppInstance
apiVersion: internal.acorn.io/v1
metadata:
name: app-name
namespace: app-namespace
uid: 1234567890abcdef
spec:
image: test
memory:
"": 3145728 # 3Mi - this will take precedence over the 1Mi specified below in the status.appSpec
status:
observedGeneration: 1
namespace: app-created-namespace
appImage:
id: test
appSpec:
containers:
oneimage:
sidecars:
left:
image: "foo"
ports:
- port: 90
targetPort: 91
protocol: tcp
ports:
- port: 80
targetPort: 81
protocol: http
image: "image-name"
build:
dockerfile: "Dockerfile"
context: "."
memory: 1048576 # 1Mi

0 comments on commit 1142dab

Please sign in to comment.