使用 java 客户端从 Kubernetes 命名空间中删除 contour httpproxy

Deleting contour httpproxy from Kubernetes namespace using java client

我正在使用 kubernetes java 客户端开发 K8s 实现。我正在寻找删除处于无效状态的 Contour HTTPProxy 的解决方案。但是,在 Java 客户端的帮助下,我无法弄清楚如何做到这一点。

我知道我们可以使用下面的代码删除入口

k8sClient.extensions().ingresses().withName("my-ingress").delete();

任何有关如何使用 java 客户端从 K8s 命名空间中删除 Contour HTTPProxy 对象的帮助将不胜感激?

Contour HTTPProxy 似乎是一个custom resource. You can either use our typed(required CustomResource POJOs) or typeless API(CustomResource manipulation using raw maps) 用于删除 HTTPProxy。

下面是一个使用无类型 API(基于 KubernetesClient v5.4.1)的例子:

try (KubernetesClient client = new DefaultKubernetesClient()) {
    CustomResourceDefinitionContext context = new CustomResourceDefinitionContext.Builder()
            .withKind("HTTPProxy")
            .withPlural("httpproxies")
            .withGroup("projectcontour.io")
            .withVersion("v1")
            .withScope("Namespaced")
            .build();

    boolean isDeleted = client.customResource(context).inNamespace("default").withName("root").delete();
    if (!isDeleted) {
        logger.warn("Unable to Delete HTTPProxy {} in {} namespace", "root", "default");
    }
    logger.info("HTTPProxy {} successfully deleted.", "root");
} catch (KubernetesClientException exception) {
    logger.error("Exception in interacting with Kubernetes API", exception);
}