mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2024-12-29 18:18:52 +00:00
Add support for service hostname
Plus several small bug fixes: * Allow target states with apps with no release * Fix lock override and a TypeError in compareServicesForUpdate * Lowercase service names when doing migrations and legacy preload * Fix deltas from scratch Signed-off-by: Pablo Carranza Velez <pablo@resin.io>
This commit is contained in:
parent
839ebf8688
commit
f653fa4961
@ -383,7 +383,7 @@ module.exports = class ApplicationManager extends EventEmitter
|
||||
removePairs = []
|
||||
installPairs = []
|
||||
updatePairs = []
|
||||
if currentServices.length == 1 and targetServices.length == 1 and
|
||||
if currentServices?.length == 1 and targetServices?.length == 1 and
|
||||
targetServices[0].serviceName == currentServices[0].serviceName and
|
||||
checkTruthy(currentServices[0].labels['io.resin.legacy-container'])
|
||||
# This is a legacy preloaded app or container, so we didn't have things like serviceId.
|
||||
@ -880,7 +880,7 @@ module.exports = class ApplicationManager extends EventEmitter
|
||||
return Promise.resolve()
|
||||
@config.get('lockOverride')
|
||||
.then (lockOverride) ->
|
||||
return lockOverride or force
|
||||
return checkTruthy(lockOverride) or force
|
||||
.then (force) ->
|
||||
updateLock.lock(appId, { force }, fn)
|
||||
|
||||
|
@ -54,7 +54,7 @@ module.exports = class Images extends EventEmitter
|
||||
if validation.checkTruthy(opts.delta)
|
||||
@logger.logSystemEvent(logTypes.downloadImageDelta, { image })
|
||||
Promise.try =>
|
||||
if opts.deltaSource
|
||||
if opts.deltaSource and opts.deltaSource != 'resin/scratch'
|
||||
@inspectByName(opts.deltaSource)
|
||||
.then (srcImage) ->
|
||||
opts.deltaSourceId = srcImage.Id
|
||||
|
@ -1,5 +1,6 @@
|
||||
_ = require 'lodash'
|
||||
path = require 'path'
|
||||
os = require 'os'
|
||||
{ checkTruthy, checkInt } = require '../lib/validation'
|
||||
updateLock = require '../lib/update-lock'
|
||||
constants = require '../lib/constants'
|
||||
@ -138,7 +139,6 @@ module.exports = class Service
|
||||
@exposedPorts
|
||||
@portBindings
|
||||
@networks
|
||||
|
||||
@memLimit
|
||||
@memReservation
|
||||
@shmSize
|
||||
@ -162,6 +162,7 @@ module.exports = class Service
|
||||
@healthcheck
|
||||
@readOnly
|
||||
@sysctls
|
||||
@hostname
|
||||
} = _.mapKeys(serviceProperties, (v, k) -> _.camelCase(k))
|
||||
|
||||
@networks ?= {}
|
||||
@ -205,6 +206,8 @@ module.exports = class Service
|
||||
|
||||
@sysctls ?= {}
|
||||
|
||||
@hostname ?= ''
|
||||
|
||||
# If the service has no containerId, it is a target service and has to be normalised and extended
|
||||
if !@containerId?
|
||||
@networkMode ?= 'default'
|
||||
@ -405,6 +408,12 @@ module.exports = class Service
|
||||
nameComponents = container.Name.match(/.*_(\d+)_(\d+)$/)
|
||||
imageId = checkInt(nameComponents?[1])
|
||||
releaseId = checkInt(nameComponents?[2])
|
||||
hostname = container.Config.Hostname
|
||||
# A hostname equal to the first part of the container ID actually
|
||||
# means no hostname was specified
|
||||
if hostname == container.Id.substr(0, 12) or
|
||||
(container.HostConfig.NetworkMode == 'host' and hostname == os.hostname())
|
||||
hostname = ''
|
||||
service = {
|
||||
appId: appId
|
||||
serviceId: serviceId
|
||||
@ -453,6 +462,7 @@ module.exports = class Service
|
||||
init: container.HostConfig.Init
|
||||
readOnly: container.HostConfig.ReadonlyRootfs
|
||||
sysctls: container.HostConfig.Sysctls
|
||||
hostname: hostname
|
||||
}
|
||||
# I've seen docker use either 'no' or '' for no restart policy, so we normalise to 'no'.
|
||||
if service.restartPolicy.Name == ''
|
||||
@ -582,6 +592,7 @@ module.exports = class Service
|
||||
'init'
|
||||
'readOnly'
|
||||
'sysctls'
|
||||
'hostname'
|
||||
]
|
||||
arraysToCompare = [
|
||||
'volumes'
|
||||
|
@ -72,7 +72,7 @@ singleToMulticontainerApp = (app) ->
|
||||
{
|
||||
serviceId: 1
|
||||
appId: appId
|
||||
serviceName: app.name
|
||||
serviceName: app.name.toLowerCase()
|
||||
imageId: 1
|
||||
commit: app.commit
|
||||
releaseId: 1
|
||||
|
@ -61,7 +61,7 @@ exports.isValidAppsObject = (obj) ->
|
||||
return false if !_.isObject(obj)
|
||||
return false if !_.every obj, (val, appId) ->
|
||||
return false if !isValidShortText(appId) or !checkInt(appId)?
|
||||
return false if !isValidShortText(val.name) or !checkInt(val.releaseId)?
|
||||
return false if !isValidShortText(val.name) or (val.releaseId? and !checkInt(val.releaseId)?)
|
||||
return false if !_.isObject(val.services)
|
||||
return false if !_.every(val.services, isValidService)
|
||||
return true
|
||||
|
@ -49,7 +49,7 @@ var singleToMulticontainerApp = function (app, appId) {
|
||||
{
|
||||
serviceId: 1,
|
||||
appId: appId,
|
||||
serviceName: app.name,
|
||||
serviceName: app.name.toLowerCase(),
|
||||
imageId: 1,
|
||||
commit: app.commit,
|
||||
releaseId: 1,
|
||||
|
Loading…
Reference in New Issue
Block a user