Search in sources :

Example 6 with StackGresDistributedLogs

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();
}
Also used : StackGresBackup(io.stackgres.common.crd.sgbackup.StackGresBackup) StackGresDistributedLogs(io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogs) RoleBuilder(io.fabric8.kubernetes.api.model.rbac.RoleBuilder) PolicyRuleBuilder(io.fabric8.kubernetes.api.model.rbac.PolicyRuleBuilder)

Example 7 with StackGresDistributedLogs

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());
}
Also used : SecretBuilder(io.fabric8.kubernetes.api.model.SecretBuilder) StackGresDistributedLogs(io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogs) HashMap(java.util.HashMap)

Example 8 with StackGresDistributedLogs

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();
}
Also used : StackGresDistributedLogs(io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogs) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) ServiceBuilder(io.fabric8.kubernetes.api.model.ServiceBuilder)

Example 9 with StackGresDistributedLogs

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();
}
Also used : StackGresDistributedLogs(io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogs) ServicePortBuilder(io.fabric8.kubernetes.api.model.ServicePortBuilder) StackGresPostgresServices(io.stackgres.common.crd.postgres.service.StackGresPostgresServices) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) ServiceBuilder(io.fabric8.kubernetes.api.model.ServiceBuilder)

Example 10 with StackGresDistributedLogs

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;
}
Also used : HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) StackGresDistributedLogs(io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogs) StackGresPostgresServices(io.stackgres.common.crd.postgres.service.StackGresPostgresServices) StackGresPostgresService(io.stackgres.common.crd.postgres.service.StackGresPostgresService) Service(io.fabric8.kubernetes.api.model.Service) IntOrString(io.fabric8.kubernetes.api.model.IntOrString)

Aggregations

StackGresDistributedLogs (io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogs)48 NotNull (org.jetbrains.annotations.NotNull)14 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)13 IntOrString (io.fabric8.kubernetes.api.model.IntOrString)12 Inject (javax.inject.Inject)11 Test (org.junit.jupiter.api.Test)11 Optional (java.util.Optional)10 Collectors (java.util.stream.Collectors)10 List (java.util.List)9 Map (java.util.Map)9 Volume (io.fabric8.kubernetes.api.model.Volume)8 StatefulSet (io.fabric8.kubernetes.api.model.apps.StatefulSet)8 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)7 Container (io.fabric8.kubernetes.api.model.Container)7 ObjectMeta (io.fabric8.kubernetes.api.model.ObjectMeta)7 VolumeMount (io.fabric8.kubernetes.api.model.VolumeMount)7 StackGresUtil (io.stackgres.common.StackGresUtil)7 StackGresCluster (io.stackgres.common.crd.sgcluster.StackGresCluster)7 JsonNode (com.fasterxml.jackson.databind.JsonNode)6 ImmutableMap (com.google.common.collect.ImmutableMap)6