kubectl
kubectl copied to clipboard
The result after executing the Json Patch command is not as expected
What happened: When using the add operator of JSON Patch to modify the CRD, it is found that the original value is overwritten instead of appended
What you expected to happen: Append the desired value to the corresponding property.
How to reproduce it (as minimally and precisely as possible): 1、This is the initial declaration for the corresponding CRD:
[root@k8s-master-001 3.1.0-4.0.0]# kubectl get crd baserouteserversettings.configuration.baosight.io -o yaml
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.4.1
kubectl.kubernetes.io/last-applied-configuration: |
{"apiVersion":"apiextensions.k8s.io/v1","kind":"CustomResourceDefinition","metadata":{"annotations":{"controller-gen.kubebuilder.io/version":"v0.4.1"},"creationTimestamp":null,"name":"baserouteserversettings.configuration.baosight.io"},"spec":{"group":"configuration.baosight.io","names":{"kind":"BaseRouteServerSetting","listKind":"BaseRouteServerSettingList","plural":"baserouteserversettings","singular":"baserouteserversetting"},"scope":"Namespaced","versions":[{"name":"v1","schema":{"openAPIV3Schema":{"description":"BaseRouteServerSetting is the Schema for the baserouteserversettings API","properties":{"apiVersion":{"description":"APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources","type":"string"},"kind":{"description":"Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds","type":"string"},"metadata":{"type":"object"},"spec":{"description":"BaseRouteServerSettingSpec defines the desired state of BaseRouteServerSetting","properties":{"auth_by_secret_address":{"description":"Query the interface address of APP_SECRET","type":"string"},"auth_by_secret_effective_time":{"description":"Effective time","type":"integer"},"auth_by_secret_rigorous_mode":{"description":"Secret Authentication Rigorous Mode","type":"boolean"},"auth_by_secret_switch":{"description":"Secret authentication switch","type":"boolean"},"auth_by_token_switch":{"description":"Token authentication switch","type":"boolean"},"base_security_public_key":{"description":"The public key used when parsing the Security Center JWT","type":"string"},"enable_tracing":{"description":"Whether to enable Access log buried point","type":"boolean"},"ignore_domain":{"description":"The request domain name that needs to be ignored when processing share service route","items":{"type":"string"},"type":"array"}},"type":"object"},"status":{"description":"BaseRouteServerSettingStatus defines the observed state of BaseRouteServerSetting","type":"object"}},"type":"object"}},"served":true,"storage":true,"subresources":{"status":{}}}]},"status":{"acceptedNames":{"kind":"","plural":""},"conditions":[],"storedVersions":[]}}
creationTimestamp: "2023-01-16T12:54:37Z"
generation: 7
managedFields:
- apiVersion: apiextensions.k8s.io/v1
fieldsType: FieldsV1
fieldsV1:
f:status:
f:acceptedNames:
f:kind: {}
f:listKind: {}
f:plural: {}
f:singular: {}
f:conditions: {}
manager: kube-apiserver
operation: Update
time: "2023-01-16T12:54:37Z"
- apiVersion: apiextensions.k8s.io/v1
fieldsType: FieldsV1
fieldsV1:
f:metadata:
f:annotations:
.: {}
f:controller-gen.kubebuilder.io/version: {}
f:kubectl.kubernetes.io/last-applied-configuration: {}
f:spec:
f:conversion:
.: {}
f:strategy: {}
f:group: {}
f:names:
f:kind: {}
f:listKind: {}
f:plural: {}
f:singular: {}
f:scope: {}
f:status:
f:storedVersions: {}
manager: kubectl-client-side-apply
operation: Update
time: "2023-01-16T12:54:37Z"
- apiVersion: apiextensions.k8s.io/v1
fieldsType: FieldsV1
fieldsV1:
f:spec:
f:versions: {}
manager: kubectl-edit
operation: Update
time: "2023-01-16T13:43:53Z"
name: baserouteserversettings.configuration.baosight.io
resourceVersion: "193561305"
selfLink: /apis/apiextensions.k8s.io/v1/customresourcedefinitions/baserouteserversettings.configuration.baosight.io
uid: 5ce311ab-aa03-45fe-92d5-c75c2f548e0f
spec:
conversion:
strategy: None
group: configuration.baosight.io
names:
kind: BaseRouteServerSetting
listKind: BaseRouteServerSettingList
plural: baserouteserversettings
singular: baserouteserversetting
scope: Namespaced
versions:
- name: v1
schema:
openAPIV3Schema:
description: BaseRouteServerSetting is the Schema for the baserouteserversettings
API
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
type: string
kind:
description: 'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
metadata:
type: object
spec:
description: BaseRouteServerSettingSpec defines the desired state of BaseRouteServerSetting
properties:
auth_by_secret_address:
description: Query the interface address of APP_SECRET
type: string
auth_by_secret_effective_time:
description: Effective time
type: integer
auth_by_secret_rigorous_mode:
description: Secret Authentication Rigorous Mode
type: boolean
auth_by_secret_switch:
description: Secret authentication switch
type: boolean
auth_by_token_switch:
description: Token authentication switch
type: boolean
base_security_public_key:
description: The public key used when parsing the Security Center
JWT
type: string
type: object
status:
description: BaseRouteServerSettingStatus defines the observed state of
BaseRouteServerSetting
type: object
type: object
served: true
storage: true
subresources:
status: {}
status:
acceptedNames:
kind: BaseRouteServerSetting
listKind: BaseRouteServerSettingList
plural: baserouteserversettings
singular: baserouteserversetting
conditions:
- lastTransitionTime: "2023-01-16T12:54:37Z"
message: no conflicts found
reason: NoConflicts
status: "True"
type: NamesAccepted
- lastTransitionTime: "2023-01-16T12:54:37Z"
message: the initial names have been accepted
reason: InitialNamesAccepted
status: "True"
type: Established
storedVersions:
- v1
2、This is the instruction of the executed JSON Patch:
[root@k8s-master-001 backups]# kubectl patch crd baserouteserversettings.configuration.baosight.io --type json -p '[{"op":"add","path":"/spec/versions/0/schema/openAPIV3Schema/properties/spec/properties","value":{"enable_tracing":{"description":"Whether to enable Access log buried point","type":"boolean"}}}]'
customresourcedefinition.apiextensions.k8s.io/baserouteserversettings.configuration.baosight.io patched
[root@k8s-master-001 backups]# kubectl get crd baserouteserversettings.configuration.baosight.io -o yaml
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.4.1
kubectl.kubernetes.io/last-applied-configuration: |
{"apiVersion":"apiextensions.k8s.io/v1","kind":"CustomResourceDefinition","metadata":{"annotations":{"controller-gen.kubebuilder.io/version":"v0.4.1"},"creationTimestamp":null,"name":"baserouteserversettings.configuration.baosight.io"},"spec":{"group":"configuration.baosight.io","names":{"kind":"BaseRouteServerSetting","listKind":"BaseRouteServerSettingList","plural":"baserouteserversettings","singular":"baserouteserversetting"},"scope":"Namespaced","versions":[{"name":"v1","schema":{"openAPIV3Schema":{"description":"BaseRouteServerSetting is the Schema for the baserouteserversettings API","properties":{"apiVersion":{"description":"APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources","type":"string"},"kind":{"description":"Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds","type":"string"},"metadata":{"type":"object"},"spec":{"description":"BaseRouteServerSettingSpec defines the desired state of BaseRouteServerSetting","properties":{"auth_by_secret_address":{"description":"Query the interface address of APP_SECRET","type":"string"},"auth_by_secret_effective_time":{"description":"Effective time","type":"integer"},"auth_by_secret_rigorous_mode":{"description":"Secret Authentication Rigorous Mode","type":"boolean"},"auth_by_secret_switch":{"description":"Secret authentication switch","type":"boolean"},"auth_by_token_switch":{"description":"Token authentication switch","type":"boolean"},"base_security_public_key":{"description":"The public key used when parsing the Security Center JWT","type":"string"},"enable_tracing":{"description":"Whether to enable Access log buried point","type":"boolean"},"ignore_domain":{"description":"The request domain name that needs to be ignored when processing share service route","items":{"type":"string"},"type":"array"}},"type":"object"},"status":{"description":"BaseRouteServerSettingStatus defines the observed state of BaseRouteServerSetting","type":"object"}},"type":"object"}},"served":true,"storage":true,"subresources":{"status":{}}}]},"status":{"acceptedNames":{"kind":"","plural":""},"conditions":[],"storedVersions":[]}}
creationTimestamp: "2023-01-16T12:54:37Z"
generation: 8
managedFields:
- apiVersion: apiextensions.k8s.io/v1
fieldsType: FieldsV1
fieldsV1:
f:status:
f:acceptedNames:
f:kind: {}
f:listKind: {}
f:plural: {}
f:singular: {}
f:conditions: {}
manager: kube-apiserver
operation: Update
time: "2023-01-16T12:54:37Z"
- apiVersion: apiextensions.k8s.io/v1
fieldsType: FieldsV1
fieldsV1:
f:metadata:
f:annotations:
.: {}
f:controller-gen.kubebuilder.io/version: {}
f:kubectl.kubernetes.io/last-applied-configuration: {}
f:spec:
f:conversion:
.: {}
f:strategy: {}
f:group: {}
f:names:
f:kind: {}
f:listKind: {}
f:plural: {}
f:singular: {}
f:scope: {}
f:status:
f:storedVersions: {}
manager: kubectl-client-side-apply
operation: Update
time: "2023-01-16T12:54:37Z"
- apiVersion: apiextensions.k8s.io/v1
fieldsType: FieldsV1
fieldsV1:
f:spec:
f:versions: {}
manager: kubectl-patch
operation: Update
time: "2023-01-16T13:48:03Z"
name: baserouteserversettings.configuration.baosight.io
resourceVersion: "193562069"
selfLink: /apis/apiextensions.k8s.io/v1/customresourcedefinitions/baserouteserversettings.configuration.baosight.io
uid: 5ce311ab-aa03-45fe-92d5-c75c2f548e0f
spec:
conversion:
strategy: None
group: configuration.baosight.io
names:
kind: BaseRouteServerSetting
listKind: BaseRouteServerSettingList
plural: baserouteserversettings
singular: baserouteserversetting
scope: Namespaced
versions:
- name: v1
schema:
openAPIV3Schema:
description: BaseRouteServerSetting is the Schema for the baserouteserversettings
API
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
type: string
kind:
description: 'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
metadata:
type: object
spec:
description: BaseRouteServerSettingSpec defines the desired state of BaseRouteServerSetting
properties:
enable_tracing:
description: Whether to enable Access log buried point
type: boolean
type: object
status:
description: BaseRouteServerSettingStatus defines the observed state of
BaseRouteServerSetting
type: object
type: object
served: true
storage: true
subresources:
status: {}
status:
acceptedNames:
kind: BaseRouteServerSetting
listKind: BaseRouteServerSettingList
plural: baserouteserversettings
singular: baserouteserversetting
conditions:
- lastTransitionTime: "2023-01-16T12:54:37Z"
message: no conflicts found
reason: NoConflicts
status: "True"
type: NamesAccepted
- lastTransitionTime: "2023-01-16T12:54:37Z"
message: the initial names have been accepted
reason: InitialNamesAccepted
status: "True"
type: Established
storedVersions:
- v1
[root@k8s-master-001 backups]#
From the final result, it can be found that after the Patch command is executed, the required value is not added to the corresponding attribute, but the value of the original attribute is overwritten. What is the problem?
Anything else we need to know?:
Environment:
- Kubernetes client and server versions (use
kubectl version
):
[root@k8s-master-001 ~]# kubectl version
Client Version: version.Info{Major:"1", Minor:"19", GitVersion:"v1.19.0", GitCommit:"e19964183377d0ec2052d1f1fa930c4d7575bd50", GitTreeState:"clean", BuildDate:"2020-08-26T14:30:33Z", GoVersion:"go1.15", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"19", GitVersion:"v1.19.0", GitCommit:"e19964183377d0ec2052d1f1fa930c4d7575bd50", GitTreeState:"clean", BuildDate:"2020-08-26T14:23:04Z", GoVersion:"go1.15", Compiler:"gc", Platform:"linux/amd64"}
- Cloud provider or hardware configuration:
[root@k8s-master-001 ~]# cat /proc/cpuinfo | grep -c processor
8
[root@k8s-master-001 ~]# free -g
total used free shared buff/cache available
Mem: 15 2 2 0 9 12
Swap: 0 0 0
[root@k8s-master-001 ~]#
- OS (e.g:
cat /etc/os-release
):
[root@k8s-master-001 ~]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)
[root@k8s-master-001 ~]#