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

decouple suspension of propagation and resourcebinding #5974

Merged
merged 1 commit into from
Dec 28, 2024
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
16 changes: 15 additions & 1 deletion api/openapi-spec/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
},
Expand Down Expand Up @@ -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",
Expand Down
7 changes: 6 additions & 1 deletion pkg/apis/work/v1alpha2/binding_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
19 changes: 18 additions & 1 deletion pkg/apis/work/v1alpha2/zz_generated.deepcopy.go

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

2 changes: 1 addition & 1 deletion pkg/controllers/binding/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
12 changes: 6 additions & 6 deletions pkg/controllers/binding/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -337,36 +337,36 @@ 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,
},
{
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,
Expand Down
11 changes: 9 additions & 2 deletions pkg/detector/detector.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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) {
Expand Down Expand Up @@ -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(),
Expand All @@ -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) {
Expand Down
33 changes: 31 additions & 2 deletions pkg/generated/openapi/zz_generated.openapi.go

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