From 4ad9c2485ad2150b79a2ed590fe7297ab6f5c38f Mon Sep 17 00:00:00 2001 From: Lyndon-Li Date: Wed, 18 Dec 2024 10:32:52 +0800 Subject: [PATCH] hybrid deploy Signed-off-by: Lyndon-Li --- pkg/exposer/csi_snapshot_test.go | 2 +- pkg/exposer/generic_restore_test.go | 2 +- pkg/nodeagent/node_agent.go | 7 +++++-- pkg/nodeagent/node_agent_test.go | 8 ++++---- pkg/podvolume/backupper_test.go | 2 +- 5 files changed, 12 insertions(+), 9 deletions(-) diff --git a/pkg/exposer/csi_snapshot_test.go b/pkg/exposer/csi_snapshot_test.go index 77d7926356..9f2865f07c 100644 --- a/pkg/exposer/csi_snapshot_test.go +++ b/pkg/exposer/csi_snapshot_test.go @@ -1146,7 +1146,7 @@ func Test_csiSnapshotExposer_DiagnoseExpose(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Namespace: velerov1.DefaultNamespace, Name: "node-agent-pod-1", - Labels: map[string]string{"name": "node-agent"}, + Labels: map[string]string{"role": "node-agent"}, }, Spec: corev1.PodSpec{ NodeName: "fake-node", diff --git a/pkg/exposer/generic_restore_test.go b/pkg/exposer/generic_restore_test.go index 2eec0ce182..d2d56ece73 100644 --- a/pkg/exposer/generic_restore_test.go +++ b/pkg/exposer/generic_restore_test.go @@ -627,7 +627,7 @@ func Test_ReastoreDiagnoseExpose(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Namespace: velerov1.DefaultNamespace, Name: "node-agent-pod-1", - Labels: map[string]string{"name": "node-agent"}, + Labels: map[string]string{"role": "node-agent"}, }, Spec: corev1.PodSpec{ NodeName: "fake-node", diff --git a/pkg/nodeagent/node_agent.go b/pkg/nodeagent/node_agent.go index a57379f37f..898ea1e018 100644 --- a/pkg/nodeagent/node_agent.go +++ b/pkg/nodeagent/node_agent.go @@ -35,6 +35,9 @@ import ( const ( // daemonSet is the name of the Velero node agent daemonset. daemonSet = "node-agent" + + // nodeAgentRole marks pods with node-agent role on all nodes. + nodeAgentRole = "node-agent" ) var ( @@ -116,7 +119,7 @@ func isRunningInNode(ctx context.Context, namespace string, nodeName string, crC } pods := new(v1.PodList) - parsedSelector, err := labels.Parse(fmt.Sprintf("name=%s", daemonSet)) + parsedSelector, err := labels.Parse(fmt.Sprintf("role=%s", nodeAgentRole)) if err != nil { return errors.Wrap(err, "fail to parse selector") } @@ -128,7 +131,7 @@ func isRunningInNode(ctx context.Context, namespace string, nodeName string, crC } if err != nil { - return errors.Wrap(err, "failed to list daemonset pods") + return errors.Wrap(err, "failed to list node-agent pods") } for i := range pods.Items { diff --git a/pkg/nodeagent/node_agent_test.go b/pkg/nodeagent/node_agent_test.go index 1c24427b1f..700acdec8f 100644 --- a/pkg/nodeagent/node_agent_test.go +++ b/pkg/nodeagent/node_agent_test.go @@ -108,11 +108,11 @@ func TestIsRunningInNode(t *testing.T) { corev1.AddToScheme(scheme) nonNodeAgentPod := builder.ForPod("fake-ns", "fake-pod").Result() - nodeAgentPodNotRunning := builder.ForPod("fake-ns", "fake-pod").Labels(map[string]string{"name": "node-agent"}).Result() - nodeAgentPodRunning1 := builder.ForPod("fake-ns", "fake-pod-1").Labels(map[string]string{"name": "node-agent"}).Phase(corev1.PodRunning).Result() - nodeAgentPodRunning2 := builder.ForPod("fake-ns", "fake-pod-2").Labels(map[string]string{"name": "node-agent"}).Phase(corev1.PodRunning).Result() + nodeAgentPodNotRunning := builder.ForPod("fake-ns", "fake-pod").Labels(map[string]string{"role": "node-agent"}).Result() + nodeAgentPodRunning1 := builder.ForPod("fake-ns", "fake-pod-1").Labels(map[string]string{"role": "node-agent"}).Phase(corev1.PodRunning).Result() + nodeAgentPodRunning2 := builder.ForPod("fake-ns", "fake-pod-2").Labels(map[string]string{"role": "node-agent"}).Phase(corev1.PodRunning).Result() nodeAgentPodRunning3 := builder.ForPod("fake-ns", "fake-pod-3"). - Labels(map[string]string{"name": "node-agent"}). + Labels(map[string]string{"role": "node-agent"}). Phase(corev1.PodRunning). NodeName("fake-node"). Result() diff --git a/pkg/podvolume/backupper_test.go b/pkg/podvolume/backupper_test.go index fe50f9e30e..c21ad5ebb9 100644 --- a/pkg/podvolume/backupper_test.go +++ b/pkg/podvolume/backupper_test.go @@ -260,7 +260,7 @@ func createPodObj(running bool, withVolume bool, withVolumeMounted bool, volumeN func createNodeAgentPodObj(running bool) *corev1api.Pod { podObj := builder.ForPod(velerov1api.DefaultNamespace, "fake-node-agent").Result() - podObj.Labels = map[string]string{"name": "node-agent"} + podObj.Labels = map[string]string{"role": "node-agent"} if running { podObj.Status.Phase = corev1api.PodRunning