Skip to content

Commit

Permalink
Fix runtime config properties recording in OpenShift
Browse files Browse the repository at this point in the history
  • Loading branch information
michalvavrik committed Apr 21, 2024
1 parent 2cf7d6f commit 25cf512
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,10 @@ 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));
}
}
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

0 comments on commit 25cf512

Please sign in to comment.