diff --git a/internal/pvc/info.go b/internal/pvc/info.go index 5b450aee564466c2e7c4556aa98c3e73768dcef1..e7b0c81b6b758fc8cc2b29e7ad202ed22b43dce8 100644 --- a/internal/pvc/info.go +++ b/internal/pvc/info.go @@ -10,12 +10,13 @@ import ( ) type Info struct { - ClusterClient *k8s.ClusterClient - Claim *corev1.PersistentVolumeClaim - MountedNode string - SupportsRWO bool - SupportsROX bool - SupportsRWX bool + ClusterClient *k8s.ClusterClient + Claim *corev1.PersistentVolumeClaim + MountedNode string + AffinityHelmValues map[string]any + SupportsRWO bool + SupportsROX bool + SupportsRWX bool } func New(client *k8s.ClusterClient, namespace string, name string) (*Info, error) { @@ -32,6 +33,8 @@ func New(client *k8s.ClusterClient, namespace string, name string) (*Info, error return nil, err } + affinityHelmValues := buildAffinityHelmValues(mountedNode) + supportsRWO := false supportsROX := false supportsRWX := false @@ -50,12 +53,13 @@ func New(client *k8s.ClusterClient, namespace string, name string) (*Info, error } return &Info{ - ClusterClient: client, - Claim: claim, - MountedNode: mountedNode, - SupportsRWO: supportsRWO, - SupportsROX: supportsROX, - SupportsRWX: supportsRWX, + ClusterClient: client, + Claim: claim, + MountedNode: mountedNode, + AffinityHelmValues: affinityHelmValues, + SupportsRWO: supportsRWO, + SupportsROX: supportsROX, + SupportsRWX: supportsRWX, }, nil } @@ -76,3 +80,28 @@ func findMountedNode(kubeClient kubernetes.Interface, pvc *corev1.PersistentVolu return "", nil } + +func buildAffinityHelmValues(nodeName string) map[string]any { + if nodeName == "" { + return nil + } + + return map[string]any{ + "nodeAffinity": map[string]any{ + "preferredDuringSchedulingIgnoredDuringExecution": []map[string]any{ + { + "weight": 1, + "preference": map[string]any{ + "matchFields": []map[string]any{ + { + "key": "metadata.name", + "operator": "In", + "values": []string{nodeName}, + }, + }, + }, + }, + }, + }, + } +} diff --git a/internal/strategy/lbsvc.go b/internal/strategy/lbsvc.go index 7de5b2633c025ba0ef61d428e186384e204490cd..e73f24879fd43fa6ebf68c8b014c94976d08cd44 100644 --- a/internal/strategy/lbsvc.go +++ b/internal/strategy/lbsvc.go @@ -89,6 +89,7 @@ func installOnSource(attempt *migration.Attempt, releaseName, publicKey, srcMoun "mountPath": srcMountPath, }, }, + "affinity": sourceInfo.AffinityHelmValues, }, } @@ -132,7 +133,8 @@ func installOnDest(attempt *migration.Attempt, releaseName, privateKey, "mountPath": destMountPath, }, }, - "command": rsyncCmdStr, + "command": rsyncCmdStr, + "affinity": destInfo.AffinityHelmValues, }, } diff --git a/internal/strategy/local.go b/internal/strategy/local.go index cb754c66f011269f29ce93752cc5baffe72ba53b..5c1b222e1cc1e704569cdc6ff7a675206b695bd3 100644 --- a/internal/strategy/local.go +++ b/internal/strategy/local.go @@ -197,6 +197,7 @@ func installLocalOnSource(attempt *migration.Attempt, releaseName, "mountPath": srcMountPath, }, }, + "affinity": sourceInfo.AffinityHelmValues, }, } @@ -219,6 +220,7 @@ func installLocalOnDest(attempt *migration.Attempt, releaseName, publicKey, dest "mountPath": destMountPath, }, }, + "affinity": destInfo.AffinityHelmValues, }, } diff --git a/internal/strategy/mnt2.go b/internal/strategy/mnt2.go index 34500b6ed80a78048b2a7e23a3b898a96191bdaa..1031ccf4b68cdf0fb9f66961ec71b07c97f23003 100644 --- a/internal/strategy/mnt2.go +++ b/internal/strategy/mnt2.go @@ -60,7 +60,8 @@ func (r *Mnt2) Run(attempt *migration.Attempt) (bool, error) { "mountPath": destMountPath, }, }, - "command": rsyncCmd, + "command": rsyncCmd, + "affinity": sourceInfo.AffinityHelmValues, }, } diff --git a/internal/strategy/svc.go b/internal/strategy/svc.go index 46cd8769fee45d5fea304153e2f12d11f22e0239..74ce6587942d6471530396dad265ca197a7964b6 100644 --- a/internal/strategy/svc.go +++ b/internal/strategy/svc.go @@ -98,7 +98,8 @@ func buildHelmVals(mig *migration.Migration, helmReleaseName string) (map[string "mountPath": destMountPath, }, }, - "command": rsyncCmdStr, + "command": rsyncCmdStr, + "affinity": destInfo.AffinityHelmValues, }, "sshd": map[string]any{ "enabled": true, @@ -111,6 +112,7 @@ func buildHelmVals(mig *migration.Migration, helmReleaseName string) (map[string "readOnly": mig.Request.SourceMountReadOnly, }, }, + "affinity": sourceInfo.AffinityHelmValues, }, }, nil }