-
Notifications
You must be signed in to change notification settings - Fork 271
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feat/operator-pod-disruption
- Loading branch information
Showing
35 changed files
with
922 additions
and
120 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
73 changes: 73 additions & 0 deletions
73
operator/controller/src/main/java/io/apicurio/registry/operator/feat/Cors.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,73 @@ | ||
package io.apicurio.registry.operator.feat; | ||
|
||
import io.apicurio.registry.operator.EnvironmentVariables; | ||
import io.apicurio.registry.operator.api.v1.ApicurioRegistry3; | ||
import io.apicurio.registry.operator.api.v1.ApicurioRegistry3Spec; | ||
import io.apicurio.registry.operator.api.v1.spec.ComponentSpec; | ||
import io.apicurio.registry.operator.resource.ResourceFactory; | ||
import io.apicurio.registry.operator.utils.IngressUtils; | ||
import io.fabric8.kubernetes.api.model.EnvVar; | ||
import io.fabric8.kubernetes.api.model.EnvVarBuilder; | ||
|
||
import java.util.Arrays; | ||
import java.util.LinkedHashMap; | ||
import java.util.Optional; | ||
import java.util.Set; | ||
import java.util.TreeSet; | ||
|
||
/** | ||
* Helper class used to handle CORS related configuration. | ||
*/ | ||
public class Cors { | ||
/** | ||
* Configure the QUARKUS_HTTP_CORS_ORIGINS environment variable with the following: | ||
* <ul> | ||
* <li>Add the ingress host</li> | ||
* <li>Override if QUARKUS_HTTP_CORS_ORIGINS is configured in the "env" section</li> | ||
* </ul> | ||
* | ||
* @param primary | ||
* @param envVars | ||
*/ | ||
public static void configureAllowedOrigins(ApicurioRegistry3 primary, | ||
LinkedHashMap<String, EnvVar> envVars) { | ||
TreeSet<String> allowedOrigins = new TreeSet<>(); | ||
|
||
// If the QUARKUS_HTTP_CORS_ORIGINS env var is configured in the "env" section of the CR, | ||
// then make sure to add those configured values to the set of allowed origins we want to | ||
// configure. | ||
Optional.ofNullable(primary.getSpec()).map(ApicurioRegistry3Spec::getApp).map(ComponentSpec::getEnv) | ||
.ifPresent(env -> { | ||
env.stream().filter( | ||
envVar -> envVar.getName().equals(EnvironmentVariables.QUARKUS_HTTP_CORS_ORIGINS)) | ||
.forEach(envVar -> { | ||
Optional.ofNullable(envVar.getValue()).ifPresent(envVarValue -> { | ||
Arrays.stream(envVarValue.split(",")).forEach(allowedOrigins::add); | ||
}); | ||
}); | ||
}); | ||
|
||
// If not, let's try to figure it out from other sources. | ||
if (allowedOrigins.isEmpty()) { | ||
// If there is a configured Ingress host for the UI or the Studio UI, add them to the allowed | ||
// origins. | ||
Set.of(ResourceFactory.COMPONENT_UI, ResourceFactory.COMPONENT_STUDIO_UI).forEach(component -> { | ||
String host = IngressUtils.getConfiguredHost(component, primary); | ||
if (host != null) { | ||
allowedOrigins.add("http://" + host); | ||
allowedOrigins.add("https://" + host); | ||
} | ||
}); | ||
} | ||
|
||
// If we still do not have anything, then default to "*" | ||
if (allowedOrigins.isEmpty()) { | ||
allowedOrigins.add("*"); | ||
} | ||
|
||
// Join the values in allowedOrigins into a String and set it as the new value of the env var. | ||
String envVarValue = String.join(",", allowedOrigins); | ||
envVars.put(EnvironmentVariables.QUARKUS_HTTP_CORS_ORIGINS, new EnvVarBuilder() | ||
.withName(EnvironmentVariables.QUARKUS_HTTP_CORS_ORIGINS).withValue(envVarValue).build()); | ||
} | ||
} |
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
80 changes: 80 additions & 0 deletions
80
operator/controller/src/main/java/io/apicurio/registry/operator/feat/KafkaSqlTLS.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,80 @@ | ||
package io.apicurio.registry.operator.feat; | ||
|
||
import io.apicurio.registry.operator.api.v1.ApicurioRegistry3; | ||
import io.apicurio.registry.operator.api.v1.ApicurioRegistry3Spec; | ||
import io.apicurio.registry.operator.api.v1.spec.AppSpec; | ||
import io.apicurio.registry.operator.api.v1.spec.KafkaSqlSpec; | ||
import io.apicurio.registry.operator.api.v1.spec.KafkaSqlTLSSpec; | ||
import io.apicurio.registry.operator.api.v1.spec.StorageSpec; | ||
import io.apicurio.registry.operator.utils.SecretKeyRefTool; | ||
import io.fabric8.kubernetes.api.model.EnvVar; | ||
import io.fabric8.kubernetes.api.model.apps.Deployment; | ||
|
||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
import static io.apicurio.registry.operator.EnvironmentVariables.*; | ||
import static io.apicurio.registry.operator.resource.app.AppDeploymentResource.addEnvVar; | ||
import static java.util.Optional.ofNullable; | ||
|
||
public class KafkaSqlTLS { | ||
|
||
/** | ||
* Plain KafkaSQL must be already configured. | ||
*/ | ||
public static boolean configureKafkaSQLTLS(ApicurioRegistry3 primary, Deployment deployment, | ||
String containerName, Map<String, EnvVar> env) { | ||
|
||
// spotless:off | ||
var keystore = new SecretKeyRefTool(getKafkaSqlTLSSpec(primary) | ||
.map(KafkaSqlTLSSpec::getKeystoreSecretRef) | ||
.orElse(null), "user.p12"); | ||
|
||
var keystorePassword = new SecretKeyRefTool(getKafkaSqlTLSSpec(primary) | ||
.map(KafkaSqlTLSSpec::getKeystorePasswordSecretRef) | ||
.orElse(null), "user.password"); | ||
|
||
var truststore = new SecretKeyRefTool(getKafkaSqlTLSSpec(primary) | ||
.map(KafkaSqlTLSSpec::getTruststoreSecretRef) | ||
.orElse(null), "ca.p12"); | ||
|
||
var truststorePassword = new SecretKeyRefTool(getKafkaSqlTLSSpec(primary) | ||
.map(KafkaSqlTLSSpec::getTruststorePasswordSecretRef) | ||
.orElse(null), "ca.password"); | ||
// spotless:on | ||
|
||
if (truststore.isValid() && truststorePassword.isValid() && keystore.isValid() | ||
&& keystorePassword.isValid()) { | ||
|
||
addEnvVar(env, KAFKASQL_SECURITY_PROTOCOL, "SSL"); | ||
|
||
// ===== Keystore | ||
|
||
addEnvVar(env, KAFKASQL_SSL_KEYSTORE_TYPE, "PKCS12"); | ||
keystore.applySecretVolume(deployment, containerName); | ||
addEnvVar(env, KAFKASQL_SSL_KEYSTORE_LOCATION, keystore.getSecretVolumeKeyPath()); | ||
keystorePassword.applySecretEnvVar(env, KAFKASQL_SSL_KEYSTORE_PASSWORD); | ||
|
||
// ===== Truststore | ||
|
||
addEnvVar(env, KAFKASQL_SSL_TRUSTSTORE_TYPE, "PKCS12"); | ||
truststore.applySecretVolume(deployment, containerName); | ||
addEnvVar(env, KAFKASQL_SSL_TRUSTSTORE_LOCATION, truststore.getSecretVolumeKeyPath()); | ||
truststorePassword.applySecretEnvVar(env, KAFKASQL_SSL_TRUSTSTORE_PASSWORD); | ||
|
||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
private static Optional<KafkaSqlTLSSpec> getKafkaSqlTLSSpec(ApicurioRegistry3 primary) { | ||
// spotless:off | ||
return ofNullable(primary) | ||
.map(ApicurioRegistry3::getSpec) | ||
.map(ApicurioRegistry3Spec::getApp) | ||
.map(AppSpec::getStorage) | ||
.map(StorageSpec::getKafkasql) | ||
.map(KafkaSqlSpec::getTls); | ||
// spotless:on | ||
} | ||
} |
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
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
Oops, something went wrong.