Skip to content

Commit 5684983

Browse files
Merge pull request openstack-k8s-operators#338 from Akrog/revert-lvm-workaround
Support LVM
2 parents 376faf4 + 646eb91 commit 5684983

File tree

5 files changed

+82
-19
lines changed

5 files changed

+82
-19
lines changed

config/samples/backends/bases/lvm/lvm.yaml

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# This machine config creates a systemd unit that creates a file based LVM VG
2+
# called cinder-volumes and mounts it on each reboot.
3+
#
4+
# Even though the systemd unit will be deployed in ALL OCP master nodes it will
5+
# only really run on the nodes that have the "openstack.org/cinder-lvm"
6+
# label.
17
apiVersion: machineconfiguration.openshift.io/v1
28
kind: MachineConfig
39
metadata:
@@ -17,19 +23,23 @@ spec:
1723
Contents: |
1824
[Unit]
1925
Description=Cinder LVM losetup
20-
DefaultDependencies=no
2126
Conflicts=umount.target
22-
Requires=lvm2-monitor.service systemd-udev-settle.service
23-
Before=local-fs.target umount.target
24-
After=var.mount lvm2-monitor.service systemd-udev-settle.service
27+
Requires=lvm2-monitor.service systemd-udev-settle.service kubelet.service
28+
After=var.mount lvm2-monitor.service systemd-udev-settle.service kubelet.service
2529
2630
[Service]
2731
Environment=VG_GB_SIZE=10G
2832
Environment=LOOPBACK_FILE=/var/home/core/cinder-volumes
29-
Type=oneshot
30-
ExecStart=bash -c "if [[ ! -e ${LOOPBACK_FILE} ]]; then /bin/truncate -s ${VG_GB_SIZE} ${LOOPBACK_FILE} && /sbin/vgcreate cinder-volumes `/sbin/losetup --show -f ${LOOPBACK_FILE}`; else /sbin/losetup -f ${LOOPBACK_FILE}; fi"
31-
ExecStop=bash -c "/sbin/losetup -d `/sbin/losetup -j ${LOOPBACK_FILE} -l -n -O NAME`"
33+
Environment=LABEL=openstack.org/cinder-lvm
34+
35+
# Waits until cluster is available by failing, then Restart kicks in after 5 seconds
36+
ExecStartPre=oc --kubeconfig=/var/lib/kubelet/kubeconfig get node
37+
ExecStart=bash -c "if [ \"$(oc --kubeconfig=/var/lib/kubelet/kubeconfig get node -l ${LABEL} -o name)\" = \"node/$(hostname)\" ]; then if [[ ! -e ${LOOPBACK_FILE} ]]; then /bin/truncate -s ${VG_GB_SIZE} ${LOOPBACK_FILE} && /sbin/vgcreate cinder-volumes `/sbin/losetup --show -f ${LOOPBACK_FILE}`; else /sbin/losetup -f ${LOOPBACK_FILE}; fi; fi"
38+
ExecStop=bash -c "if vgdisplay cinder-volumes; then /sbin/losetup -d `/sbin/losetup -j ${LOOPBACK_FILE} -l -n -O NAME`; fi"
3239
RemainAfterExit=yes
3340
41+
Restart=on-failure
42+
RestartSec=5
43+
3444
[Install]
35-
WantedBy=local-fs-pre.target
45+
WantedBy=multi-user.target
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Cinder LVM Backend Samples
2+
3+
Two LVM examples are provided using different transport protocols:
4+
5+
- LVM using iSCSI
6+
- LVM using NVMe-TCP
7+
8+
The LVM is a special case, because the stored data is actually on the OCP node
9+
and not an external storage system. This has several implications:
10+
11+
- OCP nodes will reboot after the samples manifests are applied because they
12+
are creating `MachineConfig` objects to start daemons and create the LVM
13+
backing file.
14+
15+
- Network configuration on the OCP host needs to be different, as it needs a
16+
macvlan interface on top of the storage VLAN interface. This can be easily
17+
done by modifying the operators deployment step running:
18+
`NETWORK_STORAGE_MACVLAN=true make openstack`. Other option is to manually
19+
modify the `nncp` of the OCP node.
20+
21+
- We need to mark one of our OCP nodes with a specific label so that:
22+
23+
- The LVM `MachineConfig` that creates a file based LVM Volume Group and
24+
ensures it is mounted on boot only really runs in one node (even if the
25+
systemd unit is deployed in all the nodes).
26+
27+
- The cinder-volume service for the LVM backend can only run on the node that
28+
has the LVM Volume Group.
29+
30+
To mark the first ready node as the lvm node we can run:
31+
32+
```bash
33+
$ oc label node \
34+
$(oc get nodes --field-selector spec.unschedulable=false -l node-role.kubernetes.io/worker -o jsonpath="{.items[0].metadata.name}") \
35+
openstack.org/cinder-lvm=
36+
```
37+
38+
If we have a specific node in mind we can just do:
39+
```bash
40+
$ oc label node <nodename> openstack.org/cinder-lvm=
41+
```
42+
43+
To see how this label is being used please look into the following files:
44+
45+
- `./iscsi/backend.yaml`
46+
- `./nvme-tcp/backend.yaml`
47+
- `../bases/lvm/lvm.yaml`

config/samples/backends/lvm/iscsi/backend.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
# The correct way to configure and run the daemons is using `MachineConfig` as shown in `iscsid.yaml` and `multipathd.yaml`.
44
# To create the LVM on CRC the sample also uses a `MachineConfig` using a systemd unit with file `lvm.yaml`
55
#
6-
# ATTENTION: After applying this OpenShift nodes will reboot, because of the `MachineConfig` changes and will take a while to recover.
6+
# ATTENTION:
7+
# - Node where we want LVM to run needs to be labeled with openstack.org/cinder-lvm
8+
# - After applying this OpenShift nodes will reboot, because of the `MachineConfig` changes and will take a while to recover.
79

810
apiVersion: core.openstack.org/v1beta1
911
kind: OpenStackControlPlane
@@ -14,6 +16,8 @@ spec:
1416
template:
1517
cinderVolumes:
1618
lvm-iscsi:
19+
nodeSelector:
20+
openstack.org/cinder-lvm: ""
1721
networkAttachments:
1822
- storage
1923
customServiceConfig: |

config/samples/backends/lvm/nvme-tcp/backend.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
# The correct way to configure the load of additional kernel modules is using `MachineConfig` as shown in `nvme-fabrics.yaml`.yaml`.
44
# To create the LVM on CRC the sample also uses a `MachineConfig` using a systemd unit with file `lvm.yaml`
55
#
6-
# ATTENTION: After applying this OpenShift nodes will reboot, because of the `MachineConfig` changes and will take a while to recover.
6+
# ATTENTION:
7+
# - Node where we want LVM to run needs to be labeled with openstack.org/cinder-lvm
8+
# - After applying this OpenShift nodes will reboot, because of the `MachineConfig` changes and will take a while to recover.
79
apiVersion: core.openstack.org/v1beta1
810
kind: OpenStackControlPlane
911
metadata:
@@ -13,6 +15,8 @@ spec:
1315
template:
1416
cinderVolumes:
1517
lvm-nvme-tcp:
18+
nodeSelector:
19+
openstack.org/cinder-lvm: ""
1620
networkAttachments:
1721
- storage
1822
customServiceConfig: |

controllers/cindervolume_controller.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -699,19 +699,17 @@ func (r *CinderVolumeReconciler) generateServiceConfigs(
699699

700700
templateParameters := make(map[string]interface{})
701701
if usesLVM {
702-
// Configure 'target_secondary_ip_addresses' using addresses in the
703-
// network attachments. This relies on the fact that the LVM backend
704-
// can only have one replica.
705-
//
706-
// Do not configure the primary 'target_ip_address', so that it will default
707-
// to the service's 'my_ip' address. This will be the dynamically assigned
708-
// OpenShift SDN address, which allows control plane services like g-api and
709-
// c-bak to connect to LVM volumes.
710702
networkAttachmentAddrs := cinder.GetNetworkAttachmentAddrs(
711703
instance.Namespace, instance.Spec.NetworkAttachments, instance.Status.NetworkAttachments)
712704

705+
// Configure target IP addresses using all addresses in the network
706+
// attachments. This relies on the fact that the LVM backend can only
707+
// have one replica.
713708
if len(networkAttachmentAddrs) > 0 {
714-
templateParameters["TargetSecondaryIpAddresses"] = strings.Join(networkAttachmentAddrs, ",")
709+
templateParameters["TargetIpAddress"] = networkAttachmentAddrs[0]
710+
if len(networkAttachmentAddrs) > 1 {
711+
templateParameters["TargetSecondaryIpAddresses"] = strings.Join(networkAttachmentAddrs[1:], ",")
712+
}
715713
}
716714
}
717715

0 commit comments

Comments
 (0)