Skip to content

Commit

Permalink
Rename instances to organisms and more (#1209)
Browse files Browse the repository at this point in the history
This PR makes two changes:

it renames instances in helm Values to organisms, in line with our nomenclature. This was a backlog item.
it renames the organisms in the default Values.yaml to defaultOrganisms. It only uses this if organisms is unset. Without this, if we make a new instance and set organisms appropriately, the dummy-organism, etc., gets added in too. It would be nice to do this with helm templates but I couldn't make that work.
  • Loading branch information
theosanderson authored Mar 1, 2024
1 parent c051147 commit ed8e4eb
Show file tree
Hide file tree
Showing 23 changed files with 33 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ annotation class ValidOrganism(

class OrganismValidator(private val backendConfig: BackendConfig) : ConstraintValidator<ValidOrganism, Organism> {
override fun isValid(value: Organism, context: ConstraintValidatorContext): Boolean {
val keys = backendConfig.instances.keys
val keys = backendConfig.organisms.keys
if (keys.contains(value.name)) {
return true
}
Expand Down
6 changes: 3 additions & 3 deletions backend/src/main/kotlin/org/loculus/backend/config/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import org.apache.commons.lang3.StringUtils.lowerCase
import org.loculus.backend.api.Organism

data class BackendConfig(
val instances: Map<String, InstanceConfig>,
val organisms: Map<String, InstanceConfig>,
val accessionPrefix: String,
) {
fun getInstanceConfig(organism: Organism) = instances[organism.name] ?: throw IllegalArgumentException(
"Organism: ${organism.name} not found in backend config. Available organisms: ${instances.keys}",
fun getInstanceConfig(organism: Organism) = organisms[organism.name] ?: throw IllegalArgumentException(
"Organism: ${organism.name} not found in backend config. Available organisms: ${organisms.keys}",
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fun buildOpenApiSchema(backendConfig: BackendConfig): OpenAPI {
Schema<String>()
.type("string")
.description("valid names of organisms that this $PROJECT_NAME instance supports")
._enum(backendConfig.instances.keys.toList()),
._enum(backendConfig.organisms.keys.toList()),
)
.addSecuritySchemes(
"bearerAuth",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ enum class NucleotideSymbols(override val symbol: Char) : Symbol {
@Component
class ProcessedSequenceEntryValidatorFactory(private val backendConfig: BackendConfig) {
fun create(organism: Organism): ProcessedSequenceEntryValidator {
val instanceConfig = backendConfig.instances[organism.name]!!
val instanceConfig = backendConfig.organisms[organism.name]!!
return ProcessedSequenceEntryValidator(instanceConfig.schema, instanceConfig.referenceGenomes)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class CompressionServiceTest(
mapOf("test" to "test"),
mapOf(segmentName to input),
)
val organism = Organism(backendConfig.instances.keys.first())
val organism = Organism(backendConfig.organisms.keys.first())
val compressed = compressor.compressSequencesInOriginalData(testData, organism)
val decompressed = compressor.decompressSequencesInOriginalData(compressed, organism)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const val PREFIX = "LOC_"

class GenerateAccessionFromNumberServiceTest {
private val accessionFromNumberService = GenerateAccessionFromNumberService(
BackendConfig(accessionPrefix = PREFIX, instances = emptyMap()),
BackendConfig(accessionPrefix = PREFIX, organisms = emptyMap()),
)

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class EmptyProcessedDataProviderTest {
private val underTest = EmptyProcessedDataProvider(
BackendConfig(
accessionPrefix = "LOC_",
instances = mapOf(
organisms = mapOf(
DEFAULT_ORGANISM to InstanceConfig(
schema = Schema(
FIRST_NUCLEOTIDE_SEQUENCE,
Expand Down
2 changes: 1 addition & 1 deletion backend/src/test/resources/backend_config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"accessionPrefix": "LOC_",
"instances": {
"organisms": {
"dummyOrganism": {
"referenceGenomes": {
"nucleotideSequences": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"accessionPrefix" : "LOC_",
"instances": {
"organisms": {
"dummyOrganism": {
"referenceGenomes": {
"nucleotideSequences": [
Expand Down
8 changes: 4 additions & 4 deletions kubernetes/loculus/templates/_common-metadata.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ name: {{ $.Values.name }}
logo: {{ $.Values.logo | toYaml | nindent 6 }}
accessionPrefix: {{ $.Values.accessionPrefix }}
{{- $commonMetadata := (include "loculus.commonMetadata" . | fromYaml).fields }}
instances:
{{- range $key, $instance := $.Values.instances }}
organisms:
{{- range $key, $instance := (.Values.organisms | default .Values.defaultOrganisms) }}
{{ $key }}:

schema:
Expand Down Expand Up @@ -80,8 +80,8 @@ fields:
{{- define "loculus.generateBackendConfig" }}
accessionPrefix: {{$.Values.accessionPrefix}}
name: {{ $.Values.name }}
instances:
{{- range $key, $instance := $.Values.instances }}
organisms:
{{- range $key, $instance := (.Values.organisms | default .Values.defaultOrganisms) }}
{{ $key }}:
schema:
{{- with $instance.schema }}
Expand Down
4 changes: 2 additions & 2 deletions kubernetes/loculus/templates/_lapis-urls.tpl
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{{/* generates internal LAPIS urls from given config object */}}
{{ define "loculus.generateInternalLapisUrls" }}
{{ range $key, $_ := $.Values.instances }}
{{ range $key, $_ := (.Values.organisms | default .Values.defaultOrganisms) }}
"{{ $key }}": "{{ if not $.Values.disableWebsite }}http://{{ template "loculus.lapisServiceName" $key }}:8080{{ else -}}http://localhost:8080/{{ $key }}{{ end }}"
{{ end }}
{{ end }}

{{/* generates external LAPIS urls from { config, host } */}}
{{ define "loculus.generateExternalLapisUrls"}}
{{ $host := .host }}
{{ range $key, $_ := .config.instances }}
{{ range $key, $_ := (.config.organisms | default .config.defaultOrganisms) }}
"{{ $key -}}": "{{ $host }}/{{ $key }}"
{{ end }}
{{ end }}
Expand Down
6 changes: 3 additions & 3 deletions kubernetes/loculus/templates/lapis-ingress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ kind: Ingress
metadata:
name: lapis-ingress
annotations:
traefik.ingress.kubernetes.io/router.middlewares: "{{- $first := true }}{{- range $key, $_ := $.Values.instances }}{{ if $first }}{{ $first = false }}{{ else }},{{ end }}{{ $.Release.Namespace }}-strip-{{ $key }}-prefix@kubernetescrd{{- end }}"
traefik.ingress.kubernetes.io/router.middlewares: "{{- $first := true }}{{- range $key, $_ := (.Values.organisms | default .Values.defaultOrganisms) }}{{ if $first }}{{ $first = false }}{{ else }},{{ end }}{{ $.Release.Namespace }}-strip-{{ $key }}-prefix@kubernetescrd{{- end }}"
spec:
rules:
- host: {{ if eq $.Values.environment "server" }}{{ $lapisHost }}{{ end }}
http:
paths:
{{- range $key, $_ := $.Values.instances }}
{{- range $key, $_ := (.Values.organisms | default .Values.defaultOrganisms) }}
- path: /{{ $key }}/
pathType: Prefix
backend:
Expand All @@ -30,7 +30,7 @@ spec:
{{- end }}


{{- range $key, $_ := $.Values.instances }}
{{- range $key, $_ := (.Values.organisms | default .Values.defaultOrganisms) }}
---
apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
Expand Down
2 changes: 1 addition & 1 deletion kubernetes/loculus/templates/lapis-service.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- range $key, $_ := $.Values.instances }}
{{- range $key, $_ := (.Values.organisms | default .Values.defaultOrganisms) }}
---
apiVersion: v1
kind: Service
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{- $commonMetadata := (include "loculus.commonMetadata" . | fromYaml).fields }}
{{- $importScriptLines := .Files.Lines "silo_import_job.sh" }}

{{- range $key, $instance := $.Values.instances }}
{{- range $key, $instance := (.Values.organisms | default .Values.defaultOrganisms) }}
---
apiVersion: v1
kind: ConfigMap
Expand Down
2 changes: 1 addition & 1 deletion kubernetes/loculus/templates/lapis-silo-deployment.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{- $dockerTag := include "loculus.dockerTag" $.Values }}
{{- range $key, $_ := $.Values.instances }}
{{- range $key, $_ := (.Values.organisms | default .Values.defaultOrganisms) }}
---
apiVersion: apps/v1
kind: Deployment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{{- $keycloakTokenUrl := "http://loculus-keycloak-service:8083/realms/loculusRealm/protocol/openid-connect/token" }}


{{- range $key, $_ := $.Values.instances }}
{{- range $key, $_ := (.Values.organisms | default .Values.defaultOrganisms) }}
---
apiVersion: batch/v1
kind: CronJob
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- range $key, $_ := $.Values.instances }}
{{- range $key, $_ := (.Values.organisms | default .Values.defaultOrganisms) }}
---
apiVersion: v1
kind: PersistentVolumeClaim
Expand Down
2 changes: 1 addition & 1 deletion kubernetes/loculus/templates/lapis-silo-shared-data.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- range $key, $_ := $.Values.instances }}
{{- range $key, $_ := (.Values.organisms | default .Values.defaultOrganisms) }}
---
apiVersion: v1
kind: PersistentVolumeClaim
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- range $key, $values := .Values.instances }}
{{- range $key, $values := (.Values.organisms | default .Values.defaultOrganisms) }}
{{- if $values.preprocessing.configFile }}
---
apiVersion: v1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"http://loculus-keycloak-service:8083"
}}
{{- if not .Values.disablePreprocessing }}
{{- range $key, $value := .Values.instances }}
{{- range $key, $value := (.Values.organisms | default .Values.defaultOrganisms) }}
---
apiVersion: apps/v1
kind: Deployment
Expand Down
2 changes: 1 addition & 1 deletion kubernetes/loculus/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ logo:
url: "/favicon.svg"
width: 100
height: 100
instances:
defaultOrganisms:
dummy-organism:
schema:
image: "https://www.un.org/sites/un2.un.org/files/field/image/1583952355.1997.jpg"
Expand Down
6 changes: 3 additions & 3 deletions website/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export type Organism = {
};

export function getConfiguredOrganisms() {
return Object.entries(getWebsiteConfig().instances).map(([key, instance]) => ({
return Object.entries(getWebsiteConfig().organisms).map(([key, instance]) => ({
key,
displayName: instance.schema.instanceName,
image: instance.schema.image,
Expand All @@ -41,10 +41,10 @@ export function getConfiguredOrganisms() {

function getConfig(organism: string): InstanceConfig {
const websiteConfig = getWebsiteConfig();
if (!(organism in websiteConfig.instances)) {
if (!(organism in websiteConfig.organisms)) {
throw new Error(`No configuration for organism ${organism}`);
}
return websiteConfig.instances[organism];
return websiteConfig.organisms[organism];
}

export function getSchema(organism: string): Schema {
Expand Down
2 changes: 1 addition & 1 deletion website/src/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const logoConfig = z.object({
});

export const websiteConfig = z.object({
instances: z.record(instanceConfig),
organisms: z.record(instanceConfig),
name: z.string(),
logo: logoConfig,
});
Expand Down

0 comments on commit ed8e4eb

Please sign in to comment.