prow/cmd/build/controller.go
func injectSource(b *buildv1alpha1.Build, pj prowjobv1.ProwJob) (bool, error) {
	if b.Spec.Source != nil {
		return false, nil
	}
	srcContainer, refs, cloneVolumes, err := decorate.CloneRefs(pj, codeMount, logMount)
	if err != nil {
		return false, fmt.Errorf("clone source error: %v", err)
	}
	if srcContainer == nil {
		return false, nil
	} else {
		srcContainer.Name = "" // knative-build requirement
	}

	b.Spec.Source = &buildv1alpha1.SourceSpec{
		Custom: srcContainer,
	}
	b.Spec.Volumes = append(b.Spec.Volumes, cloneVolumes...)

	wd := workDir(refs[0])
	// Inject correct working directory
	for i := range b.Spec.Steps {
		if b.Spec.Steps[i].WorkingDir != "" {
			continue
		}
		b.Spec.Steps[i].WorkingDir = wd.Value
	}
	if b.Spec.Template != nil {
		// Best we can do for a template is to set WORKDIR
		b.Spec.Template.Arguments = append(b.Spec.Template.Arguments, wd)
	}

	return true, nil
}
func injectSource(b *buildv1alpha1.Build, pj prowjobv1.ProwJob) (bool, error) {
	if b.Spec.Source != nil {
		return false, nil
	}
	srcContainer, refs, cloneVolumes, err := decorate.CloneRefs(pj, codeMount, logMount)
	if err != nil {
		return false, fmt.Errorf("clone source error: %v", err)
	}
	if srcContainer == nil {
		return false, nil
	} else {
		srcContainer.Name = "" // knative-build requirement
	}

	b.Spec.Source = &buildv1alpha1.SourceSpec{
		Custom: srcContainer,
	}
	b.Spec.Volumes = append(b.Spec.Volumes, cloneVolumes...)

	wd := workDir(refs[0])
	// Inject correct working directory
	for i := range b.Spec.Steps {
		if b.Spec.Steps[i].WorkingDir != "" {
			continue
		}
		b.Spec.Steps[i].WorkingDir = wd.Value
	}
	if b.Spec.Template != nil {
		// Best we can do for a template is to set WORKDIR
		b.Spec.Template.Arguments = append(b.Spec.Template.Arguments, wd)
	}

	return true, nil
}
func injectSource ( b * buildv1alpha1 . Build , pj prowjobv1 . ProwJob ) ( bool , error ) { if b . Spec . Source != nil { return false , nil } srcContainer , refs , cloneVolumes , err := decorate . CloneRefs ( pj , codeMount , logMount ) if err != nil { return false , fmt . Errorf ( " " , err ) } if srcContainer == nil { return false , nil } else { srcContainer . Name = " " // knative-build requirement } b . Spec . Source = & buildv1alpha1 . SourceSpec { Custom : srcContainer , } b . Spec . Volumes = append ( b . Spec . Volumes , cloneVolumes ... ) wd := workDir ( refs [ 0 ] ) // Inject correct working directory for i := range b . Spec . Steps { if b . Spec . Steps [ i ] . WorkingDir != " " { continue } b . Spec . Steps [ i ] . WorkingDir = wd . Value } if b . Spec . Template != nil { // Best we can do for a template is to set WORKDIR b . Spec . Template . Arguments = append ( b . Spec . Template . Arguments , wd ) } return true , nil }
// injectSource adds the custom source container to call clonerefs correctly.
//
// Returns true if it added this container
//
// Does nothing if the build spec predefines Source
injectSource adds the custom source container to call clonerefs correctly . Returns true if it added this container Does nothing if the build spec predefines Source