Skip to content

Instantly share code, notes, and snippets.

@chmouel
Created January 22, 2019 15:35
Show Gist options
  • Save chmouel/3be388b96dc1153a9c50a2237e0fcf39 to your computer and use it in GitHub Desktop.
Save chmouel/3be388b96dc1153a9c50a2237e0fcf39 to your computer and use it in GitHub Desktop.
func newPodForCR(cr *jrv1alpha1.JenkinsFileRunner) *corev1.Pod {
branch := cr.Spec.RepoBranch
if branch == "" {
branch = "master"
}
rev := cr.Spec.RepoRev
if rev == "" {
rev = "origin/master"
}
labels := map[string]string{
"app": cr.Name,
}
return &corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: cr.Name + "-pod",
Namespace: cr.Namespace,
Labels: labels,
},
Spec: corev1.PodSpec{
Volumes: []corev1.Volume{
corev1.Volume{
Name: "shared-data",
VolumeSource: corev1.VolumeSource{
EmptyDir: &corev1.EmptyDirVolumeSource{},
},
},
},
Containers: []corev1.Container{
{
Name: "jenkinsfile-runner",
Image: "quay.io/chmouel/openshift-jr",
ImagePullPolicy: "IfNotPresent",
Command: []string{"/usr/libexec/s2i/assemble"},
// Command: []string{"sleep", "36000"},
VolumeMounts: []corev1.VolumeMount{
corev1.VolumeMount{
MountPath: "/tmp/src",
Name: "shared-data",
},
},
Env: []corev1.EnvVar{
{
Name: "OPENSHIFT_BUILD_REFERENCE",
Value: "master",
},
{
Name: "OPENSHIFT_BUILD_NAME",
Value: "build-10",
},
}},
},
InitContainers: []corev1.Container{
{
Name: "git-clone",
Image: "quay.io/chmouel/docker-git-clone",
VolumeMounts: []corev1.VolumeMount{
corev1.VolumeMount{
MountPath: "/tmp/src",
Name: "shared-data",
},
},
Env: []corev1.EnvVar{
{
Name: "GIT_CLONE_REPO",
Value: cr.Spec.RepoURL,
},
{
Name: "GIT_CLONE_BRANCH",
Value: branch,
},
{
Name: "GIT_CLONE_DEST",
Value: "/tmp/src",
},
{
Name: "GIT_CLONE_REV",
Value: rev,
}},
},
},
},
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment