43 lines
1.4 KiB
Smarty
43 lines
1.4 KiB
Smarty
def nest_service_params:
|
|
# Select all objects with keys that start with the the name 'Service'
|
|
# Remove 'Service' prefix from key names
|
|
with_entries(select(.key | startswith("Service")) | .key = (.key | sub("^Service"; "")))
|
|
;
|
|
|
|
def create_svc_txn:
|
|
# Select our own instance
|
|
select(.ServiceTags[] | contains($mytag))
|
|
|
|
# Add needed tags, remove unwanted ones
|
|
| .ServiceTags -= ["master"]
|
|
| .ServiceTags -= ["replica"]
|
|
| .ServiceTags -= ["uninitialized"]
|
|
| .ServiceTags -= ["[[ .traefik.instance ]].enable=true"]
|
|
| .ServiceTags += [$role]
|
|
[[- if .traefik.enabled ]]
|
|
| if $role == "master" then .ServiceTags += ["[[ .traefik.instance ]].enable=true"] else .ServiceTags -= ["[[ .traefik.instance ]].enable=true"] end
|
|
[[- end ]]
|
|
|
|
# Rename 'ServiceName' to 'ServiceService'
|
|
# Will be transformed to 'Service.Service later'
|
|
| . + {ServiceService: .ServiceName}
|
|
| del(.ServiceName)
|
|
| nest_service_params as $nested_params
|
|
|
|
# Create transaction to update services using check-and-set option.
|
|
# If service has been modified since our last read, or no longer exists, the
|
|
# transaction will fail.
|
|
| {
|
|
Service: {
|
|
Verb: "cas",
|
|
Node: .Node,
|
|
|
|
# Nest service-related parameters under 'Service' key
|
|
# Add ModfyIndex key
|
|
Service: ($nested_params + {ModifyIndex: .ModifyIndex})
|
|
}
|
|
}
|
|
;
|
|
|
|
. | map(create_svc_txn)
|