Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore build time properties when mapping system properties #183

Merged
merged 1 commit into from
Feb 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import java.util.Scanner;
import java.util.Set;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -49,6 +50,7 @@
public class HelmProcessor {
private static final Logger LOGGER = Logger.getLogger(HelmProcessor.class);
private static final String NAME_FORMAT_REG_EXP = "[a-z0-9]([-a-z0-9]*[a-z0-9])?(\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*";
private static final String BUILD_TIME_PROPERTIES = "/build-time-list";

private static final String QUARKUS_KUBERNETES_NAME = "quarkus.kubernetes.name";
private static final String QUARKUS_KNATIVE_NAME = "quarkus.knative.name";
Expand All @@ -60,18 +62,21 @@ public class HelmProcessor {
private static final String PROPERTIES_CONFIG_SOURCE = "PropertiesConfigSource";
private static final String SYSTEM_PROPERTY_START = "${";
private static final String SYSTEM_PROPERTY_END = "}";
// Lazy loaded when calling `isBuildTimeProperty(xxx)`.
private static Set<String> buildProperties;

@BuildStep(onlyIf = { HelmEnabled.class, IsNormal.class })
void mapSystemPropertiesIfEnabled(Capabilities capabilities, ApplicationInfoBuildItem info, HelmChartConfig helmConfig,
BuildProducer<DecoratorBuildItem> decorators) {
if (helmConfig.mapSystemProperties) {
String deploymentName = getDeploymentName(capabilities, info);

Config config = ConfigProvider.getConfig();
config.getPropertyNames().forEach(propName -> {
for (String propName : config.getPropertyNames()) {
ConfigValue propValue = config.getConfigValue(propName);
String rawValue = propValue.getRawValue();
if (isPropertiesConfigSource(propValue.getSourceName()) && isSystemProperty(rawValue)) {
if (isPropertiesConfigSource(propValue.getSourceName())
&& isSystemProperty(rawValue)
&& !isBuildTimeProperty(propValue.getName())) {
while (isSystemProperty(rawValue)) {
int start = rawValue.indexOf(SYSTEM_PROPERTY_START);
int end = rawValue.indexOf(SYSTEM_PROPERTY_END, start);
Expand All @@ -89,7 +94,7 @@ void mapSystemPropertiesIfEnabled(Capabilities capabilities, ApplicationInfoBuil
rawValue = rawValue.substring(end + SYSTEM_PROPERTY_END.length());
}
}
});
}
}
}

Expand Down Expand Up @@ -415,6 +420,26 @@ private boolean isPropertiesConfigSource(String sourceName) {
return Strings.isNotNullOrEmpty(sourceName) && sourceName.startsWith(PROPERTIES_CONFIG_SOURCE);
}

private boolean isBuildTimeProperty(String name) {
if (buildProperties == null) {
buildProperties = new HashSet<>();
try {
Scanner scanner = new Scanner(new File(HelmProcessor.class.getResource(BUILD_TIME_PROPERTIES).getFile()));
while (scanner.hasNextLine()) {
buildProperties.add(scanner.nextLine());
}
} catch (Exception e) {
LOGGER.debugf("Can't read the build time properties file at '%s'. Caused by: %s",
BUILD_TIME_PROPERTIES,
e.getMessage());
}
}

return buildProperties.stream().anyMatch(build -> name.matches(build) // It's a regular expression
|| (build.endsWith(".") && name.startsWith(build)) // contains with
|| name.equals(build)); // or it's equal to
}

private boolean isSystemProperty(String rawValue) {
return Strings.isNotNullOrEmpty(rawValue) && rawValue.contains(SYSTEM_PROPERTY_START);
}
Expand Down
97 changes: 97 additions & 0 deletions deployment/src/main/resources/build-time-list
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# List of properties that will trigger a full build of a Quarkus application
# regular expression or start with
quarkus.amqp.devservices.enabled
quarkus.apicurio-registry.devservices.enabled
quarkus.artemis.health.enabled
quarkus.cache.enabled
quarkus.datasource.db-kind
quarkus.datasource.devservices.enabled
quarkus.datasource.devservices.image-name
quarkus.datasource.devservices.port
quarkus.datasource.devservices.properties
quarkus.datasource.health-exclude
quarkus.datasource.jdbc
quarkus.datasource.jdbc.driver
quarkus.datasource.jdbc.enable-metrics
quarkus.datasource.jdbc.transactions
quarkus.datasource.reactive
quarkus.datasource.(.+).db-kind
quarkus.datasource.(.+).devservices.enabled
quarkus.datasource.(.+).devservices.image-name
quarkus.datasource.(.+).devservices.port
quarkus.datasource.(.+).devservices.properties
quarkus.datasource.(.+).health-exclude
quarkus.datasource.(.+).jdbc
quarkus.datasource.(.+).jdbc.driver
quarkus.datasource.(.+).jdbc.enable-metrics
quarkus.datasource.(.+).jdbc.transactions
quarkus.datasource.(.+).reactive
quarkus.elasticsearch.health.enabled
quarkus.grpc.metrics.enabled
quarkus.grpc.server.grpc-health.enabled
quarkus.grpc.server.health.enabled
quarkus.health.extensions.enabled
quarkus.hibernate-orm.
quarkus.hibernate-orm.metrics.enabled
quarkus.http.auth.form.enabled
quarkus.http.auth.permission.(.+).enabled
quarkus.http.non-application-root-path
quarkus.http.redirect-to-non-application-root-path
quarkus.http.root-path
quarkus.http.ssl.client-auth
quarkus.jaeger.enabled
quarkus.jaeger.metrics.enabled
quarkus.kafka-streams.health.enabled
quarkus.kafka.devservices.enabled
quarkus.kafka.health.enabled
quarkus.kafka.snappy.enabled
quarkus.keycloak.devservices.enabled
quarkus.kubernetes-config.secrets.enabled
quarkus.kubernetes.
quarkus.micrometer.binder.http-client.enabled
quarkus.micrometer.binder.http-server.enabled
quarkus.micrometer.binder.kafka.enabled
quarkus.micrometer.binder.mp-metrics.enabled
quarkus.micrometer.binder.vertx.enabled
quarkus.micrometer.enabled
quarkus.micrometer.export.json.enabled
quarkus.micrometer.export.prometheus.enabled
quarkus.mongodb.devservices.enabled
quarkus.mongodb.health.enabled
quarkus.mongodb.metrics.enabled
quarkus.mongodb.tracing.enabled
quarkus.native.debug.enabled
quarkus.neo4j.health.enabled
quarkus.oauth2.enabled
quarkus.oidc-client.enabled
quarkus.oidc-token-propagation.enabled
quarkus.oidc.enabled
quarkus.openshift.
quarkus.opentelemetry.enabled
quarkus.opentelemetry.tracer.enabled
quarkus.opentelemetry.tracer.exporter.jaeger.enabled
quarkus.opentelemetry.tracer.exporter.otlp.enabled
quarkus.package.type
quarkus.reactive-messaging.health.enabled
quarkus.reactive-messaging.kafka.serializer-autodetection.enabled
quarkus.reactive-messaging.metrics.enabled
quarkus.redis.devservices.enabled
quarkus.redis.health.enabled
quarkus.resteasy.gzip.enabled
quarkus.resteasy.metrics.enabled
quarkus.security.jdbc.enabled
quarkus.security.ldap.enabled
quarkus.security.users.embedded.enabled
quarkus.security.users.file.enabled
quarkus.smallrye-graphql.events.enabled
quarkus.smallrye-graphql.http.get.enabled
quarkus.smallrye-graphql.http.post.queryparameters.enabled
quarkus.smallrye-graphql.metrics.enabled
quarkus.smallrye-graphql.tracing.enabled
quarkus.smallrye-graphql.validation.enabled
quarkus.smallrye-jwt.enabled
quarkus.smallrye-metrics.extensions.enabled
quarkus.smallrye-metrics.jaxrs.enabled
quarkus.ssl.native
quarkus.vault.devservices.enabled
quarkus.vault.health.enabled
2 changes: 1 addition & 1 deletion docs/modules/ROOT/pages/includes/attributes.adoc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
:quarkus-version: 2.16.2.Final
:quarkus-version: 2.16.3.Final
:quarkus-helm-version: 0.2.6
:maven-version: 3.8.1+

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,6 @@ quarkus.helm.values.host.value=override-host-in-helm
# Resteasy Reactive
quarkus.resteasy-reactive.path=${OVERRIDE_PATH}
quarkus.host.port=${OVERRIDE_PORT:8080}
quarkus.host.name=something:${OVERRIDE_PART1}-${OVERRIDE_PART2:default}
quarkus.host.name=something:${OVERRIDE_PART1}-${OVERRIDE_PART2:default}
## this should be ignored
quarkus.kubernetes.annotations.\"app.quarkus.io/vcs-url\"=${BUILD_TIME_PROPERTY}
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ public void valuesShouldContainExpectedData() throws IOException {
// Should contain system property OVERRIDE_PORT which value is specified
// using "quarkus.kubernetes.env.vars.OVERRIDE_PORT=8081"
assertEquals("8081", envs.get("OVERRIDE_PORT"));
// Build time properties should not be mapped
assertNull(envs.get("BUILD_TIME_PROPERTY"));
}

@Test
Expand Down