From 05ff7c1affe86c9a7f51acba053f6e3f615858ec Mon Sep 17 00:00:00 2001 From: Jian Qiu Date: Tue, 26 Nov 2024 15:37:17 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20an=20IgnoreFields=20option=20?= =?UTF-8?q?to=20select=20whether=20to=20override=20resource=20by=20mw=20(#?= =?UTF-8?q?345)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add an option to select override resource by mw The option is to disable overrid resource on the spoke by manifestwork when the resource is changed by another actor on the spoke Signed-off-by: Jian Qiu * Update description and add objectHash annotation Signed-off-by: Jian Qiu --------- Signed-off-by: Jian Qiu --- ...ster-management.io_addontemplates.crd.yaml | 35 ++++++++++++++++- ...uster-management.io_manifestworks.crd.yaml | 34 +++++++++++++++- work/v1/types.go | 39 ++++++++++++++++++- work/v1/zz_generated.deepcopy.go | 30 +++++++++++++- work/v1/zz_generated.swagger_doc_generated.go | 12 +++++- ...gement.io_manifestworkreplicasets.crd.yaml | 35 ++++++++++++++++- 6 files changed, 175 insertions(+), 10 deletions(-) diff --git a/addon/v1alpha1/0000_03_addon.open-cluster-management.io_addontemplates.crd.yaml b/addon/v1alpha1/0000_03_addon.open-cluster-management.io_addontemplates.crd.yaml index 8c7718c8c..fcf4a87f6 100644 --- a/addon/v1alpha1/0000_03_addon.open-cluster-management.io_addontemplates.crd.yaml +++ b/addon/v1alpha1/0000_03_addon.open-cluster-management.io_addontemplates.crd.yaml @@ -255,8 +255,8 @@ spec: properties: serverSideApply: description: |- - serverSideApply defines the configuration for server side apply. It is honored only when - type of updateStrategy is ServerSideApply + serverSideApply defines the configuration for server side apply. It is honored only when the + type of the updateStrategy is ServerSideApply properties: fieldManager: default: work-agent @@ -269,6 +269,37 @@ spec: description: Force represents to force apply the manifest. type: boolean + ignoreFields: + description: IgnoreFields defines a list of json + paths in the resource that will not be updated + on the spoke. + items: + properties: + condition: + default: OnSpokePresent + description: |- + Condition defines the condition that the fields should be ignored when apply the resource. + Fields in JSONPaths are all ignored when condition is met, otherwise no fields is ignored + in the apply operation. + enum: + - OnSpokePresent + - OnSpokeChange + type: string + jsonPaths: + description: JSONPaths defines the list of + json path in the resource to be ignored + items: + type: string + minItems: 1 + type: array + required: + - condition + - jsonPaths + type: object + type: array + x-kubernetes-list-map-keys: + - condition + x-kubernetes-list-type: map type: object type: default: Update diff --git a/work/v1/0000_00_work.open-cluster-management.io_manifestworks.crd.yaml b/work/v1/0000_00_work.open-cluster-management.io_manifestworks.crd.yaml index 3542af39e..c54c3ccdf 100644 --- a/work/v1/0000_00_work.open-cluster-management.io_manifestworks.crd.yaml +++ b/work/v1/0000_00_work.open-cluster-management.io_manifestworks.crd.yaml @@ -239,8 +239,8 @@ spec: properties: serverSideApply: description: |- - serverSideApply defines the configuration for server side apply. It is honored only when - type of updateStrategy is ServerSideApply + serverSideApply defines the configuration for server side apply. It is honored only when the + type of the updateStrategy is ServerSideApply properties: fieldManager: default: work-agent @@ -252,6 +252,36 @@ spec: force: description: Force represents to force apply the manifest. type: boolean + ignoreFields: + description: IgnoreFields defines a list of json paths + in the resource that will not be updated on the spoke. + items: + properties: + condition: + default: OnSpokePresent + description: |- + Condition defines the condition that the fields should be ignored when apply the resource. + Fields in JSONPaths are all ignored when condition is met, otherwise no fields is ignored + in the apply operation. + enum: + - OnSpokePresent + - OnSpokeChange + type: string + jsonPaths: + description: JSONPaths defines the list of json + path in the resource to be ignored + items: + type: string + minItems: 1 + type: array + required: + - condition + - jsonPaths + type: object + type: array + x-kubernetes-list-map-keys: + - condition + x-kubernetes-list-type: map type: object type: default: Update diff --git a/work/v1/types.go b/work/v1/types.go index 08f560fd9..e62dcded0 100644 --- a/work/v1/types.go +++ b/work/v1/types.go @@ -170,13 +170,14 @@ type UpdateStrategy struct { // +required Type UpdateStrategyType `json:"type,omitempty"` - // serverSideApply defines the configuration for server side apply. It is honored only when - // type of updateStrategy is ServerSideApply + // serverSideApply defines the configuration for server side apply. It is honored only when the + // type of the updateStrategy is ServerSideApply // +optional ServerSideApply *ServerSideApplyConfig `json:"serverSideApply,omitempty"` } type UpdateStrategyType string +type IgnoreFieldsCondition string const ( // UpdateStrategyTypeUpdate means to update resource by an update call. @@ -196,6 +197,13 @@ const ( // If the statusFeedBackRules are set, the feedbackResult will also be returned. // The resource will not be removed when the type is ReadOnly, and only resource metadata is required. UpdateStrategyTypeReadOnly UpdateStrategyType = "ReadOnly" + + // IgnoreFieldsConditionOnSpokeChange is the condition when resource fields is updated by another actor + // on the spoke cluster. + IgnoreFieldsConditionOnSpokeChange IgnoreFieldsCondition = "OnSpokeChange" + + // IgnoreFieldsConditionOnSpokePresent is the condition when the resource exist on the spoke cluster. + IgnoreFieldsConditionOnSpokePresent IgnoreFieldsCondition = "OnSpokePresent" ) type ServerSideApplyConfig struct { @@ -209,6 +217,29 @@ type ServerSideApplyConfig struct { // +kubebuilder:validation:Pattern=`^work-agent` // +optional FieldManager string `json:"fieldManager,omitempty"` + + // IgnoreFields defines a list of json paths in the resource that will not be updated on the spoke. + // +listType:=map + // +listMapKey:=condition + // +optional + IgnoreFields []IgnoreField `json:"ignoreFields,omitempty"` +} + +type IgnoreField struct { + // Condition defines the condition that the fields should be ignored when apply the resource. + // Fields in JSONPaths are all ignored when condition is met, otherwise no fields is ignored + // in the apply operation. + // +kubebuilder:default=OnSpokePresent + // +kubebuilder:validation:Enum=OnSpokePresent;OnSpokeChange + // +kubebuilder:validation:Required + // +required + Condition IgnoreFieldsCondition `json:"condition"` + + // JSONPaths defines the list of json path in the resource to be ignored + // +kubebuilder:validation:Required + // +kubebuilder:validation:MinItems=1 + // +required + JSONPaths []string `json:"jsonPaths"` } // DefaultFieldManager is the default field manager of the manifestwork when the field manager is not set. @@ -506,6 +537,10 @@ const ( // ensure all resource relates to appliedmanifestwork is deleted before appliedmanifestwork itself // is deleted. AppliedManifestWorkFinalizer = "cluster.open-cluster-management.io/applied-manifest-work-cleanup" + + // ObjectSpecHash is the key of the annotation on the applied resources. The value is the computed hash + // from the resource manifests in the manifestwork. + ObjectSpecHash = "open-cluster-management.io/object-hash" ) // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object diff --git a/work/v1/zz_generated.deepcopy.go b/work/v1/zz_generated.deepcopy.go index 522d86b67..a09a23b62 100644 --- a/work/v1/zz_generated.deepcopy.go +++ b/work/v1/zz_generated.deepcopy.go @@ -224,6 +224,27 @@ func (in *FieldValue) DeepCopy() *FieldValue { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *IgnoreField) DeepCopyInto(out *IgnoreField) { + *out = *in + if in.JSONPaths != nil { + in, out := &in.JSONPaths, &out.JSONPaths + *out = make([]string, len(*in)) + copy(*out, *in) + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new IgnoreField. +func (in *IgnoreField) DeepCopy() *IgnoreField { + if in == nil { + return nil + } + out := new(IgnoreField) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *JsonPath) DeepCopyInto(out *JsonPath) { *out = *in @@ -602,6 +623,13 @@ func (in *SelectivelyOrphan) DeepCopy() *SelectivelyOrphan { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ServerSideApplyConfig) DeepCopyInto(out *ServerSideApplyConfig) { *out = *in + if in.IgnoreFields != nil { + in, out := &in.IgnoreFields, &out.IgnoreFields + *out = make([]IgnoreField, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } return } @@ -644,7 +672,7 @@ func (in *UpdateStrategy) DeepCopyInto(out *UpdateStrategy) { if in.ServerSideApply != nil { in, out := &in.ServerSideApply, &out.ServerSideApply *out = new(ServerSideApplyConfig) - **out = **in + (*in).DeepCopyInto(*out) } return } diff --git a/work/v1/zz_generated.swagger_doc_generated.go b/work/v1/zz_generated.swagger_doc_generated.go index 0b4e308dc..97385341a 100644 --- a/work/v1/zz_generated.swagger_doc_generated.go +++ b/work/v1/zz_generated.swagger_doc_generated.go @@ -102,6 +102,15 @@ func (FieldValue) SwaggerDoc() map[string]string { return map_FieldValue } +var map_IgnoreField = map[string]string{ + "condition": "Condition defines the condition that the fields should be ignored when apply the resource. Fields in JSONPaths are all ignored when condition is met, otherwise no fields is ignored in the apply operation.", + "jsonPaths": "JSONPaths defines the list of json path in the resource to be ignored", +} + +func (IgnoreField) SwaggerDoc() map[string]string { + return map_IgnoreField +} + var map_JsonPath = map[string]string{ "name": "Name represents the alias name for this field", "version": "Version is the version of the Kubernetes resource. If it is not specified, the resource with the semantically latest version is used to resolve the path.", @@ -270,6 +279,7 @@ func (SelectivelyOrphan) SwaggerDoc() map[string]string { var map_ServerSideApplyConfig = map[string]string{ "force": "Force represents to force apply the manifest.", "fieldManager": "FieldManager is the manager to apply the resource. It is work-agent by default, but can be other name with work-agent as the prefix.", + "ignoreFields": "IgnoreFields defines a list of json paths in the resource that will not be updated on the spoke.", } func (ServerSideApplyConfig) SwaggerDoc() map[string]string { @@ -288,7 +298,7 @@ func (StatusFeedbackResult) SwaggerDoc() map[string]string { var map_UpdateStrategy = map[string]string{ "": "UpdateStrategy defines the strategy to update this manifest", "type": "type defines the strategy to update this manifest, default value is Update. Update type means to update resource by an update call. CreateOnly type means do not update resource based on current manifest. ServerSideApply type means to update resource using server side apply with work-controller as the field manager. If there is conflict, the related Applied condition of manifest will be in the status of False with the reason of ApplyConflict. ReadOnly type means the agent will only check the existence of the resource based on its metadata, statusFeedBackRules can still be used to get feedbackResults.", - "serverSideApply": "serverSideApply defines the configuration for server side apply. It is honored only when type of updateStrategy is ServerSideApply", + "serverSideApply": "serverSideApply defines the configuration for server side apply. It is honored only when the type of the updateStrategy is ServerSideApply", } func (UpdateStrategy) SwaggerDoc() map[string]string { diff --git a/work/v1alpha1/0000_00_work.open-cluster-management.io_manifestworkreplicasets.crd.yaml b/work/v1alpha1/0000_00_work.open-cluster-management.io_manifestworkreplicasets.crd.yaml index 499146f25..9ace877ba 100644 --- a/work/v1alpha1/0000_00_work.open-cluster-management.io_manifestworkreplicasets.crd.yaml +++ b/work/v1alpha1/0000_00_work.open-cluster-management.io_manifestworkreplicasets.crd.yaml @@ -262,8 +262,8 @@ spec: properties: serverSideApply: description: |- - serverSideApply defines the configuration for server side apply. It is honored only when - type of updateStrategy is ServerSideApply + serverSideApply defines the configuration for server side apply. It is honored only when the + type of the updateStrategy is ServerSideApply properties: fieldManager: default: work-agent @@ -276,6 +276,37 @@ spec: description: Force represents to force apply the manifest. type: boolean + ignoreFields: + description: IgnoreFields defines a list of json + paths in the resource that will not be updated + on the spoke. + items: + properties: + condition: + default: OnSpokePresent + description: |- + Condition defines the condition that the fields should be ignored when apply the resource. + Fields in JSONPaths are all ignored when condition is met, otherwise no fields is ignored + in the apply operation. + enum: + - OnSpokePresent + - OnSpokeChange + type: string + jsonPaths: + description: JSONPaths defines the list of + json path in the resource to be ignored + items: + type: string + minItems: 1 + type: array + required: + - condition + - jsonPaths + type: object + type: array + x-kubernetes-list-map-keys: + - condition + x-kubernetes-list-type: map type: object type: default: Update