Skip to content

Commit

Permalink
Use a single volumesToVolumeMounts method
Browse files Browse the repository at this point in the history
Using single method to handle volumeMount object creation under
specific directories

Signed-off-by: Pradipta Banerjee <[email protected]>
  • Loading branch information
bpradipt committed Mar 6, 2024
1 parent 66fd3fd commit f49b6ab
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
9 changes: 9 additions & 0 deletions controllers/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ const (

// Default KBS Resources Path
kbsResourcesPath = "/opt/confidential-containers/kbs/repository/default"

// Default KBS config path
kbsDefaultConfigPath = "/etc"

// Default AS config path
asDefaultConfigPath = "/etc"

// Default RVPS config path
rvpsDefaultConfigPath = "/etc"
)

func contains(list []string, s string) bool {
Expand Down
22 changes: 5 additions & 17 deletions controllers/kbsconfig_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,15 +323,15 @@ func (r *KbsConfigReconciler) buildKbsVolumeMounts(ctx context.Context, volumes
return nil, nil, err
}
// All the above kbsVolumes gets mounted under "/etc" directory
volumeMounts := volumesToVolumeMounts(kbsEtcVolumes)
volumeMounts := volumesToVolumeMounts(kbsEtcVolumes, kbsDefaultConfigPath)
volumes = append(volumes, kbsEtcVolumes...)

kbsSecretResourceVolumes, err = r.processKbsSecretResources(ctx, kbsSecretResourceVolumes)
if err != nil {
return nil, nil, err
}
// Add the kbsSecretResourceVolumes to the volumesMounts
volumeMounts = append(volumeMounts, volumesToVolumeMountsCustom(kbsSecretResourceVolumes, kbsResourcesPath)...)
volumeMounts = append(volumeMounts, volumesToVolumeMounts(kbsSecretResourceVolumes, kbsResourcesPath)...)
volumes = append(volumes, kbsSecretResourceVolumes...)

return volumes, volumeMounts, nil
Expand All @@ -343,7 +343,7 @@ func (r *KbsConfigReconciler) buildAsVolumesMounts(ctx context.Context, volumes
if err != nil {
return nil, nil, err
}
volumeMounts := volumesToVolumeMounts(asVolumes)
volumeMounts := volumesToVolumeMounts(asVolumes, asDefaultConfigPath)
volumes = append(volumes, asVolumes...)
return volumes, volumeMounts, nil
}
Expand All @@ -354,25 +354,13 @@ func (r *KbsConfigReconciler) buildRvpsVolumesMounts(ctx context.Context, volume
if err != nil {
return nil, nil, err
}
volumeMounts := volumesToVolumeMounts(rvpsVolumes)
volumeMounts := volumesToVolumeMounts(rvpsVolumes, rvpsDefaultConfigPath)
volumes = append(volumes, rvpsVolumes...)
return volumes, volumeMounts, nil
}

// Method to add volumeMounts for KBS under "/etc" directory
func volumesToVolumeMounts(volumes []corev1.Volume) []corev1.VolumeMount {
volumeMounts := []corev1.VolumeMount{}
for _, volume := range volumes {
volumeMounts = append(volumeMounts, corev1.VolumeMount{
Name: volume.Name,
MountPath: "/etc/" + volume.Name,
})
}
return volumeMounts
}

// Method to add volumeMounts for KBS under custom directory
func volumesToVolumeMountsCustom(volumes []corev1.Volume, mountPath string) []corev1.VolumeMount {
func volumesToVolumeMounts(volumes []corev1.Volume, mountPath string) []corev1.VolumeMount {
volumeMounts := []corev1.VolumeMount{}
for _, volume := range volumes {
// Create MountPath ensuring file path separators are handled correctly
Expand Down

0 comments on commit f49b6ab

Please sign in to comment.