-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
184 additions
and
62 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
// TODO: implement more from: https://storageclass.info/csidrivers/ | ||
// https://github.com/storageclass/storageclass.github.io/blob/main/data/csidrivers.yaml | ||
const KNOWN_CLASS = [ | ||
#{ | ||
"driverClass": "cephfs.csi.ceph.com", | ||
"accessModes": #{"readOnlyMany": true, "readWriteMany": true, "readWriteOnce": true, "readWriteOncePod": false}, | ||
"capabilities": #{"clone": true, "dynamic": true, "expansion": true, "raw": false, "snapshot": true, "topology": false, "tracking": false}, | ||
}, #{ | ||
"driverClass": "rbd.csi.ceph.com", | ||
"accessModes": #{"readOnlyMany": true, "readWriteMany": true, "readWriteOnce": true, "readWriteOncePod": true}, | ||
"capabilities": #{"clone": true, "dynamic": true, "expansion": true, "raw": true, "snapshot": true, "topology": true, "tracking": false}, | ||
}, #{ | ||
"driverClass": "smb.csi.k8s.io", | ||
"accessModes": #{"readOnlyMany": true, "readWriteMany": true, "readWriteOnce": true, "readWriteOncePod": false}, | ||
"capabilities": #{"dynamic": true}, | ||
}, #{ | ||
"driverClass": "nfs.csi.k8s.io", | ||
"accessModes": #{"readOnlyMany": true, "readWriteMany": true, "readWriteOnce": true, "readWriteOncePod": false}, | ||
"capabilities": #{"dynamic": true}, | ||
}, #{ | ||
"driverClass": "k8s-sigs.io/nfs-provisioner", | ||
"accessModes": #{"readOnlyMany": true, "readWriteMany": true, "readWriteOnce": true, "readWriteOncePod": false}, | ||
"capabilities": #{"dynamic": true}, | ||
}, #{ | ||
"driverClass": "rancher.io/local-path", | ||
"accessModes": #{"readOnlyMany": false, "readWriteMany": false, "readWriteOnce": true, "readWriteOncePod": true}, | ||
"capabilities": #{"dynamic": true}, | ||
}, #{ | ||
"driverClass": "csi.scaleway.com", | ||
"accessModes": #{"readOnlyMany": true, "readWriteMany": true, "readWriteOnce": true, "readWriteOncePod": true}, | ||
"capabilities": #{"clone": false, "dynamic": true, "expansion": true, "raw": true, "snapshot": true, "topology": true, "tracking": false}, | ||
}, #{ | ||
"driverClass": "filestore.csi.storage.gke.io", | ||
"accessModes": #{"readOnlyMany": true, "readWriteMany": true, "readWriteOnce": true, "readWriteOncePod": false}, | ||
"capabilities": #{"dynamic": true, "file": true}, | ||
}, #{ | ||
"driverClass": "file.csi.azure.com", | ||
"accessModes": #{"readOnlyMany": true, "readWriteMany": true, "readWriteOnce": true, "readWriteOncePod": false}, | ||
"capabilities": #{"clone": false, "dynamic": true, "expansion": true, "file": true, "raw": false, "snapshot": false, "topology": false, "tracking": false}, | ||
}, #{ | ||
"driverClass": "efs.csi.aws.com", | ||
"accessModes": #{"readOnlyMany": true, "readWriteMany": true, "readWriteOnce": true, "readWriteOncePod": false}, | ||
"capabilities": #{"dynamic": true, "file": true}, | ||
} | ||
]; | ||
|
||
fn get_default_access_modes_from_all(all) { | ||
if all.contains("ReadWriteMany") { | ||
["ReadWriteMany"] | ||
} else if all.contains("ReadOnlyMany") && all.contains("ReadWriteOnce") { | ||
["ReadOnlyMany", "ReadWriteOnce"] | ||
} else if all.contains("ReadWriteOncePod") { | ||
["ReadWriteOncePod"] | ||
} else { | ||
all | ||
} | ||
} | ||
|
||
fn classes_enrich(scs) { | ||
let enriched = []; | ||
for i in scs { | ||
i["volumeMode"] = "Filesystem"; | ||
let f = global::KNOWN_CLASS.find(|k| i.provisioner.contains(k.driverClass)); | ||
if f != () { | ||
i["capabilities"] = f.capabilities; | ||
let keys = f.accessModes.keys(); | ||
i["allAccessModes"] = keys.filter(|k| f.accessModes[k]).map(|s| {s.replace("read","Read");s}); | ||
if (f.capabilities.raw == true) { | ||
let b = i; | ||
b["volumeMode"] = "Block"; | ||
i["allAccessModes"] = keys.filter(|k| f.accessModes[k] && k != "ReadWriteMany"); | ||
b["accessModes"] = get_default_access_modes_from_all(b["allAccessModes"]); | ||
enriched.push(b); | ||
} | ||
i["accessModes"] = get_default_access_modes_from_all(i["allAccessModes"]); | ||
} else { | ||
i["capabilities"] = #{}; | ||
i["allAccessModes"] = ["ReadWriteOnce"]; | ||
i["accessModes"] = ["ReadWriteOnce"]; | ||
} | ||
enriched.push(i); | ||
} | ||
enriched | ||
} | ||
|
||
fn get_prefered_sc(scs) { | ||
let pref = #{ | ||
"block_readWriteMany": (), | ||
"block_readWriteOnce": (), | ||
"fs_cheap_readWriteMany": (), | ||
"fs_fast_readWriteMany": (), | ||
"fs_readWriteMany": (), | ||
"fs_cheap_readWriteOnce": (), | ||
"fs_fast_readWriteOnce": (), | ||
"fs_readWriteOnce": (), | ||
}; | ||
let block = scs.filter(|s| s.volumeMode=="Block"); | ||
let fs_only = scs.filter(|s| s.volumeMode=="Filesystem" && [["ReadWriteOncePod"],["ReadWriteOnce"]].contains(s.accessModes)); | ||
let fs_many = scs.filter(|s| s.volumeMode=="Filesystem" && s.accessModes==["ReadWriteMany"]); | ||
if block.len() > 0 { | ||
let many = block.filter(|s| s.accessModes==["ReadWriteMany"]); | ||
let others = block.filter(|s| s.accessModes!=["ReadWriteMany"]); | ||
if many.len() > 0 { | ||
pref["block_readWriteMany"] = many[0].name; | ||
} | ||
if others.len() > 0 { | ||
pref["block_readWriteOnce"] = others[0].name; | ||
} else { | ||
pref["block_readWriteOnce"] = many[0].name; | ||
} | ||
} | ||
if fs_many.len() > 0 { | ||
pref["fs_readWriteMany"] = fs_many[0].name; | ||
} | ||
if fs_only.len() > 0 { | ||
pref["fs_readWriteOnce"] = fs_only[0].name; | ||
} | ||
pref | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
fn for_deployments(context, typed) { | ||
let scs = context.cluster.storage_classes; | ||
if typed=="fast" && context.cluster.prefered_storage.fs_fast_readWriteMany != () { | ||
scs.find(|s| s.name == context.cluster.prefered_storage.fs_fast_readWriteMany && s.volumeMode == "Filesystem") | ||
} else if typed=="cheap" && context.cluster.prefered_storage.fs_cheap_readWriteMany != () { | ||
scs.find(|s| s.name == context.cluster.prefered_storage.fs_cheap_readWriteMany && s.volumeMode == "Filesystem") | ||
} else if context.cluster.prefered_storage.fs_readWriteMany != () { | ||
scs.find(|s| s.name == context.cluster.prefered_storage.fs_readWriteMany && s.volumeMode == "Filesystem") | ||
} else if typed=="fast" && context.cluster.prefered_storage.fs_fast_readWriteOnce != () { | ||
scs.find(|s| s.name == context.cluster.prefered_storage.fs_fast_readWriteOnce && s.volumeMode == "Filesystem") | ||
} else if typed=="cheap" && context.cluster.prefered_storage.fs_cheap_readWriteOnce != () { | ||
scs.find(|s| s.name == context.cluster.prefered_storage.fs_cheap_readWriteOnce && s.volumeMode == "Filesystem") | ||
} else if context.cluster.prefered_storage.fs_readWriteOnce != () { | ||
scs.find(|s| s.name == context.cluster.prefered_storage.fs_readWriteOnce && s.volumeMode == "Filesystem") | ||
} else { | ||
scs.find(|s| s.is_default) | ||
} | ||
} | ||
fn for_deployments(context) { | ||
for_deployments(context, ()); | ||
} | ||
|
||
fn for_statefulsets(context, typed) { | ||
let scs = context.cluster.storage_classes; | ||
if typed=="fast" && context.cluster.prefered_storage.fs_fast_readWriteOnce != () { | ||
scs.find(|s| s.name == context.cluster.prefered_storage.fs_fast_readWriteOnce && s.volumeMode == "Filesystem") | ||
} else if typed=="cheap" && context.cluster.prefered_storage.fs_cheap_readWriteOnce != () { | ||
scs.find(|s| s.name == context.cluster.prefered_storage.fs_cheap_readWriteOnce && s.volumeMode == "Filesystem") | ||
} else if context.cluster.prefered_storage.fs_readWriteOnce != () { | ||
scs.find(|s| s.name == context.cluster.prefered_storage.fs_readWriteOnce && s.volumeMode == "Filesystem") | ||
} else { | ||
scs.find(|s| s.is_default) | ||
} | ||
} | ||
fn for_statefulsets(context) { | ||
for_statefulsets(context, ()); | ||
} | ||
|
||
fn for_vm(context) { | ||
let scs = context.cluster.storage_classes; | ||
if context.cluster.prefered_storage.block_readWriteMany != () { | ||
scs.find(|s| s.name == context.cluster.prefered_storage.block_readWriteMany && s.volumeMode == "Block") | ||
} else if context.cluster.prefered_storage.block_readWriteOnce != () { | ||
scs.find(|s| s.name == context.cluster.prefered_storage.block_readWriteOnce && s.volumeMode == "Block") | ||
} else { | ||
scs.find(|s| s.is_default) | ||
} | ||
} |