From 2d428a98949e2d35381af200584eebf949680376 Mon Sep 17 00:00:00 2001 From: Nikita Skrynnik Date: Tue, 23 May 2023 16:17:03 +0700 Subject: [PATCH] generate client ID for pods only Signed-off-by: Nikita Skrynnik --- main.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 271a7a0..0e42a66 100644 --- a/main.go +++ b/main.go @@ -106,10 +106,14 @@ func (s *admissionWebhookServer) Review(ctx context.Context, in *admissionv1.Adm } if annotation != "" { - clientID := uuid.NewString() + nsmNameEnv := corev1.EnvVar{Name: "NSM_NAME", Value: "$(POD_NAME)"} + if podMetaPtr.GenerateName == "" { + clientID := uuid.NewString() + nsmNameEnv.Value = fmt.Sprintf("$(POD_NAME)-%v", clientID) + } envVars := append(s.config.GetOrResolveEnvs(), corev1.EnvVar{Name: s.config.NSURLEnvName, Value: annotation}, - corev1.EnvVar{Name: "NSM_NAME", Value: fmt.Sprintf("$(POD_NAME)-%v", clientID)}) + nsmNameEnv) bytes, err := json.Marshal([]jsonpatch.JsonPatchOperation{ s.createInitContainerPatch(p, annotation, spec.InitContainers, envVars...),