fabric8 中的 certmanager 实现

certmanager implementation in the fabric8

看了一篇文章https://developers.redhat.com/articles/2021/07/16/whats-new-fabric8-kubernetes-client-version-550#new_features_in_fabric8_kubernetes_client_5_5_0,里面提到在5.5版本中增加了“证书管理”,但是,我在fabric8 repo中似乎找不到任何相关的源代码。

当我运行像这样的简单代码时


        try (CertManagerClient certManagerClient = new DefaultCertManagerClient()) {

 
            CertificateRequest certificateRequest = new CertificateRequestBuilder()
                .withNewMetadata().withName("barry_coding_test").endMetadata()
                .withNewSpec()
                .withRequest(request)
                .withIsCA(false)
                .addToUsages("signing", "digital signature", "server auth")
                .withDuration(Duration.parse("2160h"))
                .withIssuerRef(new ObjectReferenceBuilder()
                    .withName("barry-dlc-cert-issuer")
                    .withKind("Issuer")
                    .withGroup("cert-manager.io")
                    .build())
                .endSpec()
                .build();

            certManagerClient.v1().certificateRequests().inNamespace("barry").create(certificateRequest);


        } catch (Exception e) {
            e.printStackTrace();
        }

它抛出错误

Exception in thread "main" java.lang.NoSuchMethodError: io/fabric8/kubernetes/client/dsl/base/HasMetadataOperation.<init>(Lio/fabric8/kubernetes/client/dsl/base/OperationContext;)V (loaded from file:/Users/zhBarry@ca.ibm.com/osprey/mvnexample/java-app/dlc-management-service/libs/kubernetes-client-5.8.0.jar by jdk.internal.loader.ClassLoaders$AppClassLoader@40575da4) called from class io.fabric8.certmanager.client.api.v1.internal.CertificateRequestOperationsImpl (loaded from file:/Users/zhBarry@ca.ibm.com/osprey/mvnexample/java-app/dlc-management-service/libs/certmanager-client-5.5.0.jar by jdk.internal.loader.ClassLoaders$AppClassLoader@40575da4).
    at io.fabric8.certmanager.client.api.v1.internal.CertificateRequestOperationsImpl.<init>(CertificateRequestOperationsImpl.java:32)
    at io.fabric8.certmanager.client.api.v1.internal.CertificateRequestOperationsImpl.<init>(CertificateRequestOperationsImpl.java:28)
    at io.fabric8.certmanager.client.V1APIGroupClient.certificateRequests(V1APIGroupClient.java:51)
    at com.ibm.si.osprey.App.main(App.java:67)

我在 repo 中根本找不到源代码 CertificateRequestOperationsImpl.java。

有什么想法吗?我在哪里可以在 fabric8 存储库中实现 certmanager?

您不会在 kubernetes-client jar 本身中找到与 CertManager 相关的功能。所有 Fabric8 Kubernetes 客户端扩展都可以通过它们自己的独立 jar 获得。对于 CertManager,您需要添加此依赖项:

专家:

<dependency>
  <groupId>io.fabric8</groupId>
  <artifactId>certmanager-client</artifactId>
  <version>5.9.0</version>
</dependency>

Gradle:

implementation 'io.fabric8:certmanager-client:5.9.0'

https://github.com/fabric8io/kubernetes-client/tree/master/extensions/certmanager/examples/src/main/java/io/fabric8/certmanager/examples/v1 中有一个示例。也许这部分需要改进;如果您有时间,欢迎您提供更多示例 :-) .

我已经在一个演示项目上测试了您的示例,该项目具有 certmanager-client 依赖关系,并且在 minikube 上安装了 certmanager。你可以在这里找到演示项目:https://github.com/rohankanojia-forks/cert-manager-java-extension-demo