Skip to content

Commit

Permalink
update auto-change. update deployment for auto-change
Browse files Browse the repository at this point in the history
  • Loading branch information
mcanoy committed Aug 22, 2021
1 parent 54230d6 commit c8e8be3
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 75 deletions.
18 changes: 11 additions & 7 deletions deployment/templates/deploymentconfig.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,26 @@ spec:
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumeMounts:
{{- range $rConfig := .Values.runtimeConfigs }}
- name: {{ $rConfig.name }}-cm-volume
mountPath: {{ $rConfig.path }}/{{ $rConfig.file }}
subPath: {{ $rConfig.file }}
{{- range .Values.runtimeConfigs }}
- name: lodestar-runtime-{{ . }}-cm-volume
mountPath: {{ $.Values.baseConfigMapPath }}/{{ . }}
{{- end }}
- name: hook-cm-volume
mountPath: /hooks
dnsPolicy: ClusterFirst
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
terminationGracePeriodSeconds: 30
volumes:
{{- range $rConfig := .Values.runtimeConfigs }}
- name: {{ $rConfig.name }}-cm-volume
{{- range .Values.runtimeConfigs }}
- name: lodestar-runtime-{{ . }}-cm-volume
configMap:
name: {{ $rConfig.name }}-cm
name: lodestar-runtime-{{ . }}-cm
{{- end }}
- name: hook-cm-volume
configMap:
name: hook-cm
test: false
triggers:
- type: ConfigChange
Expand Down
4 changes: 2 additions & 2 deletions deployment/templates/runtime-config-cm.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{- if .Values.development }}
apiVersion: v1
data:
lodestar-runtime-config.yaml: |
lodestar-runtime-config-base.yaml: |
---
basic_information:
engagement_types:
Expand All @@ -25,5 +25,5 @@ data:
value: optionTwo
kind: ConfigMap
metadata:
name: lodestar-runtime-cm
name: lodestar-runtime-base-cm
{{- end }}
13 changes: 4 additions & 9 deletions deployment/values-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,8 @@ git:
uri: https://github.com/rht-labs/lodestar-config.git
ref: master

baseConfigMapPath: /runtime
runtimeConfigs:
- name: lodestar-runtime
file: lodestar-runtime-config.yaml
path: /runtime
- name: lodestar-runtime-one
file: lodestar-runtime-config-one.yaml
path: /runtime
- name: lodestar-runtime-two
file: lodestar-runtime-config-two.yaml
path: /runtime
- base
- one
- two
5 changes: 2 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
<maven.compiler.target>11</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<quarkus-plugin.version>2.1.3.Final</quarkus-plugin.version>
<quarkus.platform.artifact-id>quarkus-universe-bom</quarkus.platform.artifact-id>
<quarkus.platform.group-id>io.quarkus</quarkus.platform.group-id>
<quarkus.platform.version>2.1.3.Final</quarkus.platform.version>
Expand All @@ -23,7 +22,7 @@
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
<sonar.project.key>rht-labs_lodestar-config</sonar.project.key>
<sonar.organization>rht-labs</sonar.organization>
<sonar.jacoco.reportPath>target/jacoco-quarkus.exec</sonar.jacoco.reportPath>
<sonar.jacoco.reportPath>target/jacoco-quarkus.exec</sonar.jacoco.reportPath>
</properties>
<dependencyManagement>
<dependencies>
Expand Down Expand Up @@ -104,7 +103,7 @@
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
<version>${quarkus-plugin.version}</version>
<version>${quarkus.platform.version}</version>
<extensions>true</extensions>
<executions>
<execution>
Expand Down
11 changes: 7 additions & 4 deletions src/main/java/com/redhat/labs/lodestar/model/ConfigMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.FileTime;
import java.util.Optional;

import lombok.ToString;
Expand All @@ -29,12 +28,12 @@ public class ConfigMap {
private Optional<String> content = Optional.empty();

/**
* The last modified date is flakely in-container. Instead, read file
* The last modified date is flaky in-container. Instead, read file
* each time and update when changed. Limited reads via scheduler
* @return true if the content changed
*/
public boolean readAndUpdateMountedFile() {
String currentContent = content.isPresent() ? content.get() : "";
String currentContent = content.orElse("");

if (!checkPath()) {
LOGGER.warn("Unable to read file {}", filePath);
Expand All @@ -46,7 +45,11 @@ public boolean readAndUpdateMountedFile() {
content = Optional.of(newContent);
LOGGER.trace("content match ({}) = {} ", filePath, currentContent.equals(newContent));

return !currentContent.equals(newContent);
if(!currentContent.equals(newContent)) {
LOGGER.debug("Content changed for file path {}", filePath);
return true;
}

} catch (IOException e) {
LOGGER.error("Error updating mounted file %{} {} ", path, filePath);
content = Optional.empty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public void loadFromConfigMapIfChanged() {
}

public Map<String, Object> getConfiguration() {
return configuration;
return configuration;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,73 +11,48 @@
import org.junit.jupiter.api.Test;

import com.redhat.labs.lodestar.utils.ResourceLoader;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.NullSource;
import org.junit.jupiter.params.provider.ValueSource;

class ConfigServiceTest {

JsonbConfig config = new JsonbConfig().withFormatting(true);
Jsonb jsonb = JsonbBuilder.create(config);

@Test
void testGetBaseConfiguration() {
@ParameterizedTest
@NullSource
@ValueSource(strings = { "TypeOne", " TypeTwo", "TypeThree" })
void testGetBaseConfiguration(String type) {

String expected = ResourceLoader.load("expected/service-base-config.json");
String expected = ResourceLoader.load(getExpected(type == null ? "" : type));

RuntimeConfigService service = new RuntimeConfigService();
service.jsonb = jsonb;
service.runtimeBaseConfig = "src/test/resources/runtime-config-base.yaml";

service.createRuntimeConfigurations();

String configuration = service.getRuntimeConfiguration(Optional.empty());
assertEquals(expected, configuration);

}

@Test
void testGetTypeOneConfiguration() {

String expected = ResourceLoader.load("expected/service-get-type-one-config.json");

RuntimeConfigService service = new RuntimeConfigService();
service.jsonb = jsonb;
service.runtimeBaseConfig = "src/test/resources/runtime-config-base.yaml";
Optional configOption = Optional.ofNullable(type);

service.createRuntimeConfigurations();

String configuration = service.getRuntimeConfiguration(Optional.of("TypeOne"));
String configuration = service.getRuntimeConfiguration(configOption);
assertEquals(expected, configuration);

}

@Test
void testGetTypeTwoConfiguration() {
String expected = ResourceLoader.load("expected/service-get-type-two-config.json");

RuntimeConfigService service = new RuntimeConfigService();
service.jsonb = jsonb;
service.runtimeBaseConfig = "src/test/resources/runtime-config-base.yaml";

service.createRuntimeConfigurations();

String configuration = service.getRuntimeConfiguration(Optional.of("TypeTwo"));
assertEquals(expected, configuration);

}

@Test
void testGetTypeThreeConfigurationNotFound() {

String expected = ResourceLoader.load("expected/service-base-config.json");

RuntimeConfigService service = new RuntimeConfigService();
service.jsonb = jsonb;
service.runtimeBaseConfig = "src/test/resources/runtime-config-base.yaml";

service.createRuntimeConfigurations();

String configuration = service.getRuntimeConfiguration(Optional.of("TypeThree"));
assertEquals(expected, configuration);

private String getExpected(String type) {
String expected;
switch (type) {
case "TypeOne":
expected = "expected/service-get-type-one-config.json";
break;
case "TypeTwo":
expected = "expected/service-get-type-two-config.json";
break;
default:
expected = "expected/service-base-config.json";
}

return expected;
}

}

0 comments on commit c8e8be3

Please sign in to comment.