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

Commit

Permalink
Add support to ignore resource requests/limits for local dev purposes (
Browse files Browse the repository at this point in the history
  • Loading branch information
Oscar Ward authored Jan 9, 2024
1 parent 3dc0733 commit e533da1
Show file tree
Hide file tree
Showing 10 changed files with 105 additions and 11 deletions.
1 change: 1 addition & 0 deletions docs/docs/100-reference/01-command-line/acorn_install.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ acorn install
--features strings Enable or disable features. (example foo=true,bar=false)
-h, --help help for install
--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}})
--ignore-resource-requirements Ignore memory and CPU requests and limits, intended for local development (default is false)
--ignore-user-labels-and-annotations Don't propagate user-defined labels and annotations to dependent objects
--image string Override the default image used for the deployment
--ingress-class-name string The ingress class name to assign to all created ingress resources (default '')
Expand Down
28 changes: 28 additions & 0 deletions integration/helper/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"testing"

"github.com/acorn-io/runtime/pkg/config"
"github.com/acorn-io/z"
kclient "sigs.k8s.io/controller-runtime/pkg/client"
)

Expand Down Expand Up @@ -41,3 +42,30 @@ func EnableFeatureWithRestore(t *testing.T, ctx context.Context, kclient kclient
t.Fatal(err)
}
}

func SetIgnoreResourceRequirementsWithRestore(t *testing.T, ctx context.Context, kclient kclient.WithWatch) {
t.Helper()

cfg, err := config.Get(ctx, kclient)
if err != nil {
t.Fatal(err)
}

state := z.Dereference(cfg.IgnoreResourceRequirements)

cfg.IgnoreResourceRequirements = z.Pointer(true)

t.Cleanup(func() {
cfg.IgnoreResourceRequirements = z.Pointer(state)

err = config.Set(ctx, kclient, cfg)
if err != nil {
t.Fatal(err)
}
})

err = config.Set(ctx, kclient, cfg)
if err != nil {
t.Fatal(err)
}
}
41 changes: 41 additions & 0 deletions integration/run/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1788,3 +1788,44 @@ func TestAutoUpgradeLocalImage(t *testing.T) {
t.Fatal(err)
}
}

func TestIgnoreResourceRequirements(t *testing.T) {
ctx := helper.GetCTX(t)

helper.StartController(t)
restConfig, err := restconfig.New(scheme.Scheme)
if err != nil {
t.Fatal("error while getting rest config:", err)
}
kclient := helper.MustReturn(kclient.Default)
project := helper.TempProject(t, kclient)

helper.SetIgnoreResourceRequirementsWithRestore(t, ctx, kclient)

c, err := client.New(restConfig, project.Name, project.Name)
if err != nil {
t.Fatal(err)
}

image, err := c.AcornImageBuild(ctx, "./testdata/simple/Acornfile", &client.AcornImageBuildOptions{
Cwd: "./testdata/simple",
})
if err != nil {
t.Fatal(err)
}

// deploy an app with memory request configured, verify that it doesn't have the constraints
app, err := c.AppRun(ctx, image.ID, &client.AppRunOptions{
Memory: map[string]*int64{
"": z.Pointer(int64(1073741824)),
},
})
if err != nil {
t.Fatal(err)
}

app = helper.WaitForObject(t, helper.Watcher(t, c), &apiv1.AppList{}, app, func(obj *apiv1.App) bool {
return obj.Status.Condition(v1.AppInstanceConditionParsed).Success
})
assert.Empty(t, app.Status.Scheduling["simple"].Requirements)
}
21 changes: 11 additions & 10 deletions pkg/apis/api.acorn.io/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -560,16 +560,17 @@ type Config struct {
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)"`

// Flags for setting resource request and limits on sytem components
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)"`
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)"`
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)"`
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)"`
BuildkitdMemory *string `json:"buildkitdMemory" name:"buildkitd-memory" usage:"The memory to allocate to buildkitd in the format of <req>:<limit> (example 256Mi:1Gi)"`
BuildkitdCPU *string `json:"buildkitdCPU" name:"buildkitd-cpu" usage:"The CPU to allocate to buildkitd in the format of <req>:<limit> (example 200m:1000m)"`
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)"`
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)"`
RegistryMemory *string `json:"registryMemory" name:"registry-memory" usage:"The memory to allocate to the registry in the format of <req>:<limit> (example 256Mi:1Gi)"`
RegistryCPU *string `json:"registryCPU" name:"registry-cpu" usage:"The CPU to allocate to the registry in the format of <req>:<limit> (example 200m:1000m)"`
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)"`
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)"`
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)"`
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)"`
BuildkitdMemory *string `json:"buildkitdMemory" name:"buildkitd-memory" usage:"The memory to allocate to buildkitd in the format of <req>:<limit> (example 256Mi:1Gi)"`
BuildkitdCPU *string `json:"buildkitdCPU" name:"buildkitd-cpu" usage:"The CPU to allocate to buildkitd in the format of <req>:<limit> (example 200m:1000m)"`
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)"`
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)"`
RegistryMemory *string `json:"registryMemory" name:"registry-memory" usage:"The memory to allocate to the registry in the format of <req>:<limit> (example 256Mi:1Gi)"`
RegistryCPU *string `json:"registryCPU" name:"registry-cpu" usage:"The CPU to allocate to the registry in the format of <req>:<limit> (example 200m:1000m)"`
IgnoreResourceRequirements *bool `json:"ignoreResourceRequirements" name:"ignore-resource-requirements" usage:"Ignore memory and CPU requests and limits, intended for local development (default is false)"`
}

type EncryptionKey struct {
Expand Down
5 changes: 5 additions & 0 deletions pkg/apis/api.acorn.io/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ func complete(ctx context.Context, c *apiv1.Config, getter kclient.Reader, inclu
if c.APIServerCPU == nil {
c.APIServerCPU = profile.APIServerCPU
}
if c.IgnoreResourceRequirements == nil {
c.IgnoreResourceRequirements = profile.IgnoreResourceRequirements
}
if c.Features == nil {
c.Features = profile.Features
} else {
Expand Down Expand Up @@ -456,6 +459,9 @@ func merge(oldConfig, newConfig *apiv1.Config) *apiv1.Config {
if newConfig.APIServerCPU != nil {
mergedConfig.APIServerCPU = newConfig.APIServerCPU
}
if newConfig.IgnoreResourceRequirements != nil {
mergedConfig.IgnoreResourceRequirements = newConfig.IgnoreResourceRequirements
}
if newConfig.AutoConfigureKarpenterDontEvictAnnotations != nil {
mergedConfig.AutoConfigureKarpenterDontEvictAnnotations = newConfig.AutoConfigureKarpenterDontEvictAnnotations
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/controller/scheduling/scheduling.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ func ResourceRequirements(req router.Request, app *v1.AppInstance, containerName
}

requirements := &corev1.ResourceRequirements{Limits: corev1.ResourceList{}, Requests: corev1.ResourceList{}}
if z.Dereference(cfg.IgnoreResourceRequirements) {
return requirements, nil
}

if computeClass != nil && computeClass.Resources != nil {
if computeClass.Resources.Requests != nil {
requirements.Requests = computeClass.Resources.Requests
Expand Down
8 changes: 7 additions & 1 deletion pkg/openapi/generated/openapi_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pkg/profiles/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ func defaultProfile() apiv1.Config {
ControllerCPU: new(string),
APIServerMemory: new(string),
APIServerCPU: new(string),
IgnoreResourceRequirements: z.Pointer(false),
AutoConfigureKarpenterDontEvictAnnotations: z.Pointer(true),
}
}
1 change: 1 addition & 0 deletions pkg/profiles/production.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func productionProfile() apiv1.Config {
conf.ControllerCPU = z.Pointer("100m")
conf.APIServerMemory = z.Pointer("256Mi")
conf.APIServerCPU = z.Pointer("100m")
conf.IgnoreResourceRequirements = z.Pointer(false)
conf.AutoConfigureKarpenterDontEvictAnnotations = z.Pointer(true)

return conf
Expand Down

0 comments on commit e533da1

Please sign in to comment.