Skip to content

Commit

Permalink
Fix conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosthe19916 committed Nov 13, 2024
1 parent d9911b3 commit 08d639f
Show file tree
Hide file tree
Showing 11 changed files with 85 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import io.javaoperatorsdk.operator.processing.dependent.Creator;
import io.javaoperatorsdk.operator.processing.dependent.Matcher;
import io.javaoperatorsdk.operator.processing.dependent.kubernetes.CRUDKubernetesDependentResource;
import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependent;
import jakarta.enterprise.context.ApplicationScoped;
import org.trustify.operator.Constants;
import org.trustify.operator.cdrs.v2alpha1.Trustify;
Expand All @@ -14,9 +15,12 @@
import java.util.Map;
import java.util.Random;

@KubernetesDependent(labelSelector = DBSecret.LABEL_SELECTOR, resourceDiscriminator = DBSecretDiscriminator.class)
@ApplicationScoped
public class DBSecret extends CRUDKubernetesDependentResource<Secret, Trustify> implements Creator<Secret, Trustify> {

public static final String LABEL_SELECTOR = "app.kubernetes.io/managed-by=trustify-operator,component=db";

public DBSecret() {
super(Secret.class);
}
Expand All @@ -42,6 +46,7 @@ private Secret newSecret(Trustify cr, Context<Trustify> context) {
.withName(getSecretName(cr))
.withNamespace(cr.getMetadata().getNamespace())
.withLabels(labels)
.addToLabels("component", "db")
.withOwnerReferences(CRDUtils.getOwnerReference(cr))
.endMetadata()
.addToStringData(Constants.DB_SECRET_USERNAME, generateRandomString(10))
Expand Down
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
public class KeycloakDBDeployment extends CRUDKubernetesDependentResource<Deployment, Trustify>
implements Matcher<Deployment, Trustify>, Condition<Deployment, Trustify> {

public static final String LABEL_SELECTOR = "app.kubernetes.io/managed-by=trustify-operator,component=oidc";
public static final String LABEL_SELECTOR = "app.kubernetes.io/managed-by=trustify-operator,component=keycloak";

@Inject
Config config;
Expand Down Expand Up @@ -79,7 +79,7 @@ private Deployment newDeployment(Trustify cr, Context<Trustify> context) {
.withName(getDeploymentName(cr))
.withNamespace(cr.getMetadata().getNamespace())
.withLabels(contextLabels)
.addToLabels("component", "oidc")
.addToLabels("component", "keycloak")
.addToLabels(Map.of(
"app.openshift.io/runtime", "postgresql"
))
Expand Down Expand Up @@ -217,7 +217,7 @@ private List<EnvVar> getEnvVars(Trustify cr) {
}

public static String getDeploymentName(Trustify cr) {
return cr.getMetadata().getName() + Constants.DB_DEPLOYMENT_SUFFIX;
return cr.getMetadata().getName() + Constants.OIDC_DB_DEPLOYMENT_SUFFIX;
}

public static SecretKeySelector getUsernameSecretKeySelector(Trustify cr) {
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 KeycloakDBDeploymentDiscriminator implements ResourceDiscriminator<
public Optional<Deployment> distinguish(Class<Deployment> resource, Trustify cr, Context<Trustify> context) {
String deploymentName = KeycloakDBDeployment.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 @@ -18,7 +18,7 @@
public class KeycloakDBPersistentVolumeClaim extends CRUDKubernetesDependentResource<PersistentVolumeClaim, Trustify>
implements Creator<PersistentVolumeClaim, Trustify> {

public static final String LABEL_SELECTOR = "app.kubernetes.io/managed-by=trustify-operator,component=oidc";
public static final String LABEL_SELECTOR = "app.kubernetes.io/managed-by=trustify-operator,component=keycloak";

public KeycloakDBPersistentVolumeClaim() {
super(PersistentVolumeClaim.class);
Expand All @@ -35,14 +35,14 @@ private PersistentVolumeClaim newPersistentVolumeClaim(Trustify cr, Context<Trus
.getMandatory(Constants.CONTEXT_LABELS_KEY, Map.class);

String pvcStorageSize = CRDUtils.getValueFromSubSpec(cr.getSpec().databaseSpec(), TrustifySpec.DatabaseSpec::pvcSize)
.orElse(Constants.POSTGRESQL_PVC_SIZE);
.orElse(Constants.DEFAULT_PVC_SIZE);

return new PersistentVolumeClaimBuilder()
.withNewMetadata()
.withName(getPersistentVolumeClaimName(cr))
.withNamespace(cr.getMetadata().getNamespace())
.withLabels(labels)
.addToLabels("component", "oidc")
.addToLabels("component", "keycloak")
.withOwnerReferences(CRDUtils.getOwnerReference(cr))
.endMetadata()
.withSpec(new PersistentVolumeClaimSpecBuilder()
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 KeycloakDBPersistentVolumeClaimDiscriminator implements ResourceDis
public Optional<PersistentVolumeClaim> distinguish(Class<PersistentVolumeClaim> resource, Trustify cr, Context<Trustify> context) {
String persistentVolumeClaimName = KeycloakDBPersistentVolumeClaim.getPersistentVolumeClaimName(cr);
ResourceID resourceID = new ResourceID(persistentVolumeClaimName, cr.getMetadata().getNamespace());
var informerEventSource = (InformerEventSource<PersistentVolumeClaim, Trustify>) context.eventSourceRetriever().getResourceEventSourceFor(PersistentVolumeClaim.class);
var informerEventSource = (InformerEventSource<PersistentVolumeClaim, Trustify>) context.eventSourceRetriever().getResourceEventSourceFor(PersistentVolumeClaim.class, TrustifyReconciler.PVC_EVENT_SOURCE);
return informerEventSource.get(resourceID);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,21 @@
import io.javaoperatorsdk.operator.api.reconciler.Context;
import io.javaoperatorsdk.operator.processing.dependent.Creator;
import io.javaoperatorsdk.operator.processing.dependent.kubernetes.CRUDKubernetesDependentResource;
import io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependent;
import jakarta.enterprise.context.ApplicationScoped;
import org.trustify.operator.Constants;
import org.trustify.operator.cdrs.v2alpha1.Trustify;
import org.trustify.operator.cdrs.v2alpha1.db.DBSecret;
import org.trustify.operator.utils.CRDUtils;

import java.util.Map;
import java.util.Random;

@KubernetesDependent(labelSelector = KeycloakDBSecret.LABEL_SELECTOR, resourceDiscriminator = KeycloakDBSecretDiscriminator.class)
@ApplicationScoped
public class KeycloakDBSecret extends CRUDKubernetesDependentResource<Secret, Trustify> implements Creator<Secret, Trustify> {

public static final String LABEL_SELECTOR = "app.kubernetes.io/managed-by=trustify-operator,component=keycloak";

public KeycloakDBSecret() {
super(Secret.class);
}
Expand All @@ -42,6 +45,7 @@ private Secret newSecret(Trustify cr, Context<Trustify> context) {
.withName(getSecretName(cr))
.withNamespace(cr.getMetadata().getNamespace())
.withLabels(labels)
.addToLabels("component", "keycloak")
.withOwnerReferences(CRDUtils.getOwnerReference(cr))
.endMetadata()
.addToStringData(Constants.DB_SECRET_USERNAME, generateRandomString(10))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.trustify.operator.cdrs.v2alpha1.keycloak;

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 KeycloakDBSecretDiscriminator implements ResourceDiscriminator<Secret, Trustify> {
@Override
public Optional<Secret> distinguish(Class<Secret> resource, Trustify cr, Context<Trustify> context) {
String secret = KeycloakDBSecret.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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
@ApplicationScoped
public class KeycloakDBService extends CRUDKubernetesDependentResource<Service, Trustify> {

public static final String LABEL_SELECTOR = "app.kubernetes.io/managed-by=trustify-operator,component=db";
public static final String LABEL_SELECTOR = "app.kubernetes.io/managed-by=trustify-operator,component=keycloak";

public KeycloakDBService() {
super(Service.class);
Expand All @@ -39,7 +39,7 @@ private Service newService(Trustify cr, Context<Trustify> context) {
.withName(getServiceName(cr))
.withNamespace(cr.getMetadata().getNamespace())
.withLabels(labels)
.addToLabels("component", "db")
.addToLabels("component", "keycloak")
.withOwnerReferences(CRDUtils.getOwnerReference(cr))
.endMetadata()
.withSpec(getServiceSpec(cr))
Expand All @@ -58,7 +58,7 @@ private ServiceSpec getServiceSpec(Trustify cr) {
}

public static String getServiceName(Trustify cr) {
return cr.getMetadata().getName() + Constants.DB_SERVICE_SUFFIX;
return cr.getMetadata().getName() + Constants.OIDC_DB_SERVICE_SUFFIX;
}

}
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 KeycloakDBServiceDiscriminator implements ResourceDiscriminator<Ser
public Optional<Service> distinguish(Class<Service> resource, Trustify cr, Context<Trustify> context) {
String serviceName = KeycloakDBService.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
@@ -1,6 +1,7 @@
package org.trustify.operator.controllers;

import io.fabric8.kubernetes.api.model.PersistentVolumeClaim;
import io.fabric8.kubernetes.api.model.Secret;
import io.fabric8.kubernetes.api.model.Service;
import io.fabric8.kubernetes.api.model.apps.Deployment;
import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration;
Expand All @@ -12,8 +13,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.keycloak.KeycloakDBPersistentVolumeClaim;
import org.trustify.operator.cdrs.v2alpha1.keycloak.KeycloakDBPersistentVolumeClaimActivationCondition;
import org.trustify.operator.cdrs.v2alpha1.keycloak.*;
import org.trustify.operator.cdrs.v2alpha1.server.*;

import java.time.Duration;
Expand All @@ -25,29 +25,26 @@
namespaces = WATCH_CURRENT_NAMESPACE,
name = "trustify",
dependents = {
// OIDC
@Dependent(
name = "oidc-db-pvc",
name = "keycloak-db-pvc",
type = KeycloakDBPersistentVolumeClaim.class,
activationCondition = KeycloakDBPersistentVolumeClaimActivationCondition.class,
useEventSourceWithName = TrustifyReconciler.PVC_EVENT_SOURCE
activationCondition = KeycloakDBPersistentVolumeClaimActivationCondition.class
),
@Dependent(
name = "oidc-db-secret",
name = "keycloak-db-secret",
type = KeycloakDBSecret.class,
activationCondition = KeycloakDBSecretActivationCondition.class
),
@Dependent(
name = "oidc-db-deployment",
name = "keycloak-db-deployment",
type = KeycloakDBDeployment.class,
dependsOn = {"db-pvc", "db-secret"},
readyPostcondition = KeycloakDBDeployment.class,
activationCondition = KeycloakDBDeploymentActivationCondition.class
),
@Dependent(
name = "oidc-db-service",
name = "keycloak-db-service",
type = KeycloakDBService.class,
dependsOn = {"oidc-db-deployment"},
activationCondition = KeycloakDBServiceActivationCondition.class
),

Expand All @@ -71,28 +68,27 @@
@Dependent(
name = "db-service",
type = DBService.class,
dependsOn = {"db-deployment"},
activationCondition = DBServiceActivationCondition.class
),

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

@Dependent(
name = "ingress",
type = ServerIngress.class,
dependsOn = {"server-service"},
readyPostcondition = ServerIngress.class
)
}
Expand All @@ -102,6 +98,7 @@ public class TrustifyReconciler implements Reconciler<Trustify>, ContextInitiali
private static final Logger logger = Logger.getLogger(TrustifyReconciler.class);

public static final String PVC_EVENT_SOURCE = "pcvSource";
public static final String SECRET_EVENT_SOURCE = "secretSource";
public static final String DEPLOYMENT_EVENT_SOURCE = "deploymentSource";
public static final String SERVICE_EVENT_SOURCE = "serviceSource";

Expand Down Expand Up @@ -150,15 +147,18 @@ public UpdateControl<Trustify> reconcile(Trustify cr, Context context) {
@Override
public Map<String, EventSource> prepareEventSources(EventSourceContext<Trustify> context) {
var pcvInformerConfiguration = InformerConfiguration.from(PersistentVolumeClaim.class, context).build();
var secretInformerConfiguration = InformerConfiguration.from(Secret.class, context).build();
var deploymentInformerConfiguration = InformerConfiguration.from(Deployment.class, context).build();
var serviceInformerConfiguration = InformerConfiguration.from(Service.class, context).build();

var pcvInformerEventSource = new InformerEventSource<>(pcvInformerConfiguration, context);
var secretInformerEventSource = new InformerEventSource<>(secretInformerConfiguration, context);
var deploymentInformerEventSource = new InformerEventSource<>(deploymentInformerConfiguration, context);
var serviceInformerEventSource = new InformerEventSource<>(serviceInformerConfiguration, context);

return Map.of(
PVC_EVENT_SOURCE, pcvInformerEventSource,
SECRET_EVENT_SOURCE, secretInformerEventSource,
DEPLOYMENT_EVENT_SOURCE, deploymentInformerEventSource,
SERVICE_EVENT_SOURCE, serviceInformerEventSource
);
Expand Down

0 comments on commit 08d639f

Please sign in to comment.