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

Commit e533da1

Browse files
author
Oscar Ward
authored
Add support to ignore resource requests/limits for local dev purposes (#2400)
1 parent 3dc0733 commit e533da1

File tree

10 files changed

+105
-11
lines changed

10 files changed

+105
-11
lines changed

docs/docs/100-reference/01-command-line/acorn_install.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ acorn install
4747
--features strings Enable or disable features. (example foo=true,bar=false)
4848
-h, --help help for install
4949
--http-endpoint-pattern string Go template for formatting application http endpoints. Valid variables to use are: App, Container, Namespace, Hash and ClusterDomain. (default pattern is {{hashConcat 8 .Container .App .Namespace | truncate}}.{{.ClusterDomain}})
50+
--ignore-resource-requirements Ignore memory and CPU requests and limits, intended for local development (default is false)
5051
--ignore-user-labels-and-annotations Don't propagate user-defined labels and annotations to dependent objects
5152
--image string Override the default image used for the deployment
5253
--ingress-class-name string The ingress class name to assign to all created ingress resources (default '')

integration/helper/config.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"testing"
66

77
"github.com/acorn-io/runtime/pkg/config"
8+
"github.com/acorn-io/z"
89
kclient "sigs.k8s.io/controller-runtime/pkg/client"
910
)
1011

@@ -41,3 +42,30 @@ func EnableFeatureWithRestore(t *testing.T, ctx context.Context, kclient kclient
4142
t.Fatal(err)
4243
}
4344
}
45+
46+
func SetIgnoreResourceRequirementsWithRestore(t *testing.T, ctx context.Context, kclient kclient.WithWatch) {
47+
t.Helper()
48+
49+
cfg, err := config.Get(ctx, kclient)
50+
if err != nil {
51+
t.Fatal(err)
52+
}
53+
54+
state := z.Dereference(cfg.IgnoreResourceRequirements)
55+
56+
cfg.IgnoreResourceRequirements = z.Pointer(true)
57+
58+
t.Cleanup(func() {
59+
cfg.IgnoreResourceRequirements = z.Pointer(state)
60+
61+
err = config.Set(ctx, kclient, cfg)
62+
if err != nil {
63+
t.Fatal(err)
64+
}
65+
})
66+
67+
err = config.Set(ctx, kclient, cfg)
68+
if err != nil {
69+
t.Fatal(err)
70+
}
71+
}

integration/run/run_test.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1788,3 +1788,44 @@ func TestAutoUpgradeLocalImage(t *testing.T) {
17881788
t.Fatal(err)
17891789
}
17901790
}
1791+
1792+
func TestIgnoreResourceRequirements(t *testing.T) {
1793+
ctx := helper.GetCTX(t)
1794+
1795+
helper.StartController(t)
1796+
restConfig, err := restconfig.New(scheme.Scheme)
1797+
if err != nil {
1798+
t.Fatal("error while getting rest config:", err)
1799+
}
1800+
kclient := helper.MustReturn(kclient.Default)
1801+
project := helper.TempProject(t, kclient)
1802+
1803+
helper.SetIgnoreResourceRequirementsWithRestore(t, ctx, kclient)
1804+
1805+
c, err := client.New(restConfig, project.Name, project.Name)
1806+
if err != nil {
1807+
t.Fatal(err)
1808+
}
1809+
1810+
image, err := c.AcornImageBuild(ctx, "./testdata/simple/Acornfile", &client.AcornImageBuildOptions{
1811+
Cwd: "./testdata/simple",
1812+
})
1813+
if err != nil {
1814+
t.Fatal(err)
1815+
}
1816+
1817+
// deploy an app with memory request configured, verify that it doesn't have the constraints
1818+
app, err := c.AppRun(ctx, image.ID, &client.AppRunOptions{
1819+
Memory: map[string]*int64{
1820+
"": z.Pointer(int64(1073741824)),
1821+
},
1822+
})
1823+
if err != nil {
1824+
t.Fatal(err)
1825+
}
1826+
1827+
app = helper.WaitForObject(t, helper.Watcher(t, c), &apiv1.AppList{}, app, func(obj *apiv1.App) bool {
1828+
return obj.Status.Condition(v1.AppInstanceConditionParsed).Success
1829+
})
1830+
assert.Empty(t, app.Status.Scheduling["simple"].Requirements)
1831+
}

pkg/apis/api.acorn.io/v1/types.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -560,16 +560,17 @@ type Config struct {
560560
AutoConfigureKarpenterDontEvictAnnotations *bool `json:"autoConfigureKarpenterDontEvictAnnotations" name:"auto-configure-karpenter-dont-evict-annotations" usage:"Automatically configure Karpenter to not evict pods with the given annotations if app is running a single replica. (default false)"`
561561

562562
// Flags for setting resource request and limits on sytem components
563-
ControllerMemory *string `json:"controllerMemory" name:"controller-memory" usage:"The memory to allocate to the runtime-controller in the format of <req>:<limit> (example 256Mi:1Gi)"`
564-
ControllerCPU *string `json:"controllerCPU" name:"controller-cpu" usage:"The CPU to allocate to the runtime-controller in the format of <req>:<limit> (example 200m:1000m)"`
565-
APIServerMemory *string `json:"apiServerMemory" name:"api-server-memory" usage:"The memory to allocate to the runtime-api-server in the format of <req>:<limit> (example 256Mi:1Gi)"`
566-
APIServerCPU *string `json:"apiServerCPU" name:"api-server-cpu" usage:"The CPU to allocate to the runtime-api-server in the format of <req>:<limit> (example 200m:1000m)"`
567-
BuildkitdMemory *string `json:"buildkitdMemory" name:"buildkitd-memory" usage:"The memory to allocate to buildkitd in the format of <req>:<limit> (example 256Mi:1Gi)"`
568-
BuildkitdCPU *string `json:"buildkitdCPU" name:"buildkitd-cpu" usage:"The CPU to allocate to buildkitd in the format of <req>:<limit> (example 200m:1000m)"`
569-
BuildkitdServiceMemory *string `json:"buildkitdServiceMemory" name:"buildkitd-service-memory" usage:"The memory to allocate to the buildkitd service in the format of <req>:<limit> (example 256Mi:1Gi)"`
570-
BuildkitdServiceCPU *string `json:"buildkitdServiceCPU" name:"buildkitd-service-cpu" usage:"The CPU to allocate to the buildkitd service in the format of <req>:<limit> (example 200m:1000m)"`
571-
RegistryMemory *string `json:"registryMemory" name:"registry-memory" usage:"The memory to allocate to the registry in the format of <req>:<limit> (example 256Mi:1Gi)"`
572-
RegistryCPU *string `json:"registryCPU" name:"registry-cpu" usage:"The CPU to allocate to the registry in the format of <req>:<limit> (example 200m:1000m)"`
563+
ControllerMemory *string `json:"controllerMemory" name:"controller-memory" usage:"The memory to allocate to the runtime-controller in the format of <req>:<limit> (example 256Mi:1Gi)"`
564+
ControllerCPU *string `json:"controllerCPU" name:"controller-cpu" usage:"The CPU to allocate to the runtime-controller in the format of <req>:<limit> (example 200m:1000m)"`
565+
APIServerMemory *string `json:"apiServerMemory" name:"api-server-memory" usage:"The memory to allocate to the runtime-api-server in the format of <req>:<limit> (example 256Mi:1Gi)"`
566+
APIServerCPU *string `json:"apiServerCPU" name:"api-server-cpu" usage:"The CPU to allocate to the runtime-api-server in the format of <req>:<limit> (example 200m:1000m)"`
567+
BuildkitdMemory *string `json:"buildkitdMemory" name:"buildkitd-memory" usage:"The memory to allocate to buildkitd in the format of <req>:<limit> (example 256Mi:1Gi)"`
568+
BuildkitdCPU *string `json:"buildkitdCPU" name:"buildkitd-cpu" usage:"The CPU to allocate to buildkitd in the format of <req>:<limit> (example 200m:1000m)"`
569+
BuildkitdServiceMemory *string `json:"buildkitdServiceMemory" name:"buildkitd-service-memory" usage:"The memory to allocate to the buildkitd service in the format of <req>:<limit> (example 256Mi:1Gi)"`
570+
BuildkitdServiceCPU *string `json:"buildkitdServiceCPU" name:"buildkitd-service-cpu" usage:"The CPU to allocate to the buildkitd service in the format of <req>:<limit> (example 200m:1000m)"`
571+
RegistryMemory *string `json:"registryMemory" name:"registry-memory" usage:"The memory to allocate to the registry in the format of <req>:<limit> (example 256Mi:1Gi)"`
572+
RegistryCPU *string `json:"registryCPU" name:"registry-cpu" usage:"The CPU to allocate to the registry in the format of <req>:<limit> (example 200m:1000m)"`
573+
IgnoreResourceRequirements *bool `json:"ignoreResourceRequirements" name:"ignore-resource-requirements" usage:"Ignore memory and CPU requests and limits, intended for local development (default is false)"`
573574
}
574575

575576
type EncryptionKey struct {

pkg/apis/api.acorn.io/v1/zz_generated.deepcopy.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/config/config.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@ func complete(ctx context.Context, c *apiv1.Config, getter kclient.Reader, inclu
143143
if c.APIServerCPU == nil {
144144
c.APIServerCPU = profile.APIServerCPU
145145
}
146+
if c.IgnoreResourceRequirements == nil {
147+
c.IgnoreResourceRequirements = profile.IgnoreResourceRequirements
148+
}
146149
if c.Features == nil {
147150
c.Features = profile.Features
148151
} else {
@@ -456,6 +459,9 @@ func merge(oldConfig, newConfig *apiv1.Config) *apiv1.Config {
456459
if newConfig.APIServerCPU != nil {
457460
mergedConfig.APIServerCPU = newConfig.APIServerCPU
458461
}
462+
if newConfig.IgnoreResourceRequirements != nil {
463+
mergedConfig.IgnoreResourceRequirements = newConfig.IgnoreResourceRequirements
464+
}
459465
if newConfig.AutoConfigureKarpenterDontEvictAnnotations != nil {
460466
mergedConfig.AutoConfigureKarpenterDontEvictAnnotations = newConfig.AutoConfigureKarpenterDontEvictAnnotations
461467
}

pkg/controller/scheduling/scheduling.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,10 @@ func ResourceRequirements(req router.Request, app *v1.AppInstance, containerName
159159
}
160160

161161
requirements := &corev1.ResourceRequirements{Limits: corev1.ResourceList{}, Requests: corev1.ResourceList{}}
162+
if z.Dereference(cfg.IgnoreResourceRequirements) {
163+
return requirements, nil
164+
}
165+
162166
if computeClass != nil && computeClass.Resources != nil {
163167
if computeClass.Resources.Requests != nil {
164168
requirements.Requests = computeClass.Resources.Requests

pkg/openapi/generated/openapi_generated.go

Lines changed: 7 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/profiles/default.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ func defaultProfile() apiv1.Config {
7373
ControllerCPU: new(string),
7474
APIServerMemory: new(string),
7575
APIServerCPU: new(string),
76+
IgnoreResourceRequirements: z.Pointer(false),
7677
AutoConfigureKarpenterDontEvictAnnotations: z.Pointer(true),
7778
}
7879
}

pkg/profiles/production.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ func productionProfile() apiv1.Config {
3333
conf.ControllerCPU = z.Pointer("100m")
3434
conf.APIServerMemory = z.Pointer("256Mi")
3535
conf.APIServerCPU = z.Pointer("100m")
36+
conf.IgnoreResourceRequirements = z.Pointer(false)
3637
conf.AutoConfigureKarpenterDontEvictAnnotations = z.Pointer(true)
3738

3839
return conf

0 commit comments

Comments
 (0)