Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TAM Implementation #655

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions amqp_job_queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ func (q *AMQPJobQueue) Jobs(ctx gocontext.Context) (outChan <-chan Job, err erro
buildJob.startAttributes.VMSize = buildJob.payload.VMSize
buildJob.startAttributes.VMConfig = buildJob.payload.VMConfig
buildJob.startAttributes.Warmer = buildJob.payload.Warmer
buildJob.startAttributes.TamToken = buildJob.payload.TamToken
buildJob.startAttributes.SetDefaults(q.DefaultLanguage, q.DefaultDist, q.DefaultArch, q.DefaultGroup, q.DefaultOS, VMTypeDefault, VMConfigDefault)
buildJob.conn = q.conn
buildJob.stateCount = buildJob.payload.Meta.StateUpdateCount
Expand Down
19 changes: 18 additions & 1 deletion backend/lxd.go
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,19 @@ func (p *lxdProvider) Start(ctx gocontext.Context, startAttributes *StartAttribu
// Select the image
if startAttributes.ImageName != "" {
imageName = startAttributes.ImageName
} else if startAttributes.OSCustom != "" {
imageName = startAttributes.OSCustom

var imgManager *image.Manager
imgManager, err = image.NewManager(ctx, nil, p.imageBaseURL)
if err != nil {
return nil, err
}
err = imgManager.LoadCustom(imageName, startAttributes.TamToken)

if err != nil {
return nil, err
}
} else {
imageArch := startAttributes.Arch
if p.archOverride != "" {
Expand Down Expand Up @@ -724,6 +737,10 @@ func (p *lxdProvider) Start(ctx gocontext.Context, startAttributes *StartAttribu

container.Devices["eth0"]["ipv4.address"] = strings.Split(address, "/")[0]

if startAttributes.OSCustom != "" {
startAttributes.Dist = ""
}

var fileName, content string
switch startAttributes.Dist {
case "xenial":
Expand All @@ -741,7 +758,7 @@ iface eth0 inet static
mtu %s
`, address, p.networkGateway, strings.Join(p.networkDNS, " "), p.networkMTU)
default:
fileName = "/etc/netplan/50-cloud-init.yaml"
fileName = "/etc/netplan/51-cloud-init.yaml"
content = fmt.Sprintf(`network:
version: 2
ethernets:
Expand Down
7 changes: 5 additions & 2 deletions backend/start_attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type StartAttributes struct {
Group string `json:"group"`
OS string `json:"os"`
ImageName string `json:"image_name"`
OSCustom string `json:"os_custom"`

// The VMType isn't stored in the config directly, but in the top level of
// the job payload, see the worker.JobPayload struct.
Expand All @@ -29,12 +30,10 @@ type StartAttributes struct {
// the job payload, see the worker.JobPayload struct.
VMConfig VmConfig `json:"-"`


// The VMSize isn't stored in the config directly, but in the top level of
// the job payload, see the worker.JobPayload struct.
VMSize string `json:"-"`


// Warmer isn't stored in the config directly, but in the top level of
// the job payload, see the worker.JobPayload struct.
Warmer bool `json:"-"`
Expand All @@ -46,6 +45,10 @@ type StartAttributes struct {
// ProgressType isn't stored in the config directly, but is injected from
// the processor
ProgressType string `json:"-"`

// TamToken isn't stored in the config directly, but in the top level of
// the job payload, see the worker.JobPayload struct.
TamToken string `json:"-"`
}

// SetDefaults sets any missing required attributes to the default values provided
Expand Down
31 changes: 31 additions & 0 deletions image/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,31 @@ func (m *Manager) Load(imageName string) error {
return m.importImage(imageName, imageURL)
}

func (m *Manager) LoadCustom(imageName string, tamToken string) error {
ok, err := m.Exists(imageName)
if err != nil {
return err
}

if ok {
m.logger.WithFields(logrus.Fields{
"image_name": imageName,
"token": tamToken,
}).Info("image already present")

return nil
}

imageURL := m.customImageUrl(imageName, tamToken)

m.logger.WithFields(logrus.Fields{
"image_name": imageName,
"image_url": imageURL,
}).Info("importing image")

return m.importImage(imageName, imageURL)
}

func (m *Manager) Exists(imageName string) (bool, error) {
images, err := m.client.GetImages()
if err != nil {
Expand Down Expand Up @@ -206,3 +231,9 @@ func (m *Manager) imageUrl(name string) string {
u.Path = fmt.Sprintf("/images/travis/%s", name)
return u.String()
}

func (m *Manager) customImageUrl(name string, tamToken string) string {
u := *m.imagesServerURL
u.Path = fmt.Sprintf("/images/custom/%s/%s", url.QueryEscape(name), tamToken)
return u.String()
}
1 change: 1 addition & 0 deletions job.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type JobPayload struct {
Queue string `json:"queue"`
Trace bool `json:"trace"`
Warmer bool `json:"warmer"`
TamToken string `json:"tam_token"`
}

// JobMetaPayload contains meta information about the job.
Expand Down