From ee6fd520008b198f08e0d859354c7fb712855523 Mon Sep 17 00:00:00 2001 From: kanha gupta <92207457+kanha-gupta@users.noreply.github.com> Date: Thu, 23 May 2024 02:37:06 +0530 Subject: [PATCH] Improve labels for antctl check framework (#6341) Signed-off-by: Kanha gupta --- pkg/antctl/raw/check/cluster/command.go | 2 +- pkg/antctl/raw/check/installation/command.go | 14 +++++++------- pkg/antctl/raw/check/util.go | 2 -- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/pkg/antctl/raw/check/cluster/command.go b/pkg/antctl/raw/check/cluster/command.go index 07c3ae313ce..a351f8fdac4 100644 --- a/pkg/antctl/raw/check/cluster/command.go +++ b/pkg/antctl/raw/check/cluster/command.go @@ -116,7 +116,7 @@ func Run() error { func (t *testContext) setup(ctx context.Context) error { t.Log("Creating Namespace %s for pre installation tests...", t.namespace) - _, err := t.client.CoreV1().Namespaces().Create(ctx, &corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: t.namespace}}, metav1.CreateOptions{}) + _, err := t.client.CoreV1().Namespaces().Create(ctx, &corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: t.namespace, Labels: map[string]string{"app": "antrea", "component": "cluster-checker"}}}, metav1.CreateOptions{}) if err != nil { return fmt.Errorf("unable to create Namespace %s: %s", t.namespace, err) } diff --git a/pkg/antctl/raw/check/installation/command.go b/pkg/antctl/raw/check/installation/command.go index 256124ef2a9..97c1c100f14 100644 --- a/pkg/antctl/raw/check/installation/command.go +++ b/pkg/antctl/raw/check/installation/command.go @@ -194,7 +194,7 @@ func (t *testContext) setup(ctx context.Context) error { return fmt.Errorf("unable to determine status of Antrea DaemonSet: %w", err) } t.Log("Creating Namespace %s for post installation tests...", t.namespace) - _, err = t.client.CoreV1().Namespaces().Create(ctx, &corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: t.namespace}}, metav1.CreateOptions{}) + _, err = t.client.CoreV1().Namespaces().Create(ctx, &corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: t.namespace, Labels: map[string]string{"app": "antrea", "component": "installation-checker"}}}, metav1.CreateOptions{}) if err != nil { return fmt.Errorf("unable to create Namespace %s: %s", t.namespace, err) } @@ -211,7 +211,7 @@ func (t *testContext) setup(ctx context.Context) error { Effect: "NoSchedule", }, } - echoDeployment := check.NewDeployment(check.DeploymentParameters{ + echoSameNodeDeployment := check.NewDeployment(check.DeploymentParameters{ Name: echoSameNodeDeploymentName, Role: kindEchoName, Port: 80, @@ -236,9 +236,9 @@ func (t *testContext) setup(ctx context.Context) error { }, }, Tolerations: commonToleration, - Labels: map[string]string{"app": echoSameNodeDeploymentName}, + Labels: map[string]string{"app": "antrea", "component": "installation-checker", "name": echoSameNodeDeploymentName}, }) - _, err = t.client.AppsV1().Deployments(t.namespace).Create(ctx, echoDeployment, metav1.CreateOptions{}) + _, err = t.client.AppsV1().Deployments(t.namespace).Create(ctx, echoSameNodeDeployment, metav1.CreateOptions{}) if err != nil { return fmt.Errorf("unable to create Deployment %s: %s", echoSameNodeDeploymentName, err) } @@ -250,7 +250,7 @@ func (t *testContext) setup(ctx context.Context) error { Command: []string{"/agnhost", "pause"}, Port: 80, Tolerations: commonToleration, - Labels: map[string]string{"app": clientDeploymentName}, + Labels: map[string]string{"app": "antrea", "component": "installation-checker", "name": clientDeploymentName}, }) _, err = t.client.AppsV1().Deployments(t.namespace).Create(ctx, clientDeployment, metav1.CreateOptions{}) if err != nil { @@ -277,7 +277,7 @@ func (t *testContext) setup(ctx context.Context) error { }, }, Tolerations: commonToleration, - Labels: map[string]string{"app": echoOtherNodeDeploymentName}, + Labels: map[string]string{"app": "antrea", "component": "installation-checker", "name": echoOtherNodeDeploymentName}, }) nodes, err := t.client.CoreV1().Nodes().List(ctx, metav1.ListOptions{}) if err != nil { @@ -310,7 +310,7 @@ func (t *testContext) setup(ctx context.Context) error { return err } } - podList, err := t.client.CoreV1().Pods(t.namespace).List(ctx, metav1.ListOptions{LabelSelector: "kind=" + kindClientName}) + podList, err := t.client.CoreV1().Pods(t.namespace).List(ctx, metav1.ListOptions{LabelSelector: "name=" + clientDeploymentName}) if err != nil { return fmt.Errorf("unable to list client Pods: %s", err) } diff --git a/pkg/antctl/raw/check/util.go b/pkg/antctl/raw/check/util.go index d5f3aa92843..1eb24ab87b9 100644 --- a/pkg/antctl/raw/check/util.go +++ b/pkg/antctl/raw/check/util.go @@ -121,8 +121,6 @@ func NewDeployment(p DeploymentParameters) *appsv1.Deployment { if p.Labels == nil { p.Labels = make(map[string]string) } - p.Labels["name"] = p.Name - p.Labels["kind"] = p.Role return &appsv1.Deployment{ ObjectMeta: metav1.ObjectMeta{ Name: p.Name,