Files
deployment-portal-be/templates/deployment_util.jsonnet
Ashvin S d6a6ecb35a INFRA-2883 | Ashvin | Add support for FSx (#837)
* INFRA-2883 | Ashvin | Add support for FSx

* INFRA-2883 | Ashvin | Fix test

* INFRA-2883 | Ashvin | Remove claimName field from fsx object
2024-03-15 22:13:07 +05:30

109 lines
4.5 KiB
Jsonnet

local deployment_manifest = import 'deployment_manifest.jsonnet';
local deployment = deployment_manifest.deployment;
local vars = import 'vars.jsonnet';
local rolloutController = vars.rolloutController;
local deploymentController = deployment.controller;
local ingress = deployment_manifest.deployment.loadBalancers[0];
local load_balancer_util = import 'load_balancer_util.jsonnet';
local chart = import 'chart.jsonnet';
local port_map = import 'port_map.jsonnet';
local namespace_values = import 'namespace_values.jsonnet';
local empty(parent, field) = if (field in parent && parent[field] != {} && parent[field] != [] && parent[field] != '') then false else true;
{
stepsValueMap(step):: {
manualPromotion: { pause: {} },
setWeight: { setWeight: step.value },
pause: { pause: { duration: step.value } },
}[step.name],
getSteps(steps):: [
$.stepsValueMap(step)
for step in steps
],
stickinessConfig(stickinessDuration):: {
enabled: true,
durationSeconds: stickinessDuration,
},
getMaxSurge(deployment)::
if deployment.maxSurge == null || deployment.maxSurge == '' then
if deployment.hpa.minReplicas <= 5 then '51%' else '20%'
else
deployment.maxSurge + '%',
strategy:: {
rollingUpdate()::
if (deploymentController == rolloutController) then {
canary: {
maxSurge: $.getMaxSurge(deployment),
maxUnavailable: 0,
},
} else {
assert deployment.strategy != 'canary' : '%s controller does not support canary' % deploymentController,
type: 'RollingUpdate',
rollingUpdate: {
maxSurge: $.getMaxSurge(deployment),
maxUnavailable: 0,
},
}
,
canary(config={}):: {
assert deploymentController == rolloutController : '%s controller is not supported for canary' % deployment.controller,
assert std.find(ingress.type, ['alb', 'sharedAlbAcrossNamespace']) != [] : '%s is not supported for canary' % ingress.type,
local ingressFullName = load_balancer_util.ingress_name(chart.full_service_name(deployment.name), ingress),
local fullName = chart.full_service_name(deployment.name),
local analysisConfig = if !empty(config, 'analysis') then config.analysis else {},
canary: {
maxSurge: '51%',
maxUnavailable: 0,
[if analysisConfig != {} then 'analysis']: {
templates: [{
templateName: chart.full_service_name(deployment.name),
}],
[if !empty(analysisConfig, 'templates') && deployment.analysisTemplate != null then 'templates']: analysisConfig.templates,
[if !empty(analysisConfig, 'args') then 'args']: analysisConfig.args,
[if !empty(analysisConfig, 'startingStep') then 'startingStep']: analysisConfig.startingStep,
},
steps: if empty(config, 'steps') then vars.defaultCanarySteps else $.getSteps(config.steps),
stableService: '%s-stable' % fullName,
canaryService: '%s-canary' % fullName,
trafficRouting: {
alb: {
ingress: ingressFullName,
rootService: fullName,
servicePort: port_map.getPort('serviceport'),
[if 'stickinessDuration' in config && config.stickinessDuration > 0 then 'stickinessConfig']: $.stickinessConfig(config.stickinessDuration),
},
},
},
},
rollingUpdateWithCanaryMixIn(config={}):: {
assert deploymentController == rolloutController : '%s controller is not supported for canary' % deployment.controller,
assert std.find(ingress.type, ['alb', 'sharedAlbAcrossNamespace']) != [] : '%s is not supported for canary' % ingress.type,
local ingressFullName = load_balancer_util.ingress_name(chart.full_service_name(deployment.name), ingress),
local fullName = chart.full_service_name(deployment.name),
canary: {
maxSurge: '51%',
maxUnavailable: 0,
stableService: '%s-stable' % fullName,
canaryService: '%s-canary' % fullName,
trafficRouting: {
alb: {
ingress: ingressFullName,
rootService: fullName,
servicePort: port_map.getPort('serviceport'),
[if 'stickinessDuration' in config && config.stickinessDuration > 0 then 'stickinessConfig']: $.stickinessConfig(config.stickinessDuration),
},
},
[if config.currentStrategy == 'canary' then 'steps']: [{ pause: {} }],
},
},
},
isEfsNeeded(deployment):: namespace_values.isEfsSupported && 'efs' in deployment,
isFsxNeeded(deployment):: namespace_values.isFsxSupported && 'fsx' in deployment,
}