Skip to content

Commit 6d80d03

Browse files
authored
Merge pull request #82 from dwasinge/config
Read Config.yml from ConfigMap
2 parents 7635417 + 5babe3e commit 6d80d03

File tree

12 files changed

+197
-27
lines changed

12 files changed

+197
-27
lines changed

deployment/README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ helm template . \
3131
--values values-dev.yaml \
3232
--set git.uri=https://github.com/rht-labs/open-management-portal-git-api.git \
3333
--set git.ref=master \
34-
--set configFile=<your-config-file> \
3534
--set configRepositoryId=<your-config-repository-id> \
3635
--set deployKey=<your-gitlab-deploy-key-id> \
3736
--set gitLabApiUrl=<your-gitlab-base-url> \
@@ -46,11 +45,16 @@ It accepts the following variables
4645
|---|---|
4746
| `git.uri` | The HTTPS reference to the repo (your fork!) to build |
4847
| `git.ref` | The branch name to build |
49-
| `configFile` | The path including name of the config file |
5048
| `configRepositoryId` | The GitLab ID of the config repository |
5149
| `deployKey` | The ID of the GitLab deploy key to enable on newly-created repositories |
5250
| `gitLabApiUrl` | The base URL of the GitLab instance to use |
5351
| `gitLabPersonalAccessToken` | The access token to use to auth against GitLab |
5452
| `engagementsRepositoryId` | The ID of the GitLab group under which to create new projects |
5553

5654
This will spin up all of the usual resources that this service needs in production, plus a `BuildConfig` configured to build it from source from the Git repository specified. To trigger this build, use `oc start-build omp-git-api`.
55+
56+
## Config Map Configurations
57+
58+
Please note that there is a configuration for both, webhooks and the runtime configuration. These are provided as samples or subsets and will not be kept current with the values configured in the test/integration/production environments.
59+
60+
These ConfigMaps have already been configured and provided when deployed into the official OpenShift environments.
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
{{- if .Values.development }}
2+
apiVersion: v1
3+
data:
4+
lodestar-runtime-config.yaml: |
5+
---
6+
basic_information:
7+
project_name:
8+
validators:
9+
- kind: regex
10+
value: ^\w+[\w- ()]*$
11+
message: Only alphanumeric characters and spaces are allowed
12+
customer_name:
13+
validators:
14+
- kind: regex
15+
value: ^\w+[\w- ()]*$
16+
message: Only alphanumeric characters and spaces are allowed
17+
cloud_options:
18+
providers:
19+
options:
20+
- label: AWS
21+
value: ec2
22+
options:
23+
- label: US East 1 (N. Virginia)
24+
value: us-east-1
25+
- label: US East 2 (Ohio)
26+
value: us-east-2
27+
- label: US West 1 (N. California)
28+
value: us-west-1
29+
- label: US West 2 (Oregon)
30+
value: us-west-2
31+
- label: Other
32+
value: other
33+
options:
34+
- label: Other
35+
value: other
36+
openshift_options:
37+
versions:
38+
options:
39+
- label: v4.4
40+
value: 4.4.10
41+
- label: v4.5
42+
value: 4.5.0
43+
persistent_storage:
44+
validators:
45+
- kind: notnull
46+
options:
47+
- label: None
48+
value: none
49+
- label: 50GB
50+
value: 50G
51+
cluster_size:
52+
options:
53+
- label: Small
54+
value: small
55+
user_options:
56+
user_roles:
57+
options:
58+
- label: Developer
59+
value: developer
60+
- label: Observer
61+
value: observer
62+
- label: Admin
63+
value: admin
64+
logistics_options:
65+
start_date:
66+
end_date:
67+
validators:
68+
- kind: date
69+
value:
70+
min: "@today"
71+
message: "End date must be after today"
72+
technical_contact_email:
73+
env_default_grace_period: 30
74+
env_grace_period_max: 180
75+
kind: ConfigMap
76+
metadata:
77+
name: lodestar-runtime-cm
78+
{{- end }}

deployment/templates/deploymentconfig.yaml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ spec:
4444
terminationMessagePolicy: File
4545
volumeMounts:
4646
- name: hook-cm-volume
47-
mountPath: {{ .Values.config.hookFile.path }}
47+
mountPath: {{ .Values.config.hookFile.path }}/{{ .Values.config.hookFile.name }}
48+
subPath: {{ .Values.config.hookFile.name }}
49+
- name: lodestar-runtime-cm-volume
50+
mountPath: {{ .Values.config.runtimeConfigFile.path }}/{{ .Values.config.runtimeConfigFile.name }}
51+
subPath: {{ .Values.config.runtimeConfigFile.name }}
4852
dnsPolicy: ClusterFirst
4953
restartPolicy: Always
5054
schedulerName: default-scheduler
@@ -54,6 +58,9 @@ spec:
5458
- name: hook-cm-volume
5559
configMap:
5660
name: hook-cm
61+
- name: lodestar-runtime-cm-volume
62+
configMap:
63+
name: lodestar-runtime-cm
5764
test: false
5865
triggers:
5966
- type: ConfigChange

deployment/templates/gitlab-secret.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ metadata:
55
name: omp-gitlab-configuration
66
type: Opaque
77
stringData:
8-
CONFIG_FILE: "{{ .Values.configFile }}"
98
CONFIG_REPOSITORY_ID: "{{ .Values.configRepositoryId }}"
109
DEPLOY_KEY: "{{ .Values.deployKey }}"
1110
GITLAB_API_URL: "{{ .Values.gitLabApiUrl }}"

deployment/values-dev.yaml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ git:
1313
uri: https://github.com/rht-labs/open-management-portal-git-api.git
1414
ref: master
1515

16-
configFile: false
1716
configRepositoryId: false
1817
deployKey: false
1918
gitLabApiUrl: false
@@ -22,7 +21,7 @@ engagementsRepositoryId: false
2221

2322
config:
2423
hookFile:
25-
path: /schema
24+
path: /runtime
2625
name: webhooks.yaml
2726
hooks:
2827
- name: hook1
@@ -31,4 +30,7 @@ config:
3130
- name: hook2
3231
baseUrl: http://localhost/hook2
3332
token: anunoby
34-
33+
runtimeConfigFile:
34+
path: /runtime
35+
name: lodestar-runtime-config.yaml
36+

deployment/values.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,11 @@ imageName: "quay.io/rht-labs/omp-git-api"
66
imageTag: "latest" # This is intended to be overridden by the parent Helm chart.
77

88
gitlabRef: "master"
9+
10+
config:
11+
hookFile:
12+
path: /runtime
13+
name: webhooks.yaml
14+
configFile:
15+
path: /runtime
16+
name: lodestar-runtime-config.yaml

src/main/java/com/redhat/labs/omp/service/ConfigService.java

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package com.redhat.labs.omp.service;
22

3+
import java.io.IOException;
4+
import java.nio.file.Files;
5+
import java.nio.file.Path;
6+
import java.nio.file.Paths;
37
import java.util.ArrayList;
48
import java.util.List;
59
import java.util.Optional;
@@ -25,58 +29,87 @@ public class ConfigService {
2529

2630
@ConfigProperty(name = "config.file")
2731
String configFile;
28-
32+
2933
@ConfigProperty(name = "webhook.file")
3034
String webHooksFile;
3135

3236
@ConfigProperty(name = "config.repository.id", defaultValue = "9407")
3337
String configRepositoryId;
34-
38+
3539
@ConfigProperty(name = "config.gitlab.ref", defaultValue = "master")
3640
String gitRef;
37-
41+
3842
List<HookConfig> hookConfigList;
43+
File configuration;
3944

4045
@Inject
4146
FileService fileService;
42-
47+
4348
@Inject
4449
JsonMarshaller marshaller;
45-
50+
4651
void onStart(@Observes StartupEvent event) {
4752
hookConfigList = marshaller.fromYamlFile(webHooksFile, HookConfig.class);
4853
LOGGER.debug("Hook Config List {}", hookConfigList);
54+
String content = readFile(configFile);
55+
if (null != content) {
56+
configuration = File.builder().filePath(configFile).content(content).build();
57+
LOGGER.debug("Loaded Runtime Config from File, {}", configFile);
58+
}
59+
4960
}
5061

5162
public File getConfigFile() {
5263

53-
Optional<File> optional = fileService.getFile(configRepositoryId, configFile, gitRef);
64+
if (null != configuration) {
65+
return configuration;
66+
}
67+
68+
String gitLabConfigFile = configFile.charAt(0) == '/' ? configFile.substring(1) : configFile;
69+
Optional<File> optional = fileService.getFile(configRepositoryId, gitLabConfigFile, gitRef);
5470

5571
if (!optional.isPresent()) {
5672
throw new FileNotFoundException("the configured file was not found in the gitlab repository.");
5773
}
5874

5975
return optional.get();
6076
}
61-
77+
6278
public List<HookConfig> getHookConfig() {
6379

64-
if(hookConfigList != null) {
80+
if (hookConfigList != null) {
6581
return hookConfigList;
6682
}
67-
83+
6884
String gitLabHookFile = webHooksFile.charAt(0) == '/' ? webHooksFile.substring(1) : webHooksFile;
6985
Optional<File> optional = fileService.getFile(configRepositoryId, gitLabHookFile, gitRef);
7086

7187
if (!optional.isPresent()) {
7288
LOGGER.error("No webhook file could be found. This is abnormal but not a deal breaker");
7389
return new ArrayList<>();
7490
}
75-
91+
7692
File file = optional.get();
77-
93+
7894
return marshaller.fromYaml(file.getContent(), HookConfig.class);
79-
95+
96+
}
97+
98+
private String readFile(String file) {
99+
100+
Path path = Paths.get(file);
101+
102+
if (Files.isReadable(path)) {
103+
LOGGER.debug("Loading config file {}", file);
104+
try {
105+
return new String(Files.readAllBytes(path));
106+
} catch (IOException e) {
107+
LOGGER.error(String.format("Found but unable to read file %s", file), e);
108+
}
109+
}
110+
111+
return null;
112+
80113
}
81114

82115
}

src/main/resources/application.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ gitlab.deploy.key=${DEPLOY_KEY:0}
2626

2727
# config
2828
config.repository.id=${CONFIG_REPOSITORY_ID:1}
29-
config.file=${CONFIG_FILE:schema/config.yml}
30-
webhook.file=${WEBHOOK_FILE:/schema/webhooks.yaml}
29+
config.file=${CONFIG_FILE:/runtime/lodestar-runtime-config.yaml}
30+
webhook.file=${WEBHOOK_FILE:/runtime/webhooks.yaml}
3131
webhook.default.token=${WEBHOOK_DEFAULT_TOKEN:tolkien}
3232
config.gitlab.ref=${CONFIG_GITLAB_REF:master}
3333
commit.page.size=100

src/test/java/com/redhat/labs/omp/mocks/MockGitLabService.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ public File getFile(String projectId, String filePath, String ref) {
157157

158158
}
159159

160-
if ("schema/webhooks.yaml".equalsIgnoreCase(filePath)) {
160+
if ("runtime/webhooks.yaml".equalsIgnoreCase(filePath)) {
161161
String content = ResourceLoader.load("webhooks.yaml");
162162
content = new String(EncodingUtils.base64Encode(content.getBytes()), StandardCharsets.UTF_8);
163163
return File.builder().filePath(filePath).content(content).build();
@@ -186,8 +186,8 @@ public File getFile(String projectId, String filePath, String ref) {
186186
throw new WebApplicationException(500);
187187
}
188188

189-
if("schema/config.yml".equals(filePath)) {
190-
String content = ResourceLoader.load("config.yml");
189+
if("runtime/lodestar-runtime-config.yaml".equals(filePath)) {
190+
String content = ResourceLoader.load("lodestar-runtime-config.yaml");
191191
content = new String(EncodingUtils.base64Encode(content.getBytes()), StandardCharsets.UTF_8);
192192
return File.builder().filePath(filePath).content(content).build();
193193
}

src/test/java/com/redhat/labs/omp/resource/ConfigResourceTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class ConfigResourceTest {
1515
void testGetConfigFileSuccess() {
1616

1717
given().when().contentType(ContentType.JSON).get("/api/v1/config").then().statusCode(200).body(is(
18-
"{\"content\":\"---\\nproviders:\\n- label: AWS\\n value: ec2\\n regions:\\n - label: US East 1 (N. Virginia)\\n value: us-east-1\\n - label: US East 2 (Ohio)\\n value: us-east-2\\nopenshift:\\n versions:\\n - label: v4.1\\n value: 4.1.31\\n - label: v4.2\\n value: 4.2.16\\n - label: v4.3\\n value: 4.3.0\\n persistent-storage:\\n - label: None\\n value: none\\n - label: 50GB\\n value: 50G\\n - label: 100GB\\n value: 100G\\n - label: 250GB\\n value: 250G\\n - label: 500GB\\n value: 500G\\n cluster-size:\\n - label: Small\\n value: small\\nuser-management:\\n rbac:\\n roles:\\n - label: Developer \\n value: developer\\n - label: Observer \\n value: observer\\n - label: Admin \\n value: admin\\n\",\"encoding\":\"base64\",\"file_path\":\"schema/config.yml\"}"));
18+
"{\"content\":\"---\\nproviders:\\n- label: AWS\\n value: ec2\\n regions:\\n - label: US East 1 (N. Virginia)\\n value: us-east-1\\n - label: US East 2 (Ohio)\\n value: us-east-2\\nopenshift:\\n versions:\\n - label: v4.1\\n value: 4.1.31\\n - label: v4.2\\n value: 4.2.16\\n - label: v4.3\\n value: 4.3.0\\n persistent-storage:\\n - label: None\\n value: none\\n - label: 50GB\\n value: 50G\\n - label: 100GB\\n value: 100G\\n - label: 250GB\\n value: 250G\\n - label: 500GB\\n value: 500G\\n cluster-size:\\n - label: Small\\n value: small\\nuser-management:\\n rbac:\\n roles:\\n - label: Developer \\n value: developer\\n - label: Observer \\n value: observer\\n - label: Admin \\n value: admin\\n\",\"encoding\":\"base64\",\"file_path\":\"runtime/lodestar-runtime-config.yaml\"}"));
1919

2020
}
2121

0 commit comments

Comments
 (0)