From f1c16f182d072c2cba5c585098361e81cdb0cf88 Mon Sep 17 00:00:00 2001 From: Carlos Feria <2582866+carlosthe19916@users.noreply.github.com> Date: Tue, 12 Nov 2024 14:39:56 +0100 Subject: [PATCH] optionMapper accepts null --- .../controllers/TrustifyDistConfigurator.java | 50 +++++++++++-------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/src/main/java/org/trustify/operator/controllers/TrustifyDistConfigurator.java b/src/main/java/org/trustify/operator/controllers/TrustifyDistConfigurator.java index b9fee97..ee14ea8 100644 --- a/src/main/java/org/trustify/operator/controllers/TrustifyDistConfigurator.java +++ b/src/main/java/org/trustify/operator/controllers/TrustifyDistConfigurator.java @@ -122,20 +122,32 @@ private void configureDatabase() { } private void configureStorage() { - TrustifySpec.StorageSpec storageSpec = cr.getSpec().storageSpec(); - TrustifySpec.StorageStrategyType storageStrategyType = Objects.nonNull(storageSpec) && Objects.nonNull(storageSpec.type()) ? storageSpec.type() : TrustifySpec.StorageStrategyType.FILESYSTEM; + List envVars = new ArrayList<>(); - List envVars = optionMapper(storageSpec) - .mapOption("TRUSTD_STORAGE_COMPRESSION", spec -> Objects.nonNull(spec) && Objects.nonNull(spec.compression()) ? spec.compression().getValue() : null) - .mapOption("TRUSTD_STORAGE_STRATEGY", spec -> storageStrategyType.getValue()) - .getEnvVars(); + TrustifySpec.StorageSpec storageSpec = Optional.ofNullable(cr.getSpec().storageSpec()) + .orElse(new TrustifySpec.StorageSpec(null, null, null, null)); + + // 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() + ); + + // Other config + envVars.addAll(optionMapper(storageSpec) + .mapOption("TRUSTD_STORAGE_COMPRESSION", spec -> Objects.nonNull(spec.compression()) ? spec.compression().getValue() : null) + .getEnvVars() + ); switch (storageStrategyType) { case FILESYSTEM -> { - List filesystemEnvVars = optionMapper(storageSpec) - .mapOption("TRUSTD_STORAGE_FS_PATH", spec -> "/opt/trustify/storage") - .getEnvVars(); - envVars.addAll(filesystemEnvVars); + envVars.add(new EnvVarBuilder() + .withName("TRUSTD_STORAGE_FS_PATH") + .withValue("/opt/trustify/storage") + .build() + ); var volume = new VolumeBuilder() .withName("trustify-pvol") @@ -154,17 +166,13 @@ private void configureStorage() { allVolumeMounts.add(volumeMount); } case S3 -> { - List s3EnvVars = Optional.ofNullable(storageSpec) - .flatMap(spec -> Optional.ofNullable(spec.s3StorageSpec())) - .map(spec -> optionMapper(spec) - .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() - ) - .orElseGet(ArrayList::new); - envVars.addAll(s3EnvVars); + 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() + ); } }