<p>Let's suppose that I have such code to generate new pod</p>
<pre><code>req := &amp;api.Pod{
        TypeMeta: unversioned.TypeMeta{
            Kind:       &quot;Pod&quot;,
            APIVersion: &quot;v1&quot;,
        },
        ObjectMeta: api.ObjectMeta{
            GenerateName: &quot;name-, // need to get that name, before creating an object
        },
        Spec: api.PodSpec{
            Containers: []api.Container{
                {
                    Name:  &quot;nginx&quot;,
                    Image: &quot;nginx&quot;,
                    Env:   []corev1.EnvVar{} // pass here the generated name,

                },
            },
        },
}
...
// Do some work on the generated name, before creating the resource in Kubernetes cluster
...
err := client.Create(context.Background(), req)
</code></pre>
<p>Is it possible to get that generated name before creating an object? Or is it possible to store that generated name in the env of the same object?</p>

<p>The generated name seem to be created in conjunction with the apiServer. See <a href="https://github.com/kubernetes/kubernetes/issues/44501#issuecomment-294255660" rel="nofollow noreferrer">Issue comment</a> and <a href="https://kubernetes.io/docs/reference/using-api/api-concepts/#generated-values" rel="nofollow noreferrer">Kubernetes API Concepts - Generated values</a>.</p>
<p>It is recommended to not depend on it. Typically, labels and selectors is more common in the Kubernetes ecosystem.</p>
<pre><code>Env:   []corev1.EnvVar{} // pass here the generated name,
</code></pre>
<p>You can use the Downward API for this.
Example:</p>
<pre><code>          env:
            - name: POD_NAME
              valueFrom:
                fieldRef:
                  fieldPath: metadata.name
</code></pre>
