Skip to content

RFE: In the template syntax, I want to know what topology a given service is in #4127

Closed
@irvingpop

Description

@irvingpop

Currently, you have at the time of template writing whether or not you're binding to a service that is in a topology (e.g. leader) or not. when writing your template, you either choose something like this for finding the leader:

{{~ #if bind.database}}
  {{~ #eachAlive bind.database.members as |member|}}
    {{~ #if member.leader}}
PGHOST="{{member.sys.ip}}"
    {{~ /if}}
  {{~ /eachAlive}}
{{~ /if}}

but if the service isn't in a topology, member.leader will always be false and instead users are instructed to rely on the @first or @last helpers. There's no way to detect if a given service is in a topology or not, so you have to know this in advance and that makes reuse difficult.

Ideally, I would want to do something like this in my template:

{{~#if bind.database}}
  {{~#if bind.database.topology?}}
     {{~#findLeader bind.database.members as |member|}}
       PGHOST="{{member.sys.ip}}"
     {{~/findLeader}}
  {{else}}
     # loop through via #eachAlive
  {{~/if}}
{{~/if}}

or an even more terse way would be something like:

  {{~#if bind.database.topology?}}
     PGHOST={{bind.database.leader.sys.ip}}
  {{else}}
  {{~/if}}

pie in the sky, but a "just do the right thing" pointer that would choose the leader the in a leader topology or any alive member at random in a non-leader topology would be the nicest from a user perspective

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocumentationFlags an issue / PR for attention by the technical documentation teamFocus:SupervisorRelated to the Habitat Supervisor (core/hab-sup) componentType: FeatureIssues that describe a new desired feature

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions