io.jenkins.x.client.kube.ClientHelper Maven / Gradle / Ivy
package io.jenkins.x.client.kube;
import io.fabric8.kubernetes.api.model.ObjectMeta;
import io.fabric8.kubernetes.api.model.apiextensions.CustomResourceDefinition;
import io.fabric8.kubernetes.api.model.apiextensions.CustomResourceDefinitionBuilder;
import io.fabric8.kubernetes.api.model.apiextensions.CustomResourceDefinitionList;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.dsl.NonNamespaceOperation;
import io.fabric8.kubernetes.client.dsl.Resource;
import java.util.List;
/**
*/
public class ClientHelper {
public static String JENKINS_CRD_GROUP = "jenkins.io";
public static String PIPELINE_ACTIVITIES_CRD_NAME = "pipelineactivities." + JENKINS_CRD_GROUP;
public static NonNamespaceOperation> pipelineActivityClient(KubernetesClient client, String namespace) {
CustomResourceDefinitionList crds = client.customResourceDefinitions().list();
List crdsItems = crds.getItems();
CustomResourceDefinition runCRD = null;
for (CustomResourceDefinition crd : crdsItems) {
ObjectMeta metadata = crd.getMetadata();
if (metadata != null) {
String name = metadata.getName();
if (PIPELINE_ACTIVITIES_CRD_NAME.equals(name)) {
runCRD = crd;
}
}
}
if (runCRD == null) {
runCRD = new CustomResourceDefinitionBuilder().
withApiVersion("apiextensions.k8s.io/v1beta1").
withNewMetadata().withName(PIPELINE_ACTIVITIES_CRD_NAME).endMetadata().
withNewSpec().withGroup(JENKINS_CRD_GROUP).withVersion("v1").withScope("Namespaced").
withNewNames().withKind("PipelineActivity").withShortNames("pipelineactivity", "activity", "act").withPlural("pipelineactivities").endNames().endSpec().
build();
client.customResourceDefinitions().create(runCRD);
}
return client.customResources(runCRD, PipelineActivity.class, PipelineActivityList.class, DoneablePipelineActivities.class).inNamespace(namespace);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy