Skip to content
Merged
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: 3 additions & 0 deletions Deploy.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# deploying the ICRN kernel manager services

## get the most recent changes moved to campus cluster


## Changes needed to ICRN containers in dev


Expand Down
4 changes: 2 additions & 2 deletions documentation/catalog_resources/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ The central repository should be organized as follows:
```
central_repository/
├── icrn_kernel_catalog.json
├── r_kernels/
├── R/
│ ├── cowsay/
│ │ └── 1.0/
│ │ └── R_cowsay.conda.pack.tar.gz
│ ├── pecan/
│ │ └── 1.9/
│ │ └── PEcAn-base-3.tar.gz
│ └── ...
├── python_kernels/
├── Python/
│ ├── numpy/
│ │ └── 1.20/
│ │ └── python_numpy.conda.pack.tar.gz
Expand Down
129 changes: 119 additions & 10 deletions icrn_manager
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,11 @@ ICRN_USER_KERNEL_BASE=${ICRN_USER_KERNEL_BASE:-${ICRN_USER_BASE}/${icrn_kernels}
ICRN_USER_CATALOG=${ICRN_USER_CATALOG:-${ICRN_USER_KERNEL_BASE}/user_catalog.json}

if [ ! -e ${ICRN_MANAGER_CONFIG} ]; then
# if manager config json doesn't exist, we need to be in the 'init' call
if [ ! "$2" = "init" ]; then
echo "You must run 'icrn_manager kernels init' prior to leveraging this tool."
exit 1
fi
# if the config doesn't exist, it will be created and populated during the init call
# Note: Auto-initialization will be handled in kernels() function
# This section sets up default paths for when config doesn't exist yet
ICRN_KERNEL_REPOSITORY=$central_catalog_default
ICRN_R_KERNELS=${ICRN_KERNEL_REPOSITORY}"/r_kernels"
ICRN_PYTHON_KERNELS=${ICRN_KERNEL_REPOSITORY}"/python_kernels"
ICRN_R_KERNELS=${ICRN_KERNEL_REPOSITORY}"/R"
ICRN_PYTHON_KERNELS=${ICRN_KERNEL_REPOSITORY}"/Python"
ICRN_KERNEL_CATALOG=${ICRN_KERNEL_REPOSITORY}"/icrn_kernel_catalog.json"
else
ICRN_KERNEL_REPOSITORY=$(jq -r ".\"icrn_central_catalog_path\"" "${ICRN_MANAGER_CONFIG}")
Expand Down Expand Up @@ -846,6 +842,80 @@ function kernels__init() # create base resources
echo ""
echo "central catalog location will be: ${central_repository}"
echo ""

# Determine which paths will be affected
ICRN_MANAGER_CONFIG=${ICRN_MANAGER_CONFIG:-${ICRN_USER_BASE}/manager_config.json}

echo "The following paths will be created or modified:"
echo ""

local paths_to_create=()
local paths_to_overwrite=()

# Check ICRN_USER_BASE
if [ ! -e "${ICRN_USER_BASE}/" ]; then
paths_to_create+=("${ICRN_USER_BASE}/ (directory)")
fi

# Check ICRN_USER_KERNEL_BASE
if [ ! -e "${ICRN_USER_KERNEL_BASE}" ]; then
paths_to_create+=("${ICRN_USER_KERNEL_BASE} (directory)")
fi

# Check language-specific subdirectories
if [ ! -e "${ICRN_USER_KERNEL_BASE}/r" ]; then
paths_to_create+=("${ICRN_USER_KERNEL_BASE}/r (directory)")
fi

if [ ! -e "${ICRN_USER_KERNEL_BASE}/python" ]; then
paths_to_create+=("${ICRN_USER_KERNEL_BASE}/python (directory)")
fi

# Check ICRN_USER_CATALOG
if [ ! -e "${ICRN_USER_CATALOG}" ]; then
paths_to_create+=("${ICRN_USER_CATALOG} (file)")
fi

# Check ICRN_MANAGER_CONFIG
if [ ! -e "${ICRN_MANAGER_CONFIG}" ]; then
paths_to_create+=("${ICRN_MANAGER_CONFIG} (file)")
elif [ -n "$overwrite" ]; then
paths_to_overwrite+=("${ICRN_MANAGER_CONFIG} (file - will update central catalog path)")
fi

# Display paths that will be created
if [ ${#paths_to_create[@]} -gt 0 ]; then
echo "Paths that will be CREATED:"
for path in "${paths_to_create[@]}"; do
echo " - $path"
done
echo ""
fi

# Display paths that will be overwritten/modified
if [ ${#paths_to_overwrite[@]} -gt 0 ]; then
echo "Paths that will be MODIFIED:"
for path in "${paths_to_overwrite[@]}"; do
echo " - $path"
done
echo ""
fi

# If nothing will be created or modified, inform user
if [ ${#paths_to_create[@]} -eq 0 ] && [ ${#paths_to_overwrite[@]} -eq 0 ]; then
echo "All required paths already exist. No changes will be made."
echo ""
return 0
fi

# Ask for confirmation
read -r -p "Do you want to proceed with these changes? [y/N] " response
if [[ ! "$response" =~ ^([yY][eE][sS]|[yY])$ ]]; then
echo "Initialization cancelled."
exit 0
fi
echo ""

# check for existence of
#~{HOME}/.icrn/
#~{HOME}/.icrn/icrn_kernels/
Expand Down Expand Up @@ -895,8 +965,8 @@ function kernels__init() # create base resources
echo "creating ${ICRN_MANAGER_CONFIG}"
echo "{
\"icrn_central_catalog_path\": \"${central_repository}\",
\"icrn_r_kernels\": \"r_kernels\",
\"icrn_python_kernels\": \"python_kernels\",
\"icrn_r_kernels\": \"R\",
\"icrn_python_kernels\": \"Python\",
\"icrn_kernel_catalog\": \"icrn_kernel_catalog.json\"
}" > $ICRN_MANAGER_CONFIG
# non-append enables re-pointing of central repo via 'init' later
Expand Down Expand Up @@ -940,6 +1010,32 @@ function kernels__init() # create base resources
echo ""
}

# Check if initialization is needed and perform it automatically if required
#
# This function checks if the ICRN Manager has been initialized by verifying
# the existence of the manager configuration file. If not initialized, it
# automatically calls kernels__init with the default central repository path.
#
# Parameters:
# None
#
# Returns:
# 0 if initialization was performed, 1 if already initialized
#
# Side effects:
# - Calls kernels__init() if configuration is missing
# - Creates user directories and configuration files
function check_and_init_if_needed()
{
if [ ! -e "${ICRN_MANAGER_CONFIG}" ]; then
echo "ICRN Manager not initialized. Auto-initializing with default settings..."
echo ""
kernels__init
return 0
fi
return 1
}

# Main launcher function for kernel management subcommands.
#
# This function routes kernel-related subcommands to their respective handler functions.
Expand All @@ -961,6 +1057,19 @@ function kernels__init() # create base resources
function kernels() # launcher
{
local cmdname=$1; shift

# Auto-initialize if needed (skip for 'init' command itself)
if [ "$cmdname" != "init" ]; then
check_and_init_if_needed
# After auto-init, reload config variables since they may have changed
if [ -e "${ICRN_MANAGER_CONFIG}" ]; then
ICRN_KERNEL_REPOSITORY=$(jq -r ".\"icrn_central_catalog_path\"" "${ICRN_MANAGER_CONFIG}")
ICRN_R_KERNELS=${ICRN_KERNEL_REPOSITORY}"/"$(jq -r ".\"icrn_r_kernels\"" "${ICRN_MANAGER_CONFIG}")
ICRN_PYTHON_KERNELS=${ICRN_KERNEL_REPOSITORY}"/"$(jq -r ".\"icrn_python_kernels\"" "${ICRN_MANAGER_CONFIG}")
ICRN_KERNEL_CATALOG=${ICRN_KERNEL_REPOSITORY}"/"$(jq -r ".\"icrn_kernel_catalog\"" "${ICRN_MANAGER_CONFIG}")
fi
fi
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Auto-init triggers even with empty/missing subcommand

The kernels() function checks [ "$cmdname" != "init" ] before validating that cmdname is non-empty. When a user runs icrn_manager kernels without specifying a subcommand, cmdname is empty string, which doesn't equal "init", so check_and_init_if_needed() is called prompting for initialization. Only afterwards does the code check if cmdname is empty to display the help message. The empty command check at line 1073 should occur before the auto-initialization logic.

Fix in Cursor Fix in Web


if [ -z "$cmdname" ]; then
echo ""
echo Error: No subcommand specified.
Expand Down
Loading
Loading