-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
task: add tests and move DB conditions into a single util (#47)
- Loading branch information
1 parent
881b088
commit debf50b
Showing
20 changed files
with
712 additions
and
249 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package org.trustify.operator; | ||
|
||
import io.smallrye.config.ConfigMapping; | ||
import io.smallrye.config.WithName; | ||
|
||
@ConfigMapping(prefix = "trustify") | ||
public interface TrustifyConfig { | ||
|
||
@WithName("default-pvc-size") | ||
String defaultPvcSize(); | ||
} |
8 changes: 2 additions & 6 deletions
8
src/main/java/org/trustify/operator/cdrs/v2alpha1/db/DBActivationCondition.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,12 @@ | ||
package org.trustify.operator.cdrs.v2alpha1.db; | ||
|
||
import org.trustify.operator.cdrs.v2alpha1.Trustify; | ||
import org.trustify.operator.cdrs.v2alpha1.TrustifySpec; | ||
|
||
import java.util.Optional; | ||
import org.trustify.operator.cdrs.v2alpha1.server.utils.ServerUtils; | ||
|
||
public abstract class DBActivationCondition { | ||
|
||
protected boolean isMet(Trustify cr) { | ||
return !Optional.ofNullable(cr.getSpec().databaseSpec()) | ||
.map(TrustifySpec.DatabaseSpec::externalDatabase) | ||
.orElse(false); | ||
return ServerUtils.isServerDBRequired(cr); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/main/java/org/trustify/operator/cdrs/v2alpha1/db/DBSecretDiscriminator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package org.trustify.operator.cdrs.v2alpha1.db; | ||
|
||
import io.fabric8.kubernetes.api.model.Secret; | ||
import io.javaoperatorsdk.operator.api.reconciler.Context; | ||
import io.javaoperatorsdk.operator.api.reconciler.ResourceDiscriminator; | ||
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; | ||
|
||
public class DBSecretDiscriminator implements ResourceDiscriminator<Secret, Trustify> { | ||
@Override | ||
public Optional<Secret> distinguish(Class<Secret> resource, Trustify cr, Context<Trustify> context) { | ||
String secret = DBSecret.getSecretName(cr); | ||
ResourceID resourceID = new ResourceID(secret, cr.getMetadata().getNamespace()); | ||
var informerEventSource = (InformerEventSource<Secret, Trustify>) context.eventSourceRetriever().getResourceEventSourceFor(Secret.class, TrustifyReconciler.SECRET_EVENT_SOURCE); | ||
return informerEventSource.get(resourceID); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/org/trustify/operator/cdrs/v2alpha1/db/utils/DBUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package org.trustify.operator.cdrs.v2alpha1.db.utils; | ||
|
||
import io.fabric8.kubernetes.api.model.apps.Deployment; | ||
import io.javaoperatorsdk.operator.api.reconciler.Context; | ||
import io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResource; | ||
import org.trustify.operator.cdrs.v2alpha1.Trustify; | ||
import org.trustify.operator.cdrs.v2alpha1.db.DBDeploymentDiscriminator; | ||
|
||
public class DBUtils { | ||
|
||
public static boolean isDeploymentReady(DependentResource<Deployment, Trustify> dependentResource, Trustify primary, Context<Trustify> context) { | ||
return context.getSecondaryResource(Deployment.class, new DBDeploymentDiscriminator()) | ||
.map(deployment -> { | ||
final var status = deployment.getStatus(); | ||
if (status != null) { | ||
final var readyReplicas = status.getReadyReplicas(); | ||
return readyReplicas != null && readyReplicas >= 1; | ||
} | ||
return false; | ||
}) | ||
.orElse(false); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
src/main/java/org/trustify/operator/cdrs/v2alpha1/server/utils/ServerUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package org.trustify.operator.cdrs.v2alpha1.server.utils; | ||
|
||
import org.trustify.operator.cdrs.v2alpha1.Trustify; | ||
import org.trustify.operator.cdrs.v2alpha1.TrustifySpec; | ||
|
||
import java.util.Optional; | ||
|
||
public class ServerUtils { | ||
|
||
public static boolean isServerDBRequired(Trustify cr) { | ||
return !Optional.ofNullable(cr.getSpec().databaseSpec()) | ||
.map(TrustifySpec.DatabaseSpec::externalDatabase) | ||
.orElse(false); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
trustify: | ||
default-pvc-size: 10G | ||
"%test": | ||
trustify: | ||
default-pvc-size: 1G | ||
# Operator config | ||
related: | ||
image: | ||
|
Oops, something went wrong.