Skip to content

Commit b8fb9dd

Browse files
Fix OADP-4623: OpenShift on IBMCloud setup for OADP (#1482)
* Fix OADP-4623: OpenShift on IBMCLoud setup for OADP * fix unit tests and minor updates * add updates for host-plugins host path * fix unit tests * lint fix
1 parent 54fed94 commit b8fb9dd

File tree

9 files changed

+2309
-46
lines changed

9 files changed

+2309
-46
lines changed

bundle/manifests/oadp-operator.clusterserviceversion.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,8 @@ spec:
648648
- infrastructures
649649
verbs:
650650
- get
651+
- list
652+
- watch
651653
- apiGroups:
652654
- cloudcredential.openshift.io
653655
resources:
@@ -904,6 +906,9 @@ spec:
904906
valueFrom:
905907
fieldRef:
906908
fieldPath: metadata.annotations['olm.targetNamespaces']
909+
- name: RESTIC_PV_HOSTPATH
910+
- name: FS_PV_HOSTPATH
911+
- name: PLUGINS_HOSTPATH
907912
- name: RELATED_IMAGE_VELERO
908913
value: quay.io/konveyor/velero:latest
909914
- name: RELATED_IMAGE_VELERO_RESTORE_HELPER

config/manager/manager.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ spec:
3636
valueFrom:
3737
fieldRef:
3838
fieldPath: metadata.namespace
39+
- name: RESTIC_PV_HOSTPATH
40+
value: ""
41+
- name: FS_PV_HOSTPATH
42+
value: ""
43+
- name: PLUGINS_HOSTPATH
44+
value: ""
3945
- name: RELATED_IMAGE_VELERO
4046
value: quay.io/konveyor/velero:latest
4147
- name: RELATED_IMAGE_VELERO_RESTORE_HELPER

config/rbac/role.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ rules:
1212
- infrastructures
1313
verbs:
1414
- get
15+
- list
16+
- watch
1517
- apiGroups:
1618
- cloudcredential.openshift.io
1719
resources:

controllers/bsl_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88

99
"github.com/go-logr/logr"
1010
"github.com/google/go-cmp/cmp"
11+
configv1 "github.com/openshift/api/config/v1"
1112
velerov1 "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
1213
corev1 "k8s.io/api/core/v1"
1314
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -36,6 +37,11 @@ func getSchemeForFakeClient() (*runtime.Scheme, error) {
3637
return nil, err
3738
}
3839

40+
err = configv1.AddToScheme((scheme.Scheme))
41+
if err != nil {
42+
return nil, err
43+
}
44+
3945
return scheme.Scheme, nil
4046
}
4147

controllers/nodeagent.go

Lines changed: 80 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
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

2728
const (
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

3444
var (
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

6597
func 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

Comments
 (0)