Skip to content

Commit

Permalink
Remove Runtime Config API (#132)
Browse files Browse the repository at this point in the history
* remove config file api

* remove runtime configmap from deployment
  • Loading branch information
dwasinge authored May 11, 2021
1 parent f886c14 commit 223f712
Show file tree
Hide file tree
Showing 8 changed files with 2 additions and 338 deletions.
78 changes: 0 additions & 78 deletions deployment/templates/configmap-config.yaml

This file was deleted.

6 changes: 0 additions & 6 deletions deployment/templates/deploymentconfig.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,6 @@ spec:
- name: hook-cm-volume
mountPath: {{ .Values.config.hookFile.path }}/{{ .Values.config.hookFile.name }}
subPath: {{ .Values.config.hookFile.name }}
- name: lodestar-runtime-cm-volume
mountPath: {{ .Values.config.configFile.path }}/{{ .Values.config.configFile.name }}
subPath: {{ .Values.config.configFile.name }}
dnsPolicy: ClusterFirst
restartPolicy: Always
schedulerName: default-scheduler
Expand All @@ -76,9 +73,6 @@ spec:
- name: hook-cm-volume
configMap:
name: hook-cm
- name: lodestar-runtime-cm-volume
configMap:
name: lodestar-runtime-cm
test: false
triggers:
- type: ConfigChange
Expand Down
3 changes: 0 additions & 3 deletions deployment/values-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,4 @@ config:
- name: hook2
baseUrl: http://localhost/hook2
token: anunoby
configFile:
path: /runtime
name: lodestar-runtime-config.yaml

Original file line number Diff line number Diff line change
Expand Up @@ -10,52 +10,21 @@
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import com.redhat.labs.lodestar.models.gitlab.File;
import com.redhat.labs.lodestar.models.gitlab.HookConfig;
import com.redhat.labs.lodestar.service.ConfigService;

@Path("/api")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public class ConfigResource {
private static final Logger LOGGER = LoggerFactory.getLogger(ConfigResource.class);

@Inject
ConfigService configService;

@GET
@Path("/v1/config")
public File get() {
LOGGER.info("V1 or undefined is deprecated");
return configService.getConfigFile();
}

@GET
@Path("/v2/config")
public Response getJson() {
File configFile = configService.getConfigFile();
ObjectMapper om = new ObjectMapper(new YAMLFactory());
try {
LOGGER.trace(configFile.getContent());
Object content = om.readValue(configFile.getContent(), Object.class);
return Response.ok(content).build();
} catch (JsonProcessingException e) {
LOGGER.error(String.format("Error processing config file %s", configFile.getFilePath()), e);
return Response.serverError().build();
}
}

@GET
@Path("/v2/config/webhooks")
public Response getWebhooks() {
List<HookConfig> hooks = configService.getHookConfig();

List<HookConfig> hooks = configService.getHookConfig();
return Response.ok(hooks).build();
}
}
48 changes: 0 additions & 48 deletions src/main/java/com/redhat/labs/lodestar/service/ConfigService.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import org.slf4j.LoggerFactory;

import com.redhat.labs.lodestar.config.JsonMarshaller;
import com.redhat.labs.lodestar.exception.FileNotFoundException;
import com.redhat.labs.lodestar.models.ConfigMap;
import com.redhat.labs.lodestar.models.Engagement;
import com.redhat.labs.lodestar.models.gitlab.File;
Expand All @@ -32,9 +31,6 @@ public class ConfigService {

private static final String IAC = "iac";

@ConfigProperty(name = "config.file")
String configFile;

@ConfigProperty(name = "webhook.file")
String webHooksFile;

Expand Down Expand Up @@ -79,7 +75,6 @@ public class ConfigService {
void reloadConfigMapData() {
if (reloadConfig) {
loadWebHookData();
loadConfigurationData();
}
}

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

}

/**
* Loads the configuration data from the configured file if it has been
* modified.
*/
void loadConfigurationData() {

// create config map
if (null == configurationConfigMap) {
configurationConfigMap = ConfigMap.builder().filePath(configFile).build();
}
// load initial content
configurationConfigMap.updateMountedFile();
// create file
Optional<String> content = configurationConfigMap.getContent();
if (content.isPresent()) {
configuration = File.builder().filePath(configFile).content(content.get()).build();
}

}

/**
* Returns a {@link File} containging the configuration data from the configured
* file. If the configured file is not available, the data is loaded from
* GitLab.
*
* @return
*/
public File getConfigFile() {

if (null != configuration) {
return configuration;
}

String gitLabConfigFile = configFile.charAt(0) == '/' ? configFile.substring(1) : configFile;
Optional<File> optional = fileService.getFile(configRepositoryId, gitLabConfigFile, gitRef);

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

return optional.get();
}

/**
* Returns a {@link List} of {@link HookConfig} from the configured file. If the
* configured file is not available, the data is loaded from GitLab.
Expand Down
1 change: 0 additions & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ gitlab.deploy.key=${DEPLOY_KEY:0}

# config
config.repository.id=${CONFIG_REPOSITORY_ID:1}
config.file=${CONFIG_FILE:/runtime/lodestar-runtime-config.yaml}
webhook.file=${WEBHOOK_FILE:/runtime/webhooks.yaml}
webhook.default.token=${WEBHOOK_DEFAULT_TOKEN:tolkien}
config.gitlab.ref=${CONFIG_GITLAB_REF:master}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,106 +10,7 @@

@QuarkusTest
class ConfigResourceTest {

@Test
void testGetConfigFileSuccess() {

given().when().contentType(ContentType.JSON).get("/api/v1/config").then().statusCode(200).body(is(
"\n{\n" +
" \"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" +
" \"encoding\": \"base64\",\n" +
" \"file_path\": \"runtime/lodestar-runtime-config.yaml\"\n" +
"}"));

}

@Test
void testGetConfigFileSuccessV2() {

given().when().contentType(ContentType.JSON).get("/api/v2/config").then().statusCode(200).body(is(
"\n{\n" +
" \"providers\": [\n" +
" {\n" +
" \"label\": \"AWS\",\n" +
" \"value\": \"ec2\",\n" +
" \"regions\": [\n" +
" {\n" +
" \"label\": \"US East 1 (N. Virginia)\",\n" +
" \"value\": \"us-east-1\"\n" +
" },\n" +
" {\n" +
" \"label\": \"US East 2 (Ohio)\",\n" +
" \"value\": \"us-east-2\"\n" +
" }\n" +
" ]\n" +
" }\n" +
" ],\n" +
" \"openshift\": {\n" +
" \"versions\": [\n" +
" {\n" +
" \"label\": \"v4.1\",\n" +
" \"value\": \"4.1.31\"\n" +
" },\n" +
" {\n" +
" \"label\": \"v4.2\",\n" +
" \"value\": \"4.2.16\"\n" +
" },\n" +
" {\n" +
" \"label\": \"v4.3\",\n" +
" \"value\": \"4.3.0\"\n" +
" }\n" +
" ],\n" +
" \"persistent-storage\": [\n" +
" {\n" +
" \"label\": \"None\",\n" +
" \"value\": \"none\"\n" +
" },\n" +
" {\n" +
" \"label\": \"50GB\",\n" +
" \"value\": \"50G\"\n" +
" },\n" +
" {\n" +
" \"label\": \"100GB\",\n" +
" \"value\": \"100G\"\n" +
" },\n" +
" {\n" +
" \"label\": \"250GB\",\n" +
" \"value\": \"250G\"\n" +
" },\n" +
" {\n" +
" \"label\": \"500GB\",\n" +
" \"value\": \"500G\"\n" +
" }\n" +
" ],\n" +
" \"cluster-size\": [\n" +
" {\n" +
" \"label\": \"Small\",\n" +
" \"value\": \"small\"\n" +
" }\n" +
" ]\n" +
" },\n" +
" \"user-management\": {\n" +
" \"rbac\": {\n" +
" \"roles\": [\n" +
" {\n" +
" \"label\": \"Developer\",\n" +
" \"value\": \"developer\"\n" +
" },\n" +
" {\n" +
" \"label\": \"Observer\",\n" +
" \"value\": \"observer\"\n" +
" },\n" +
" {\n" +
" \"label\": \"Admin\",\n" +
" \"value\": \"admin\"\n" +
" }\n" +
" ]\n" +
" }\n" +
" }\n" +
"}"));

}


@Test
void testGetHookFileSuccess() {

Expand Down
Loading

0 comments on commit 223f712

Please sign in to comment.