mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2025-04-16 15:28:52 +00:00
Change all labels to use hyphens instead of underscores, and fix some instances of using split instead of a regex
Signed-off-by: Pablo Carranza Velez <pablo@resin.io>
This commit is contained in:
parent
3a710506a6
commit
60f0cd2fcb
@ -629,7 +629,7 @@ module.exports = class ApplicationManager extends EventEmitter
|
||||
validStrategies = [ 'download-then-kill', 'kill-then-download', 'delete-then-download', 'hand-over' ]
|
||||
if !_.includes(validStrategies, strategy)
|
||||
strategy = 'download-then-kill'
|
||||
timeout = checkInt(target.labels['io.resin.update.handover_timeout'])
|
||||
timeout = checkInt(target.labels['io.resin.update.handover-timeout'])
|
||||
return @_strategySteps[strategy](current, target, needsDownload, dependenciesMetForStart, dependenciesMetForKill, needsSpecialKill, timeout)
|
||||
|
||||
_nextStepsForAppUpdate: (currentApp, targetApp, availableImages = [], stepsInProgress = []) =>
|
||||
|
@ -10,7 +10,7 @@ module.exports = class Networks
|
||||
|
||||
# TODO: parse supported config fields
|
||||
format: (network) ->
|
||||
m = /^([0-9]+)_(.+)$/.match(network.Name)
|
||||
m = network.Name.match(/^([0-9]+)_(.+)$/)
|
||||
appId = checkInt(m[1])
|
||||
name = m[2]
|
||||
return {
|
||||
|
@ -82,7 +82,7 @@ module.exports = class ServiceManager extends EventEmitter
|
||||
return service
|
||||
|
||||
getAllByAppId: (appId) =>
|
||||
@getAll("io.resin.app_id=#{appId}")
|
||||
@getAll("io.resin.app-id=#{appId}")
|
||||
|
||||
stopAllByAppId: (appId) =>
|
||||
Promise.map @getAllByAppId(appId), (service) =>
|
||||
@ -164,7 +164,7 @@ module.exports = class ServiceManager extends EventEmitter
|
||||
|
||||
# Returns an array with the container(s) matching a service by appId, commit, image and environment
|
||||
get: (service) =>
|
||||
@getAll("io.resin.service_id=#{service.serviceId}")
|
||||
@getAll("io.resin.service-id=#{service.serviceId}")
|
||||
.filter((currentService) -> currentService.isSameContainer(service))
|
||||
.get(0)
|
||||
|
||||
@ -219,7 +219,7 @@ module.exports = class ServiceManager extends EventEmitter
|
||||
.then =>
|
||||
@start(targetService)
|
||||
.then =>
|
||||
@waitToKill(currentService, targetService.labels['io.resin.update.handover_timeout'])
|
||||
@waitToKill(currentService, targetService.labels['io.resin.update.handover-timeout'])
|
||||
.then =>
|
||||
@kill(currentService)
|
||||
|
||||
|
@ -276,16 +276,16 @@ module.exports = class Service
|
||||
addFeaturesFromLabels: (opts) =>
|
||||
if checkTruthy(@labels['io.resin.features.dbus'])
|
||||
@volumes.push('/run/dbus:/host/run/dbus')
|
||||
if checkTruthy(@labels['io.resin.features.kernel_modules'])
|
||||
if checkTruthy(@labels['io.resin.features.kernel-modules'])
|
||||
@volumes.push('/lib/modules:/lib/modules')
|
||||
if checkTruthy(@labels['io.resin.features.firmware'])
|
||||
@volumes.push('/lib/firmware:/lib/firmware')
|
||||
if checkTruthy(@labels['io.resin.features.supervisor_api'])
|
||||
if checkTruthy(@labels['io.resin.features.supervisor-api'])
|
||||
@_addSupervisorApi(opts)
|
||||
else
|
||||
# We ensure the user hasn't added "supervisor0" to the service's networks
|
||||
delete @networks[constants.supervisorNetworkInterface]
|
||||
if checkTruthy(@labels['io.resin.features.resin_api'])
|
||||
if checkTruthy(@labels['io.resin.features.resin-api'])
|
||||
@environment['RESIN_API_KEY'] = opts.deviceApiKey
|
||||
|
||||
extendEnvVars: ({ imageInfo, uuid, appName, name, version, deviceType, osVersion }) =>
|
||||
@ -312,9 +312,9 @@ module.exports = class Service
|
||||
@labels = _.clone(@labels)
|
||||
_.defaults(@labels, imageInfo?.Config?.Labels ? {})
|
||||
@labels['io.resin.supervised'] = 'true'
|
||||
@labels['io.resin.app_id'] = @appId.toString()
|
||||
@labels['io.resin.service_id'] = @serviceId.toString()
|
||||
@labels['io.resin.service_name'] = @serviceName
|
||||
@labels['io.resin.app-id'] = @appId.toString()
|
||||
@labels['io.resin.service-id'] = @serviceId.toString()
|
||||
@labels['io.resin.service-name'] = @serviceName
|
||||
return @labels
|
||||
|
||||
extendAndSanitiseExposedPorts: (imageInfo) =>
|
||||
@ -333,10 +333,13 @@ module.exports = class Service
|
||||
for vol in @volumes
|
||||
isBind = /:/.test(vol)
|
||||
if isBind
|
||||
[ bindSource, bindDest ] = vol.split(':')
|
||||
[ bindSource, bindDest, mode ] = vol.split(':')
|
||||
if !path.isAbsolute(bindSource)
|
||||
# Rewrite named volumes to namespace by appId
|
||||
volumes.push("#{@appId}_#{bindSource}:#{bindDest}")
|
||||
volDefinition = "#{@appId}_#{bindSource}:#{bindDest}"
|
||||
if mode?
|
||||
volDefinition += ":#{mode}"
|
||||
volumes.push(volDefinition)
|
||||
else
|
||||
console.log("Ignoring invalid bind mount #{vol}")
|
||||
else
|
||||
@ -353,7 +356,8 @@ module.exports = class Service
|
||||
return null
|
||||
bindSource = vol.split(':')[0]
|
||||
if !path.isAbsolute(bindSource)
|
||||
return bindSource.split('_')[1]
|
||||
m = bindSource.match(/[0-9]+_(.+)/)
|
||||
return m[1]
|
||||
else
|
||||
return null
|
||||
return _.filter(validVolumes, (v) -> !_.isNull(v))
|
||||
@ -395,9 +399,9 @@ module.exports = class Service
|
||||
if containerPort? and !_.includes(boundContainerPorts, containerPort)
|
||||
expose.push(containerPort)
|
||||
|
||||
appId = checkInt(container.Config.Labels['io.resin.app_id'])
|
||||
serviceId = checkInt(container.Config.Labels['io.resin.service_id'])
|
||||
serviceName = container.Config.Labels['io.resin.service_name']
|
||||
appId = checkInt(container.Config.Labels['io.resin.app-id'])
|
||||
serviceId = checkInt(container.Config.Labels['io.resin.service-id'])
|
||||
serviceName = container.Config.Labels['io.resin.service-name']
|
||||
nameComponents = container.Name.match(/.*_(\d+)_(\d+)$/)
|
||||
imageId = checkInt(nameComponents?[1])
|
||||
releaseId = checkInt(nameComponents?[2])
|
||||
|
@ -12,7 +12,7 @@ module.exports = class Volumes
|
||||
constructor: ({ @docker, @logger }) ->
|
||||
|
||||
format: (volume) =>
|
||||
m = /^([0-9]+)_(.+)$/.match(volume.Name)
|
||||
m = volume.Name.match(/^([0-9]+)_(.+)$/)
|
||||
appId = checkInt(m[1])
|
||||
name = m[2]
|
||||
return {
|
||||
|
@ -32,7 +32,7 @@ exports.isValidEnv = isValidEnv = (obj) ->
|
||||
|
||||
exports.isValidLabelsObject = isValidLabelsObject = (obj) ->
|
||||
_.isObject(obj) and _.every obj, (val, key) ->
|
||||
isValidShortText(key) and /^[a-zA-Z_]+[a-zA-Z0-9_.]*$/.test(key) and _.isString(val)
|
||||
isValidShortText(key) and /^[a-zA-Z_]+[a-zA-Z0-9\.\-]*$/.test(key) and _.isString(val)
|
||||
|
||||
undefinedOrValidEnv = (val) ->
|
||||
if val? and !isValidEnv(val)
|
||||
|
@ -60,13 +60,13 @@ var singleToMulticontainerApp = function (app, appId) {
|
||||
`${defaultVolume}:/data`
|
||||
],
|
||||
labels: {
|
||||
'io.resin.features.kernel_modules': '1',
|
||||
'io.resin.features.kernel-modules': '1',
|
||||
'io.resin.features.firmware': '1',
|
||||
'io.resin.features.dbus': '1',
|
||||
'io.resin.features.supervisor_api': '1',
|
||||
'io.resin.features.resin_api': '1',
|
||||
'io.resin.features.supervisor-api': '1',
|
||||
'io.resin.features.resin-api': '1',
|
||||
'io.resin.update.strategy': updateStrategy,
|
||||
'io.resin.update.handover_timeout': handoverTimeout
|
||||
'io.resin.update.handover-timeout': handoverTimeout
|
||||
},
|
||||
environment: environment,
|
||||
restart: restartPolicy,
|
||||
|
Loading…
x
Reference in New Issue
Block a user