Skip to content

Commit 3141713

Browse files
authored
feat: support for private images, always pull on startup (#22)
* fix: "Always" pull images on startup * feat: allow for imagePullSecrets * fix: syntax error when building image_pull_secrets * fix: include NDSLABS_HOME variable in configmap * fix: testing adding imagePullSecrets * fix: working impl for imagEPullSecrets
1 parent 1b3ef7c commit 3141713

1 file changed

Lines changed: 24 additions & 2 deletions

File tree

pkg/kube.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,7 @@ def create_userapp(username, email, userapp, spec_map):
523523

524524
configmap_data['NDSLABS_STACK'] = userapp_id
525525
configmap_data['NDSLABS_USER'] = username
526+
configmap_data['NDSLABS_HOME'] = f'/home/{username}'
526527
configmap_data['NDSLABS_EMAIL'] = email
527528
configmap_data['NDSLABS_NAMESPACE'] = namespace
528529
configmap_data['NDSLABS_SERVICE'] = stack_service['id']
@@ -614,7 +615,15 @@ def create_userapp(username, email, userapp, spec_map):
614615

615616
service_account = backend_config['userapps']['service_account_name'] if 'userapps' in backend_config and 'service_account_name' in backend_config['userapps'] else None
616617

617-
# Create one deployment per-stack (start with 0 replicas, aka "Stopped")
618+
secrets = None
619+
logger.info(f'Parsing secrets: {str(app_spec)}')
620+
if 'image' in app_spec and 'secrets' in app_spec['image']:
621+
secrets = []
622+
for secret_name in app_spec['image']['secrets']:
623+
logger.info(f'Adding secret: {secret_name}')
624+
secrets.append({'name': secret_name})
625+
626+
# Create one deployment per-stack (start with 0 replicas, aka "Stopped")
618627
create_deployment(deployment_name=resource_name,
619628
namespace=namespace,
620629
replicas=0,
@@ -623,6 +632,7 @@ def create_userapp(username, email, userapp, spec_map):
623632
init_containers=init_containers,
624633
labels=svc_labels,
625634
containers=[container],
635+
image_pull_secrets=secrets,
626636
collocate=userapp_id if 'collocate' in app_spec and app_spec['collocate'] else False)
627637

628638
# Create one ingress per-stack
@@ -649,6 +659,15 @@ def create_userapp(username, email, userapp, spec_map):
649659

650660
if should_run_as_single_pod:
651661
service_account = backend_config['userapps']['service_account_name'] if 'userapps' in backend_config and 'service_account_name' in backend_config['userapps'] else None
662+
app_spec = spec_map.get(userapp_key, None)
663+
664+
secrets = None
665+
logger.info(f'Parsing secrets: {str(app_spec)}')
666+
if 'image' in app_spec and 'secrets' in app_spec['image']:
667+
secrets = []
668+
for secret_name in app_spec['image']['secrets']:
669+
logger.info(f'Adding secret: {secret_name}')
670+
secrets.append({ 'name': secret_name })
652671

653672
# No need to collocate, since all will run in single pod
654673
# Create one deployment per-stack (start with 0 replicas, aka "Stopped")
@@ -658,6 +677,7 @@ def create_userapp(username, email, userapp, spec_map):
658677
service_account=service_account,
659678
username=get_username(username),
660679
labels=labels,
680+
image_pull_secrets=secrets,
661681
# TODO: how to wait for deps in singlepod mode?
662682
# init_containers=init_containers,
663683
containers=containers)
@@ -951,7 +971,7 @@ def get_home_storage_class():
951971

952972
# Containers:
953973
# "busybox" -> { name, configmap, image, lifecycle, ports, command }
954-
def create_deployment(deployment_name, containers, labels, username, **kwargs):
974+
def create_deployment(deployment_name, containers, labels, username, image_pull_secrets, **kwargs):
955975
appv1 = client.AppsV1Api()
956976

957977
# TODO: Validation
@@ -1002,6 +1022,7 @@ def create_deployment(deployment_name, containers, labels, username, **kwargs):
10021022

10031023
# Build a podspec from given containers and other parameters
10041024
podspec = client.V1PodSpec(
1025+
image_pull_secrets=image_pull_secrets,
10051026
service_account_name=service_account_name,
10061027
volumes=shared_volumes,
10071028
init_containers=init_containers,
@@ -1040,6 +1061,7 @@ def create_deployment(deployment_name, containers, labels, username, **kwargs):
10401061
# TODO: support container.lifecycle?
10411062
lifecycle=container['lifecycle'] if 'lifecycle' in container else None,
10421063
image=get_image_string(container['image']),
1064+
image_pull_policy='Always',
10431065
ports=[
10441066
client.V1ContainerPort(
10451067
name='%s%s' % (port['protocol'] if 'protocol' in port else 'tcp', str(port['port'])),

0 commit comments

Comments
 (0)