我在Kubernetes集群中创建了一个变异的准入webhook。api突变webhook为部署YAML增加了容忍度。但是,它显示一个错误Internal error occurred: jsonpatch add operation does not apply: doc is missing path: "/spec/template/spec/tolerations/"
我的Yaml示例文件:
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
namespace: webhook
labels:
app: nginx
spec:
replicas: 1
selector:
matchLabels:
app: nginx
strategy:
rollingUpdate:
maxSurge: 100%
maxUnavailable: 50%
type: RollingUpdate
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: "nginx:1.17"
imagePullPolicy: Always
ports:
- containerPort: 80
name: nginxPython代码:
mutations = []
mutations.append({"op": "add", "path": "/spec/template/spec/tolerations/" + str(counter),
"value": {key: t[key]}})但是,在测试时出现上述错误。请帮帮忙。:(
发布于 2021-10-19 13:29:27
我看不到整个文件,因此我无法更正它。但是问题出在您的路径上,您可能正在链接一个数组--您必须指定一个索引。当您想要在数组的末尾添加一个元素时,可以像这样使用-1:spec/template/spec/containers/0/env/-1
看一下这个例子
...
spec:
template:
spec:
containers: # this is an array, there is 0 in the path
- name: somename
image: someimage
env: # another array, we are putting the element at the end, therefore index is -1
- name: SOME_VALUE_0
value: "foo"
- name: SOME_VALUE_1
value: "bar"
# I want to add second env variable SOME_VALUE_2 here
...kustomization.yamlapiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- ../link/to/your/yaml
patchesJson6902:
- target:
...
patch: |-
- op: "add"
path: "/spec/jobTemplate/spec/template/spec/containers/0/env/-1"
value: {name: "SOME_VALUE_2", value: "baz"}https://stackoverflow.com/questions/62171048
复制相似问题