feat(opensearch): support OpenSearch 3.x, validate engine versions, real ES 7.10 OSS image (#1025)

Centralizes engine versions in a new OpenSearchVersions catalog and
threads them through CreateDomain / UpdateDomainConfig / UpgradeDomain
validation plus per-version Docker image resolution.

- Adds OpenSearch 3.0–3.6 and 2.15 / 2.17 / 2.19 to the supported list;
  default version is now OpenSearch_2.19 (was 2.11).
- EngineVersion now maps to a concrete image tag at start time, so
  CreateDomain --engine-version=OpenSearch_3.6 actually pulls
  opensearchproject/opensearch:3.6.0 instead of always pulling the
  default 2.x rolling tag.
- Elasticsearch_7.10 / 7.9 / 7.8 now resolve to their OSS images on
  docker.elastic.co; previously these versions were advertised but the
  service silently ran an OpenSearch 2.x container under the hood.
- OpenSearch 2.12+ start scripts require OPENSEARCH_INITIAL_ADMIN_PASSWORD
  even when the security plugin is disabled. Set automatically.
- The Elasticsearch OSS distribution ships without x-pack, so any xpack.*
  setting is rejected as an unknown setting at boot. Don't touch xpack
  env on Elasticsearch_* domains.
- CreateDomain / UpdateDomainConfig / UpgradeDomain now reject unknown
  engine versions and unsupported upgrade hops with ValidationException.
- GetCompatibleVersions returns the full source→targets matrix when
  domainName is omitted and a single domain-scoped row when set, matching
  AWS's documented behavior.
- INSTANCE_TYPES catalog gains Graviton2/3 (m6g, r6g, c6g, m7g, r7g, c7g)
  and or1.* OpenSearch-optimized families that AWS now exposes.

Tests: 44 OpenSearch tests pass (31 integration + 13 new
OpenSearchVersionsTest unit tests). All four engine version paths
exercised live against Docker (OS 3.6, OS 2.11, ES 7.10 OSS, unknown
version rejection).
This commit is contained in:
Shubham Srivastava authored and GitHub committed 2026-05-25 11:47:06 -05:00
1 parent bd5ba4a224
commit 89d405316d
11 files changed
+482 -33

No files matched your search

@@ -639,8 +639,14 @@ public interface EmulatorConfig {
@WithDefault("false")
boolean mock();
@WithDefault("opensearchproject/opensearch:2")
String defaultImage();
/**
* Optional fixed image used for every domain regardless of the
* requested {@code EngineVersion}. Useful for operators running a
* private registry mirror or pinning a specific patch tag. When unset
* (the common case), images resolve from
* {@code OpenSearchVersions.imageFor(...)} per the requested version.
*/
Optional<String> defaultImage();
@WithDefault("9400")
int proxyBasePort();
@@ -31,17 +31,18 @@ public class OpenSearchController {
private static final Logger LOG = Logger.getLogger(OpenSearchController.class);
private static final List<String> SUPPORTED_VERSIONS = List.of(
"OpenSearch_2.13", "OpenSearch_2.11", "OpenSearch_2.9", "OpenSearch_2.7",
"OpenSearch_2.5", "OpenSearch_2.3", "OpenSearch_1.3", "OpenSearch_1.2",
"Elasticsearch_7.10", "Elasticsearch_7.9", "Elasticsearch_7.8"
);
private static final List<String> INSTANCE_TYPES = List.of(
"t3.small.search", "t3.medium.search",
"m5.large.search", "m5.xlarge.search", "m5.2xlarge.search",
"m6g.large.search", "m6g.xlarge.search", "m6g.2xlarge.search",
"m7g.large.search", "m7g.xlarge.search", "m7g.2xlarge.search",
"r5.large.search", "r5.xlarge.search", "r5.2xlarge.search",
"c5.large.search", "c5.xlarge.search", "c5.2xlarge.search"
"r6g.large.search", "r6g.xlarge.search", "r6g.2xlarge.search",
"r7g.large.search", "r7g.xlarge.search", "r7g.2xlarge.search",
"c5.large.search", "c5.xlarge.search", "c5.2xlarge.search",
"c6g.large.search", "c6g.xlarge.search", "c6g.2xlarge.search",
"c7g.large.search", "c7g.xlarge.search", "c7g.2xlarge.search",
"or1.medium.search", "or1.large.search", "or1.xlarge.search", "or1.2xlarge.search"
);
private final OpenSearchService service;
@@ -266,7 +267,7 @@ public class OpenSearchController {
public Response listVersions(@Context HttpHeaders headers) {
ObjectNode response = objectMapper.createObjectNode();
ArrayNode versions = response.putArray("Versions");
SUPPORTED_VERSIONS.forEach(versions::add);
OpenSearchVersions.supportedVersions().forEach(versions::add);
return Response.ok(response).build();
}
@@ -277,12 +278,25 @@ public class OpenSearchController {
ObjectNode response = objectMapper.createObjectNode();
ArrayNode compatibleVersions = response.putArray("CompatibleVersions");
ObjectNode entry = objectMapper.createObjectNode();
entry.put("SourceVersion", "OpenSearch_2.9");
ArrayNode targets = entry.putArray("TargetVersions");
targets.add("OpenSearch_2.11");
targets.add("OpenSearch_2.13");
compatibleVersions.add(entry);
// When domainName is set, narrow the response to that domain's source
// version — matches AWS's GetCompatibleVersions behavior. Otherwise
// return the full matrix so SDK clients can render upgrade pickers.
if (domainName != null && !domainName.isBlank()) {
String sourceVersion = service.describeDomain(domainName).getEngineVersion();
ObjectNode entry = objectMapper.createObjectNode();
entry.put("SourceVersion", sourceVersion);
ArrayNode targets = entry.putArray("TargetVersions");
OpenSearchVersions.compatibleTargets(sourceVersion).forEach(targets::add);
compatibleVersions.add(entry);
} else {
OpenSearchVersions.compatibilityMatrix().forEach((source, targetList) -> {
ObjectNode entry = objectMapper.createObjectNode();
entry.put("SourceVersion", source);
ArrayNode targets = entry.putArray("TargetVersions");
targetList.forEach(targets::add);
compatibleVersions.add(entry);
});
}
return Response.ok(response).build();
}
@@ -47,11 +47,11 @@ public class OpenSearchDomainManager {
}
public void startDomain(Domain domain) {
String image = config.services().opensearch().defaultImage();
String image = resolveImage(domain.getEngineVersion());
String containerName = "floci-opensearch-" + domain.getDomainName();
LOG.infov("Starting OpenSearch container for domain: {0} using image {1}",
domain.getDomainName(), image);
LOG.infov("Starting OpenSearch container for domain: {0} (version={1}, image={2})",
domain.getDomainName(), domain.getEngineVersion(), image);
int hostPort = portAllocator.allocate(
config.services().opensearch().proxyBasePort(),
@@ -62,11 +62,12 @@ public class OpenSearchDomainManager {
ContainerBuilder.Builder specBuilder = containerBuilder.newContainer(image)
.withName(containerName)
.withEnv("discovery.type", "single-node")
.withEnv("DISABLE_SECURITY_PLUGIN", "true")
.withPortBinding(OPENSEARCH_PORT, hostPort)
.withDockerNetwork(config.services().dockerNetwork())
.withLogRotation();
applyEngineEnv(specBuilder, domain.getEngineVersion());
if (ContainerStorageHelper.isNamedVolumeMode(config)) {
ContainerStorageHelper.applyStorage(specBuilder, lifecycleManager,
"opensearch", domain.getVolumeId(), domain.getDomainName(),
@@ -135,4 +136,51 @@ public class OpenSearchDomainManager {
ContainerStorageHelper.removeStorage(config, lifecycleManager,
"opensearch", domain.getVolumeId(), domain.getDomainName());
}
private String resolveImage(String engineVersion) {
return OpenSearchVersions.resolveImage(
config.services().opensearch().defaultImage(), engineVersion);
}
/**
* Engine env that differs between OpenSearch lines and Elasticsearch. Both
* the security-plugin disable flag and the v2.12+ initial admin password
* are baked here rather than the call site so the {@link #startDomain}
* builder chain stays linear.
*/
private void applyEngineEnv(ContainerBuilder.Builder specBuilder, String engineVersion) {
if (engineVersion != null && engineVersion.startsWith("Elasticsearch")) {
// The OSS distribution of Elasticsearch ships without x-pack, so
// any xpack.* setting is rejected as unknown and the node refuses
// to boot. The default OSS build has no security plugin to disable
// — leave the env empty and let the image use its bare defaults.
return;
}
specBuilder.withEnv("DISABLE_SECURITY_PLUGIN", "true");
// OpenSearch 2.12+ refuses to start without an initial admin password
// even when the security plugin is disabled (the bootstrap check fires
// before plugin config). Provide a fixed value — the security plugin
// is off so this isn't a real credential.
if (requiresInitialAdminPassword(engineVersion)) {
specBuilder.withEnv("OPENSEARCH_INITIAL_ADMIN_PASSWORD", "FlociAdmin1!");
}
}
private boolean requiresInitialAdminPassword(String engineVersion) {
if (engineVersion == null || !engineVersion.startsWith("OpenSearch_")) {
return false;
}
String numeric = engineVersion.substring("OpenSearch_".length());
int dot = numeric.indexOf('.');
if (dot < 0) {
return false;
}
try {
int major = Integer.parseInt(numeric.substring(0, dot));
int minor = Integer.parseInt(numeric.substring(dot + 1));
return major > 2 || (major == 2 && minor >= 12);
} catch (NumberFormatException e) {
return false;
}
}
}
@@ -30,7 +30,7 @@ public class OpenSearchService {
private static final Logger LOG = Logger.getLogger(OpenSearchService.class);
private static final String DEFAULT_ENGINE_VERSION = "OpenSearch_2.11";
private static final String DEFAULT_ENGINE_VERSION = OpenSearchVersions.DEFAULT_VERSION;
private final StorageBackend<String, Domain> domainStore;
private final EmulatorConfig config;
@@ -76,6 +76,7 @@ public class OpenSearchService {
public Domain createDomain(String domainName, String engineVersion, ClusterConfig clusterConfig,
EbsOptions ebsOptions, Map<String, String> tags, String region) {
validateDomainName(domainName);
OpenSearchVersions.validate(engineVersion);
if (domainStore.get(domainName).isPresent()) {
throw new AwsException("ResourceAlreadyExistsException",
@@ -143,6 +144,7 @@ public class OpenSearchService {
ClusterConfig clusterConfig, EbsOptions ebsOptions,
String region) {
Domain domain = describeDomain(domainName);
OpenSearchVersions.validate(engineVersion);
if (engineVersion != null && !engineVersion.isBlank()) {
domain.setEngineVersion(engineVersion);
@@ -203,10 +205,13 @@ public class OpenSearchService {
public Domain upgradeDomain(String domainName, String targetVersion) {
Domain domain = describeDomain(domainName);
if (targetVersion != null && !targetVersion.isBlank()) {
domain.setEngineVersion(targetVersion);
domainStore.put(domainName, domain);
if (targetVersion == null || targetVersion.isBlank()) {
throw new AwsException("ValidationException",
"TargetVersion is required for UpgradeDomain.", 400);
}
OpenSearchVersions.validateUpgrade(domain.getEngineVersion(), targetVersion);
domain.setEngineVersion(targetVersion);
domainStore.put(domainName, domain);
return domain;
}
@@ -0,0 +1,170 @@
package io.github.hectorvent.floci.services.opensearch;
import io.github.hectorvent.floci.core.common.AwsException;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
/**
* Catalog of OpenSearch / Elasticsearch engine versions Floci can advertise on
* {@code ListVersions} and validate against on {@code CreateDomain} /
* {@code UpdateDomainConfig} / {@code UpgradeDomain}.
*
* <p>Each entry maps an AWS-shaped engine version (e.g. {@code OpenSearch_3.0})
* to the Docker image tag that {@link OpenSearchDomainManager} pulls when the
* service runs in real-container mode. Without this map, every domain would
* boot whatever {@code opensearchproject/opensearch:2} resolved to at pull
* time, regardless of the user-requested {@code EngineVersion} — a footgun for
* anyone testing version-specific behavior (mapping changes between OS 2 and
* 3, plugin compatibility, removed APIs, etc.).
*
* <p>The Elasticsearch 7.10 entry deliberately points at the last
* Apache-2-licensed image ({@code elasticsearch-oss:7.10.2}). Newer
* Elasticsearch releases ship under the Elastic License v2 / SSPL and are
* intentionally out of scope.
*/
public final class OpenSearchVersions {
/**
* Default engine version when {@code CreateDomain} omits {@code EngineVersion}.
* Tracks the latest 2.x LTS-style line that's broadly compatible with
* Elasticsearch 7.10 client SDKs (the most common reason users still use
* Floci's OpenSearch surface).
*/
public static final String DEFAULT_VERSION = "OpenSearch_2.19";
private static final Map<String, String> VERSION_TO_IMAGE = new LinkedHashMap<>();
private static final Map<String, List<String>> COMPAT_MATRIX = new LinkedHashMap<>();
static {
// OpenSearch 3.x line — pinned to a concrete image tag rather than the
// floating "3" alias so test runs are reproducible.
VERSION_TO_IMAGE.put("OpenSearch_3.6", "opensearchproject/opensearch:3.6.0");
VERSION_TO_IMAGE.put("OpenSearch_3.5", "opensearchproject/opensearch:3.5.0");
VERSION_TO_IMAGE.put("OpenSearch_3.4", "opensearchproject/opensearch:3.4.0");
VERSION_TO_IMAGE.put("OpenSearch_3.3", "opensearchproject/opensearch:3.3.2");
VERSION_TO_IMAGE.put("OpenSearch_3.2", "opensearchproject/opensearch:3.2.0");
VERSION_TO_IMAGE.put("OpenSearch_3.1", "opensearchproject/opensearch:3.1.0");
VERSION_TO_IMAGE.put("OpenSearch_3.0", "opensearchproject/opensearch:3.0.0");
// OpenSearch 2.x — keep the historical entries Floci already accepted,
// bump the head to 2.19.5 (current latest 2.x as of 2026-05).
VERSION_TO_IMAGE.put("OpenSearch_2.19", "opensearchproject/opensearch:2.19.5");
VERSION_TO_IMAGE.put("OpenSearch_2.17", "opensearchproject/opensearch:2.17.1");
VERSION_TO_IMAGE.put("OpenSearch_2.15", "opensearchproject/opensearch:2.15.0");
VERSION_TO_IMAGE.put("OpenSearch_2.13", "opensearchproject/opensearch:2.13.0");
VERSION_TO_IMAGE.put("OpenSearch_2.11", "opensearchproject/opensearch:2.11.1");
VERSION_TO_IMAGE.put("OpenSearch_2.9", "opensearchproject/opensearch:2.9.0");
VERSION_TO_IMAGE.put("OpenSearch_2.7", "opensearchproject/opensearch:2.7.0");
VERSION_TO_IMAGE.put("OpenSearch_2.5", "opensearchproject/opensearch:2.5.0");
VERSION_TO_IMAGE.put("OpenSearch_2.3", "opensearchproject/opensearch:2.3.0");
// OpenSearch 1.x — kept for legacy upgrade paths (1.x → 2.x).
VERSION_TO_IMAGE.put("OpenSearch_1.3", "opensearchproject/opensearch:1.3.20");
VERSION_TO_IMAGE.put("OpenSearch_1.2", "opensearchproject/opensearch:1.2.4");
// Elasticsearch 7.x — last Apache-2 OSS line. Image is on Elastic's
// registry, not Docker Hub; image string includes the host so the
// Docker daemon doesn't try to resolve it under {@code library/}.
VERSION_TO_IMAGE.put("Elasticsearch_7.10", "docker.elastic.co/elasticsearch/elasticsearch-oss:7.10.2");
VERSION_TO_IMAGE.put("Elasticsearch_7.9", "docker.elastic.co/elasticsearch/elasticsearch-oss:7.9.3");
VERSION_TO_IMAGE.put("Elasticsearch_7.8", "docker.elastic.co/elasticsearch/elasticsearch-oss:7.8.1");
// Compatibility matrix — mirrors AWS OpenSearch's allowed in-place
// upgrade hops. Source versions that are still on the supported list
// but that AWS no longer lets you upgrade out of are intentionally
// omitted.
//
// Per AWS's version-migration guide, OpenSearch 1.3 / 2.x domains must
// first upgrade to OpenSearch_2.19 before they can hop to the 3.x
// line, so non-2.19 2.x sources do NOT list any 3.x targets directly.
// https://docs.aws.amazon.com/opensearch-service/latest/developerguide/version-migration.html
COMPAT_MATRIX.put("Elasticsearch_7.10", List.of("OpenSearch_1.3", "OpenSearch_2.19"));
COMPAT_MATRIX.put("OpenSearch_1.3", List.of("OpenSearch_2.19", "OpenSearch_2.17", "OpenSearch_2.15", "OpenSearch_2.13"));
COMPAT_MATRIX.put("OpenSearch_2.19", List.of("OpenSearch_3.0", "OpenSearch_3.1", "OpenSearch_3.6"));
COMPAT_MATRIX.put("OpenSearch_2.17", List.of("OpenSearch_2.19"));
COMPAT_MATRIX.put("OpenSearch_2.15", List.of("OpenSearch_2.19"));
COMPAT_MATRIX.put("OpenSearch_2.13", List.of("OpenSearch_2.19"));
COMPAT_MATRIX.put("OpenSearch_2.11", List.of("OpenSearch_2.13", "OpenSearch_2.19"));
COMPAT_MATRIX.put("OpenSearch_2.9", List.of("OpenSearch_2.11", "OpenSearch_2.13"));
COMPAT_MATRIX.put("OpenSearch_3.0", List.of("OpenSearch_3.1", "OpenSearch_3.6"));
COMPAT_MATRIX.put("OpenSearch_3.1", List.of("OpenSearch_3.2", "OpenSearch_3.6"));
}
private OpenSearchVersions() {
}
/** Versions advertised on {@code ListVersions}, newest-first. */
public static List<String> supportedVersions() {
return List.copyOf(VERSION_TO_IMAGE.keySet());
}
/**
* Pick the image for a domain, honoring an optional operator-supplied
* override that applies to every domain regardless of
* {@code engineVersion} (private registry mirror, pinned patch). When the
* override is absent we delegate to {@link #imageFor(String)}.
*/
public static String resolveImage(Optional<String> override, String engineVersion) {
return override.orElseGet(() -> imageFor(engineVersion));
}
/**
* Docker image to pull for {@code engineVersion}. Falls back to the
* default-version image only when {@code engineVersion} is null/blank;
* unknown versions throw — call {@link #validate(String)} first.
*/
public static String imageFor(String engineVersion) {
if (engineVersion == null || engineVersion.isBlank()) {
return VERSION_TO_IMAGE.get(DEFAULT_VERSION);
}
String image = VERSION_TO_IMAGE.get(engineVersion);
if (image == null) {
throw new AwsException("ValidationException",
"Unsupported EngineVersion: " + engineVersion, 400);
}
return image;
}
/** Targets reachable from {@code sourceVersion}, empty if no upgrade path is defined. */
public static List<String> compatibleTargets(String sourceVersion) {
return COMPAT_MATRIX.getOrDefault(sourceVersion, List.of());
}
/** Every {@code (source, targets)} pair in the matrix, in declaration order. */
public static Map<String, List<String>> compatibilityMatrix() {
return Map.copyOf(COMPAT_MATRIX);
}
/**
* Throws {@code ValidationException} when {@code engineVersion} is set but
* not in the supported list. A null/blank value is allowed — callers that
* accept an omitted {@code EngineVersion} fall back to {@link #DEFAULT_VERSION}.
*/
public static void validate(String engineVersion) {
if (engineVersion == null || engineVersion.isBlank()) {
return;
}
if (!VERSION_TO_IMAGE.containsKey(engineVersion)) {
throw new AwsException("ValidationException",
"Unsupported EngineVersion: " + engineVersion
+ ". Supported: " + VERSION_TO_IMAGE.keySet(), 400);
}
}
/**
* Throws {@code ValidationException} when {@code targetVersion} is not in
* the supported list, or not a documented upgrade target from {@code sourceVersion}.
*/
public static void validateUpgrade(String sourceVersion, String targetVersion) {
validate(targetVersion);
List<String> allowed = compatibleTargets(sourceVersion);
if (!allowed.contains(targetVersion)) {
throw new AwsException("ValidationException",
"Cannot upgrade from " + sourceVersion + " to " + targetVersion
+ ". Allowed targets: " + allowed, 400);
}
}
}
@@ -24,7 +24,7 @@ public class Domain {
private String arn;
@JsonProperty("EngineVersion")
private String engineVersion = "OpenSearch_2.11";
private String engineVersion;
@JsonProperty("Processing")
private boolean processing = false;