Skip to content

Commit

Permalink
feat: set a few additional envvars to pass context to apps (#20)
Browse files Browse the repository at this point in the history
* feat: set a few additional envvars to pass context to apps

* fix: include NDSLABS_DOMAIN (for Dataverse + TwoRavens)

* fix: include NDSLABS_EMAIL (for DSpace)
  • Loading branch information
bodom0015 authored Jan 17, 2024
1 parent 09454be commit 909cf85
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
4 changes: 3 additions & 1 deletion api/v1/user_apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ def to_spec_map(specs, existing_map=None):


def create_userapp(stack, user, token_info):
logger.info('token_info=%s' % token_info)
username = kube.get_username(user)
user_email = token_info['email']
stack['creator'] = username
stack_id = generate_unique_id(user)
stack['id'] = stack['_id'] = stack_id
Expand All @@ -84,7 +86,7 @@ def create_userapp(stack, user, token_info):
kube.init_user(username=user)

# Create service(s) / ingress / deployment
kube.create_userapp(username=username, userapp=stack, spec_map=spec_map)
kube.create_userapp(username=username, email=user_email, userapp=stack, spec_map=spec_map)

# Save metadata to database
stack = data_store.create_userapp(stack)
Expand Down
11 changes: 9 additions & 2 deletions pkg/kube.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ def get_init_container(username, spec_key, svc_key):


# Creates the Kubernetes resources related to a userapp
def create_userapp(username, userapp, spec_map):
def create_userapp(username, email, userapp, spec_map):
namespace = get_resource_namespace(username)
containers = []
ingress_hosts = {}
Expand All @@ -501,7 +501,8 @@ def create_userapp(username, userapp, spec_map):
stack_service_id = get_stack_service_id(userapp_id, service_key)
resource_name = get_resource_name(get_username(username), userapp_id, service_key)
service_ports = app_spec['ports'] if 'ports' in app_spec else []
ingress_hosts[resource_name] = service_ports
if app_spec['access'] == 'external':
ingress_hosts[resource_name] = service_ports

# Build up config from userapp env/config and appspec config
configmap_data = stack_service['config'] if 'config' in stack_service else {}
Expand All @@ -520,6 +521,12 @@ def create_userapp(username, userapp, spec_map):
else:
configmap_data[cfg['name']] = cfg['value'] if 'value' in cfg else ''

configmap_data['NDSLABS_STACK'] = userapp_id
configmap_data['NDSLABS_USER'] = username
configmap_data['NDSLABS_EMAIL'] = email
configmap_data['NDSLABS_NAMESPACE'] = namespace
configmap_data['NDSLABS_SERVICE'] = stack_service['id']
configmap_data['NDSLABS_DOMAIN'] = config.DOMAIN
stack_service['config'] = configmap_data

# TODO: Support custom volume mounts?
Expand Down

0 comments on commit 909cf85

Please sign in to comment.