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(trait): builder configuration from platform #5862

Merged
merged 1 commit into from
Sep 26, 2024
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
16 changes: 10 additions & 6 deletions pkg/trait/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,11 @@ func (t *builderTrait) Apply(e *Environment) error {
var pipelineTasks []v1.Task

// task configuration resources
tasksConf, err := t.parseTasksConf()
defaultBuildConf := &v1.BuildConfiguration{}
if e.Platform != nil {
defaultBuildConf = &e.Platform.Status.Build.BuildConfiguration
}
tasksConf, err := t.parseTasksConf(defaultBuildConf)
if err != nil {
return err
}
Expand Down Expand Up @@ -539,7 +543,7 @@ func taskConfOrDefault(tasksConf map[string]*v1.BuildConfiguration, taskName str
return tasksConf[taskName]
}

func (t *builderTrait) parseTasksConf() (map[string]*v1.BuildConfiguration, error) {
func (t *builderTrait) parseTasksConf(defaultBuildConf *v1.BuildConfiguration) (map[string]*v1.BuildConfiguration, error) {
tasksConf := make(map[string]*v1.BuildConfiguration)

for _, t := range t.TasksRequestCPU {
Expand All @@ -550,7 +554,7 @@ func (t *builderTrait) parseTasksConf() (map[string]*v1.BuildConfiguration, erro
taskName := splits[0]
taskResource := splits[1]
if tasksConf[taskName] == nil {
tasksConf[taskName] = &v1.BuildConfiguration{}
tasksConf[taskName] = defaultBuildConf
}
tasksConf[taskName].RequestCPU = taskResource
}
Expand All @@ -563,7 +567,7 @@ func (t *builderTrait) parseTasksConf() (map[string]*v1.BuildConfiguration, erro
taskName := splits[0]
taskResource := splits[1]
if tasksConf[taskName] == nil {
tasksConf[taskName] = &v1.BuildConfiguration{}
tasksConf[taskName] = defaultBuildConf
}
tasksConf[taskName].RequestMemory = taskResource
}
Expand All @@ -576,7 +580,7 @@ func (t *builderTrait) parseTasksConf() (map[string]*v1.BuildConfiguration, erro
taskName := splits[0]
taskResource := splits[1]
if tasksConf[taskName] == nil {
tasksConf[taskName] = &v1.BuildConfiguration{}
tasksConf[taskName] = defaultBuildConf
}
tasksConf[taskName].LimitCPU = taskResource
}
Expand All @@ -589,7 +593,7 @@ func (t *builderTrait) parseTasksConf() (map[string]*v1.BuildConfiguration, erro
taskName := splits[0]
taskResource := splits[1]
if tasksConf[taskName] == nil {
tasksConf[taskName] = &v1.BuildConfiguration{}
tasksConf[taskName] = defaultBuildConf
}
tasksConf[taskName].LimitMemory = taskResource
}
Expand Down
18 changes: 16 additions & 2 deletions pkg/trait/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ func TestBuilderCustomTasksConfiguration(t *testing.T) {
builderTrait.TasksRequestMemory = append(builderTrait.TasksRequestMemory, "package:8Gi")
builderTrait.TasksLimitMemory = append(builderTrait.TasksLimitMemory, "spectrum:4Gi")

tasksConf, err := builderTrait.parseTasksConf()
tasksConf, err := builderTrait.parseTasksConf(&v1.BuildConfiguration{})

require.NoError(t, err)
assert.Equal(t, 4, len(tasksConf))
Expand All @@ -403,7 +403,7 @@ func TestBuilderCustomTasksConfigurationError(t *testing.T) {
builderTrait := createNominalBuilderTraitTest()
builderTrait.TasksLimitCPU = append(builderTrait.TasksLimitCPU, "syntax error")

_, err := builderTrait.parseTasksConf()
_, err := builderTrait.parseTasksConf(&v1.BuildConfiguration{})

require.Error(t, err)
assert.Equal(t, "could not parse syntax error, expected format <task-name>:<task-resource>", err.Error())
Expand Down Expand Up @@ -594,6 +594,20 @@ func TestBuilderTasksFilterAndReorderCustomTasks(t *testing.T) {
assert.Equal(t, []string{"builder", "my-custom-task", "package", "my-custom-publish"}, pipelineTasks)
}

func TestBuilderTasksNodeSelectorPlatformBuildStrategyPod(t *testing.T) {
env := createBuilderTestEnv(v1.IntegrationPlatformClusterKubernetes, v1.IntegrationPlatformBuildPublishStrategyJib, v1.BuildStrategyPod)
builderTrait := createNominalBuilderTraitTest()
builderTrait.NodeSelector = map[string]string{
"kubernetes.io/arch": "amd64",
}

err := builderTrait.Apply(env)
require.NoError(t, err)
builderTask := getBuilderTask(env.Pipeline)
assert.NotNil(t, builderTask)
assert.Equal(t, map[string]string{"kubernetes.io/arch": "amd64"}, builderTask.Configuration.NodeSelector)
}

func findCustomTaskByName(tasks []v1.Task, name string) v1.Task {
for _, t := range tasks {
if t.Custom != nil && t.Custom.Name == name {
Expand Down
Loading