-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Controlling the Migration Assistant Control Plane #1060
Closed
peternied
wants to merge
3
commits into
opensearch-project:main
from
peternied:proto-use-services-yaml-directly
Closed
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,85 +3,28 @@ | |
# Fail the script if any command fails | ||
set -e | ||
|
||
# Print our ENV variables | ||
if [[ $RFS_COMMAND != *"--target-password"* ]]; then | ||
echo "RFS_COMMAND: $RFS_COMMAND" | ||
else | ||
echo "RFS Target Cluster password found in RFS_COMMAND; skipping logging of the value" | ||
fi | ||
|
||
echo "RFS_TARGET_USER: $RFS_TARGET_USER" | ||
echo "RFS_TARGET_PASSWORD: <redacted>" | ||
echo "RFS_TARGET_PASSWORD_ARN: $RFS_TARGET_PASSWORD_ARN" | ||
|
||
# Check if the RFS Command already contains a username; only do special work if it does not | ||
if [[ $RFS_COMMAND != *"--target-username"* ]]; then | ||
if [[ -n "$RFS_TARGET_USER" ]]; then | ||
echo "Using username from ENV variable RFS_TARGET_USER. Updating RFS Command with username." | ||
RFS_COMMAND="$RFS_COMMAND --target-username \"$RFS_TARGET_USER\"" | ||
fi | ||
fi | ||
|
||
# Check if the RFS Command already contains a password; only do special work if it does not | ||
if [[ $RFS_COMMAND != *"--target-password"* ]]; then | ||
PASSWORD_TO_USE="" | ||
|
||
# Check if the password is available in plaintext; if, use it. Otherwise, retrieve it from AWS Secrets Manager | ||
if [[ -n "$RFS_TARGET_PASSWORD" ]]; then | ||
echo "Using plaintext password from ENV variable RFS_TARGET_PASSWORD" | ||
PASSWORD_TO_USE="$RFS_TARGET_PASSWORD" | ||
elif [[ -n "$RFS_TARGET_PASSWORD_ARN" ]]; then | ||
# Retrieve password from AWS Secrets Manager if ARN is provided | ||
echo "Using password from AWS Secrets Manager ARN in ENV variable RFS_TARGET_PASSWORD_ARN" | ||
PASSWORD_TO_USE=$(aws secretsmanager get-secret-value --secret-id "$RFS_TARGET_PASSWORD_ARN" --query SecretString --output text) | ||
fi | ||
|
||
# Append the username/password to the RFS Command if have an updated password | ||
if [[ -n "$PASSWORD_TO_USE" ]]; then | ||
echo "Updating RFS Command with password." | ||
RFS_COMMAND="$RFS_COMMAND --target-password \"$PASSWORD_TO_USE\"" | ||
fi | ||
fi | ||
|
||
# Extract the value passed after --s3-local-dir | ||
S3_LOCAL_DIR=$(echo "$RFS_COMMAND" | sed -n 's/.*--s3-local-dir\s\+\("[^"]\+"\|[^ ]\+\).*/\1/p' | tr -d '"') | ||
# Extract the value passed after --lucene-dir | ||
LUCENE_DIR=$(echo "$RFS_COMMAND" | sed -n 's/.*--lucene-dir\s\+\("[^"]\+"\|[^ ]\+\).*/\1/p' | tr -d '"') | ||
if [[ -n "$S3_LOCAL_DIR" ]]; then | ||
echo "Will delete S3 local directory between runs: $S3_LOCAL_DIR" | ||
else | ||
echo "--s3-local-dir argument not found in RFS_COMMAND. Will not delete S3 local directory between runs." | ||
fi | ||
|
||
if [[ -n "$LUCENE_DIR" ]]; then | ||
echo "Will delete lucene local directory between runs: $LUCENE_DIR" | ||
else | ||
echo "--lucene-dir argument not found in RFS_COMMAND. This is required." | ||
exit 1 | ||
fi | ||
|
||
cleanup_directories() { | ||
if [[ -n "$S3_LOCAL_DIR" ]]; then | ||
echo "Cleaning up S3 local directory: $S3_LOCAL_DIR" | ||
rm -rf "$S3_LOCAL_DIR" | ||
echo "Directory $S3_LOCAL_DIR has been cleaned up." | ||
fi | ||
|
||
if [[ -n "$LUCENE_DIR" ]]; then | ||
echo "Cleaning up Lucene local directory: $LUCENE_DIR" | ||
rm -rf "$LUCENE_DIR" | ||
echo "Directory $LUCENE_DIR has been cleaned up." | ||
fi | ||
} | ||
|
||
|
||
# Discussion needed: Container will have a minimum number of | ||
# parameters after on start services.yaml is loaded. | ||
# | ||
# This script was parsing the parameters that were feed into the | ||
# container, unless this script is pulling parameters from the | ||
# services.yaml its going to be out of sync. | ||
# | ||
# Metadata & Snapshot will already need to know how to read the | ||
# Secrets from ARNs so this seems like it aligns well to do this | ||
# at the same time. | ||
|
||
# Discussion needed: Directly cleanup was being done by script based | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧵 For Discussion |
||
# on arguments | ||
# | ||
# Alternative, java can clean these directories on start since this script | ||
# won't be able to resolve the path(s) without parsing the services.yaml | ||
|
||
[ -z "$RFS_COMMAND" ] && \ | ||
{ echo "Warning: RFS_COMMAND is empty! Exiting."; exit 1; } || \ | ||
until ! { | ||
echo "Running command $RFS_COMMAND" | ||
eval "$RFS_COMMAND" | ||
}; do | ||
echo "Cleaning up directories before the next run." | ||
cleanup_directories | ||
echo "About to start the next run." | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
import org.opensearch.migrations.tracing.CompositeContextTracker; | ||
import org.opensearch.migrations.tracing.RootOtelContext; | ||
import org.opensearch.migrations.utils.ProcessHelpers; | ||
import org.opensearch.migrations.config.MigrationConfig; | ||
|
||
import com.beust.jcommander.JCommander; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
@@ -22,15 +23,62 @@ | |
public class MetadataMigration { | ||
|
||
public static void main(String[] args) throws Exception { | ||
|
||
var metadataArgs = new MetadataArgs(); | ||
var migrateArgs = new MigrateArgs(); | ||
// Note; need to handle these effectively duplicated parsed args | ||
var evaluateArgs = new EvaluateArgs(); | ||
var jCommander = JCommander.newBuilder() | ||
|
||
// Load from the command line first | ||
JCommander.newBuilder() | ||
.addObject(metadataArgs) | ||
.addCommand(migrateArgs) | ||
.addCommand(evaluateArgs) | ||
.build(); | ||
jCommander.parse(args); | ||
.build() | ||
.parse(args); | ||
|
||
// Then override with settings | ||
var config = getConfig(args); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧵 For Discussion |
||
if (config != null) { | ||
metadataArgs.otelCollectorEndpoint = config.metadata_migration.otel_endpoint; | ||
|
||
// Note; we've got some serious null ref risk in this block of code, will need to use a lot of optionals. | ||
migrateArgs.dataFilterArgs.indexAllowlist = config.metadata_migration.index_allowlist; | ||
migrateArgs.dataFilterArgs.indexTemplateAllowlist = config.metadata_migration.index_template_allowlist; | ||
migrateArgs.dataFilterArgs.componentTemplateAllowlist = config.metadata_migration.component_template_allowlist; | ||
|
||
migrateArgs.fileSystemRepoPath = config.snapshot.fs.repo_path; | ||
migrateArgs.snapshotName = config.snapshot.snapshot_name; | ||
migrateArgs.s3LocalDirPath = config.metadata_migration.local_dir; | ||
migrateArgs.s3Region = config.snapshot.s3.aws_region; | ||
migrateArgs.s3RepoUri = config.snapshot.s3.repo_uri; | ||
|
||
migrateArgs.sourceArgs.host = config.source_cluster.endpoint; | ||
migrateArgs.sourceArgs.username = config.source_cluster.basic_auth.username; | ||
migrateArgs.sourceArgs.password = config.source_cluster.basic_auth.password; | ||
migrateArgs.sourceArgs.awsRegion = config.source_cluster.sigv4.region; | ||
migrateArgs.sourceArgs.awsServiceSigningName = config.source_cluster.sigv4.service; | ||
migrateArgs.sourceArgs.insecure = config.source_cluster.allow_insecure; | ||
|
||
// Need to special case indirect values such as AWS Secrets | ||
if (config.source_cluster.basic_auth.password_from_secret_arn != null) { | ||
migrateArgs.sourceArgs.password = ""; // Load this from AWS and insert into this arg + log a message | ||
} | ||
|
||
migrateArgs.targetArgs.host = config.target_cluster.endpoint; | ||
migrateArgs.targetArgs.username = config.target_cluster.basic_auth.username; | ||
migrateArgs.targetArgs.password = config.target_cluster.basic_auth.password; | ||
migrateArgs.targetArgs.awsRegion = config.target_cluster.sigv4.region; | ||
migrateArgs.targetArgs.awsServiceSigningName = config.target_cluster.sigv4.service; | ||
migrateArgs.targetArgs.insecure = config.target_cluster.allow_insecure; | ||
|
||
// Need to special case indirect values such as AWS Secrets | ||
if (config.target_cluster.basic_auth.password != null) { | ||
migrateArgs.targetArgs.password = ""; // Load this from AWS and insert into this arg + log a message | ||
} | ||
|
||
migrateArgs.minNumberOfReplicas = config.metadata_migration.min_replicas; | ||
} | ||
|
||
var context = new RootMetadataMigrationContext( | ||
RootOtelContext.initializeOpenTelemetryWithCollectorOrAsNoop(metadataArgs.otelCollectorEndpoint, "metadata", | ||
|
@@ -115,4 +163,24 @@ private static void printCommandUsage(JCommander jCommander) { | |
jCommander.getUsageFormatter().usage(jCommander.getParsedCommand(), sb); | ||
log.info(sb.toString()); | ||
} | ||
|
||
private static MigrationConfig getConfig(String[] args) { | ||
var metadataArgs = new MetadataArgs(); | ||
|
||
JCommander.newBuilder() | ||
.addObject(metadataArgs) | ||
.acceptUnknownOptions(true) | ||
.build() | ||
.parse(args); | ||
|
||
if (metadataArgs.configFile != null) { | ||
try { | ||
return MigrationConfig.loadFrom(metadataArgs.configFile); | ||
} catch (Exception e) { | ||
log.warn("Unable to load from config file, falling back to command line arguments."); | ||
} | ||
} | ||
return null; | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧵 For Discussion