Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Add an IgnoreFields option to select whether to override resource by mw #345

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -266,6 +266,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 @@ -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
Expand All @@ -249,6 +249,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"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be a required field? if it is empty, what should we do?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not think list can be required, but we could set the minItem to 1

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

}

// DefaultFieldManager is the default field manager of the manifestwork when the field manager is not set.
Expand Down Expand Up @@ -504,6 +535,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 @@ -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
Expand All @@ -273,6 +273,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
Loading