Skip to content

Commit

Permalink
✨ Add an IgnoreFields option to select whether to override resource b…
Browse files Browse the repository at this point in the history
…y mw (open-cluster-management-io#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]>
  • Loading branch information
qiujian16 authored Nov 26, 2024
1 parent d07397a commit 05ff7c1
Show file tree
Hide file tree
Showing 6 changed files with 175 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
39 changes: 37 additions & 2 deletions work/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 {
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand Down
30 changes: 29 additions & 1 deletion work/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 11 additions & 1 deletion work/v1/zz_generated.swagger_doc_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 05ff7c1

Please sign in to comment.