@@ -405,6 +405,17 @@ func (c *BackingImageDataSourceController) syncBackingImage(bids *longhorn.Backi
405
405
}
406
406
}
407
407
408
+ // Only copy the secret to spec if it is to encrypt other backing image
409
+ // because we use spec secret to check if it is encrypted.
410
+ if isEncryptionRequire (bi ) {
411
+ if bi .Spec .SourceParameters [longhorn .DataSourceTypeCloneParameterSecret ] != "" {
412
+ bi .Spec .Secret = bi .Spec .SourceParameters [longhorn .DataSourceTypeCloneParameterSecret ]
413
+ }
414
+ if bi .Spec .SourceParameters [longhorn .DataSourceTypeCloneParameterSecretNamespace ] != "" {
415
+ bi .Spec .SecretNamespace = bi .Spec .SourceParameters [longhorn .DataSourceTypeCloneParameterSecretNamespace ]
416
+ }
417
+ }
418
+
408
419
return nil
409
420
}
410
421
@@ -669,7 +680,11 @@ func (c *BackingImageDataSourceController) generateBackingImageDataSourcePodMani
669
680
"--source-type" , string (bids .Spec .SourceType ),
670
681
}
671
682
672
- if err := c .prepareRunningParameters (bids ); err != nil {
683
+ bids .Status .RunningParameters = bids .Spec .Parameters
684
+ if err := c .prepareRunningParametersForClone (bids ); err != nil {
685
+ return nil , err
686
+ }
687
+ if err := c .prepareRunningParametersForExport (bids ); err != nil {
673
688
return nil , err
674
689
}
675
690
for key , value := range bids .Status .RunningParameters {
@@ -679,6 +694,21 @@ func (c *BackingImageDataSourceController) generateBackingImageDataSourcePodMani
679
694
cmd = append (cmd , "--checksum" , bids .Spec .Checksum )
680
695
}
681
696
697
+ if bids .Spec .SourceType == longhorn .BackingImageDataSourceTypeClone && secretExists (bids ) {
698
+
699
+ credential , err := c .ds .GetEncryptionSecret (
700
+ bids .Spec .Parameters [longhorn .DataSourceTypeCloneParameterSecretNamespace ],
701
+ bids .Spec .Parameters [longhorn .DataSourceTypeCloneParameterSecret ],
702
+ )
703
+ if err != nil {
704
+ return nil , err
705
+ }
706
+
707
+ for key , value := range credential {
708
+ cmd = append (cmd , "--credential" , fmt .Sprintf ("%s=%s" , key , value ))
709
+ }
710
+ }
711
+
682
712
if bids .Spec .SourceType == longhorn .BackingImageDataSourceTypeRestore {
683
713
var credential map [string ]string
684
714
backupTarget , err := c .ds .GetBackupTargetRO (types .DefaultBackupTargetName )
@@ -745,6 +775,14 @@ func (c *BackingImageDataSourceController) generateBackingImageDataSourcePodMani
745
775
Name : "disk-path" ,
746
776
MountPath : bimtypes .DiskPathInContainer ,
747
777
},
778
+ {
779
+ Name : "host-dev" ,
780
+ MountPath : "/dev" ,
781
+ },
782
+ {
783
+ Name : "host-proc" ,
784
+ MountPath : "/host/proc" , // we use this to enter the host namespace
785
+ },
748
786
},
749
787
Env : []corev1.EnvVar {
750
788
{
@@ -770,6 +808,22 @@ func (c *BackingImageDataSourceController) generateBackingImageDataSourcePodMani
770
808
},
771
809
},
772
810
},
811
+ {
812
+ Name : "host-dev" ,
813
+ VolumeSource : corev1.VolumeSource {
814
+ HostPath : & corev1.HostPathVolumeSource {
815
+ Path : "/dev" ,
816
+ },
817
+ },
818
+ },
819
+ {
820
+ Name : "host-proc" ,
821
+ VolumeSource : corev1.VolumeSource {
822
+ HostPath : & corev1.HostPathVolumeSource {
823
+ Path : "/proc" ,
824
+ },
825
+ },
826
+ },
773
827
},
774
828
NodeName : bids .Spec .NodeID ,
775
829
RestartPolicy : corev1 .RestartPolicyNever ,
@@ -802,8 +856,21 @@ func (c *BackingImageDataSourceController) generateBackingImageDataSourcePodMani
802
856
return podSpec , nil
803
857
}
804
858
805
- func (c * BackingImageDataSourceController ) prepareRunningParameters (bids * longhorn.BackingImageDataSource ) error {
806
- bids .Status .RunningParameters = bids .Spec .Parameters
859
+ func (c * BackingImageDataSourceController ) prepareRunningParametersForClone (bids * longhorn.BackingImageDataSource ) error {
860
+ if bids .Spec .SourceType != longhorn .BackingImageDataSourceTypeClone {
861
+ return nil
862
+ }
863
+
864
+ sourceBackingImageName := bids .Spec .Parameters [longhorn .DataSourceTypeCloneParameterBackingImage ]
865
+ sourceBackingImage , err := c .ds .GetBackingImageRO (sourceBackingImageName )
866
+ if err != nil {
867
+ return err
868
+ }
869
+ bids .Status .RunningParameters [longhorn .DataSourceTypeCloneParameterBackingImageUUID ] = sourceBackingImage .Status .UUID
870
+ return nil
871
+ }
872
+
873
+ func (c * BackingImageDataSourceController ) prepareRunningParametersForExport (bids * longhorn.BackingImageDataSource ) error {
807
874
if bids .Spec .SourceType != longhorn .BackingImageDataSourceTypeExportFromVolume {
808
875
return nil
809
876
}
@@ -1173,3 +1240,13 @@ func (m *BackingImageDataSourceMonitor) sync() {
1173
1240
func (c * BackingImageDataSourceController ) isResponsibleFor (bids * longhorn.BackingImageDataSource ) bool {
1174
1241
return isControllerResponsibleFor (c .controllerID , c .ds , bids .Name , bids .Spec .NodeID , bids .Status .OwnerID )
1175
1242
}
1243
+
1244
+ func isEncryptionRequire (bi * longhorn.BackingImage ) bool {
1245
+ encryptionType := bimtypes .EncryptionType (bi .Spec .SourceParameters [longhorn .DataSourceTypeCloneParameterEncryption ])
1246
+ return bi .Spec .SourceType == longhorn .BackingImageDataSourceTypeClone && encryptionType == bimtypes .EncryptionTypeEncrypt
1247
+ }
1248
+
1249
+ func secretExists (bids * longhorn.BackingImageDataSource ) bool {
1250
+ return bids .Spec .Parameters [longhorn .DataSourceTypeCloneParameterSecretNamespace ] != "" &&
1251
+ bids .Spec .Parameters [longhorn .DataSourceTypeCloneParameterSecret ] != ""
1252
+ }
0 commit comments