Skip to content

Commit 786a8d5

Browse files
committed
setup build and tempsshdir for restic sftp
1 parent b2adbd3 commit 786a8d5

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

internal/controller/mover/restic/builder.go

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ func (rb *Builder) FromSource(client client.Client, logger logr.Logger,
124124
saHandler := utils.NewSAHandler(client, source, isSource, privileged,
125125
source.Spec.Restic.MoverServiceAccount)
126126

127-
return &Mover{
127+
mover := &Mover{
128128
client: client,
129129
logger: logger.WithValues("method", "Restic"),
130130
eventRecorder: eventRecorder,
@@ -136,6 +136,7 @@ func (rb *Builder) FromSource(client client.Client, logger logr.Logger,
136136
cacheCapacity: source.Spec.Restic.CacheCapacity,
137137
cacheStorageClassName: source.Spec.Restic.CacheStorageClassName,
138138
repositoryName: source.Spec.Restic.Repository,
139+
sshKeys: source.Spec.Restic.SSHKeys,
139140
isSource: isSource,
140141
paused: source.Spec.Paused,
141142
mainPVCName: &source.Spec.SourcePVC,
@@ -147,7 +148,13 @@ func (rb *Builder) FromSource(client client.Client, logger logr.Logger,
147148
sourceStatus: source.Status.Restic,
148149
latestMoverStatus: source.Status.LatestMoverStatus,
149150
moverConfig: source.Spec.Restic.MoverConfig,
150-
}, nil
151+
}
152+
153+
if source.Spec.Restic.SSHKeys != nil {
154+
mover.moverConfig.MoverSecurityContext = nil
155+
}
156+
157+
return mover, nil
151158
}
152159

153160
func (rb *Builder) FromDestination(client client.Client, logger logr.Logger,
@@ -177,7 +184,7 @@ func (rb *Builder) FromDestination(client client.Client, logger logr.Logger,
177184
saHandler := utils.NewSAHandler(client, destination, isSource, privileged,
178185
destination.Spec.Restic.MoverServiceAccount)
179186

180-
return &Mover{
187+
mover := &Mover{
181188
client: client,
182189
logger: logger.WithValues("method", "Restic"),
183190
eventRecorder: eventRecorder,
@@ -190,6 +197,7 @@ func (rb *Builder) FromDestination(client client.Client, logger logr.Logger,
190197
cacheStorageClassName: destination.Spec.Restic.CacheStorageClassName,
191198
cleanupCachePVC: destination.Spec.Restic.CleanupCachePVC,
192199
repositoryName: destination.Spec.Restic.Repository,
200+
sshKeys: destination.Spec.Restic.SSHKeys,
193201
isSource: isSource,
194202
paused: destination.Spec.Paused,
195203
mainPVCName: destination.Spec.Restic.DestinationPVC,
@@ -201,5 +209,11 @@ func (rb *Builder) FromDestination(client client.Client, logger logr.Logger,
201209
enableFileDeletionOnRestore: destination.Spec.Restic.EnableFileDeletion,
202210
latestMoverStatus: destination.Status.LatestMoverStatus,
203211
moverConfig: destination.Spec.Restic.MoverConfig,
204-
}, nil
212+
}
213+
214+
if destination.Spec.Restic.SSHKeys != nil {
215+
mover.moverConfig.MoverSecurityContext = nil
216+
}
217+
218+
return mover, nil
205219
}

internal/controller/mover/restic/mover.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,14 +518,17 @@ func (m *Mover) ensureJob(ctx context.Context, cachePVC *corev1.PersistentVolume
518518
}
519519
if resticSecretName != "" {
520520
podSpec.Containers[0].Env = append(podSpec.Containers[0].Env, corev1.EnvVar{
521-
Name: "SSH_KEYS",
521+
Name: "SSH_KEYS",
522522
Value: "true",
523523
})
524524
// Mount the custom CA certificate
525525
podSpec.Containers[0].VolumeMounts =
526526
append(podSpec.Containers[0].VolumeMounts, corev1.VolumeMount{
527527
Name: "keys",
528528
MountPath: "/keys",
529+
}, corev1.VolumeMount{
530+
Name: "tempsshdir",
531+
MountPath: "/root/.ssh",
529532
})
530533
podSpec.Volumes = append(podSpec.Volumes, corev1.Volume{
531534
Name: "keys", VolumeSource: corev1.VolumeSource{
@@ -534,6 +537,10 @@ func (m *Mover) ensureJob(ctx context.Context, cachePVC *corev1.PersistentVolume
534537
DefaultMode: ptr.To[int32](0600),
535538
},
536539
},
540+
}, corev1.Volume{Name: "tempsshdir", VolumeSource: corev1.VolumeSource{
541+
EmptyDir: &corev1.EmptyDirVolumeSource{
542+
Medium: corev1.StorageMediumMemory,
543+
}},
537544
})
538545
}
539546
if m.vh.IsCopyMethodDirect() {

mover-restic/entry.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ Host *
6262
# Enable protocol-level keepalive to detect connection failure
6363
ServerAliveCountMax 4
6464
ServerAliveInterval 30
65-
# We don't know the key of the server, so be strict
65+
# We don't know the key of the server
6666
StrictHostKeyChecking no
6767
# Using protocol-level, so we don't need TCP-level
6868
TCPKeepAlive no

0 commit comments

Comments
 (0)