this is an extremely basic question & probably...
# general
m
this is an extremely basic question & probably covered in the docs, but I can't find it referenced in the auto-naming section of the FAQ, so here goes: if I have a resource whose name is automatically generated (say, a k8s job named
migration-z6pw7
, how do I reference that entire name as an argument to another resource? using
job.metadata.name
only results in `migration`; using
job.id
results in
my-system/migration
, and I just can't find where to get the concrete hex ID back.
I explicitly don't want to use a manually-assigned name, auto-naming is correct for us here! But I do want to be able to refer back to the exact resource in string arguments to other pods.
b
It sounds like you're doing the right thing. We have an example here where we create a namespace (which will be autonamed) then create a variable with the name in and then use that name in a deployment. Take a look at that
(I know you're talking about a job and I'm talking about a namespace but it should be similar)
m
so do I understand right that what I should get from
job.metadata.name
is the auto-named resource name?
I do:
Copy code
wait_for_migration = k8s.core.v1.ContainerArgs(
    name=f"{base_name}-migrate-wait",
    image="groundnuty/k8s-wait-for:1.3",
    args=["job", migrations_job.metadata.name],
    image_pull_policy="IfNotPresent",
    **env,
)
and when using that in init_containers of other pods, I get the following args when I
describe pod
those:
Copy code
Args:
      job
      migration
    State:          Waiting
      Reason:       CrashLoopBackOff
OHO! I think my problem was that I passed an explicit
name
to metadata on
migrations_job
.
which ... still auto-names the k8s resource, but leads the "plain" return value
ok, now all my names line up - thanks!
wait, no, I'm wrong: they don't.
the migration pod is named
migration-4hooo8ld-dkxqn
and the name output seems to be
migration-4hooo8ld
... what.
b
so the pods are named by k8s... so they're taking the name of the deployment and giving it a further autonaming suffix
m
hah, sorry: yep, the names do line up - I need the job's name after all, which is exactly the above.
so, it does work - just can't pass the metadata name to the resource (:
b
Would you mind opening an issue in this repo: https://github.com/pulumi/pulumi-kubernetes it kinda feels like this is a bug
👍 1