@@ -833,7 +833,7 @@ func makeNginxPod(ns string, nodeSelector map[string]string, pvclaims []*v1.Pers
833
833
// MakeSecPod returns a pod definition based on the namespace. The pod references the PVC's
834
834
// name. A slice of BASH commands can be supplied as args to be run by the pod.
835
835
// SELinux testing requires to pass HostIPC and HostPID as booleansi arguments.
836
- func MakeSecPod (ns string , pvclaims []* v1.PersistentVolumeClaim , isPrivileged bool , command string , hostIPC bool , hostPID bool , seLinuxLabel * v1.SELinuxOptions , fsGroup * int64 ) * v1.Pod {
836
+ func MakeSecPod (ns string , pvclaims []* v1.PersistentVolumeClaim , inlineVolumeSources [] * v1. VolumeSource , isPrivileged bool , command string , hostIPC bool , hostPID bool , seLinuxLabel * v1.SELinuxOptions , fsGroup * int64 ) * v1.Pod {
837
837
if len (command ) == 0 {
838
838
command = "trap exit TERM; while true; do sleep 1; done"
839
839
}
@@ -874,17 +874,27 @@ func MakeSecPod(ns string, pvclaims []*v1.PersistentVolumeClaim, isPrivileged bo
874
874
}
875
875
var volumeMounts = make ([]v1.VolumeMount , 0 )
876
876
var volumeDevices = make ([]v1.VolumeDevice , 0 )
877
- var volumes = make ([]v1.Volume , len (pvclaims ))
878
- for index , pvclaim := range pvclaims {
879
- volumename := fmt .Sprintf ("volume%v" , index + 1 )
877
+ var volumes = make ([]v1.Volume , len (pvclaims )+ len (inlineVolumeSources ))
878
+ volumeIndex := 0
879
+ for _ , pvclaim := range pvclaims {
880
+ volumename := fmt .Sprintf ("volume%v" , volumeIndex + 1 )
880
881
if pvclaim .Spec .VolumeMode != nil && * pvclaim .Spec .VolumeMode == v1 .PersistentVolumeBlock {
881
882
volumeDevices = append (volumeDevices , v1.VolumeDevice {Name : volumename , DevicePath : "/mnt/" + volumename })
882
883
} else {
883
884
volumeMounts = append (volumeMounts , v1.VolumeMount {Name : volumename , MountPath : "/mnt/" + volumename })
884
885
}
885
886
886
- volumes [index ] = v1.Volume {Name : volumename , VolumeSource : v1.VolumeSource {PersistentVolumeClaim : & v1.PersistentVolumeClaimVolumeSource {ClaimName : pvclaim .Name , ReadOnly : false }}}
887
+ volumes [volumeIndex ] = v1.Volume {Name : volumename , VolumeSource : v1.VolumeSource {PersistentVolumeClaim : & v1.PersistentVolumeClaimVolumeSource {ClaimName : pvclaim .Name , ReadOnly : false }}}
888
+ volumeIndex ++
889
+ }
890
+ for _ , src := range inlineVolumeSources {
891
+ volumename := fmt .Sprintf ("volume%v" , volumeIndex + 1 )
892
+ // In-line volumes can be only filesystem, not block.
893
+ volumeMounts = append (volumeMounts , v1.VolumeMount {Name : volumename , MountPath : "/mnt/" + volumename })
894
+ volumes [volumeIndex ] = v1.Volume {Name : volumename , VolumeSource : * src }
895
+ volumeIndex ++
887
896
}
897
+
888
898
podSpec .Spec .Containers [0 ].VolumeMounts = volumeMounts
889
899
podSpec .Spec .Containers [0 ].VolumeDevices = volumeDevices
890
900
podSpec .Spec .Volumes = volumes
@@ -933,13 +943,13 @@ func CreateNginxPod(client clientset.Interface, namespace string, nodeSelector m
933
943
}
934
944
935
945
// CreateSecPod creates security pod with given claims
936
- func CreateSecPod (client clientset.Interface , namespace string , pvclaims []* v1.PersistentVolumeClaim , isPrivileged bool , command string , hostIPC bool , hostPID bool , seLinuxLabel * v1.SELinuxOptions , fsGroup * int64 , timeout time.Duration ) (* v1.Pod , error ) {
937
- return CreateSecPodWithNodeSelection (client , namespace , pvclaims , isPrivileged , command , hostIPC , hostPID , seLinuxLabel , fsGroup , NodeSelection {}, timeout )
946
+ func CreateSecPod (client clientset.Interface , namespace string , pvclaims []* v1.PersistentVolumeClaim , inlineVolumeSources [] * v1. VolumeSource , isPrivileged bool , command string , hostIPC bool , hostPID bool , seLinuxLabel * v1.SELinuxOptions , fsGroup * int64 , timeout time.Duration ) (* v1.Pod , error ) {
947
+ return CreateSecPodWithNodeSelection (client , namespace , pvclaims , inlineVolumeSources , isPrivileged , command , hostIPC , hostPID , seLinuxLabel , fsGroup , NodeSelection {}, timeout )
938
948
}
939
949
940
950
// CreateSecPodWithNodeSelection creates security pod with given claims
941
- func CreateSecPodWithNodeSelection (client clientset.Interface , namespace string , pvclaims []* v1.PersistentVolumeClaim , isPrivileged bool , command string , hostIPC bool , hostPID bool , seLinuxLabel * v1.SELinuxOptions , fsGroup * int64 , node NodeSelection , timeout time.Duration ) (* v1.Pod , error ) {
942
- pod := MakeSecPod (namespace , pvclaims , isPrivileged , command , hostIPC , hostPID , seLinuxLabel , fsGroup )
951
+ func CreateSecPodWithNodeSelection (client clientset.Interface , namespace string , pvclaims []* v1.PersistentVolumeClaim , inlineVolumeSources [] * v1. VolumeSource , isPrivileged bool , command string , hostIPC bool , hostPID bool , seLinuxLabel * v1.SELinuxOptions , fsGroup * int64 , node NodeSelection , timeout time.Duration ) (* v1.Pod , error ) {
952
+ pod := MakeSecPod (namespace , pvclaims , inlineVolumeSources , isPrivileged , command , hostIPC , hostPID , seLinuxLabel , fsGroup )
943
953
// Setting node
944
954
pod .Spec .NodeName = node .Name
945
955
pod .Spec .NodeSelector = node .Selector
0 commit comments