Skip to content

Commit

Permalink
Fix submodule checkout failure when checkout configuration is provided (
Browse files Browse the repository at this point in the history
  • Loading branch information
rianmcguire authored Dec 10, 2024
1 parent 20e92c9 commit 06a3601
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
3 changes: 3 additions & 0 deletions internal/controller/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ func appendNegatedToEnvOpt(ctr *corev1.Container, name string, value *bool) {
}

func appendCommaSepToEnv(ctr *corev1.Container, name string, values []string) {
if len(values) == 0 {
return
}
ctr.Env = append(ctr.Env, corev1.EnvVar{
Name: name,
Value: strings.Join(values, ","),
Expand Down
42 changes: 42 additions & 0 deletions internal/controller/scheduler/scheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,48 @@ func TestBuildSkipCheckout(t *testing.T) {
}
}

func TestBuildCheckoutEmptyConfigEnv(t *testing.T) {
t.Parallel()

pluginsYAML := `- github.com/buildkite-plugins/kubernetes-buildkite-plugin:
checkout: {}
`

pluginsJSON, err := yaml.YAMLToJSONStrict([]byte(pluginsYAML))
require.NoError(t, err)

job := &api.CommandJob{
Uuid: "abc",
Command: "echo hello world",
Env: []string{fmt.Sprintf("BUILDKITE_PLUGINS=%s", pluginsJSON)},
AgentQueryRules: []string{"queue=kubernetes"},
}

worker := scheduler.New(
zaptest.NewLogger(t),
nil,
scheduler.Config{
Namespace: "buildkite",
Image: "buildkite/agent:latest",
AgentTokenSecretName: "bkcq_1234567890",
},
)
inputs, err := worker.ParseJob(job)
require.NoError(t, err)
kjob, err := worker.Build(&corev1.PodSpec{}, false, inputs)
require.NoError(t, err)

for _, container := range kjob.Spec.Template.Spec.Containers {
if container.Name == "checkout" {
for _, envVar := range container.Env {
if envVar.Name == "BUILDKITE_GIT_SUBMODULE_CLONE_CONFIG" {
t.Error("with `checkout: {}`, want no BUILDKITE_GIT_SUBMODULE_CLONE_CONFIG env on checkout container")
}
}
}
}
}

func TestFailureJobs(t *testing.T) {
t.Parallel()
pluginsJSON, err := json.Marshal([]map[string]any{
Expand Down

0 comments on commit 06a3601

Please sign in to comment.