From a5a6e47e4253e2d34b8112fa403829420b740099 Mon Sep 17 00:00:00 2001 From: Lyndon-Li Date: Tue, 17 Dec 2024 13:27:51 +0800 Subject: [PATCH] add use-node-agent-windows Signed-off-by: Lyndon-Li --- pkg/cmd/cli/install/install.go | 5 ++++- pkg/install/resources.go | 21 +++++++++++++-------- pkg/install/resources_test.go | 19 +++++++++++-------- 3 files changed, 28 insertions(+), 17 deletions(-) diff --git a/pkg/cmd/cli/install/install.go b/pkg/cmd/cli/install/install.go index a72ac59724..320de41596 100644 --- a/pkg/cmd/cli/install/install.go +++ b/pkg/cmd/cli/install/install.go @@ -66,6 +66,7 @@ type Options struct { BackupStorageConfig flag.Map VolumeSnapshotConfig flag.Map UseNodeAgent bool + UseNodeAgentWindows bool PrivilegedNodeAgent bool //TODO remove UseRestic when migration test out of using it UseRestic bool @@ -119,7 +120,8 @@ func (o *Options) BindFlags(flags *pflag.FlagSet) { flags.BoolVar(&o.UseVolumeSnapshots, "use-volume-snapshots", o.UseVolumeSnapshots, "Whether or not to create snapshot location automatically. Set to false if you do not plan to create volume snapshots via a storage provider.") flags.BoolVar(&o.RestoreOnly, "restore-only", o.RestoreOnly, "Run the server in restore-only mode. Optional.") flags.BoolVar(&o.DryRun, "dry-run", o.DryRun, "Generate resources, but don't send them to the cluster. Use with -o. Optional.") - flags.BoolVar(&o.UseNodeAgent, "use-node-agent", o.UseNodeAgent, "Create Velero node-agent daemonset. Optional. Velero node-agent hosts Velero modules that need to run in one or more nodes(i.e. Restic, Kopia).") + flags.BoolVar(&o.UseNodeAgent, "use-node-agent", o.UseNodeAgent, "Create Velero node-agent daemonset. Optional. Velero node-agent hosts Velero modules that need to run in one or more Linux nodes(i.e. Restic, Kopia).") + flags.BoolVar(&o.UseNodeAgentWindows, "use-node-agent-windows", o.UseNodeAgentWindows, "Create Velero node-agent-windows daemonset. Optional. Velero node-agent-windows hosts Velero modules that need to run in one or more Windows nodes(i.e. Restic, Kopia).") flags.BoolVar(&o.PrivilegedNodeAgent, "privileged-node-agent", o.PrivilegedNodeAgent, "Use privileged mode for the node agent. Optional. Required to backup block devices.") flags.BoolVar(&o.Wait, "wait", o.Wait, "Wait for Velero deployment to be ready. Optional.") flags.DurationVar(&o.DefaultRepoMaintenanceFrequency, "default-repo-maintain-frequency", o.DefaultRepoMaintenanceFrequency, "How often 'maintain' is run for backup repositories by default. Optional.") @@ -269,6 +271,7 @@ func (o *Options) AsVeleroOptions() (*install.VeleroOptions, error) { SecretData: secretData, RestoreOnly: o.RestoreOnly, UseNodeAgent: o.UseNodeAgent, + UseNodeAgentWindows: o.UseNodeAgentWindows, PrivilegedNodeAgent: o.PrivilegedNodeAgent, UseVolumeSnapshots: o.UseVolumeSnapshots, BSLConfig: o.BackupStorageConfig.Data(), diff --git a/pkg/install/resources.go b/pkg/install/resources.go index 824e3e92c9..6560d2e153 100644 --- a/pkg/install/resources.go +++ b/pkg/install/resources.go @@ -246,6 +246,7 @@ type VeleroOptions struct { SecretData []byte RestoreOnly bool UseNodeAgent bool + UseNodeAgentWindows bool PrivilegedNodeAgent bool UseVolumeSnapshots bool BSLConfig map[string]string @@ -395,7 +396,7 @@ func AllResources(o *VeleroOptions) *unstructured.UnstructuredList { fmt.Printf("error appending Deployment %s: %s\n", deploy.GetName(), err.Error()) } - if o.UseNodeAgent { + if o.UseNodeAgent || o.UseNodeAgentWindows { dsOpts := []podTemplateOption{ WithAnnotations(o.PodAnnotations), WithLabels(o.PodLabels), @@ -414,16 +415,20 @@ func AllResources(o *VeleroOptions) *unstructured.UnstructuredList { dsOpts = append(dsOpts, WithNodeAgentConfigMap(o.NodeAgentConfigMap)) } - ds := DaemonSet(o.Namespace, dsOpts...) - if err := appendUnstructured(resources, ds); err != nil { - fmt.Printf("error appending DaemonSet %s: %s\n", ds.GetName(), err.Error()) + if o.UseNodeAgent { + ds := DaemonSet(o.Namespace, dsOpts...) + if err := appendUnstructured(resources, ds); err != nil { + fmt.Printf("error appending DaemonSet %s: %s\n", ds.GetName(), err.Error()) + } } - dsOpts = append(dsOpts, WithForWindows()) + if o.UseNodeAgentWindows { + dsOpts = append(dsOpts, WithForWindows()) - dsWin := DaemonSet(o.Namespace, dsOpts...) - if err := appendUnstructured(resources, dsWin); err != nil { - fmt.Printf("error appending DaemonSet %s: %s\n", dsWin.GetName(), err.Error()) + dsWin := DaemonSet(o.Namespace, dsOpts...) + if err := appendUnstructured(resources, dsWin); err != nil { + fmt.Printf("error appending DaemonSet %s: %s\n", dsWin.GetName(), err.Error()) + } } } diff --git a/pkg/install/resources_test.go b/pkg/install/resources_test.go index 58bbac58ca..5708e531f8 100644 --- a/pkg/install/resources_test.go +++ b/pkg/install/resources_test.go @@ -77,21 +77,22 @@ func TestAllCRDs(t *testing.T) { func TestAllResources(t *testing.T) { option := &VeleroOptions{ - Namespace: "velero", - SecretData: []byte{'a'}, - UseVolumeSnapshots: true, - UseNodeAgent: true, + Namespace: "velero", + SecretData: []byte{'a'}, + UseVolumeSnapshots: true, + UseNodeAgent: true, + UseNodeAgentWindows: true, } list := AllResources(option) - objects := map[string]unstructured.Unstructured{} + objects := map[string][]unstructured.Unstructured{} for _, item := range list.Items { - objects[item.GetKind()] = item + objects[item.GetKind()] = append(objects[item.GetKind()], item) } ns, exist := objects["Namespace"] require.True(t, exist) - assert.Equal(t, "velero", ns.GetName()) + assert.Equal(t, "velero", ns[0].GetName()) _, exist = objects["ClusterRoleBinding"] assert.True(t, exist) @@ -111,6 +112,8 @@ func TestAllResources(t *testing.T) { _, exist = objects["Deployment"] assert.True(t, exist) - _, exist = objects["DaemonSet"] + ds, exist := objects["DaemonSet"] assert.True(t, exist) + + assert.Equal(t, 2, len(ds)) }