Last active
December 11, 2020 08:55
-
-
Save manusa/dda58cb3629f5b73b802cf687fd33291 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
///usr/bin/env jbang "$0" "$@" ; exit $? | |
//DEPS io.fabric8:kubernetes-client:5.0-SNAPSHOT | |
//DEPS io.fabric8:openshift-client:5.0-SNAPSHOT | |
import io.fabric8.kubernetes.api.model.BindingBuilder; | |
import io.fabric8.kubernetes.api.model.PodBuilder; | |
import io.fabric8.kubernetes.api.model.Quantity; | |
import io.fabric8.kubernetes.client.DefaultKubernetesClient; | |
import io.fabric8.kubernetes.client.KubernetesClient; | |
public class BindingBuilderTest { | |
public static void main(String... args) throws Exception { | |
// https://gist.github.com/kelseyhightower/2349c9c645d32a3fcbe385082de74668 | |
final String podName = "nginx"; | |
final String nodeName = "minikube"; | |
try (KubernetesClient kc = new DefaultKubernetesClient()) { | |
kc.pods().inNamespace("default").create(new PodBuilder() | |
.withNewMetadata().withName(podName).addToLabels("run", "nginx").endMetadata() | |
.withNewSpec() | |
.withNewSchedulerName("I-dont-exist") // Required to avoid an initial Pod scheduler assignment | |
.addNewContainer().withName(podName).withImage("nginx:latest").withNewResources().addToRequests("cpu", Quantity.parse("100m")) | |
.endResources().endContainer().endSpec() | |
.build()); | |
// Slightly different to Kelsey's example. The gist uses the /bindings Pod subresource | |
kc.bindings().inNamespace("default").create(new BindingBuilder() | |
.withNewMetadata().withName(podName).endMetadata() | |
.withNewTarget().withKind("Node").withApiVersion("v1").withName(nodeName).endTarget() | |
.build()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Partial Java implementation of https://gist.github.com/kelseyhightower/2349c9c645d32a3fcbe385082de74668