error: error executing jsonpath "{.contexts[?(@.name==\"\")].context.namespace}": Error executing template: <nil> is not array or slice and cannot be filtered. Printing more information for debugging the template:
template was:
{.contexts[?(@.name=="")].context.namespace}
object given to jsonpath engine was:
map[string]interface {}{"apiVersion":"v1", "clusters":interface {}(nil), "contexts":interface {}(nil), "current-context":"", "kind":"Config", "preferences":map[string]interface {}{}, "users":interface {}(nil)}
最佳答案
我也遇到这个问题了。它是在我将 kubectl 升级到较新版本后开始的。 就我而言,在我的 zsh 中,我有一个使用 POWERLEVEL_9K 插件的自定义提示,它显示当前的 k8s 集群/命名空间。 我的 ~/.zshrc 中的提示配置看起来像
POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(status root_indicator command_execution_time kubecontext background_jobs history time)
从那里删除 kubecontext 就可以了。
如果您想在提示中保留 k8s 信息,则需要修复主题中的模板。我之前使用的是 POWERLEVEL9K,切换到 POWERLEVEL10K 对我来说很有效。
关于zsh - 在 zsh 中执行任何命令时出现 jsonpath 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62084291/