kbase / service_wizard2

service_wizard2
MIT License
0 stars 0 forks source link

Service Wizard 2

codecov

The service wizard manages the lifecycle of "dynamic services" in KBase. The previous service wizard talked directly to rancher1, this one talks directly to kubernetes. Dynamic services are responsible for providing data and/or UI components for the KBase UI and Narrative.

Known issues

Environment Variables

The following environment variables are used to configure the application. Ensure that all the required environment variables are properly set before running the application. See .env file for example

Required Environment Variables

Client URLs

Service Wizard URLs

SW Admin Stuff

Kubernetes configs

NOTE THAT setting the KUBECONFIG environment variable will have no effect when USE_INCLUSTER_CONFIG is set to " true". The application will automatically use the in-cluster configuration provided by the underlying infrastructure. If you want to use an external configuration file, ensure that USE_INCLUSTER_CONFIG is set to "false" and provide the path to the configuration file using the KUBECONFIG environment variable.

NOTE THAT setting NAMESPACE also creates a toleration V1Toleration(effect="NoSchedule", key=namespace, operator="Exists")

Optional Environment Variables

Telemetry and Miscellaneous configs

Code Review Request

Local Development

This repo uses a pipenv to manage dependencies. To install pipenv, run pip install pipenv To install dependencies, run

pipenv --python 3.11-service_wizard2
pipenv install --dev
pipenv shell

To start the server, run

PYTHONPATH=.:src uvicorn --host 0.0.0.0 --factory factory:create_app --reload --port 1234```

To install pre-commit hook and test it

pre-commit install pre-commit run --all-files


Convenience scripts are provided in the [scripts](scripts) directory to setup the pipenv environment and install
dependencies.

In order to connect to a kubernetes cluster, you will need to have a kubeconfig file in your home directory.
The kubeconfig file is typically located at `~/.kube/config`.
Read more about kubeconfig
files [here](https://kubernetes.io/docs/concepts/configuration/organize-cluster-access-kubeconfig/).
Ensure that your context is set to the correct cluster and namespace and matches the environmental variables in
the [env](test/.env) file.

# PYCHARM

You can run the service in pycharm as well, but you will need to set the following parameters in the run configuration:

parameters = `PYTHONPATH=.:src uvicorn --host 0.0.0.0 --factory factory:create_app --reload --port 1234`
## Usage

OpenAPI documentation is provided at the `/docs` endpoint of the server (in KBase, this is
at `<host>/service/service_wizard2/docs`, for example
[https://ci.kbase.us/services/service_wizard2/docs](https://ci.kbase.us/services/service_wizard2/docs)).

However, the RPC endpoints are not documented. See the [original service wizard spec](documentation/ServiceWizard_Artifacts/ServiceWizard.spec) for details on how to use the endpoint.

### Error codes

Errors are return as JSONRPC errors.

## Administration

* Ensure the approproiate kubernetes roles/rolebindings/ are in place for the service account
  used by the service.
* Ensure that the namespace is created for both the Service Wizard and the Dynamic Services.
* Ensure that the environment is properly configured for the service.

## File structure

* `/src/clients` - KBase and Kubernetes clients with caches
* `/src/configs` - the configuration for the app
* `/src/dependencies` - shared service code
* `/src/models` - models for the app returns, logic for calculating service status, other models
* `/src/routes` - the routes for the app
* `/src/rpc` - the RPC endpoints for the app and common code
* `/test/src` - test code. Subdirectories should mirror the folder structure above, e.g.
* `/test/ServiceWizard_Artifacts` - the original Service Wizard related code

## Development
* Update the release notes in the [RELEASE_NOTES.md](RELEASE_NOTES.md) file.
* You can run the app via `docker-compose.yaml`
* You can update your credentials in your `kubeconfig` to deploy and launch the app in Rancher2 Desktop

### Running tests

Python 3.11 must be installed on the system.

pipenv sync --dev # only the first time or when Pipfile.lock changes pipenv shell PYTHONPATH=. pytest test