Skip to content

Commit 06a3601

Browse files
authored
Fix submodule checkout failure when checkout configuration is provided (#444)
1 parent 20e92c9 commit 06a3601

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

internal/controller/config/config.go

+3
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@ func appendNegatedToEnvOpt(ctr *corev1.Container, name string, value *bool) {
151151
}
152152

153153
func appendCommaSepToEnv(ctr *corev1.Container, name string, values []string) {
154+
if len(values) == 0 {
155+
return
156+
}
154157
ctr.Env = append(ctr.Env, corev1.EnvVar{
155158
Name: name,
156159
Value: strings.Join(values, ","),

internal/controller/scheduler/scheduler_test.go

+42
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,48 @@ func TestBuildSkipCheckout(t *testing.T) {
405405
}
406406
}
407407

408+
func TestBuildCheckoutEmptyConfigEnv(t *testing.T) {
409+
t.Parallel()
410+
411+
pluginsYAML := `- github.com/buildkite-plugins/kubernetes-buildkite-plugin:
412+
checkout: {}
413+
`
414+
415+
pluginsJSON, err := yaml.YAMLToJSONStrict([]byte(pluginsYAML))
416+
require.NoError(t, err)
417+
418+
job := &api.CommandJob{
419+
Uuid: "abc",
420+
Command: "echo hello world",
421+
Env: []string{fmt.Sprintf("BUILDKITE_PLUGINS=%s", pluginsJSON)},
422+
AgentQueryRules: []string{"queue=kubernetes"},
423+
}
424+
425+
worker := scheduler.New(
426+
zaptest.NewLogger(t),
427+
nil,
428+
scheduler.Config{
429+
Namespace: "buildkite",
430+
Image: "buildkite/agent:latest",
431+
AgentTokenSecretName: "bkcq_1234567890",
432+
},
433+
)
434+
inputs, err := worker.ParseJob(job)
435+
require.NoError(t, err)
436+
kjob, err := worker.Build(&corev1.PodSpec{}, false, inputs)
437+
require.NoError(t, err)
438+
439+
for _, container := range kjob.Spec.Template.Spec.Containers {
440+
if container.Name == "checkout" {
441+
for _, envVar := range container.Env {
442+
if envVar.Name == "BUILDKITE_GIT_SUBMODULE_CLONE_CONFIG" {
443+
t.Error("with `checkout: {}`, want no BUILDKITE_GIT_SUBMODULE_CLONE_CONFIG env on checkout container")
444+
}
445+
}
446+
}
447+
}
448+
}
449+
408450
func TestFailureJobs(t *testing.T) {
409451
t.Parallel()
410452
pluginsJSON, err := json.Marshal([]map[string]any{

0 commit comments

Comments
 (0)