Create a provider to use Azure Batch (#133)
* Started work on provider * WIP Adding batch provider * Working basic call into pool client. Need to parameterize the baseurl * Fixed job creation by manipulating the content-type * WIP Kicking off containers. Dirty * [wip] More meat around scheduling simple containers. * Working on basic task wrapper to co-schedule pods * WIP on task wrapper * WIP * Working pod minimal wrapper for batch * Integrate pod template code into provider * Cleaning up * Move to docker without gpu * WIP batch integration * partially working * Working logs * Tidy code * WIP: Testing and readme * Added readme and terraform deployment for GPU Azure Batch pool. * Update to enable low priority nodes for gpu * Fix log formatting bug. Return node logs when container not yet started * Moved to golang v1.10 * Fix cri test * Fix up minor docs Issue. Add provider to readme. Add var for vk image.
This commit is contained in:
committed by
Robbie Zhang
parent
1ad6fb434e
commit
d6e8b3daf7
105
vendor/github.com/lawrencegripper/pod2docker/pod2docker.go
generated
vendored
Normal file
105
vendor/github.com/lawrencegripper/pod2docker/pod2docker.go
generated
vendored
Normal file
@@ -0,0 +1,105 @@
|
||||
package pod2docker
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"strings"
|
||||
"text/template"
|
||||
|
||||
"k8s.io/api/core/v1"
|
||||
)
|
||||
|
||||
// ImageRegistryCredential - Used to input a credential used by docker login
|
||||
type ImageRegistryCredential struct {
|
||||
Server string `json:"server,omitempty"`
|
||||
Username string `json:"username,omitempty"`
|
||||
Password string `json:"password,omitempty"`
|
||||
}
|
||||
|
||||
// PodComponents provides details to run a pod
|
||||
type PodComponents struct {
|
||||
PullCredentials []ImageRegistryCredential
|
||||
InitContainers []v1.Container
|
||||
Containers []v1.Container
|
||||
Volumes []v1.Volume
|
||||
PodName string
|
||||
}
|
||||
|
||||
// GetBashCommand generates the bash script to execute the pod
|
||||
func GetBashCommand(p PodComponents) (string, error) {
|
||||
template := template.New("run.sh.tmpl").Option("missingkey=error").Funcs(template.FuncMap{
|
||||
"getLaunchCommand": getLaunchCommand,
|
||||
"isHostPathVolume": isHostPathVolume,
|
||||
"isEmptyDirVolume": isEmptyDirVolume,
|
||||
"isPullAlways": isPullAlways,
|
||||
"getValidVolumeMounts": getValidVolumeMounts,
|
||||
"isNvidiaRuntime": isNvidiaRuntime,
|
||||
})
|
||||
|
||||
template, err := template.Parse(azureBatchPodTemplate)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
var output bytes.Buffer
|
||||
err = template.Execute(&output, p)
|
||||
return output.String(), err
|
||||
}
|
||||
|
||||
func getLaunchCommand(container v1.Container) (cmd string) {
|
||||
if len(container.Command) > 0 {
|
||||
cmd += strings.Join(container.Command, " ")
|
||||
}
|
||||
if len(cmd) > 0 {
|
||||
cmd += " "
|
||||
}
|
||||
if len(container.Args) > 0 {
|
||||
cmd += strings.Join(container.Args, " ")
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func isNvidiaRuntime(c v1.Container) bool {
|
||||
if _, exists := c.Resources.Limits["nvidia.com/gpu"]; exists {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func isHostPathVolume(v v1.Volume) bool {
|
||||
if v.HostPath == nil {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func isEmptyDirVolume(v v1.Volume) bool {
|
||||
if v.EmptyDir == nil {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func isPullAlways(c v1.Container) bool {
|
||||
if c.ImagePullPolicy == v1.PullAlways {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func getValidVolumeMounts(container v1.Container, volumes []v1.Volume) []v1.VolumeMount {
|
||||
volDic := make(map[string]v1.Volume)
|
||||
for _, vol := range volumes {
|
||||
volDic[vol.Name] = vol
|
||||
}
|
||||
var mounts []v1.VolumeMount
|
||||
for _, mount := range container.VolumeMounts {
|
||||
vol, ok := volDic[mount.Name]
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
if vol.EmptyDir == nil && vol.HostPath == nil {
|
||||
continue
|
||||
}
|
||||
mounts = append(mounts, mount)
|
||||
}
|
||||
return mounts
|
||||
}
|
||||
Reference in New Issue
Block a user