-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Don't create PVCs if no default StorageClass is set #2679
Merged
k8s-ci-robot
merged 13 commits into
kubeflow:master
from
arrikto:feature-webapp-storageclass
Mar 20, 2019
Merged
Changes from 8 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
6d0d838
Check for default StorageClass
kimwnasptd 6916851
Add helper functions
kimwnasptd 5bdd961
Handle the token from the html
kimwnasptd 2461d63
Fix sharp corners
kimwnasptd a375798
Use client for creating pvcs
kimwnasptd 050e37d
Refactor code. Cleanup post_notebook()
kimwnasptd 9a244f7
Add permissions to list storage classes
kimwnasptd 254c49b
Add logging
kimwnasptd 38aeb64
Reorganize code
kimwnasptd ddd6f23
Update the Dockerfile
kimwnasptd 6ebb370
Add prodonjs and avdaredevil as Reviewers
kimwnasptd 5c4ae93
Add comments
kimwnasptd 80846f3
Sort OWNERS
kimwnasptd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,9 @@ | |
import json | ||
from kubernetes import client, config | ||
from kubernetes.config import ConfigException | ||
from kubeflow.jupyter.utils import create_logger | ||
|
||
logger = create_logger(__name__) | ||
|
||
try: | ||
# Load configuration inside the Pod | ||
|
@@ -13,6 +16,7 @@ | |
# Create the Apis | ||
v1_core = client.CoreV1Api() | ||
custom_api = client.CustomObjectsApi() | ||
storage_api = client.StorageV1Api() | ||
|
||
|
||
def parse_error(e): | ||
|
@@ -26,10 +30,79 @@ def parse_error(e): | |
return err | ||
|
||
|
||
def create_workspace_pvc(body): | ||
"""If the type is New, then create a new PVC, else use an existing one""" | ||
if body["ws_type"] == "New": | ||
pvc = client.V1PersistentVolumeClaim( | ||
metadata=client.V1ObjectMeta( | ||
name=body['ws_name'], | ||
namespace=body['ns'] | ||
), | ||
spec=client.V1PersistentVolumeClaimSpec( | ||
access_modes=[body['ws_access_modes']], | ||
resources=client.V1ResourceRequirements( | ||
requests={ | ||
'storage': body['ws_size'] + 'Gi' | ||
} | ||
) | ||
) | ||
) | ||
|
||
create_pvc(pvc) | ||
|
||
return | ||
|
||
|
||
def create_datavol_pvc(body, i): | ||
pvc_nm = body['vol_name' + i] | ||
|
||
# Create a PVC if its a new Data Volume | ||
if body["vol_type" + i] == "New": | ||
size = body['vol_size' + i] + 'Gi' | ||
mode = body['vol_access_modes' + i] | ||
|
||
pvc = client.V1PersistentVolumeClaim( | ||
metadata=client.V1ObjectMeta( | ||
name=pvc_nm, | ||
namespace=body['ns'] | ||
), | ||
spec=client.V1PersistentVolumeClaimSpec( | ||
access_modes=[mode], | ||
resources=client.V1ResourceRequirements( | ||
requests={ | ||
'storage': size | ||
} | ||
) | ||
) | ||
) | ||
|
||
create_pvc(pvc) | ||
|
||
return | ||
|
||
|
||
def get_secret(nm, ns): | ||
return v1_core.read_namespaced_secret(nm, ns) | ||
|
||
|
||
def get_default_storageclass(): | ||
strg_classes = storage_api.list_storage_class().items | ||
for strgclss in strg_classes: | ||
annotations = strgclss.metadata.annotations | ||
# List of possible annotations | ||
keys = [] | ||
keys.append("storageclass.kubernetes.io/is-default-class") | ||
keys.append("storageclass.beta.kubernetes.io/is-default-class") # GKE | ||
|
||
for key in keys: | ||
is_default = annotations.get(key, False) | ||
if is_default: | ||
return strgclss.metadata.name | ||
|
||
# No StorageClass is default | ||
return "" | ||
|
||
|
||
def get_namespaces(): | ||
nmsps = v1_core.list_namespace() | ||
return [ns.metadata.name for ns in nmsps.items] | ||
|
@@ -60,5 +133,5 @@ def create_notebook(body): | |
|
||
|
||
def create_pvc(body): | ||
ns = body['metadata']['namespace'] | ||
ns = body.metadata.namespace | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So in this case body has actually changed from a dict to an object. Again, having no context it may be helpful to have some kind of comment or change the name of the param to reflect that it's not a deserialized JSON response as a dict but is not a typed object. |
||
return v1_core.create_namespaced_persistent_volume_claim(ns, body) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally I think there would be some kind of definition for the shape of the body dict being passed in, but since I have almost no context of looking at this I'm not going to be picky.