Skip to content
This repository has been archived by the owner on Sep 5, 2019. It is now read-only.

Commit

Permalink
no init containers
Browse files Browse the repository at this point in the history
  • Loading branch information
aaron-prindle committed Nov 13, 2018
1 parent e13cd91 commit 80d210c
Showing 1 changed file with 52 additions and 18 deletions.
70 changes: 52 additions & 18 deletions pkg/reconciler/build/resources/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,8 @@ func MakePod(build *v1alpha1.Build, kubeclient kubernetes.Interface) (*corev1.Po
var sources []v1alpha1.SourceSpec
// if source is present convert into sources

// NOTES(aaron-prindle) adds custom steps outside of user Steps for git, logs, etc
podContainers := []corev1.Container{*cred}
initContainers := []corev1.Container{*cred}
podContainers := []corev1.Container{}
if source := build.Spec.Source; source != nil {
sources = []v1alpha1.SourceSpec{*source}
}
Expand All @@ -267,13 +267,13 @@ func MakePod(build *v1alpha1.Build, kubeclient kubernetes.Interface) (*corev1.Po
if err != nil {
return nil, err
}
podContainers = append(podContainers, *git)
initContainers = append(initContainers, *git)
case source.GCS != nil:
gcs, err := gcsToContainer(source, i)
if err != nil {
return nil, err
}
podContainers = append(podContainers, *gcs)
initContainers = append(initContainers, *gcs)
case source.Custom != nil:
cust, err := customToContainer(source.Custom, source.Name)
if err != nil {
Expand All @@ -286,7 +286,16 @@ func MakePod(build *v1alpha1.Build, kubeclient kubernetes.Interface) (*corev1.Po
workspaceSubPath = source.SubPath
}

// NOTES(aaron-prindle) setup volume mounts for steps
// setup entrypoint rewriting container
initContainers = append(initContainers,
corev1.Container{
Name: InitContainerName,
Image: DefaultEntrypointImage,
Command: []string{"/bin/cp"},
Args: []string{"/entrypoint", BinaryLocation},
VolumeMounts: []corev1.VolumeMount{toolsMount},
})

for i, step := range build.Spec.Steps {
step.Env = append(implicitEnvVars, step.Env...)
// TODO(mattmoor): Check that volumeMounts match volumes.
Expand Down Expand Up @@ -324,11 +333,15 @@ func MakePod(build *v1alpha1.Build, kubeclient kubernetes.Interface) (*corev1.Po
// declared user volumes.
volumes := append(build.Spec.Volumes, implicitVolumes...)
volumes = append(volumes, secrets...)
volumes = append(volumes, corev1.Volume{
Name: MountName,
VolumeSource: corev1.VolumeSource{
EmptyDir: &corev1.EmptyDirVolumeSource{},
},
})
if err := v1alpha1.ValidateVolumes(volumes); err != nil {
return nil, err
}

// entrypoint.RedirectSteps(podContainers)
RedirectSteps(podContainers)

return &corev1.Pod{
Expand Down Expand Up @@ -356,6 +369,7 @@ func MakePod(build *v1alpha1.Build, kubeclient kubernetes.Interface) (*corev1.Po
Spec: corev1.PodSpec{
// If the build fails, don't restart it.
RestartPolicy: corev1.RestartPolicyNever,
InitContainers: initContainers,
Containers: podContainers,
ServiceAccountName: build.Spec.ServiceAccountName,
Volumes: volumes,
Expand All @@ -365,8 +379,6 @@ func MakePod(build *v1alpha1.Build, kubeclient kubernetes.Interface) (*corev1.Po
}, nil
}

// from build-pipeline

const (
// MountName is the name of the pvc being mounted (which
// will contain the entrypoint binary and eventually the logs)
Expand All @@ -375,8 +387,15 @@ const (
BinaryLocation = MountPoint + "/entrypoint"
JSONConfigEnvVar = "ENTRYPOINT_OPTIONS"
InitContainerName = "place-tools"
ProcessLogFile = "/tools/process-log.txt"
MarkerFile = "/tools/marker-file.txt"
// TODO(aaron-prindle) change this to wherever is sensible
DefaultEntrypointImage = "gcr.io/aprindle-vm-test/entrypoint:latest"

ProcessLogFile = "/tools/process-log.txt"
MarkerFile = "/tools/marker-file.txt"
ShouldWaitForPrevStep = false
PreRunFile = "0"
ShouldRunPostRun = true
PostRunFile = "0"
)

var toolsMount = corev1.VolumeMount{
Expand All @@ -388,6 +407,11 @@ type entrypointArgs struct {
Args []string `json:"args"`
ProcessLog string `json:"process_log"`
MarkerFile string `json:"marker_file"`

ShouldWaitForPrevStep bool `json:"shouldWaitForPrevStep"`
PreRunFile string `json:"preRunFile"`
ShouldRunPostRun bool `json:"shouldRunPostRun"`
PostRunFile string `json:"postRunFile"`
}

// RedirectSteps will modify each of the steps/containers such that
Expand All @@ -397,10 +421,11 @@ type entrypointArgs struct {
func RedirectSteps(steps []corev1.Container) error {
for i := range steps {
step := &steps[i]
e, err := getEnvVar(step.Command, step.Args)
e, err := getEnvVar(step.Command, step.Args, i)
if err != nil {
return fmt.Errorf("couldn't get env var for entrypoint: %s", err)
}

step.Command = []string{BinaryLocation}
step.Args = []string{}

Expand All @@ -413,16 +438,25 @@ func RedirectSteps(steps []corev1.Container) error {
return nil
}

func getEnvVar(cmd, args []string) (string, error) {
func getEnvVar(cmd, args []string, stepNumber int) (string, error) {
shouldWaitForPrevStep := ShouldWaitForPrevStep
// TODO(aaron-prindle) modify ShouldRunPostRun to not run on last step
if stepNumber != 0 {
shouldWaitForPrevStep = true
}

entrypointArgs := entrypointArgs{
Args: append(cmd, args...),
ProcessLog: ProcessLogFile,
MarkerFile: MarkerFile,
// TODO(aaron-prindle) add the new options here
Args: append(cmd, args...),
ProcessLog: ProcessLogFile,
MarkerFile: MarkerFile,
ShouldWaitForPrevStep: shouldWaitForPrevStep,
PreRunFile: filepath.Join(MountPoint, strconv.Itoa(stepNumber)),
ShouldRunPostRun: ShouldRunPostRun,
PostRunFile: filepath.Join(MountPoint, strconv.Itoa(stepNumber+1)),
}
j, err := json.Marshal(entrypointArgs)
if err != nil {
return "", fmt.Errorf("couldn't marshal arguments %q for entrypoint env var: %s", entrypointArgs, err)
return "", fmt.Errorf("couldn't marshal arguments %v for entrypoint env var: %s", entrypointArgs, err)
}
return string(j), nil
}

0 comments on commit 80d210c

Please sign in to comment.