Skip to content

Commit 223f712

Browse files
authored
Remove Runtime Config API (#132)
* remove config file api * remove runtime configmap from deployment
1 parent f886c14 commit 223f712

File tree

8 files changed

+2
-338
lines changed

8 files changed

+2
-338
lines changed

deployment/templates/configmap-config.yaml

Lines changed: 0 additions & 78 deletions
This file was deleted.

deployment/templates/deploymentconfig.yaml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,6 @@ spec:
6464
- name: hook-cm-volume
6565
mountPath: {{ .Values.config.hookFile.path }}/{{ .Values.config.hookFile.name }}
6666
subPath: {{ .Values.config.hookFile.name }}
67-
- name: lodestar-runtime-cm-volume
68-
mountPath: {{ .Values.config.configFile.path }}/{{ .Values.config.configFile.name }}
69-
subPath: {{ .Values.config.configFile.name }}
7067
dnsPolicy: ClusterFirst
7168
restartPolicy: Always
7269
schedulerName: default-scheduler
@@ -76,9 +73,6 @@ spec:
7673
- name: hook-cm-volume
7774
configMap:
7875
name: hook-cm
79-
- name: lodestar-runtime-cm-volume
80-
configMap:
81-
name: lodestar-runtime-cm
8276
test: false
8377
triggers:
8478
- type: ConfigChange

deployment/values-dev.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,4 @@ config:
3030
- name: hook2
3131
baseUrl: http://localhost/hook2
3232
token: anunoby
33-
configFile:
34-
path: /runtime
35-
name: lodestar-runtime-config.yaml
3633

src/main/java/com/redhat/labs/lodestar/resource/ConfigResource.java

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -10,52 +10,21 @@
1010
import javax.ws.rs.core.MediaType;
1111
import javax.ws.rs.core.Response;
1212

13-
import org.slf4j.Logger;
14-
import org.slf4j.LoggerFactory;
15-
16-
import com.fasterxml.jackson.core.JsonProcessingException;
17-
import com.fasterxml.jackson.databind.ObjectMapper;
18-
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
19-
import com.redhat.labs.lodestar.models.gitlab.File;
2013
import com.redhat.labs.lodestar.models.gitlab.HookConfig;
2114
import com.redhat.labs.lodestar.service.ConfigService;
2215

2316
@Path("/api")
2417
@Produces(MediaType.APPLICATION_JSON)
2518
@Consumes(MediaType.APPLICATION_JSON)
2619
public class ConfigResource {
27-
private static final Logger LOGGER = LoggerFactory.getLogger(ConfigResource.class);
2820

2921
@Inject
3022
ConfigService configService;
31-
32-
@GET
33-
@Path("/v1/config")
34-
public File get() {
35-
LOGGER.info("V1 or undefined is deprecated");
36-
return configService.getConfigFile();
37-
}
38-
39-
@GET
40-
@Path("/v2/config")
41-
public Response getJson() {
42-
File configFile = configService.getConfigFile();
43-
ObjectMapper om = new ObjectMapper(new YAMLFactory());
44-
try {
45-
LOGGER.trace(configFile.getContent());
46-
Object content = om.readValue(configFile.getContent(), Object.class);
47-
return Response.ok(content).build();
48-
} catch (JsonProcessingException e) {
49-
LOGGER.error(String.format("Error processing config file %s", configFile.getFilePath()), e);
50-
return Response.serverError().build();
51-
}
52-
}
5323

5424
@GET
5525
@Path("/v2/config/webhooks")
5626
public Response getWebhooks() {
57-
List<HookConfig> hooks = configService.getHookConfig();
58-
27+
List<HookConfig> hooks = configService.getHookConfig();
5928
return Response.ok(hooks).build();
6029
}
6130
}

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

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import org.slf4j.LoggerFactory;
1717

1818
import com.redhat.labs.lodestar.config.JsonMarshaller;
19-
import com.redhat.labs.lodestar.exception.FileNotFoundException;
2019
import com.redhat.labs.lodestar.models.ConfigMap;
2120
import com.redhat.labs.lodestar.models.Engagement;
2221
import com.redhat.labs.lodestar.models.gitlab.File;
@@ -32,9 +31,6 @@ public class ConfigService {
3231

3332
private static final String IAC = "iac";
3433

35-
@ConfigProperty(name = "config.file")
36-
String configFile;
37-
3834
@ConfigProperty(name = "webhook.file")
3935
String webHooksFile;
4036

@@ -79,7 +75,6 @@ public class ConfigService {
7975
void reloadConfigMapData() {
8076
if (reloadConfig) {
8177
loadWebHookData();
82-
loadConfigurationData();
8378
}
8479
}
8580

@@ -204,49 +199,6 @@ public void createWebhooksForEnagement(Engagement engagement) {
204199

205200
}
206201

207-
/**
208-
* Loads the configuration data from the configured file if it has been
209-
* modified.
210-
*/
211-
void loadConfigurationData() {
212-
213-
// create config map
214-
if (null == configurationConfigMap) {
215-
configurationConfigMap = ConfigMap.builder().filePath(configFile).build();
216-
}
217-
// load initial content
218-
configurationConfigMap.updateMountedFile();
219-
// create file
220-
Optional<String> content = configurationConfigMap.getContent();
221-
if (content.isPresent()) {
222-
configuration = File.builder().filePath(configFile).content(content.get()).build();
223-
}
224-
225-
}
226-
227-
/**
228-
* Returns a {@link File} containging the configuration data from the configured
229-
* file. If the configured file is not available, the data is loaded from
230-
* GitLab.
231-
*
232-
* @return
233-
*/
234-
public File getConfigFile() {
235-
236-
if (null != configuration) {
237-
return configuration;
238-
}
239-
240-
String gitLabConfigFile = configFile.charAt(0) == '/' ? configFile.substring(1) : configFile;
241-
Optional<File> optional = fileService.getFile(configRepositoryId, gitLabConfigFile, gitRef);
242-
243-
if (!optional.isPresent()) {
244-
throw new FileNotFoundException("the configured file was not found in the gitlab repository.");
245-
}
246-
247-
return optional.get();
248-
}
249-
250202
/**
251203
* Returns a {@link List} of {@link HookConfig} from the configured file. If the
252204
* configured file is not available, the data is loaded from GitLab.

src/main/resources/application.properties

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ gitlab.deploy.key=${DEPLOY_KEY:0}
2626

2727
# config
2828
config.repository.id=${CONFIG_REPOSITORY_ID:1}
29-
config.file=${CONFIG_FILE:/runtime/lodestar-runtime-config.yaml}
3029
webhook.file=${WEBHOOK_FILE:/runtime/webhooks.yaml}
3130
webhook.default.token=${WEBHOOK_DEFAULT_TOKEN:tolkien}
3231
config.gitlab.ref=${CONFIG_GITLAB_REF:master}

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

Lines changed: 1 addition & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -10,106 +10,7 @@
1010

1111
@QuarkusTest
1212
class ConfigResourceTest {
13-
14-
@Test
15-
void testGetConfigFileSuccess() {
16-
17-
given().when().contentType(ContentType.JSON).get("/api/v1/config").then().statusCode(200).body(is(
18-
"\n{\n" +
19-
" \"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\",\n" +
20-
" \"encoding\": \"base64\",\n" +
21-
" \"file_path\": \"runtime/lodestar-runtime-config.yaml\"\n" +
22-
"}"));
23-
24-
}
25-
26-
@Test
27-
void testGetConfigFileSuccessV2() {
28-
29-
given().when().contentType(ContentType.JSON).get("/api/v2/config").then().statusCode(200).body(is(
30-
"\n{\n" +
31-
" \"providers\": [\n" +
32-
" {\n" +
33-
" \"label\": \"AWS\",\n" +
34-
" \"value\": \"ec2\",\n" +
35-
" \"regions\": [\n" +
36-
" {\n" +
37-
" \"label\": \"US East 1 (N. Virginia)\",\n" +
38-
" \"value\": \"us-east-1\"\n" +
39-
" },\n" +
40-
" {\n" +
41-
" \"label\": \"US East 2 (Ohio)\",\n" +
42-
" \"value\": \"us-east-2\"\n" +
43-
" }\n" +
44-
" ]\n" +
45-
" }\n" +
46-
" ],\n" +
47-
" \"openshift\": {\n" +
48-
" \"versions\": [\n" +
49-
" {\n" +
50-
" \"label\": \"v4.1\",\n" +
51-
" \"value\": \"4.1.31\"\n" +
52-
" },\n" +
53-
" {\n" +
54-
" \"label\": \"v4.2\",\n" +
55-
" \"value\": \"4.2.16\"\n" +
56-
" },\n" +
57-
" {\n" +
58-
" \"label\": \"v4.3\",\n" +
59-
" \"value\": \"4.3.0\"\n" +
60-
" }\n" +
61-
" ],\n" +
62-
" \"persistent-storage\": [\n" +
63-
" {\n" +
64-
" \"label\": \"None\",\n" +
65-
" \"value\": \"none\"\n" +
66-
" },\n" +
67-
" {\n" +
68-
" \"label\": \"50GB\",\n" +
69-
" \"value\": \"50G\"\n" +
70-
" },\n" +
71-
" {\n" +
72-
" \"label\": \"100GB\",\n" +
73-
" \"value\": \"100G\"\n" +
74-
" },\n" +
75-
" {\n" +
76-
" \"label\": \"250GB\",\n" +
77-
" \"value\": \"250G\"\n" +
78-
" },\n" +
79-
" {\n" +
80-
" \"label\": \"500GB\",\n" +
81-
" \"value\": \"500G\"\n" +
82-
" }\n" +
83-
" ],\n" +
84-
" \"cluster-size\": [\n" +
85-
" {\n" +
86-
" \"label\": \"Small\",\n" +
87-
" \"value\": \"small\"\n" +
88-
" }\n" +
89-
" ]\n" +
90-
" },\n" +
91-
" \"user-management\": {\n" +
92-
" \"rbac\": {\n" +
93-
" \"roles\": [\n" +
94-
" {\n" +
95-
" \"label\": \"Developer\",\n" +
96-
" \"value\": \"developer\"\n" +
97-
" },\n" +
98-
" {\n" +
99-
" \"label\": \"Observer\",\n" +
100-
" \"value\": \"observer\"\n" +
101-
" },\n" +
102-
" {\n" +
103-
" \"label\": \"Admin\",\n" +
104-
" \"value\": \"admin\"\n" +
105-
" }\n" +
106-
" ]\n" +
107-
" }\n" +
108-
" }\n" +
109-
"}"));
110-
111-
}
112-
13+
11314
@Test
11415
void testGetHookFileSuccess() {
11516

0 commit comments

Comments
 (0)