Java Code Examples for io.fabric8.kubernetes.api.model.Container#setName()

The following examples show how to use io.fabric8.kubernetes.api.model.Container#setName() . 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: ContainerResourceProvisionerTest.java    From che with Eclipse Public License 2.0 6 votes vote down vote up
@BeforeMethod
public void setup() {
  resourceProvisioner = new ContainerResourceProvisioner(1024, 512, "500m", "100m");
  container = new Container();
  container.setName(CONTAINER_NAME);
  when(k8sEnv.getMachines()).thenReturn(of(MACHINE_NAME, internalMachineConfig));
  when(internalMachineConfig.getAttributes())
      .thenReturn(
          of(
              MEMORY_LIMIT_ATTRIBUTE,
              RAM_LIMIT_VALUE,
              MEMORY_REQUEST_ATTRIBUTE,
              RAM_REQUEST_VALUE,
              CPU_LIMIT_ATTRIBUTE,
              CPU_LIMIT_VALUE,
              CPU_REQUEST_ATTRIBUTE,
              CPU_REQUEST_VALUE));
  final ObjectMeta podMetadata = mock(ObjectMeta.class);
  when(podMetadata.getName()).thenReturn(POD_NAME);
  final PodSpec podSpec = mock(PodSpec.class);
  when(podSpec.getContainers()).thenReturn(Collections.singletonList(container));
  when(k8sEnv.getPodsData()).thenReturn(of(POD_NAME, new PodData(podSpec, podMetadata)));
}
 
Example 2
Source File: KubernetesIntegrationTest.java    From wildfly-camel with Apache License 2.0 6 votes vote down vote up
private PodSpec createPodSpec() throws IOException {
    PodSpec podSpec = new PodSpec();
    podSpec.setHostname("localhost");

    Container container = new Container();
    container.setImage("docker.io/wildflyext/wildfly-camel:latest");
    container.setName("wildfly-camel-test");

    ContainerPort port = new ContainerPort();
    port.setHostIP("0.0.0.0");
    port.setContainerPort(8080);

    List<ContainerPort> ports = new ArrayList<>();
    ports.add(port);
    container.setPorts(ports);

    List<Container> containers = new ArrayList<>();
    containers.add(container);

    podSpec.setContainers(containers);

    return podSpec;
}
 
Example 3
Source File: ImageEnricher.java    From jkube with Eclipse Public License 2.0 5 votes vote down vote up
private void mergeContainerName(ImageConfiguration imageConfiguration, Container container) {
    if (StringUtils.isBlank(container.getName())) {
        String containerName = extractContainerName(getContext().getGav(), imageConfiguration);
        log.verbose("Setting container name %s",containerName);
        container.setName(containerName);
    }
}
 
Example 4
Source File: KubernetesResource.java    From camel-quarkus with Apache License 2.0 5 votes vote down vote up
private PodSpec createPodSpec(String containerName) {
    PodSpec podSpec = new PodSpec();

    Container container = new Container();
    container.setImage("docker.io/busybox:latest");
    container.setName(containerName);

    List<Container> containers = new ArrayList<>();
    containers.add(container);

    podSpec.setContainers(containers);

    return podSpec;
}
 
Example 5
Source File: KubernetesTest.java    From camel-quarkus with Apache License 2.0 4 votes vote down vote up
@Test
public void testKubernetesComponent() {
    Container container = new Container();
    container.setImage("docker.io/busybox:latest");
    container.setName("camel-pod");

    Pod pod = new PodBuilder()
            .withNewMetadata()
            .withName("camel-pod")
            .withNamespace("test")
            .and()
            .withNewSpec()
            .withContainers(container)
            .and()
            .build();

    mockServer.expect()
            .post()
            .withPath("/api/v1/namespaces/test/pods")
            .andReturn(201, pod)
            .once();

    mockServer.expect()
            .get()
            .withPath("/api/v1/namespaces/test/pods/camel-pod")
            .andReturn(200, pod)
            .always();

    mockServer.expect()
            .delete()
            .withPath("/api/v1/namespaces/test/pods/camel-pod")
            .andReturn(200, "{}")
            .once();

    RestAssured.when()
            .post("/kubernetes/pod/test/camel-pod")
            .then()
            .statusCode(201);

    RestAssured.when()
            .get("/kubernetes/pod/test/camel-pod")
            .then()
            .statusCode(200)
            .body(is("camel-pod"));

    RestAssured.when()
            .delete("/kubernetes/pod/test/camel-pod")
            .then()
            .statusCode(204);
}
 
Example 6
Source File: KubernetesSchedulerTests.java    From spring-cloud-deployer-kubernetes with Apache License 2.0 4 votes vote down vote up
@Test
public void listScheduleWithExternalCronJobs() {
	CronJobList cronJobList = new CronJobList();
	CronJobSpec cronJobSpec = new CronJobSpec();
	JobTemplateSpec jobTemplateSpec = new JobTemplateSpec();
	JobSpec jobSpec = new JobSpec();
	PodTemplateSpec podTemplateSpec = new PodTemplateSpec();
	PodSpec podSpec = new PodSpec();
	Container container = new Container();
	container.setName("test");
	container.setImage("busybox");
	podSpec.setContainers(Arrays.asList(container));
	podSpec.setRestartPolicy("OnFailure");
	podTemplateSpec.setSpec(podSpec);
	jobSpec.setTemplate(podTemplateSpec);
	jobTemplateSpec.setSpec(jobSpec);
	cronJobSpec.setJobTemplate(jobTemplateSpec);
	cronJobSpec.setSchedule("0/10 * * * *");

	CronJob cronJob1 = new CronJob();
	ObjectMeta objectMeta1 = new ObjectMeta();
	Map<String, String> labels = new HashMap<>();
	labels.put("spring-cronjob-id", "test");
	objectMeta1.setLabels(labels);
	objectMeta1.setName("job1");
	cronJob1.setMetadata(objectMeta1);
	cronJob1.setSpec(cronJobSpec);
	ObjectMeta objectMeta2 = new ObjectMeta();
	objectMeta2.setName("job2");
	CronJob cronJob2 = new CronJob();
	cronJob2.setSpec(cronJobSpec);
	cronJob2.setMetadata(objectMeta2);
	ObjectMeta objectMeta3 = new ObjectMeta();
	objectMeta3.setName("job3");
	CronJob cronJob3 = new CronJob();
	cronJob3.setSpec(cronJobSpec);
	cronJob3.setMetadata(objectMeta3);
	cronJobList.setItems(Arrays.asList(cronJob1, cronJob2, cronJob3));
	this.kubernetesClient.batch().cronjobs().create(cronJob1);
	this.kubernetesClient.batch().cronjobs().create(cronJob2);
	this.kubernetesClient.batch().cronjobs().create(cronJob3);
	List<ScheduleInfo> scheduleInfos = this.scheduler.list();
	assertThat(scheduleInfos.size() == 1);
	assertThat(scheduleInfos.get(0).getScheduleName().equals("job1"));
}