Skip to content

Commit

Permalink
feat: add flag --source-dns-suffix
Browse files Browse the repository at this point in the history
Add a flag indicating the cluster DNS suffix for the source cluster.
If present, lbsvc strat should use the fully qualified DNS name for
a ClusterIP service instead of a LoadBalancer service.  This allows
transfers between bare-metal clusters where Service IPs are reachable
between clusters.
  • Loading branch information
bewing committed Oct 20, 2022
1 parent 95ce716 commit 34cb1d6
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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).

4 changes: 4 additions & 0 deletions internal/app/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const (
FlagSourceContext = "source-context"
FlagSourceNamespace = "source-namespace"
FlagSourcePath = "source-path"
FlagSourceDnsSuffix = "source-dns-suffix"

FlagDestKubeconfig = "dest-kubeconfig"
FlagDestContext = "dest-context"
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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{
Expand All @@ -161,6 +164,7 @@ func runMigration(cmd *cobra.Command, args []string) error {
HelmFileValues: helmSetFile,
Strategies: strs,
DestHostOverride: destHostOverride,
SourceDnsSuffix: srcDnsSuffix,
Logger: logger,
}

Expand Down
11 changes: 10 additions & 1 deletion internal/strategy/lbsvc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -73,14 +78,18 @@ 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{
"enabled": true,
"namespace": namespace,
"publicKey": publicKey,
"service": map[string]any{
"type": "LoadBalancer",
"type": svcType,
},
"pvcMounts": []map[string]any{
{
Expand Down
1 change: 1 addition & 0 deletions migration/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type Request struct {
Strategies []string
Logger *log.Entry
DestHostOverride string
SourceDnsSuffix string
}

type Migration struct {
Expand Down

0 comments on commit 34cb1d6

Please sign in to comment.