Merge pull request #4418 from chaunceyjiang/pr_4410
feat: set conflictResolution for dependent resources.
This commit is contained in:
commit
f7d6da341e
|
@ -561,6 +561,11 @@ func (d *DependenciesDistributor) createOrUpdateAttachedBinding(attachedBinding
|
|||
bindingKey := client.ObjectKeyFromObject(attachedBinding)
|
||||
err := d.Client.Get(context.TODO(), bindingKey, existBinding)
|
||||
if err == nil {
|
||||
// If the spec.Placement is nil, this means that existBinding is generated by the dependency mechanism.
|
||||
// If the spec.Placement is not nil, then it must be generated by PropagationPolicy.
|
||||
if existBinding.Spec.Placement == nil {
|
||||
existBinding.Spec.ConflictResolution = attachedBinding.Spec.ConflictResolution
|
||||
}
|
||||
existBinding.Spec.RequiredBy = mergeBindingSnapshot(existBinding.Spec.RequiredBy, attachedBinding.Spec.RequiredBy)
|
||||
existBinding.Labels = util.DedupeAndMergeLabels(existBinding.Labels, attachedBinding.Labels)
|
||||
existBinding.Spec.Resource = attachedBinding.Spec.Resource
|
||||
|
@ -707,6 +712,7 @@ func buildAttachedBinding(independentBinding *workv1alpha2.ResourceBinding, obje
|
|||
},
|
||||
RequiredBy: result,
|
||||
PreserveResourcesOnDeletion: independentBinding.Spec.PreserveResourcesOnDeletion,
|
||||
ConflictResolution: independentBinding.Spec.ConflictResolution,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,6 +39,7 @@ import (
|
|||
"sigs.k8s.io/controller-runtime/pkg/event"
|
||||
|
||||
configv1alpha1 "github.com/karmada-io/karmada/pkg/apis/config/v1alpha1"
|
||||
policyv1alpha1 "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1"
|
||||
workv1alpha2 "github.com/karmada-io/karmada/pkg/apis/work/v1alpha2"
|
||||
"github.com/karmada-io/karmada/pkg/util"
|
||||
"github.com/karmada-io/karmada/pkg/util/fedinformer/genericmanager"
|
||||
|
@ -2486,6 +2487,175 @@ func Test_createOrUpdateAttachedBinding(t *testing.T) {
|
|||
return fake.NewClientBuilder().WithScheme(Scheme).Build()
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "update attached binding with ConflictResolution",
|
||||
attachedBinding: &workv1alpha2.ResourceBinding{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "test-binding",
|
||||
Namespace: "test",
|
||||
ResourceVersion: "1000",
|
||||
Labels: map[string]string{"app": "nginx"},
|
||||
},
|
||||
Spec: workv1alpha2.ResourceBindingSpec{
|
||||
Resource: workv1alpha2.ObjectReference{
|
||||
APIVersion: "apps/v1",
|
||||
Kind: "Deployment",
|
||||
Namespace: "fake-ns",
|
||||
Name: "demo-app",
|
||||
ResourceVersion: "22222",
|
||||
},
|
||||
RequiredBy: []workv1alpha2.BindingSnapshot{
|
||||
{
|
||||
Namespace: "test-1",
|
||||
Name: "test-binding-1",
|
||||
Clusters: []workv1alpha2.TargetCluster{
|
||||
{
|
||||
Name: "foo",
|
||||
Replicas: 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Namespace: "default-2",
|
||||
Name: "default-binding-2",
|
||||
Clusters: []workv1alpha2.TargetCluster{
|
||||
{
|
||||
Name: "member2",
|
||||
Replicas: 4,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Namespace: "test-2",
|
||||
Name: "test-binding-2",
|
||||
Clusters: []workv1alpha2.TargetCluster{
|
||||
{
|
||||
Name: "bar",
|
||||
Replicas: 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
ConflictResolution: policyv1alpha1.ConflictOverwrite,
|
||||
},
|
||||
},
|
||||
wantErr: false,
|
||||
wantBinding: &workv1alpha2.ResourceBinding{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "test-binding",
|
||||
Namespace: "test",
|
||||
ResourceVersion: "1001",
|
||||
Labels: map[string]string{"app": "nginx", "foo": "bar"},
|
||||
},
|
||||
Spec: workv1alpha2.ResourceBindingSpec{
|
||||
Resource: workv1alpha2.ObjectReference{
|
||||
APIVersion: "apps/v1",
|
||||
Kind: "Deployment",
|
||||
Namespace: "fake-ns",
|
||||
Name: "demo-app",
|
||||
ResourceVersion: "22222",
|
||||
},
|
||||
RequiredBy: []workv1alpha2.BindingSnapshot{
|
||||
{
|
||||
Namespace: "default-1",
|
||||
Name: "default-binding-1",
|
||||
Clusters: []workv1alpha2.TargetCluster{
|
||||
{
|
||||
Name: "member1",
|
||||
Replicas: 2,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Namespace: "default-2",
|
||||
Name: "default-binding-2",
|
||||
Clusters: []workv1alpha2.TargetCluster{
|
||||
{
|
||||
Name: "member2",
|
||||
Replicas: 4,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Namespace: "default-3",
|
||||
Name: "default-binding-3",
|
||||
Clusters: []workv1alpha2.TargetCluster{
|
||||
{
|
||||
Name: "member3",
|
||||
Replicas: 4,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Namespace: "test-1",
|
||||
Name: "test-binding-1",
|
||||
Clusters: []workv1alpha2.TargetCluster{
|
||||
{
|
||||
Name: "foo",
|
||||
Replicas: 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Namespace: "test-2",
|
||||
Name: "test-binding-2",
|
||||
Clusters: []workv1alpha2.TargetCluster{
|
||||
{
|
||||
Name: "bar",
|
||||
Replicas: 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
ConflictResolution: policyv1alpha1.ConflictOverwrite,
|
||||
},
|
||||
},
|
||||
setupClient: func() client.Client {
|
||||
rb := &workv1alpha2.ResourceBinding{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "test-binding",
|
||||
Namespace: "test",
|
||||
ResourceVersion: "1000",
|
||||
Labels: map[string]string{"foo": "bar"},
|
||||
},
|
||||
Spec: workv1alpha2.ResourceBindingSpec{
|
||||
RequiredBy: []workv1alpha2.BindingSnapshot{
|
||||
{
|
||||
Namespace: "default-1",
|
||||
Name: "default-binding-1",
|
||||
Clusters: []workv1alpha2.TargetCluster{
|
||||
{
|
||||
Name: "member1",
|
||||
Replicas: 2,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Namespace: "default-2",
|
||||
Name: "default-binding-2",
|
||||
Clusters: []workv1alpha2.TargetCluster{
|
||||
{
|
||||
Name: "member2",
|
||||
Replicas: 3,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Namespace: "default-3",
|
||||
Name: "default-binding-3",
|
||||
Clusters: []workv1alpha2.TargetCluster{
|
||||
{
|
||||
Name: "member3",
|
||||
Replicas: 4,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
return fake.NewClientBuilder().WithScheme(Scheme).WithObjects(rb).Build()
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
|
|
Loading…
Reference in New Issue