Skip to content

Commit 05ff7c1

Browse files
authored
✨ Add an IgnoreFields option to select whether to override resource by mw (#345)
* 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 <[email protected]> * Update description and add objectHash annotation Signed-off-by: Jian Qiu <[email protected]> --------- Signed-off-by: Jian Qiu <[email protected]>
1 parent d07397a commit 05ff7c1

6 files changed

+175
-10
lines changed

addon/v1alpha1/0000_03_addon.open-cluster-management.io_addontemplates.crd.yaml

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,8 @@ spec:
255255
properties:
256256
serverSideApply:
257257
description: |-
258-
serverSideApply defines the configuration for server side apply. It is honored only when
259-
type of updateStrategy is ServerSideApply
258+
serverSideApply defines the configuration for server side apply. It is honored only when the
259+
type of the updateStrategy is ServerSideApply
260260
properties:
261261
fieldManager:
262262
default: work-agent
@@ -269,6 +269,37 @@ spec:
269269
description: Force represents to force apply the
270270
manifest.
271271
type: boolean
272+
ignoreFields:
273+
description: IgnoreFields defines a list of json
274+
paths in the resource that will not be updated
275+
on the spoke.
276+
items:
277+
properties:
278+
condition:
279+
default: OnSpokePresent
280+
description: |-
281+
Condition defines the condition that the fields should be ignored when apply the resource.
282+
Fields in JSONPaths are all ignored when condition is met, otherwise no fields is ignored
283+
in the apply operation.
284+
enum:
285+
- OnSpokePresent
286+
- OnSpokeChange
287+
type: string
288+
jsonPaths:
289+
description: JSONPaths defines the list of
290+
json path in the resource to be ignored
291+
items:
292+
type: string
293+
minItems: 1
294+
type: array
295+
required:
296+
- condition
297+
- jsonPaths
298+
type: object
299+
type: array
300+
x-kubernetes-list-map-keys:
301+
- condition
302+
x-kubernetes-list-type: map
272303
type: object
273304
type:
274305
default: Update

work/v1/0000_00_work.open-cluster-management.io_manifestworks.crd.yaml

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,8 @@ spec:
239239
properties:
240240
serverSideApply:
241241
description: |-
242-
serverSideApply defines the configuration for server side apply. It is honored only when
243-
type of updateStrategy is ServerSideApply
242+
serverSideApply defines the configuration for server side apply. It is honored only when the
243+
type of the updateStrategy is ServerSideApply
244244
properties:
245245
fieldManager:
246246
default: work-agent
@@ -252,6 +252,36 @@ spec:
252252
force:
253253
description: Force represents to force apply the manifest.
254254
type: boolean
255+
ignoreFields:
256+
description: IgnoreFields defines a list of json paths
257+
in the resource that will not be updated on the spoke.
258+
items:
259+
properties:
260+
condition:
261+
default: OnSpokePresent
262+
description: |-
263+
Condition defines the condition that the fields should be ignored when apply the resource.
264+
Fields in JSONPaths are all ignored when condition is met, otherwise no fields is ignored
265+
in the apply operation.
266+
enum:
267+
- OnSpokePresent
268+
- OnSpokeChange
269+
type: string
270+
jsonPaths:
271+
description: JSONPaths defines the list of json
272+
path in the resource to be ignored
273+
items:
274+
type: string
275+
minItems: 1
276+
type: array
277+
required:
278+
- condition
279+
- jsonPaths
280+
type: object
281+
type: array
282+
x-kubernetes-list-map-keys:
283+
- condition
284+
x-kubernetes-list-type: map
255285
type: object
256286
type:
257287
default: Update

work/v1/types.go

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,13 +170,14 @@ type UpdateStrategy struct {
170170
// +required
171171
Type UpdateStrategyType `json:"type,omitempty"`
172172

173-
// serverSideApply defines the configuration for server side apply. It is honored only when
174-
// type of updateStrategy is ServerSideApply
173+
// serverSideApply defines the configuration for server side apply. It is honored only when the
174+
// type of the updateStrategy is ServerSideApply
175175
// +optional
176176
ServerSideApply *ServerSideApplyConfig `json:"serverSideApply,omitempty"`
177177
}
178178

179179
type UpdateStrategyType string
180+
type IgnoreFieldsCondition string
180181

181182
const (
182183
// UpdateStrategyTypeUpdate means to update resource by an update call.
@@ -196,6 +197,13 @@ const (
196197
// If the statusFeedBackRules are set, the feedbackResult will also be returned.
197198
// The resource will not be removed when the type is ReadOnly, and only resource metadata is required.
198199
UpdateStrategyTypeReadOnly UpdateStrategyType = "ReadOnly"
200+
201+
// IgnoreFieldsConditionOnSpokeChange is the condition when resource fields is updated by another actor
202+
// on the spoke cluster.
203+
IgnoreFieldsConditionOnSpokeChange IgnoreFieldsCondition = "OnSpokeChange"
204+
205+
// IgnoreFieldsConditionOnSpokePresent is the condition when the resource exist on the spoke cluster.
206+
IgnoreFieldsConditionOnSpokePresent IgnoreFieldsCondition = "OnSpokePresent"
199207
)
200208

201209
type ServerSideApplyConfig struct {
@@ -209,6 +217,29 @@ type ServerSideApplyConfig struct {
209217
// +kubebuilder:validation:Pattern=`^work-agent`
210218
// +optional
211219
FieldManager string `json:"fieldManager,omitempty"`
220+
221+
// IgnoreFields defines a list of json paths in the resource that will not be updated on the spoke.
222+
// +listType:=map
223+
// +listMapKey:=condition
224+
// +optional
225+
IgnoreFields []IgnoreField `json:"ignoreFields,omitempty"`
226+
}
227+
228+
type IgnoreField struct {
229+
// Condition defines the condition that the fields should be ignored when apply the resource.
230+
// Fields in JSONPaths are all ignored when condition is met, otherwise no fields is ignored
231+
// in the apply operation.
232+
// +kubebuilder:default=OnSpokePresent
233+
// +kubebuilder:validation:Enum=OnSpokePresent;OnSpokeChange
234+
// +kubebuilder:validation:Required
235+
// +required
236+
Condition IgnoreFieldsCondition `json:"condition"`
237+
238+
// JSONPaths defines the list of json path in the resource to be ignored
239+
// +kubebuilder:validation:Required
240+
// +kubebuilder:validation:MinItems=1
241+
// +required
242+
JSONPaths []string `json:"jsonPaths"`
212243
}
213244

214245
// DefaultFieldManager is the default field manager of the manifestwork when the field manager is not set.
@@ -506,6 +537,10 @@ const (
506537
// ensure all resource relates to appliedmanifestwork is deleted before appliedmanifestwork itself
507538
// is deleted.
508539
AppliedManifestWorkFinalizer = "cluster.open-cluster-management.io/applied-manifest-work-cleanup"
540+
541+
// ObjectSpecHash is the key of the annotation on the applied resources. The value is the computed hash
542+
// from the resource manifests in the manifestwork.
543+
ObjectSpecHash = "open-cluster-management.io/object-hash"
509544
)
510545

511546
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

work/v1/zz_generated.deepcopy.go

Lines changed: 29 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

work/v1/zz_generated.swagger_doc_generated.go

Lines changed: 11 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

work/v1alpha1/0000_00_work.open-cluster-management.io_manifestworkreplicasets.crd.yaml

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,8 @@ spec:
262262
properties:
263263
serverSideApply:
264264
description: |-
265-
serverSideApply defines the configuration for server side apply. It is honored only when
266-
type of updateStrategy is ServerSideApply
265+
serverSideApply defines the configuration for server side apply. It is honored only when the
266+
type of the updateStrategy is ServerSideApply
267267
properties:
268268
fieldManager:
269269
default: work-agent
@@ -276,6 +276,37 @@ spec:
276276
description: Force represents to force apply the
277277
manifest.
278278
type: boolean
279+
ignoreFields:
280+
description: IgnoreFields defines a list of json
281+
paths in the resource that will not be updated
282+
on the spoke.
283+
items:
284+
properties:
285+
condition:
286+
default: OnSpokePresent
287+
description: |-
288+
Condition defines the condition that the fields should be ignored when apply the resource.
289+
Fields in JSONPaths are all ignored when condition is met, otherwise no fields is ignored
290+
in the apply operation.
291+
enum:
292+
- OnSpokePresent
293+
- OnSpokeChange
294+
type: string
295+
jsonPaths:
296+
description: JSONPaths defines the list of
297+
json path in the resource to be ignored
298+
items:
299+
type: string
300+
minItems: 1
301+
type: array
302+
required:
303+
- condition
304+
- jsonPaths
305+
type: object
306+
type: array
307+
x-kubernetes-list-map-keys:
308+
- condition
309+
x-kubernetes-list-type: map
279310
type: object
280311
type:
281312
default: Update

0 commit comments

Comments
 (0)