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

Commit

Permalink
add controller side changes and tests
Browse files Browse the repository at this point in the history
Signed-off-by: Oscar Ward <[email protected]>
  • Loading branch information
Oscar Ward committed Feb 14, 2024
1 parent 643edce commit aba032b
Show file tree
Hide file tree
Showing 23 changed files with 880 additions and 2 deletions.
8 changes: 8 additions & 0 deletions pkg/controller/defaults/memory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ func TestMemorySameGeneration(t *testing.T) {
tester.DefaultTest(t, scheme.Scheme, "testdata/memory/same-generation", Calculate)
}

func TestTwoCCCDefaultsCrossRegion(t *testing.T) {
tester.DefaultTest(t, scheme.Scheme, "testdata/memory/two-ccc-defaults-different-regions", Calculate)
}

func TestTwoPCCDefaultsCrossRegion(t *testing.T) {
tester.DefaultTest(t, scheme.Scheme, "testdata/memory/two-pcc-defaults-different-regions", Calculate)
}

func TestTwoCCCDefaultsShouldError(t *testing.T) {
harness, input, err := tester.FromDir(scheme.Scheme, "testdata/memory/two-ccc-defaults-should-error")
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
---
kind: ClusterComputeClassInstance
apiVersion: internal.admin.acorn.io/v1
metadata:
name: sample-compute-class
description: Simple description for a simple ComputeClass
cpuScaler: 0.25
default: true
memory:
min: 1Mi # 1Mi
max: 2Mi # 2Mi
default: 1Mi # 1Mi
supportedRegions: [local]
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: foo
operator: In
values:
- bar
---
kind: ClusterComputeClassInstance
apiVersion: internal.admin.acorn.io/v1
metadata:
name: sample-compute-class-other
description: Simple description for a simple ComputeClass
cpuScaler: 0.25
default: true
supportedRegions: [non-local]
memory:
min: 1Mi # 1Mi
max: 2Mi # 2Mi
default: 2Mi # 2Mi
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: foo
operator: In
values:
- bar
---
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,62 @@
`apiVersion: internal.acorn.io/v1
kind: AppInstance
metadata:
creationTimestamp: null
name: app-name
namespace: app-namespace
uid: 1234567890abcdef
spec:
image: test
memory:
oneimage: 1048576
status:
appImage:
buildContext: {}
id: test
imageData: {}
vcs: {}
appSpec:
containers:
oneimage:
build:
context: .
dockerfile: Dockerfile
image: image-name
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: defaults
defaults:
memory:
"": 1048576
left: 1048576
oneimage: 1048576
region: local
namespace: app-created-namespace
observedGeneration: 1
resolvedOfferings: {}
staged:
appImage:
buildContext: {}
imageData: {}
vcs: {}
summary: {}
`
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
kind: AppInstance
apiVersion: internal.acorn.io/v1
metadata:
name: app-name
namespace: app-namespace
uid: 1234567890abcdef
spec:
image: test
memory:
oneimage: 1048576 # 1Mi
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: "."
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
---
kind: ProjectComputeClassInstance
apiVersion: internal.admin.acorn.io/v1
metadata:
name: sample-compute-class
namespace: app-namespace
description: Simple description for a simple ComputeClass
cpuScaler: 0.25
default: true
memory:
min: 1Mi # 1Mi
max: 2Mi # 2Mi
default: 1Mi # 1Mi
supportedRegions: [local]
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: foo
operator: In
values:
- bar
---
kind: ProjectComputeClassInstance
apiVersion: internal.admin.acorn.io/v1
metadata:
name: sample-compute-class-other
namespace: app-namespace
description: Simple description for a simple ComputeClass
cpuScaler: 0.25
default: true
supportedRegions: [non-local]
memory:
min: 1Mi # 1Mi
max: 2Mi # 2Mi
default: 2Mi # 2Mi
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: foo
operator: In
values:
- bar
---
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,62 @@
`apiVersion: internal.acorn.io/v1
kind: AppInstance
metadata:
creationTimestamp: null
name: app-name
namespace: app-namespace
uid: 1234567890abcdef
spec:
image: test
memory:
oneimage: 1048576
status:
appImage:
buildContext: {}
id: test
imageData: {}
vcs: {}
appSpec:
containers:
oneimage:
build:
context: .
dockerfile: Dockerfile
image: image-name
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: defaults
defaults:
memory:
"": 0
left: 1048576
oneimage: 1048576
region: local
namespace: app-created-namespace
observedGeneration: 1
resolvedOfferings: {}
staged:
appImage:
buildContext: {}
imageData: {}
vcs: {}
summary: {}
`
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
kind: AppInstance
apiVersion: internal.acorn.io/v1
metadata:
name: app-name
namespace: app-namespace
uid: 1234567890abcdef
spec:
image: test
memory:
oneimage: 1048576 # 1Mi
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: "."
2 changes: 1 addition & 1 deletion pkg/controller/resolvedofferings/computeclass.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func resolveComputeClassForContainer(req router.Request, appInstance *v1.AppInst
var ccName string

// First, get the compute class for the workload
cc, err := computeclasses.GetClassForWorkload(req.Ctx, req.Client, appInstance.Spec.ComputeClasses, container, containerName, appInstance.Namespace)
cc, err := computeclasses.GetClassForWorkload(req.Ctx, req.Client, appInstance.Spec.ComputeClasses, container, containerName, appInstance.Namespace, appInstance.GetRegion())
if err != nil {
return v1.ContainerResolvedOffering{}, err
}
Expand Down
8 changes: 8 additions & 0 deletions pkg/controller/resolvedofferings/computeclass_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ func TestTwoPCCDefaultsShouldError(t *testing.T) {
assert.True(t, resp.NoPrune, "NoPrune should be true when error occurs")
}

func TestTwoCCCDefaultsDifferentRegions(t *testing.T) {
tester.DefaultTest(t, scheme.Scheme, "testdata/computeclass/two-ccc-defaults-different-regions", Calculate)
}

func TestTwoPCCDefaultsDifferentRegions(t *testing.T) {
tester.DefaultTest(t, scheme.Scheme, "testdata/computeclass/two-pcc-defaults-different-regions", Calculate)
}

func TestComputeClassDefault(t *testing.T) {
tester.DefaultTest(t, scheme.Scheme, "testdata/computeclass/compute-class-default", Calculate)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
---
kind: ClusterComputeClassInstance
apiVersion: internal.admin.acorn.io/v1
metadata:
name: sample-compute-class
description: Simple description for a simple ComputeClass
cpuScaler: 0.25
default: true
supportedRegions: [local]
memory:
min: 1Mi # 1Mi
max: 2Mi # 2Mi
default: 1Mi # 1Mi
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: foo
operator: In
values:
- bar
---
kind: ClusterComputeClassInstance
apiVersion: internal.admin.acorn.io/v1
metadata:
name: sample-compute-class-other
description: Simple description for a simple ComputeClass
cpuScaler: 0.25
default: true
supportedRegions: [non-local]
memory:
min: 1Mi # 1Mi
max: 2Mi # 2Mi
default: 2Mi # 2Mi
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: foo
operator: In
values:
- bar
---
kind: ProjectInstance
apiVersion: internal.acorn.io/v1
metadata:
name: app-namespace
spec: {}
status:
defaultRegion: local
supportedRegions:
- local
Loading

0 comments on commit aba032b

Please sign in to comment.