prow/pod-utils/decorate/podspec.go
func CloneRefs(pj prowapi.ProwJob, codeMount, logMount coreapi.VolumeMount) (*coreapi.Container, []prowapi.Refs, []coreapi.Volume, error) {
	if pj.Spec.DecorationConfig == nil {
		return nil, nil, nil, nil
	}
	if skip := pj.Spec.DecorationConfig.SkipCloning; skip != nil && *skip {
		return nil, nil, nil, nil
	}
	var cloneVolumes []coreapi.Volume
	var refs []prowapi.Refs // Do not return []*prowapi.Refs which we do not own
	if pj.Spec.Refs != nil {
		refs = append(refs, *pj.Spec.Refs)
	}
	for _, r := range pj.Spec.ExtraRefs {
		refs = append(refs, r)
	}
	if len(refs) == 0 { // nothing to clone
		return nil, nil, nil, nil
	}
	if codeMount.Name == "" || codeMount.MountPath == "" {
		return nil, nil, nil, fmt.Errorf("codeMount must set Name and MountPath")
	}
	if logMount.Name == "" || logMount.MountPath == "" {
		return nil, nil, nil, fmt.Errorf("logMount must set Name and MountPath")
	}

	var cloneMounts []coreapi.VolumeMount
	var sshKeyPaths []string
	for _, secret := range pj.Spec.DecorationConfig.SSHKeySecrets {
		volume, mount := sshVolume(secret)
		cloneMounts = append(cloneMounts, mount)
		sshKeyPaths = append(sshKeyPaths, mount.MountPath)
		cloneVolumes = append(cloneVolumes, volume)
	}

	var cloneArgs []string
	var cookiefilePath string

	if cp := pj.Spec.DecorationConfig.CookiefileSecret; cp != "" {
		v, vm, vp := cookiefileVolume(cp)
		cloneMounts = append(cloneMounts, vm)
		cloneVolumes = append(cloneVolumes, v)
		cookiefilePath = vp
		cloneArgs = append(cloneArgs, "--cookiefile="+cookiefilePath)
	}

	env, err := cloneEnv(clonerefs.Options{
		CookiePath:       cookiefilePath,
		GitRefs:          refs,
		GitUserEmail:     clonerefs.DefaultGitUserEmail,
		GitUserName:      clonerefs.DefaultGitUserName,
		HostFingerprints: pj.Spec.DecorationConfig.SSHHostFingerprints,
		KeyFiles:         sshKeyPaths,
		Log:              CloneLogPath(logMount),
		SrcRoot:          codeMount.MountPath,
	})
	if err != nil {
		return nil, nil, nil, fmt.Errorf("clone env: %v", err)
	}

	container := coreapi.Container{
		Name:         cloneRefsName,
		Image:        pj.Spec.DecorationConfig.UtilityImages.CloneRefs,
		Command:      []string{cloneRefsCommand},
		Args:         cloneArgs,
		Env:          env,
		VolumeMounts: append([]coreapi.VolumeMount{logMount, codeMount}, cloneMounts...),
	}
	return &container, refs, cloneVolumes, nil
}
func CloneRefs(pj prowapi.ProwJob, codeMount, logMount coreapi.VolumeMount) (*coreapi.Container, []prowapi.Refs, []coreapi.Volume, error) {
	if pj.Spec.DecorationConfig == nil {
		return nil, nil, nil, nil
	}
	if skip := pj.Spec.DecorationConfig.SkipCloning; skip != nil && *skip {
		return nil, nil, nil, nil
	}
	var cloneVolumes []coreapi.Volume
	var refs []prowapi.Refs // Do not return []*prowapi.Refs which we do not own
	if pj.Spec.Refs != nil {
		refs = append(refs, *pj.Spec.Refs)
	}
	for _, r := range pj.Spec.ExtraRefs {
		refs = append(refs, r)
	}
	if len(refs) == 0 { // nothing to clone
		return nil, nil, nil, nil
	}
	if codeMount.Name == "" || codeMount.MountPath == "" {
		return nil, nil, nil, fmt.Errorf("codeMount must set Name and MountPath")
	}
	if logMount.Name == "" || logMount.MountPath == "" {
		return nil, nil, nil, fmt.Errorf("logMount must set Name and MountPath")
	}

	var cloneMounts []coreapi.VolumeMount
	var sshKeyPaths []string
	for _, secret := range pj.Spec.DecorationConfig.SSHKeySecrets {
		volume, mount := sshVolume(secret)
		cloneMounts = append(cloneMounts, mount)
		sshKeyPaths = append(sshKeyPaths, mount.MountPath)
		cloneVolumes = append(cloneVolumes, volume)
	}

	var cloneArgs []string
	var cookiefilePath string

	if cp := pj.Spec.DecorationConfig.CookiefileSecret; cp != "" {
		v, vm, vp := cookiefileVolume(cp)
		cloneMounts = append(cloneMounts, vm)
		cloneVolumes = append(cloneVolumes, v)
		cookiefilePath = vp
		cloneArgs = append(cloneArgs, "--cookiefile="+cookiefilePath)
	}

	env, err := cloneEnv(clonerefs.Options{
		CookiePath:       cookiefilePath,
		GitRefs:          refs,
		GitUserEmail:     clonerefs.DefaultGitUserEmail,
		GitUserName:      clonerefs.DefaultGitUserName,
		HostFingerprints: pj.Spec.DecorationConfig.SSHHostFingerprints,
		KeyFiles:         sshKeyPaths,
		Log:              CloneLogPath(logMount),
		SrcRoot:          codeMount.MountPath,
	})
	if err != nil {
		return nil, nil, nil, fmt.Errorf("clone env: %v", err)
	}

	container := coreapi.Container{
		Name:         cloneRefsName,
		Image:        pj.Spec.DecorationConfig.UtilityImages.CloneRefs,
		Command:      []string{cloneRefsCommand},
		Args:         cloneArgs,
		Env:          env,
		VolumeMounts: append([]coreapi.VolumeMount{logMount, codeMount}, cloneMounts...),
	}
	return &container, refs, cloneVolumes, nil
}
func CloneRefs ( pj prowapi . ProwJob , codeMount , logMount coreapi . VolumeMount ) ( * coreapi . Container , [ ] prowapi . Refs , [ ] coreapi . Volume , error ) { if pj . Spec . DecorationConfig == nil { return nil , nil , nil , nil } if skip := pj . Spec . DecorationConfig . SkipCloning ; skip != nil && * skip { return nil , nil , nil , nil } var cloneVolumes [ ] coreapi . Volume var refs [ ] prowapi . Refs // Do not return []*prowapi.Refs which we do not own if pj . Spec . Refs != nil { refs = append ( refs , * pj . Spec . Refs ) } for _ , r := range pj . Spec . ExtraRefs { refs = append ( refs , r ) } if len ( refs ) == 0 { // nothing to clone return nil , nil , nil , nil } if codeMount . Name == " " || codeMount . MountPath == " " { return nil , nil , nil , fmt . Errorf ( " " ) } if logMount . Name == " " || logMount . MountPath == " " { return nil , nil , nil , fmt . Errorf ( " " ) } var cloneMounts [ ] coreapi . VolumeMount var sshKeyPaths [ ] string for _ , secret := range pj . Spec . DecorationConfig . SSHKeySecrets { volume , mount := sshVolume ( secret ) cloneMounts = append ( cloneMounts , mount ) sshKeyPaths = append ( sshKeyPaths , mount . MountPath ) cloneVolumes = append ( cloneVolumes , volume ) } var cloneArgs [ ] string var cookiefilePath string if cp := pj . Spec . DecorationConfig . CookiefileSecret ; cp != " " { v , vm , vp := cookiefileVolume ( cp ) cloneMounts = append ( cloneMounts , vm ) cloneVolumes = append ( cloneVolumes , v ) cookiefilePath = vp cloneArgs = append ( cloneArgs , " " + cookiefilePath ) } env , err := cloneEnv ( clonerefs . Options { CookiePath : cookiefilePath , GitRefs : refs , GitUserEmail : clonerefs . DefaultGitUserEmail , GitUserName : clonerefs . DefaultGitUserName , HostFingerprints : pj . Spec . DecorationConfig . SSHHostFingerprints , KeyFiles : sshKeyPaths , Log : CloneLogPath ( logMount ) , SrcRoot : codeMount . MountPath , } ) if err != nil { return nil , nil , nil , fmt . Errorf ( " " , err ) } container := coreapi . Container { Name : cloneRefsName , Image : pj . Spec . DecorationConfig . UtilityImages . CloneRefs , Command : [ ] string { cloneRefsCommand } , Args : cloneArgs , Env : env , VolumeMounts : append ( [ ] coreapi . VolumeMount { logMount , codeMount } , cloneMounts ... ) , } return & container , refs , cloneVolumes , nil }
// CloneRefs constructs the container and volumes necessary to clone the refs requested by the ProwJob.
//
// The container checks out repositories specified by the ProwJob Refs to `codeMount`.
// A log of what it checked out is written to `clone.json` in `logMount`.
//
// The container may need to mount SSH keys and/or cookiefiles in order to access private refs.
// CloneRefs returns a list of volumes containing these secrets required by the container.
CloneRefs constructs the container and volumes necessary to clone the refs requested by the ProwJob . The container checks out repositories specified by the ProwJob Refs to codeMount . A log of what it checked out is written to clone . json in logMount . The container may need to mount SSH keys and / or cookiefiles in order to access private refs . CloneRefs returns a list of volumes containing these secrets required by the container .