oc + bash - 如何使用 "oc exec" 在 Openshift pod 中执行本地函数?

oc + bash - How to execute a local function in Openshift pod with "oc exec"?

我想在 Openshift 的每个 pod 中的脚本中执行一个本地函数。

function1() {
    ...
}

function2() {
    ...
}

verify() {
    ... # the function I want to execute in each pod
}

main() {
    # : openshift host
    if ! oc projects > /dev/null; then
        oc logout
        oc login ""
    fi
 
    while IFS= read -r project;
    do
        oc project $project
        while IFS= read -r pod;
        do
            echo Check pod $pod
            type verify # here it says it's a function
            ## how do we put it here?? this does not work, nothing happens, it just hangs. I expect "type verify" to be a function in the pod, just like above
            oc exec $pod -- bash -s "export -f function1; export -f function2; export -f verify; type verify; verify" 
        done <<< $(oc get pods | awk '/broker*/ {print }')
    done <<< $(oc projects | awk '{ some logic here }')
}

setup "$@"
main "$@"

我知道:

但是现在是本地函数,我不知道。

ssh 一样,typeset 将使您的函数在远程 pod 上可用。 oc exec $pod -- bash -c "$(typeset -f function1); function1"