Jack Moore

Email: jack(at)jmoore53.com
Project Updates

Fission Packages and Serverless

09 Jun 2022 » serverless, fisison, k8s

Well it started with re-installing and upgrading fission to 1.16.0 from 1.15.1.

Upgrading Fission

Make a note to update the PVC to use the correct storage class:

# Source: fission-all/templates/storagesvc/pvc.yaml
kind: PersistentVolumeClaim
apiVersion: v1
  name: fission-storage-pvc
    app: fission-storage
    chart: "fission-all-v1.16.0"
    release: "fission-v1-16-0"
  # This line below needed to be added or the PVC will sit in pending all confused
  # This is because I'm using openebs-hostpath as a storageClass
  storageClassName: openebs-hostpath
    - "ReadWriteOnce"
      storage: "8Gi"

Creating the Fission Environment, and Package

This is basically a straight rip from the documentation:

# Create the environment
fission env create --name pythonsrc --image fission/python-env:latest \
                     --builder fission/python-builder:latest \
                     --mincpu 40 --maxcpu 80 \
                     --minmemory 64 --maxmemory 128 \
                     --poolsize 2

mkdir sourcepkg
cd sourcepkg
touch __init__.py build.sh requirements.txt user.py
# Populate all the files with the necessary code.. See the documentation here: https://fission.io/docs/usage/function/package/
chmod +x build.sh

cd ../

zip -jr demo-src-pkg.zip sourcepkg/

fission package create --sourcearchive demo-src-pkg.zip --env pythonsrc --buildcmd "./build.sh"
# will return something like:
# Package 'demo-src-pkg-zip-oe1m' created

# ensure the package succeeded:
fission pkg info --name demo-src-pkg-zip-oe1m

# Create the function from the package
fission fn create --name srcpy --pkg demo-src-pkg-zip-oe1m --entrypoint "user.main"

# Test the function
fission fn test --name srcpy

# Step 3: look at nonsense user.py code, and profit

Python YAML Fix

This is where my true error was.. I had to disregard an error in the function.

# Running the user.py would return a warning which needed to be ignored...
# Below is the command with the output/debug trace:
$ python3 sourcepkg/user.py
sourcepkg/user.py:13: YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated, as the default Loader is unsafe. Please read https://msg.pyyaml.org/load for full detail
  a = yaml.dump(yaml.load(document))
a: 1
  c: 3
  d: 4

To fix this error that was causing so much pain, I had to update the python script (main function) to the following:

import sys
import yaml

document = """
  a: 1
    c: 3
    d: 4

def main():
    # The error was the document line, the line below would throw the warning about the yaml loader
    # a = yaml.dump(yaml.load(document))
    # The fix was to add the ", Loader=yaml.FullLoader" as an argument to the yaml.load function
    a = yaml.dump(yaml.load(document, Loader=yaml.FullLoader))
    return a


© Jack Moore