Skip to content

Unable create Custom Resource Definition with ApiextensionsV1Api.createCustomResourceDefinition() #4311

@ardhendusaha

Description

@ardhendusaha

Describe the bug
Hello,

I'm trying to create a custom resource following this official example:
https://github.com/kubernetes-client/java/blob/v24.0.0/kubernetes/docs/ApiextensionsV1Api.md#createCustomResourceDefinition

        V1CustomResourceDefinition result = apiInstance.createCustomResourceDefinition(body)
                .dryRun(dryRun)
                .execute();

No matter what I specify in the body , the result is always an HTTP 422 error response from the server:

   {"kind":"Status","apiVersion":"v1","metadata":{},"status":"Failure","message":"CustomResourceDefinition.apiextensions.k8s.io \"widgets.example.com\" is invalid: spec.validation.openAPIV3Schema.dependencies: Forbidden: dependencies is not supported","reason":"Invalid","details":{"name":"widgets.example.com","group":"apiextensions.k8s.io","kind":"CustomResourceDefinition","causes":[{"reason":"FieldValueForbidden","message":"Forbidden: dependencies is not supported","field":"spec.validation.openAPIV3Schema.dependencies"}]},"code":422}

Client Version
24.0.0

Kubernetes Version
v1.28.0

Java Version
Java 17

To Reproduce
Steps to reproduce the behavior:

Copy below java code and execute from local system.

       String kubeConfigPath = "C:\\Users\\Administrator\\WORK\\Projects\\java-client\\kube\\config";
        ApiClient client = Config.fromConfig(kubeConfigPath);
        Configuration.setDefaultApiClient(client);
        ApiextensionsV1Api apiInstance = new ApiextensionsV1Api(client);
        V1CustomResourceDefinition body = new V1CustomResourceDefinition();
        body.setApiVersion("apiextensions.k8s.io/v1");
        body.setKind("CustomResourceDefinition");
        body.setMetadata(new V1ObjectMeta().name("widgets.example.com"));
        List<V1CustomResourceDefinitionVersion> versions = new ArrayList<>();
        V1CustomResourceValidation schema = new V1CustomResourceValidation().openAPIV3Schema(new V1JSONSchemaProps().type("object").dependencies(new HashMap<>()));
        V1CustomResourceDefinitionVersion v1 = new V1CustomResourceDefinitionVersion().name("v1").served(true).storage(true).served(true).schema(schema);
        versions.add(v1);
        body.setSpec(new V1CustomResourceDefinitionSpec().group("example.com").names(new V1CustomResourceDefinitionNames().kind("Widget").plural("widgets")).scope("Namespaced")
                .versions(versions));
        body.setStatus(new V1CustomResourceDefinitionStatus().acceptedNames(new V1CustomResourceDefinitionNames().kind("Widget")));

        String dryRun = "All";
        V1CustomResourceDefinition result = apiInstance.createCustomResourceDefinition(body)
                .dryRun(dryRun)
                .execute();

Results in:

  	SLF4J(W): No SLF4J providers were found.
SLF4J(W): Defaulting to no-operation (NOP) logger implementation
SLF4J(W): See https://www.slf4j.org/codes.html#noProviders for further details.
Oct 06, 2025 8:25:57 PM okhttp3.internal.platform.Platform log
INFO: --> POST https://10.235.11.65:6443/apis/apiextensions.k8s.io/v1/customresourcedefinitions?dryRun=All
Oct 06, 2025 8:25:57 PM okhttp3.internal.platform.Platform log
INFO: Content-Length: 772
Oct 06, 2025 8:25:57 PM okhttp3.internal.platform.Platform log
INFO: Accept: application/json
Oct 06, 2025 8:25:57 PM okhttp3.internal.platform.Platform log
INFO: Content-Type: application/json
Oct 06, 2025 8:25:57 PM okhttp3.internal.platform.Platform log
INFO: User-Agent: Kubernetes Java Client/24.0.0-SNAPSHOT
Oct 06, 2025 8:25:57 PM okhttp3.internal.platform.Platform log
INFO: 
Oct 06, 2025 8:25:57 PM okhttp3.internal.platform.Platform log
INFO: {"apiVersion":"apiextensions.k8s.io/v1","kind":"CustomResourceDefinition","metadata":{"annotations":{},"finalizers":[],"labels":{},"name":"widgets.example.com","ownerReferences":[]},"spec":{"group":"example.com","names":{"categories":[],"kind":"Widget","plural":"widgets","shortNames":[]},"scope":"Namespaced","versions":[{"additionalPrinterColumns":[],"name":"v1","schema":{"openAPIV3Schema":{"allOf":[],"anyOf":[],"definitions":{},"dependencies":{},"enum":[],"oneOf":[],"patternProperties":{},"properties":{},"required":[],"type":"object","x-kubernetes-list-map-keys":[],"x-kubernetes-validations":[]}},"selectableFields":[],"served":true,"storage":true}]},"status":{"acceptedNames":{"categories":[],"kind":"Widget","shortNames":[]},"conditions":[],"storedVersions":[]}}
Oct 06, 2025 8:25:57 PM okhttp3.internal.platform.Platform log
INFO: --> END POST (772-byte body)
Oct 06, 2025 8:25:58 PM okhttp3.internal.platform.Platform log
INFO: <-- 422 https://10.235.11.65:6443/apis/apiextensions.k8s.io/v1/customresourcedefinitions?dryRun=All (619ms)
Oct 06, 2025 8:25:58 PM okhttp3.internal.platform.Platform log
INFO: audit-id: 0801aeff-97de-422d-a6d6-9c8b2b6890af
Oct 06, 2025 8:25:58 PM okhttp3.internal.platform.Platform log
INFO: cache-control: no-cache, private
Oct 06, 2025 8:25:58 PM okhttp3.internal.platform.Platform log
INFO: content-type: application/json
Oct 06, 2025 8:25:58 PM okhttp3.internal.platform.Platform log
INFO: warning: 299 - "unknown field \"spec.versions[0].selectableFields\""
Oct 06, 2025 8:25:58 PM okhttp3.internal.platform.Platform log
INFO: x-kubernetes-pf-flowschema-uid: 7cd60bae-d919-4fdd-886f-ced99e44cb01
Oct 06, 2025 8:25:58 PM okhttp3.internal.platform.Platform log
INFO: x-kubernetes-pf-prioritylevel-uid: e3c32b39-315a-44b3-a223-702ebb709445
Oct 06, 2025 8:25:58 PM okhttp3.internal.platform.Platform log
INFO: content-length: 538
Oct 06, 2025 8:25:58 PM okhttp3.internal.platform.Platform log
INFO: date: Mon, 06 Oct 2025 14:06:23 GMT
Oct 06, 2025 8:25:58 PM okhttp3.internal.platform.Platform log
INFO: 
Oct 06, 2025 8:25:58 PM okhttp3.internal.platform.Platform log
INFO: {"kind":"Status","apiVersion":"v1","metadata":{},"status":"Failure","message":"CustomResourceDefinition.apiextensions.k8s.io \"widgets.example.com\" is invalid: spec.validation.openAPIV3Schema.dependencies: Forbidden: dependencies is not supported","reason":"Invalid","details":{"name":"widgets.example.com","group":"apiextensions.k8s.io","kind":"CustomResourceDefinition","causes":[{"reason":"FieldValueForbidden","message":"Forbidden: dependencies is not supported","field":"spec.validation.openAPIV3Schema.dependencies"}]},"code":422}

Oct 06, 2025 8:25:58 PM okhttp3.internal.platform.Platform log
INFO: <-- END HTTP (538-byte body)
Exception when calling ApiextensionsV1Api#createCustomResourceDefinition
Status code: 422
Reason: {"kind":"Status","apiVersion":"v1","metadata":{},"status":"Failure","message":"CustomResourceDefinition.apiextensions.k8s.io \"widgets.example.com\" is invalid: spec.validation.openAPIV3Schema.dependencies: Forbidden: dependencies is not supported","reason":"Invalid","details":{"name":"widgets.example.com","group":"apiextensions.k8s.io","kind":"CustomResourceDefinition","causes":[{"reason":"FieldValueForbidden","message":"Forbidden: dependencies is not supported","field":"spec.validation.openAPIV3Schema.dependencies"}]},"code":422}

Response headers: {audit-id=[0801aeff-97de-422d-a6d6-9c8b2b6890af], cache-control=[no-cache, private], content-length=[538], content-type=[application/json], date=[Mon, 06 Oct 2025 14:06:23 GMT], warning=[299 - "unknown field \"spec.versions[0].selectableFields\""], x-kubernetes-pf-flowschema-uid=[7cd60bae-d919-4fdd-886f-ced99e44cb01], x-kubernetes-pf-prioritylevel-uid=[e3c32b39-315a-44b3-a223-702ebb709445]}
io.kubernetes.client.openapi.ApiException: Message: 
HTTP response code: 422
HTTP response body: {"kind":"Status","apiVersion":"v1","metadata":{},"status":"Failure","message":"CustomResourceDefinition.apiextensions.k8s.io \"widgets.example.com\" is invalid: spec.validation.openAPIV3Schema.dependencies: Forbidden: dependencies is not supported","reason":"Invalid","details":{"name":"widgets.example.com","group":"apiextensions.k8s.io","kind":"CustomResourceDefinition","causes":[{"reason":"FieldValueForbidden","message":"Forbidden: dependencies is not supported","field":"spec.validation.openAPIV3Schema.dependencies"}]},"code":422}

HTTP response headers: {audit-id=[0801aeff-97de-422d-a6d6-9c8b2b6890af], cache-control=[no-cache, private], content-length=[538], content-type=[application/json], date=[Mon, 06 Oct 2025 14:06:23 GMT], warning=[299 - "unknown field \"spec.versions[0].selectableFields\""], x-kubernetes-pf-flowschema-uid=[7cd60bae-d919-4fdd-886f-ced99e44cb01], x-kubernetes-pf-prioritylevel-uid=[e3c32b39-315a-44b3-a223-702ebb709445]}
	at io.kubernetes.client.openapi.ApiClient.handleResponse(ApiClient.java:1154)
	at io.kubernetes.client.openapi.ApiClient.execute(ApiClient.java:1067)
	at io.kubernetes.client.openapi.apis.ApiextensionsV1Api.createCustomResourceDefinitionWithHttpInfo(ApiextensionsV1Api.java:158)
	at io.kubernetes.client.openapi.apis.ApiextensionsV1Api$APIcreateCustomResourceDefinitionRequest.execute(ApiextensionsV1Api.java:259)
	at com.example.crd.CrdTest.main(CrdTest.java:43)

Expected behavior
The expectation is that the above code would create the CRD.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions