Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(build): don't override user provided resources #4964

Merged
merged 1 commit into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"))
}
Loading