Skip to content

list namespaced crd objects using crd yaml without global crd reading permission #1777

Closed
@LeiYangGH

Description

@LeiYangGH

similiar to issue 740, which deals with creating. but now i'm listing.

What is the feature and why do you need it:

In certain circumstances, the servcie account doesn't have read permission to read global crd, but we already have crd yaml locally. and i want to list namespaced cr objects.

config.load_incluster_config()
crs = client.CustomObjectsApi().list_namespaced_custom_object(group="company.com", version="v1beta1",
                                                                   plural="some-configs", namespace='namespace')

won't work because it tries to read global crd via k8s api first(no permission).

Describe the solution you'd like to see:

config.load_incluster_config()
crs = client.CustomObjectsApi().list_namespaced_custom_object(group="com.company", version="v1beta1",
         plural="some-configs", namespace='namespace', crd_yaml=loadresource(some_local_file))

We have similiar issue with java client and we have some working code like this:

  public final CustomResourceDefinition extractCrdInfo(NamespacedKubernetesClient client,
      String localCrdFileName){
    InputStream is = getClass().getResourceAsStream(localCrdFileName);
    return loadCRD(client, is);
  }

  public final CustomResourceDefinitionContext buildCrdCtx(CustomResourceDefinition crd) {
    return new CustomResourceDefinitionContext.Builder()
        .withName(crd.getMetadata().getName())
        .withScope("Namespaced")
        .withVersion("v1beta1")
        .withPlural(crd.getSpec().getNames().getPlural())
        .withKind(crd.getSpec().getNames().getKind())
        .withGroup(crd.getSpec().getGroup())
        .build();
  }
    return client.customResources(resourceCrdCtx, SOMEJAVA.class, SOMEJAVA1.class,
        SOMEJAVA2.class);

Metadata

Metadata

Assignees

Labels

kind/featureCategorizes issue or PR as related to a new feature.lifecycle/staleDenotes an issue or PR has remained open with no activity and has become stale.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions