Skip to content

Commit

Permalink
feat: add oidc (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosthe19916 authored Nov 8, 2024
1 parent c1d5c42 commit 29ff442
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ public record TrustifySpec(
@JsonPropertyDescription("In this section you can configure features related to HTTP and HTTPS")
HttpSpec httpSpec,

@JsonProperty("oidc")
@JsonPropertyDescription("In this section you can configure Oidc settings.")
OidcSpec oidcSpec,

@JsonProperty("serverResourceLimits")
@JsonPropertyDescription("In this section you can configure resource limits settings for the Server.")
ResourcesLimitSpec serverResourceLimitSpec
Expand All @@ -46,6 +50,7 @@ public TrustifySpec() {
null,
null,
null,
null,
null
);
}
Expand Down Expand Up @@ -89,6 +94,18 @@ public record HttpSpec(
) {
}

public record OidcSpec(
@JsonPropertyDescription("Enable Oidc Auth.")
boolean enabled,
@JsonPropertyDescription("Oidc server url.")
String serverUrl,
@JsonPropertyDescription("Oidc client id for the UI.")
String uiClientId,
@JsonPropertyDescription("Oidc client id for the Server.")
String serverClientId
) {
}

public record ResourcesLimitSpec(
@JsonPropertyDescription("Requested CPU.")
String cpuRequest,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class ServerDeploymentDiscriminator implements ResourceDiscriminator<Depl
public Optional<Deployment> distinguish(Class<Deployment> resource, Trustify cr, Context<Trustify> context) {
String deploymentName = ServerDeployment.getDeploymentName(cr);
ResourceID resourceID = new ResourceID(deploymentName, cr.getMetadata().getNamespace());
var informerEventSource = (InformerEventSource<Deployment, Trustify>) context.eventSourceRetriever().getResourceEventSourceFor(Deployment.class, TrustifyReconciler.SERVER_DEPLOYMENT_EVENT_SOURCE);
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 @@ -15,7 +15,7 @@ public class ServerServiceDiscriminator implements ResourceDiscriminator<Service
public Optional<Service> distinguish(Class<Service> resource, Trustify cr, Context<Trustify> context) {
String serviceName = ServerService.getServiceName(cr);
ResourceID resourceID = new ResourceID(serviceName, cr.getMetadata().getNamespace());
var informerEventSource = (InformerEventSource<Service, Trustify>) context.eventSourceRetriever().getResourceEventSourceFor(Service.class, TrustifyReconciler.SERVER_SERVICE_EVENT_SOURCE);
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 @@ -146,9 +146,21 @@ private void configureStorage() {
}

private void configureOidc() {
List<EnvVar> envVars = optionMapper(cr.getSpec())
.mapOption("AUTH_DISABLED", spec -> true)
.getEnvVars();
List<EnvVar> envVars = Optional.ofNullable(cr.getSpec().oidcSpec())
.map(oidcSpec -> optionMapper(oidcSpec)
.mapOption("AUTH_DISABLED", spec -> !spec.enabled())
.mapOption("AUTHENTICATOR_OIDC_ISSUER_URL", TrustifySpec.OidcSpec::serverUrl)
.mapOption("AUTHENTICATOR_OIDC_CLIENT_IDS", TrustifySpec.OidcSpec::serverClientId)
.mapOption("UI_ISSUER_URL", TrustifySpec.OidcSpec::serverUrl)
.mapOption("UI_CLIENT_ID", TrustifySpec.OidcSpec::uiClientId)
.getEnvVars()
)
.orElseGet(() -> List.of(new EnvVarBuilder()
.withName("AUTH_DISABLED")
.withValue(Boolean.TRUE.toString())
.build())
);

allEnvVars.addAll(envVars);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.trustify.operator.controllers;

import io.fabric8.kubernetes.api.model.PersistentVolumeClaim;
import io.fabric8.kubernetes.api.model.Service;
import io.fabric8.kubernetes.api.model.apps.Deployment;
import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration;
Expand Down Expand Up @@ -53,13 +54,13 @@
type = ServerDeployment.class,
// dependsOn = {"db-service"},
readyPostcondition = ServerDeployment.class,
useEventSourceWithName = "server-deployment"
useEventSourceWithName = TrustifyReconciler.DEPLOYMENT_EVENT_SOURCE
),
@Dependent(
name = "server-service",
type = ServerService.class,
dependsOn = {"server-deployment"},
useEventSourceWithName = "server-service"
useEventSourceWithName = TrustifyReconciler.SERVICE_EVENT_SOURCE
),

@Dependent(
Expand All @@ -74,8 +75,8 @@ public class TrustifyReconciler implements Reconciler<Trustify>, ContextInitiali

private static final Logger logger = Logger.getLogger(TrustifyReconciler.class);

public static final String SERVER_DEPLOYMENT_EVENT_SOURCE = "server-deployment";
public static final String SERVER_SERVICE_EVENT_SOURCE = "server-service";
public static final String DEPLOYMENT_EVENT_SOURCE = "deploymentSource";
public static final String SERVICE_EVENT_SOURCE = "serviceSource";

@Override
public void initContext(Trustify cr, Context<Trustify> context) {
Expand Down Expand Up @@ -121,15 +122,15 @@ public UpdateControl<Trustify> reconcile(Trustify cr, Context context) {

@Override
public Map<String, EventSource> prepareEventSources(EventSourceContext<Trustify> context) {
var serverDeploymentInformerConfiguration = InformerConfiguration.from(Deployment.class, context).build();
var serverServiceInformerConfiguration = InformerConfiguration.from(Service.class, context).build();
var deploymentInformerConfiguration = InformerConfiguration.from(Deployment.class, context).build();
var serviceInformerConfiguration = InformerConfiguration.from(Service.class, context).build();

var serverDeploymentInformerEventSource = new InformerEventSource<>(serverDeploymentInformerConfiguration, context);
var serverServiceInformerEventSource = new InformerEventSource<>(serverServiceInformerConfiguration, context);
var deploymentInformerEventSource = new InformerEventSource<>(deploymentInformerConfiguration, context);
var serviceInformerEventSource = new InformerEventSource<>(serviceInformerConfiguration, context);

return Map.of(
SERVER_DEPLOYMENT_EVENT_SOURCE, serverDeploymentInformerEventSource,
SERVER_SERVICE_EVENT_SOURCE, serverServiceInformerEventSource
DEPLOYMENT_EVENT_SOURCE, deploymentInformerEventSource,
SERVICE_EVENT_SOURCE, serviceInformerEventSource
);
}
}

0 comments on commit 29ff442

Please sign in to comment.