fairing icon indicating copy to clipboard operation
fairing copied to clipboard

name 'yaml' is not defined

Open kwonmha opened this issue 3 years ago • 2 comments

I'm running notebook- https://github.com/kubeflow/fairing/blob/master/examples/mnist/mnist_e2e_on_prem.ipynb And on the 4th cell

from kubernetes import client as k8s_client
from kubernetes import config as k8s_config
from kubeflow.fairing.utils import is_running_in_k8s

pv_yaml = f'''
apiVersion: v1
kind: PersistentVolume
metadata:
  name: {pv_name}
spec:
  capacity:
    storage: 10Gi
  accessModes:
  - ReadWriteMany
  persistentVolumeReclaimPolicy: Retain
  nfs:
    path: {nfs_path}
    server: {nfs_server}
'''
pvc_yaml = f'''
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: {pvc_name}
  namespace: {my_namespace}
spec:
  accessModes:
    - ReadWriteMany
  storageClassName: ""
  resources:
    requests:
      storage: 10Gi
'''

if is_running_in_k8s():
    k8s_config.load_incluster_config()
else:
    k8s_config.load_kube_config()

k8s_core_api = k8s_client.CoreV1Api()
k8s_core_api.create_persistent_volume(yaml.safe_load(pv_yaml))
k8s_core_api.create_namespaced_persistent_volume_claim(my_namespace, yaml.safe_load(pvc_yaml))

It says

---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-10-da6a0e14757a> in <module>
     39 
     40 k8s_core_api = k8s_client.CoreV1Api()
---> 41 k8s_core_api.create_persistent_volume(yaml.safe_load(pv_yaml))
     42 k8s_core_api.create_namespaced_persistent_volume_claim(my_namespace, yaml.safe_load(pvc_yaml))

NameError: name 'yaml' is not defined

What should I do?

Environment:

  • Fairing version: (use python -c "import kubeflow.fairing; print(kubeflow.fairing.__version__)"):
    1.0.2

  • Kubeflow version: (version number can be found at the bottom left corner of the Kubeflow dashboard): It says 'version dev_local'

  • Minikube version: I used microk8s

  • Kubernetes version: (use kubectl version):

Client Version: version.Info{Major:"1", Minor:"20+", GitVersion:"v1.20.4-34+1ae8c29bbb48f7", GitCommit:"1ae8c29bbb48f7a11f9b522538a707477322b3ab", GitTreeState:"clean", BuildDate:"2021-03-08T09:25:07Z", GoVersion:"go1.15.8", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"20+", GitVersion:"v1.20.4-34+1ae8c29bbb48f7", GitCommit:"1ae8c29bbb48f7a11f9b522538a707477322b3ab", GitTreeState:"clean", BuildDate:"2021-03-08T09:26:35Z", GoVersion:"go1.15.8", Compiler:"gc", Platform:"linux/amd64"}
  • OS (e.g. from /etc/os-release):
NAME="Ubuntu"
VERSION="18.04.3 LTS (Bionic Beaver)"

NOTE: If you are using fair from master, please provide us the git commit hash.

kwonmha avatar Mar 17 '21 12:03 kwonmha

You need to add import yaml on the cell.

kwonmha avatar Mar 25 '21 10:03 kwonmha

And also msrestazure library is needed to run the notebook.

kwonmha avatar Mar 25 '21 11:03 kwonmha