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
22 changes: 11 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
.PHONY: install build lint pyinstaller clean

venv:
python3 -m venv venv
.venv:
python3 -m venv .venv

clean:
rm -rf venv
rm -rf .venv

install: venv
. venv/bin/activate && python -m pip install --editable .[dev]
install: .venv
. .venv/bin/activate && python -m pip install --editable .[dev]

build: venv
build: .venv
rm -f README.rst
. venv/bin/activate && python -m build
. .venv/bin/activate && python -m build

# Note: "make install" needs to be ran once before this target will work, but we
# don't want to set it as a dependency otherwise it unnecessarily slows down
# fast implement/test cycles. "make install" created an editable install of the
# package which is linked to the files you are editing so there is no need to
# re-install after each change.
unit-test:
. venv/bin/activate && pytest test/src/mock
. .venv/bin/activate && pytest test/src/mock

lint: venv
lint: .venv
rm -f README.rst
. venv/bin/activate && flake8 src --count --select=E9,F63,F7,F82 --show-source --statistics && flake8 src --count --exit-zero --max-complexity=10 --max-line-length=200 --statistics
. .venv/bin/activate && flake8 src --count --select=E9,F63,F7,F82 --show-source --statistics && flake8 src --count --exit-zero --max-complexity=10 --max-line-length=200 --statistics

pyinstaller: venv
rm -f README.rst
. venv/bin/activate && pyinstaller src/mas-upgrade --onefile --noconfirm --add-data="src/mas/devops/templates/ibm-mas-tekton.yaml:mas/devops/templates" --add-data="src/mas/devops/templates/subscription.yml.j2:mas/devops/templates/" --add-data="src/mas/devops/templates/pipelinerun-upgrade.yml.j2:mas/devops/templates/"
. .venv/bin/activate && pyinstaller src/mas-upgrade --onefile --noconfirm --add-data="src/mas/devops/templates/ibm-mas-tekton.yaml:mas/devops/templates" --add-data="src/mas/devops/templates/subscription.yml.j2:mas/devops/templates/" --add-data="src/mas/devops/templates/pipelinerun-upgrade.yml.j2:mas/devops/templates/"
56 changes: 56 additions & 0 deletions src/mas/devops/aiservice.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# *****************************************************************************
# Copyright (c) 2025 IBM Corporation and other Contributors.
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-v10.html
#
# *****************************************************************************

import logging
from openshift.dynamic import DynamicClient
from openshift.dynamic.exceptions import NotFoundError, ResourceNotFoundError, UnauthorizedError

from .ocp import listInstances
from .olm import getSubscription

logger = logging.getLogger(__name__)


def listAiServiceInstances(dynClient: DynamicClient) -> list:
"""
Get a list of AI Service instances on the cluster
"""
return listInstances(dynClient, "aiservice.ibm.com/v1", "AIServiceApp")


def verifyAiServiceInstance(dynClient: DynamicClient, instanceId: str) -> bool:
"""
Validate that the chosen AI Service instance exists
"""
try:
aiserviceAPI = dynClient.resources.get(api_version="aiservice.ibm.com/v1", kind="AIServiceApp")
aiserviceAPI.get(name=instanceId, namespace=f"aiservice-{instanceId}")
return True
except NotFoundError:
print("NOT FOUND")
return False
except ResourceNotFoundError:
# The AIServiceApp CRD has not even been installed in the cluster
print("RESOURCE NOT FOUND")
return False
except UnauthorizedError as e:
logger.error(f"Error: Unable to verify AI Service instance due to failed authorization: {e}")
return False


def getAiserviceChannel(dynClient: DynamicClient, instanceId: str) -> str:
"""
Get the AI Service channel from the subscription
"""
aiserviceSubscription = getSubscription(dynClient, f"aiservice-{instanceId}", "ibm-aiservice")
if aiserviceSubscription is None:
return None
else:
return aiserviceSubscription.spec.channel
Loading