io.fabric8.kubernetes.api.model.batch.Job Java Examples

The following examples show how to use io.fabric8.kubernetes.api.model.batch.Job. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JobHandler.java    From module-ballerina-kubernetes with Apache License 2.0 6 votes vote down vote up
private Job getJob(JobModel jobModel) {
    JobBuilder jobBuilder = new JobBuilder()
            .withNewMetadata()
            .withName(jobModel.getName())
            .withNamespace(dataHolder.getNamespace())
            .endMetadata()
            .withNewSpec()
            .withNewTemplate()
            .withNewSpec()
            .withRestartPolicy(jobModel.getRestartPolicy())
            .withContainers(generateContainer(jobModel))
            .withImagePullSecrets(getImagePullSecrets(jobModel))
            .withNodeSelector(jobModel.getNodeSelector())
            .endSpec()
            .endTemplate()
            .endSpec();
    return jobBuilder.build();
}
 
Example #2
Source File: KubernetesResource.java    From strimzi-kafka-operator with Apache License 2.0 6 votes vote down vote up
public static DoneableJob deployNewJob(Job job) {
    return new DoneableJob(job, kubernetesJob -> {
        TestUtils.waitFor("Job creation " + job.getMetadata().getName(), Constants.POLL_INTERVAL_FOR_RESOURCE_CREATION, Constants.TIMEOUT_FOR_CR_CREATION,
            () -> {
                try {
                    ResourceManager.kubeClient().getClient().batch().jobs().inNamespace(kubeClient().getNamespace()).createOrReplace(kubernetesJob);
                    return true;
                } catch (KubernetesClientException e) {
                    if (e.getMessage().contains("object is being deleted")) {
                        return false;
                    } else {
                        throw e;
                    }
                }
            }
        );
        return deleteLater(kubernetesJob);
    });
}
 
Example #3
Source File: JobTest.java    From kubernetes-client with Apache License 2.0 6 votes vote down vote up
@Test
public void testGet() {
 server.expect().withPath("/apis/batch/v1/namespaces/test/jobs/job1").andReturn(200, new JobBuilder().build()).once();
 server.expect().withPath("/apis/batch/v1/namespaces/ns1/jobs/job2").andReturn(200, new JobBuilder().build()).once();

  KubernetesClient client = server.getClient();

  Job job = client.batch().jobs().withName("job1").get();
  assertNotNull(job);

  job = client.batch().jobs().withName("job2").get();
  assertNull(job);

  job = client.batch().jobs().inNamespace("ns1").withName("job2").get();
  assertNotNull(job);
}
 
Example #4
Source File: JobTest.java    From module-ballerina-kubernetes with Apache License 2.0 6 votes vote down vote up
@Test
public void testKubernetesJobNodeSelector() throws IOException, InterruptedException {
    Assert.assertEquals(KubernetesTestUtils.compileBallerinaFile(SOURCE_DIR_PATH, "node_selector.bal"), 0);

    File dockerFile = DOCKER_TARGET_PATH.resolve("Dockerfile").toFile();
    Assert.assertTrue(dockerFile.exists());
    InspectImageResponse imageInspect = getDockerImage(DOCKER_IMAGE_NODE);
    Assert.assertNotNull(imageInspect.getConfig());

    File jobYAML = KUBERNETES_TARGET_PATH.resolve("node_selector_job.yaml").toFile();
    Job job = KubernetesTestUtils.loadYaml(jobYAML);
    Assert.assertEquals(job.getMetadata().getName(), "node-selector-job");
    Assert.assertEquals(job.getSpec().getTemplate().getSpec().getContainers().size(), 1);

    Container container = job.getSpec().getTemplate().getSpec().getContainers().get(0);
    Assert.assertEquals(container.getImage(), DOCKER_IMAGE_NODE);
    Assert.assertEquals(container.getImagePullPolicy(), KubernetesConstants.ImagePullPolicy.IfNotPresent.name());
    Assert.assertEquals(job.getSpec().getTemplate().getSpec()
            .getRestartPolicy(), KubernetesConstants.RestartPolicy.Never.name());

    //Validate node selector
    Map<String, String> nodeSelectors = job.getSpec().getTemplate().getSpec().getNodeSelector();
    Assert.assertEquals(nodeSelectors.size(), 1);
    Assert.assertEquals(nodeSelectors.get("disktype"), "ssd");
}
 
Example #5
Source File: JobTest.java    From module-ballerina-kubernetes with Apache License 2.0 6 votes vote down vote up
@Test
public void testKubernetesJobGeneration() throws IOException, InterruptedException {
    Assert.assertEquals(KubernetesTestUtils.compileBallerinaFile(SOURCE_DIR_PATH, "ballerina_job.bal"), 0);

    File dockerFile = DOCKER_TARGET_PATH.resolve("Dockerfile").toFile();
    Assert.assertTrue(dockerFile.exists());
    InspectImageResponse imageInspect = getDockerImage(DOCKER_IMAGE_JOB);
    Assert.assertNotNull(imageInspect.getConfig());

    File jobYAML = KUBERNETES_TARGET_PATH.resolve("ballerina_job_job.yaml").toFile();
    Job job = KubernetesTestUtils.loadYaml(jobYAML);
    Assert.assertEquals(job.getMetadata().getName(), "ballerina-job-job");
    Assert.assertEquals(job.getSpec().getTemplate().getSpec().getContainers().size(), 1);

    Container container = job.getSpec().getTemplate().getSpec().getContainers().get(0);
    Assert.assertEquals(container.getImage(), DOCKER_IMAGE_JOB);
    Assert.assertEquals(container.getImagePullPolicy(), KubernetesConstants.ImagePullPolicy.IfNotPresent.name());
    Assert.assertEquals(job.getSpec().getTemplate().getSpec()
            .getRestartPolicy(), KubernetesConstants.RestartPolicy.Never.name());
}
 
Example #6
Source File: JobOperationsImpl.java    From kubernetes-client with Apache License 2.0 6 votes vote down vote up
@Override
public Job replace(Job job) {
  if (job == null) {
    job = getItem();
  }
  // Fetch item from server and patch Selector and PodTemplate
  // metadata in case not present already in order to avoid 422
  Job jobFromServer = fromServer().get();
  if (job.getSpec().getSelector() == null) {
    job.getSpec().setSelector(jobFromServer.getSpec().getSelector());
  }
  if (job.getSpec().getTemplate().getMetadata() != null) {
    job.getSpec().getTemplate().getMetadata().setLabels(jobFromServer.getSpec().getTemplate().getMetadata().getLabels());
  } else {
    job.getSpec().getTemplate().setMetadata(jobFromServer.getSpec().getTemplate().getMetadata());
  }

  return super.replace(job);
}
 
Example #7
Source File: JobOperationsImpl.java    From kubernetes-client with Apache License 2.0 6 votes vote down vote up
private List<PodResource<Pod, DoneablePod>> doGetLog(boolean isPretty) {
  List<PodResource<Pod, DoneablePod>> pods = new ArrayList<>();
  Job job = fromServer().get();
  String jobUid = job.getMetadata().getUid();

  PodOperationsImpl podOperations = new PodOperationsImpl(new PodOperationContext(context.getClient(),
    context.getConfig(), context.getPlural(), context.getNamespace(), context.getName(), null,
    "v1", context.getCascading(), context.getItem(), context.getLabels(), context.getLabelsNot(),
    context.getLabelsIn(), context.getLabelsNotIn(), context.getFields(), context.getFieldsNot(), context.getResourceVersion(),
    context.getReloadingFromServer(), context.getGracePeriodSeconds(), context.getPropagationPolicy(),
    context.getWatchRetryInitialBackoffMillis(), context.getWatchRetryBackoffMultiplier(), null, null, null, null, null,
    null, null, null, null, false, false, false, null, null,
    null, isPretty, null, null, null, null, null));
  PodList jobPodList = podOperations.withLabel("controller-uid", jobUid).list();

  for (Pod pod : jobPodList.getItems()) {
    OwnerReference ownerReference = KubernetesResourceUtil.getControllerUid(pod);
    if (ownerReference != null && ownerReference.getUid().equals(jobUid)) {
      pods.add(podOperations.withName(pod.getMetadata().getName()));
    }
  }
  return pods;
}
 
Example #8
Source File: ApplyService.java    From jkube with Eclipse Public License 2.0 6 votes vote down vote up
protected void applyJob(Job job, String sourceName) {
    String namespace = getNamespace();
    String id = getName(job);
    Objects.requireNonNull(id, "No name for " + job + " " + sourceName);
    if (isServicesOnlyMode()) {
        log.debug("Only processing Services right now so ignoring Job: " + namespace + ":" + id);
        return;
    }
    // Not using createOrReplace() here (https://github.com/fabric8io/kubernetes-client/issues/1586)
    try {
        doCreateJob(job, namespace, sourceName);
    } catch (KubernetesClientException exception) {
        if(exception.getStatus().getCode().equals(HttpURLConnection.HTTP_CONFLICT)) {
            Job old = kubernetesClient.batch().jobs().inNamespace(namespace).withName(id).get();
            Job updatedJob = patchService.compareAndPatchEntity(namespace, job, old);
            log.info("Updated Job: " + old.getMetadata().getName());
            return;
        }
        onApplyError("Failed to apply Job from " + job.getMetadata().getName(), exception);
    }
}
 
Example #9
Source File: PatchService.java    From jkube with Eclipse Public License 2.0 6 votes vote down vote up
private static EntityPatcher<Job> jobPatcher() {
    return (KubernetesClient client, String namespace, Job newObj, Job oldObj) -> {
        if (UserConfigurationCompare.configEqual(newObj, oldObj)) {
            return oldObj;
        }

        DoneableJob entity = client.batch().jobs().withName(oldObj.getMetadata().getName()).edit();

        if (!UserConfigurationCompare.configEqual(newObj.getMetadata(), oldObj.getMetadata())) {
            entity.withMetadata(newObj.getMetadata());
        }

        if (!UserConfigurationCompare.configEqual(newObj.getSpec().getSelector(), oldObj.getSpec().getSelector())) {
            entity.editSpec().withSelector(newObj.getSpec().getSelector());
        }

        if (!UserConfigurationCompare.configEqual(newObj.getSpec().getTemplate(), oldObj.getSpec().getSelector())) {
            entity.editSpec().withTemplate(newObj.getSpec().getTemplate());
        }

        return entity.done();
    };
}
 
Example #10
Source File: JobHandlerTest.java    From jkube with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void jobHandlerTest() {

    ContainerHandler containerHandler = getContainerHandler();

    PodTemplateHandler podTemplateHandler = new PodTemplateHandler(containerHandler);

    JobHandler jobHandler = new JobHandler(podTemplateHandler);

    ResourceConfig config = ResourceConfig.builder()
            .imagePullPolicy("IfNotPresent")
            .controllerName("testing")
            .serviceAccount("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());

}
 
Example #11
Source File: JobTest.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateWithNameMismatch() {
  Assertions.assertThrows(KubernetesClientException.class, () -> {
    Job job1 = new JobBuilder().withNewMetadata().withName("job1").withNamespace("test").and().build();
    Job job2 = new JobBuilder().withNewMetadata().withName("job2").withNamespace("ns1").and().build();
    KubernetesClient client = server.getClient();

    client.batch().jobs().inNamespace("test1").withName("myjob1").create(job1);
  });
}
 
Example #12
Source File: JobTest.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
@Test
public void testDeleteWithNamespaceMismatch() {
  Assertions.assertThrows(KubernetesClientException.class, () -> {
    Job job1 = new JobBuilder().withNewMetadata().withName("job1").withNamespace("test").and().build();
    KubernetesClient client = server.getClient();

    Boolean deleted = client.batch().jobs().inNamespace("test1").delete(job1);
    assertTrue(deleted);
  });
}
 
Example #13
Source File: JobOperationsImpl.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
/**
 * Lets wait until there are enough Ready pods of the given Job
 */
private void waitUntilJobIsScaled() {
  final CountDownLatch countDownLatch = new CountDownLatch(1);

  final AtomicReference<Job> atomicJob = new AtomicReference<>();

  final Runnable jobPoller = () -> {
    try {
      Job job = getMandatory();
      atomicJob.set(job);
      Integer activeJobs = job.getStatus().getActive();
      if (activeJobs == null) {
        activeJobs = 0;
      }
      if (Objects.equals(job.getSpec().getParallelism(), activeJobs)) {
        countDownLatch.countDown();
      } else {
        LOG.debug("Only {}/{} pods scheduled for Job: {} in namespace: {} seconds so waiting...",
          job.getStatus().getActive(), job.getSpec().getParallelism(), job.getMetadata().getName(), namespace);
      }
    } catch (Throwable t) {
      LOG.error("Error while waiting for Job to be scaled.", t);
    }
  };

  ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
  ScheduledFuture poller = executor.scheduleWithFixedDelay(jobPoller, 0, POLL_INTERVAL_MS, TimeUnit.MILLISECONDS);
  try {
    countDownLatch.await(getConfig().getScaleTimeout(), TimeUnit.MILLISECONDS);
    executor.shutdown();
  } catch (InterruptedException e) {
    Thread.currentThread().interrupt();
    poller.cancel(true);
    executor.shutdown();
    LOG.error("Only {}/{} pod(s) ready for Job: {} in namespace: {} - giving up",
      atomicJob.get().getStatus().getActive(), atomicJob.get().getSpec().getParallelism(), atomicJob.get().getMetadata().getName(), namespace);
  }
}
 
Example #14
Source File: JobOperationsImpl.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
@Override
public Job scale(int count, boolean wait) {
  Job res = cascading(false).edit().editSpec().withParallelism(count).endSpec().done();
  if (wait) {
    waitUntilJobIsScaled();
    res = getMandatory();
  }
  return res;
}
 
Example #15
Source File: JobOperationsImpl.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
public JobOperationsImpl(OperationContext context) {
  super(context.withApiGroupName("batch")
    .withApiGroupVersion("v1")
    .withPlural("jobs"));

  this.type = Job.class;
  this.listType = JobList.class;
  this.doneableType = DoneableJob.class;
}
 
Example #16
Source File: ContainerSearch.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
private Stream<Container> findContainers(HasMetadata o) {
  // hopefully, this covers all types of objects that can contain a container
  if (o instanceof Pod) {
    return ((Pod) o).getSpec().getContainers().stream();
  } else if (o instanceof PodTemplate) {
    return ((PodTemplate) o).getTemplate().getSpec().getContainers().stream();
  } else if (o instanceof DaemonSet) {
    return ((DaemonSet) o).getSpec().getTemplate().getSpec().getContainers().stream();
  } else if (o instanceof Deployment) {
    return ((Deployment) o).getSpec().getTemplate().getSpec().getContainers().stream();
  } else if (o instanceof Job) {
    return ((Job) o).getSpec().getTemplate().getSpec().getContainers().stream();
  } else if (o instanceof ReplicaSet) {
    return ((ReplicaSet) o).getSpec().getTemplate().getSpec().getContainers().stream();
  } else if (o instanceof ReplicationController) {
    return ((ReplicationController) o).getSpec().getTemplate().getSpec().getContainers().stream();
  } else if (o instanceof StatefulSet) {
    return ((StatefulSet) o).getSpec().getTemplate().getSpec().getContainers().stream();
  } else if (o instanceof CronJob) {
    return ((CronJob) o)
        .getSpec()
        .getJobTemplate()
        .getSpec()
        .getTemplate()
        .getSpec()
        .getContainers()
        .stream();
  } else if (o instanceof DeploymentConfig) {
    return ((DeploymentConfig) o).getSpec().getTemplate().getSpec().getContainers().stream();
  } else if (o instanceof Template) {
    return ((Template) o).getObjects().stream().flatMap(this::findContainers);
  } else {
    return Stream.empty();
  }
}
 
Example #17
Source File: JobOperationsImpl.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
@Override
public ScalableResource<Job, DoneableJob> load(InputStream is) {
  try {
    Job item = unmarshal(is, Job.class);
    return new JobOperationsImpl(context.withItem(item));
  } catch (Throwable t) {
    throw KubernetesClientException.launderThrowable(t);
  }
}
 
Example #18
Source File: KubernetesTaskLauncher.java    From spring-cloud-deployer-kubernetes with Apache License 2.0 5 votes vote down vote up
private Job getJob(String jobName) {
	List<Job> jobs = client.batch().jobs().withLabel(SPRING_APP_KEY, jobName).list().getItems();

	for (Job job : jobs) {
		if (jobName.equals(job.getMetadata().getName())) {
			return job;
		}
	}

	return null;
}
 
Example #19
Source File: KubernetesTaskLauncher.java    From spring-cloud-deployer-kubernetes with Apache License 2.0 5 votes vote down vote up
private void deleteJob(String id) {
	FilterWatchListDeletable<Job, JobList, Boolean, Watch, Watcher<Job>> jobsToDelete = client.batch().jobs()
			.withLabel(SPRING_APP_KEY, id);

	if (jobsToDelete != null && jobsToDelete.list().getItems() != null) {
		logger.debug(String.format("Deleting Job for task: %s", id));
		boolean jobDeleted = jobsToDelete.delete();
		logger.debug(String.format("Job deleted for: %s - %b", id, jobDeleted));
	}
}
 
Example #20
Source File: KubernetesTaskLauncher.java    From spring-cloud-deployer-kubernetes with Apache License 2.0 5 votes vote down vote up
TaskStatus buildTaskStatus(String id) {

		if(properties.isCreateJob()){
			Job job = getJob(id);

			if (job == null) {
				return new TaskStatus(id, LaunchState.unknown, new HashMap<>());
			}

			JobStatus jobStatus = job.getStatus();

			if (jobStatus == null) {
				return new TaskStatus(id, LaunchState.unknown, new HashMap<>());
			}

			boolean failed = jobStatus.getFailed() != null && jobStatus.getFailed() > 0;
			boolean succeeded = jobStatus.getSucceeded() != null && jobStatus.getSucceeded() > 0;
			if (failed) {
				return new TaskStatus(id, LaunchState.failed, new HashMap<>());
			}
			if (succeeded) {
				return new TaskStatus(id, LaunchState.complete, new HashMap<>());
			}
			return new TaskStatus(id, LaunchState.launching, new HashMap<>());

		} else {
			return buildPodStatus(id);
		}
	}
 
Example #21
Source File: ExistingManifestsExampleTest.java    From dekorate with Apache License 2.0 5 votes vote down vote up
@Test
void shouldContainExistingManifestEntries() {
  final KubernetesList list = Serialization.unmarshalAsList(ExistingManifestsExampleTest.class.getClassLoader().getResourceAsStream("META-INF/dekorate/kubernetes.yml"));
  assertNotNull(list);
  final Optional<Job> job = list.getItems().stream().filter(Job.class::isInstance).map(Job.class::cast).findAny();
  assertTrue(job.isPresent());
  assertEquals(job.get().getMetadata().getName(), "Example Job");
  assertEquals(job.get().getSpec().getTemplate().getMetadata().getName(), "Example Job");
  final Optional<Container> container = job.get().getSpec().getTemplate().getSpec().getContainers().stream()
    .filter(c -> c.getName().equals("countdown"))
    .filter(c -> c.getImage().equals("alpine:3.10"))
    .findAny();
  assertTrue(container.isPresent());
}
 
Example #22
Source File: Sample11Test.java    From module-ballerina-kubernetes with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public void compileSample() throws IOException, InterruptedException {
    Assert.assertEquals(KubernetesTestUtils.compileBallerinaFile(SOURCE_DIR_PATH, "hello_world_job.bal"), 0);
    File artifactYaml = KUBERNETES_TARGET_PATH.resolve("hello_world_job.yaml").toFile();
    Assert.assertTrue(artifactYaml.exists());
    KubernetesClient client = new DefaultKubernetesClient();
    List<HasMetadata> k8sItems = client.load(new FileInputStream(artifactYaml)).get();
    for (HasMetadata data : k8sItems) {
        if ("Job".equals(data.getKind())) {
            job = (Job) data;
        } else {
            Assert.fail("Unexpected k8s resource found: " + data.getKind());
        }
    }
}
 
Example #23
Source File: NoAnnotationsTest.java    From module-ballerina-kubernetes with Apache License 2.0 5 votes vote down vote up
@Test(timeOut = 90000)
public void mainWithNoAnnotationTest() throws IOException, InterruptedException, DockerTestException,
        KubernetesPluginException {
    Assert.assertEquals(KubernetesTestUtils.compileBallerinaFile(BAL_DIRECTORY, "no_annotations_main.bal"), 0);
    File yamlFile = KUBERNETES_TARGET_PATH.resolve("no_annotations_main.yaml").toFile();
    Assert.assertTrue(yamlFile.exists());
    KubernetesClient client = new DefaultKubernetesClient();
    List<HasMetadata> k8sItems = client.load(new FileInputStream(yamlFile)).get();
    for (HasMetadata data : k8sItems) {
        if ("Job".equals(data.getKind())) {
            Job job = (Job) data;
            Assert.assertEquals(job.getMetadata().getName(), "no-annotations-main-job");
            Assert.assertEquals(job.getSpec().getTemplate().getSpec().getContainers().size(), 1);

            Container container = job.getSpec().getTemplate().getSpec().getContainers().get(0);
            Assert.assertEquals(container.getImage(), "no_annotations_main:latest");
            Assert.assertEquals(container.getImagePullPolicy(),
                    KubernetesConstants.ImagePullPolicy.IfNotPresent.name());
            Assert.assertEquals(job.getSpec().getTemplate().getSpec()
                    .getRestartPolicy(), KubernetesConstants.RestartPolicy.Never.name());
        }
    }
    
    validateDockerfile();
    
    KubernetesUtils.deleteDirectory(KUBERNETES_TARGET_PATH);
    KubernetesUtils.deleteDirectory(DOCKER_TARGET_PATH);
    KubernetesTestUtils.deleteDockerImage("no_annotations_main:latest");
}
 
Example #24
Source File: KubernetesJobGeneratorTests.java    From module-ballerina-kubernetes with Apache License 2.0 5 votes vote down vote up
private void assertGeneratedYAML(File yamlFile) throws IOException {
    Job job = Utils.loadYaml(yamlFile);
    Assert.assertEquals(jobName, job.getMetadata().getName());
    Assert.assertEquals(1, job.getSpec().getTemplate().getSpec().getContainers().size());
    Container container = job.getSpec().getTemplate().getSpec().getContainers().get(0);
    Assert.assertEquals(imageName, container.getImage());
    Assert.assertEquals(imagePullPolicy, container.getImagePullPolicy());
    Assert.assertEquals(1, container.getEnv().size());
}
 
Example #25
Source File: ApplyService.java    From jkube with Eclipse Public License 2.0 5 votes vote down vote up
public void doCreateJob(Job job, String namespace, String sourceName) throws KubernetesClientException {
    if (StringUtils.isNotBlank(namespace)) {
        kubernetesClient.batch().jobs().inNamespace(namespace).create(job);
    } else {
        kubernetesClient.batch().jobs().inNamespace(getNamespace()).create(job);
    }
    log.info("Creating a Job from " + sourceName + " namespace " + namespace + " name " + getName(job));
}
 
Example #26
Source File: TriggersAnnotationEnricherTest.java    From jkube with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testNoEnrichment() {

    KubernetesListBuilder builder = new KubernetesListBuilder().addToItems(new JobBuilder()
        .withNewMetadata()
            .addToAnnotations("dummy", "annotation")
        .endMetadata()
        .withNewSpec()
            .withNewTemplate()
                .withNewSpec()
                    .withContainers(createContainers(
                        "c1", "is1:latest",
                        "c2", "is2:latest"
                    ))
                .endSpec()
            .endTemplate()
        .endSpec()
        .build());


    TriggersAnnotationEnricher enricher = new TriggersAnnotationEnricher(context);
    enricher.enrich(PlatformMode.kubernetes, builder);


    Job res = (Job) builder.build().getItems().get(0);
    String triggers = res.getMetadata().getAnnotations().get("image.openshift.io/triggers");
    assertNull(triggers);
}
 
Example #27
Source File: JobHandler.java    From jkube with Eclipse Public License 2.0 5 votes vote down vote up
public Job getJob(ResourceConfig config,
                  List<ImageConfiguration> images) {
    return new JobBuilder()
            .withMetadata(createJobSpecMetaData(config))
            .withSpec(createJobSpec(config, images))
            .build();
}
 
Example #28
Source File: UtilsTest.java    From kubernetes-client with Apache License 2.0 4 votes vote down vote up
@Test
void testGetPluralFromKind() {
  // Given
  Map<String, Class> pluralToKubernetesResourceMap = new HashMap<>();
  pluralToKubernetesResourceMap.put("bindings", Binding.class);
  pluralToKubernetesResourceMap.put("componentstatuses", ComponentStatus.class);
  pluralToKubernetesResourceMap.put("configmaps", ConfigMap.class);
  pluralToKubernetesResourceMap.put("endpoints", Endpoints.class);
  pluralToKubernetesResourceMap.put("events", Event.class);
  pluralToKubernetesResourceMap.put("limitranges", LimitRange.class);
  pluralToKubernetesResourceMap.put("namespaces", Namespace.class);
  pluralToKubernetesResourceMap.put("nodes", Node.class);
  pluralToKubernetesResourceMap.put("persistentvolumeclaims", PersistentVolumeClaim.class);
  pluralToKubernetesResourceMap.put("persistentvolumes", PersistentVolume.class);
  pluralToKubernetesResourceMap.put("pods", Pod.class);
  pluralToKubernetesResourceMap.put("podtemplates", PodTemplate.class);
  pluralToKubernetesResourceMap.put("replicationcontrollers", ReplicationController.class);
  pluralToKubernetesResourceMap.put("resourcequotas", ResourceQuota.class);
  pluralToKubernetesResourceMap.put("secrets", Secret.class);
  pluralToKubernetesResourceMap.put("serviceaccounts", ServiceAccount.class);
  pluralToKubernetesResourceMap.put("services", Service.class);
  pluralToKubernetesResourceMap.put("mutatingwebhookconfigurations", MutatingWebhookConfiguration.class);
  pluralToKubernetesResourceMap.put("validatingwebhookconfigurations", ValidatingWebhookConfiguration.class);
  pluralToKubernetesResourceMap.put("customresourcedefinitions", CustomResourceDefinition.class);
  pluralToKubernetesResourceMap.put("controllerrevisions", ControllerRevision.class);
  pluralToKubernetesResourceMap.put("daemonsets", DaemonSet.class);
  pluralToKubernetesResourceMap.put("deployments", Deployment.class);
  pluralToKubernetesResourceMap.put("replicasets", ReplicaSet.class);
  pluralToKubernetesResourceMap.put("statefulsets", StatefulSet.class);
  pluralToKubernetesResourceMap.put("tokenreviews", TokenReview.class);
  pluralToKubernetesResourceMap.put("localsubjectaccessreviews", LocalSubjectAccessReview.class);
  pluralToKubernetesResourceMap.put("selfsubjectaccessreviews", SelfSubjectAccessReview.class);
  pluralToKubernetesResourceMap.put("selfsubjectrulesreviews", SelfSubjectRulesReview.class);
  pluralToKubernetesResourceMap.put("subjectaccessreviews", SubjectAccessReview.class);
  pluralToKubernetesResourceMap.put("horizontalpodautoscalers", HorizontalPodAutoscaler.class);
  pluralToKubernetesResourceMap.put("cronjobs", CronJob.class);
  pluralToKubernetesResourceMap.put("jobs", Job.class);
  pluralToKubernetesResourceMap.put("certificatesigningrequests", CertificateSigningRequest.class);
  pluralToKubernetesResourceMap.put("leases", Lease.class);
  pluralToKubernetesResourceMap.put("endpointslices", EndpointSlice.class);
  pluralToKubernetesResourceMap.put("ingresses", Ingress.class);
  pluralToKubernetesResourceMap.put("networkpolicies", NetworkPolicy.class);
  pluralToKubernetesResourceMap.put("poddisruptionbudgets", PodDisruptionBudget.class);
  pluralToKubernetesResourceMap.put("podsecuritypolicies", PodSecurityPolicy.class);
  pluralToKubernetesResourceMap.put("clusterrolebindings", ClusterRoleBinding.class);
  pluralToKubernetesResourceMap.put("clusterroles", ClusterRole.class);
  pluralToKubernetesResourceMap.put("rolebindings", RoleBinding.class);
  pluralToKubernetesResourceMap.put("roles", Role.class);
  pluralToKubernetesResourceMap.put("priorityclasses", PriorityClass.class);
  pluralToKubernetesResourceMap.put("csidrivers", CSIDriver.class);
  pluralToKubernetesResourceMap.put("csinodes", CSINode.class);
  pluralToKubernetesResourceMap.put("storageclasses", StorageClass.class);
  pluralToKubernetesResourceMap.put("volumeattachments", VolumeAttachment.class);

  // When & Then
  pluralToKubernetesResourceMap.forEach((plural, kubernetesResource)
    -> assertEquals(plural, Utils.getPluralFromKind(kubernetesResource.getSimpleName())));
}
 
Example #29
Source File: BatchAPIGroupClient.java    From kubernetes-client with Apache License 2.0 4 votes vote down vote up
@Override
public MixedOperation<Job, JobList, DoneableJob, ScalableResource<Job, DoneableJob>> jobs() {
  return new JobOperationsImpl(httpClient, getConfiguration());
}
 
Example #30
Source File: ExtensionsAPIGroupClient.java    From kubernetes-client with Apache License 2.0 4 votes vote down vote up
@Override
@Deprecated
public MixedOperation<Job, JobList, DoneableJob, ScalableResource<Job, DoneableJob>> jobs() {
  return new JobOperationsImpl(httpClient, getConfiguration());
}