use of io.stackgres.common.crd.sgdbops.StackGresDbOps in project stackgres by ongres.
the class DbOpsRole method createRoleBinding.
/**
* Create the RoleBinding for Job associated to the dbOps.
*/
private RoleBinding createRoleBinding(StackGresDbOpsContext context) {
final StackGresDbOps dbOps = context.getSource();
final Map<String, String> labels = labelFactory.clusterLabels(context.getCluster());
return new RoleBindingBuilder().withNewMetadata().withName(roleName(context)).withNamespace(dbOps.getMetadata().getNamespace()).withLabels(labels).endMetadata().withSubjects(new SubjectBuilder().withKind("ServiceAccount").withName(roleName(context)).withNamespace(dbOps.getMetadata().getNamespace()).build()).withRoleRef(new RoleRefBuilder().withKind("Role").withName(roleName(context)).withApiGroup("rbac.authorization.k8s.io").build()).build();
}
use of io.stackgres.common.crd.sgdbops.StackGresDbOps in project stackgres by ongres.
the class DbOpsRole method createServiceAccount.
/**
* Create the ServiceAccount for Job associated to the dbOps.
*/
private ServiceAccount createServiceAccount(StackGresDbOpsContext context) {
final StackGresDbOps dbOps = context.getSource();
final Map<String, String> labels = labelFactory.clusterLabels(context.getCluster());
final String serviceAccountName = roleName(context);
final String serviceAccountNamespace = dbOps.getMetadata().getNamespace();
return new ServiceAccountBuilder().withNewMetadata().withName(serviceAccountName).withNamespace(serviceAccountNamespace).withLabels(labels).endMetadata().build();
}
use of io.stackgres.common.crd.sgdbops.StackGresDbOps in project stackgres by ongres.
the class DbOpsRole method createRole.
/**
* Create the Role for Job associated to the dbOps.
*/
private Role createRole(StackGresDbOpsContext context) {
final StackGresDbOps dbOps = context.getSource();
final Map<String, String> labels = labelFactory.clusterLabels(context.getCluster());
return new RoleBuilder().withNewMetadata().withName(roleName(context)).withNamespace(dbOps.getMetadata().getNamespace()).withLabels(labels).endMetadata().addToRules(new PolicyRuleBuilder().withApiGroups("").withResources("pods").withVerbs("get", "list", "watch", "delete").build()).addToRules(new PolicyRuleBuilder().withApiGroups("").withResources("pods/log").withVerbs("get").build()).addToRules(new PolicyRuleBuilder().withApiGroups("").withResources("pods/exec").withVerbs("create").build()).addToRules(new PolicyRuleBuilder().withApiGroups("").withResources("services", "secrets").withVerbs("get", "list").build()).addToRules(new PolicyRuleBuilder().withApiGroups("apps").withResources("statefulsets").withVerbs("get", "delete").build()).addToRules(new PolicyRuleBuilder().withApiGroups("").withResources("events").withVerbs("get", "list", "create", "patch", "update").build()).addToRules(new PolicyRuleBuilder().withApiGroups(CommonDefinition.GROUP).withResources(HasMetadata.getPlural(StackGresDbOps.class)).withVerbs("get", "list", "watch", "patch", "update").build()).addToRules(new PolicyRuleBuilder().withApiGroups(CommonDefinition.GROUP).withResources(HasMetadata.getPlural(StackGresCluster.class)).withVerbs("get", "list", "watch", "patch", "update").build()).addToRules(new PolicyRuleBuilder().withApiGroups(CommonDefinition.GROUP).withResources(HasMetadata.getPlural(StackGresCluster.class) + "/status").withVerbs("update").build()).build();
}
use of io.stackgres.common.crd.sgdbops.StackGresDbOps 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;
}
use of io.stackgres.common.crd.sgdbops.StackGresDbOps in project stackgres by ongres.
the class PgbenchBenchmark method getRunEnvVars.
@Override
protected List<EnvVar> getRunEnvVars(StackGresDbOpsContext context) {
StackGresDbOps dbOps = context.getSource();
StackGresDbOpsBenchmark benchmark = dbOps.getSpec().getBenchmark();
StackGresDbOpsPgbench pgbench = benchmark.getPgbench();
final String primaryServiceDns = PatroniServices.readWriteName(context);
final String serviceDns;
if (benchmark.isConnectionTypePrimaryService()) {
serviceDns = primaryServiceDns;
} else {
serviceDns = PatroniServices.readOnlyName(context);
}
final String scale = Quantity.getAmountInBytes(Quantity.parse(pgbench.getDatabaseSize())).divide(Quantity.getAmountInBytes(Quantity.parse("16Mi"))).toPlainString();
final String duration = String.valueOf(Duration.parse(pgbench.getDuration()).getSeconds());
return ImmutableList.of(new EnvVarBuilder().withName("PGHOST").withValue(serviceDns).build(), new EnvVarBuilder().withName("PRIMARY_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(), new EnvVarBuilder().withName("SCALE").withValue(scale).build(), new EnvVarBuilder().withName("DURATION").withValue(duration).build(), new EnvVarBuilder().withName("PROTOCOL").withValue(Optional.of(pgbench).map(StackGresDbOpsPgbench::getUsePreparedStatements).map(usePreparedStatements -> usePreparedStatements ? "prepared" : "simple").orElse("simple")).build(), new EnvVarBuilder().withName("READ_WRITE").withValue(Optional.of(benchmark).map(StackGresDbOpsBenchmark::isConnectionTypePrimaryService).map(String::valueOf).orElse("true")).build(), new EnvVarBuilder().withName("CLIENTS").withValue(Optional.of(pgbench).map(StackGresDbOpsPgbench::getConcurrentClients).map(String::valueOf).orElse("1")).build(), new EnvVarBuilder().withName("JOBS").withValue(Optional.of(pgbench).map(StackGresDbOpsPgbench::getThreads).map(String::valueOf).orElse("1")).build());
}
Aggregations