77 "reflect"
88
99 "github.com/go-logr/logr"
10+ configv1 "github.com/openshift/api/config/v1"
1011 "github.com/operator-framework/operator-lib/proxy"
1112 "github.com/vmware-tanzu/velero/pkg/install"
1213 appsv1 "k8s.io/api/apps/v1"
@@ -25,14 +26,24 @@ import (
2526)
2627
2728const (
28- ResticRestoreHelperCM = "restic-restore-action-config"
29- FsRestoreHelperCM = "fs-restore-action-config"
30- HostPods = "host-pods"
31- HostPlugins = "host-plugins"
29+ ResticRestoreHelperCM = "restic-restore-action-config"
30+ FsRestoreHelperCM = "fs-restore-action-config"
31+ HostPods = "host-pods"
32+ HostPlugins = "host-plugins"
33+ Cluster = "cluster"
34+ IBMCloudPlatform = "IBMCloud"
35+ GenericPVHostPath = "/var/lib/kubelet/pods"
36+ IBMCloudPVHostPath = "/var/data/kubelet/pods"
37+ GenericPluginsHostPath = "/var/lib/kubelet/plugins"
38+ IBMCloudPluginsHostPath = "/var/data/kubelet/plugins"
39+ ResticPVHostPathEnvVar = "RESTIC_PV_HOSTPATH"
40+ FSPVHostPathEnvVar = "FS_PV_HOSTPATH"
41+ PluginsHostPathEnvVar = "PLUGINS_HOSTPATH"
3242)
3343
3444var (
35- fsPvHostPath string = getFsPvHostPath ()
45+ fsPvHostPath = getFsPvHostPath ("" )
46+ pluginsHostPath = getPluginsHostPath ("" )
3647
3748 // v1.MountPropagationHostToContainer is a const. Const cannot be pointed to.
3849 // we need to declare mountPropagationToHostContainer so that we have an address to point to
@@ -47,19 +58,40 @@ var (
4758 }
4859)
4960
50- func getFsPvHostPath () string {
51- env := os .Getenv ("RESTIC_PV_HOSTPATH" )
52- envFs := os .Getenv ("FS_PV_HOSTPATH" )
61+ // getFsPvHostPath returns the host path for persistent volumes based on the platform type.
62+ func getFsPvHostPath (platformType string ) string {
63+ // Check if environment variables are set for host paths
64+ if envFs := os .Getenv (FSPVHostPathEnvVar ); envFs != "" {
65+ return envFs
66+ }
5367
54- if env != "" {
68+ if env := os . Getenv ( ResticPVHostPathEnvVar ); env != "" {
5569 return env
5670 }
5771
58- if envFs != "" {
59- return envFs
72+ // Return platform-specific host paths
73+ switch platformType {
74+ case IBMCloudPlatform :
75+ return IBMCloudPVHostPath
76+ default :
77+ return GenericPVHostPath
78+ }
79+ }
80+
81+ // getPluginsHostPath returns the host path for persistent volumes based on the platform type.
82+ func getPluginsHostPath (platformType string ) string {
83+ // Check if environment var is set for host plugins
84+ if env := os .Getenv (PluginsHostPathEnvVar ); env != "" {
85+ return env
6086 }
6187
62- return "/var/lib/kubelet/pods"
88+ // Return platform-specific host paths
89+ switch platformType {
90+ case IBMCloudPlatform :
91+ return IBMCloudPluginsHostPath
92+ default :
93+ return GenericPluginsHostPath
94+ }
6395}
6496
6597func getNodeAgentObjectMeta (r * DPAReconciler ) metav1.ObjectMeta {
@@ -281,10 +313,22 @@ func (r *DPAReconciler) customizeNodeAgentDaemonset(dpa *oadpv1alpha1.DataProtec
281313 },
282314 })
283315
316+ // check platform type
317+ platformType , err := r .getPlatformType ()
318+ if err != nil {
319+ return nil , fmt .Errorf ("error checking platform type: %s" , err )
320+ }
284321 // update nodeAgent host PV path
285322 for i , vol := range ds .Spec .Template .Spec .Volumes {
286323 if vol .Name == HostPods {
287- ds .Spec .Template .Spec .Volumes [i ].HostPath .Path = getFsPvHostPath ()
324+ ds .Spec .Template .Spec .Volumes [i ].HostPath .Path = getFsPvHostPath (platformType )
325+ }
326+ }
327+
328+ // update nodeAgent plugins host path
329+ for i , vol := range ds .Spec .Template .Spec .Volumes {
330+ if vol .Name == HostPlugins {
331+ ds .Spec .Template .Spec .Volumes [i ].HostPath .Path = getPluginsHostPath (platformType )
288332 }
289333 }
290334
@@ -310,6 +354,13 @@ func (r *DPAReconciler) customizeNodeAgentDaemonset(dpa *oadpv1alpha1.DataProtec
310354 Name : "certs" ,
311355 MountPath : "/etc/ssl/certs" ,
312356 })
357+
358+ // update nodeAgent plugins volume mount host path
359+ for v , volumeMount := range nodeAgentContainer .VolumeMounts {
360+ if volumeMount .Name == HostPlugins {
361+ nodeAgentContainer .VolumeMounts [v ].MountPath = getPluginsHostPath (platformType )
362+ }
363+ }
313364 // append PodConfig envs to nodeAgent container
314365 if useResticConf {
315366 if dpa .Spec .Configuration .Restic .PodConfig != nil && dpa .Spec .Configuration .Restic .PodConfig .Env != nil {
@@ -452,3 +503,19 @@ func (r *DPAReconciler) updateFsRestoreHelperCM(fsRestoreHelperCM *corev1.Config
452503
453504 return nil
454505}
506+
507+ // getPlatformType fetches the cluster infrastructure object and returns the platform type.
508+ func (r * DPAReconciler ) getPlatformType () (string , error ) {
509+ infra := & configv1.Infrastructure {}
510+ key := types.NamespacedName {Name : Cluster }
511+ if err := r .Get (r .Context , key , infra ); err != nil {
512+ return "" , err
513+ }
514+
515+ if platformStatus := infra .Status .PlatformStatus ; platformStatus != nil {
516+ if platformType := platformStatus .Type ; platformType != "" {
517+ return string (platformType ), nil
518+ }
519+ }
520+ return "" , nil
521+ }
0 commit comments