Skip to content

Commit

Permalink
fix(build): don't override user provided resources
Browse files Browse the repository at this point in the history
Closes #4956
  • Loading branch information
squakez committed Dec 5, 2023
1 parent 52f7f23 commit 46cf4e5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
20 changes: 17 additions & 3 deletions pkg/trait/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,17 @@ func (t *builderTrait) Configure(e *Environment) (bool, *TraitCondition, error)
// it should be performed as the last custom task
t.Tasks = append(t.Tasks, fmt.Sprintf(`quarkus-native;%s;/bin/bash -c "%s"`, nativeBuilderImage, command))
// Force the build to run in a separate Pod and strictly sequential
m := "This is a Quarkus native build: setting build configuration with build Pod strategy, and native container with 1 CPU core and 4 GiB memory. Make sure your cluster can handle it."
m := "This is a Quarkus native build: setting build configuration with build Pod strategy and native container sensible resources (if not specified by the user). Make sure your cluster can handle it."
t.L.Info(m)
condition = newOrAppend(condition, m)
t.Strategy = string(v1.BuildStrategyPod)
t.OrderStrategy = string(v1.BuildOrderStrategySequential)
t.TasksRequestCPU = append(t.TasksRequestCPU, "quarkus-native:1000m")
t.TasksRequestMemory = append(t.TasksRequestMemory, "quarkus-native:4Gi")
if !existsTaskRequest(t.TasksRequestCPU, "quarkus-native") {
t.TasksRequestCPU = append(t.TasksRequestCPU, "quarkus-native:1000m")
}
if !existsTaskRequest(t.TasksRequestMemory, "quarkus-native") {
t.TasksRequestMemory = append(t.TasksRequestMemory, "quarkus-native:4Gi")
}
}
}

Expand All @@ -102,6 +106,16 @@ func (t *builderTrait) Configure(e *Environment) (bool, *TraitCondition, error)
return false, condition, nil
}

func existsTaskRequest(tasks []string, taskName string) bool {
for _, task := range tasks {
ts := strings.Split(task, ":")
if len(ts) == 2 && ts[0] == taskName {
return true
}
}
return false
}

func (t *builderTrait) adaptDeprecatedFields() *TraitCondition {
var condition *TraitCondition
if t.RequestCPU != "" {
Expand Down
7 changes: 7 additions & 0 deletions pkg/trait/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -442,3 +442,10 @@ func TestBuilderDeprecatedParams(t *testing.T) {
assert.Equal(t, "builder:100Mi", builderTrait.TasksLimitMemory[0])
assert.Equal(t, "builder:100Mi", builderTrait.TasksRequestMemory[0])
}

func TestExistsTaskRequest(t *testing.T) {
tasks := []string{"quarkus-native:1000m", "builder:1000m", "shouldfail"}
assert.True(t, existsTaskRequest(tasks, "quarkus-native"))
assert.False(t, existsTaskRequest(tasks, "quarkus"))
assert.False(t, existsTaskRequest(tasks, "shouldfail"))
}

0 comments on commit 46cf4e5

Please sign in to comment.