Skip to content

Commit

Permalink
finish hook
Browse files Browse the repository at this point in the history
Signed-off-by: Viktor Kramarenko <[email protected]>
  • Loading branch information
ViktorKram committed Aug 29, 2024
1 parent ef55309 commit 05ab1b3
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 6 deletions.
29 changes: 23 additions & 6 deletions hooks/convert_block_device_names_to_selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,34 @@

import kubernetes

config = """
configVersion: v1
afterHelm: 10
"""

group = "storage.deckhouse.io"
plural = "lvmvolumegroups"
version = "v1alpha1"


def main(ctx: hook.Context):
kubernetes.config.load_incluster_config()

lvg_list: Any = kubernetes.client.CustomObjectsApi().list_cluster_custom_object(group="storage.deckhouse.io",
plural="lvmvolumegroups",
version="v1alpha1")
lvg_list: Any = kubernetes.client.CustomObjectsApi().list_cluster_custom_object(group=group,
plural=plural,
version=version)

for lvg in lvg_list["items"]:
bdNames: List[str] = lvg["spec"]["blockDeviceNames"]
lvg["spec"].pop("blockDeviceNames")
bd_names: List[str] = lvg["spec"]["blockDeviceNames"]
del lvg["spec"]["blockDeviceNames"]
lvg["spec"]["local"]["nodeName"] = lvg["status"]["nodes"][0]["name"]
lvg["spec"]["blockDeviceSelector"]["matchLabels"] = {""}
lvg["spec"]["blockDeviceSelector"]["matchLabels"]["kubernetes.io/hostname"] = lvg["spec"]["local"]["nodeName"]
lvg["spec"]["blockDeviceSelector"]["matchExpressions"][0]["key"] = "kubernetes.io/metadata.name"
lvg["spec"]["blockDeviceSelector"]["matchExpressions"][0]["operator"] = "in"
lvg["spec"]["blockDeviceSelector"]["matchExpressions"][0]["values"] = bd_names

kubernetes.client.CustomObjectsApi.patch_cluster_custom_object(group=group, plural=plural, version=version)


if __name__ == "__main__":
hook.run(main, config=config)
13 changes: 13 additions & 0 deletions images/agent/src/pkg/controller/lvm_volume_group_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,19 @@ func RunLVMVolumeGroupWatcherController(
// return reconcile.Result{}, nil
//}

log.Debug(fmt.Sprintf("[RunLVMVolumeGroupWatcherController] tries to add label %s to the LVMVolumeGroup %s", LVGMetadateNameLabelKey, cfg.NodeName))
added, err = addLVGLabelIfNeeded(ctx, cl, log, lvg, LVGMetadateNameLabelKey, lvg.Name)
if err != nil {
log.Error(err, fmt.Sprintf("[RunLVMVolumeGroupWatcherController] unable to add label %s to the LVMVolumeGroup %s", LVGMetadateNameLabelKey, lvg.Name))
return reconcile.Result{}, err
}

if added {
log.Debug(fmt.Sprintf("[RunLVMVolumeGroupWatcherController] successfully added label %s to the LVMVolumeGroup %s", LVGMetadateNameLabelKey, lvg.Name))
} else {
log.Debug(fmt.Sprintf("[RunLVMVolumeGroupWatcherController] no need to add label %s to the LVMVolumeGroup %s", LVGMetadateNameLabelKey, lvg.Name))
}

// We do this after BlockDevices validation and node belonging check to prevent multiple updates by all agents pods
bds, _ := sdsCache.GetDevices()
if len(bds) == 0 {
Expand Down

0 comments on commit 05ab1b3

Please sign in to comment.