use of io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogs in project stackgres by ongres.
the class PatroniRole method createRole.
/**
* Create the Role for patroni associated to the cluster.
*/
private Role createRole(StackGresDistributedLogsContext context) {
final StackGresDistributedLogs cluster = context.getSource();
final Map<String, String> labels = labelFactory.clusterLabels(cluster);
return new RoleBuilder().withNewMetadata().withName(roleName(context)).withNamespace(cluster.getMetadata().getNamespace()).withLabels(labels).endMetadata().addToRules(new PolicyRuleBuilder().withApiGroups("").withResources("endpoints", "configmaps").withVerbs("create", "get", "list", "patch", "update", "watch").build()).addToRules(new PolicyRuleBuilder().withApiGroups("").withResources("secrets").withVerbs("get").build()).addToRules(new PolicyRuleBuilder().withApiGroups("").withResources("pods").withVerbs("get", "list", "patch", "update", "watch").build()).addToRules(new PolicyRuleBuilder().withApiGroups("").withResources("pods/exec").withVerbs("create").build()).addToRules(new PolicyRuleBuilder().withApiGroups("batch").withResources("cronjobs").withVerbs("get", "patch").build()).addToRules(new PolicyRuleBuilder().withApiGroups("").withResources("services").withVerbs("create").build()).addToRules(new PolicyRuleBuilder().withApiGroups("").withResources("events").withVerbs("get", "list", "create", "patch", "update").build()).addToRules(new PolicyRuleBuilder().withApiGroups(CommonDefinition.GROUP).withResources(HasMetadata.getPlural(StackGresBackup.class)).withVerbs("list", "get", "create", "patch", "delete").build()).addToRules(new PolicyRuleBuilder().withApiGroups(CommonDefinition.GROUP).withResources(HasMetadata.getPlural(StackGresBackup.class), HasMetadata.getPlural(StackGresBackupConfig.class), HasMetadata.getPlural(StackGresCluster.class), HasMetadata.getPlural(StackGresPostgresConfig.class), HasMetadata.getPlural(StackGresPoolingConfig.class), HasMetadata.getPlural(StackGresProfile.class), HasMetadata.getPlural(StackGresDistributedLogs.class), HasMetadata.getPlural(StackGresDbOps.class)).withVerbs("get", "list", "watch", "patch").build()).addToRules(new PolicyRuleBuilder().withApiGroups(CommonDefinition.GROUP).withResources(HasMetadata.getPlural(StackGresDistributedLogs.class)).withVerbs("update", "patch").build()).addToRules(new PolicyRuleBuilder().withApiGroups(CommonDefinition.GROUP).withResources(HasMetadata.getPlural(StackGresDistributedLogs.class) + "/status").withVerbs("update").build()).addToRules(new PolicyRuleBuilder().withApiGroups(CommonDefinition.GROUP).withResources(HasMetadata.getPlural(StackGresCluster.class) + "/status").withVerbs("update").build()).build();
}
use of io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogs in project stackgres by ongres.
the class PatroniSecret method generateResource.
/**
* Create the Secret for patroni associated to the cluster.
*/
@Override
public Stream<HasMetadata> generateResource(StackGresDistributedLogsContext context) {
final StackGresDistributedLogs cluster = context.getSource();
final String name = cluster.getMetadata().getName();
final String namespace = cluster.getMetadata().getNamespace();
final Map<String, String> labels = factoryFactory.clusterLabels(cluster);
Map<String, String> generatedPasswords = context.getDatabaseCredentials().map(Secret::getData).orElse(Map.of());
Map<String, String> data = new HashMap<>();
data.put(SUPERUSER_PASSWORD_KEY, generatedPasswords.getOrDefault(SUPERUSER_PASSWORD_KEY, generatePassword()));
data.put(REPLICATION_PASSWORD_KEY, generatedPasswords.getOrDefault(REPLICATION_PASSWORD_KEY, generatePassword()));
data.put(AUTHENTICATOR_PASSWORD_KEY, generatedPasswords.getOrDefault(AUTHENTICATOR_PASSWORD_KEY, generatePassword()));
data.put(RESTAPI_PASSWORD_KEY, generatedPasswords.getOrDefault(RESTAPI_PASSWORD_KEY, generatePassword()));
return Stream.of(new SecretBuilder().withNewMetadata().withNamespace(namespace).withName(name).withLabels(labels).endMetadata().withType("Opaque").withData(data).build());
}
use of io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogs in project stackgres by ongres.
the class PatroniServices method createPrimaryService.
private Service createPrimaryService(StackGresDistributedLogsContext context) {
StackGresDistributedLogs cluster = context.getSource();
final Map<String, String> primaryLabels = labelFactory.clusterLabels(cluster);
return new ServiceBuilder().withNewMetadata().withNamespace(cluster.getMetadata().getNamespace()).withName(readWriteName(context)).withLabels(primaryLabels).endMetadata().withNewSpec().withType("ExternalName").withExternalName(name(context) + "." + cluster.getMetadata().getNamespace() + ".svc.cluster.local").endSpec().build();
}
use of io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogs in project stackgres by ongres.
the class PatroniServices method createReplicaService.
private Service createReplicaService(StackGresDistributedLogsContext context) {
StackGresDistributedLogs cluster = context.getSource();
final Map<String, String> replicaLabels = labelFactory.patroniReplicaLabels(cluster);
final String namespace = cluster.getMetadata().getNamespace();
final String serviceName = readOnlyName(context);
String serviceType = Optional.ofNullable(cluster.getSpec()).map(StackGresDistributedLogsSpec::getPostgresServices).map(StackGresPostgresServices::getReplicas).map(StackGresPostgresService::getType).orElse(CLUSTER_IP.toString());
return new ServiceBuilder().withNewMetadata().withNamespace(namespace).withName(serviceName).withLabels(replicaLabels).endMetadata().withNewSpec().withSelector(replicaLabels).withPorts(new ServicePortBuilder().withProtocol("TCP").withName(PatroniConfigMap.POSTGRES_PORT_NAME).withPort(PatroniUtil.POSTGRES_SERVICE_PORT).withTargetPort(new IntOrString(PatroniConfigMap.POSTGRES_PORT_NAME)).build(), new ServicePortBuilder().withProtocol("TCP").withName(PatroniConfigMap.POSTGRES_REPLICATION_PORT_NAME).withPort(PatroniUtil.REPLICATION_SERVICE_PORT).withTargetPort(new IntOrString(PatroniConfigMap.POSTGRES_REPLICATION_PORT_NAME)).build()).withType(serviceType).endSpec().build();
}
use of io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogs in project stackgres by ongres.
the class PatroniServices method generateResource.
/**
* Create the Services associated with the cluster.
*/
@Override
public Stream<HasMetadata> generateResource(StackGresDistributedLogsContext context) {
final StackGresDistributedLogs cluster = context.getSource();
final String namespace = cluster.getMetadata().getNamespace();
final Map<String, String> clusterLabels = labelFactory.clusterLabels(cluster);
Service config = createConfigService(namespace, configName(context), clusterLabels);
Service patroni = createPatroniService(context);
Service primary = createPrimaryService(context);
Seq<HasMetadata> services = Seq.of(config, patroni, primary);
boolean isReplicasServiceEnabled = Optional.of(cluster).map(StackGresDistributedLogs::getSpec).map(StackGresDistributedLogsSpec::getPostgresServices).map(StackGresPostgresServices::getReplicas).map(StackGresPostgresService::getEnabled).orElse(true);
if (isReplicasServiceEnabled) {
services = services.append(createReplicaService(context));
}
return services;
}
Aggregations