Search in sources :

Example 16 with Job

use of io.fabric8.kubernetes.api.model.batch.Job in project fabric8-maven-plugin by fabric8io.

the class KubernetesResourceUtil method getPodLabelSelector.

public static LabelSelector getPodLabelSelector(HasMetadata entity) {
    LabelSelector selector = null;
    if (entity instanceof Deployment) {
        Deployment resource = (Deployment) entity;
        DeploymentSpec spec = resource.getSpec();
        if (spec != null) {
            selector = spec.getSelector();
        }
    } else if (entity instanceof ReplicaSet) {
        ReplicaSet resource = (ReplicaSet) entity;
        ReplicaSetSpec spec = resource.getSpec();
        if (spec != null) {
            selector = spec.getSelector();
        }
    } else if (entity instanceof DeploymentConfig) {
        DeploymentConfig resource = (DeploymentConfig) entity;
        DeploymentConfigSpec spec = resource.getSpec();
        if (spec != null) {
            selector = toLabelSelector(spec.getSelector());
        }
    } else if (entity instanceof ReplicationController) {
        ReplicationController resource = (ReplicationController) entity;
        ReplicationControllerSpec spec = resource.getSpec();
        if (spec != null) {
            selector = toLabelSelector(spec.getSelector());
        }
    } else if (entity instanceof DaemonSet) {
        DaemonSet resource = (DaemonSet) entity;
        DaemonSetSpec spec = resource.getSpec();
        if (spec != null) {
            selector = spec.getSelector();
        }
    } else if (entity instanceof StatefulSet) {
        StatefulSet resource = (StatefulSet) entity;
        StatefulSetSpec spec = resource.getSpec();
        if (spec != null) {
            selector = spec.getSelector();
        }
    } else if (entity instanceof Job) {
        Job resource = (Job) entity;
        JobSpec spec = resource.getSpec();
        if (spec != null) {
            selector = spec.getSelector();
        }
    }
    return selector;
}
Also used : StatefulSetSpec(io.fabric8.kubernetes.api.model.extensions.StatefulSetSpec) ReplicaSetSpec(io.fabric8.kubernetes.api.model.extensions.ReplicaSetSpec) LabelSelector(io.fabric8.kubernetes.api.model.LabelSelector) Deployment(io.fabric8.kubernetes.api.model.extensions.Deployment) DaemonSetSpec(io.fabric8.kubernetes.api.model.extensions.DaemonSetSpec) DeploymentSpec(io.fabric8.kubernetes.api.model.extensions.DeploymentSpec) ReplicationController(io.fabric8.kubernetes.api.model.ReplicationController) DaemonSet(io.fabric8.kubernetes.api.model.extensions.DaemonSet) JobSpec(io.fabric8.kubernetes.api.model.JobSpec) DeploymentConfig(io.fabric8.openshift.api.model.DeploymentConfig) DeploymentConfigSpec(io.fabric8.openshift.api.model.DeploymentConfigSpec) StatefulSet(io.fabric8.kubernetes.api.model.extensions.StatefulSet) Job(io.fabric8.kubernetes.api.model.Job) ReplicaSet(io.fabric8.kubernetes.api.model.extensions.ReplicaSet) ReplicationControllerSpec(io.fabric8.kubernetes.api.model.ReplicationControllerSpec)

Example 17 with Job

use of io.fabric8.kubernetes.api.model.batch.Job in project fabric8-maven-plugin by fabric8io.

the class JobHandlerTest method jobHandlerTest.

@Test
public void jobHandlerTest() {
    ContainerHandler containerHandler = new ContainerHandler(project, envVarHandler, probeHandler);
    PodTemplateHandler podTemplateHandler = new PodTemplateHandler(containerHandler);
    JobHandler jobHandler = new JobHandler(podTemplateHandler);
    ResourceConfig config = new ResourceConfig.Builder().imagePullPolicy("IfNotPresent").controllerName("testing").withServiceAccount("test-account").volumes(volumes1).build();
    Job job = jobHandler.getJob(config, images);
    // Assertion
    assertNotNull(job.getSpec());
    assertNotNull(job.getMetadata());
    assertNotNull(job.getSpec().getTemplate());
    assertEquals("testing", job.getMetadata().getName());
    assertEquals("test-account", job.getSpec().getTemplate().getSpec().getServiceAccountName());
    assertFalse(job.getSpec().getTemplate().getSpec().getVolumes().isEmpty());
    assertEquals("test", job.getSpec().getTemplate().getSpec().getVolumes().get(0).getName());
    assertEquals("/test/path", job.getSpec().getTemplate().getSpec().getVolumes().get(0).getHostPath().getPath());
    assertNotNull(job.getSpec().getTemplate().getSpec().getContainers());
}
Also used : ResourceConfig(io.fabric8.maven.core.config.ResourceConfig) Job(io.fabric8.kubernetes.api.model.Job) Test(org.junit.Test)

Example 18 with Job

use of io.fabric8.kubernetes.api.model.batch.Job in project fabric8-maven-plugin by fabric8io.

the class KubernetesResourceUtilTest method job.

@Test
public void job() throws Exception {
    HasMetadata ret = getResource(DEFAULT_RESOURCE_VERSIONING, new File(fabric8Dir, "job.yml"), "app");
    assertEquals("Job", ret.getKind());
    assertEquals(JOB_VERSION, ret.getApiVersion());
}
Also used : HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) File(java.io.File) Test(org.junit.Test)

Example 19 with Job

use of io.fabric8.kubernetes.api.model.batch.Job in project flink by apache.

the class InternalServiceDecorator method buildAccompanyingKubernetesResources.

@Override
public List<HasMetadata> buildAccompanyingKubernetesResources() throws IOException {
    if (!kubernetesJobManagerParameters.isInternalServiceEnabled()) {
        return Collections.emptyList();
    }
    final String serviceName = getInternalServiceName(kubernetesJobManagerParameters.getClusterId());
    final Service headlessService = HeadlessClusterIPService.INSTANCE.buildUpInternalService(kubernetesJobManagerParameters);
    // Set job manager address to namespaced service name
    final String namespace = kubernetesJobManagerParameters.getNamespace();
    kubernetesJobManagerParameters.getFlinkConfiguration().setString(JobManagerOptions.ADDRESS, getNamespacedInternalServiceName(serviceName, namespace));
    return Collections.singletonList(headlessService);
}
Also used : HeadlessClusterIPService(org.apache.flink.kubernetes.kubeclient.services.HeadlessClusterIPService) Service(io.fabric8.kubernetes.api.model.Service)

Example 20 with Job

use of io.fabric8.kubernetes.api.model.batch.Job in project fabric8 by fabric8io.

the class ViewPipeline method main.

public static void main(String[] args) {
    if (args.length == 0) {
        System.err.println("Usage: ViewPipeline jobName [branchName] [gitUrl]");
        return;
    }
    String jobName = args[0];
    String branchName = "master";
    String gitUrl = null;
    if (args.length > 1) {
        branchName = args[1];
    }
    if (args.length > 2) {
        gitUrl = args[2];
    }
    try {
        JobEnvironment environment = new JobEnvironment();
        environment.setJobName(jobName);
        environment.setBranchName(branchName);
        environment.setGitUrl(gitUrl);
        KubernetesClient kubernetesClient = new DefaultKubernetesClient();
        String namespace = kubernetesClient.getNamespace();
        if (Strings.isNullOrBlank(namespace)) {
            namespace = KubernetesHelper.defaultNamespace();
        }
        Pipeline pipeline = Pipelines.getPipeline(kubernetesClient, namespace, environment);
        System.out.println("Found pipeline for job: " + pipeline.getJobName() + " of kind: " + pipeline.getKind());
    } catch (IntrospectionException e) {
        System.out.println("Failed with: " + e);
        e.printStackTrace();
    }
}
Also used : KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) IntrospectionException(java.beans.IntrospectionException) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient)

Aggregations

IOException (java.io.IOException)8 DefaultKubernetesClient (io.fabric8.kubernetes.client.DefaultKubernetesClient)6 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)6 Block (io.fabric8.utils.Block)6 URISyntaxException (java.net.URISyntaxException)6 Container (io.fabric8.kubernetes.api.model.Container)5 Job (io.fabric8.kubernetes.api.model.batch.Job)4 File (java.io.File)4 HashMap (java.util.HashMap)4 List (java.util.List)4 Test (org.junit.Test)4 Test (org.testng.annotations.Test)4 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)3 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)3 Job (io.fabric8.kubernetes.api.model.Job)3 InspectImageResponse (com.github.dockerjava.api.command.InspectImageResponse)2 JobWithDetails (com.offbytwo.jenkins.model.JobWithDetails)2 Controller (io.fabric8.kubernetes.api.Controller)2 LocalObjectReference (io.fabric8.kubernetes.api.model.LocalObjectReference)2 ObjectMeta (io.fabric8.kubernetes.api.model.ObjectMeta)2