假设我有这样的代码来生成新的 pod
req := &api.Pod{
TypeMeta: unversioned.TypeMeta{
Kind: "Pod",
APIVersion: "v1",
},
ObjectMeta: api.ObjectMeta{
GenerateName: "name-, // need to get that name, before creating an object
},
Spec: api.PodSpec{
Containers: []api.Container{
{
Name: "nginx",
Image: "nginx",
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)
是否可以在创建对象之前获取生成的名称?或者是否可以将生成的名称存储在同一个对象的环境中?