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()
metadataBuilder.withName(substituteEnv(slave.getNodeName()));
.withName(podTemplate.getName()) .addToLabels(labels) .addToLabels("owner", "jenkins")
.withAnnotations(podAnnotations).withLabels(podLabels); if (!Strings.isNullOrEmpty(template.getMetadata().getName())) { metadataBuilder.withName(template.getMetadata().getName());
final PodBuilder podBuilder = new PodBuilder() .withNewMetadata() .withName(executionId) .addToAnnotations(STYX_WORKFLOW_INSTANCE_ANNOTATION, workflowInstance.toKey()) .addToAnnotations(DOCKER_TERMINATION_LOGGING_ANNOTATION,
.withName("pod")// .addToLabels(OpenShiftService.INTEGRATION_ID_LABEL, "id")// .addToLabels(OpenShiftService.DEPLOYMENT_VERSION_LABEL, "1")//
.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(); }
@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()
@Before public void setup() { pod = new PodBuilder().withNewMetadata().withName("pod1").withNamespace("test").and().build(); service = new ServiceBuilder() .withNewMetadata().withName("service1").withNamespace("test").and() .build(); final ReplicationController rc = new ReplicationControllerBuilder() .withNewMetadata().withName("repl1").withNamespace("test").endMetadata() .withNewSpec().withReplicas(1).endSpec() .build(); kubeList = new KubernetesListBuilder().withItems(pod, service, rc).build(); }