Skip to content
This repository was archived by the owner on Sep 11, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions scripts/examples/storage-filesystem.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: "org.trustify/v1alpha1"
kind: "Trustify"
metadata:
name: myapp
spec:
storage:
type: FILESYSTEM
filesystem:
pvcSize: 5Gi
12 changes: 12 additions & 0 deletions scripts/examples/storage-s3.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: "org.trustify/v1alpha1"
kind: "Trustify"
metadata:
name: myapp
spec:
storage:
type: S3
s3:
region: myregion
bucket: mybucket
secretKey: mysecretkey
accessKey: myaccesskey
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ public record TrustifySpec(
@JsonPropertyDescription("In this section you can configure Oidc settings.")
OidcSpec oidcSpec,

@JsonProperty("storage")
@JsonPropertyDescription("In this section you can configure Storage settings.")
StorageSpec storageSpec,

@JsonProperty("serverResourceLimits")
@JsonPropertyDescription("In this section you can configure resource limits settings for the Server.")
ResourcesLimitSpec serverResourceLimitSpec
Expand All @@ -51,6 +55,7 @@ public TrustifySpec() {
null,
null,
null,
null,
null
);
}
Expand Down Expand Up @@ -106,6 +111,64 @@ public record OidcSpec(
) {
}

public enum StorageStrategyType {
FILESYSTEM("fs"),
S3("s3");
private final String value;

StorageStrategyType(String value) {
this.value = value;
}

public String getValue() {
return value;
}
}

public enum StorageCompressionType {
NONE("none"),
ZSTD("zstd");
private final String value;

StorageCompressionType(String value) {
this.value = value;
}

public String getValue() {
return value;
}
}

public record StorageSpec(
@JsonPropertyDescription("Storage compression.")
StorageCompressionType compression,
@JsonPropertyDescription("Storage type.")
StorageStrategyType type,
@JsonProperty("filesystem")
FilesystemStorageSpec filesystemStorageSpec,
@JsonProperty("s3")
S3StorageSpec s3StorageSpec
) {
}

public record FilesystemStorageSpec(
@JsonPropertyDescription("Size of the PVC to create.")
String pvcSize
) {
}

public record S3StorageSpec(
@JsonPropertyDescription("Region name.")
String region,
@JsonPropertyDescription("Bucket name.")
String bucket,
@JsonPropertyDescription("Access key.")
String accessKey,
@JsonPropertyDescription("Secret key.")
String secretKey
) {
}

public record ResourcesLimitSpec(
@JsonPropertyDescription("Requested CPU.")
String cpuRequest,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import io.javaoperatorsdk.operator.processing.event.ResourceID;
import io.javaoperatorsdk.operator.processing.event.source.informer.InformerEventSource;
import org.trustify.operator.cdrs.v2alpha1.Trustify;
import org.trustify.operator.controllers.TrustifyReconciler;

import java.util.Optional;

Expand All @@ -14,7 +15,7 @@ public class DBDeploymentDiscriminator implements ResourceDiscriminator<Deployme
public Optional<Deployment> distinguish(Class<Deployment> resource, Trustify cr, Context<Trustify> context) {
String deploymentName = DBDeployment.getDeploymentName(cr);
ResourceID resourceID = new ResourceID(deploymentName, cr.getMetadata().getNamespace());
var informerEventSource = (InformerEventSource<Deployment, Trustify>) context.eventSourceRetriever().getResourceEventSourceFor(Deployment.class, "db-deployment");
var informerEventSource = (InformerEventSource<Deployment, Trustify>) context.eventSourceRetriever().getResourceEventSourceFor(Deployment.class, TrustifyReconciler.DEPLOYMENT_EVENT_SOURCE);
return informerEventSource.get(resourceID);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import io.javaoperatorsdk.operator.processing.event.ResourceID;
import io.javaoperatorsdk.operator.processing.event.source.informer.InformerEventSource;
import org.trustify.operator.cdrs.v2alpha1.Trustify;
import org.trustify.operator.controllers.TrustifyReconciler;

import java.util.Optional;

Expand All @@ -14,7 +15,7 @@ public class DBServiceDiscriminator implements ResourceDiscriminator<Service, Tr
public Optional<Service> distinguish(Class<Service> resource, Trustify cr, Context<Trustify> context) {
String serviceName = DBService.getServiceName(cr);
ResourceID resourceID = new ResourceID(serviceName, cr.getMetadata().getNamespace());
var informerEventSource = (InformerEventSource<Service, Trustify>) context.eventSourceRetriever().getResourceEventSourceFor(Service.class, "db-service");
var informerEventSource = (InformerEventSource<Service, Trustify>) context.eventSourceRetriever().getResourceEventSourceFor(Service.class, TrustifyReconciler.SERVICE_EVENT_SOURCE);
return informerEventSource.get(resourceID);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
import jakarta.enterprise.context.ApplicationScoped;
import org.trustify.operator.Constants;
import org.trustify.operator.cdrs.v2alpha1.Trustify;
import org.trustify.operator.cdrs.v2alpha1.TrustifySpec;
import org.trustify.operator.utils.CRDUtils;

import java.util.Map;
import java.util.Optional;

@KubernetesDependent(labelSelector = ServerStoragePersistentVolumeClaim.LABEL_SELECTOR, resourceDiscriminator = ServerStoragePersistentVolumeClaimDiscriminator.class)
@ApplicationScoped
Expand All @@ -33,7 +35,10 @@ private PersistentVolumeClaim newPersistentVolumeClaim(Trustify cr, Context<Trus
final var labels = (Map<String, String>) context.managedDependentResourceContext()
.getMandatory(Constants.CONTEXT_LABELS_KEY, Map.class);

String pvcStorageSize = "10Gi";
String pvcStorageSize = Optional.ofNullable(cr.getSpec().storageSpec())
.flatMap(storageSpec -> Optional.ofNullable(storageSpec.filesystemStorageSpec()))
.map(TrustifySpec.FilesystemStorageSpec::pvcSize)
.orElse(Constants.DEFAULT_PVC_SIZE);

return new PersistentVolumeClaimBuilder()
.withNewMetadata()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.trustify.operator.cdrs.v2alpha1.server;

import io.fabric8.kubernetes.api.model.PersistentVolumeClaim;
import io.javaoperatorsdk.operator.api.reconciler.Context;
import io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResource;
import io.javaoperatorsdk.operator.processing.dependent.workflow.Condition;
import jakarta.enterprise.context.ApplicationScoped;
import org.trustify.operator.cdrs.v2alpha1.Trustify;
import org.trustify.operator.cdrs.v2alpha1.TrustifySpec;

import java.util.Objects;
import java.util.Optional;

@ApplicationScoped
public class ServerStoragePersistentVolumeClaimActivationCondition implements Condition<PersistentVolumeClaim, Trustify> {

@Override
public boolean isMet(DependentResource<PersistentVolumeClaim, Trustify> resource, Trustify cr, Context<Trustify> context) {
return Optional.ofNullable(cr.getSpec().storageSpec())
.map(storageSpec -> Objects.isNull(storageSpec.type()) || Objects.equals(TrustifySpec.StorageStrategyType.FILESYSTEM, storageSpec.type()))
.orElse(true);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -122,25 +122,59 @@ private void configureDatabase() {
}

private void configureStorage() {
List<EnvVar> envVars = optionMapper(cr.getSpec())
.mapOption("TRUSTD_STORAGE_FS_PATH", spec -> "/opt/trustify/storage")
.getEnvVars();
List<EnvVar> envVars = new ArrayList<>();

var volume = new VolumeBuilder()
.withName("trustify-pvol")
.withPersistentVolumeClaim(new PersistentVolumeClaimVolumeSourceBuilder()
.withClaimName(ServerStoragePersistentVolumeClaim.getPersistentVolumeClaimName(cr))
.build()
)
.build();
TrustifySpec.StorageSpec storageSpec = Optional.ofNullable(cr.getSpec().storageSpec())
.orElse(new TrustifySpec.StorageSpec(null, null, null, null));

var volumeMount = new VolumeMountBuilder()
.withName(volume.getName())
.withMountPath("/opt/trustify")
.build();
// Storage type
TrustifySpec.StorageStrategyType storageStrategyType = Objects.nonNull(storageSpec.type()) ? storageSpec.type() : TrustifySpec.StorageStrategyType.FILESYSTEM;
envVars.add(new EnvVarBuilder()
.withName("TRUSTD_STORAGE_STRATEGY")
.withValue(storageStrategyType.getValue())
.build()
);

allVolumes.add(volume);
allVolumeMounts.add(volumeMount);
// Other config
envVars.addAll(optionMapper(storageSpec)
.mapOption("TRUSTD_STORAGE_COMPRESSION", spec -> Objects.nonNull(spec.compression()) ? spec.compression().getValue() : null)
.getEnvVars()
);

switch (storageStrategyType) {
case FILESYSTEM -> {
envVars.add(new EnvVarBuilder()
.withName("TRUSTD_STORAGE_FS_PATH")
.withValue("/opt/trustify/storage")
.build()
);

var volume = new VolumeBuilder()
.withName("trustify-pvol")
.withPersistentVolumeClaim(new PersistentVolumeClaimVolumeSourceBuilder()
.withClaimName(ServerStoragePersistentVolumeClaim.getPersistentVolumeClaimName(cr))
.build()
)
.build();

var volumeMount = new VolumeMountBuilder()
.withName(volume.getName())
.withMountPath("/opt/trustify")
.build();

allVolumes.add(volume);
allVolumeMounts.add(volumeMount);
}
case S3 -> {
envVars.addAll(optionMapper(storageSpec.s3StorageSpec())
.mapOption("TRUSTD_S3_BUCKET", TrustifySpec.S3StorageSpec::bucket)
.mapOption("TRUSTD_S3_REGION", TrustifySpec.S3StorageSpec::region)
.mapOption("TRUSTD_S3_ACCESS_KEY", TrustifySpec.S3StorageSpec::accessKey)
.mapOption("TRUSTD_S3_SECRET_KEY", TrustifySpec.S3StorageSpec::secretKey)
.getEnvVars()
);
}
}

allEnvVars.addAll(envVars);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@
import org.trustify.operator.cdrs.v2alpha1.Trustify;
import org.trustify.operator.cdrs.v2alpha1.TrustifyStatusCondition;
import org.trustify.operator.cdrs.v2alpha1.db.*;
import org.trustify.operator.cdrs.v2alpha1.server.ServerDeployment;
import org.trustify.operator.cdrs.v2alpha1.server.ServerIngress;
import org.trustify.operator.cdrs.v2alpha1.server.ServerService;
import org.trustify.operator.cdrs.v2alpha1.server.ServerStoragePersistentVolumeClaim;
import org.trustify.operator.cdrs.v2alpha1.server.*;

import java.time.Duration;
import java.util.Map;
Expand Down Expand Up @@ -46,32 +43,27 @@
@Dependent(
name = "db-service",
type = DBService.class,
dependsOn = {"db-deployment"},
activationCondition = DBServiceActivationCondition.class
),

@Dependent(
name = "server-pvc",
type = ServerStoragePersistentVolumeClaim.class
type = ServerStoragePersistentVolumeClaim.class,
activationCondition = ServerStoragePersistentVolumeClaimActivationCondition.class
),
@Dependent(
name = "server-deployment",
type = ServerDeployment.class,
// dependsOn = {"db-service"},
readyPostcondition = ServerDeployment.class,
useEventSourceWithName = TrustifyReconciler.DEPLOYMENT_EVENT_SOURCE
readyPostcondition = ServerDeployment.class
),
@Dependent(
name = "server-service",
type = ServerService.class,
dependsOn = {"server-deployment"},
useEventSourceWithName = TrustifyReconciler.SERVICE_EVENT_SOURCE
type = ServerService.class
),

@Dependent(
name = "ingress",
type = ServerIngress.class,
dependsOn = {"server-service"},
readyPostcondition = ServerIngress.class
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
import org.hamcrest.Matchers;
import org.junit.jupiter.api.*;
import org.trustify.operator.Constants;
import org.trustify.operator.cdrs.v2alpha1.*;
import org.trustify.operator.cdrs.v2alpha1.Trustify;
import org.trustify.operator.cdrs.v2alpha1.db.DBDeployment;
import org.trustify.operator.cdrs.v2alpha1.db.DBService;
import org.trustify.operator.cdrs.v2alpha1.server.ServerDeployment;
import org.trustify.operator.cdrs.v2alpha1.server.ServerIngress;
import org.trustify.operator.cdrs.v2alpha1.server.ServerService;
import org.trustify.operator.cdrs.v2alpha1.db.DBDeployment;
import org.trustify.operator.cdrs.v2alpha1.db.DBService;
import org.trustify.operator.controllers.setup.K3sResource;

import java.util.List;
Expand Down