Skip to content

Commit 350838d

Browse files
authored
Merge pull request #5029 from XiShanYongYe-Chang/remove-pp-name-length-limit
Remove pp/cpp name length limit
2 parents 96f5149 + 911cc44 commit 350838d

File tree

5 files changed

+148
-74
lines changed

5 files changed

+148
-74
lines changed

Diff for: pkg/util/validation/validation.go

-3
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@ import (
3131
"github.com/karmada-io/karmada/pkg/util"
3232
)
3333

34-
// LabelValueMaxLength is a label's max length
35-
const LabelValueMaxLength int = 63
36-
3734
// ValidatePropagationSpec validates a PropagationSpec before creation or update.
3835
func ValidatePropagationSpec(spec policyv1alpha1.PropagationSpec) field.ErrorList {
3936
var allErrs field.ErrorList

Diff for: pkg/webhook/clusterpropagationpolicy/mutating.go

-6
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package clusterpropagationpolicy
1919
import (
2020
"context"
2121
"encoding/json"
22-
"fmt"
2322
"net/http"
2423

2524
"github.com/google/uuid"
@@ -30,7 +29,6 @@ import (
3029
policyv1alpha1 "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1"
3130
"github.com/karmada-io/karmada/pkg/util"
3231
"github.com/karmada-io/karmada/pkg/util/helper"
33-
"github.com/karmada-io/karmada/pkg/util/validation"
3432
)
3533

3634
// MutatingAdmission mutates API request if necessary.
@@ -67,10 +65,6 @@ func (a *MutatingAdmission) Handle(_ context.Context, req admission.Request) adm
6765
helper.AddTolerations(&policy.Spec.Placement, helper.NewNotReadyToleration(a.DefaultNotReadyTolerationSeconds),
6866
helper.NewUnreachableToleration(a.DefaultUnreachableTolerationSeconds))
6967

70-
if len(policy.Name) > validation.LabelValueMaxLength {
71-
return admission.Errored(http.StatusBadRequest, fmt.Errorf("ClusterPropagationPolicy's name should be no more than %d characters", validation.LabelValueMaxLength))
72-
}
73-
7468
if helper.ContainsServiceImport(policy.Spec.ResourceSelectors) {
7569
policy.Spec.PropagateDeps = true
7670
}

Diff for: pkg/webhook/propagationpolicy/mutating.go

-5
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package propagationpolicy
1919
import (
2020
"context"
2121
"encoding/json"
22-
"fmt"
2322
"net/http"
2423

2524
"github.com/google/uuid"
@@ -31,7 +30,6 @@ import (
3130
policyv1alpha1 "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1"
3231
"github.com/karmada-io/karmada/pkg/util"
3332
"github.com/karmada-io/karmada/pkg/util/helper"
34-
"github.com/karmada-io/karmada/pkg/util/validation"
3533
)
3634

3735
// MutatingAdmission mutates API request if necessary.
@@ -75,9 +73,6 @@ func (a *MutatingAdmission) Handle(_ context.Context, req admission.Request) adm
7573
}
7674
}
7775

78-
if len(policy.Name) > validation.LabelValueMaxLength {
79-
return admission.Errored(http.StatusBadRequest, fmt.Errorf("PropagationPolicy's name should be no more than %d characters", validation.LabelValueMaxLength))
80-
}
8176
// Set default spread constraints if both 'SpreadByField' and 'SpreadByLabel' not set.
8277
helper.SetDefaultSpreadConstraints(policy.Spec.Placement.SpreadConstraints)
8378
helper.AddTolerations(&policy.Spec.Placement, helper.NewNotReadyToleration(a.DefaultNotReadyTolerationSeconds),

Diff for: test/e2e/clusterpropagationpolicy_test.go

+73-21
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,22 @@ import (
4343
testhelper "github.com/karmada-io/karmada/test/helper"
4444
)
4545

46-
var _ = ginkgo.Describe("[BasicClusterPropagation] propagation testing", func() {
46+
var _ = ginkgo.Describe("[BasicCase] ClusterPropagationPolicy testing", func() {
47+
var policyName string
48+
var policy *policyv1alpha1.ClusterPropagationPolicy
49+
50+
ginkgo.JustBeforeEach(func() {
51+
framework.CreateClusterPropagationPolicy(karmadaClient, policy)
52+
ginkgo.DeferCleanup(func() {
53+
framework.RemoveClusterPropagationPolicy(karmadaClient, policy.Name)
54+
})
55+
})
56+
4757
ginkgo.Context("CustomResourceDefinition propagation testing", func() {
4858
var crdGroup string
4959
var randStr string
5060
var crdSpecNames apiextensionsv1.CustomResourceDefinitionNames
5161
var crd *apiextensionsv1.CustomResourceDefinition
52-
var crdPolicy *policyv1alpha1.ClusterPropagationPolicy
5362

5463
ginkgo.BeforeEach(func() {
5564
crdGroup = fmt.Sprintf("example-%s.karmada.io", rand.String(RandomStrLength))
@@ -61,7 +70,8 @@ var _ = ginkgo.Describe("[BasicClusterPropagation] propagation testing", func()
6170
Singular: fmt.Sprintf("foo%s", randStr),
6271
}
6372
crd = testhelper.NewCustomResourceDefinition(crdGroup, crdSpecNames, apiextensionsv1.NamespaceScoped)
64-
crdPolicy = testhelper.NewClusterPropagationPolicy(crd.Name, []policyv1alpha1.ResourceSelector{
73+
policyName = crd.Name
74+
policy = testhelper.NewClusterPropagationPolicy(policyName, []policyv1alpha1.ResourceSelector{
6575
{
6676
APIVersion: crd.APIVersion,
6777
Kind: crd.Kind,
@@ -75,10 +85,8 @@ var _ = ginkgo.Describe("[BasicClusterPropagation] propagation testing", func()
7585
})
7686

7787
ginkgo.BeforeEach(func() {
78-
framework.CreateClusterPropagationPolicy(karmadaClient, crdPolicy)
7988
framework.CreateCRD(dynamicClient, crd)
8089
ginkgo.DeferCleanup(func() {
81-
framework.RemoveClusterPropagationPolicy(karmadaClient, crdPolicy.Name)
8290
framework.RemoveCRD(dynamicClient, crd.Name)
8391
framework.WaitCRDDisappearedOnClusters(framework.ClusterNames(), crd.Name)
8492
})
@@ -94,8 +102,6 @@ var _ = ginkgo.Describe("[BasicClusterPropagation] propagation testing", func()
94102
ginkgo.Context("ClusterRole propagation testing", func() {
95103
var (
96104
clusterRoleName string
97-
policyName string
98-
policy *policyv1alpha1.ClusterPropagationPolicy
99105
clusterRole *rbacv1.ClusterRole
100106
)
101107

@@ -118,10 +124,8 @@ var _ = ginkgo.Describe("[BasicClusterPropagation] propagation testing", func()
118124
})
119125

120126
ginkgo.BeforeEach(func() {
121-
framework.CreateClusterPropagationPolicy(karmadaClient, policy)
122127
framework.CreateClusterRole(kubeClient, clusterRole)
123128
ginkgo.DeferCleanup(func() {
124-
framework.RemoveClusterPropagationPolicy(karmadaClient, policy.Name)
125129
framework.RemoveClusterRole(kubeClient, clusterRole.Name)
126130
framework.WaitClusterRoleDisappearOnClusters(framework.ClusterNames(), clusterRole.Name)
127131
})
@@ -138,8 +142,6 @@ var _ = ginkgo.Describe("[BasicClusterPropagation] propagation testing", func()
138142
ginkgo.Context("ClusterRoleBinding propagation testing", func() {
139143
var (
140144
clusterRoleBindingName string
141-
policyName string
142-
policy *policyv1alpha1.ClusterPropagationPolicy
143145
clusterRoleBinding *rbacv1.ClusterRoleBinding
144146
)
145147

@@ -162,10 +164,8 @@ var _ = ginkgo.Describe("[BasicClusterPropagation] propagation testing", func()
162164
})
163165

164166
ginkgo.BeforeEach(func() {
165-
framework.CreateClusterPropagationPolicy(karmadaClient, policy)
166167
framework.CreateClusterRoleBinding(kubeClient, clusterRoleBinding)
167168
ginkgo.DeferCleanup(func() {
168-
framework.RemoveClusterPropagationPolicy(karmadaClient, policy.Name)
169169
framework.RemoveClusterRoleBinding(kubeClient, clusterRoleBinding.Name)
170170
framework.WaitClusterRoleBindingDisappearOnClusters(framework.ClusterNames(), clusterRoleBinding.Name)
171171
})
@@ -180,13 +180,12 @@ var _ = ginkgo.Describe("[BasicClusterPropagation] propagation testing", func()
180180
})
181181

182182
ginkgo.Context("Deployment propagation testing", func() {
183-
var policy *policyv1alpha1.ClusterPropagationPolicy
184183
var deployment *appsv1.Deployment
185184
var targetMember string
186185

187186
ginkgo.BeforeEach(func() {
188187
targetMember = framework.ClusterNames()[0]
189-
policyName := cppNamePrefix + rand.String(RandomStrLength)
188+
policyName = cppNamePrefix + rand.String(RandomStrLength)
190189
deploymentName := deploymentNamePrefix + rand.String(RandomStrLength)
191190

192191
deployment = testhelper.NewDeployment(testNamespace, deploymentName)
@@ -204,10 +203,8 @@ var _ = ginkgo.Describe("[BasicClusterPropagation] propagation testing", func()
204203
})
205204

206205
ginkgo.BeforeEach(func() {
207-
framework.CreateClusterPropagationPolicy(karmadaClient, policy)
208206
framework.CreateDeployment(kubeClient, deployment)
209207
ginkgo.DeferCleanup(func() {
210-
framework.RemoveClusterPropagationPolicy(karmadaClient, policy.Name)
211208
framework.RemoveDeployment(kubeClient, deployment.Namespace, deployment.Name)
212209
})
213210
})
@@ -227,7 +224,62 @@ var _ = ginkgo.Describe("[BasicClusterPropagation] propagation testing", func()
227224
})
228225
})
229226

230-
var _ = ginkgo.Describe("[AdvancedClusterPropagation] propagation testing", func() {
227+
var _ = ginkgo.Describe("[CornerCase] ClusterPropagationPolicy testing", func() {
228+
var policyName string
229+
var policy *policyv1alpha1.ClusterPropagationPolicy
230+
231+
ginkgo.JustBeforeEach(func() {
232+
framework.CreateClusterPropagationPolicy(karmadaClient, policy)
233+
ginkgo.DeferCleanup(func() {
234+
framework.RemoveClusterPropagationPolicy(karmadaClient, policy.Name)
235+
})
236+
})
237+
238+
ginkgo.Context("Deployment propagation testing", func() {
239+
var deployment *appsv1.Deployment
240+
var targetMember string
241+
242+
ginkgo.BeforeEach(func() {
243+
targetMember = framework.ClusterNames()[0]
244+
policyName = cppNamePrefix + rand.String(RandomStrLength)
245+
deploymentName := deploymentNamePrefix + rand.String(RandomStrLength)
246+
247+
deployment = testhelper.NewDeployment(testNamespace, deploymentName)
248+
policy = testhelper.NewClusterPropagationPolicy(policyName, []policyv1alpha1.ResourceSelector{
249+
{
250+
APIVersion: deployment.APIVersion,
251+
Kind: deployment.Kind,
252+
Name: deployment.Name,
253+
}}, policyv1alpha1.Placement{
254+
ClusterAffinity: &policyv1alpha1.ClusterAffinity{
255+
ClusterNames: []string{targetMember},
256+
},
257+
})
258+
})
259+
260+
ginkgo.BeforeEach(func() {
261+
framework.CreateDeployment(kubeClient, deployment)
262+
ginkgo.DeferCleanup(func() {
263+
framework.RemoveDeployment(kubeClient, deployment.Namespace, deployment.Name)
264+
})
265+
})
266+
267+
ginkgo.It("deployment propagation testing", func() {
268+
framework.WaitDeploymentPresentOnClusterFitWith(targetMember, deployment.Namespace, deployment.Name,
269+
func(d *appsv1.Deployment) bool {
270+
return *d.Spec.Replicas == *deployment.Spec.Replicas
271+
})
272+
273+
framework.UpdateDeploymentReplicas(kubeClient, deployment, updateDeploymentReplicas)
274+
framework.WaitDeploymentPresentOnClusterFitWith(targetMember, deployment.Namespace, deployment.Name,
275+
func(deployment *appsv1.Deployment) bool {
276+
return *deployment.Spec.Replicas == updateDeploymentReplicas
277+
})
278+
})
279+
})
280+
})
281+
282+
var _ = ginkgo.Describe("[AdvancedCase] ClusterPropagationPolicy testing", func() {
231283
ginkgo.Context("Edit ClusterPropagationPolicy ResourceSelectors", func() {
232284
ginkgo.When("propagate namespace scope resource", func() {
233285
var policy *policyv1alpha1.ClusterPropagationPolicy
@@ -552,7 +604,7 @@ var _ = ginkgo.Describe("[AdvancedClusterPropagation] propagation testing", func
552604

553605
// ImplicitPriority more than one PP matches the object, we should choose the most suitable one.
554606
// Set it to run sequentially to avoid affecting other test cases.
555-
var _ = framework.SerialDescribe("[ImplicitPriority] propagation testing", func() {
607+
var _ = framework.SerialDescribe("[ImplicitPriority] ClusterPropagationPolicy testing", func() {
556608
ginkgo.Context("priorityMatchName/priorityMatchLabel/priorityMatchAll propagation testing", func() {
557609
var priorityMatchName, priorityMatchLabelSelector, priorityMatchAll string
558610
var deploymentNamespace, deploymentName string
@@ -652,7 +704,7 @@ var _ = framework.SerialDescribe("[ImplicitPriority] propagation testing", func(
652704

653705
// ExplicitPriority more than one CPP matches the object, we should select the one with the highest explicit priority, if the
654706
// explicit priority is same, select the one with the highest implicit priority.
655-
var _ = ginkgo.Describe("[ExplicitPriority] propagation testing", func() {
707+
var _ = ginkgo.Describe("[ExplicitPriority] ClusterPropagationPolicy testing", func() {
656708
ginkgo.Context("high explicit/low priority/implicit priority ClusterPropagationPolicy propagation testing", func() {
657709
var higherPriorityLabelSelector, lowerPriorityMatchName, implicitPriorityMatchName string
658710
var deploymentNamespace, deploymentName string
@@ -809,7 +861,7 @@ var _ = ginkgo.Describe("[ExplicitPriority] propagation testing", func() {
809861

810862
// Delete when delete a clusterPropagationPolicy, and no more clusterPropagationPolicy matches the object, something like
811863
// labels should be cleaned.
812-
var _ = ginkgo.Describe("[Delete] clusterPropagation testing", func() {
864+
var _ = ginkgo.Describe("[DeleteCase] ClusterPropagationPolicy testing", func() {
813865
ginkgo.Context("delete clusterPropagation and remove the labels and annotations from the resource template and reference binding", func() {
814866
var policy *policyv1alpha1.ClusterPropagationPolicy
815867
var deployment *appsv1.Deployment

0 commit comments

Comments
 (0)