Skip to content

Commit

Permalink
removed -i and -o from arguments
Browse files Browse the repository at this point in the history
Signed-off-by: ctartici <[email protected]>
  • Loading branch information
ctartici committed Feb 13, 2025
1 parent 610ea23 commit 01a2e27
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 36 deletions.
14 changes: 7 additions & 7 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -307,27 +307,27 @@ Sail Operator's Istio resource does not have a `spec.components` field. Instead,
This script is used to convert an Istio in-cluster operator configuration to a Sail Operator configuration. Upon execution, the script takes an input YAML file and istio version and generates a sail operator configuration file.

#### Usage
To run the configuration-converter.sh script, you need to provide four arguments, two of which are mandatory. The script uses default values for the optional arguments:
To run the configuration-converter.sh script, you need to provide four arguments, two of which are required:

1. Input file path (-i <input>): The path to your Istio operator configuration YAML file (mandatory).
2. Output file path (-o <output>): The path where the converted Sail configuration will be saved. If not provided, the script will save the output with -sail.yaml appended to the input file name.
1. Input file path (<input>): The path to your Istio operator configuration YAML file (required).
2. Output file path (<output>): The path where the converted Sail configuration will be saved. If not provided, the script will save the output with -sail.yaml appended to the input file name.
3. Namespace (-n <namespace>): The Kubernetes namespace for the Istio deployment. Defaults to istio-system if not provided.
4. Version (-v <version>): The version of Istio to be used (mandatory).
4. Version (-v <version>): The version of Istio to be used (required).

```bash
./tools/configuration-converter.sh -i /path/to/input.yaml -o [optional-output.yaml] -n [optional-namespace] -v [version]
./tools/configuration-converter.sh /path/to/input.yaml [optional-output.yaml] -n [optional-namespace] -v [version]
```

##### Sample command with default namespace and output:

```bash
./tools/configuration-converter.sh -i /home/user/istio_config.yaml -v v1.24.3
./tools/configuration-converter.sh /home/user/istio_config.yaml -v v1.24.3
```

##### Sample command with custom output and namespace:

```bash
./tools/configuration-converter.sh -i /home/user/input/istio_config.yaml -o /home/user/output/output.yaml -n custom-namespace -v v1.24.3
./tools/configuration-converter.sh /home/user/input/istio_config.yaml /home/user/output/output.yaml -n custom-namespace -v v1.24.3
```

> [!WARNING]
Expand Down
12 changes: 5 additions & 7 deletions pkg/converter/converter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,24 +147,22 @@ func saveYamlToFile(input, istioFile string) error {

func executeConfigConverter(input, output, controlPlaneNamespace, istioVersion string) error {
converter := filepath.Join(project.RootDir, "tools", "configuration-converter.sh")
args := []string{
converter,
"-i", input,
"-v", istioVersion,
}
args := []string{converter, input}

if output != "" {
args = append(args, "-o", output)
args = append(args, output)
}

if controlPlaneNamespace != "" {
args = append(args, "-n", controlPlaneNamespace)
}

args = append(args, "-v", istioVersion)

cmd := strings.Join(args, " ")
_, err := shell.ExecuteCommand(cmd)
if err != nil {
return fmt.Errorf("error in execution of %s -i %s -o %s -n %s -v %s: %w", converter, input, output, controlPlaneNamespace, istioVersion, err)
return fmt.Errorf("error in execution of %s %s %s -n %s -v %s: %w", converter, input, output, controlPlaneNamespace, istioVersion, err)
}
return nil
}
Expand Down
51 changes: 29 additions & 22 deletions tools/configuration-converter.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,43 @@
# In the end of the execution new yaml file will be created with "sail-ISTIO_CONFIG_YAML" name.
# Usage: ./configuration-converter.sh ISTIO_CONFIG_YAML_WITH_PATH, example: ./configuration-converter.sh sample_config.yaml"
set -e

# Default values
NAMESPACE="istio-system"
NAMESPACE="${NAMESPACE:-istio-system}"
VERSION=""
INPUT=""
OUTPUT=""

# Function to show usage
usage() {
echo "Usage: $0 -i <input> [-o <output>] [-n <namespace>] [-v <version>]"
echo " -i <input> : Input file (required)"
echo " -o <output> : Output file (optional, defaults to input's base directory with '-sail.yaml' suffix)"
echo "Usage: $0 <input> [output] [-n <namespace>] [-v <version>]"
echo " <input> : Input file (required)"
echo " [output] : Output file (optional, defaults to input's base directory with '-sail.yaml' suffix)"
echo " -n <namespace> : Namespace (optional, defaults to 'istio-system')"
echo " -v <version> : Version (optional)"
echo " -v <version> : Istio Version (required)"
exit 1
}

# Parse command-line arguments
# Ensure input file is provided
if [[ -z "$1" ]]; then
echo "Error: Input file is required."
usage
fi

INPUT="$1"
OUTPUT="$2"

# Shift parameters if output is provided
if [[ -n "$OUTPUT" && "$OUTPUT" != -* ]]; then
shift 2
else
OUTPUT="$(dirname "$INPUT")/$(basename "$INPUT" .yaml)-sail.yaml"
shift 1
fi

# Parse optional namespace and version arguments
while [[ $# -gt 0 ]]; do
case "$1" in
-i)
INPUT="$2"
shift 2
;;
-o)
OUTPUT="$2"
shift 2
;;
-n)
NAMESPACE="$2"
shift 2
Expand All @@ -59,16 +69,13 @@ while [[ $# -gt 0 ]]; do
esac
done

# Ensure input file is provided
if [[ -z "$INPUT" ]]; then
echo "Error: Input file is required."
if [[ -z "$VERSION" ]]; then
echo "Error: Version (-v) is required."
usage
fi

# Set default output file if not provided.
if [[ -z "$OUTPUT" ]]; then
OUTPUT="$(dirname "$INPUT")/$(basename "$INPUT" .yaml)-sail.yaml"
elif [[ -d "$OUTPUT" ]]; then
# Ensure output is not a directory
if [[ -d "$OUTPUT" ]]; then
echo "Error: OUTPUT must be a file, not a directory."
exit 1
fi
Expand Down Expand Up @@ -103,7 +110,7 @@ function boolean_2_string(){
# Note that if there is an entry except spec.components.<component>.enabled: true/false converter will delete them and warn user
function validate_spec_components(){
yq -i 'del(.spec.components.[] | keys[] | select(. != "enabled")) | .spec.values *= .spec.components | del (.spec.components)' "$OUTPUT"
echo "Values only spec.components.<component>.enabled: true/false are supported for conversion. Please see https://github.com/istio-ecosystem/sail-operator/tree/main/docs#components-field"
echo "Only values in the format spec.components.<component>.enabled: true/false are supported for conversion. For more details, refer to the documentation: https://github.com/istio-ecosystem/sail-operator/tree/main/docs#components-field"
}

# create output file
Expand Down

0 comments on commit 01a2e27

Please sign in to comment.