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

Fix runtime config properties recording in OpenShift #1094

Merged
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 @@ -3,6 +3,7 @@
import static java.util.regex.Pattern.quote;

import java.lang.annotation.Annotation;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ServiceLoader;

Expand Down Expand Up @@ -91,4 +92,18 @@ protected Path getApplicationFolder() {

return appFolder;
}

@Override
protected void copyResourcesInFolderToAppFolder(Path folder) {
// normal apps will create application.properties from parent folder but our source is git project
super.copyResourcesInFolderToAppFolder(getApplicationFolder().resolve(folder));
}

@Override
protected void copyResourcesToAppFolder() {
// app folder may not exist when S2I scenario use OpenShift build strategy where we do not clone git project
if (Files.exists(getApplicationFolder())) {
super.copyResourcesToAppFolder();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ private boolean isBuildProperty(String name) {
|| name.equals(build)); // or it's equal to
}

private void copyResourcesInFolderToAppFolder(Path folder) {
protected void copyResourcesInFolderToAppFolder(Path folder) {
try (Stream<Path> binariesFound = Files
.find(folder, Integer.MAX_VALUE,
(path, basicFileAttributes) -> !Files.isDirectory(path))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import static io.quarkus.test.utils.MavenUtils.withProperty;
import static org.junit.jupiter.api.Assertions.fail;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
Expand Down Expand Up @@ -50,7 +51,7 @@ public class ExtensionOpenShiftQuarkusApplicationManagedResource
private static final String KNATIVE = "knative";
private static final String QUARKUS_KUBERNETES_DEPLOYMENT_TARGET_OPENSHIFT = String.format("-D%s=%s",
QUARKUS_KUBERNETES_DEPLOYMENT_TARGET, OPENSHIFT);
private static final Path RESOURCES_FOLDER = Paths.get("src", "main", "resources", "application.properties");
private static final Path APPLICATION_PROPERTIES_PATH = Paths.get("src", "main", "resources", "application.properties");

public ExtensionOpenShiftQuarkusApplicationManagedResource(ProdQuarkusApplicationManagedResourceBuilder model) {
super(model);
Expand All @@ -59,7 +60,7 @@ public ExtensionOpenShiftQuarkusApplicationManagedResource(ProdQuarkusApplicatio
@Override
protected void doInit() {
cloneProjectToServiceAppFolder();
copyBuildPropertiesIntoAppFolder();
copyComputedPropertiesIntoAppFolder();
deployProjectUsingMavenCommand();
exposeManagementRoute();
}
Expand Down Expand Up @@ -101,19 +102,32 @@ protected void withAdditionalArguments(List<String> args) {

}

private void copyBuildPropertiesIntoAppFolder() {
Map<String, String> buildProperties = model.getBuildProperties();
if (buildProperties.isEmpty()) {
return;
private void copyComputedPropertiesIntoAppFolder() {
// always copy computed properties to app folder as system properties are not propagated to OpenShift
Path computedPropertiesPath = model.getComputedApplicationProperties();
if (Files.exists(computedPropertiesPath)) {
var computedProperties = PropertiesUtils.toMap(computedPropertiesPath);
if (!computedProperties.isEmpty()) {
Path appPropertiesPath = model.getApplicationFolder().resolve(APPLICATION_PROPERTIES_PATH);
createApplicationPropertiesIfNotExists(appPropertiesPath);
PropertiesUtils.fromMap(computedProperties, appPropertiesPath);
}
}
model.createSnapshotOfBuildProperties();
}

Path applicationPropertiesPath = model.getComputedApplicationProperties();
if (Files.exists(applicationPropertiesPath)) {
buildProperties.putAll(PropertiesUtils.toMap(applicationPropertiesPath));
private static void createApplicationPropertiesIfNotExists(Path appPropertiesPath) {
if (!Files.exists(appPropertiesPath)) {
if (!Files.exists(appPropertiesPath.getParent())) {
appPropertiesPath.getParent().toFile().mkdirs();
}
try {
appPropertiesPath.toFile().createNewFile();
} catch (IOException e) {
throw new RuntimeException(
"Failed to create application properties file at path: '%s'".formatted(appPropertiesPath), e);
}
}

PropertiesUtils.fromMap(buildProperties, getContext().getServiceFolder().resolve(RESOURCES_FOLDER));
model.createSnapshotOfBuildProperties();
}

private void deployProjectUsingMavenCommand() {
Expand Down