Skip to content

Commit

Permalink
fix: consolidate user pvc logic, ignore 409
Browse files Browse the repository at this point in the history
  • Loading branch information
bodom0015 committed Apr 24, 2023
1 parent f94d2eb commit b64df32
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 15 deletions.
14 changes: 1 addition & 13 deletions api/v1/user_apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,6 @@ def to_spec_map(specs, existing_map=None):
return spec_map


def ensure_create_home_pvc(user):
username = kube.get_username(user)

# Ensure user home PVC exists
pvc_name = kube.get_home_pvc_name(user)
storage_class = kube.get_home_storage_class()
try:
kube.create_persistent_volume_claim(pvc_name=pvc_name, namespace=kube.get_resource_namespace(username=username), storage_class=storage_class)
except Exception as e:
logger.warning(f'Failed to create home PVC for user={username}: ', str(e))
pass


def create_userapp(stack, user, token_info):
username = kube.get_username(user)
Expand All @@ -93,7 +81,7 @@ def create_userapp(stack, user, token_info):

try:
# Ensure that user's home PVC has been created
ensure_create_home_pvc(user=user)
kube.init_user(username=user)

# Create service(s) / ingress / deployment
kube.create_userapp(username=username, userapp=stack, spec_map=spec_map)
Expand Down
7 changes: 5 additions & 2 deletions pkg/kube.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,9 +442,12 @@ def initialize():

# Create necessary resources for a new user
def init_user(username):
username = get_username(username)
namespace = get_resource_namespace(username)
# resource_name = get_resource_name(get_username(username))

# Ensure user home PVC exists
pvc_name = get_home_pvc_name(username)
storage_class = get_home_storage_class()
if not is_single_namespace():
try:
create_namespace(namespace_name=namespace)
Expand All @@ -454,7 +457,7 @@ def init_user(username):
raise e

try:
create_persistent_volume_claim(namespace=namespace, pvc_name=username)
create_persistent_volume_claim(namespace=namespace, pvc_name=pvc_name, storage_class=storage_class)
except ApiException as e:
# Ignore conflict - creation of these resources is idempotent
if e.status != 409:
Expand Down

0 comments on commit b64df32

Please sign in to comment.