Better handling of tags update
This commit is contained in:
parent
26f3f1d1f8
commit
80da801ea6
|
@ -201,9 +201,13 @@ def create_svc_txn:
|
|||
select(.ServiceTags[] | contains($mytag))
|
||||
|
||||
# Add needed tags
|
||||
| .ServiceTags -= ["master", "replica", "uninitialized"]
|
||||
| .ServiceTags -= ["master"]
|
||||
| .ServiceTags -= ["replica"]
|
||||
| .ServiceTags -= ["uninitialized"]
|
||||
| .ServiceTags -= ["traefik.enable=true"]
|
||||
| .ServiceTags -= ["traefik.enable=false"]
|
||||
| .ServiceTags += [$role]
|
||||
| if $role == "master" then .ServiceTags += ["traefik.enable=true"] else .ServiceTags -= ["traefik.enable=true"] end
|
||||
| if $role == "master" then .ServiceTags += ["traefik.enable=true"] else .ServiceTags += ["traefik.enable=false"] end
|
||||
|
||||
# Rewrite keys to remove the Service prefix
|
||||
| nest_service_params as $nested_params
|
||||
|
|
|
@ -9,10 +9,14 @@ def create_svc_txn:
|
|||
select(.ServiceTags[] | contains($mytag))
|
||||
|
||||
# Add needed tags
|
||||
| .ServiceTags -= ["master", "replica", "uninitialized"]
|
||||
| .ServiceTags -= ["master"]
|
||||
| .ServiceTags -= ["replica"]
|
||||
| .ServiceTags -= ["uninitialized"]
|
||||
| .ServiceTags -= ["[[ .traefik.instance ]].enable=true"]
|
||||
| .ServiceTags -= ["[[ .traefik.instance ]].enable=false"]
|
||||
| .ServiceTags += [$role]
|
||||
[[- if .traefik.enabled ]]
|
||||
| if $role == "master" then .ServiceTags += ["[[ .traefik.instance ]].enable=true"] else .ServiceTags -= ["[[ .traefik.instance ]].enable=true"] end
|
||||
| if $role == "master" then .ServiceTags += ["[[ .traefik.instance ]].enable=true"] else .ServiceTags += ["[[ .traefik.instance ]].enable=false"] end
|
||||
[[- end ]]
|
||||
|
||||
# Rewrite keys to remove the Service prefix
|
||||
|
|
|
@ -19,10 +19,10 @@ CURL_OPTS="--connect-timeout 5 --max-time 10 --retry 5 --retry-delay 1 --retry-m
|
|||
|
||||
# Update tags on the main service
|
||||
curl ${CURL_OPTS} -H "X-Consul-Token: ${CONSUL_HTTP_TOKEN}" http://{{ sockaddr "GetInterfaceIP \"nomad\"" }}:8500/v1/catalog/service/[[ .instance ]] |\
|
||||
jq --from-file /local/serviceformat.jq --arg role ${NEW_ROLE} --arg mytag [[ .instance ]]-{{ env "NOMAD_ALLOC_INDEX" }} |\
|
||||
jq --from-file /local/serviceformat.jq --arg role ${NEW_ROLE} --arg mytag postgres-{{ env "NOMAD_ALLOC_INDEX" }} |\
|
||||
curl ${CORL_OPTS} -H "X-Consul-Token: ${CONSUL_HTTP_TOKEN}" -X PUT -d @- http://{{ sockaddr "GetInterfaceIP \"nomad\"" }}:8500/v1/agent/service/register
|
||||
|
||||
# Update tags on the sidecar service (connect-proxy)
|
||||
curl ${CURL_OPTS} -H "X-Consul-Token: ${CONSUL_HTTP_TOKEN}" http://{{ sockaddr "GetInterfaceIP \"nomad\"" }}:8500/v1/catalog/service/[[ .instance ]]-sidecar-proxy |\
|
||||
jq --from-file /local/serviceformat.jq --arg role ${NEW_ROLE} --arg mytag [[ .instance ]]-{{ env "NOMAD_ALLOC_INDEX" }} |\
|
||||
jq --from-file /local/serviceformat.jq --arg role ${NEW_ROLE} --arg mytag postgres-{{ env "NOMAD_ALLOC_INDEX" }} |\
|
||||
curl ${CURL_OPTS} -H "X-Consul-Token: ${CONSUL_HTTP_TOKEN}" -X PUT -d @- http://{{ sockaddr "GetInterfaceIP \"nomad\"" }}:8500/v1/agent/service/register
|
||||
|
|
Loading…
Reference in New Issue