slomad

package
v0.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 8, 2023 License: MIT Imports: 10 Imported by: 0

README

slomad

import "github.com/ecshreve/slomad/pkg/slomad"

Index

Variables

var (
    DEFAULT_TASK = TaskResource{CPU: DEFAULT, MEM: DEFAULT}
    TINY_TASK    = TaskResource{CPU: TINY, MEM: TINY}
    SMALL_TASK   = TaskResource{CPU: SMALL, MEM: SMALL}
    LARGE_TASK   = TaskResource{CPU: LARGE, MEM: LARGE}
    XLARGE_TASK  = TaskResource{CPU: XLARGE, MEM: XLARGE}
    MEM_TASK     = TaskResource{CPU: SMALL, MEM: LARGE}
    COMPUTE_TASK = TaskResource{CPU: LARGE, MEM: SMALL}
    PLEX_TASK    = TaskResource{CPU: LARGE, MEM: XXLARGE}
)

DeployTargetRegex is a map of DeployTarget to a regex string that matches the target's hostname.

var DeployTargetRegex = map[DeployTarget]string{
    ALL:      "^.*$",
    SERVER:   "^server-[0-9]+$",
    WORKER:   "^worker-[0-9]+$",
    CODERBOX: "^coderbox$",
    DEVBOX:   "^devbox$",
    PLEXBOX:  "^plexbox$",
}

func convertJob

func convertJob(in *nomadStructs.Job) (*nomadApi.Job, error)

convertJob converts a Nomad Job to a Nomad API Job.

func extractLabels

func extractLabels(ports []*Port) []string

extractLabels returns a list of labels from a list of Ports.

func getCSIPluginConfig

func getCSIPluginConfig(j *Job) *nomadStructs.TaskCSIPluginConfig

getCSIPluginConfig returns a CSIPluginConfig for a given job.

func getConfig

func getConfig(name string, jt JobType, args []string, ports []*Port, vols []Volume) map[string]interface{}

getConfig returns a nomad config struct for a given job.

func getConstraint

func getConstraint(dt DeployTarget) *nomadStructs.Constraint

getConstraint returns a nomad constraint for a given deploy target.

func getDisk

func getDisk() *nomadStructs.EphemeralDisk

getDisk returns a nomad disk struct with a default size for a given job.

func getGroup

func getGroup(j *Job) *nomadStructs.TaskGroup

getGroup returns a nomad task group struct for a given job.

func getMounts

func getMounts(vols []Volume) []*nomadStructs.VolumeMount

getMounts converts a list of Volumes to a list of Nomad VolumeMounts.

func getNetworks

func getNetworks(ports []*Port) []*nomadStructs.NetworkResource

getNetworks converts a list of Ports to a list of Nomad NetworkResources.

func getNomadVolumeReq

func getNomadVolumeReq(vols []Volume) map[string]*nomadStructs.VolumeRequest

getNomadVolumeReq converts a slice of Volumes to map of nomad VolumeRequest.

TODO: validation

func getReschedulePolicy

func getReschedulePolicy(jt JobType) *nomadStructs.ReschedulePolicy

getReschedulePolicy returns a nomad reschedule policy for a given job.

func getResource

func getResource(tr TaskResource) *nomadStructs.Resources

getResource is a helper function to convert a TaskResource to a Nomad Resources struct.

func getService

func getService(taskName string, portLabel string) *nomadStructs.Service

getService returns a nomad service struct for a given task.

func getServices

func getServices(taskName string, portLabels []string) []*nomadStructs.Service

getServices returns a list of services for a given job.

func getTask

func getTask(j *Job) *nomadStructs.Task

getTask returns a nomad task struct for a given job.

func getTemplates

func getTemplates(templates map[string]string) []*nomadStructs.Template

func getVolumeStrings

func getVolumeStrings(vols []Volume) []string

getVolumeString converts a list of Volumes to a list of Volume strings. These are meant to be passed to the docker driver.

func toNomadPort

func toNomadPort(p *Port) nomadStructs.Port

func toNomadPortMap

func toNomadPortMap(ports []*Port) map[string][]nomadStructs.Port

toNomadPortMap converts a list of Ports to a map of static and dynamic ports.

type DeployTarget

DeployTarget is an enum that represents the target of a job.

type DeployTarget int
const (
    UNKNOWN_DEPLOY_TARGET DeployTarget = iota
    ALL
    SERVER
    WORKER
    CODERBOX
    DEVBOX
    PLEXBOX
)

type Job

Job is a struct that represents a Nomad Job.

type Job struct {
    Name      string
    Type      JobType
    Shape     TaskResource
    Target    DeployTarget
    Ports     []*Port
    Volumes   []Volume
    Args      []string
    Env       map[string]string
    User      string
    Templates map[string]string
}
func (*Job) GetNomadApiJob
func (j *Job) GetNomadApiJob(force bool) (*nomadApi.Job, error)

GetNomadApiJob returns a nomadApi Job for the given slomad.Job.

type JobType

JobType is an enum that represents the type of a job.

type JobType int
const (
    UNKNOWN_JOB_TYPE JobType = iota
    SERVICE
    SYSTEM
    BATCH
    STORAGE_CONTROLLER
    STORAGE_NODE
)
func (JobType) String
func (jt JobType) String() string

String implements the Stringer interface for JobType.

type Port

Port is a struct that represents a network port for a task.

type Port struct {
    Label  string
    To     int
    From   int
    Static bool
}
func BasicPortConfig
func BasicPortConfig(val int) []*Port

BasicPortConfig returns a list with a single Port element with a default label.

func basicPort
func basicPort(val int) *Port

basicPort returns a basic port struct with a default label.

type ResourceValue

type ResourceValue int
const (
    TINY    ResourceValue = 128
    SMALL   ResourceValue = 256
    DEFAULT ResourceValue = 512
    LARGE   ResourceValue = 1024
    XLARGE  ResourceValue = 2048
    XXLARGE ResourceValue = 4096
)

type TaskResource

TaskResource is a struct that represents the CPU and MEM resources for a task.

type TaskResource struct {
    CPU ResourceValue
    MEM ResourceValue
}

type Volume

type Volume struct {
    Src   string
    Dst   string
    Mount bool
}

Generated by gomarkdoc

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DEFAULT_TASK = TaskResource{CPU: DEFAULT, MEM: DEFAULT}
	TINY_TASK    = TaskResource{CPU: TINY, MEM: TINY}
	SMALL_TASK   = TaskResource{CPU: SMALL, MEM: SMALL}
	LARGE_TASK   = TaskResource{CPU: LARGE, MEM: LARGE}
	XLARGE_TASK  = TaskResource{CPU: XLARGE, MEM: XLARGE}
	MEM_TASK     = TaskResource{CPU: SMALL, MEM: LARGE}
	COMPUTE_TASK = TaskResource{CPU: LARGE, MEM: SMALL}
	PLEX_TASK    = TaskResource{CPU: LARGE, MEM: XXLARGE}
)
View Source
var DeployTargetRegex = map[DeployTarget]string{
	ALL:      "^.*$",
	SERVER:   "^server-[0-9]+$",
	WORKER:   "^worker-[0-9]+$",
	CODERBOX: "^coderbox$",
	DEVBOX:   "^devbox$",
	PLEXBOX:  "^plexbox$",
}

DeployTargetRegex is a map of DeployTarget to a regex string that matches the target's hostname.

Functions

This section is empty.

Types

type DeployTarget

type DeployTarget int

DeployTarget is an enum that represents the target of a job.

const (
	UNKNOWN_DEPLOY_TARGET DeployTarget = iota
	ALL
	SERVER
	WORKER
	CODERBOX
	DEVBOX
	PLEXBOX
)

type Job

type Job struct {
	Name      string
	Type      JobType
	Shape     TaskResource
	Target    DeployTarget
	Ports     []*Port
	Volumes   []Volume
	Args      []string
	Env       map[string]string
	User      string
	Templates map[string]string
}

Job is a struct that represents a Nomad Job.

func (*Job) GetNomadApiJob added in v0.2.0

func (j *Job) GetNomadApiJob(force bool) (*nomadApi.Job, error)

GetNomadApiJob returns a nomadApi Job for the given slomad.Job.

type JobType

type JobType int

JobType is an enum that represents the type of a job.

const (
	UNKNOWN_JOB_TYPE JobType = iota
	SERVICE
	SYSTEM
	BATCH
	STORAGE_CONTROLLER
	STORAGE_NODE
)

func (JobType) String

func (jt JobType) String() string

String implements the Stringer interface for JobType.

type Port

type Port struct {
	Label  string
	To     int
	From   int
	Static bool
}

Port is a struct that represents a network port for a task.

func BasicPortConfig

func BasicPortConfig(val int) []*Port

BasicPortConfig returns a list with a single Port element with a default label.

type ResourceValue

type ResourceValue int
const (
	TINY    ResourceValue = 128
	SMALL   ResourceValue = 256
	DEFAULT ResourceValue = 512
	LARGE   ResourceValue = 1024
	XLARGE  ResourceValue = 2048
	XXLARGE ResourceValue = 4096
)

type TaskResource

type TaskResource struct {
	CPU ResourceValue
	MEM ResourceValue
}

TaskResource is a struct that represents the CPU and MEM resources for a task.

type Volume

type Volume struct {
	Src   string
	Dst   string
	Mount bool
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL