Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[qfix] Fix createpod overriding labels #204

Merged
merged 1 commit into from
Jul 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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