Search in sources :

Example 21 with CronJob

use of io.fabric8.kubernetes.api.model.batch.v1.CronJob in project kubernetes-client by fabric8io.

the class V1CronJobTest method testCreateWithNameMismatch.

@Test
void testCreateWithNameMismatch() {
    CronJob cronjob1 = new CronJobBuilder().withNewMetadata().withName("cronjob1").withNamespace("test").and().build();
    Resource<CronJob> cronJobOp = client.batch().v1().cronjobs().inNamespace("test1").withName("mycronjob1");
    Assertions.assertThrows(KubernetesClientException.class, () -> cronJobOp.create(cronjob1));
}
Also used : CronJob(io.fabric8.kubernetes.api.model.batch.v1.CronJob) CronJobBuilder(io.fabric8.kubernetes.api.model.batch.v1.CronJobBuilder) Test(org.junit.jupiter.api.Test)

Example 22 with CronJob

use of io.fabric8.kubernetes.api.model.batch.v1.CronJob in project che-server by eclipse-che.

the class ContainerSearchTest method setup.

@BeforeMethod
public void setup() {
    // These are all the object types that can be contained in a KubernetesList which can contain a
    // container:
    // Pod, PodTemplate, DaemonSet, Deployment, Job, ReplicaSet, ReplicationController, StatefulSet,
    // CronJob, DeploymentConfig, Template
    Container container1 = new ContainerBuilder().withName("container1").build();
    Container container2 = new ContainerBuilder().withName("container2").build();
    Container container3 = new ContainerBuilder().withName("container3").build();
    Container container4 = new ContainerBuilder().withName("container4").build();
    Container container5 = new ContainerBuilder().withName("container5").build();
    Container container6 = new ContainerBuilder().withName("container6").build();
    Container container7 = new ContainerBuilder().withName("container7").build();
    Container container8 = new ContainerBuilder().withName("container8").build();
    Container container9 = new ContainerBuilder().withName("container9").build();
    Container container10 = new ContainerBuilder().withName("container10").build();
    Container container11 = new ContainerBuilder().withName("container11").build();
    Container container12 = new ContainerBuilder().withName("container12").build();
    Pod podWithName = new PodBuilder().withNewMetadata().withName("podWithName").addToLabels("app", "che").endMetadata().withNewSpec().withContainers(container1).endSpec().build();
    Pod podWithGenerateName = new PodBuilder().withNewMetadata().withGenerateName("podWithGenerateName").endMetadata().withNewSpec().withContainers(container2).endSpec().build();
    PodTemplate podTemplate = new PodTemplateBuilder().withNewMetadata().withName("podTemplate").addToLabels("app", "che").endMetadata().withNewTemplate().withNewSpec().withContainers(container3).endSpec().endTemplate().build();
    DaemonSet daemonSet = new DaemonSetBuilder().withNewMetadata().withName("daemonSet").endMetadata().withNewSpec().withNewTemplate().withNewSpec().withContainers(container4).endSpec().endTemplate().endSpec().build();
    Deployment deployment = new DeploymentBuilder().withNewMetadata().withName("deployment").addToLabels("app", "che").endMetadata().withNewSpec().withNewTemplate().withNewMetadata().withName("podWithName").endMetadata().withNewSpec().withContainers(container5).endSpec().endTemplate().endSpec().build();
    Job job = new JobBuilder().withNewMetadata().withName("job").endMetadata().withNewSpec().withNewTemplate().withNewSpec().withContainers(container6).endSpec().endTemplate().endSpec().build();
    ReplicaSet replicaSet = new ReplicaSetBuilder().withNewMetadata().withName("replicaSet").addToLabels("app", "che").endMetadata().withNewSpec().withNewTemplate().withNewSpec().withContainers(container7).endSpec().endTemplate().endSpec().build();
    ReplicationController replicationController = new ReplicationControllerBuilder().withNewMetadata().withName("replicationController").endMetadata().withNewSpec().withNewTemplate().withNewSpec().withContainers(container8).endSpec().endTemplate().endSpec().build();
    StatefulSet statefulSet = new StatefulSetBuilder().withNewMetadata().withName("statefulSet").addToLabels("app", "che").endMetadata().withNewSpec().withNewTemplate().withNewSpec().withContainers(container9).endSpec().endTemplate().endSpec().build();
    CronJob cronJob = new CronJobBuilder().withNewMetadata().withName("cronJob").endMetadata().withNewSpec().withNewJobTemplate().withNewSpec().withNewTemplate().withNewSpec().withContainers(container10).endSpec().endTemplate().endSpec().endJobTemplate().endSpec().build();
    DeploymentConfig deploymentConfig = new DeploymentConfigBuilder().withNewMetadata().withName("deploymentConfig").addToLabels("app", "che").endMetadata().withNewSpec().withNewTemplate().withNewSpec().withContainers(container11).endSpec().endTemplate().endSpec().build();
    Template template = new TemplateBuilder().addToObjects(new DeploymentBuilder().withNewMetadata().withName("deploymentWithName").endMetadata().withNewSpec().withNewTemplate().withNewMetadata().withName("podWithName").endMetadata().withNewSpec().withContainers(container12).endSpec().endTemplate().endSpec().build()).build();
    // Pod, PodTemplate, DaemonSet, Deployment, Job, ReplicaSet, ReplicationController, StatefulSet,
    // CronJob, DeploymentConfig, Template
    testList = asList(podWithName, podWithGenerateName, podTemplate, daemonSet, deployment, job, replicaSet, replicationController, statefulSet, cronJob, deploymentConfig, template);
}
Also used : ReplicaSetBuilder(io.fabric8.kubernetes.api.model.apps.ReplicaSetBuilder) PodTemplateBuilder(io.fabric8.kubernetes.api.model.PodTemplateBuilder) Pod(io.fabric8.kubernetes.api.model.Pod) ReplicationControllerBuilder(io.fabric8.kubernetes.api.model.ReplicationControllerBuilder) PodBuilder(io.fabric8.kubernetes.api.model.PodBuilder) TemplateBuilder(io.fabric8.openshift.api.model.TemplateBuilder) PodTemplateBuilder(io.fabric8.kubernetes.api.model.PodTemplateBuilder) CronJobBuilder(io.fabric8.kubernetes.api.model.batch.v1.CronJobBuilder) JobBuilder(io.fabric8.kubernetes.api.model.batch.v1.JobBuilder) DeploymentConfigBuilder(io.fabric8.openshift.api.model.DeploymentConfigBuilder) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) CronJobBuilder(io.fabric8.kubernetes.api.model.batch.v1.CronJobBuilder) StatefulSetBuilder(io.fabric8.kubernetes.api.model.apps.StatefulSetBuilder) PodTemplate(io.fabric8.kubernetes.api.model.PodTemplate) Template(io.fabric8.openshift.api.model.Template) DaemonSetBuilder(io.fabric8.kubernetes.api.model.apps.DaemonSetBuilder) Container(io.fabric8.kubernetes.api.model.Container) ContainerBuilder(io.fabric8.kubernetes.api.model.ContainerBuilder) CronJob(io.fabric8.kubernetes.api.model.batch.v1.CronJob) ReplicationController(io.fabric8.kubernetes.api.model.ReplicationController) DaemonSet(io.fabric8.kubernetes.api.model.apps.DaemonSet) CronJob(io.fabric8.kubernetes.api.model.batch.v1.CronJob) Job(io.fabric8.kubernetes.api.model.batch.v1.Job) StatefulSet(io.fabric8.kubernetes.api.model.apps.StatefulSet) DeploymentConfig(io.fabric8.openshift.api.model.DeploymentConfig) ReplicaSet(io.fabric8.kubernetes.api.model.apps.ReplicaSet) DeploymentBuilder(io.fabric8.kubernetes.api.model.apps.DeploymentBuilder) PodTemplate(io.fabric8.kubernetes.api.model.PodTemplate) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 23 with CronJob

use of io.fabric8.kubernetes.api.model.batch.v1.CronJob in project devspaces-images by redhat-developer.

the class ContainerSearchTest method setup.

@BeforeMethod
public void setup() {
    // These are all the object types that can be contained in a KubernetesList which can contain a
    // container:
    // Pod, PodTemplate, DaemonSet, Deployment, Job, ReplicaSet, ReplicationController, StatefulSet,
    // CronJob, DeploymentConfig, Template
    Container container1 = new ContainerBuilder().withName("container1").build();
    Container container2 = new ContainerBuilder().withName("container2").build();
    Container container3 = new ContainerBuilder().withName("container3").build();
    Container container4 = new ContainerBuilder().withName("container4").build();
    Container container5 = new ContainerBuilder().withName("container5").build();
    Container container6 = new ContainerBuilder().withName("container6").build();
    Container container7 = new ContainerBuilder().withName("container7").build();
    Container container8 = new ContainerBuilder().withName("container8").build();
    Container container9 = new ContainerBuilder().withName("container9").build();
    Container container10 = new ContainerBuilder().withName("container10").build();
    Container container11 = new ContainerBuilder().withName("container11").build();
    Container container12 = new ContainerBuilder().withName("container12").build();
    Pod podWithName = new PodBuilder().withNewMetadata().withName("podWithName").addToLabels("app", "che").endMetadata().withNewSpec().withContainers(container1).endSpec().build();
    Pod podWithGenerateName = new PodBuilder().withNewMetadata().withGenerateName("podWithGenerateName").endMetadata().withNewSpec().withContainers(container2).endSpec().build();
    PodTemplate podTemplate = new PodTemplateBuilder().withNewMetadata().withName("podTemplate").addToLabels("app", "che").endMetadata().withNewTemplate().withNewSpec().withContainers(container3).endSpec().endTemplate().build();
    DaemonSet daemonSet = new DaemonSetBuilder().withNewMetadata().withName("daemonSet").endMetadata().withNewSpec().withNewTemplate().withNewSpec().withContainers(container4).endSpec().endTemplate().endSpec().build();
    Deployment deployment = new DeploymentBuilder().withNewMetadata().withName("deployment").addToLabels("app", "che").endMetadata().withNewSpec().withNewTemplate().withNewMetadata().withName("podWithName").endMetadata().withNewSpec().withContainers(container5).endSpec().endTemplate().endSpec().build();
    Job job = new JobBuilder().withNewMetadata().withName("job").endMetadata().withNewSpec().withNewTemplate().withNewSpec().withContainers(container6).endSpec().endTemplate().endSpec().build();
    ReplicaSet replicaSet = new ReplicaSetBuilder().withNewMetadata().withName("replicaSet").addToLabels("app", "che").endMetadata().withNewSpec().withNewTemplate().withNewSpec().withContainers(container7).endSpec().endTemplate().endSpec().build();
    ReplicationController replicationController = new ReplicationControllerBuilder().withNewMetadata().withName("replicationController").endMetadata().withNewSpec().withNewTemplate().withNewSpec().withContainers(container8).endSpec().endTemplate().endSpec().build();
    StatefulSet statefulSet = new StatefulSetBuilder().withNewMetadata().withName("statefulSet").addToLabels("app", "che").endMetadata().withNewSpec().withNewTemplate().withNewSpec().withContainers(container9).endSpec().endTemplate().endSpec().build();
    CronJob cronJob = new CronJobBuilder().withNewMetadata().withName("cronJob").endMetadata().withNewSpec().withNewJobTemplate().withNewSpec().withNewTemplate().withNewSpec().withContainers(container10).endSpec().endTemplate().endSpec().endJobTemplate().endSpec().build();
    DeploymentConfig deploymentConfig = new DeploymentConfigBuilder().withNewMetadata().withName("deploymentConfig").addToLabels("app", "che").endMetadata().withNewSpec().withNewTemplate().withNewSpec().withContainers(container11).endSpec().endTemplate().endSpec().build();
    Template template = new TemplateBuilder().addToObjects(new DeploymentBuilder().withNewMetadata().withName("deploymentWithName").endMetadata().withNewSpec().withNewTemplate().withNewMetadata().withName("podWithName").endMetadata().withNewSpec().withContainers(container12).endSpec().endTemplate().endSpec().build()).build();
    // Pod, PodTemplate, DaemonSet, Deployment, Job, ReplicaSet, ReplicationController, StatefulSet,
    // CronJob, DeploymentConfig, Template
    testList = asList(podWithName, podWithGenerateName, podTemplate, daemonSet, deployment, job, replicaSet, replicationController, statefulSet, cronJob, deploymentConfig, template);
}
Also used : ReplicaSetBuilder(io.fabric8.kubernetes.api.model.apps.ReplicaSetBuilder) PodTemplateBuilder(io.fabric8.kubernetes.api.model.PodTemplateBuilder) Pod(io.fabric8.kubernetes.api.model.Pod) ReplicationControllerBuilder(io.fabric8.kubernetes.api.model.ReplicationControllerBuilder) PodBuilder(io.fabric8.kubernetes.api.model.PodBuilder) TemplateBuilder(io.fabric8.openshift.api.model.TemplateBuilder) PodTemplateBuilder(io.fabric8.kubernetes.api.model.PodTemplateBuilder) CronJobBuilder(io.fabric8.kubernetes.api.model.batch.v1.CronJobBuilder) JobBuilder(io.fabric8.kubernetes.api.model.batch.v1.JobBuilder) DeploymentConfigBuilder(io.fabric8.openshift.api.model.DeploymentConfigBuilder) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) CronJobBuilder(io.fabric8.kubernetes.api.model.batch.v1.CronJobBuilder) StatefulSetBuilder(io.fabric8.kubernetes.api.model.apps.StatefulSetBuilder) PodTemplate(io.fabric8.kubernetes.api.model.PodTemplate) Template(io.fabric8.openshift.api.model.Template) DaemonSetBuilder(io.fabric8.kubernetes.api.model.apps.DaemonSetBuilder) Container(io.fabric8.kubernetes.api.model.Container) ContainerBuilder(io.fabric8.kubernetes.api.model.ContainerBuilder) CronJob(io.fabric8.kubernetes.api.model.batch.v1.CronJob) ReplicationController(io.fabric8.kubernetes.api.model.ReplicationController) DaemonSet(io.fabric8.kubernetes.api.model.apps.DaemonSet) CronJob(io.fabric8.kubernetes.api.model.batch.v1.CronJob) Job(io.fabric8.kubernetes.api.model.batch.v1.Job) StatefulSet(io.fabric8.kubernetes.api.model.apps.StatefulSet) DeploymentConfig(io.fabric8.openshift.api.model.DeploymentConfig) ReplicaSet(io.fabric8.kubernetes.api.model.apps.ReplicaSet) DeploymentBuilder(io.fabric8.kubernetes.api.model.apps.DeploymentBuilder) PodTemplate(io.fabric8.kubernetes.api.model.PodTemplate) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 24 with CronJob

use of io.fabric8.kubernetes.api.model.batch.v1.CronJob in project yakc by manusa.

the class CronJobService method updateSuspend.

public CronJob updateSuspend(String name, String namespace, boolean suspend) throws IOException {
    final CronJob toPatch = emptyCronJob();
    toPatch.getSpec().setSuspend(suspend);
    return kubernetesClient.create(BatchV1beta1Api.class).patchNamespacedCronJob(name, namespace, toPatch).get();
}
Also used : CronJob(com.marcnuri.yakc.model.io.k8s.api.batch.v1beta1.CronJob)

Example 25 with CronJob

use of io.fabric8.kubernetes.api.model.batch.v1.CronJob in project yakc by manusa.

the class CronJobService method trigger.

public Job trigger(String name, String namespace) throws IOException {
    final CronJob cronJob = kubernetesClient.create(BatchV1beta1Api.class).readNamespacedCronJob(name, namespace).get();
    final JobTemplateSpec jts = cronJob.getSpec().getJobTemplate();
    final String jobName = String.format("%s-manual-%s", name.length() > 38 ? name.substring(0, 38) : name, new Random().nextInt(999999));
    return kubernetesClient.create(BatchV1Api.class).createNamespacedJob(namespace, Job.builder().metadata(ObjectMeta.builder().name(jobName).namespace(namespace).labels(new HashMap<>(Optional.ofNullable(cronJob.getMetadata().getLabels()).orElse(Collections.emptyMap()))).putInAnnotations("cronjob.kubernetes.io/instantiate", "manual").addToOwnerReferences(OwnerReference.builder().kind(cronJob.getKind()).apiVersion(cronJob.getApiVersion()).controller(false).name(cronJob.getMetadata().getName()).uid(cronJob.getMetadata().getUid()).build()).build()).spec(jts.getSpec()).build()).get();
}
Also used : Random(java.util.Random) CronJob(com.marcnuri.yakc.model.io.k8s.api.batch.v1beta1.CronJob) JobTemplateSpec(com.marcnuri.yakc.model.io.k8s.api.batch.v1beta1.JobTemplateSpec)

Aggregations

CronJob (io.fabric8.kubernetes.api.model.batch.v1beta1.CronJob)14 Test (org.junit.jupiter.api.Test)12 CronJob (io.fabric8.kubernetes.api.model.batch.v1.CronJob)9 CronJobBuilder (io.fabric8.kubernetes.api.model.batch.v1.CronJobBuilder)8 CronJobBuilder (io.fabric8.kubernetes.api.model.batch.v1beta1.CronJobBuilder)8 CronJob (com.marcnuri.yakc.model.io.k8s.api.batch.v1beta1.CronJob)5 Container (io.fabric8.kubernetes.api.model.Container)4 PodTemplateSpec (io.fabric8.kubernetes.api.model.PodTemplateSpec)4 JobTemplateSpec (io.fabric8.kubernetes.api.model.batch.v1beta1.JobTemplateSpec)4 ContainerBuilder (io.fabric8.kubernetes.api.model.ContainerBuilder)3 ObjectMeta (io.fabric8.kubernetes.api.model.ObjectMeta)3 Pod (io.fabric8.kubernetes.api.model.Pod)3 Job (io.fabric8.kubernetes.api.model.batch.v1.Job)3 Random (java.util.Random)3 JobTemplateSpec (com.marcnuri.yakc.model.io.k8s.api.batch.v1beta1.JobTemplateSpec)2 PodBuilder (io.fabric8.kubernetes.api.model.PodBuilder)2 PodTemplate (io.fabric8.kubernetes.api.model.PodTemplate)2 PodTemplateBuilder (io.fabric8.kubernetes.api.model.PodTemplateBuilder)2 ReplicationController (io.fabric8.kubernetes.api.model.ReplicationController)2 ReplicationControllerBuilder (io.fabric8.kubernetes.api.model.ReplicationControllerBuilder)2