diff --git a/webhook/webhook.go b/webhook/webhook.go index 9acaac44b2..ea23c7487f 100644 --- a/webhook/webhook.go +++ b/webhook/webhook.go @@ -558,26 +558,9 @@ func (ac *AdmissionController) mutate(ctx context.Context, kind metav1.GroupVers } } - if err := validateMetadata(newObj); err != nil { - logger.Error("Failed to validate", zap.Error(err)) - return nil, fmt.Errorf("Failed to validate: %s", err) - } return json.Marshal(patches) } -func validateMetadata(new GenericCRD) error { - name := new.GetObjectMeta().GetName() - - if strings.Contains(name, ".") { - return errors.New("Invalid resource name: special character . must not be present") - } - - if len(name) > 63 { - return errors.New("Invalid resource name: length must be no more than 63 characters") - } - return nil -} - // updateGeneration sets the generation by following this logic: // if there's no old object, it's create, set generation to 1 // if there's an old object and spec has changed, set generation to oldGeneration + 1 diff --git a/webhook/webhook_test.go b/webhook/webhook_test.go index ed0ae8824e..8dbc1cda89 100644 --- a/webhook/webhook_test.go +++ b/webhook/webhook_test.go @@ -135,35 +135,6 @@ func TestUnknownKindFails(t *testing.T) { expectFailsWith(t, ac.admit(TestContextWithLogger(t), &req), "unhandled kind") } -func TestInvalidNameFails(t *testing.T) { - _, ac := newNonRunningTestAdmissionController(t, newDefaultOptions()) - req := &admissionv1beta1.AdmissionRequest{ - Operation: admissionv1beta1.Create, - Kind: metav1.GroupVersionKind{ - Group: "pkg.knative.dev", - Version: "v1alpha1", - Kind: "Resource", - }, - } - invalidName := "an.example" - config := createResource(0, invalidName) - marshaled, err := json.Marshal(config) - if err != nil { - t.Fatalf("Failed to marshal resource: %s", err) - } - req.Object.Raw = marshaled - expectFailsWith(t, ac.admit(TestContextWithLogger(t), req), "Invalid resource name") - - invalidName = strings.Repeat("a", 64) - config = createResource(0, invalidName) - marshaled, err = json.Marshal(config) - if err != nil { - t.Fatalf("Failed to marshal resource: %s", err) - } - req.Object.Raw = marshaled - expectFailsWith(t, ac.admit(TestContextWithLogger(t), req), "Invalid resource name") -} - func TestValidCreateResourceSucceeds(t *testing.T) { r := createResource(1234, "a name") r.SetDefaults() // Fill in defaults to check that there are no patches.