📜  fabric8 kubernetes 补丁终结器 - 任何代码示例

📅  最后修改于: 2022-03-11 14:55:37.903000             🧑  作者: Mango

代码示例2
try (KubernetesClient client = new DefaultKubernetesClient()) {
    CustomResourceDefinitionContext crdContext = new CustomResourceDefinitionContext.Builder()
            .withGroup("demo.fabric8.io")
            .withPlural("dummies")
            .withScope("Namespaced")
            .withVersion("v1")
            .withName("dummies.demo.fabric8.io")
            .build();
    // Fetch resource fom Kubernetes API server
    Map dummy2  = client.customResource(crdContext).get("default", "second-dummy");
    JSONObject dummy2JsonObj = new JSONObject(dummy2);
    // Get metadata
    JSONObject dummy2ObjectMeta = dummy2JsonObj.getJSONObject("metadata");
    // Modify metadata
    dummy2ObjectMeta.put("finalizers", new String[] { "finalizer.stable.example.com"});
    // Patch it back in Custom Resource
    dummy2JsonObj.put("metadata", dummy2ObjectMeta);

    // Patch to Kubernetes
    client.customResource(crdContext).edit("default", "second-dummy", dummy2JsonObj.toString());
}