Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test https://github.com/projectsyn/reclass-rs #1087

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
[submodule "kapitan/reclass"]
path = kapitan/reclass
url = https://github.com/kapicorp/reclass.git
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ WORKDIR /kapitan
RUN apt-get update \
&& apt-get install --no-install-recommends -y \
curl \
build-essential
build-essential \
git \
rustc

ENV POETRY_VERSION=1.4.0
ENV VIRTUAL_ENV=/opt/venv
Expand Down
1 change: 0 additions & 1 deletion kapitan/reclass
Submodule reclass deleted from d220e8
36 changes: 36 additions & 0 deletions kapitan/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import logging
import os
import sys
from datetime import datetime
from functools import partial

import jsonschema
Expand All @@ -27,6 +28,16 @@
import reclass.core
from reclass.errors import NotFoundError, ReclassException

have_reclass_rs = False
try:
from reclass_rs import Reclass

# Configure reclass-rs to use as many threads as there are logical cores in the system
Reclass.set_thread_count(0)
have_reclass_rs = True
except ImportError:
print("Couldn't import reclass_rs, falling back to Python reclass", file=sys.stderr)

logger = logging.getLogger(__name__)

try:
Expand Down Expand Up @@ -350,6 +361,27 @@ def inventory_reclass(inventory_path, ignore_class_notfound=False):
for uri in ("nodes_uri", "classes_uri"):
reclass_config[uri] = os.path.normpath(os.path.join(inventory_path, reclass_config[uri]))

if have_reclass_rs:
r = Reclass(
nodes_path=reclass_config["nodes_uri"],
classes_path=reclass_config["classes_uri"],
ignore_class_notfound=ignore_class_notfound,
)

print("running reclass_rs", file=sys.stderr)
start = datetime.now()
try:
inv = r.inventory()
except ValueError as e:
logger.error(f"Inventory reclass_rs error: {e}")
raise InventoryError(e)
elapsed = datetime.now() - start
print(f"Inventory (reclass_rs) took {elapsed}", file=sys.stderr)

cached.inv = inv.as_dict()
return cached.inv

print("Falling back to Python reclass", file=sys.stderr)
try:
storage = reclass.get_storage(
reclass_config["storage_type"],
Expand All @@ -360,7 +392,11 @@ def inventory_reclass(inventory_path, ignore_class_notfound=False):
class_mappings = reclass_config.get("class_mappings") # this defaults to None (disabled)
_reclass = reclass.core.Core(storage, class_mappings, reclass.settings.Settings(reclass_config))

print("running reclass", file=sys.stderr)
start = datetime.now()
cached.inv = _reclass.inventory()
elapsed = datetime.now() - start
print(f"Inventory (reclass) took {elapsed}", file=sys.stderr)
except ReclassException as e:
if isinstance(e, NotFoundError):
logger.error("Inventory reclass error: inventory not found")
Expand Down
Loading
Loading