Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docker/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ cluster:
name: default-cluster

etcd:
endpoints:
- http://host.docker.internal:2379
# Comma-separated list of etcd endpoints, can be overridden by ETCD_ENDPOINTS env var
endpoints: ${ETCD_ENDPOINTS:http://host.docker.internal:2379}

task:
intervalSeconds: 30
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.clustercontroller.config;

import io.clustercontroller.util.EnvironmentUtils;
import lombok.Data;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -105,14 +106,16 @@ private ConfigModel loadYamlConfig() {

private String[] parseEndpoints(ConfigModel config) {
try {
if (config.getEtcd() != null && config.getEtcd().getEndpoints() != null) {
var endpoints = config.getEtcd().getEndpoints();
if (!endpoints.isEmpty()) {
return endpoints.toArray(new String[0]);
}
// Get from EnvironmentUtils (reads from Spring Environment with env var support)
// Supports comma-separated endpoints: "http://etcd1:2379,http://etcd2:2379"
String endpointsStr = EnvironmentUtils.get("etcd.endpoints");
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe as a follow up change.
I think we should abstract the config parsing into a separate class. but doing this field by field as using environment variable is a common pattern

String[] endpoints = endpointsStr.split(",");
for (int i = 0; i < endpoints.length; i++) {
endpoints[i] = endpoints[i].trim();
}
return endpoints;
} catch (Exception e) {
log.warn("Failed to parse etcd endpoints from config, using defaults: {}", e.getMessage());
log.warn("Failed to get etcd.endpoints from config: {}", e.getMessage());
}

return new String[]{DEFAULT_ETCD_ENDPOINT};
Expand Down Expand Up @@ -169,7 +172,7 @@ public static class ConfigModel {

@Data
public static class Etcd {
private List<String> endpoints;
private String endpoints; // Comma-separated, resolved via Spring: ${ETCD_ENDPOINTS:default}
}

@Data
Expand All @@ -180,6 +183,7 @@ public static class Task {
@Data
public static class Controller {
private String id;
private String runtime_env; // Resolved via Spring: ${RUNTIME_ENV:staging}
private Ttl ttl;
private Keepalive keepalive;
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Application Configuration

etcd:
endpoints:
- http://localhost:2379
# Comma-separated list of etcd endpoints, can be overridden by ETCD_ENDPOINTS env var
endpoints: ${ETCD_ENDPOINTS:http://localhost:2379}

task:
intervalSeconds: 30
Expand Down