.withGenerateName(config.getContainerIdPrefix()) .addToLabels(config.getLabels()) .endMetadata() .withNewSpec() .withNodeSelector(config.getNodeSelector())
public static void main(String args[]) throws InterruptedException { String master = "https://192.168.99.100:8443/"; if (args.length == 1) { master = args[0]; } log("Using master with url ", master); Config config = new ConfigBuilder().withMasterUrl(master).build(); try (final KubernetesClient client = new DefaultKubernetesClient(config)) { PriorityClass priorityClass = new PriorityClassBuilder() .withNewMetadata().withName("high-priority").endMetadata() .withValue(new Integer(100000)) .withGlobalDefault(false) .withDescription("This priority class should be used for XYZ service pods only.") .build(); client.scheduling().priorityClass().create(priorityClass); client.pods().inNamespace("default").create(new PodBuilder() .withNewMetadata().withName("nginx").withLabels(Collections.singletonMap("env", "test")).endMetadata() .withNewSpec() .addToContainers(new ContainerBuilder().withName("nginx").withImage("nginx").withImagePullPolicy("IfNotPresent").build()) .withPriorityClassName("high-priority") .endSpec() .build() ); } catch (KubernetesClientException e) { e.printStackTrace(); log("Could not create resource", e.getMessage()); } }
KubernetesConstants.KUBERNETES_PODS_LABELS, Map.class); Pod podCreating = new PodBuilder().withNewMetadata() .withName(podName).withLabels(labels).endMetadata() .withSpec(podSpec).build(); pod = getEndpoint().getKubernetesClient().pods()
SpecNested<PodBuilder> builder = metadataBuilder.endMetadata().withNewSpec();
.addToLabels("name", podTemplate.getName()) .addToLabels("image", containers.get(0).getName()) .endMetadata() .withNewSpec() .withNodeSelector(node != null ? node.getMetadata().getLabels() : new HashMap<String, String>())
SpecNested<PodBuilder> specBuilder = metadataBuilder.endMetadata() //
.addToAnnotations(DOCKER_TERMINATION_LOGGING_ANNOTATION, String.valueOf(runSpec.terminationLogging())) .endMetadata();
.addToLabels(OpenShiftService.INTEGRATION_ID_LABEL, "id")// .addToLabels(OpenShiftService.DEPLOYMENT_VERSION_LABEL, "1")// .endMetadata()//
.withName(TILLER_POD_NAME) .withLabels(TILLER_LABELS) .endMetadata()
@Override protected PodList listPods() { return new PodListBuilder() .addNewItem() .withNewMetadata() .withName("test-pod-x23x") .addToLabels(OpenShiftService.COMPONENT_LABEL, "integration") .addToLabels(OpenShiftService.DEPLOYMENT_ID_LABEL, "3") .addToAnnotations(OpenShiftService.INTEGRATION_ID_LABEL, "my-integration") .endMetadata() .withNewStatus() .withPhase("Running") .endStatus() .endItem().build(); }
@Override protected PodList listPods() { return new PodListBuilder() .addNewItem() .withNewMetadata() .withName("test-pod-x23x") .addToLabels(OpenShiftService.COMPONENT_LABEL, "integration") .addToLabels(OpenShiftService.DEPLOYMENT_VERSION_LABEL, "3") .addToLabels(OpenShiftService.INTEGRATION_ID_LABEL, "my-integration") .endMetadata() .withNewStatus() .withPhase("Running") .endStatus() .endItem().build(); }
@Override protected PodList listPods() { return new PodListBuilder() .addNewItem() .withNewMetadata() .withName("test-pod-x23x") .addToLabels(OpenShiftService.COMPONENT_LABEL, "integration") .addToAnnotations(OpenShiftService.DEPLOYMENT_VERSION_ANNOTATION, "3") .addToAnnotations(OpenShiftService.INTEGRATION_ID_ANNOTATION, "my-integration") .endMetadata() .withNewStatus() .withPhase("Running") .endStatus() .endItem().build(); }
private SpecNested<PodBuilder> podBuilder() { return new PodBuilder().withNewMetadata().endMetadata().withNewSpec(); }
@Test public void shouldCombineAllLabels() { Pod pod1 = new PodBuilder().withNewMetadata().withLabels( // ImmutableMap.of("label1", "pod1", "label2", "pod1") // ).endMetadata().withNewSpec().endSpec().build(); Pod pod2 = new PodBuilder().withNewMetadata().withLabels( // ImmutableMap.of("label1", "pod2", "label3", "pod2") // ).endMetadata().withNewSpec().endSpec().build(); Map<String, String> labels = combine(pod1, pod2).getMetadata().getLabels(); assertThat(labels, hasEntry("label1", "pod2")); assertThat(labels, hasEntry("label2", "pod1")); assertThat(labels, hasEntry("label3", "pod2")); }
@Before public void configureCloud() throws Exception { client = setupCloud(this).connect(); deletePods(client, getLabels(this), false); String image = "busybox"; Container c = new ContainerBuilder().withName(image).withImagePullPolicy("IfNotPresent").withImage(image) .withCommand("cat").withTty(true).build(); String podName = "test-command-execution-" + RandomStringUtils.random(5, "bcdfghjklmnpqrstvwxz0123456789"); pod = client.pods().create(new PodBuilder().withNewMetadata().withName(podName).withLabels(getLabels(this)) .endMetadata().withNewSpec().withContainers(c).endSpec().build()); System.out.println("Created pod: " + pod.getMetadata().getName()); decorator = new ContainerExecDecorator(client, pod.getMetadata().getName(), image, client.getNamespace()); }
private void launchPod(String appId, PodSpec podSpec, Map<String, String> labelMap, Map<String, String> idMap, Map<String, String> annotations) { client.pods() .createNew() .withNewMetadata() .withName(appId) .withLabels(labelMap) .withAnnotations(annotations) .addToLabels(idMap) .endMetadata() .withSpec(podSpec) .done(); }
@Override protected Pod resource() { return new PodBuilder() .withNewMetadata() .withNamespace(NAMESPACE) .withName(RESOURCE_NAME) .endMetadata() .withNewSpec() .withHostname("foo") .endSpec().build(); }
.withName("testpod") .addToLabels("server", "nginx") .endMetadata() .withNewSpec() .addNewContainer().withName("nginx").withImage("nginx")