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

feat: set a few additional envvars to pass context to apps #20

Merged
merged 4 commits into from
Jan 17, 2024
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
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