|
@@ -0,0 +1,47 @@
|
|
|
+package net.p0f.k8s.demo.apiclient;
|
|
|
+
|
|
|
+import org.jboss.logmanager.Logger;
|
|
|
+
|
|
|
+public class Job {
|
|
|
+ final Logger LOG = Logger.getLogger(Job.class.getName());
|
|
|
+
|
|
|
+ final String apiResourceTemplate = """
|
|
|
+ {
|
|
|
+ "apiVersion": "batch/v1",
|
|
|
+ "kind": "Job",
|
|
|
+ "metadata": { "name": "%s",
|
|
|
+ "namespace": "%s" },
|
|
|
+ "spec": { "activeDeadlineSeconds": 30,
|
|
|
+ "completions": 1,
|
|
|
+ "parallelism": 1,
|
|
|
+ "selector": { "matchLabels": { "jobname": "%s" }},
|
|
|
+ "template": {
|
|
|
+ "metadata": { "labels": { "jobname": "%s" }},
|
|
|
+ "spec": { "containers": [{
|
|
|
+ "name": "job-%s",
|
|
|
+ "image": "registry.access.redhat.com/ubi9/ubi:latest",
|
|
|
+ "command": [ "/bin/bash", "-c", "%s" ]
|
|
|
+ }]
|
|
|
+ }
|
|
|
+ }}}
|
|
|
+ """;
|
|
|
+ String apiResource;
|
|
|
+
|
|
|
+ public Job(String namespace, String name, String command) {
|
|
|
+ LOG.info("Constructing: namespace = " + namespace + ", " +
|
|
|
+ "name = " + name + ", " +
|
|
|
+ "command = " + command);
|
|
|
+
|
|
|
+ this.apiResource = String.format(apiResourceTemplate,
|
|
|
+ name,
|
|
|
+ namespace,
|
|
|
+ name, name, name,
|
|
|
+ command);
|
|
|
+
|
|
|
+ LOG.info("Constructed:\n" + this.apiResource);
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getApiResource() {
|
|
|
+ return apiResource;
|
|
|
+ }
|
|
|
+}
|