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

Skip checkout when there are parse errors #275

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
1 change: 0 additions & 1 deletion .buildkite/steps/tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,5 @@ export IMAGE

gotestsum --junitfile "junit-${BUILDKITE_JOB_ID}.xml" -- \
-count=1 \
-failfast \
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we want to see all the failures at once.

-ldflags="-X ${package}.branch=${branch}" \
./...
34 changes: 25 additions & 9 deletions internal/controller/scheduler/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (w *worker) Create(ctx context.Context, job *api.CommandJob) error {
logger := w.logger.With(zap.String("uuid", job.Uuid))
logger.Info("creating job")
jobWrapper := NewJobWrapper(w.logger, job, w.cfg).ParsePlugins()
kjob, err := jobWrapper.Build()
kjob, err := jobWrapper.Build(false)
if err != nil {
kjob, err = jobWrapper.BuildFailureJob(err)
if err != nil {
Expand Down Expand Up @@ -146,7 +146,7 @@ func (w *jobWrapper) ParsePlugins() *jobWrapper {
return w
}

func (w *jobWrapper) Build() (*batchv1.Job, error) {
func (w *jobWrapper) Build(skipCheckout bool) (*batchv1.Job, error) {
// if previous steps have failed, error immediately
if w.err != nil {
return nil, w.err
Expand Down Expand Up @@ -231,7 +231,11 @@ func (w *jobWrapper) Build() (*batchv1.Job, error) {
volumeMounts := []corev1.VolumeMount{{Name: "workspace", MountPath: "/workspace"}}
volumeMounts = append(volumeMounts, w.k8sPlugin.ExtraVolumeMounts...)

const systemContainers = 1
systemContainerCount := 0
if !skipCheckout {
systemContainerCount = 1
}

ttl := int32(w.cfg.JobTTL.Seconds())
kjob.Spec.TTLSecondsAfterFinished = &ttl

Expand Down Expand Up @@ -261,7 +265,7 @@ func (w *jobWrapper) Build() (*batchv1.Job, error) {
},
corev1.EnvVar{
Name: "BUILDKITE_CONTAINER_ID",
Value: strconv.Itoa(i + systemContainers),
Value: strconv.Itoa(i + systemContainerCount),
},
corev1.EnvVar{
Name: "BUILDKITE_PLUGINS_PATH",
Expand Down Expand Up @@ -294,7 +298,7 @@ func (w *jobWrapper) Build() (*batchv1.Job, error) {
podSpec.Containers[i] = c
}

containerCount := len(podSpec.Containers) + systemContainers
containerCount := len(podSpec.Containers) + systemContainerCount

for i, c := range w.k8sPlugin.Sidecars {
if c.Name == "" {
Expand Down Expand Up @@ -366,10 +370,12 @@ func (w *jobWrapper) Build() (*batchv1.Job, error) {
},
}
agentContainer.Env = append(agentContainer.Env, env...)
podSpec.Containers = append(podSpec.Containers, agentContainer)

checkoutContainer := w.createCheckoutContainer(kjob, env, volumeMounts)
if !skipCheckout {
podSpec.Containers = append(podSpec.Containers, w.createCheckoutContainer(kjob, env, volumeMounts))
}

podSpec.Containers = append(podSpec.Containers, agentContainer, checkoutContainer)
podSpec.InitContainers = append(podSpec.InitContainers, corev1.Container{
Name: "copy-agent",
Image: w.cfg.Image,
Expand Down Expand Up @@ -495,14 +501,24 @@ func (w *jobWrapper) BuildFailureJob(err error) (*batchv1.Job, error) {
PodSpec: &corev1.PodSpec{
Containers: []corev1.Container{
{
Image: w.cfg.Image,
// the configured agent image may be private. If there is an error in specifying the
// secrets for this image, we should still be able to run the failure job. So, we
// bypass the potentially private image and use a public one. We could use a
// thinner public image like `alpine:latest`, but it's generally unwise to depend
// on an image that's not published by us.
//
// TODO: pin the version of the agent image and use that here.
// Currently, DefaultAgentImage has a latest tag. That's not ideal as
// a given version of agent stack-k8s may use different versions of the agent image over
// time. We should consider using a specific version of the agent image here.
Image: config.DefaultAgentImage,
Command: []string{fmt.Sprintf("echo %q && exit 1", err.Error())},
},
},
},
}
w.otherPlugins = nil
return w.Build()
return w.Build(true)
}

func (w *jobWrapper) labelWithAgentTags() {
Expand Down
8 changes: 4 additions & 4 deletions internal/controller/scheduler/scheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func TestJobPluginConversion(t *testing.T) {
input,
scheduler.Config{AgentToken: "token-secret"},
)
result, err := wrapper.ParsePlugins().Build()
result, err := wrapper.ParsePlugins().Build(false)
require.NoError(t, err)

assert.Len(t, result.Spec.Template.Spec.Containers, 3)
Expand Down Expand Up @@ -122,7 +122,7 @@ func TestTagEnv(t *testing.T) {
AgentQueryRules: []string{"queue=kubernetes"},
}
wrapper := scheduler.NewJobWrapper(logger, input, scheduler.Config{AgentToken: "token-secret"})
result, err := wrapper.ParsePlugins().Build()
result, err := wrapper.ParsePlugins().Build(false)
require.NoError(t, err)

container := findContainer(t, result.Spec.Template.Spec.Containers, "agent")
Expand Down Expand Up @@ -152,7 +152,7 @@ func TestJobWithNoKubernetesPlugin(t *testing.T) {
AgentQueryRules: []string{},
}
wrapper := scheduler.NewJobWrapper(zaptest.NewLogger(t), input, scheduler.Config{})
result, err := wrapper.ParsePlugins().Build()
result, err := wrapper.ParsePlugins().Build(false)
require.NoError(t, err)

require.Len(t, result.Spec.Template.Spec.Containers, 3)
Expand All @@ -179,7 +179,7 @@ func TestFailureJobs(t *testing.T) {
AgentQueryRules: []string{"queue=kubernetes"},
}
wrapper := scheduler.NewJobWrapper(zaptest.NewLogger(t), input, scheduler.Config{})
_, err = wrapper.ParsePlugins().Build()
_, err = wrapper.ParsePlugins().Build(false)
require.Error(t, err)

result, err := wrapper.BuildFailureJob(err)
Expand Down