Skip to content

Commit 159d3bf

Browse files
committed
Add missing migrations (etcd/crd) for ZFS rename
1 parent 667f224 commit 159d3bf

File tree

3 files changed

+112
-0
lines changed

3 files changed

+112
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010

1111
### Fixed
1212

13+
- Add missing migrations (etcd/crd) for ZFS rename
1314
- Only satellite zfs migrate nodes that have a ZFS pool
1415

1516
## [1.31.0-rc.1] - 2025-03-19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package com.linbit.linstor.dbcp.migration.etcd;
2+
3+
import com.linbit.linstor.dbcp.migration.Migration_2024_11_21_CreateSnapshotsFromZfsClones;
4+
import com.linbit.linstor.storage.kinds.DeviceProviderKind;
5+
import com.linbit.linstor.transaction.EtcdTransaction;
6+
7+
import java.util.HashSet;
8+
import java.util.Map;
9+
import java.util.Set;
10+
import java.util.TreeMap;
11+
12+
@EtcdMigration(
13+
description = "Add property for satellites to mark CF_ snapshots for deletion",
14+
version = 67
15+
)
16+
public class Migration_40_CreateSnapshotsFromZfsClones extends BaseEtcdMigration
17+
{
18+
private static final String ETCD_CLM_NAME_PROP_VALUE = "/PROP_VALUE";
19+
20+
@Override
21+
public void migrate(EtcdTransaction tx, final String prefix) throws Exception
22+
{
23+
final String prefixedDbTableStr = prefix + "NODE_STOR_POOL/";
24+
final int prefixedTblKeyLen = prefixedDbTableStr.length();
25+
TreeMap<String, String> allNodeStorPool = tx.get(prefix + "NODE_STOR_POOL", true);
26+
27+
Set<String> alreadySet = new HashSet<>();
28+
for (Map.Entry<String, String> entry : allNodeStorPool.entrySet())
29+
{
30+
String value = entry.getValue();
31+
if (entry.getKey().endsWith("DRIVER_NAME") && (value.equalsIgnoreCase(
32+
DeviceProviderKind.ZFS_THIN.name()) || value.equalsIgnoreCase(DeviceProviderKind.ZFS.name())))
33+
{
34+
String combinedPkAndColumn = entry.getKey().substring(prefixedTblKeyLen);
35+
String combinedPk = combinedPkAndColumn.substring(0, combinedPkAndColumn.lastIndexOf("/"));
36+
37+
String[] pks = combinedPk.split(":");
38+
String nodeName = pks[0];
39+
40+
if (!alreadySet.contains(nodeName))
41+
{
42+
String propInstance = String.format("/NODES/%s", nodeName);
43+
String propsPrefix = prefix + "PROPS_CONTAINERS/" + propInstance + ":";
44+
String key = propsPrefix + Migration_2024_11_21_CreateSnapshotsFromZfsClones.PROP_KEY_STLT_MIGRATION +
45+
ETCD_CLM_NAME_PROP_VALUE;
46+
tx.put(key, Migration_2024_11_21_CreateSnapshotsFromZfsClones.PROP_VALUE_STLT_MIGRATION);
47+
alreadySet.add(nodeName);
48+
}
49+
}
50+
}
51+
}
52+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package com.linbit.linstor.dbcp.migration.k8s.crd;
2+
3+
import com.linbit.linstor.ControllerK8sCrdDatabase;
4+
import com.linbit.linstor.dbcp.migration.Migration_2024_11_21_CreateSnapshotsFromZfsClones;
5+
import com.linbit.linstor.dbdrivers.k8s.crd.GenCrdV1_27_1;
6+
import com.linbit.linstor.dbdrivers.k8s.crd.GenCrdV1_27_1.NodeStorPool;
7+
import com.linbit.linstor.dbdrivers.k8s.crd.GenCrdV1_27_1.NodeStorPoolSpec;
8+
import com.linbit.linstor.storage.kinds.DeviceProviderKind;
9+
10+
import static com.linbit.linstor.dbdrivers.k8s.crd.GenCrdV1_27_1.GeneratedDatabaseTables.NODE_STOR_POOL;
11+
import static com.linbit.linstor.dbdrivers.k8s.crd.GenCrdV1_27_1.GeneratedDatabaseTables.PROPS_CONTAINERS;
12+
13+
import java.util.Collection;
14+
import java.util.HashSet;
15+
import java.util.Set;
16+
17+
@K8sCrdMigration(
18+
description = "Add property for satellites to mark CF_ snapshots for deletion",
19+
version = 27
20+
)
21+
public class Migration_27_v1_27_1_CreateSnapshotsFromZfsClones extends BaseK8sCrdMigration
22+
{
23+
public Migration_27_v1_27_1_CreateSnapshotsFromZfsClones()
24+
{
25+
super(GenCrdV1_27_1.createMigrationContext());
26+
}
27+
28+
@Override
29+
public MigrationResult migrateImpl(ControllerK8sCrdDatabase k8sDbRef) throws Exception
30+
{
31+
Collection<NodeStorPool> crdList = txFrom.<NodeStorPool, NodeStorPoolSpec>getCrd(
32+
NODE_STOR_POOL
33+
).values();
34+
35+
Set<String> alreadySet = new HashSet<>();
36+
for (NodeStorPool nodeStorPoolCrd : crdList)
37+
{
38+
NodeStorPoolSpec nodeStorPoolSpec = nodeStorPoolCrd.getSpec();
39+
if (nodeStorPoolSpec.driverName.equalsIgnoreCase(DeviceProviderKind.ZFS_THIN.name()) ||
40+
nodeStorPoolSpec.driverName.equalsIgnoreCase(DeviceProviderKind.ZFS.name()))
41+
{
42+
if (!alreadySet.contains(nodeStorPoolSpec.nodeName))
43+
{
44+
String propInstance = String.format("/NODES/%s", nodeStorPoolSpec.nodeName);
45+
txTo.create(PROPS_CONTAINERS,
46+
GenCrdV1_27_1.createPropsContainers(
47+
propInstance,
48+
Migration_2024_11_21_CreateSnapshotsFromZfsClones.PROP_KEY_STLT_MIGRATION,
49+
Migration_2024_11_21_CreateSnapshotsFromZfsClones.PROP_VALUE_STLT_MIGRATION
50+
)
51+
);
52+
alreadySet.add(nodeStorPoolSpec.nodeName);
53+
}
54+
}
55+
}
56+
57+
return null;
58+
}
59+
}

0 commit comments

Comments
 (0)