@Override protected List<Container> getContainers() { return pod.getSpec().getContainers(); } }
static IntOrString toIntOrString(ContainerPort port) { IntOrString intOrString = new IntOrString(); intOrString.setIntVal(port.getContainerPort()); return intOrString; }
private ReplicationController createReplicationController(String name, String apiVersion, Map<String, String> labels, int replicas, Map<String, String> selector, PodTemplateSpec podTemplate) throws Exception { ReplicationController rc = new ReplicationController(); rc.setApiVersion(apiVersion); ObjectMeta objectMeta = new ObjectMeta(); rc.setMetadata(objectMeta); objectMeta.setName(name); objectMeta.setLabels(labels); ReplicationControllerSpec spec = new ReplicationControllerSpec(); rc.setSpec(spec); spec.setReplicas(replicas); spec.setSelector(selector); spec.setTemplate(podTemplate); return rc; }
private int resolvePort(Service service) { final Pod pod = getRandomPod(client, service.getMetadata().getName(), namespace); final ServicePort servicePort = (service.getSpec() != null && service.getSpec().getPorts() != null) ? service.getSpec().getPorts().get(0) : null; final int containerPort = servicePort != null ? servicePort.getTargetPort().getIntVal() : 0; return portForward(pod.getMetadata().getName(), containerPort, namespace); }
private Pod createStartablePod(Template<Pod> template, Map<String, String> defaultLabels) { Map<String, String> allLabels = new HashMap<String, String>(); allLabels.putAll(defaultLabels); allLabels.putAll(template.getTarget().getMetadata().getLabels()); Pod service = new PodBuilder() .withNewMetadataLike(template.getTarget().getMetadata()) .withLabels(allLabels) .endMetadata() .withNewSpecLike(template.getTarget().getSpec()) .endSpec() .build(); return service; }
public static Binding toBinding(Service pod) { Binding binding = null; if (pod.getStatus() != null && pod.getSpec().getClusterIP() != null) { // Running // pod binding = new Binding(pod.getSpec().getClusterIP()); } else { // Configured pod binding = new Binding(null); } for (ServicePort port : pod.getSpec().getPorts()) { // nodePort is service equivalent of pod's hostPort binding.addPortBinding(port.getPort(), port.getNodePort()); } return binding; }
@Override public void eventReceived(Action action, Pod pod) { switch (action) { case ADDED: case MODIFIED: if (pod.getStatus().getPhase().equalsIgnoreCase("Running")) { addConsole(pod.getMetadata().getName()); } break; case DELETED: case ERROR: delConsole(pod.getMetadata().getName()); break; } }
protected boolean isReady(Pod pod) { PodStatus status = pod.getStatus(); if (pod.getMetadata().getDeletionTimestamp() == null) { if ("Running".equalsIgnoreCase(status.getPhase())) { List<PodCondition> conditions = status.getConditions(); if (conditions != null) { for (PodCondition condition : conditions) { if ("Ready".equalsIgnoreCase(condition.getType())) { return "True".equalsIgnoreCase(condition.getStatus()); } } } } } return false; } }
public static Binding toBinding(Pod pod) { Binding binding = null; if (pod.getStatus() != null && pod.getStatus().getHostIP() != null) { // Running // pod binding = new Binding(pod.getStatus().getHostIP()); } else { // Configured pod binding = new Binding(null); } for (Container container : pod.getSpec().getContainers()) { for (ContainerPort port : container.getPorts()) { binding.addPortBinding(port.getContainerPort(), port.getHostPort()); } } return binding; }
private Container createContainer(String image, String name, List<EnvVar> envVars, List<ContainerPort> ports, List<VolumeMount> volumes, Lifecycle lifecycle, Probe probe, String imagePullPolicy) throws Exception { Container container = new Container(); container.setImage(image); container.setName(name); container.setEnv(envVars); container.setPorts(ports); container.setVolumeMounts(volumes); container.setLifecycle(lifecycle); container.setReadinessProbe(probe); container.setImagePullPolicy(imagePullPolicy); return container; }
private PodTemplateSpec createPodTemplateSpec(Map<String, String> labels, List<Container> containers, MountSecret mountSecret) throws Exception { PodTemplateSpec pts = new PodTemplateSpec(); ObjectMeta objectMeta = new ObjectMeta(); pts.setMetadata(objectMeta); objectMeta.setLabels(labels); PodSpec ps = new PodSpec(); pts.setSpec(ps); ps.setContainers(containers); mountSecret(ps, mountSecret); return pts; }
@Override public void visit(HasMetadata item) { logger.get().info("Applying " + item.getKind() + ":" + item.getMetadata().getName()); } }
protected String getName(Pod pod) { return pod.getMetadata().getName(); }
private String getActualName(String prefix, Iterable<? extends HasMetadata> objects, String msg) throws Exception { for (HasMetadata hmd : objects) { String name = hmd.getMetadata().getName(); if (name.startsWith(prefix)) { return name; } } throw new Exception(msg); }
private static void mountSecret(PodSpec ps, MountSecret mountSecret) { if (mountSecret != null) { Volume volume = new Volume(); volume.setName(mountSecret.volumeName()); SecretVolumeSource svc = new SecretVolumeSource(); svc.setSecretName(mountSecret.secretName()); volume.setSecret(svc); ps.setVolumes(Collections.singletonList(volume)); } }
private static boolean isReady(PodStatus status) { for (PodCondition condition : status.getConditions()) { if ("Ready".equalsIgnoreCase(condition.getType()) && "False".equalsIgnoreCase(condition.getStatus())) { return false; } } return true; }
private int resolvePort(Service service) { final Pod pod = getRandomPod(client, service.getMetadata().getName(), namespace); final ServicePort servicePort = (service.getSpec() != null && service.getSpec().getPorts() != null) ? service.getSpec().getPorts().get(0) : null; final int containerPort = servicePort != null ? servicePort.getTargetPort().getIntVal() : 0; return portForward(pod.getMetadata().getName(), containerPort, namespace); }
@Override public void eventReceived(Action action, Pod pod) { switch (action) { case ADDED: case MODIFIED: if (pod.getStatus().getPhase().equalsIgnoreCase("Running")) { addConsole(pod.getMetadata().getName()); } break; case DELETED: case ERROR: delConsole(pod.getMetadata().getName()); break; } }
@Override public void visit(HasMetadata item) { logger.get().info("Applying " + item.getKind() + ":" + item.getMetadata().getName()); } }