Skip to content

Commit

Permalink
Merge pull request #204 from d-uzlov/qfix/createpod-labels-override
Browse files Browse the repository at this point in the history
[qfix] Fix createpod overriding labels
  • Loading branch information
denis-tingaikin authored Jul 14, 2021
2 parents 6a4dea6 + e269001 commit 63be0f0
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 21 deletions.
10 changes: 0 additions & 10 deletions pkg/networkservice/common/createpod/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,6 @@ func WithNamespace(namespace string) Option {
}
}

// WithLabelsKey sets labels key value. Default value is "NSM_LABELS".
//
// Environment variable with specified labels key is set on pod creation,
// to notify the pod about the node it is being create on.
func WithLabelsKey(labelsKey string) Option {
return func(t *createPodServer) {
t.labelsKey = labelsKey
}
}

// WithNameGenerator sets function to be used for pod name generation.
// Default behavior is to append a random uuid to the template name.
func WithNameGenerator(nameGenerator func(templateName, nodeName string) string) Option {
Expand Down
10 changes: 1 addition & 9 deletions pkg/networkservice/common/createpod/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ type createPodServer struct {
client kubernetes.Interface
podTemplate *corev1.Pod
namespace string
labelsKey string
nodeMap nodeInfoMap
nameGenerator func(templateName, nodeName string) string
}
Expand All @@ -63,8 +62,7 @@ func NewServer(ctx context.Context, client kubernetes.Interface, podTemplate *co
podTemplate: podTemplate.DeepCopy(),
client: client,
namespace: "default",
labelsKey: "NSM_LABELS",
nameGenerator: func(templateName, nodeName string) string { return templateName + uuid.New().String() },
nameGenerator: func(templateName, nodeName string) string { return templateName + "-" + uuid.New().String() },
}

for _, opt := range options {
Expand Down Expand Up @@ -137,12 +135,6 @@ func (s *createPodServer) createPod(ctx context.Context, nodeName, podName strin
podTemplate := s.podTemplate.DeepCopy()
podTemplate.ObjectMeta.Name = podName
podTemplate.Spec.NodeName = nodeName
for i := range podTemplate.Spec.Containers {
podTemplate.Spec.Containers[i].Env = append(podTemplate.Spec.Containers[i].Env, corev1.EnvVar{
Name: s.labelsKey,
Value: "nodeName: " + nodeName,
})
}

_, err := s.client.CoreV1().Pods(s.namespace).Create(ctx, podTemplate, metav1.CreateOptions{})
return err
Expand Down
2 changes: 0 additions & 2 deletions pkg/networkservice/common/createpod/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@ func TestCreatePod_RepeatedRequest(t *testing.T) {

want := podTemplate.DeepCopy()
want.Spec.NodeName = nodeName1
want.Spec.Containers[0].Env = []corev1.EnvVar{{Name: "NSM_LABELS", Value: "nodeName: " + nodeName1}}
want.Spec.Containers[1].Env = []corev1.EnvVar{{Name: "NSM_LABELS", Value: "nodeName: " + nodeName1}}
require.Equal(t, pod.Spec, want.Spec)

pod.Status.Phase = "Succeeded"
Expand Down

0 comments on commit 63be0f0

Please sign in to comment.