Sidekick how detect primary service (container)?

I was playing with metadata and have not found a simple way how to get primary service container name without looping all containers and comparing self/stack/services/$MAIN/containers/[0..N]/host_uuid with self/host/uuid. which works if service is scheduled only once per host.

Did I miss something?

You should be able to get your self name self/container/name to get your own name and then in self/stack/services/$MAIN/containers, you’d be able to get all names and then exclude yourself to determine what is the primary service.

What you described works only if primary has only one sidekick and scale of one doesn’t it?

For example I have setup proxy (main) + service (sidekick) + proxy confd (sidekick) and proxy needs to know IP of the service that is on the same host (to use unix socket instead or to adjust weight for load balancing).

It would be useful for sidekicks and primary service to have information about sidekick/primary service containers that are on same host.

@mishak you can fetch this information from container’s “labels” field on the metadata. Primary + (n) sidekick containers have the same “io.rancher.service.deployment.unit” value. For a example, in service with scale=3 having 1 sidekick, there will be 3 deployment units, each having 1 container of primary + 1 container of a sidekick service. So to get your peers, you find out what your deployment.unit is, and then get instances having the same deployment.unit from /latest/containers. Hope that helps

1 Like

Exactly what I needed thanks!

@alena is it possible to specify “deployment.unit” as a macros like we have for $${stack_name}?
I’m looking for this label “ io.rancher.service.deployment.unit=$${deployment_unit}”