Skip to content

Instantly share code, notes, and snippets.

@manusa
Last active December 11, 2020 08:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save manusa/dda58cb3629f5b73b802cf687fd33291 to your computer and use it in GitHub Desktop.
Save manusa/dda58cb3629f5b73b802cf687fd33291 to your computer and use it in GitHub Desktop.
///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());
}
}
}
@manusa
Copy link
Author

manusa commented Dec 11, 2020

@jarorosFork
Copy link

nice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment