Skip to content

Conversation

@yabirgb
Copy link

@yabirgb yabirgb commented Aug 20, 2025

we found that in the case of containers running in kubernetes the library raised MachineIdNotFound. There the regex used for docker doesn't return anything. Instead we used the /etc/hostname that contains the pod name.

Not a kubernetes expert but seems that the containers inside the pod can be regenerated and using the container id is not very reliable as they are much more ephemeral.

https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/

➜  rotki git:(docker/build-fix) ✗ kubectl -n rotki exec -it deploy/rotki -- sh

# cat /etc/hostname
rotki-759fdc47dd-bjgvd
#
➜  rotki git:(docker/build-fix) ✗ kubectl -n rotki get pods
NAME                     READY   STATUS    RESTARTS   AGE
rotki-759fdc47dd-bjgvd   1/1     Running   0          6m50s

@ezekg
Copy link
Member

ezekg commented Aug 20, 2025

Containers are by design ephemeral, and mostly useful for concurrency-based licensing models, rather than long-lived node-locked based models, simply because the underlying machines can change very often during autoscaling/rotation.

Regardless, I don't think using the hostname is the right solution here, especially since your implementation doesn't only run in k8s, i.e. it'll break the proceeding powershell line. The hostname is also easily changed. Maybe it'd be a better idea in k8s to use the Downward API to put the pod's UID metadata into a known file such as /etc/machine-id:

volumes:
  - name: podinfo
    downwardAPI:
      items:
        - path: /etc/machine-id
          fieldRef:
            fieldPath: metadata.uid

If overwriting /etc/machine-id is undesirable, I'm fine adding a check for a new file e.g. /etc/pod-id.

@yabirgb
Copy link
Author

yabirgb commented Aug 20, 2025

Thanks for the valuable feedback, @ezekg. In our use case, we don’t have control over the configuration that users run with, but we still need to detect a unique ID when our program runs. If you feel the Kubernetes case doesn’t require special handling in the code itself, adding a note in the README could be a good way to help others who might encounter the same issue.

@ezekg
Copy link
Member

ezekg commented Aug 23, 2025

I want to support k8s, but I'm not sure the hostname here works as a fallback for everything outside of k8s.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants