From 26ec0c78227533ea00e8cfce17f178d5a29f60f2 Mon Sep 17 00:00:00 2001 From: Jian Qiu Date: Tue, 12 Nov 2024 17:20:15 +0800 Subject: [PATCH] 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 --- ...ster-management.io_addontemplates.crd.yaml | 27 +++++++++++++++++-- ...uster-management.io_manifestworks.crd.yaml | 26 ++++++++++++++++-- work/v1/types.go | 21 +++++++++++++-- work/v1/zz_generated.deepcopy.go | 26 ++++++++++++++++++ work/v1/zz_generated.swagger_doc_generated.go | 17 +++++++++--- ...gement.io_manifestworkreplicasets.crd.yaml | 27 +++++++++++++++++-- 6 files changed, 133 insertions(+), 11 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 64d46da06..619682f61 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 @@ -252,8 +252,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 @@ -266,6 +266,18 @@ 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: + type: string + type: array + onSpokeChange: + description: |- + OnSpokeChange defines whether the resource should be overriden by the manifestwork it is changed + on the spoke by another actor. + type: string type: object type: default: Update @@ -284,6 +296,17 @@ spec: - ServerSideApply - ReadOnly type: string + update: + description: |- + update defines the configuration for update. It is honored only when the type of the updateStrategy + is Update + properties: + onSpokeChange: + description: |- + OnSpokeChange defines whether the resource should be overriden by the manifestwork it is changed + on the spoke by another actor. + type: string + type: object required: - type type: object 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 efb889f9d..727228b9a 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 @@ -236,8 +236,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 @@ -249,6 +249,17 @@ 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: + type: string + type: array + onSpokeChange: + description: |- + OnSpokeChange defines whether the resource should be overriden by the manifestwork it is changed + on the spoke by another actor. + type: string type: object type: default: Update @@ -267,6 +278,17 @@ spec: - ServerSideApply - ReadOnly type: string + update: + description: |- + update defines the configuration for update. It is honored only when the type of the updateStrategy + is Update + properties: + onSpokeChange: + description: |- + OnSpokeChange defines whether the resource should be overriden by the manifestwork it is changed + on the spoke by another actor. + type: string + type: object required: - type type: object diff --git a/work/v1/types.go b/work/v1/types.go index 0a66a837d..54cb10a5c 100644 --- a/work/v1/types.go +++ b/work/v1/types.go @@ -170,10 +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"` + + // update defines the configuration for update. It is honored only when the type of the updateStrategy + // is Update + Update *UpdateConfig `json:"update,omitempty"` } type UpdateStrategyType string @@ -209,6 +213,19 @@ 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. + IgnoreFields []string `json:"ignoreFields,omitempty"` + + // OnSpokeChange defines whether the resource should be overriden by the manifestwork it is changed + // on the spoke by another actor. + OnSpokeChange string `json:"onSpokeChange,omitempty"` +} + +type UpdateConfig struct { + // OnSpokeChange defines whether the resource should be overriden by the manifestwork it is changed + // on the spoke by another actor. + OnSpokeChange string `json:"onSpokeChange,omitempty"` } // DefaultFieldManager is the default field manager of the manifestwork when the field manager is not set. diff --git a/work/v1/zz_generated.deepcopy.go b/work/v1/zz_generated.deepcopy.go index 522d86b67..e242ed40d 100644 --- a/work/v1/zz_generated.deepcopy.go +++ b/work/v1/zz_generated.deepcopy.go @@ -602,6 +602,11 @@ 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([]string, len(*in)) + copy(*out, *in) + } return } @@ -638,12 +643,33 @@ func (in *StatusFeedbackResult) DeepCopy() *StatusFeedbackResult { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *UpdateConfig) DeepCopyInto(out *UpdateConfig) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new UpdateConfig. +func (in *UpdateConfig) DeepCopy() *UpdateConfig { + if in == nil { + return nil + } + out := new(UpdateConfig) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *UpdateStrategy) DeepCopyInto(out *UpdateStrategy) { *out = *in if in.ServerSideApply != nil { in, out := &in.ServerSideApply, &out.ServerSideApply *out = new(ServerSideApplyConfig) + (*in).DeepCopyInto(*out) + } + if in.Update != nil { + in, out := &in.Update, &out.Update + *out = new(UpdateConfig) **out = **in } return diff --git a/work/v1/zz_generated.swagger_doc_generated.go b/work/v1/zz_generated.swagger_doc_generated.go index 0b4e308dc..aae77962b 100644 --- a/work/v1/zz_generated.swagger_doc_generated.go +++ b/work/v1/zz_generated.swagger_doc_generated.go @@ -268,8 +268,10 @@ 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.", + "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.", + "onSpokeChange": "OnSpokeChange defines whether the resource should be overriden by the manifestwork it is changed on the spoke by another actor.", } func (ServerSideApplyConfig) SwaggerDoc() map[string]string { @@ -285,10 +287,19 @@ func (StatusFeedbackResult) SwaggerDoc() map[string]string { return map_StatusFeedbackResult } +var map_UpdateConfig = map[string]string{ + "onSpokeChange": "OnSpokeChange defines whether the resource should be overriden by the manifestwork it is changed on the spoke by another actor.", +} + +func (UpdateConfig) SwaggerDoc() map[string]string { + return map_UpdateConfig +} + 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", + "update": "update defines the configuration for update. It is honored only when the type of the updateStrategy is Update", } 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 6acb6340f..15b98d8b7 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 @@ -259,8 +259,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 @@ -273,6 +273,18 @@ 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: + type: string + type: array + onSpokeChange: + description: |- + OnSpokeChange defines whether the resource should be overriden by the manifestwork it is changed + on the spoke by another actor. + type: string type: object type: default: Update @@ -291,6 +303,17 @@ spec: - ServerSideApply - ReadOnly type: string + update: + description: |- + update defines the configuration for update. It is honored only when the type of the updateStrategy + is Update + properties: + onSpokeChange: + description: |- + OnSpokeChange defines whether the resource should be overriden by the manifestwork it is changed + on the spoke by another actor. + type: string + type: object required: - type type: object