Create Nix module for Creating Longhorn volumes
This commit is contained in:
parent
4232b18ea1
commit
e791c1df9c
3 changed files with 71 additions and 38 deletions
kubenix-modules/custom
68
kubenix-modules/custom/longhorn-volume.nix
Normal file
68
kubenix-modules/custom/longhorn-volume.nix
Normal file
|
@ -0,0 +1,68 @@
|
|||
{ lib, config, ... }:
|
||||
let
|
||||
longhornVolumeOpts = { name, ... }: {
|
||||
options = {
|
||||
storage = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
};
|
||||
};
|
||||
};
|
||||
in
|
||||
{
|
||||
options = {
|
||||
lab.longhornVolumes = lib.mkOption {
|
||||
type = with lib.types; attrsOf (submodule longhornVolumeOpts);
|
||||
default = { };
|
||||
};
|
||||
};
|
||||
|
||||
config = {
|
||||
kubernetes.resources = {
|
||||
persistentVolumes = builtins.mapAttrs
|
||||
(name: longhornVolume: {
|
||||
spec = {
|
||||
accessModes = [ "ReadWriteOnce" ];
|
||||
capacity.storage = longhornVolume.storage;
|
||||
|
||||
claimRef = {
|
||||
inherit name;
|
||||
namespace = "default";
|
||||
};
|
||||
|
||||
csi = {
|
||||
driver = "driver.longhorn.io";
|
||||
fsType = "ext4";
|
||||
|
||||
volumeAttributes = {
|
||||
dataLocality = "disabled";
|
||||
fromBackup = "";
|
||||
fsType = "ext4";
|
||||
numberOfReplicas = "2";
|
||||
recurringJobSelector = lib.generators.toYAML { } [{
|
||||
name = "backup-nfs";
|
||||
isGroup = false;
|
||||
}];
|
||||
staleReplicaTimeout = "30";
|
||||
unmapMarkSnapChainRemoved = "ignored";
|
||||
};
|
||||
volumeHandle = name;
|
||||
};
|
||||
|
||||
persistentVolumeReclaimPolicy = "Delete";
|
||||
volumeMode = "Filesystem";
|
||||
};
|
||||
})
|
||||
config.lab.longhornVolumes;
|
||||
|
||||
persistentVolumeClaims = builtins.mapAttrs
|
||||
(name: longhornVolume: {
|
||||
spec = {
|
||||
accessModes = [ "ReadWriteOnce" ];
|
||||
resources.requests.storage = longhornVolume.storage;
|
||||
storageClassName = "";
|
||||
};
|
||||
})
|
||||
config.lab.longhornVolumes;
|
||||
};
|
||||
};
|
||||
}
|
Reference in a new issue