use of io.fabric8.kubernetes.api.model.batch.JobBuilder in project stackgres by ongres.
the class DbOpsRestartJob method createJob.
@Override
public Job createJob(StackGresDbOpsContext context) {
StackGresDbOps dbOps = context.getSource();
String namespace = dbOps.getMetadata().getNamespace();
final Map<String, String> labels = dbOpsLabelFactory.dbOpsPodLabels(context.getSource());
return new JobBuilder().withNewMetadata().withNamespace(namespace).withName(jobName(dbOps, "restart")).withLabels(labels).endMetadata().withNewSpec().withBackoffLimit(0).withCompletions(1).withParallelism(1).withNewTemplate().withNewMetadata().withNamespace(namespace).withName(jobName(dbOps)).withLabels(labels).endMetadata().withNewSpec().withSecurityContext(podSecurityFactory.createResource(context)).withRestartPolicy("Never").withServiceAccountName(DbOpsRole.roleName(context)).withContainers(new ContainerBuilder().withName("restart").withImagePullPolicy("IfNotPresent").withImage(String.format(IMAGE_NAME, StackGresProperty.OPERATOR_IMAGE_VERSION.getString())).addToEnv(new EnvVarBuilder().withName(OperatorProperty.OPERATOR_NAME.getEnvironmentVariableName()).withValue(OperatorProperty.OPERATOR_NAME.getString()).build(), new EnvVarBuilder().withName(OperatorProperty.OPERATOR_NAMESPACE.getEnvironmentVariableName()).withValue(OperatorProperty.OPERATOR_NAMESPACE.getString()).build(), new EnvVarBuilder().withName("JOB_NAMESPACE").withValue(namespace).build(), new EnvVarBuilder().withName(StackGresProperty.OPERATOR_VERSION.getEnvironmentVariableName()).withValue(StackGresProperty.OPERATOR_VERSION.getString()).build(), new EnvVarBuilder().withName("CRD_UPGRADE").withValue(Boolean.FALSE.toString()).build(), new EnvVarBuilder().withName("CONVERSION_WEBHOOKS").withValue(Boolean.FALSE.toString()).build(), new EnvVarBuilder().withName("DATABASE_OPERATION_JOB").withValue(Boolean.TRUE.toString()).build(), new EnvVarBuilder().withName("DATABASE_OPERATION_CR_NAME").withValue(dbOps.getMetadata().getName()).build(), new EnvVarBuilder().withName("SERVICE_ACCOUNT").withNewValueFrom().withNewFieldRef().withFieldPath("spec.serviceAccountName").endFieldRef().endValueFrom().build(), new EnvVarBuilder().withName("POD_NAME").withNewValueFrom().withNewFieldRef().withFieldPath("metadata.name").endFieldRef().endValueFrom().build(), new EnvVarBuilder().withName("APP_OPTS").withValue(System.getenv("APP_OPTS")).build(), new EnvVarBuilder().withName("JAVA_OPTS").withValue(System.getenv("JAVA_OPTS")).build(), new EnvVarBuilder().withName("DEBUG_JOBS").withValue(System.getenv("DEBUG_OPERATOR")).build(), new EnvVarBuilder().withName("DEBUG_JOBS_SUSPEND").withValue(System.getenv("DEBUG_OPERATOR_SUSPEND")).build(), new EnvVarBuilder().withName("DBOPS_LOCK_TIMEOUT").withValue(OperatorProperty.LOCK_TIMEOUT.getString()).build(), new EnvVarBuilder().withName("DBOPS_LOCK_POLL_INTERVAL").withValue(OperatorProperty.LOCK_POLL_INTERVAL.getString()).build()).build()).endSpec().endTemplate().endSpec().build();
}
use of io.fabric8.kubernetes.api.model.batch.JobBuilder in project fabric8-maven-plugin by fabric8io.
the class TriggersAnnotationEnricherTest method testNoEnrichment.
@Test
public void testNoEnrichment() {
KubernetesListBuilder builder = new KubernetesListBuilder().addToItems(new JobBuilder().withNewMetadata().addToAnnotations("dummy", "annotation").endMetadata().withNewSpec().withNewTemplate().withNewSpec().withContainers(createContainers("c1", "is1:latest", "c2", "is2:latest")).endSpec().endTemplate().endSpec().build());
TriggersAnnotationEnricher enricher = new TriggersAnnotationEnricher(context);
enricher.enrich(PlatformMode.kubernetes, builder);
Job res = (Job) builder.build().getItems().get(0);
String triggers = res.getMetadata().getAnnotations().get("image.openshift.io/triggers");
assertNull(triggers);
}
use of io.fabric8.kubernetes.api.model.batch.JobBuilder in project strimzi by strimzi.
the class KafkaAdminClients method defaultAdmin.
public Job defaultAdmin() {
Map<String, String> adminLabels = new HashMap<>();
adminLabels.put("app", adminName);
adminLabels.put(Constants.KAFKA_ADMIN_CLIENT_LABEL_KEY, Constants.KAFKA_ADMIN_CLIENT_LABEL_VALUE);
PodSpecBuilder podSpecBuilder = new PodSpecBuilder();
if (Environment.SYSTEM_TEST_STRIMZI_IMAGE_PULL_SECRET != null && !Environment.SYSTEM_TEST_STRIMZI_IMAGE_PULL_SECRET.isEmpty()) {
List<LocalObjectReference> imagePullSecrets = Collections.singletonList(new LocalObjectReference(Environment.SYSTEM_TEST_STRIMZI_IMAGE_PULL_SECRET));
podSpecBuilder.withImagePullSecrets(imagePullSecrets);
}
return new JobBuilder().withNewMetadata().withNamespace(this.getNamespaceName()).withLabels(adminLabels).withName(adminName).endMetadata().withNewSpec().withBackoffLimit(0).withNewTemplate().withNewMetadata().withName(adminName).withNamespace(this.getNamespaceName()).withLabels(adminLabels).endMetadata().withNewSpecLike(podSpecBuilder.build()).withRestartPolicy("Never").withContainers().addNewContainer().withName(adminName).withImagePullPolicy(Constants.IF_NOT_PRESENT_IMAGE_PULL_POLICY).withImage(Environment.TEST_ADMIN_IMAGE).addNewEnv().withName("BOOTSTRAP_SERVERS").withValue(this.getBootstrapAddress()).endEnv().addNewEnv().withName("TOPIC").withValue(this.getTopicName()).endEnv().addNewEnv().withName("TOPIC_OPERATION").withValue(topicOperation).endEnv().addNewEnv().withName("REPLICATION_FACTOR").withValue(String.valueOf(replicationFactor)).endEnv().addNewEnv().withName("PARTITIONS").withValue(String.valueOf(partitions)).endEnv().addNewEnv().withName("TOPICS_COUNT").withValue(String.valueOf(topicCount)).endEnv().addNewEnv().withName("TOPIC_OFFSET").withValue(String.valueOf(topicOffset)).endEnv().addNewEnv().withName("LOG_LEVEL").withValue("DEBUG").endEnv().addNewEnv().withName("ADDITIONAL_CONFIG").withValue(this.getAdditionalConfig()).endEnv().endContainer().endSpec().endTemplate().endSpec().build();
}
use of io.fabric8.kubernetes.api.model.batch.JobBuilder in project strimzi by strimzi.
the class BridgeClients method producerStrimziBridge.
public Job producerStrimziBridge() {
Map<String, String> producerLabels = new HashMap<>();
producerLabels.put("app", this.getProducerName());
producerLabels.put(Constants.KAFKA_CLIENTS_LABEL_KEY, Constants.KAFKA_BRIDGE_CLIENTS_LABEL_VALUE);
PodSpecBuilder podSpecBuilder = new PodSpecBuilder();
if (Environment.SYSTEM_TEST_STRIMZI_IMAGE_PULL_SECRET != null && !Environment.SYSTEM_TEST_STRIMZI_IMAGE_PULL_SECRET.isEmpty()) {
List<LocalObjectReference> imagePullSecrets = Collections.singletonList(new LocalObjectReference(Environment.SYSTEM_TEST_STRIMZI_IMAGE_PULL_SECRET));
podSpecBuilder.withImagePullSecrets(imagePullSecrets);
}
return new JobBuilder().withNewMetadata().withNamespace(this.getNamespaceName()).withLabels(producerLabels).withName(this.getProducerName()).endMetadata().withNewSpec().withBackoffLimit(0).withNewTemplate().withNewMetadata().withLabels(producerLabels).endMetadata().withNewSpecLike(podSpecBuilder.build()).withRestartPolicy("OnFailure").addNewContainer().withName(this.getProducerName()).withImagePullPolicy(Constants.IF_NOT_PRESENT_IMAGE_PULL_POLICY).withImage(Environment.TEST_HTTP_PRODUCER_IMAGE).addNewEnv().withName("HOSTNAME").withValue(this.getBootstrapAddress()).endEnv().addNewEnv().withName("PORT").withValue(Integer.toString(port)).endEnv().addNewEnv().withName("TOPIC").withValue(this.getTopicName()).endEnv().addNewEnv().withName("DELAY_MS").withValue(String.valueOf(this.getDelayMs())).endEnv().addNewEnv().withName("MESSAGE_COUNT").withValue(Integer.toString(this.getMessageCount())).endEnv().endContainer().endSpec().endTemplate().endSpec().build();
}
use of io.fabric8.kubernetes.api.model.batch.JobBuilder in project strimzi by strimzi.
the class KafkaClients method defaultConsumerStrimzi.
public JobBuilder defaultConsumerStrimzi() {
if (consumerName == null || consumerName.isEmpty()) {
throw new InvalidParameterException("Consumer name is not set.");
}
Map<String, String> consumerLabels = new HashMap<>();
consumerLabels.put("app", consumerName);
consumerLabels.put(Constants.KAFKA_CLIENTS_LABEL_KEY, Constants.KAFKA_CLIENTS_LABEL_VALUE);
PodSpecBuilder podSpecBuilder = new PodSpecBuilder();
if (Environment.SYSTEM_TEST_STRIMZI_IMAGE_PULL_SECRET != null && !Environment.SYSTEM_TEST_STRIMZI_IMAGE_PULL_SECRET.isEmpty()) {
List<LocalObjectReference> imagePullSecrets = Collections.singletonList(new LocalObjectReference(Environment.SYSTEM_TEST_STRIMZI_IMAGE_PULL_SECRET));
podSpecBuilder.withImagePullSecrets(imagePullSecrets);
}
return new JobBuilder().withNewMetadata().withNamespace(this.getNamespaceName()).withLabels(consumerLabels).withName(consumerName).endMetadata().withNewSpec().withBackoffLimit(0).withNewTemplate().withNewMetadata().withLabels(consumerLabels).withNamespace(this.getNamespaceName()).withName(consumerName).endMetadata().withNewSpecLike(podSpecBuilder.build()).withRestartPolicy("Never").withContainers().addNewContainer().withName(consumerName).withImagePullPolicy(Constants.IF_NOT_PRESENT_IMAGE_PULL_POLICY).withImage(Environment.TEST_CONSUMER_IMAGE).addNewEnv().withName("BOOTSTRAP_SERVERS").withValue(this.getBootstrapAddress()).endEnv().addNewEnv().withName("TOPIC").withValue(this.getTopicName()).endEnv().addNewEnv().withName("DELAY_MS").withValue(String.valueOf(delayMs)).endEnv().addNewEnv().withName("LOG_LEVEL").withValue("DEBUG").endEnv().addNewEnv().withName("MESSAGE_COUNT").withValue(String.valueOf(messageCount)).endEnv().addNewEnv().withName("GROUP_ID").withValue(consumerGroup).endEnv().addNewEnv().withName("ADDITIONAL_CONFIG").withValue(this.getAdditionalConfig()).endEnv().endContainer().endSpec().endTemplate().endSpec();
}
Aggregations