decouple suspension of propagation and resourcebinding
Signed-off-by: Monokaix <changxuzheng@huawei.com>
This commit is contained in:
parent
7112723f3d
commit
eb2a4bd051
|
@ -20395,7 +20395,7 @@
|
|||
},
|
||||
"suspension": {
|
||||
"description": "Suspension declares the policy for suspending different aspects of propagation. nil means no suspension. no default values.",
|
||||
"$ref": "#/definitions/com.github.karmada-io.karmada.pkg.apis.policy.v1alpha1.Suspension"
|
||||
"$ref": "#/definitions/com.github.karmada-io.karmada.pkg.apis.work.v1alpha2.Suspension"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -20434,6 +20434,20 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"com.github.karmada-io.karmada.pkg.apis.work.v1alpha2.Suspension": {
|
||||
"description": "Suspension defines the policy for suspending of propagation.",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"dispatching": {
|
||||
"description": "Dispatching controls whether dispatching should be suspended. nil means not suspend, no default value, only accepts 'true'. Note: true means stop propagating to all clusters. Can not co-exist with DispatchingOnClusters which is used to suspend particular clusters.",
|
||||
"type": "boolean"
|
||||
},
|
||||
"dispatchingOnClusters": {
|
||||
"description": "DispatchingOnClusters declares a list of clusters to which the dispatching should be suspended. Note: Can not co-exist with Dispatching which is used to suspend all.",
|
||||
"$ref": "#/definitions/com.github.karmada-io.karmada.pkg.apis.policy.v1alpha1.SuspendClusters"
|
||||
}
|
||||
}
|
||||
},
|
||||
"com.github.karmada-io.karmada.pkg.apis.work.v1alpha2.TargetCluster": {
|
||||
"description": "TargetCluster represents the identifier of a member cluster.",
|
||||
"type": "object",
|
||||
|
|
|
@ -150,7 +150,7 @@ type ResourceBindingSpec struct {
|
|||
// Suspension declares the policy for suspending different aspects of propagation.
|
||||
// nil means no suspension. no default values.
|
||||
// +optional
|
||||
Suspension *policyv1alpha1.Suspension `json:"suspension,omitempty"`
|
||||
Suspension *Suspension `json:"suspension,omitempty"`
|
||||
|
||||
// PreserveResourcesOnDeletion controls whether resources should be preserved on the
|
||||
// member clusters when the binding object is deleted.
|
||||
|
@ -322,6 +322,11 @@ type BindingSnapshot struct {
|
|||
Clusters []TargetCluster `json:"clusters,omitempty"`
|
||||
}
|
||||
|
||||
// Suspension defines the policy for suspending of propagation.
|
||||
type Suspension struct {
|
||||
policyv1alpha1.Suspension `json:",inline"`
|
||||
}
|
||||
|
||||
// ResourceBindingStatus represents the overall status of the strategy as well as the referenced resources.
|
||||
type ResourceBindingStatus struct {
|
||||
// SchedulerObservedGeneration is the generation(.metadata.generation) observed by the scheduler.
|
||||
|
|
|
@ -362,7 +362,7 @@ func (in *ResourceBindingSpec) DeepCopyInto(out *ResourceBindingSpec) {
|
|||
}
|
||||
if in.Suspension != nil {
|
||||
in, out := &in.Suspension, &out.Suspension
|
||||
*out = new(v1alpha1.Suspension)
|
||||
*out = new(Suspension)
|
||||
(*in).DeepCopyInto(*out)
|
||||
}
|
||||
if in.PreserveResourcesOnDeletion != nil {
|
||||
|
@ -417,6 +417,23 @@ func (in *ResourceBindingStatus) DeepCopy() *ResourceBindingStatus {
|
|||
return out
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *Suspension) DeepCopyInto(out *Suspension) {
|
||||
*out = *in
|
||||
in.Suspension.DeepCopyInto(&out.Suspension)
|
||||
return
|
||||
}
|
||||
|
||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Suspension.
|
||||
func (in *Suspension) DeepCopy() *Suspension {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := new(Suspension)
|
||||
in.DeepCopyInto(out)
|
||||
return out
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *TargetCluster) DeepCopyInto(out *TargetCluster) {
|
||||
*out = *in
|
||||
|
|
|
@ -302,7 +302,7 @@ func needReviseReplicas(replicas int32, placement *policyv1alpha1.Placement) boo
|
|||
return replicas > 0 && placement != nil && placement.ReplicaSchedulingType() == policyv1alpha1.ReplicaSchedulingTypeDivided
|
||||
}
|
||||
|
||||
func shouldSuspendDispatching(suspension *policyv1alpha1.Suspension, targetCluster workv1alpha2.TargetCluster) bool {
|
||||
func shouldSuspendDispatching(suspension *workv1alpha2.Suspension, targetCluster workv1alpha2.TargetCluster) bool {
|
||||
if suspension == nil {
|
||||
return false
|
||||
}
|
||||
|
|
|
@ -321,7 +321,7 @@ func Test_mergeConflictResolution(t *testing.T) {
|
|||
|
||||
func Test_shouldSuspendDispatching(t *testing.T) {
|
||||
type args struct {
|
||||
suspension *policyv1alpha1.Suspension
|
||||
suspension *workv1alpha2.Suspension
|
||||
targetCluster workv1alpha2.TargetCluster
|
||||
}
|
||||
tests := []struct {
|
||||
|
@ -337,28 +337,28 @@ func Test_shouldSuspendDispatching(t *testing.T) {
|
|||
{
|
||||
name: "false for nil dispatching",
|
||||
args: args{
|
||||
suspension: &policyv1alpha1.Suspension{Dispatching: nil},
|
||||
suspension: &workv1alpha2.Suspension{Suspension: policyv1alpha1.Suspension{Dispatching: nil}},
|
||||
},
|
||||
want: false,
|
||||
},
|
||||
{
|
||||
name: "false for not suspension",
|
||||
args: args{
|
||||
suspension: &policyv1alpha1.Suspension{Dispatching: ptr.To(false)},
|
||||
suspension: &workv1alpha2.Suspension{Suspension: policyv1alpha1.Suspension{Dispatching: ptr.To(false)}},
|
||||
},
|
||||
want: false,
|
||||
},
|
||||
{
|
||||
name: "true for suspension",
|
||||
args: args{
|
||||
suspension: &policyv1alpha1.Suspension{Dispatching: ptr.To(true)},
|
||||
suspension: &workv1alpha2.Suspension{Suspension: policyv1alpha1.Suspension{Dispatching: ptr.To(true)}},
|
||||
},
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "true for matching cluster",
|
||||
args: args{
|
||||
suspension: &policyv1alpha1.Suspension{DispatchingOnClusters: &policyv1alpha1.SuspendClusters{ClusterNames: []string{"clusterA"}}},
|
||||
suspension: &workv1alpha2.Suspension{Suspension: policyv1alpha1.Suspension{DispatchingOnClusters: &policyv1alpha1.SuspendClusters{ClusterNames: []string{"clusterA"}}}},
|
||||
targetCluster: workv1alpha2.TargetCluster{Name: "clusterA"},
|
||||
},
|
||||
want: true,
|
||||
|
@ -366,7 +366,7 @@ func Test_shouldSuspendDispatching(t *testing.T) {
|
|||
{
|
||||
name: "false for mismatched cluster",
|
||||
args: args{
|
||||
suspension: &policyv1alpha1.Suspension{DispatchingOnClusters: &policyv1alpha1.SuspendClusters{ClusterNames: []string{"clusterB"}}},
|
||||
suspension: &workv1alpha2.Suspension{Suspension: policyv1alpha1.Suspension{DispatchingOnClusters: &policyv1alpha1.SuspendClusters{ClusterNames: []string{"clusterB"}}}},
|
||||
targetCluster: workv1alpha2.TargetCluster{Name: "clusterA"},
|
||||
},
|
||||
want: false,
|
||||
|
|
|
@ -724,7 +724,6 @@ func (d *ResourceDetector) BuildResourceBinding(object *unstructured.Unstructure
|
|||
Placement: &policySpec.Placement,
|
||||
Failover: policySpec.Failover,
|
||||
ConflictResolution: policySpec.ConflictResolution,
|
||||
Suspension: policySpec.Suspension,
|
||||
PreserveResourcesOnDeletion: policySpec.PreserveResourcesOnDeletion,
|
||||
Resource: workv1alpha2.ObjectReference{
|
||||
APIVersion: object.GetAPIVersion(),
|
||||
|
@ -736,6 +735,11 @@ func (d *ResourceDetector) BuildResourceBinding(object *unstructured.Unstructure
|
|||
},
|
||||
},
|
||||
}
|
||||
|
||||
if policySpec.Suspension != nil {
|
||||
propagationBinding.Spec.Suspension = &workv1alpha2.Suspension{Suspension: *policySpec.Suspension}
|
||||
}
|
||||
|
||||
claimFunc(propagationBinding, policyID, policyMeta)
|
||||
|
||||
if d.ResourceInterpreter.HookEnabled(object.GroupVersionKind(), configv1alpha1.InterpreterOperationInterpretReplica) {
|
||||
|
@ -769,7 +773,6 @@ func (d *ResourceDetector) BuildClusterResourceBinding(object *unstructured.Unst
|
|||
Placement: &policySpec.Placement,
|
||||
Failover: policySpec.Failover,
|
||||
ConflictResolution: policySpec.ConflictResolution,
|
||||
Suspension: policySpec.Suspension,
|
||||
PreserveResourcesOnDeletion: policySpec.PreserveResourcesOnDeletion,
|
||||
Resource: workv1alpha2.ObjectReference{
|
||||
APIVersion: object.GetAPIVersion(),
|
||||
|
@ -781,6 +784,10 @@ func (d *ResourceDetector) BuildClusterResourceBinding(object *unstructured.Unst
|
|||
},
|
||||
}
|
||||
|
||||
if policySpec.Suspension != nil {
|
||||
binding.Spec.Suspension = &workv1alpha2.Suspension{Suspension: *policySpec.Suspension}
|
||||
}
|
||||
|
||||
AddCPPClaimMetadata(binding, policyID, policyMeta)
|
||||
|
||||
if d.ResourceInterpreter.HookEnabled(object.GroupVersionKind(), configv1alpha1.InterpreterOperationInterpretReplica) {
|
||||
|
|
|
@ -180,6 +180,7 @@ func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenA
|
|||
"github.com/karmada-io/karmada/pkg/apis/work/v1alpha2.ResourceBindingList": schema_pkg_apis_work_v1alpha2_ResourceBindingList(ref),
|
||||
"github.com/karmada-io/karmada/pkg/apis/work/v1alpha2.ResourceBindingSpec": schema_pkg_apis_work_v1alpha2_ResourceBindingSpec(ref),
|
||||
"github.com/karmada-io/karmada/pkg/apis/work/v1alpha2.ResourceBindingStatus": schema_pkg_apis_work_v1alpha2_ResourceBindingStatus(ref),
|
||||
"github.com/karmada-io/karmada/pkg/apis/work/v1alpha2.Suspension": schema_pkg_apis_work_v1alpha2_Suspension(ref),
|
||||
"github.com/karmada-io/karmada/pkg/apis/work/v1alpha2.TargetCluster": schema_pkg_apis_work_v1alpha2_TargetCluster(ref),
|
||||
"github.com/karmada-io/karmada/pkg/apis/work/v1alpha2.TaskOptions": schema_pkg_apis_work_v1alpha2_TaskOptions(ref),
|
||||
"k8s.io/api/admissionregistration/v1.AuditAnnotation": schema_k8sio_api_admissionregistration_v1_AuditAnnotation(ref),
|
||||
|
@ -7374,7 +7375,7 @@ func schema_pkg_apis_work_v1alpha2_ResourceBindingSpec(ref common.ReferenceCallb
|
|||
"suspension": {
|
||||
SchemaProps: spec.SchemaProps{
|
||||
Description: "Suspension declares the policy for suspending different aspects of propagation. nil means no suspension. no default values.",
|
||||
Ref: ref("github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1.Suspension"),
|
||||
Ref: ref("github.com/karmada-io/karmada/pkg/apis/work/v1alpha2.Suspension"),
|
||||
},
|
||||
},
|
||||
"preserveResourcesOnDeletion": {
|
||||
|
@ -7389,7 +7390,7 @@ func schema_pkg_apis_work_v1alpha2_ResourceBindingSpec(ref common.ReferenceCallb
|
|||
},
|
||||
},
|
||||
Dependencies: []string{
|
||||
"github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1.FailoverBehavior", "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1.Placement", "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1.Suspension", "github.com/karmada-io/karmada/pkg/apis/work/v1alpha2.BindingSnapshot", "github.com/karmada-io/karmada/pkg/apis/work/v1alpha2.GracefulEvictionTask", "github.com/karmada-io/karmada/pkg/apis/work/v1alpha2.ObjectReference", "github.com/karmada-io/karmada/pkg/apis/work/v1alpha2.ReplicaRequirements", "github.com/karmada-io/karmada/pkg/apis/work/v1alpha2.TargetCluster", "k8s.io/apimachinery/pkg/apis/meta/v1.Time"},
|
||||
"github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1.FailoverBehavior", "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1.Placement", "github.com/karmada-io/karmada/pkg/apis/work/v1alpha2.BindingSnapshot", "github.com/karmada-io/karmada/pkg/apis/work/v1alpha2.GracefulEvictionTask", "github.com/karmada-io/karmada/pkg/apis/work/v1alpha2.ObjectReference", "github.com/karmada-io/karmada/pkg/apis/work/v1alpha2.ReplicaRequirements", "github.com/karmada-io/karmada/pkg/apis/work/v1alpha2.Suspension", "github.com/karmada-io/karmada/pkg/apis/work/v1alpha2.TargetCluster", "k8s.io/apimachinery/pkg/apis/meta/v1.Time"},
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7456,6 +7457,34 @@ func schema_pkg_apis_work_v1alpha2_ResourceBindingStatus(ref common.ReferenceCal
|
|||
}
|
||||
}
|
||||
|
||||
func schema_pkg_apis_work_v1alpha2_Suspension(ref common.ReferenceCallback) common.OpenAPIDefinition {
|
||||
return common.OpenAPIDefinition{
|
||||
Schema: spec.Schema{
|
||||
SchemaProps: spec.SchemaProps{
|
||||
Description: "Suspension defines the policy for suspending of propagation.",
|
||||
Type: []string{"object"},
|
||||
Properties: map[string]spec.Schema{
|
||||
"dispatching": {
|
||||
SchemaProps: spec.SchemaProps{
|
||||
Description: "Dispatching controls whether dispatching should be suspended. nil means not suspend, no default value, only accepts 'true'. Note: true means stop propagating to all clusters. Can not co-exist with DispatchingOnClusters which is used to suspend particular clusters.",
|
||||
Type: []string{"boolean"},
|
||||
Format: "",
|
||||
},
|
||||
},
|
||||
"dispatchingOnClusters": {
|
||||
SchemaProps: spec.SchemaProps{
|
||||
Description: "DispatchingOnClusters declares a list of clusters to which the dispatching should be suspended. Note: Can not co-exist with Dispatching which is used to suspend all.",
|
||||
Ref: ref("github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1.SuspendClusters"),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
Dependencies: []string{
|
||||
"github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1.SuspendClusters"},
|
||||
}
|
||||
}
|
||||
|
||||
func schema_pkg_apis_work_v1alpha2_TargetCluster(ref common.ReferenceCallback) common.OpenAPIDefinition {
|
||||
return common.OpenAPIDefinition{
|
||||
Schema: spec.Schema{
|
||||
|
|
Loading…
Reference in New Issue