diff --git a/USAGE.md b/USAGE.md index 45f3a478f8..e9797c6e9e 100644 --- a/USAGE.md +++ b/USAGE.md @@ -47,6 +47,7 @@ Flags: -o, --no-chown omit chown on rsync -b, --no-progress-bar do not display a progress bar -c, --source-context string context in the kubeconfig file of the source PVC + -S --source-dns-suffix dns suffix for destination cluster (for inter-cluster services) -k, --source-kubeconfig string path of the kubeconfig file of the source PVC -R, --source-mount-read-only mount the source PVC in ReadOnly mode (default true) -n, --source-namespace string namespace of the source PVC @@ -132,4 +133,3 @@ $ pv-migrate migrate \ **For further customization on the rendered manifests** (custom labels, annotations etc.), see the [Helm chart values](helm/pv-migrate). - diff --git a/internal/app/migrate.go b/internal/app/migrate.go index 629ffbcf04..34e1738a6e 100644 --- a/internal/app/migrate.go +++ b/internal/app/migrate.go @@ -21,6 +21,7 @@ const ( FlagSourceContext = "source-context" FlagSourceNamespace = "source-namespace" FlagSourcePath = "source-path" + FlagSourceDnsSuffix = "source-dns-suffix" FlagDestKubeconfig = "dest-kubeconfig" FlagDestContext = "dest-context" @@ -93,6 +94,7 @@ func setMigrateCmdFlags(cmd *cobra.Command) { flags.StringP(FlagSourceContext, "c", "", "context in the kubeconfig file of the source PVC") flags.StringP(FlagSourceNamespace, "n", "", "namespace of the source PVC") flags.StringP(FlagSourcePath, "p", "/", "the filesystem path to migrate in the source PVC") + flags.StringP(FlagSourceDnsSuffix, "S", "", "dns suffix for source cluster (for inter-cluster services)") flags.StringP(FlagDestKubeconfig, "K", "", "path of the kubeconfig file of the destination PVC") flags.StringP(FlagDestContext, "C", "", "context in the kubeconfig file of the destination PVC") @@ -143,6 +145,7 @@ func runMigration(cmd *cobra.Command, args []string) error { helmSetFile, _ := flags.GetStringSlice(FlagHelmSetFile) strs, _ := flags.GetStringSlice(FlagStrategies) destHostOverride, _ := flags.GetString(FlagDestHostOverride) + srcDnsSuffix, _ := flags.GetString(FlagSourceDnsSuffix) deleteExtraneousFiles, _ := flags.GetBool(FlagDestDeleteExtraneousFiles) request := migration.Request{ @@ -161,6 +164,7 @@ func runMigration(cmd *cobra.Command, args []string) error { HelmFileValues: helmSetFile, Strategies: strs, DestHostOverride: destHostOverride, + SourceDnsSuffix: srcDnsSuffix, Logger: logger, } diff --git a/internal/strategy/lbsvc.go b/internal/strategy/lbsvc.go index e73f24879f..5ae6a2fae2 100644 --- a/internal/strategy/lbsvc.go +++ b/internal/strategy/lbsvc.go @@ -51,6 +51,11 @@ func (r *LbSvc) Run(attempt *migration.Attempt) (bool, error) { } sshTargetHost := formatSSHTargetHost(lbSvcAddress) + + if mig.Request.SourceDnsSuffix != "" { + sshTargetHost = fmt.Sprintf("%s.%s", lbSvcAddress, mig.Request.SourceDnsSuffix) + } + if mig.Request.DestHostOverride != "" { sshTargetHost = mig.Request.DestHostOverride } @@ -73,6 +78,10 @@ func installOnSource(attempt *migration.Attempt, releaseName, publicKey, srcMoun mig := attempt.Migration sourceInfo := mig.SourceInfo namespace := sourceInfo.Claim.Namespace + svcType := "LoadBalancer" + if attempt.Migration.Request.SourceDnsSuffix != "" { + svcType = "ClusterIP" + } vals := map[string]any{ "sshd": map[string]any{ @@ -80,7 +89,7 @@ func installOnSource(attempt *migration.Attempt, releaseName, publicKey, srcMoun "namespace": namespace, "publicKey": publicKey, "service": map[string]any{ - "type": "LoadBalancer", + "type": svcType, }, "pvcMounts": []map[string]any{ { diff --git a/migration/types.go b/migration/types.go index 21555c00b5..8bc9418daf 100644 --- a/migration/types.go +++ b/migration/types.go @@ -34,6 +34,7 @@ type Request struct { Strategies []string Logger *log.Entry DestHostOverride string + SourceDnsSuffix string } type Migration struct {