<jupyter_start><jupyter_text>Operator Upgrade Tests  Setup Seldon CoreFollow the instructions to [Setup Cluster](seldon_core_setup.ipynbSetup-Cluster) with [Ambassador Ingress](seldon_core_setup.ipynbAmbassador) and [Install Seldon Core](seldon_core_setup.ipynbInstall-Seldon-Core).<jupyter_code>!kubectl create namespace seldon
!kubectl config set-context $(kubectl config current-context) --namespace=seldon
import time
import json<jupyter_output><empty_output><jupyter_text>Install Stable Version<jupyter_code>!kubectl create namespace seldon-system
!helm upgrade seldon-core seldon-core-operator --repo https://storage.googleapis.com/seldon-charts --namespace seldon-system --set istio.enabled=true --wait<jupyter_output><empty_output><jupyter_text>Launch a Range of Models<jupyter_code>!kubectl create -f resources/model.yaml
!kubectl create -f ../servers/sklearnserver/samples/iris.yaml
!kubectl create -f ../servers/tfserving/samples/halfplustwo_rest.yaml
!kubectl create -f ../examples/models/payload_logging/model_logger.yaml
#!kubectl apply -f resources/income_explainer.yaml<jupyter_output><empty_output><jupyter_text>Wait for all models to be available<jupyter_code>def waitStatus(desired):
    for i in range(120):
        allAvailable = True
        failedGet = False
        state=!kubectl get sdep -o json
        state=json.loads("".join(state))
        for model in state["items"]:
            if "status" in model:
                print("model",model["metadata"]["name"],model["status"]["state"])
                if model["status"]["state"]!="Available":
                    allAvailable=False
                    break
            else:
                failedGet = True
        if allAvailable == desired and not failedGet:
            break
        time.sleep(1)
    return allAvailable
actual = waitStatus(True)
assert(actual==True)<jupyter_output><empty_output><jupyter_text>Count the number of resources<jupyter_code>def getOwned(raw):
    count = 0
    for res in raw["items"]:
        if "ownerReferences" in res["metadata"] and res["metadata"]["ownerReferences"][0]["kind"]=="SeldonDeployment":
            count += 1
    return count

def getResourceStats():
    #Get number of deployments
    dps=!kubectl get deployment -o json
    dps=json.loads("".join(dps))
    numDps = getOwned(dps)
    print("Number of deployments owned",numDps)

    #Get number of services
    svcs=!kubectl get svc -o json
    svcs=json.loads("".join(svcs))
    numSvcs = getOwned(svcs)
    print("Number of services owned",numSvcs)

    #Get number of virtual services
    vss=!kubectl get vs -o json
    vss=json.loads("".join(vss))
    numVs = getOwned(vss)
    print("Number of virtual services owned",numVs)

    #Get number of hpas
    hpas=!kubectl get hpa -o json
    hpas=json.loads("".join(hpas))
    numHpas = getOwned(hpas)
    print("Number of hpas owned",numHpas)
    
    return (numDps, numSvcs, numVs, numHpas)
    
(dp1,svc1,vs1,hpa1) = getResourceStats()<jupyter_output><empty_output><jupyter_text>Upgrade to latest<jupyter_code>!helm upgrade seldon-core ../helm-charts/seldon-core-operator --namespace seldon-system --set istio.enabled=true --wait
actual = waitStatus(False)
assert(actual==False)
actual = waitStatus(True)
assert(actual==True)
#Give time for resources to terminate
for i in range(120):
    (dp2,svc2,vs2,hpa2) = getResourceStats()
    if dp1==dp2 and svc1==svc2 and vs1==vs2 and hpa1==hpa2:
        break
    time.sleep(1)
assert(dp1==dp2)
assert(svc1==svc2)
assert(vs1==vs2)
assert(hpa1==hpa2)
!kubectl delete sdep --all<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11936560934891485, 'fraction_numerical': 0.009738452977184196, 'mean_word_length': 4.042075736325386, 'pattern_counts': {'":': 2, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '135235', 'license': 'Apache-2.0', 'n_tokens_mistral': 1249, 'n_tokens_neox': 1219, 'n_words': 263, 'path': 'notebooks/operator_upgrade.ipynb', 'repo_name': 'xaniasd/seldon-core', 'size': '3594'}