Search in sources :

Example 1 with StackGresDbOpsContext

use of io.stackgres.operator.conciliation.dbops.StackGresDbOpsContext 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 2 with StackGresDbOpsContext

use of io.stackgres.operator.conciliation.dbops.StackGresDbOpsContext in project stackgres by ongres.

the class DbOpsJobsGenerator method generateResource.

@Override
public Stream<HasMetadata> generateResource(StackGresDbOpsContext config) {
    Instant now = Instant.now();
    Map<String, JobFactory> factories = jobsDiscoverer.discoverFactories(config);
    return Seq.of(config.getSource()).filter(dbOp -> !isToRunAfter(dbOp, now)).map(dbOp -> {
        JobFactory jobFactory = factories.get(dbOp.getSpec().getOp());
        if (jobFactory == null) {
            throw new UnsupportedOperationException("DbOps " + dbOp.getSpec().getOp() + " not implemented!");
        }
        return jobFactory.createJob(config);
    });
}
Also used : StackGresVersion(io.stackgres.operator.common.StackGresVersion) Instant(java.time.Instant) Singleton(javax.inject.Singleton) Seq(org.jooq.lambda.Seq) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) OperatorVersionBinder(io.stackgres.operator.conciliation.OperatorVersionBinder) StackGresDbOps(io.stackgres.common.crd.sgdbops.StackGresDbOps) Inject(javax.inject.Inject) StackGresDbOpsContext(io.stackgres.operator.conciliation.dbops.StackGresDbOpsContext) Stream(java.util.stream.Stream) ResourceGenerator(io.stackgres.operator.conciliation.ResourceGenerator) Map(java.util.Map) Optional(java.util.Optional) StackGresDbOpsSpec(io.stackgres.common.crd.sgdbops.StackGresDbOpsSpec) Instant(java.time.Instant)

Example 3 with StackGresDbOpsContext

use of io.stackgres.operator.conciliation.dbops.StackGresDbOpsContext 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 StackGresDbOpsContext

use of io.stackgres.operator.conciliation.dbops.StackGresDbOpsContext 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 StackGresDbOpsContext

use of io.stackgres.operator.conciliation.dbops.StackGresDbOpsContext in project stackgres by ongres.

the class DbOpsVacuumJob method getRunEnvVars.

@Override
protected List<EnvVar> getRunEnvVars(StackGresDbOpsContext context) {
    StackGresDbOps dbOps = context.getSource();
    StackGresDbOpsVacuum vacuum = dbOps.getSpec().getVacuum();
    final String primaryServiceDns = PatroniServices.readWriteName(context);
    List<EnvVar> runEnvVars = ImmutableList.<EnvVar>builder().add(new EnvVarBuilder().withName("PGHOST").withValue(primaryServiceDns).build(), new EnvVarBuilder().withName("PGUSER").withValue("postgres").build(), new EnvVarBuilder().withName("PGPASSWORD").withNewValueFrom().withNewSecretKeyRef().withName(PatroniSecret.name(context.getCluster())).withKey(PatroniSecret.SUPERUSER_PASSWORD_KEY).endSecretKeyRef().endValueFrom().build()).addAll(getVacuumConfigEnvVar(vacuum)).add(new EnvVarBuilder().withName("DATABASES").withValue(Seq.seq(Optional.ofNullable(vacuum).map(StackGresDbOpsVacuum::getDatabases).stream()).flatMap(List::stream).map(database -> Seq.seq(getVacuumConfigEnvVar(vacuum)).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) StackGresDbOpsVacuum(io.stackgres.common.crd.sgdbops.StackGresDbOpsVacuum) Singleton(javax.inject.Singleton) Seq(org.jooq.lambda.Seq) StackGresDbOps(io.stackgres.common.crd.sgdbops.StackGresDbOps) Inject(javax.inject.Inject) StackGresDbOpsVacuumConfig(io.stackgres.common.crd.sgdbops.StackGresDbOpsVacuumConfig) 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) LabelFactoryForDbOps(io.stackgres.common.LabelFactoryForDbOps) PatroniSecret(io.stackgres.operator.conciliation.factory.cluster.patroni.PatroniSecret) ResourceFactory(io.stackgres.operator.conciliation.factory.ResourceFactory) LabelFactoryForCluster(io.stackgres.common.LabelFactoryForCluster) EnvVarBuilder(io.fabric8.kubernetes.api.model.EnvVarBuilder) JsonMapper(com.fasterxml.jackson.databind.json.JsonMapper) OperatorVersionBinder(io.stackgres.operator.conciliation.OperatorVersionBinder) PatroniServices(io.stackgres.operator.conciliation.factory.cluster.patroni.PatroniServices) CdiUtil(io.stackgres.common.CdiUtil) List(java.util.List) Optional(java.util.Optional) StackGresDbOpsVacuum(io.stackgres.common.crd.sgdbops.StackGresDbOpsVacuum) EnvVar(io.fabric8.kubernetes.api.model.EnvVar) StackGresDbOps(io.stackgres.common.crd.sgdbops.StackGresDbOps) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) EnvVarBuilder(io.fabric8.kubernetes.api.model.EnvVarBuilder)

Aggregations

StackGresDbOpsContext (io.stackgres.operator.conciliation.dbops.StackGresDbOpsContext)8 StackGresDbOps (io.stackgres.common.crd.sgdbops.StackGresDbOps)5 Optional (java.util.Optional)5 Inject (javax.inject.Inject)5 JsonMapper (com.fasterxml.jackson.databind.json.JsonMapper)4 ImmutableList (com.google.common.collect.ImmutableList)4 EnvVar (io.fabric8.kubernetes.api.model.EnvVar)4 EnvVarBuilder (io.fabric8.kubernetes.api.model.EnvVarBuilder)4 PodSecurityContext (io.fabric8.kubernetes.api.model.PodSecurityContext)4 ClusterStatefulSetPath (io.stackgres.common.ClusterStatefulSetPath)4 LabelFactoryForCluster (io.stackgres.common.LabelFactoryForCluster)4 LabelFactoryForDbOps (io.stackgres.common.LabelFactoryForDbOps)4 StackGresCluster (io.stackgres.common.crd.sgcluster.StackGresCluster)4 DbOpsEnvironmentVariables (io.stackgres.operator.cluster.factory.DbOpsEnvironmentVariables)4 StackGresVersion (io.stackgres.operator.common.StackGresVersion)4 OperatorVersionBinder (io.stackgres.operator.conciliation.OperatorVersionBinder)4 ResourceFactory (io.stackgres.operator.conciliation.factory.ResourceFactory)4 List (java.util.List)4 Singleton (javax.inject.Singleton)4 Seq (org.jooq.lambda.Seq)4