kubernetes-client的使用--java中提交argo工作流(7)
- UID
- 1066743
|
kubernetes-client的使用--java中提交argo工作流(7)
ArgoList.java
package com.biologic.entity;
import io.fabric8.kubernetes.client.CustomResourceList;
public class ArgoList extends CustomResourceList<ArgoCluster>{
}
DoneableArgo.java
package com.biologic.entity;
import io.fabric8.kubernetes.api.builder.Function;
import io.fabric8.kubernetes.client.CustomResourceDoneable;
public class DoneableArgo extends CustomResourceDoneable<ArgoCluster>{
public DoneableArgo(ArgoCluster resource, Function<ArgoCluster, ArgoCluster> function) {
super(resource, function);
}
}
调用crd的关键代码
Config config = new ConfigBuilder().withMasterUrl(masterurl).build();
KubernetesClient client = new DefaultKubernetesClient(config);
CustomResourceDefinition argoCRD = null;
try {
if (!client.supportsApiPath("/apis/apiextensions.k8s.io/v1beta1") && !client.supportsApiPath("/apis/apiextensions.k8s.io/v1")) {
System.out.println("WARNING this cluster does not support the API Group apiextensions.k8s.io");
return "fail";
}
CustomResourceDefinitionList list = client.customResourceDefinitions().list();
if (list == null) {
System.out.println("ERROR no list returned!");
return "fail";
}
List<CustomResourceDefinition> items = list.getItems();
for (CustomResourceDefinition item : items) {
System.out.println("CustomResourceDefinition " + item.getMetadata().getName() + " has version: " + item.getApiVersion());
if (ARGO_CRD_NAME.equals(item.getMetadata().getName())) {
argoCRD = item;
}
}
} catch (KubernetesClientException e) {
System.out.println("Failed: " + e);
e.printStackTrace();
}
if (argoCRD != null) {
System.out.println("Found CRD: " + argoCRD.getMetadata().getSelfLink());
} else {
return "fail";
}
MixedOperation<ArgoCluster, ArgoList, DoneableArgo, Resource<ArgoCluster, DoneableArgo>> argoClient = client.customResources(argoCRD, ArgoCluster.class, ArgoList.class, DoneableArgo.class);
CustomResourceList<ArgoCluster> argoList =argoClient.list();
List<ArgoCluster> items = argoList.getItems();
System.out.println(" found " + items.size() + " argo");
for (ArgoCluster item : items) {
System.out.println(" " + item);
}
ArgoCluster createArgo= argoClient.load(stream).get();
ArgoCluster finishpod=argoClient.create(createArgo);
String podname=finishpod.getMetadata().getName();
Pod pod = client.pods().inNamespace(namespace).withName(podname).get();
if (pod !=null){
System.out.println("Creating pod in namespace " + pod.getMetadata().getNamespace());
System.out.println("Created pod " + podname);
} else {
System.err.println("not found a Pod! " + podname);
} |
|
|
|
|
|