func (s *SideloadingContentProvider) Serve(jobName string) error {
	err := s.Delegate.Serve(jobName)
	if err != nil {
		return err
	}
	ticker := time.NewTicker(2 * time.Second)
	defer ticker.Stop()
	for {
		err := s.sideload(jobName)
		if err == nil {
			break
		}
		log.WithError(err).Debug("could not initialize (yet), will try again")
		<-ticker.C
	}
	log.Debug("local content served")
	return nil
}
Serve serves the actual sideload
package werft
import (
	"archive/tar"
	"bytes"
	"compress/gzip"
	"context"
	"io"
	"time"
	v1 "github.com/csweichel/werft/pkg/api/v1"
	log "github.com/sirupsen/logrus"
	"golang.org/x/xerrors"
	corev1 "k8s.io/api/core/v1"
	"k8s.io/client-go/kubernetes"
	"k8s.io/client-go/kubernetes/scheme"
	"k8s.io/client-go/rest"
	"k8s.io/client-go/tools/remotecommand"
)
const (
	PathWerftConfig = ".werft/config.yaml"
)
type RepositoryProvider interface {
	Resolve(ctx context.Context, repo *v1.Repository) error
	RemoteAnnotations(ctx context.Context, repo *v1.Repository) (annotations map[string]string, err error)
	ContentProvider(ctx context.Context, repo *v1.Repository) (ContentProvider, error)
	FileProvider(ctx context.Context, repo *v1.Repository) (FileProvider, error)
}
var errNotSupported = xerrors.Errorf("not supported")
type NoopRepositoryProvider struct{}
func (NoopRepositoryProvider) Resolve(ctx context.Context, repo *v1.Repository) error {
	return errNotSupported
}
func (NoopRepositoryProvider) RemoteAnnotations(ctx context.Context, repo *v1.Repository) (annotations map[string]string, err error) {
	return nil, errNotSupported
}
func (NoopRepositoryProvider) ContentProvider(ctx context.Context, repo *v1.Repository) (ContentProvider, error) {
	return nil, errNotSupported
}
func (NoopRepositoryProvider) FileProvider(ctx context.Context, repo *v1.Repository) (FileProvider, error) {
	return nil, errNotSupported
}
type ContentProvider interface {
	InitContainer() ([]corev1.Container, error)
	Serve(jobName string) error
}
type FileProvider interface {
	Download(ctx context.Context, path string) (io.ReadCloser, error)
	ListFiles(ctx context.Context, path string) (paths []string, err error)
}
type LocalContentProvider struct {
	TarStream io.Reader
	Namespace  string
	Kubeconfig *rest.Config
	Clientset  kubernetes.Interface
}
func (lcp *LocalContentProvider) InitContainer() ([]corev1.Container, error) {
	return []corev1.Container{
		{
			Name:       "content-upload",
			Image:      "alpine:latest",
			Command:    []string{"sh", "-c", "while [ ! -f /workspace/.ready ]; do [ -f /workspace/.failed ] && exit 1; sleep 1; done"},
			WorkingDir: "/workspace",
		},
	}, nil
}
func (lcp *LocalContentProvider) Serve(jobName string) error {
	ticker := time.NewTicker(2 * time.Second)
	defer ticker.Stop()
	for {
		err := lcp.copyToPod(jobName)
		if err == nil {
			break
		}
		log.WithError(err).Debug("could not initialize (yet), will try again")
		<-ticker.C
	}
	log.Debug("local content served")
	return nil
}
func (lcp *LocalContentProvider) copyToPod(name string) error {
	req := lcp.Clientset.CoreV1().RESTClient().
		Post().
		Namespace(lcp.Namespace).
		Resource("pods").
		Name(name).
		SubResource("exec").
		VersionedParams(&corev1.PodExecOptions{
			Container: "werft-checkout",
			Command:   []string{"sh", "-c", "cd /workspace && tar xz; if [ $? == 0 ]; then touch .ready; else touch .failed; fi"},
			Stdin:     true,
			Stdout:    true,
			Stderr:    true,
			TTY:       false,
		}, scheme.ParameterCodec)
	remoteExec, err := remotecommand.NewSPDYExecutor(lcp.Kubeconfig, "POST", req.URL())
	if err != nil {
		return xerrors.Errorf("executor run: %w", err)
	}
	err = remoteExec.Stream(remotecommand.StreamOptions{
		Stdin:  lcp.TarStream,
		Stdout: log.New().WithField("pod", name).WriterLevel(log.DebugLevel),
		Stderr: log.New().WithField("pod", name).WriterLevel(log.ErrorLevel),
		Tty:    false,
	})
	if err != nil {
		return err
	}
	return nil
}
type tarWithReadyFile struct {
	O         io.Reader
	remainder []byte
	eof       bool
}
func (t *tarWithReadyFile) Read(p []byte) (n int, err error) {
	if len(t.remainder) > 0 {
		n = copy(p, t.remainder)
		t.remainder = t.remainder[n:]
		return
	}
	if len(t.remainder) == 0 && t.eof {
		log.Debug("tarWithReadyFile EOF")
		return n, io.EOF
	}
	n, err = t.O.Read(p)
	log.WithField("n", n).WithError(err).Debug("incoming tar data")
	if err == io.EOF {
		t.eof = true
		err = nil
		buf := bytes.NewBuffer(nil)
		gzipW := gzip.NewWriter(buf)
		tarW := tar.NewWriter(gzipW)
		tarW.WriteHeader(&tar.Header{
			Name:     ".ready",
			Size:     0,
			Typeflag: tar.TypeBlock,
		})
		tarW.Close()
		gzipW.Close()
		t.remainder = buf.Bytes()
	}
	return
}
type SideloadingContentProvider struct {
	Delegate ContentProvider
	TarStream  io.Reader
	Namespace  string
	Kubeconfig *rest.Config
	Clientset  kubernetes.Interface
}
func (s *SideloadingContentProvider) InitContainer() ([]corev1.Container, error) {
	res, err := s.Delegate.InitContainer()
	if err != nil {
		return nil, err
	}
	res = append(res, corev1.Container{
		Name:  "sideload",
		Image: "alpine/git:latest",
		Command: []string{
			"sh", "-c",
			"echo waiting for sideload; while [ ! -f /workspace/.ready ]; do [ -f /workspace/.failed ] && exit 1; sleep 1; done",
		},
		WorkingDir: "/workspace",
	})
	return res, nil
}