-
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 all 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 |
---|---|---|
@@ -1,38 +1,10 @@ | ||
IMG = gcr.io/kubeflow-images-public/jupyter-web-app | ||
# Load the shared modules dir to PYTHONPATH | ||
MODULE_DIR := $(pwd) | ||
|
||
# List any changed files. We only include files in the notebooks directory. | ||
# because that is the code in the docker image. | ||
# In particular we exclude changes to the ksonnet configs. | ||
CHANGED_FILES := $(shell git diff-files --relative=components/jupyter-web-app) | ||
all: run-default | ||
|
||
ifeq ($(strip $(CHANGED_FILES)),) | ||
# Changed files is empty; not dirty | ||
# Don't include --dirty because it could be dirty if files outside the ones we care | ||
# about changed. | ||
GIT_VERSION := $(shell git describe --always) | ||
else | ||
GIT_VERSION := $(shell git describe --always)-dirty-$(shell git diff | shasum -a256 | cut -c -6) | ||
endif | ||
run-default: | ||
cd default && PYTHONPATH=${PYTHONPATH}:${MODULE_DIR} python run.py | ||
|
||
TAG := $(shell date +v%Y%m%d)-$(GIT_VERSION) | ||
all: build | ||
|
||
# To build without the cache set the environment variable | ||
# export DOCKER_BUILD_OPTS=--no-cache | ||
build: | ||
docker build ${DOCKER_BUILD_OPTS} -t $(IMG):$(TAG) . \ | ||
--build-arg kubeflowversion=$(shell git describe --abbrev=0 --tags) \ | ||
--label=git-verions=$(GIT_VERSION) | ||
docker tag $(IMG):$(TAG) $(IMG):latest | ||
@echo Built $(IMG):latest | ||
@echo Built $(IMG):$(TAG) | ||
|
||
# Build but don't attach the latest tag. This allows manual testing/inspection of the image | ||
# first. | ||
push: build | ||
gcloud docker -- push $(IMG):$(TAG) | ||
@echo Pushed $(IMG) with :$(TAG) tags | ||
|
||
push-latest: push | ||
gcloud container images add-tag --quiet $(IMG):$(TAG) $(IMG):latest --verbosity=info | ||
echo created $(IMG):latest | ||
run-rok: | ||
cd rok && PYTHONPATH=${PYTHONPATH}:${MODULE_DIR} python run.py |
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,4 +2,6 @@ approvers: | |
- ioandr | ||
- kimwnasptd | ||
reviewers: | ||
- avdaredevil | ||
- prodonjs | ||
- vkoukis |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
/__pycache__ |
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
### BaseUI: Shared functions and Utilities | ||
This module holds functions/configs that both the Default and Rok Jupyter UIs use. Each UI will need to handle its own routes. | ||
|
||
This module is loaded into the `default` and `rok` UIs with the `PYTHONPATH` environment variable. To test the UIs locally, use the corresponding `make` commands. |
Empty file.
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 |
---|---|---|
@@ -0,0 +1,144 @@ | ||
import json | ||
from kubernetes import client, config | ||
from kubernetes.config import ConfigException | ||
from baseui.utils import create_logger | ||
|
||
logger = create_logger(__name__) | ||
|
||
try: | ||
# Load configuration inside the Pod | ||
config.load_incluster_config() | ||
except ConfigException: | ||
# Load configuration for testing | ||
config.load_kube_config() | ||
|
||
# Create the Apis | ||
v1_core = client.CoreV1Api() | ||
custom_api = client.CustomObjectsApi() | ||
storage_api = client.StorageV1Api() | ||
|
||
|
||
def parse_error(e): | ||
try: | ||
err = json.loads(e.body)["message"] | ||
except json.JSONDecodeError: | ||
err = str(e) | ||
except KeyError: | ||
err = str(e) | ||
|
||
return err | ||
|
||
|
||
def create_workspace_pvc(body): | ||
# body: Dict (request 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): | ||
# body: Dict (request body) | ||
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): | ||
# nm: string | ||
# ns: string | ||
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] | ||
|
||
|
||
def get_notebooks(ns): | ||
# ns: string | ||
custom_api = client.CustomObjectsApi() | ||
|
||
notebooks = \ | ||
custom_api.list_namespaced_custom_object("kubeflow.org", "v1alpha1", | ||
ns, "notebooks") | ||
return [nb["metadata"]["name"] for nb in notebooks["items"]] | ||
|
||
|
||
def delete_notebook(nb, ns): | ||
# nb: Dict | ||
options = client.V1DeleteOptions() | ||
|
||
return \ | ||
custom_api.delete_namespaced_custom_object("kubeflow.org", "v1alpha1", | ||
ns, "notebooks", nb, options) | ||
|
||
|
||
def create_notebook(nb): | ||
# nb: Dict | ||
ns = nb["metadata"]["namespace"] | ||
return \ | ||
custom_api.create_namespaced_custom_object("kubeflow.org", "v1alpha1", | ||
ns, "notebooks", nb) | ||
|
||
|
||
def create_pvc(pvc): | ||
# pvc: V1PersistentVolumeClaim | ||
ns = pvc.metadata.namespace | ||
return v1_core.create_namespaced_persistent_volume_claim(ns, pvc) |
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.
Please alphabetically sort
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.
Done.
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.
Great! lgtm-ing