From 1142dab8af9517592f0c99d0e0525b18f2852086 Mon Sep 17 00:00:00 2001 From: Grant Linville Date: Tue, 16 Jan 2024 14:32:21 -0500 Subject: [PATCH] fix: resolved offerings: prioritize -m over Acornfile (#2415) (#2416) Signed-off-by: Grant Linville --- .../resolvedofferings/computeclass.go | 4 +- .../resolvedofferings/computeclass_test.go | 4 ++ .../existing.yaml | 9 +++ .../expected.golden | 66 +++++++++++++++++++ .../input.yaml | 34 ++++++++++ 5 files changed, 115 insertions(+), 2 deletions(-) create mode 100644 pkg/controller/resolvedofferings/testdata/computeclass/with-acornfile-memory-and-spec-override/existing.yaml create mode 100644 pkg/controller/resolvedofferings/testdata/computeclass/with-acornfile-memory-and-spec-override/expected.golden create mode 100644 pkg/controller/resolvedofferings/testdata/computeclass/with-acornfile-memory-and-spec-override/input.yaml diff --git a/pkg/controller/resolvedofferings/computeclass.go b/pkg/controller/resolvedofferings/computeclass.go index 2c0798724..ee2344b04 100644 --- a/pkg/controller/resolvedofferings/computeclass.go +++ b/pkg/controller/resolvedofferings/computeclass.go @@ -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 { diff --git a/pkg/controller/resolvedofferings/computeclass_test.go b/pkg/controller/resolvedofferings/computeclass_test.go index 76cdfbed9..ef30d298c 100644 --- a/pkg/controller/resolvedofferings/computeclass_test.go +++ b/pkg/controller/resolvedofferings/computeclass_test.go @@ -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) +} diff --git a/pkg/controller/resolvedofferings/testdata/computeclass/with-acornfile-memory-and-spec-override/existing.yaml b/pkg/controller/resolvedofferings/testdata/computeclass/with-acornfile-memory-and-spec-override/existing.yaml new file mode 100644 index 000000000..68c21dc2e --- /dev/null +++ b/pkg/controller/resolvedofferings/testdata/computeclass/with-acornfile-memory-and-spec-override/existing.yaml @@ -0,0 +1,9 @@ +kind: ProjectInstance +apiVersion: internal.acorn.io/v1 +metadata: + name: app-namespace +spec: {} +status: + defaultRegion: local + supportedRegions: + - local diff --git a/pkg/controller/resolvedofferings/testdata/computeclass/with-acornfile-memory-and-spec-override/expected.golden b/pkg/controller/resolvedofferings/testdata/computeclass/with-acornfile-memory-and-spec-override/expected.golden new file mode 100644 index 000000000..1c2465d91 --- /dev/null +++ b/pkg/controller/resolvedofferings/testdata/computeclass/with-acornfile-memory-and-spec-override/expected.golden @@ -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: {} +` diff --git a/pkg/controller/resolvedofferings/testdata/computeclass/with-acornfile-memory-and-spec-override/input.yaml b/pkg/controller/resolvedofferings/testdata/computeclass/with-acornfile-memory-and-spec-override/input.yaml new file mode 100644 index 000000000..300f4e912 --- /dev/null +++ b/pkg/controller/resolvedofferings/testdata/computeclass/with-acornfile-memory-and-spec-override/input.yaml @@ -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