@@ -21,12 +21,14 @@ import (
21
21
"encoding/json"
22
22
"fmt"
23
23
"strconv"
24
+ "strings"
24
25
"time"
25
26
26
27
appsv1 "k8s.io/api/apps/v1"
27
28
v1 "k8s.io/api/core/v1"
28
29
resourceapi "k8s.io/api/resource/v1"
29
30
schedulingv1 "k8s.io/api/scheduling/v1"
31
+ apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
30
32
apiequality "k8s.io/apimachinery/pkg/api/equality"
31
33
apierrors "k8s.io/apimachinery/pkg/api/errors"
32
34
"k8s.io/apimachinery/pkg/api/resource"
@@ -658,7 +660,7 @@ var _ = SIGDescribe("ResourceQuota", func() {
658
660
659
661
ginkgo .It ("should create a ResourceQuota and capture the life of a custom resource." , func (ctx context.Context ) {
660
662
ginkgo .By ("Creating a Custom Resource Definition" )
661
- testcrd , err := crd .CreateTestCRD (f )
663
+ testcrd , err := crd .CreateTestCRD (f , ensureShortCRDNamesForResourceQuota () )
662
664
framework .ExpectNoError (err )
663
665
ginkgo .DeferCleanup (testcrd .CleanUp )
664
666
countResourceName := "count/" + testcrd .Crd .Spec .Names .Plural + "." + testcrd .Crd .Spec .Group
@@ -2144,6 +2146,35 @@ func newTestResourceQuotaWithScopeForVolumeAttributesClass(name string, hard v1.
2144
2146
}
2145
2147
}
2146
2148
2149
+ // ensureShortCRDNamesForResourceQuota returns a CRD Option that truncates the plural name
2150
+ // if needed to ensure "count/{plural}.{group}" fits within 63 characters (Kubernetes resource name limit).
2151
+ func ensureShortCRDNamesForResourceQuota () crd.Option {
2152
+ return func (c * apiextensionsv1.CustomResourceDefinition ) {
2153
+ const maxResourceNameLength = 63
2154
+ countResourcePrefix := "count/"
2155
+
2156
+ // Calculate what the resource name would be
2157
+ fullResourceName := countResourcePrefix + c .Spec .Names .Plural + "." + c .Spec .Group
2158
+
2159
+ if len (fullResourceName ) > maxResourceNameLength {
2160
+ // Calculate max length for the plural name
2161
+ maxPluralLen := maxResourceNameLength - len (countResourcePrefix ) - len ("." ) - len (c .Spec .Group )
2162
+
2163
+ if maxPluralLen > 0 && len (c .Spec .Names .Plural ) > maxPluralLen {
2164
+ // Truncate the plural name
2165
+ originalPlural := c .Spec .Names .Plural
2166
+ truncatedPlural := strings .TrimRight (originalPlural [:maxPluralLen ], "-." )
2167
+
2168
+ // Update the CRD spec
2169
+ c .Spec .Names .Plural = truncatedPlural
2170
+ c .ObjectMeta .Name = truncatedPlural + "." + c .Spec .Group
2171
+
2172
+ framework .Logf ("Truncated CRD plural name from %q to %q to fit ResourceQuota naming constraints" , originalPlural , truncatedPlural )
2173
+ }
2174
+ }
2175
+ }
2176
+ }
2177
+
2147
2178
// newTestResourceQuota returns a quota that enforces default constraints for testing
2148
2179
func newTestResourceQuota (name string ) * v1.ResourceQuota {
2149
2180
hard := v1.ResourceList {}
0 commit comments