客户端版本:v0.15.10
当 PatchType 为 MergePatchType 或 StrategicMergePatchType 时,无法从 Deployment nodeSelector 中删除 lebels?
这是原始 yaml 文件“test1.yaml”:
apiVersion: apps/v1beta2
kind: Deployment
metadata:
labels:
k8s-app: frontgateway
name: frontgateway
spec:
replicas: 1
selector:
matchLabels:
k8s-app: frontgateway
template:
metadata:
labels:
k8s-app: frontgateway
spec:
nodeSelector:
CLUSTER: WX
GROUP: IAD
补丁代码:
playLoadBytes,_ :=json.Marshal(unstructuredObj)
_,err=DynamicClient.Resource(mapping.Resource).Namespace(namespace).Patch(name,types.StrategicMergePatchType,playLoadBytes,metav1.PatchOptions{})
补丁yaml:
apiVersion: apps/v1beta2
kind: Deployment
metadata:
labels:
k8s-app: frontgateway
name: frontgateway
spec:
replicas: 1
selector:
matchLabels:
k8s-app: frontgateway
template:
metadata:
labels:
k8s-app: frontgateway
spec:
nodeSelector:
GROUP: IAD
当我从 test1.yaml 中删除“CLUSTER: WX”行并执行 patch() 方法时,部署资源仍然具有“CLUSTER: WX”标签,但添加新标签可以工作。
看了官方文档https://kubernetes.io/docs/tasks/manage-kubernetes-objects/update-api-object-kubectl-patch/,上面写着Notice that the tolerations list in the PodSpec was replaced, not merged. This is because the Tolerations field of PodSpec does not have a patchStrategy key in its field tag. So the strategic merge patch uses the default patch strategy, which is replace.
所以我检查了Kubernetes源代码中NodeSelector的字段标签,:
NodeSelector map[string]string `json:"nodeSelector,omitempty" protobuf:"bytes,7,rep,name=nodeSelector"`
没有“patchStrategy”标签,那么为什么 patch() 不做替换?