From aa61791ccb40fec260d228dc4bfa9c3e34a0fce8 Mon Sep 17 00:00:00 2001 From: RainbowMango Date: Fri, 20 Sep 2024 15:26:06 +0800 Subject: [PATCH] Proposing preserve API to support migration sceanrios Signed-off-by: RainbowMango --- api/openapi-spec/swagger.json | 12 +++++++++++ ...karmada.io_clusterpropagationpolicies.yaml | 21 +++++++++++++++++++ ...policy.karmada.io_propagationpolicies.yaml | 21 +++++++++++++++++++ ...rk.karmada.io_clusterresourcebindings.yaml | 8 +++++++ .../work.karmada.io_resourcebindings.yaml | 8 +++++++ .../bases/work/work.karmada.io_works.yaml | 7 +++++++ pkg/apis/policy/v1alpha1/propagation_types.go | 19 +++++++++++++++++ .../policy/v1alpha1/zz_generated.deepcopy.go | 5 +++++ pkg/apis/work/v1alpha1/work_types.go | 7 +++++++ .../work/v1alpha1/zz_generated.deepcopy.go | 5 +++++ pkg/apis/work/v1alpha2/binding_types.go | 8 +++++++ .../work/v1alpha2/zz_generated.deepcopy.go | 5 +++++ pkg/generated/openapi/zz_generated.openapi.go | 21 +++++++++++++++++++ 13 files changed, 147 insertions(+) diff --git a/api/openapi-spec/swagger.json b/api/openapi-spec/swagger.json index 39bdc0082..dc9347e3d 100644 --- a/api/openapi-spec/swagger.json +++ b/api/openapi-spec/swagger.json @@ -19098,6 +19098,10 @@ "Never" ] }, + "preserveResourcesOnDeletion": { + "description": "PreserveResourcesOnDeletion controls whether resources should be preserved on the member clusters when the resource template is deleted. If set to true, resources will be preserved on the member clusters. Default is false, which means resources will be deleted along with the resource template.\n\nThis setting is particularly useful during workload migration scenarios to ensure that rollback can occur quickly without affecting the workloads running on the member clusters.\n\nAdditionally, this setting applies uniformly across all member clusters and will not selectively control preservation on only some clusters.\n\nNote: This setting does not apply to the deletion of the policy itself. When the policy is deleted, the resource templates and their corresponding propagated resources in member clusters will remain unchanged unless explicitly deleted.", + "type": "boolean" + }, "priority": { "description": "Priority indicates the importance of a policy(PropagationPolicy or ClusterPropagationPolicy). A policy will be applied for the matched resource templates if there is no other policies with higher priority at the point of the resource template be processed. Once a resource template has been claimed by a policy, by default it will not be preempted by following policies even with a higher priority. See Preemption for more details.\n\nIn case of two policies have the same priority, the one with a more precise matching rules in ResourceSelectors wins: - matching by name(resourceSelector.name) has higher priority than\n by selector(resourceSelector.labelSelector)\n- matching by selector(resourceSelector.labelSelector) has higher priority\n than by APIVersion(resourceSelector.apiVersion) and Kind(resourceSelector.kind).\nIf there is still no winner at this point, the one with the lower alphabetic order wins, e.g. policy 'bar' has higher priority than 'foo'.\n\nThe higher the value, the higher the priority. Defaults to zero.", "type": "integer", @@ -19752,6 +19756,10 @@ "description": "WorkSpec defines the desired state of Work.", "type": "object", "properties": { + "preserveResourcesOnDeletion": { + "description": "PreserveResourcesOnDeletion controls whether resources should be preserved on the member cluster when the Work object is deleted. If set to true, resources will be preserved on the member cluster. Default is false, which means resources will be deleted along with the Work object.", + "type": "boolean" + }, "suspendDispatching": { "description": "SuspendDispatching controls whether dispatching should be suspended, nil means not suspend. Note: true means stop propagating to all clusters.", "type": "boolean" @@ -20174,6 +20182,10 @@ "description": "Placement represents the rule for select clusters to propagate resources.", "$ref": "#/definitions/com.github.karmada-io.karmada.pkg.apis.policy.v1alpha1.Placement" }, + "preserveResourcesOnDeletion": { + "description": "PreserveResourcesOnDeletion controls whether resources should be preserved on the member clusters when the binding object is deleted. If set to true, resources will be preserved on the member clusters. Default is false, which means resources will be deleted along with the binding object. This setting applies to all Work objects created under this binding object.", + "type": "boolean" + }, "propagateDeps": { "description": "PropagateDeps tells if relevant resources should be propagated automatically. It is inherited from PropagationPolicy or ClusterPropagationPolicy. default false.", "type": "boolean" diff --git a/charts/karmada/_crds/bases/policy/policy.karmada.io_clusterpropagationpolicies.yaml b/charts/karmada/_crds/bases/policy/policy.karmada.io_clusterpropagationpolicies.yaml index c1ac7c572..1def90ac4 100644 --- a/charts/karmada/_crds/bases/policy/policy.karmada.io_clusterpropagationpolicies.yaml +++ b/charts/karmada/_crds/bases/policy/policy.karmada.io_clusterpropagationpolicies.yaml @@ -687,6 +687,27 @@ spec: - Always - Never type: string + preserveResourcesOnDeletion: + description: |- + PreserveResourcesOnDeletion controls whether resources should be preserved on the + member clusters when the resource template is deleted. + If set to true, resources will be preserved on the member clusters. + Default is false, which means resources will be deleted along with the resource template. + + + This setting is particularly useful during workload migration scenarios to ensure + that rollback can occur quickly without affecting the workloads running on the + member clusters. + + + Additionally, this setting applies uniformly across all member clusters and will not + selectively control preservation on only some clusters. + + + Note: This setting does not apply to the deletion of the policy itself. + When the policy is deleted, the resource templates and their corresponding + propagated resources in member clusters will remain unchanged unless explicitly deleted. + type: boolean priority: default: 0 description: |- diff --git a/charts/karmada/_crds/bases/policy/policy.karmada.io_propagationpolicies.yaml b/charts/karmada/_crds/bases/policy/policy.karmada.io_propagationpolicies.yaml index 1415e2432..43498e621 100644 --- a/charts/karmada/_crds/bases/policy/policy.karmada.io_propagationpolicies.yaml +++ b/charts/karmada/_crds/bases/policy/policy.karmada.io_propagationpolicies.yaml @@ -684,6 +684,27 @@ spec: - Always - Never type: string + preserveResourcesOnDeletion: + description: |- + PreserveResourcesOnDeletion controls whether resources should be preserved on the + member clusters when the resource template is deleted. + If set to true, resources will be preserved on the member clusters. + Default is false, which means resources will be deleted along with the resource template. + + + This setting is particularly useful during workload migration scenarios to ensure + that rollback can occur quickly without affecting the workloads running on the + member clusters. + + + Additionally, this setting applies uniformly across all member clusters and will not + selectively control preservation on only some clusters. + + + Note: This setting does not apply to the deletion of the policy itself. + When the policy is deleted, the resource templates and their corresponding + propagated resources in member clusters will remain unchanged unless explicitly deleted. + type: boolean priority: default: 0 description: |- diff --git a/charts/karmada/_crds/bases/work/work.karmada.io_clusterresourcebindings.yaml b/charts/karmada/_crds/bases/work/work.karmada.io_clusterresourcebindings.yaml index 7895411a9..82e3fab48 100644 --- a/charts/karmada/_crds/bases/work/work.karmada.io_clusterresourcebindings.yaml +++ b/charts/karmada/_crds/bases/work/work.karmada.io_clusterresourcebindings.yaml @@ -930,6 +930,14 @@ spec: type: object type: array type: object + preserveResourcesOnDeletion: + description: |- + PreserveResourcesOnDeletion controls whether resources should be preserved on the + member clusters when the binding object is deleted. + If set to true, resources will be preserved on the member clusters. + Default is false, which means resources will be deleted along with the binding object. + This setting applies to all Work objects created under this binding object. + type: boolean propagateDeps: description: |- PropagateDeps tells if relevant resources should be propagated automatically. diff --git a/charts/karmada/_crds/bases/work/work.karmada.io_resourcebindings.yaml b/charts/karmada/_crds/bases/work/work.karmada.io_resourcebindings.yaml index f69531f23..78f9a5102 100644 --- a/charts/karmada/_crds/bases/work/work.karmada.io_resourcebindings.yaml +++ b/charts/karmada/_crds/bases/work/work.karmada.io_resourcebindings.yaml @@ -930,6 +930,14 @@ spec: type: object type: array type: object + preserveResourcesOnDeletion: + description: |- + PreserveResourcesOnDeletion controls whether resources should be preserved on the + member clusters when the binding object is deleted. + If set to true, resources will be preserved on the member clusters. + Default is false, which means resources will be deleted along with the binding object. + This setting applies to all Work objects created under this binding object. + type: boolean propagateDeps: description: |- PropagateDeps tells if relevant resources should be propagated automatically. diff --git a/charts/karmada/_crds/bases/work/work.karmada.io_works.yaml b/charts/karmada/_crds/bases/work/work.karmada.io_works.yaml index 6f1fa665e..09ebb6c2e 100644 --- a/charts/karmada/_crds/bases/work/work.karmada.io_works.yaml +++ b/charts/karmada/_crds/bases/work/work.karmada.io_works.yaml @@ -54,6 +54,13 @@ spec: spec: description: Spec represents the desired behavior of Work. properties: + preserveResourcesOnDeletion: + description: |- + PreserveResourcesOnDeletion controls whether resources should be preserved on the + member cluster when the Work object is deleted. + If set to true, resources will be preserved on the member cluster. + Default is false, which means resources will be deleted along with the Work object. + type: boolean suspendDispatching: description: |- SuspendDispatching controls whether dispatching should diff --git a/pkg/apis/policy/v1alpha1/propagation_types.go b/pkg/apis/policy/v1alpha1/propagation_types.go index ee6a38a85..60be208a4 100644 --- a/pkg/apis/policy/v1alpha1/propagation_types.go +++ b/pkg/apis/policy/v1alpha1/propagation_types.go @@ -181,6 +181,25 @@ type PropagationSpec struct { // nil means no suspension. no default values. // +optional Suspension *Suspension `json:"suspension,omitempty"` + + // PreserveResourcesOnDeletion controls whether resources should be preserved on the + // member clusters when the resource template is deleted. + // If set to true, resources will be preserved on the member clusters. + // Default is false, which means resources will be deleted along with the resource template. + // + // This setting is particularly useful during workload migration scenarios to ensure + // that rollback can occur quickly without affecting the workloads running on the + // member clusters. + // + // Additionally, this setting applies uniformly across all member clusters and will not + // selectively control preservation on only some clusters. + // + // Note: This setting does not apply to the deletion of the policy itself. + // When the policy is deleted, the resource templates and their corresponding + // propagated resources in member clusters will remain unchanged unless explicitly deleted. + // + // +optional + PreserveResourcesOnDeletion *bool `json:"preserveResourcesOnDeletion,omitempty"` } // ResourceSelector the resources will be selected. diff --git a/pkg/apis/policy/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/policy/v1alpha1/zz_generated.deepcopy.go index 764fa323e..736414ce8 100644 --- a/pkg/apis/policy/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/policy/v1alpha1/zz_generated.deepcopy.go @@ -843,6 +843,11 @@ func (in *PropagationSpec) DeepCopyInto(out *PropagationSpec) { *out = new(Suspension) (*in).DeepCopyInto(*out) } + if in.PreserveResourcesOnDeletion != nil { + in, out := &in.PreserveResourcesOnDeletion, &out.PreserveResourcesOnDeletion + *out = new(bool) + **out = **in + } return } diff --git a/pkg/apis/work/v1alpha1/work_types.go b/pkg/apis/work/v1alpha1/work_types.go index f1e03ee3e..e7484f71c 100644 --- a/pkg/apis/work/v1alpha1/work_types.go +++ b/pkg/apis/work/v1alpha1/work_types.go @@ -63,6 +63,13 @@ type WorkSpec struct { // Note: true means stop propagating to all clusters. // +optional SuspendDispatching *bool `json:"suspendDispatching,omitempty"` + + // PreserveResourcesOnDeletion controls whether resources should be preserved on the + // member cluster when the Work object is deleted. + // If set to true, resources will be preserved on the member cluster. + // Default is false, which means resources will be deleted along with the Work object. + // +optional + PreserveResourcesOnDeletion *bool `json:"preserveResourcesOnDeletion,omitempty"` } // WorkloadTemplate represents the manifest workload to be deployed on managed cluster. diff --git a/pkg/apis/work/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/work/v1alpha1/zz_generated.deepcopy.go index 824f37920..1adbecfdf 100644 --- a/pkg/apis/work/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/work/v1alpha1/zz_generated.deepcopy.go @@ -386,6 +386,11 @@ func (in *WorkSpec) DeepCopyInto(out *WorkSpec) { *out = new(bool) **out = **in } + if in.PreserveResourcesOnDeletion != nil { + in, out := &in.PreserveResourcesOnDeletion, &out.PreserveResourcesOnDeletion + *out = new(bool) + **out = **in + } return } diff --git a/pkg/apis/work/v1alpha2/binding_types.go b/pkg/apis/work/v1alpha2/binding_types.go index 25952770a..7797fb3c6 100644 --- a/pkg/apis/work/v1alpha2/binding_types.go +++ b/pkg/apis/work/v1alpha2/binding_types.go @@ -151,6 +151,14 @@ type ResourceBindingSpec struct { // nil means no suspension. no default values. // +optional Suspension *policyv1alpha1.Suspension `json:"suspension,omitempty"` + + // PreserveResourcesOnDeletion controls whether resources should be preserved on the + // member clusters when the binding object is deleted. + // If set to true, resources will be preserved on the member clusters. + // Default is false, which means resources will be deleted along with the binding object. + // This setting applies to all Work objects created under this binding object. + // +optional + PreserveResourcesOnDeletion *bool `json:"preserveResourcesOnDeletion,omitempty"` } // ObjectReference contains enough information to locate the referenced object inside current cluster. diff --git a/pkg/apis/work/v1alpha2/zz_generated.deepcopy.go b/pkg/apis/work/v1alpha2/zz_generated.deepcopy.go index 826fea036..824a7d4f5 100644 --- a/pkg/apis/work/v1alpha2/zz_generated.deepcopy.go +++ b/pkg/apis/work/v1alpha2/zz_generated.deepcopy.go @@ -353,6 +353,11 @@ func (in *ResourceBindingSpec) DeepCopyInto(out *ResourceBindingSpec) { *out = new(v1alpha1.Suspension) (*in).DeepCopyInto(*out) } + if in.PreserveResourcesOnDeletion != nil { + in, out := &in.PreserveResourcesOnDeletion, &out.PreserveResourcesOnDeletion + *out = new(bool) + **out = **in + } return } diff --git a/pkg/generated/openapi/zz_generated.openapi.go b/pkg/generated/openapi/zz_generated.openapi.go index 28551c072..74f9cfba2 100644 --- a/pkg/generated/openapi/zz_generated.openapi.go +++ b/pkg/generated/openapi/zz_generated.openapi.go @@ -4878,6 +4878,13 @@ func schema_pkg_apis_policy_v1alpha1_PropagationSpec(ref common.ReferenceCallbac Ref: ref("github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1.Suspension"), }, }, + "preserveResourcesOnDeletion": { + SchemaProps: spec.SchemaProps{ + Description: "PreserveResourcesOnDeletion controls whether resources should be preserved on the member clusters when the resource template is deleted. If set to true, resources will be preserved on the member clusters. Default is false, which means resources will be deleted along with the resource template.\n\nThis setting is particularly useful during workload migration scenarios to ensure that rollback can occur quickly without affecting the workloads running on the member clusters.\n\nAdditionally, this setting applies uniformly across all member clusters and will not selectively control preservation on only some clusters.\n\nNote: This setting does not apply to the deletion of the policy itself. When the policy is deleted, the resource templates and their corresponding propagated resources in member clusters will remain unchanged unless explicitly deleted.", + Type: []string{"boolean"}, + Format: "", + }, + }, }, Required: []string{"resourceSelectors"}, }, @@ -6383,6 +6390,13 @@ func schema_pkg_apis_work_v1alpha1_WorkSpec(ref common.ReferenceCallback) common Format: "", }, }, + "preserveResourcesOnDeletion": { + SchemaProps: spec.SchemaProps{ + Description: "PreserveResourcesOnDeletion controls whether resources should be preserved on the member cluster when the Work object is deleted. If set to true, resources will be preserved on the member cluster. Default is false, which means resources will be deleted along with the Work object.", + Type: []string{"boolean"}, + Format: "", + }, + }, }, }, }, @@ -7105,6 +7119,13 @@ func schema_pkg_apis_work_v1alpha2_ResourceBindingSpec(ref common.ReferenceCallb Ref: ref("github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1.Suspension"), }, }, + "preserveResourcesOnDeletion": { + SchemaProps: spec.SchemaProps{ + Description: "PreserveResourcesOnDeletion controls whether resources should be preserved on the member clusters when the binding object is deleted. If set to true, resources will be preserved on the member clusters. Default is false, which means resources will be deleted along with the binding object. This setting applies to all Work objects created under this binding object.", + Type: []string{"boolean"}, + Format: "", + }, + }, }, Required: []string{"resource"}, },