Search in sources :

Example 1 with StackGresDbOps

use of io.stackgres.common.crd.sgdbops.StackGresDbOps in project stackgres by ongres.

the class PodTestUtil method buildJobPod.

public Pod buildJobPod(StackGresCluster cluster, int index) {
    String namespace = cluster.getMetadata().getNamespace();
    String clusterName = cluster.getMetadata().getName();
    StackGresDbOps dbOps = new StackGresDbOps();
    dbOps.setMetadata(cluster.getMetadata());
    final Map<String, String> labels = dbOpsLabelFactory.dbOpsPodLabels(dbOps);
    return new PodBuilder().withNewMetadata().withName(String.format(JOB_NAME_FORMAT, clusterName, clusterName, index, StringUtils.getRandomString(5))).withNamespace(namespace).withLabels(labels).endMetadata().build();
}
Also used : PodBuilder(io.fabric8.kubernetes.api.model.PodBuilder) StackGresDbOps(io.stackgres.common.crd.sgdbops.StackGresDbOps)

Example 2 with StackGresDbOps

use of io.stackgres.common.crd.sgdbops.StackGresDbOps in project stackgres by ongres.

the class DbOpsJob method createJob.

@Override
public Job createJob(StackGresDbOpsContext context) {
    final StackGresDbOps dbOps = context.getSource();
    final String retries = String.valueOf(DbOpsUtil.getCurrentRetry(dbOps));
    List<EnvVar> runEnvVars = getRunEnvVars(context);
    List<EnvVar> setResultEnvVars = getSetResultEnvVars(context);
    final String namespace = dbOps.getMetadata().getNamespace();
    final String name = dbOps.getMetadata().getName();
    final Map<String, String> labels = dbOpsLabelFactory.dbOpsPodLabels(context.getSource());
    final String timeout = DbOpsUtil.getTimeout(dbOps);
    return new JobBuilder().withNewMetadata().withNamespace(namespace).withName(jobName(dbOps)).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)).withInitContainers(new ContainerBuilder().withName("set-dbops-running").withImage(getSetResultImage()).withImagePullPolicy("IfNotPresent").withEnv(ImmutableList.<EnvVar>builder().addAll(clusterEnvironmentVariables.listResources(context)).add(new EnvVarBuilder().withName("OP_NAME").withValue(dbOps.getSpec().getOp()).build(), new EnvVarBuilder().withName("NORMALIZED_OP_NAME").withValue(UPPERCASE_PATTERN.matcher(dbOps.getSpec().getOp()).replaceAll(result -> " " + result.group(1).toLowerCase(Locale.US))).build(), new EnvVarBuilder().withName("KEBAB_OP_NAME").withValue(UPPERCASE_PATTERN.matcher(dbOps.getSpec().getOp()).replaceAll(result -> "-" + result.group(1).toLowerCase(Locale.US))).build(), new EnvVarBuilder().withName("CLUSTER_NAMESPACE").withValue(namespace).build(), new EnvVarBuilder().withName("DB_OPS_NAME").withValue(name).build(), new EnvVarBuilder().withName("DB_OPS_CRD_NAME").withValue(CustomResource.getCRDName(StackGresDbOps.class)).build(), new EnvVarBuilder().withName("CURRENT_RETRY").withValue(retries).build()).addAll(Seq.of(DbOpsStatusCondition.values()).map(c -> new EnvVarBuilder().withName("CONDITION_" + c.name()).withValue(conditions.get(c)).build()).toList()).build()).withCommand("/bin/sh", "-ex", ClusterStatefulSetPath.LOCAL_BIN_SET_DBOPS_RUNNING_SH_PATH.path()).withVolumeMounts(ClusterStatefulSetVolumeConfig.TEMPLATES.volumeMount(context, volumeMountBuilder -> volumeMountBuilder.withSubPath(ClusterStatefulSetPath.LOCAL_BIN_SET_DBOPS_RUNNING_SH_PATH.filename()).withMountPath(ClusterStatefulSetPath.LOCAL_BIN_SET_DBOPS_RUNNING_SH_PATH.path()).withReadOnly(true)), ClusterStatefulSetVolumeConfig.TEMPLATES.volumeMount(context, volumeMountBuilder -> volumeMountBuilder.withSubPath(ClusterStatefulSetPath.LOCAL_BIN_SHELL_UTILS_PATH.filename()).withMountPath(ClusterStatefulSetPath.LOCAL_BIN_SHELL_UTILS_PATH.path()).withReadOnly(true))).build()).withContainers(new ContainerBuilder().withName("run-dbops").withImage(getRunImage(context)).withImagePullPolicy("IfNotPresent").withEnv(ImmutableList.<EnvVar>builder().addAll(clusterEnvironmentVariables.listResources(context)).add(new EnvVarBuilder().withName("OP_NAME").withValue(dbOps.getSpec().getOp()).build(), new EnvVarBuilder().withName("EXCLUSIVE_OP").withValue(String.valueOf(isExclusiveOp())).build(), new EnvVarBuilder().withName("NORMALIZED_OP_NAME").withValue(UPPERCASE_PATTERN.matcher(dbOps.getSpec().getOp()).replaceAll(result -> " " + result.group(1).toLowerCase(Locale.US))).build(), new EnvVarBuilder().withName("KEBAB_OP_NAME").withValue(UPPERCASE_PATTERN.matcher(dbOps.getSpec().getOp()).replaceAll(result -> "-" + result.group(1).toLowerCase(Locale.US))).build(), new EnvVarBuilder().withName("RUN_SCRIPT_PATH").withValue(Optional.ofNullable(getRunScript()).map(ClusterStatefulSetPath::path).orElse("")).build(), new EnvVarBuilder().withName("TIMEOUT").withValue(timeout).build()).addAll(runEnvVars).build()).withCommand("/bin/sh", "-ex", ClusterStatefulSetPath.LOCAL_BIN_RUN_DBOPS_SH_PATH.path()).withVolumeMounts(ClusterStatefulSetVolumeConfig.SHARED.volumeMount(context), ClusterStatefulSetVolumeConfig.TEMPLATES.volumeMount(context, volumeMountBuilder -> volumeMountBuilder.withSubPath(ClusterStatefulSetPath.LOCAL_BIN_RUN_DBOPS_SH_PATH.filename()).withMountPath(ClusterStatefulSetPath.LOCAL_BIN_RUN_DBOPS_SH_PATH.path()).withReadOnly(true)), ClusterStatefulSetVolumeConfig.TEMPLATES.volumeMount(context, volumeMountBuilder -> volumeMountBuilder.withSubPath(ClusterStatefulSetPath.LOCAL_BIN_SHELL_UTILS_PATH.filename()).withMountPath(ClusterStatefulSetPath.LOCAL_BIN_SHELL_UTILS_PATH.path()).withReadOnly(true)), ClusterStatefulSetVolumeConfig.TEMPLATES.volumeMount(context, volumeMountBuilder -> volumeMountBuilder.withSubPath(getRunScript().filename()).withMountPath(getRunScript().path()).withReadOnly(true))).build(), new ContainerBuilder().withName("set-dbops-result").withImage(StackGresComponent.KUBECTL.findLatestImageName()).withImagePullPolicy("IfNotPresent").withEnv(ImmutableList.<EnvVar>builder().addAll(clusterEnvironmentVariables.listResources(context)).add(new EnvVarBuilder().withName("OP_NAME").withValue(dbOps.getSpec().getOp()).build(), new EnvVarBuilder().withName("NORMALIZED_OP_NAME").withValue(UPPERCASE_PATTERN.matcher(dbOps.getSpec().getOp()).replaceAll(result -> " " + result.group(1).toLowerCase(Locale.US))).build(), new EnvVarBuilder().withName("KEBAB_OP_NAME").withValue(UPPERCASE_PATTERN.matcher(dbOps.getSpec().getOp()).replaceAll(result -> "-" + result.group(1).toLowerCase(Locale.US))).build(), new EnvVarBuilder().withName("SET_RESULT_SCRIPT_PATH").withValue(Optional.ofNullable(getSetResultScript()).map(ClusterStatefulSetPath::path).orElse("")).build(), new EnvVarBuilder().withName("CLUSTER_NAMESPACE").withValue(namespace).build(), new EnvVarBuilder().withName("DB_OPS_NAME").withValue(name).build(), new EnvVarBuilder().withName("DB_OPS_CRD_NAME").withValue(CustomResource.getCRDName(StackGresDbOps.class)).build(), new EnvVarBuilder().withName("JOB_POD_LABELS").withValue(Seq.seq(labels).append(Tuple.tuple("job-name", jobName(dbOps))).map(t -> t.v1 + "=" + t.v2).toString(",")).build()).addAll(Seq.of(DbOpsStatusCondition.values()).map(c -> new EnvVarBuilder().withName("CONDITION_" + c.name()).withValue(conditions.get(c)).build()).toList()).addAll(setResultEnvVars).build()).withCommand("/bin/sh", "-ex", ClusterStatefulSetPath.LOCAL_BIN_SET_DBOPS_RESULT_SH_PATH.path()).withVolumeMounts(ClusterStatefulSetVolumeConfig.SHARED.volumeMount(context), ClusterStatefulSetVolumeConfig.TEMPLATES.volumeMount(context, volumeMountBuilder -> volumeMountBuilder.withSubPath(ClusterStatefulSetPath.LOCAL_BIN_SET_DBOPS_RESULT_SH_PATH.filename()).withMountPath(ClusterStatefulSetPath.LOCAL_BIN_SET_DBOPS_RESULT_SH_PATH.path()).withReadOnly(true)), ClusterStatefulSetVolumeConfig.TEMPLATES.volumeMount(context, volumeMountBuilder -> volumeMountBuilder.withSubPath(ClusterStatefulSetPath.LOCAL_BIN_SHELL_UTILS_PATH.filename()).withMountPath(ClusterStatefulSetPath.LOCAL_BIN_SHELL_UTILS_PATH.path()).withReadOnly(true))).addAllToVolumeMounts(Optional.ofNullable(getSetResultScript()).map(script -> ClusterStatefulSetVolumeConfig.TEMPLATES.volumeMount(context, volumeMountBuilder -> volumeMountBuilder.withSubPath(script.filename()).withMountPath(script.path()).withReadOnly(true))).stream().collect(Collectors.toList())).build()).withVolumes(ClusterStatefulSetVolumeConfig.SHARED.volume(context), new VolumeBuilder(ClusterStatefulSetVolumeConfig.TEMPLATES.volume(context)).editConfigMap().withDefaultMode(// NOPMD
    0555).endConfigMap().build()).endSpec().endTemplate().endSpec().build();
}
Also used : PodSecurityContext(io.fabric8.kubernetes.api.model.PodSecurityContext) EnvVar(io.fabric8.kubernetes.api.model.EnvVar) StackGresCluster(io.stackgres.common.crd.sgcluster.StackGresCluster) Seq(org.jooq.lambda.Seq) StackGresDbOps(io.stackgres.common.crd.sgdbops.StackGresDbOps) Inject(javax.inject.Inject) StackGresDbOpsContext(io.stackgres.operator.conciliation.dbops.StackGresDbOpsContext) Tuple2(org.jooq.lambda.tuple.Tuple2) ImmutableList(com.google.common.collect.ImmutableList) DbOpsEnvironmentVariables(io.stackgres.operator.cluster.factory.DbOpsEnvironmentVariables) ClusterStatefulSetPath(io.stackgres.common.ClusterStatefulSetPath) Locale(java.util.Locale) Map(java.util.Map) LabelFactoryForDbOps(io.stackgres.common.LabelFactoryForDbOps) ContainerBuilder(io.fabric8.kubernetes.api.model.ContainerBuilder) DbOpsUtil(io.stackgres.common.DbOpsUtil) Job(io.fabric8.kubernetes.api.model.batch.v1.Job) ResourceFactory(io.stackgres.operator.conciliation.factory.ResourceFactory) JobBuilder(io.fabric8.kubernetes.api.model.batch.v1.JobBuilder) Unchecked(org.jooq.lambda.Unchecked) ImmutableMap(com.google.common.collect.ImmutableMap) LabelFactoryForCluster(io.stackgres.common.LabelFactoryForCluster) EnvVarBuilder(io.fabric8.kubernetes.api.model.EnvVarBuilder) VolumeBuilder(io.fabric8.kubernetes.api.model.VolumeBuilder) Collectors(java.util.stream.Collectors) JsonMapper(com.fasterxml.jackson.databind.json.JsonMapper) DbOpsStatusCondition(io.stackgres.common.crd.sgdbops.DbOpsStatusCondition) StackGresComponent(io.stackgres.common.StackGresComponent) List(java.util.List) ClusterStatefulSetVolumeConfig(io.stackgres.operator.conciliation.factory.cluster.patroni.ClusterStatefulSetVolumeConfig) Tuple(org.jooq.lambda.tuple.Tuple) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) CustomResource(io.fabric8.kubernetes.client.CustomResource) ContainerBuilder(io.fabric8.kubernetes.api.model.ContainerBuilder) JobBuilder(io.fabric8.kubernetes.api.model.batch.v1.JobBuilder) EnvVar(io.fabric8.kubernetes.api.model.EnvVar) StackGresDbOps(io.stackgres.common.crd.sgdbops.StackGresDbOps) ClusterStatefulSetPath(io.stackgres.common.ClusterStatefulSetPath) VolumeBuilder(io.fabric8.kubernetes.api.model.VolumeBuilder) EnvVarBuilder(io.fabric8.kubernetes.api.model.EnvVarBuilder)

Example 3 with StackGresDbOps

use of io.stackgres.common.crd.sgdbops.StackGresDbOps in project stackgres by ongres.

the class DbOpsMajorVersionUpgradeJob method getRunEnvVars.

@Override
protected List<EnvVar> getRunEnvVars(StackGresDbOpsContext context) {
    StackGresDbOps dbOps = context.getSource();
    StackGresDbOpsMajorVersionUpgrade majorVersionUpgrade = dbOps.getSpec().getMajorVersionUpgrade();
    return ImmutableList.<EnvVar>builder().add(new EnvVarBuilder().withName("LINK").withValue(Optional.ofNullable(majorVersionUpgrade).map(StackGresDbOpsMajorVersionUpgrade::getLink).map(String::valueOf).orElse("false")).build(), new EnvVarBuilder().withName("CLONE").withValue(Optional.ofNullable(majorVersionUpgrade).map(StackGresDbOpsMajorVersionUpgrade::getClone).map(String::valueOf).orElse("false")).build(), new EnvVarBuilder().withName("CHECK").withValue(Optional.ofNullable(majorVersionUpgrade).map(StackGresDbOpsMajorVersionUpgrade::getCheck).map(String::valueOf).orElse("false")).build(), new EnvVarBuilder().withName("CRD_GROUP").withValue(CommonDefinition.GROUP).build(), new EnvVarBuilder().withName("CLUSTER_CRD_NAME").withValue(HasMetadata.getPlural(StackGresCluster.class)).build(), new EnvVarBuilder().withName("CLUSTER_NAMESPACE").withValue(context.getSource().getMetadata().getNamespace()).build(), new EnvVarBuilder().withName("CLUSTER_NAME").withValue(context.getSource().getSpec().getSgCluster()).build(), new EnvVarBuilder().withName("SERVICE_ACCOUNT").withValueFrom(new EnvVarSourceBuilder().withFieldRef(new ObjectFieldSelector("v1", "spec.serviceAccountName")).build()).build(), new EnvVarBuilder().withName("POD_NAME").withValueFrom(new EnvVarSourceBuilder().withFieldRef(new ObjectFieldSelector("v1", "metadata.name")).build()).build(), new EnvVarBuilder().withName("DB_OPS_CRD_NAME").withValue(CustomResource.getCRDName(StackGresDbOps.class)).build(), new EnvVarBuilder().withName("DB_OPS_NAME").withValue(dbOps.getMetadata().getName()).build(), new EnvVarBuilder().withName("CLUSTER_POD_LABELS").withValue(labelFactory.patroniClusterLabels(context.getCluster()).entrySet().stream().map(e -> e.getKey() + "=" + e.getValue()).collect(Collectors.joining(","))).build(), new EnvVarBuilder().withName("CLUSTER_PRIMARY_POD_LABELS").withValue(labelFactory.patroniPrimaryLabels(context.getCluster()).entrySet().stream().map(e -> e.getKey() + "=" + e.getValue()).collect(Collectors.joining(","))).build(), new EnvVarBuilder().withName("PATRONI_CONTAINER_NAME").withValue(StackgresClusterContainers.PATRONI).build(), new EnvVarBuilder().withName("MAJOR_VERSION_UPGRADE_CONTAINER_NAME").withValue(StackgresClusterContainers.MAJOR_VERSION_UPGRADE).build(), new EnvVarBuilder().withName("LOCK_TIMEOUT").withValue(OperatorProperty.LOCK_TIMEOUT.getString()).build(), new EnvVarBuilder().withName("LOCK_SLEEP").withValue(OperatorProperty.LOCK_POLL_INTERVAL.getString()).build()).build();
}
Also used : PodSecurityContext(io.fabric8.kubernetes.api.model.PodSecurityContext) EnvVar(io.fabric8.kubernetes.api.model.EnvVar) StackGresCluster(io.stackgres.common.crd.sgcluster.StackGresCluster) StackGresVersion(io.stackgres.operator.common.StackGresVersion) Singleton(javax.inject.Singleton) StackgresClusterContainers(io.stackgres.common.StackgresClusterContainers) StackGresDbOps(io.stackgres.common.crd.sgdbops.StackGresDbOps) Inject(javax.inject.Inject) StackGresDbOpsContext(io.stackgres.operator.conciliation.dbops.StackGresDbOpsContext) ImmutableList(com.google.common.collect.ImmutableList) DbOpsEnvironmentVariables(io.stackgres.operator.cluster.factory.DbOpsEnvironmentVariables) ClusterStatefulSetPath(io.stackgres.common.ClusterStatefulSetPath) StackGresDbOpsMajorVersionUpgrade(io.stackgres.common.crd.sgdbops.StackGresDbOpsMajorVersionUpgrade) EnvVarSourceBuilder(io.fabric8.kubernetes.api.model.EnvVarSourceBuilder) LabelFactoryForDbOps(io.stackgres.common.LabelFactoryForDbOps) ResourceFactory(io.stackgres.operator.conciliation.factory.ResourceFactory) LabelFactoryForCluster(io.stackgres.common.LabelFactoryForCluster) ObjectFieldSelector(io.fabric8.kubernetes.api.model.ObjectFieldSelector) EnvVarBuilder(io.fabric8.kubernetes.api.model.EnvVarBuilder) Collectors(java.util.stream.Collectors) JsonMapper(com.fasterxml.jackson.databind.json.JsonMapper) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) OperatorVersionBinder(io.stackgres.operator.conciliation.OperatorVersionBinder) CdiUtil(io.stackgres.common.CdiUtil) StackGresComponent(io.stackgres.common.StackGresComponent) List(java.util.List) Optional(java.util.Optional) OperatorProperty(io.stackgres.common.OperatorProperty) CommonDefinition(io.stackgres.common.crd.CommonDefinition) CustomResource(io.fabric8.kubernetes.client.CustomResource) ObjectFieldSelector(io.fabric8.kubernetes.api.model.ObjectFieldSelector) EnvVarSourceBuilder(io.fabric8.kubernetes.api.model.EnvVarSourceBuilder) EnvVar(io.fabric8.kubernetes.api.model.EnvVar) StackGresDbOps(io.stackgres.common.crd.sgdbops.StackGresDbOps) EnvVarBuilder(io.fabric8.kubernetes.api.model.EnvVarBuilder) StackGresDbOpsMajorVersionUpgrade(io.stackgres.common.crd.sgdbops.StackGresDbOpsMajorVersionUpgrade)

Example 4 with StackGresDbOps

use of io.stackgres.common.crd.sgdbops.StackGresDbOps in project stackgres by ongres.

the class DbOpsRepackJob method getRunEnvVars.

@Override
protected List<EnvVar> getRunEnvVars(StackGresDbOpsContext context) {
    StackGresDbOps dbOps = context.getSource();
    StackGresDbOpsRepack repack = dbOps.getSpec().getRepack();
    List<EnvVar> runEnvVars = ImmutableList.<EnvVar>builder().add(new EnvVarBuilder().withName("CLUSTER_NAMESPACE").withValue(context.getSource().getMetadata().getNamespace()).build(), new EnvVarBuilder().withName("CLUSTER_NAME").withValue(context.getSource().getMetadata().getName()).build(), new EnvVarBuilder().withName("CLUSTER_PRIMARY_POD_LABELS").withValue(labelFactory.patroniPrimaryLabels(context.getCluster()).entrySet().stream().map(e -> e.getKey() + "=" + e.getValue()).collect(Collectors.joining(","))).build(), new EnvVarBuilder().withName("PATRONI_CONTAINER_NAME").withValue(StackgresClusterContainers.PATRONI).build()).addAll(getRepackConfigEnvVar(repack)).add(new EnvVarBuilder().withName("DATABASES").withValue(Seq.seq(Optional.ofNullable(repack).map(StackGresDbOpsRepack::getDatabases).stream()).flatMap(List::stream).map(database -> Seq.seq(getRepackConfigEnvVar(repack)).map(envVar -> envVar.getName() + "=" + envVar.getValue()).toString(";") + " " + database.getName()).toString("\n")).build()).build();
    return runEnvVars;
}
Also used : PodSecurityContext(io.fabric8.kubernetes.api.model.PodSecurityContext) EnvVar(io.fabric8.kubernetes.api.model.EnvVar) StackGresCluster(io.stackgres.common.crd.sgcluster.StackGresCluster) StackGresVersion(io.stackgres.operator.common.StackGresVersion) Singleton(javax.inject.Singleton) Seq(org.jooq.lambda.Seq) StackgresClusterContainers(io.stackgres.common.StackgresClusterContainers) StackGresDbOps(io.stackgres.common.crd.sgdbops.StackGresDbOps) Inject(javax.inject.Inject) StackGresDbOpsContext(io.stackgres.operator.conciliation.dbops.StackGresDbOpsContext) ImmutableList(com.google.common.collect.ImmutableList) DbOpsEnvironmentVariables(io.stackgres.operator.cluster.factory.DbOpsEnvironmentVariables) ClusterStatefulSetPath(io.stackgres.common.ClusterStatefulSetPath) Duration(java.time.Duration) LabelFactoryForDbOps(io.stackgres.common.LabelFactoryForDbOps) ResourceFactory(io.stackgres.operator.conciliation.factory.ResourceFactory) LabelFactoryForCluster(io.stackgres.common.LabelFactoryForCluster) StackGresDbOpsRepackConfig(io.stackgres.common.crd.sgdbops.StackGresDbOpsRepackConfig) EnvVarBuilder(io.fabric8.kubernetes.api.model.EnvVarBuilder) Collectors(java.util.stream.Collectors) JsonMapper(com.fasterxml.jackson.databind.json.JsonMapper) OperatorVersionBinder(io.stackgres.operator.conciliation.OperatorVersionBinder) CdiUtil(io.stackgres.common.CdiUtil) StackGresComponent(io.stackgres.common.StackGresComponent) List(java.util.List) StackGresDbOpsRepack(io.stackgres.common.crd.sgdbops.StackGresDbOpsRepack) Optional(java.util.Optional) EnvVar(io.fabric8.kubernetes.api.model.EnvVar) StackGresDbOps(io.stackgres.common.crd.sgdbops.StackGresDbOps) StackGresDbOpsRepack(io.stackgres.common.crd.sgdbops.StackGresDbOpsRepack) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) EnvVarBuilder(io.fabric8.kubernetes.api.model.EnvVarBuilder)

Example 5 with StackGresDbOps

use of io.stackgres.common.crd.sgdbops.StackGresDbOps 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();
}
Also used : ContainerBuilder(io.fabric8.kubernetes.api.model.ContainerBuilder) JobBuilder(io.fabric8.kubernetes.api.model.batch.v1.JobBuilder) StackGresDbOps(io.stackgres.common.crd.sgdbops.StackGresDbOps) EnvVarBuilder(io.fabric8.kubernetes.api.model.EnvVarBuilder)

Aggregations

StackGresDbOps (io.stackgres.common.crd.sgdbops.StackGresDbOps)23 EnvVarBuilder (io.fabric8.kubernetes.api.model.EnvVarBuilder)8 List (java.util.List)8 Inject (javax.inject.Inject)8 StackGresCluster (io.stackgres.common.crd.sgcluster.StackGresCluster)7 Optional (java.util.Optional)6 ImmutableList (com.google.common.collect.ImmutableList)5 LabelFactoryForCluster (io.stackgres.common.LabelFactoryForCluster)5 LabelFactoryForDbOps (io.stackgres.common.LabelFactoryForDbOps)5 Collectors (java.util.stream.Collectors)5 JsonMapper (com.fasterxml.jackson.databind.json.JsonMapper)4 ContainerBuilder (io.fabric8.kubernetes.api.model.ContainerBuilder)4 EnvVar (io.fabric8.kubernetes.api.model.EnvVar)4 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)4 ObjectMeta (io.fabric8.kubernetes.api.model.ObjectMeta)4 PodSecurityContext (io.fabric8.kubernetes.api.model.PodSecurityContext)4 JobBuilder (io.fabric8.kubernetes.api.model.batch.v1.JobBuilder)4 ClusterStatefulSetPath (io.stackgres.common.ClusterStatefulSetPath)4 DbOpsEnvironmentVariables (io.stackgres.operator.cluster.factory.DbOpsEnvironmentVariables)4 StackGresDbOpsContext (io.stackgres.operator.conciliation.dbops.StackGresDbOpsContext)4