mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(mwaa): accept every Airflow 2.x version Amazon MWAA offers (#8394)
The default supported-versions list held 2.10.5, 2.9.3 and 2.8.4, none of which real MWAA offers, so a CreateEnvironment with an AirflowVersion AWS accepts (2.9.2, 2.10.3, 2.11.0 and the rest) failed validation. Add 2.7.2, 2.8.1, 2.9.2, 2.10.1, 2.10.3, 2.11.0 and 2.11.2 to the default list and keep the three versions Floci already offered. With 2.7.2 offered, the CLI proxy refuses "providers notifications" below Airflow 2.8, as AWS's CLI reference lists it from v2.8 only.
This commit is contained in:
1 parent
4c7f057072
commit
fb3c93018e
7 files changed
+53
-25
No files matched your search
@@ -4010,8 +4010,9 @@ public interface EmulatorConfig {
|
||||
/** Airflow versions environments may request. Combined with the image tag
|
||||
* {@code apache/airflow:<version>-<pythonTag>}, where the Python tag matches the
|
||||
* version real Amazon MWAA runs for that Airflow version: see
|
||||
* {@code MwaaEnvironmentManager.pythonTagFor}. */
|
||||
@WithDefault("2.10.5,2.9.3,2.8.4")
|
||||
* {@code MwaaEnvironmentManager.pythonTagFor}. The default is every Airflow 2.x version
|
||||
* Amazon MWAA offers, plus 2.10.5, 2.9.3 and 2.8.4, which Floci offered first. */
|
||||
@WithDefault("2.11.2,2.11.0,2.10.5,2.10.3,2.10.1,2.9.3,2.9.2,2.8.4,2.8.1,2.7.2")
|
||||
List<String> supportedVersions();
|
||||
|
||||
/** Airflow version used when {@code CreateEnvironment} omits {@code AirflowVersion}. */
|
||||
|
||||
@@ -386,9 +386,10 @@ public class MwaaEnvironmentManager {
|
||||
* arguments with POSIX quoting rules and executed without a shell, so shell syntax such as
|
||||
* {@code ;}, {@code |} or {@code $(...)} reaches Airflow as plain arguments.
|
||||
*/
|
||||
public ContainerExec.Result runAirflowCli(String airflowContainerId, String cliCommand) throws Exception {
|
||||
public ContainerExec.Result runAirflowCli(String airflowContainerId, String airflowVersion, String cliCommand)
|
||||
throws Exception {
|
||||
List<String> arguments = splitCliArguments(cliCommand);
|
||||
if (!isSupportedCliCommand(arguments)) {
|
||||
if (!isSupportedCliCommand(arguments, airflowVersion)) {
|
||||
return new ContainerExec.Result(1, "", "Command is not supported by Amazon MWAA\n", false);
|
||||
}
|
||||
List<String> argv = new ArrayList<>();
|
||||
@@ -397,7 +398,7 @@ public class MwaaEnvironmentManager {
|
||||
return execInContainer(airflowContainerId, argv.toArray(new String[0]));
|
||||
}
|
||||
|
||||
static boolean isSupportedCliCommand(List<String> arguments) {
|
||||
static boolean isSupportedCliCommand(List<String> arguments, String airflowVersion) {
|
||||
if (arguments.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
@@ -405,7 +406,14 @@ public class MwaaEnvironmentManager {
|
||||
return true;
|
||||
}
|
||||
Set<String> subcommands = MWAA_CLI_SUBCOMMANDS.get(arguments.getFirst());
|
||||
return arguments.size() >= 2 && subcommands != null && subcommands.contains(arguments.get(1));
|
||||
if (arguments.size() < 2 || subcommands == null || !subcommands.contains(arguments.get(1))) {
|
||||
return false;
|
||||
}
|
||||
// Amazon MWAA's CLI reference lists "providers notifications" from v2.8 on. It is the one
|
||||
// command above whose minimum is newer than v2.7.2, the oldest version MWAA still offers.
|
||||
boolean providersNotifications = "providers".equals(arguments.getFirst())
|
||||
&& "notifications".equals(arguments.get(1));
|
||||
return !providersNotifications || isAtLeast(airflowVersion, 2, 8);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -523,10 +531,14 @@ public class MwaaEnvironmentManager {
|
||||
* every 3.x release) runs Python 3.12.
|
||||
*/
|
||||
static String pythonTagFor(String airflowVersion) {
|
||||
return isAtLeast(airflowVersion, 2, 11) ? "python3.12" : "python3.11";
|
||||
}
|
||||
|
||||
static boolean isAtLeast(String airflowVersion, int major, int minor) {
|
||||
String[] parts = airflowVersion.split("\\.", 3);
|
||||
int major = Integer.parseInt(parts[0]);
|
||||
int minor = parts.length > 1 ? Integer.parseInt(parts[1]) : 0;
|
||||
return (major > 2 || (major == 2 && minor >= 11)) ? "python3.12" : "python3.11";
|
||||
int actualMajor = Integer.parseInt(parts[0]);
|
||||
int actualMinor = parts.length > 1 ? Integer.parseInt(parts[1]) : 0;
|
||||
return actualMajor > major || (actualMajor == major && actualMinor >= minor);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -174,7 +174,7 @@ public class MwaaService implements TagHandler {
|
||||
proxyManager.startProxy(environmentIdentity(environment), proxyPort,
|
||||
environment.getAirflowInternalHost(), environment.getAirflowInternalPort(),
|
||||
this::isValidCliToken,
|
||||
cliCommand -> environmentManager.runAirflowCli(airflowContainerId, cliCommand));
|
||||
cliCommand -> environmentManager.runAirflowCli(airflowContainerId, version, cliCommand));
|
||||
provisioned = true;
|
||||
} catch (Exception e) {
|
||||
LOG.errorv(e, "Failed to start MWAA environment {0}", name);
|
||||
|
||||
Reference in new issue
Block a user