Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
129 commits
Select commit Hold shift + click to select a range
3ed0caf
added simplyblock crds and custom resource
geoffrey1330 Dec 10, 2025
734bff8
make some spec field required in crd
geoffrey1330 Dec 10, 2025
9bb881b
moved simplyblock mgmt deployment into a single deployment
geoffrey1330 Dec 10, 2025
5ca59fc
added helm _helpers.tpl
geoffrey1330 Dec 10, 2025
e68aacd
conditionalize ingress creation
geoffrey1330 Dec 10, 2025
f8f22d4
conditionalize MongoDBCommunity cr creation
geoffrey1330 Dec 10, 2025
9c5a6ab
remove fluentbit daemonset
geoffrey1330 Dec 10, 2025
ea8ebc6
added fluent-bit sidecar container
geoffrey1330 Dec 10, 2025
30e3075
fixed yaml identation
geoffrey1330 Dec 10, 2025
d591099
use dnsPolicy: ClusterFirstWithHostNet for spdk ppd
geoffrey1330 Dec 10, 2025
ab50d55
exclude fluentbit own logs
geoffrey1330 Dec 10, 2025
269212f
shrink thanos deployments into single deployment
geoffrey1330 Dec 11, 2025
d540826
improved opensearch and graylog route
geoffrey1330 Dec 11, 2025
ae67465
call function if monitoring is enabled
geoffrey1330 Dec 11, 2025
681b823
updated monitoring endpoint format
geoffrey1330 Dec 11, 2025
554d800
removed nodeExporter
geoffrey1330 Dec 11, 2025
e3086e9
remove fdb customParameters
geoffrey1330 Dec 11, 2025
578a8d9
specified new port for thanos components
geoffrey1330 Dec 11, 2025
931e37b
updated monitoring endpoint format
geoffrey1330 Dec 11, 2025
aa5d7a5
updated monitoring endpoint format
geoffrey1330 Dec 11, 2025
023c0ad
removed hostpath capacity
geoffrey1330 Dec 11, 2025
d778741
fixed graylog input endpoint
geoffrey1330 Dec 12, 2025
d4828fa
added cluster task cr and crd
geoffrey1330 Dec 12, 2025
5fa8685
added cluster task cr and crd
geoffrey1330 Dec 12, 2025
9f0d1bb
Merge branch 'main' into improved_user_experience
geoffrey1330 Dec 12, 2025
2613855
fixed task routing
geoffrey1330 Dec 12, 2025
c88194c
fixed object has no attribute 'cluster_id'
geoffrey1330 Dec 12, 2025
2a79c85
set is_json true
geoffrey1330 Dec 12, 2025
4d59a32
return JobSchedule
geoffrey1330 Dec 12, 2025
e7f4a86
decode the json first
geoffrey1330 Dec 12, 2025
e5b782e
remove id from the dict before passing it
geoffrey1330 Dec 12, 2025
0aa31a7
remove id and uuid from the dict before passing it
geoffrey1330 Dec 12, 2025
b3eb10b
remove id, uuid and status from the dict before passing it
geoffrey1330 Dec 12, 2025
6631c84
remove id, uuid, status and deleted from the dict before passing it
geoffrey1330 Dec 12, 2025
eabd7fa
improved list task
geoffrey1330 Dec 12, 2025
5aa0c9f
use model.uuid instead
geoffrey1330 Dec 12, 2025
ba03c98
made some add snode param optional in api v2
geoffrey1330 Dec 15, 2025
f7074f0
improved sn apiv2 response data
geoffrey1330 Dec 15, 2025
2b61dff
improved sn apiv2 response data more
geoffrey1330 Dec 15, 2025
0800933
Merge branch 'main' into improved_user_experience
geoffrey1330 Dec 15, 2025
e34fd56
Merge branch 'main' into improved_user_experience
geoffrey1330 Dec 15, 2025
20b5eff
set grafana_secret empty if monitoring is disabled
geoffrey1330 Dec 16, 2025
c853af0
return the mgmt ip without kubelet ping
geoffrey1330 Dec 16, 2025
b1e81bf
updated the fdb health check logic
geoffrey1330 Dec 17, 2025
80af2f7
updated crd clusterInfo
geoffrey1330 Dec 17, 2025
953dbd0
added cr_name, cr_namespace and cr_plural to baseModel
geoffrey1330 Dec 17, 2025
bca794a
removed cr_name, cr_namespace and cr_plural to baseModel
geoffrey1330 Dec 18, 2025
ef97787
added cluster cr status patch
geoffrey1330 Dec 18, 2025
9afede4
Merge branch 'main' into improved_user_experience
geoffrey1330 Dec 18, 2025
8a1c7b8
added cluster cr status patch for rebalancing
geoffrey1330 Dec 18, 2025
fc90514
added function for patching node cr status
geoffrey1330 Dec 18, 2025
e8d093c
added function for patching node cr device status
geoffrey1330 Dec 18, 2025
e67711d
added service account across mgmt services
geoffrey1330 Dec 19, 2025
245424e
added patch for pool cr
geoffrey1330 Dec 19, 2025
b16f361
removed mode from snode model
geoffrey1330 Dec 19, 2025
b25942f
added rbac for simplyblock cr resource
geoffrey1330 Dec 19, 2025
d22db71
get cr base on node_uuid or node_mgmt_ip
geoffrey1330 Dec 19, 2025
c899b37
fixed patch_cr_node_status() missing 1 required keyword-only argument…
geoffrey1330 Dec 19, 2025
f17dfdd
updated storagenode crd memory status field
geoffrey1330 Dec 19, 2025
25a53c3
Merge branch 'main' into improved_user_experience
geoffrey1330 Dec 19, 2025
5f733c6
update snode cr nvmf and lvol port
geoffrey1330 Dec 19, 2025
367c3ea
Merge branch 'main' into improved_user_experience
geoffrey1330 Dec 19, 2025
cc952c5
updated cr kind
geoffrey1330 Dec 19, 2025
c4edbfc
updated the crds
geoffrey1330 Dec 19, 2025
7e565f9
updated service account resource name
geoffrey1330 Dec 20, 2025
b353ca7
updated pool resource name
geoffrey1330 Dec 22, 2025
99e8273
updated crd
geoffrey1330 Dec 22, 2025
bf8170b
updated crd
geoffrey1330 Dec 22, 2025
caedf26
removed capacityInfo in crd
geoffrey1330 Dec 22, 2025
9a14d5e
Merge branch 'main' into improved_user_experience
geoffrey1330 Dec 22, 2025
7305483
added lvols_cr to pool model
geoffrey1330 Dec 23, 2025
578cc69
added lvol crd
geoffrey1330 Dec 23, 2025
944d01e
updated lvol api response
geoffrey1330 Dec 29, 2025
340d13d
updated lvol api response
geoffrey1330 Dec 29, 2025
7f60119
updated lvol crd
geoffrey1330 Dec 29, 2025
0eac341
updated lvol crd
geoffrey1330 Dec 29, 2025
9482031
added func patch_cr_lvol_status
geoffrey1330 Dec 29, 2025
ae27bb7
fixed type check failure
geoffrey1330 Dec 29, 2025
e019cbb
fixed type check failure
geoffrey1330 Dec 29, 2025
408a315
added logic for updating lvol cr field
geoffrey1330 Dec 29, 2025
46e7a7f
fixed TypeError: unsupported operand type
geoffrey1330 Dec 29, 2025
b308f4c
fixed type check failure
geoffrey1330 Dec 29, 2025
7ea9baf
update snode cr health type to bool
geoffrey1330 Dec 29, 2025
19a3eb9
updated the lvol cr change condition
geoffrey1330 Dec 29, 2025
330ed82
added log message
geoffrey1330 Dec 29, 2025
70297ed
added log message
geoffrey1330 Dec 29, 2025
3b6507b
updated lvol cr name
geoffrey1330 Dec 29, 2025
cd568cd
removed debug logs
geoffrey1330 Dec 29, 2025
c8e0ded
fixed linter issue
geoffrey1330 Dec 30, 2025
1857743
added node permission
geoffrey1330 Dec 30, 2025
96106b0
Merge branch 'main' into improved_user_experience
geoffrey1330 Dec 30, 2025
750fdf7
updated ap/v2 cluster create response data
geoffrey1330 Dec 30, 2025
ae9127d
updated ap/v2 cluster create response data
geoffrey1330 Dec 30, 2025
ad9236d
removed coding from field
geoffrey1330 Dec 30, 2025
e345726
updated ap/v2 cluster create response data
geoffrey1330 Dec 30, 2025
90c41b8
added restart on another host support in api v2
geoffrey1330 Jan 5, 2026
e69646a
added default value for node_address
geoffrey1330 Jan 5, 2026
0df91b9
removed default value for node_address
geoffrey1330 Jan 5, 2026
5b070b5
updated simplyblockstoragenode crd
geoffrey1330 Jan 5, 2026
2e2e42e
updated manager permissions
geoffrey1330 Jan 5, 2026
88651b2
updated simplyblockpools crd
geoffrey1330 Jan 6, 2026
966d39b
updated simplyblock manager image tag
geoffrey1330 Jan 6, 2026
02180fa
added param id_device_by_nqn to snode add
geoffrey1330 Jan 6, 2026
21c20ec
updated simplyblockstoragenode crd
geoffrey1330 Jan 6, 2026
ec64909
Merge branch 'main' into improved_user_experience
geoffrey1330 Jan 6, 2026
07818e5
always add new devices when restarting node on new ip
Hamdy-khader Jan 6, 2026
e926226
attach fluentbit container to webapi pod
geoffrey1330 Jan 6, 2026
f02e056
updated simplyblockstoragenode crd
geoffrey1330 Jan 7, 2026
000a69e
fixed helm template structure
geoffrey1330 Jan 7, 2026
9948f0b
bind root to container host path
geoffrey1330 Jan 7, 2026
507ef32
bind root to container host path
geoffrey1330 Jan 7, 2026
182c9ca
bind root to container host path
geoffrey1330 Jan 7, 2026
54cd997
bind root to container host path
geoffrey1330 Jan 7, 2026
29111d7
Merge branch 'main' into improved_user_experience
geoffrey1330 Jan 7, 2026
dd61d25
updated simplyblockstoragecluster crd
geoffrey1330 Jan 7, 2026
0732d6b
updated sbcli helm values.yaml structure
geoffrey1330 Jan 8, 2026
bfe1ff0
added helm value for simplyblock CR
geoffrey1330 Jan 8, 2026
83ea7f9
support storage node remove and delete in one endpoint
geoffrey1330 Jan 8, 2026
a12a6b7
remove node details from CR
geoffrey1330 Jan 8, 2026
b379a7f
added api for cluster expansion
geoffrey1330 Jan 9, 2026
f5fa6d1
updated simplyblockstoragecluster crd
geoffrey1330 Jan 9, 2026
fdb74c1
added api for device remove and restart
geoffrey1330 Jan 9, 2026
f876a48
added param force
geoffrey1330 Jan 9, 2026
9a8a536
updated simplyblockdevice crd
geoffrey1330 Jan 9, 2026
e60b96a
Merge branch 'main' into improved_user_experience
geoffrey1330 Jan 9, 2026
f7c94b3
updated simplyblock manager image tag
geoffrey1330 Jan 12, 2026
5b4242c
make node_address param optional during snode restart via api
geoffrey1330 Jan 12, 2026
5c2f83a
remove the worker node from list upon node snode removal
geoffrey1330 Jan 12, 2026
788a07e
remove the worker node from list upon node snode removal
geoffrey1330 Jan 12, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,9 @@ dist
.ruff_cache
.env
.tox

# Ignore charts directory
simplyblock_core/scripts/charts/charts/

# Ignore Helm requirements lock file
simplyblock_core/scripts/charts/requirements.lock
41 changes: 31 additions & 10 deletions simplyblock_core/cluster_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def _create_update_user(cluster_id, grafana_url, grafana_secret, user_secret, up


def _add_graylog_input(cluster_ip, password):
base_url = f"http://{cluster_ip}/graylog/api"
base_url = f"{cluster_ip}/api"
input_url = f"{base_url}/system/inputs"

retries = 30
Expand Down Expand Up @@ -161,7 +161,7 @@ def _add_graylog_input(cluster_ip, password):

def _set_max_result_window(cluster_ip, max_window=100000):

url_existing_indices = f"http://{cluster_ip}/opensearch/_all/_settings"
url_existing_indices = f"{cluster_ip}/_all/_settings"

retries = 30
reachable=False
Expand All @@ -188,7 +188,7 @@ def _set_max_result_window(cluster_ip, max_window=100000):
logger.error(f"Failed to update settings for existing indices: {response.text}")
return False

url_template = f"http://{cluster_ip}/opensearch/_template/all_indices_template"
url_template = f"{cluster_ip}/_template/all_indices_template"
payload_template = json.dumps({
"index_patterns": ["*"],
"settings": {
Expand Down Expand Up @@ -317,8 +317,12 @@ def create_cluster(blk_size, page_size_in_blocks, cli_pass,
cluster.grafana_endpoint = grafana_endpoint
elif ingress_host_source == "hostip":
cluster.grafana_endpoint = f"http://{dev_ip}/grafana"
graylog_endpoint = f"http://{dev_ip}/graylog"
os_endpoint = f"http://{dev_ip}/opensearch"
else:
cluster.grafana_endpoint = f"http://{dns_name}/grafana"
graylog_endpoint = f"http://{dns_name}/graylog"
os_endpoint = f"http://{dns_name}/opensearch"
cluster.enable_node_affinity = enable_node_affinity
cluster.qpair_count = qpair_count or constants.QPAIR_COUNT
cluster.client_qpair_count = client_qpair_count or constants.CLIENT_QPAIR_COUNT
Expand Down Expand Up @@ -355,9 +359,10 @@ def create_cluster(blk_size, page_size_in_blocks, cli_pass,
if ingress_host_source == "hostip":
dns_name = dev_ip

_set_max_result_window(dns_name)

_set_max_result_window(os_endpoint)

_add_graylog_input(dns_name, monitoring_secret)
_add_graylog_input(graylog_endpoint, monitoring_secret)

_create_update_user(cluster.uuid, cluster.grafana_endpoint, monitoring_secret, cluster.secret)
if mode == "kubernetes":
Expand Down Expand Up @@ -433,12 +438,13 @@ def _run_fio(mount_point) -> None:

def add_cluster(blk_size, page_size_in_blocks, cap_warn, cap_crit, prov_cap_warn, prov_cap_crit,
distr_ndcs, distr_npcs, distr_bs, distr_chunk_bs, ha_type, enable_node_affinity, qpair_count,
max_queue_size, inflight_io_threshold, strict_node_anti_affinity, is_single_node, name, fabric="tcp",
cluster_ip=None, grafana_secret=None) -> str:
max_queue_size, inflight_io_threshold, strict_node_anti_affinity, is_single_node, name, cr_name=None,
cr_namespace=None, cr_plural=None, fabric="tcp", cluster_ip=None, grafana_secret=None) -> str:


default_cluster = None
monitoring_secret = os.environ.get("MONITORING_SECRET", "")
enable_monitoring = os.environ.get("ENABLE_MONITORING", "")
clusters = db_controller.get_clusters()
if clusters:
default_cluster = clusters[0]
Expand Down Expand Up @@ -471,16 +477,27 @@ def add_cluster(blk_size, page_size_in_blocks, cap_warn, cap_crit, prov_cap_warn
cluster.db_connection = fdb_cluster_string
if monitoring_secret:
cluster.grafana_secret = monitoring_secret
elif enable_monitoring != "true":
cluster.grafana_secret = ""
else:
raise Exception("monitoring_secret is required")
cluster.grafana_endpoint = "http://simplyblock-grafana:3000"
cluster.grafana_endpoint = constants.GRAFANA_K8S_ENDPOINT
if not cluster_ip:
cluster_ip = "0.0.0.0"

# add mgmt node object
mgmt_node_ops.add_mgmt_node(cluster_ip, "kubernetes", cluster.uuid)

_create_update_user(cluster.uuid, cluster.grafana_endpoint, cluster.grafana_secret, cluster.secret)
if enable_monitoring == "true":
graylog_endpoint = constants.GRAYLOG_K8S_ENDPOINT
os_endpoint = constants.OS_K8S_ENDPOINT
_create_update_user(cluster.uuid, cluster.grafana_endpoint, cluster.grafana_secret, cluster.secret)

_set_max_result_window(os_endpoint)

_add_graylog_input(graylog_endpoint, monitoring_secret)

if cluster.mode == "kubernetes":
utils.patch_prometheus_configmap(cluster.uuid, cluster.secret)

cluster.distr_ndcs = distr_ndcs
cluster.distr_npcs = distr_npcs
Expand All @@ -492,6 +509,10 @@ def add_cluster(blk_size, page_size_in_blocks, cap_warn, cap_crit, prov_cap_warn
cluster.qpair_count = qpair_count or constants.QPAIR_COUNT
cluster.max_queue_size = max_queue_size
cluster.inflight_io_threshold = inflight_io_threshold
cluster.cr_name = cr_name
cluster.cr_namespace = cr_namespace
cluster.cr_plural = cr_plural

if cap_warn and cap_warn > 0:
cluster.cap_warn = cap_warn
if cap_crit and cap_crit > 0:
Expand Down
9 changes: 9 additions & 0 deletions simplyblock_core/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,15 @@ def get_config_var(name, default=None):

LVO_MAX_NAMESPACES_PER_SUBSYS=32

CR_GROUP = "simplyblock.simplyblock.io"
CR_VERSION = "v1alpha1"

GRAFANA_K8S_ENDPOINT = "http://simplyblock-grafana:3000"
GRAYLOG_K8S_ENDPOINT = "http://simplyblock-graylog:9000"
OS_K8S_ENDPOINT = "http://opensearch-cluster-master:9200"

WEBAPI_K8S_ENDPOINT = "http://simplyblock-webappapi:5000/api/v2"

K8S_NAMESPACE = os.getenv('K8S_NAMESPACE', 'simplyblock')
OS_STATEFULSET_NAME = "simplyblock-opensearch"
MONGODB_STATEFULSET_NAME = "simplyblock-mongo"
Expand Down
18 changes: 18 additions & 0 deletions simplyblock_core/controllers/cluster_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from simplyblock_core.controllers import events_controller as ec
from simplyblock_core.db_controller import DBController
from simplyblock_core.models.events import EventObj
from simplyblock_core import utils, constants

logger = logging.getLogger()
db_controller = DBController()
Expand Down Expand Up @@ -39,6 +40,15 @@ def cluster_status_change(cluster, new_state, old_status):
caused_by=ec.CAUSED_BY_CLI,
message=f"Cluster status changed from {old_status} to {new_state}")

if cluster.mode == "kubernetes":
utils.patch_cr_status(
group=constants.CR_GROUP,
version=constants.CR_VERSION,
plural=cluster.cr_plural,
namespace=cluster.cr_namespace,
name=cluster.cr_name,
status_patch={"status": new_state})


def _cluster_cap_event(cluster, msg, event_level):
return ec.log_event_cluster(
Expand Down Expand Up @@ -90,3 +100,11 @@ def cluster_rebalancing_change(cluster, new_state, old_status):
db_object=cluster,
caused_by=ec.CAUSED_BY_CLI,
message=f"Cluster rebalancing changed from {old_status} to {new_state}")
if cluster.mode == "kubernetes":
utils.patch_cr_status(
group=constants.CR_GROUP,
version=constants.CR_VERSION,
plural=cluster.cr_plural,
namespace=cluster.cr_namespace,
name=cluster.cr_name,
status_patch={"rebalancing": new_state})
20 changes: 20 additions & 0 deletions simplyblock_core/controllers/device_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

from simplyblock_core.controllers import events_controller as ec
from simplyblock_core.db_controller import DBController
from simplyblock_core.models.nvme_device import NVMeDevice
from simplyblock_core import utils, constants

logger = logging.getLogger()

Expand All @@ -20,6 +22,24 @@ def _device_event(device, message, caused_by, event):
node_id=device.get_id(),
storage_id=device.cluster_device_order)

cluster = db_controller.get_cluster_by_id(snode.cluster_id)
if cluster.mode == "kubernetes":
total_devices = len(snode.nvme_devices)
online_devices = 0
for dev in snode.nvme_devices:
if dev.status == NVMeDevice.STATUS_ONLINE:
online_devices += 1
utils.patch_cr_node_status(
group=constants.CR_GROUP,
version=constants.CR_VERSION,
plural=snode.cr_plural,
namespace=snode.cr_namespace,
name=snode.cr_name,
node_uuid=snode.get_id(),
node_mgmt_ip=snode.mgmt_ip,
updates={"devices": f"{total_devices}/{online_devices}"},
)


def device_create(device, caused_by=ec.CAUSED_BY_CLI):
_device_event(device, f"Device created: {device.get_id()}", caused_by, ec.EVENT_OBJ_CREATED)
Expand Down
76 changes: 75 additions & 1 deletion simplyblock_core/controllers/lvol_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@

from simplyblock_core.controllers import events_controller as ec
from simplyblock_core.db_controller import DBController
from simplyblock_core import utils, constants

logger = logging.getLogger()


def _lvol_event(lvol, message, caused_by, event):
db_controller = DBController()
snode = db_controller.get_storage_node_by_id(lvol.node_id)
cluster = db_controller.get_cluster_by_id(snode.cluster_id)
ec.log_event_cluster(
cluster_id=snode.cluster_id,
domain=ec.DOMAIN_CLUSTER,
Expand All @@ -18,7 +20,79 @@ def _lvol_event(lvol, message, caused_by, event):
caused_by=caused_by,
message=message,
node_id=lvol.get_id())

if cluster.mode == "kubernetes":
pool = db_controller.get_pool_by_id(lvol.pool_uuid)

if event == ec.EVENT_OBJ_CREATED:
crypto_key=(
(lvol.crypto_key1, lvol.crypto_key2)
if lvol.crypto_key1 and lvol.crypto_key2
else None
)

node_urls = [
f"{constants.WEBAPI_K8S_ENDPOINT}/clusters/{snode.cluster_id}/storage-nodes/{node_id}/"
for node_id in lvol.nodes
]

utils.patch_cr_lvol_status(
group=constants.CR_GROUP,
version=constants.CR_VERSION,
plural=pool.lvols_cr_plural,
namespace=pool.lvols_cr_namespace,
name=pool.lvols_cr_name,
add={
"uuid": lvol.get_id(),
"lvolName": lvol.lvol_name,
"status": lvol.status,
"nodeUUID": node_urls,
"size": utils.humanbytes(lvol.size),
"health": lvol.health_check,
"isCrypto": crypto_key is not None,
"nqn": lvol.nqn,
"subsysPort": lvol.subsys_port,
"hostname": lvol.hostname,
"fabric": lvol.fabric,
"ha": lvol.ha_type == 'ha',
"poolUUID": lvol.pool_uuid,
"poolName": lvol.pool_name,
"PvcName": lvol.pvc_name,
"snapName": lvol.snapshot_name,
"clonedFromSnap": lvol.cloned_from_snap,
"stripeWdata": lvol.ndcs,
"stripeWparity": lvol.npcs,
"blobID": lvol.blobid,
"namespaceID": lvol.ns_id,
"qosClass": lvol.lvol_priority_class,
"maxNamespacesPerSubsystem": lvol.max_namespace_per_subsys,
"qosIOPS": lvol.rw_ios_per_sec,
"qosRWTP": lvol.rw_mbytes_per_sec,
"qosRTP": lvol.r_mbytes_per_sec,
"qosWTP": lvol.w_mbytes_per_sec,
},
)

elif event == ec.EVENT_STATUS_CHANGE:
utils.patch_cr_lvol_status(
group=constants.CR_GROUP,
version=constants.CR_VERSION,
plural=pool.lvols_cr_plural,
namespace=pool.lvols_cr_namespace,
name=pool.lvols_cr_name,
lvol_uuid=lvol.get_id(),
updates={"status": lvol.status, "health": lvol.health_check},
)
elif event == ec.EVENT_OBJ_DELETED:
logger.info("Deleting lvol CR object")
utils.patch_cr_lvol_status(
group=constants.CR_GROUP,
version=constants.CR_VERSION,
plural=pool.lvols_cr_plural,
namespace=pool.lvols_cr_namespace,
name=pool.lvols_cr_name,
lvol_uuid=lvol.get_id(),
remove=True,
)

def lvol_create(lvol, caused_by=ec.CAUSED_BY_CLI):
_lvol_event(lvol, "LVol created", caused_by, ec.EVENT_OBJ_CREATED)
Expand Down
22 changes: 20 additions & 2 deletions simplyblock_core/controllers/pool_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ def _generate_string(length):
string.ascii_letters + string.digits) for _ in range(length))


def add_pool(name, pool_max, lvol_max, max_rw_iops, max_rw_mbytes, max_r_mbytes, max_w_mbytes, cluster_id, qos_host=None):
def add_pool(name, pool_max, lvol_max, max_rw_iops, max_rw_mbytes, max_r_mbytes, max_w_mbytes, cluster_id,
cr_name=None, cr_namespace=None, cr_plural=None, qos_host=None):
db_controller = DBController()
if not name:
logger.error("Pool name is empty!")
Expand Down Expand Up @@ -71,6 +72,9 @@ def add_pool(name, pool_max, lvol_max, max_rw_iops, max_rw_mbytes, max_r_mbytes,
pool.max_rw_mbytes_per_sec = max_rw_mbytes
pool.max_r_mbytes_per_sec = max_r_mbytes
pool.max_w_mbytes_per_sec = max_w_mbytes
pool.cr_name = cr_name
pool.cr_namespace = cr_namespace
pool.cr_plural = cr_plural
if pool.has_qos() and not qos_host:
next_nodes = lvol_controller._get_next_3_nodes(cluster_id)
if next_nodes:
Expand Down Expand Up @@ -121,7 +125,8 @@ def qos_exists_on_child_lvol(db_controller: DBController, pool_uuid):
return False

def set_pool(uuid, pool_max=0, lvol_max=0, max_rw_iops=0,
max_rw_mbytes=0, max_r_mbytes=0, max_w_mbytes=0, name=""):
max_rw_mbytes=0, max_r_mbytes=0, max_w_mbytes=0, name="",
lvols_cr_name="", lvols_cr_namespace="", lvols_cr_plural=""):
db_controller = DBController()
try:
pool = db_controller.get_pool_by_id(uuid)
Expand All @@ -143,6 +148,17 @@ def set_pool(uuid, pool_max=0, lvol_max=0, max_rw_iops=0,
return False, msg
pool.pool_name = name

if lvols_cr_name and lvols_cr_name != pool.lvols_cr_name:
for p in db_controller.get_pools():
if p.lvols_cr_name == lvols_cr_name:
msg = f"Pool found with the same lvol cr name: {name}"
logger.error(msg)
return False, msg
pool.lvols_cr_name = lvols_cr_name
pool.lvols_cr_namespace = lvols_cr_namespace
pool.lvols_cr_plural = lvols_cr_plural


# Normalize inputs
max_rw_iops = max_rw_iops or 0
max_rw_mbytes = max_rw_mbytes or 0
Expand Down Expand Up @@ -265,8 +281,10 @@ def set_status(pool_id, status):
except KeyError:
logger.error(f"Pool not found {pool_id}")
return False
old_status = pool.status
pool.status = status
pool.write_to_db(db_controller.kv_store)
pool_events.pool_status_change(pool, pool.status, old_status)
logger.info("Done")


Expand Down
24 changes: 23 additions & 1 deletion simplyblock_core/controllers/pool_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
import logging

from simplyblock_core.controllers import events_controller as ec

from simplyblock_core.db_controller import DBController
from simplyblock_core import utils, constants

logger = logging.getLogger()

Expand All @@ -29,3 +30,24 @@ def pool_remove(pool):
def pool_updated(pool):
_add(pool, f"Pool updated {pool.pool_name}", event=ec.EVENT_STATUS_CHANGE)


def pool_status_change(pool, new_state, old_status):
db_controller = DBController()
cluster = db_controller.get_cluster_by_id(pool.cluster_id)
ec.log_event_cluster(
cluster_id=pool.cluster_id,
domain=ec.DOMAIN_CLUSTER,
event=ec.EVENT_STATUS_CHANGE,
db_object=pool,
caused_by=ec.CAUSED_BY_CLI,
message=f"Pool status changed from {old_status} to {new_state}",
node_id=pool.cluster_id)

if cluster.mode == "kubernetes":
utils.patch_cr_status(
group=constants.CR_GROUP,
version=constants.CR_VERSION,
plural=pool.cr_plural,
namespace=pool.cr_namespace,
name=pool.cr_name,
status_patch={"status": new_state})
Loading
Loading