Search in sources :

Example 36 with StackGresDistributedLogs

use of io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogs in project stackgres by ongres.

the class PatroniRole method createRoleBinding.

/**
 * Create the RoleBinding for patroni associated to the cluster.
 */
private RoleBinding createRoleBinding(StackGresDistributedLogsContext context) {
    final StackGresDistributedLogs cluster = context.getSource();
    final Map<String, String> labels = labelFactory.clusterLabels(cluster);
    return new RoleBindingBuilder().withNewMetadata().withName(roleName(context)).withNamespace(cluster.getMetadata().getNamespace()).withLabels(labels).endMetadata().withSubjects(new SubjectBuilder().withKind("ServiceAccount").withName(roleName(context)).withNamespace(cluster.getMetadata().getNamespace()).build()).withRoleRef(new RoleRefBuilder().withKind("Role").withName(roleName(context)).withApiGroup("rbac.authorization.k8s.io").build()).build();
}
Also used : RoleBindingBuilder(io.fabric8.kubernetes.api.model.rbac.RoleBindingBuilder) StackGresDistributedLogs(io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogs) SubjectBuilder(io.fabric8.kubernetes.api.model.rbac.SubjectBuilder) RoleRefBuilder(io.fabric8.kubernetes.api.model.rbac.RoleRefBuilder)

Example 37 with StackGresDistributedLogs

use of io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogs in project stackgres by ongres.

the class PatroniServices method configName.

public String configName(StackGresDistributedLogsContext clusterContext) {
    final StackGresDistributedLogs cluster = clusterContext.getSource();
    final String scope = labelFactory.clusterScope(cluster);
    return ResourceUtil.resourceName(scope + PatroniUtil.CONFIG_SERVICE);
}
Also used : StackGresDistributedLogs(io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogs) IntOrString(io.fabric8.kubernetes.api.model.IntOrString)

Example 38 with StackGresDistributedLogs

use of io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogs in project stackgres by ongres.

the class PatroniTemplatesConfigMap method buildSource.

@NotNull
public HasMetadata buildSource(StackGresDistributedLogsContext context) {
    Map<String, String> data = getPatroniTemplates();
    final StackGresDistributedLogs cluster = context.getSource();
    return new ConfigMapBuilder().withNewMetadata().withNamespace(cluster.getMetadata().getNamespace()).withName(name(cluster)).withLabels(labelFactory.clusterLabels(cluster)).endMetadata().withData(data).build();
}
Also used : StackGresDistributedLogs(io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogs) ConfigMapBuilder(io.fabric8.kubernetes.api.model.ConfigMapBuilder) NotNull(org.jetbrains.annotations.NotNull)

Example 39 with StackGresDistributedLogs

use of io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogs in project stackgres by ongres.

the class PatroniContainer method getContainer.

@Override
public Container getContainer(DistributedLogsContainerContext context) {
    final StackGresDistributedLogs distributedLogs = context.getDistributedLogsContext().getSource();
    final String startScript = "/start-patroni.sh";
    return new ContainerBuilder().withName(StackgresClusterContainers.PATRONI).withImage(IMAGE_NAME).withCommand("/bin/sh", "-ex", ClusterStatefulSetPath.LOCAL_BIN_PATH.path() + startScript).withImagePullPolicy("IfNotPresent").withVolumeMounts(getVolumeMounts(context)).withEnvFrom(new EnvFromSourceBuilder().withConfigMapRef(new ConfigMapEnvSourceBuilder().withName(distributedLogs.getMetadata().getName()).build()).build()).withEnv(getEnvVars(context)).withPorts(new ContainerPortBuilder().withProtocol("TCP").withName(PatroniConfigMap.POSTGRES_PORT_NAME).withContainerPort(EnvoyUtil.PG_PORT).build(), new ContainerPortBuilder().withProtocol("TCP").withName(PatroniConfigMap.POSTGRES_REPLICATION_PORT_NAME).withContainerPort(EnvoyUtil.PG_REPL_ENTRY_PORT).build(), new ContainerPortBuilder().withName(PATRONI_RESTAPI_PORT_NAME).withProtocol("TCP").withContainerPort(EnvoyUtil.PATRONI_ENTRY_PORT).build()).withLivenessProbe(new ProbeBuilder().withHttpGet(new HTTPGetActionBuilder().withPath("/cluster").withPort(new IntOrString(EnvoyUtil.PATRONI_ENTRY_PORT)).withScheme("HTTP").build()).withInitialDelaySeconds(15).withPeriodSeconds(20).withFailureThreshold(6).build()).withReadinessProbe(new ProbeBuilder().withHttpGet(new HTTPGetActionBuilder().withPath("/read-only").withPort(new IntOrString(EnvoyUtil.PATRONI_ENTRY_PORT)).withScheme("HTTP").build()).withInitialDelaySeconds(5).withPeriodSeconds(10).build()).build();
}
Also used : HTTPGetActionBuilder(io.fabric8.kubernetes.api.model.HTTPGetActionBuilder) ProbeBuilder(io.fabric8.kubernetes.api.model.ProbeBuilder) ContainerBuilder(io.fabric8.kubernetes.api.model.ContainerBuilder) StackGresDistributedLogs(io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogs) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) ContainerPortBuilder(io.fabric8.kubernetes.api.model.ContainerPortBuilder) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) EnvFromSourceBuilder(io.fabric8.kubernetes.api.model.EnvFromSourceBuilder) ConfigMapEnvSourceBuilder(io.fabric8.kubernetes.api.model.ConfigMapEnvSourceBuilder)

Example 40 with StackGresDistributedLogs

use of io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogs in project stackgres by ongres.

the class PatroniInitScriptConfigMap method buildSource.

@NotNull
public HasMetadata buildSource(StackGresDistributedLogsContext context) {
    final StackGresDistributedLogs cluster = context.getSource();
    String data = Unchecked.supplier(() -> Resources.asCharSource(PatroniInitScriptConfigMap.class.getResource("/09-distributed-logs-template.sql"), StandardCharsets.UTF_8).read()).get();
    return new ConfigMapBuilder().withNewMetadata().withNamespace(cluster.getMetadata().getNamespace()).withName(name(cluster)).withLabels(labelFactory.patroniClusterLabels(cluster)).endMetadata().withData(ImmutableMap.of("00000-distributed-logs-template.template1.sql", data)).build();
}
Also used : StackGresDistributedLogs(io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogs) ConfigMapBuilder(io.fabric8.kubernetes.api.model.ConfigMapBuilder) NotNull(org.jetbrains.annotations.NotNull)

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