in images/controller/cmd/app_publisher/app_publisher.go [285:327]
func makeAppPublishJob(namespace, jobName, appName, image, nodeName, containerID, user, projectID, templatePath string, newApp newAppData) error {
log.Printf("creating app publish job: %s, %s, %s", jobName, image, nodeName)
data := appPublishJobTemplateData{
JobName: jobName,
Namespace: namespace,
AppName: appName,
User: user,
NodeName: nodeName,
ContainerID: containerID,
ImageTag: image,
ProjectID: projectID,
NewApp: newApp,
}
destDir := path.Join("/run/app-publisher", jobName)
if err := os.MkdirAll(destDir, os.ModePerm); err != nil {
return fmt.Errorf("failed to make destDir %s: %v", destDir, err)
}
base := path.Base(templatePath)
t, err := template.New(base).Funcs(sprig.TxtFuncMap()).ParseFiles(templatePath)
if err != nil {
return fmt.Errorf("failed to initialize template: %v", err)
}
dest, _ := os.Create(strings.ReplaceAll(path.Join(destDir, base), ".tmpl", ""))
if err != nil {
return fmt.Errorf("failed to create dest template file: %v", err)
}
if err = t.Execute(dest, &data); err != nil {
return fmt.Errorf("failed to execute template: %v", err)
}
// Apply the job to the cluster
cmd := exec.Command("sh", "-c", fmt.Sprintf("kubectl apply -f %s 1>&2", destDir))
cmd.Dir = path.Dir(destDir)
stdoutStderr, err := cmd.CombinedOutput()
if err != nil {
return fmt.Errorf("error calling kubectl to apply job: %v\n%s", err, string(stdoutStderr))
}
return nil
}