Skip to content

Commit

Permalink
remove pp/cpp name length limit
Browse files Browse the repository at this point in the history
Signed-off-by: changzhen <[email protected]>
  • Loading branch information
XiShanYongYe-Chang committed Aug 16, 2024
1 parent e7cb133 commit 911cc44
Show file tree
Hide file tree
Showing 5 changed files with 148 additions and 74 deletions.
3 changes: 0 additions & 3 deletions pkg/util/validation/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ import (
"github.com/karmada-io/karmada/pkg/util"
)

// LabelValueMaxLength is a label's max length
const LabelValueMaxLength int = 63

// ValidatePropagationSpec validates a PropagationSpec before creation or update.
func ValidatePropagationSpec(spec policyv1alpha1.PropagationSpec) field.ErrorList {
var allErrs field.ErrorList
Expand Down
6 changes: 0 additions & 6 deletions pkg/webhook/clusterpropagationpolicy/mutating.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package clusterpropagationpolicy
import (
"context"
"encoding/json"
"fmt"
"net/http"

"github.com/google/uuid"
Expand All @@ -30,7 +29,6 @@ import (
policyv1alpha1 "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1"
"github.com/karmada-io/karmada/pkg/util"
"github.com/karmada-io/karmada/pkg/util/helper"
"github.com/karmada-io/karmada/pkg/util/validation"
)

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

if len(policy.Name) > validation.LabelValueMaxLength {
return admission.Errored(http.StatusBadRequest, fmt.Errorf("ClusterPropagationPolicy's name should be no more than %d characters", validation.LabelValueMaxLength))
}

if helper.ContainsServiceImport(policy.Spec.ResourceSelectors) {
policy.Spec.PropagateDeps = true
}
Expand Down
5 changes: 0 additions & 5 deletions pkg/webhook/propagationpolicy/mutating.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package propagationpolicy
import (
"context"
"encoding/json"
"fmt"
"net/http"

"github.com/google/uuid"
Expand All @@ -31,7 +30,6 @@ import (
policyv1alpha1 "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1"
"github.com/karmada-io/karmada/pkg/util"
"github.com/karmada-io/karmada/pkg/util/helper"
"github.com/karmada-io/karmada/pkg/util/validation"
)

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

if len(policy.Name) > validation.LabelValueMaxLength {
return admission.Errored(http.StatusBadRequest, fmt.Errorf("PropagationPolicy's name should be no more than %d characters", validation.LabelValueMaxLength))
}
// Set default spread constraints if both 'SpreadByField' and 'SpreadByLabel' not set.
helper.SetDefaultSpreadConstraints(policy.Spec.Placement.SpreadConstraints)
helper.AddTolerations(&policy.Spec.Placement, helper.NewNotReadyToleration(a.DefaultNotReadyTolerationSeconds),
Expand Down
94 changes: 73 additions & 21 deletions test/e2e/clusterpropagationpolicy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,22 @@ import (
testhelper "github.com/karmada-io/karmada/test/helper"
)

var _ = ginkgo.Describe("[BasicClusterPropagation] propagation testing", func() {
var _ = ginkgo.Describe("[BasicCase] ClusterPropagationPolicy testing", func() {
var policyName string
var policy *policyv1alpha1.ClusterPropagationPolicy

ginkgo.JustBeforeEach(func() {
framework.CreateClusterPropagationPolicy(karmadaClient, policy)
ginkgo.DeferCleanup(func() {
framework.RemoveClusterPropagationPolicy(karmadaClient, policy.Name)
})
})

ginkgo.Context("CustomResourceDefinition propagation testing", func() {
var crdGroup string
var randStr string
var crdSpecNames apiextensionsv1.CustomResourceDefinitionNames
var crd *apiextensionsv1.CustomResourceDefinition
var crdPolicy *policyv1alpha1.ClusterPropagationPolicy

ginkgo.BeforeEach(func() {
crdGroup = fmt.Sprintf("example-%s.karmada.io", rand.String(RandomStrLength))
Expand All @@ -61,7 +70,8 @@ var _ = ginkgo.Describe("[BasicClusterPropagation] propagation testing", func()
Singular: fmt.Sprintf("foo%s", randStr),
}
crd = testhelper.NewCustomResourceDefinition(crdGroup, crdSpecNames, apiextensionsv1.NamespaceScoped)
crdPolicy = testhelper.NewClusterPropagationPolicy(crd.Name, []policyv1alpha1.ResourceSelector{
policyName = crd.Name
policy = testhelper.NewClusterPropagationPolicy(policyName, []policyv1alpha1.ResourceSelector{
{
APIVersion: crd.APIVersion,
Kind: crd.Kind,
Expand All @@ -75,10 +85,8 @@ var _ = ginkgo.Describe("[BasicClusterPropagation] propagation testing", func()
})

ginkgo.BeforeEach(func() {
framework.CreateClusterPropagationPolicy(karmadaClient, crdPolicy)
framework.CreateCRD(dynamicClient, crd)
ginkgo.DeferCleanup(func() {
framework.RemoveClusterPropagationPolicy(karmadaClient, crdPolicy.Name)
framework.RemoveCRD(dynamicClient, crd.Name)
framework.WaitCRDDisappearedOnClusters(framework.ClusterNames(), crd.Name)
})
Expand All @@ -94,8 +102,6 @@ var _ = ginkgo.Describe("[BasicClusterPropagation] propagation testing", func()
ginkgo.Context("ClusterRole propagation testing", func() {
var (
clusterRoleName string
policyName string
policy *policyv1alpha1.ClusterPropagationPolicy
clusterRole *rbacv1.ClusterRole
)

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

ginkgo.BeforeEach(func() {
framework.CreateClusterPropagationPolicy(karmadaClient, policy)
framework.CreateClusterRole(kubeClient, clusterRole)
ginkgo.DeferCleanup(func() {
framework.RemoveClusterPropagationPolicy(karmadaClient, policy.Name)
framework.RemoveClusterRole(kubeClient, clusterRole.Name)
framework.WaitClusterRoleDisappearOnClusters(framework.ClusterNames(), clusterRole.Name)
})
Expand All @@ -138,8 +142,6 @@ var _ = ginkgo.Describe("[BasicClusterPropagation] propagation testing", func()
ginkgo.Context("ClusterRoleBinding propagation testing", func() {
var (
clusterRoleBindingName string
policyName string
policy *policyv1alpha1.ClusterPropagationPolicy
clusterRoleBinding *rbacv1.ClusterRoleBinding
)

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

ginkgo.BeforeEach(func() {
framework.CreateClusterPropagationPolicy(karmadaClient, policy)
framework.CreateClusterRoleBinding(kubeClient, clusterRoleBinding)
ginkgo.DeferCleanup(func() {
framework.RemoveClusterPropagationPolicy(karmadaClient, policy.Name)
framework.RemoveClusterRoleBinding(kubeClient, clusterRoleBinding.Name)
framework.WaitClusterRoleBindingDisappearOnClusters(framework.ClusterNames(), clusterRoleBinding.Name)
})
Expand All @@ -180,13 +180,12 @@ var _ = ginkgo.Describe("[BasicClusterPropagation] propagation testing", func()
})

ginkgo.Context("Deployment propagation testing", func() {
var policy *policyv1alpha1.ClusterPropagationPolicy
var deployment *appsv1.Deployment
var targetMember string

ginkgo.BeforeEach(func() {
targetMember = framework.ClusterNames()[0]
policyName := cppNamePrefix + rand.String(RandomStrLength)
policyName = cppNamePrefix + rand.String(RandomStrLength)
deploymentName := deploymentNamePrefix + rand.String(RandomStrLength)

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

ginkgo.BeforeEach(func() {
framework.CreateClusterPropagationPolicy(karmadaClient, policy)
framework.CreateDeployment(kubeClient, deployment)
ginkgo.DeferCleanup(func() {
framework.RemoveClusterPropagationPolicy(karmadaClient, policy.Name)
framework.RemoveDeployment(kubeClient, deployment.Namespace, deployment.Name)
})
})
Expand All @@ -227,7 +224,62 @@ var _ = ginkgo.Describe("[BasicClusterPropagation] propagation testing", func()
})
})

var _ = ginkgo.Describe("[AdvancedClusterPropagation] propagation testing", func() {
var _ = ginkgo.Describe("[CornerCase] ClusterPropagationPolicy testing", func() {
var policyName string
var policy *policyv1alpha1.ClusterPropagationPolicy

ginkgo.JustBeforeEach(func() {
framework.CreateClusterPropagationPolicy(karmadaClient, policy)
ginkgo.DeferCleanup(func() {
framework.RemoveClusterPropagationPolicy(karmadaClient, policy.Name)
})
})

ginkgo.Context("Deployment propagation testing", func() {
var deployment *appsv1.Deployment
var targetMember string

ginkgo.BeforeEach(func() {
targetMember = framework.ClusterNames()[0]
policyName = cppNamePrefix + rand.String(RandomStrLength)
deploymentName := deploymentNamePrefix + rand.String(RandomStrLength)

deployment = testhelper.NewDeployment(testNamespace, deploymentName)
policy = testhelper.NewClusterPropagationPolicy(policyName, []policyv1alpha1.ResourceSelector{
{
APIVersion: deployment.APIVersion,
Kind: deployment.Kind,
Name: deployment.Name,
}}, policyv1alpha1.Placement{
ClusterAffinity: &policyv1alpha1.ClusterAffinity{
ClusterNames: []string{targetMember},
},
})
})

ginkgo.BeforeEach(func() {
framework.CreateDeployment(kubeClient, deployment)
ginkgo.DeferCleanup(func() {
framework.RemoveDeployment(kubeClient, deployment.Namespace, deployment.Name)
})
})

ginkgo.It("deployment propagation testing", func() {
framework.WaitDeploymentPresentOnClusterFitWith(targetMember, deployment.Namespace, deployment.Name,
func(d *appsv1.Deployment) bool {
return *d.Spec.Replicas == *deployment.Spec.Replicas
})

framework.UpdateDeploymentReplicas(kubeClient, deployment, updateDeploymentReplicas)
framework.WaitDeploymentPresentOnClusterFitWith(targetMember, deployment.Namespace, deployment.Name,
func(deployment *appsv1.Deployment) bool {
return *deployment.Spec.Replicas == updateDeploymentReplicas
})
})
})
})

var _ = ginkgo.Describe("[AdvancedCase] ClusterPropagationPolicy testing", func() {
ginkgo.Context("Edit ClusterPropagationPolicy ResourceSelectors", func() {
ginkgo.When("propagate namespace scope resource", func() {
var policy *policyv1alpha1.ClusterPropagationPolicy
Expand Down Expand Up @@ -552,7 +604,7 @@ var _ = ginkgo.Describe("[AdvancedClusterPropagation] propagation testing", func

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

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

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

0 comments on commit 911cc44

Please sign in to comment.