Skip to content

Commit

Permalink
decouple suspension of propagation and resourcebinding
Browse files Browse the repository at this point in the history
Signed-off-by: Monokaix <[email protected]>
  • Loading branch information
Monokaix committed Dec 28, 2024
1 parent 7112723 commit e3390d9
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 14 deletions.
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
20 changes: 14 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 @@ -334,39 +334,47 @@ func Test_shouldSuspendDispatching(t *testing.T) {
args: args{},
want: false,
},

{
name: "false for nil suspension.Suspension",
args: args{
suspension: &workv1alpha2.Suspension{},
},
want: false,
},
{
name: "false for nil dispatching",
args: args{
suspension: &policyv1alpha1.Suspension{Dispatching: nil},
suspension: &workv1alpha2.Suspension{Suspension: &policyv1alpha1.Suspension{Dispatching: nil}},

Check failure on line 348 in pkg/controllers/binding/common_test.go

View workflow job for this annotation

GitHub Actions / lint

cannot use &policyv1alpha1.Suspension{…} (value of type *"github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1".Suspension) as "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1".Suspension value in struct literal

Check failure on line 348 in pkg/controllers/binding/common_test.go

View workflow job for this annotation

GitHub Actions / unit test

cannot use &policyv1alpha1.Suspension{…} (value of type *"github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1".Suspension) as "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1".Suspension value in struct literal

Check failure on line 348 in pkg/controllers/binding/common_test.go

View workflow job for this annotation

GitHub Actions / unit test

cannot use &policyv1alpha1.Suspension{…} (value of type *"github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1".Suspension) as "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1".Suspension value in struct literal
},
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)}},

Check failure on line 355 in pkg/controllers/binding/common_test.go

View workflow job for this annotation

GitHub Actions / lint

cannot use &policyv1alpha1.Suspension{…} (value of type *"github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1".Suspension) as "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1".Suspension value in struct literal

Check failure on line 355 in pkg/controllers/binding/common_test.go

View workflow job for this annotation

GitHub Actions / unit test

cannot use &policyv1alpha1.Suspension{…} (value of type *"github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1".Suspension) as "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1".Suspension value in struct literal

Check failure on line 355 in pkg/controllers/binding/common_test.go

View workflow job for this annotation

GitHub Actions / unit test

cannot use &policyv1alpha1.Suspension{…} (value of type *"github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1".Suspension) as "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1".Suspension value in struct literal
},
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)}},

Check failure on line 362 in pkg/controllers/binding/common_test.go

View workflow job for this annotation

GitHub Actions / lint

cannot use &policyv1alpha1.Suspension{…} (value of type *"github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1".Suspension) as "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1".Suspension value in struct literal

Check failure on line 362 in pkg/controllers/binding/common_test.go

View workflow job for this annotation

GitHub Actions / unit test

cannot use &policyv1alpha1.Suspension{…} (value of type *"github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1".Suspension) as "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1".Suspension value in struct literal

Check failure on line 362 in pkg/controllers/binding/common_test.go

View workflow job for this annotation

GitHub Actions / unit test

cannot use &policyv1alpha1.Suspension{…} (value of type *"github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1".Suspension) as "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1".Suspension value in struct literal
},
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"}}}},

Check failure on line 369 in pkg/controllers/binding/common_test.go

View workflow job for this annotation

GitHub Actions / lint

cannot use &policyv1alpha1.Suspension{…} (value of type *"github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1".Suspension) as "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1".Suspension value in struct literal

Check failure on line 369 in pkg/controllers/binding/common_test.go

View workflow job for this annotation

GitHub Actions / unit test

cannot use &policyv1alpha1.Suspension{…} (value of type *"github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1".Suspension) as "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1".Suspension value in struct literal

Check failure on line 369 in pkg/controllers/binding/common_test.go

View workflow job for this annotation

GitHub Actions / unit test

cannot use &policyv1alpha1.Suspension{…} (value of type *"github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1".Suspension) as "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1".Suspension value in struct literal
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"}}}},

Check failure on line 377 in pkg/controllers/binding/common_test.go

View workflow job for this annotation

GitHub Actions / lint

cannot use &policyv1alpha1.Suspension{…} (value of type *"github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1".Suspension) as "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1".Suspension value in struct literal (typecheck)

Check failure on line 377 in pkg/controllers/binding/common_test.go

View workflow job for this annotation

GitHub Actions / unit test

cannot use &policyv1alpha1.Suspension{…} (value of type *"github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1".Suspension) as "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1".Suspension value in struct literal

Check failure on line 377 in pkg/controllers/binding/common_test.go

View workflow job for this annotation

GitHub Actions / unit test

cannot use &policyv1alpha1.Suspension{…} (value of type *"github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1".Suspension) as "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1".Suspension value in struct literal
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.

0 comments on commit e3390d9

Please sign in to comment.