Skip to content

Commit

Permalink
converter for istio in-cluster operator config to sail operator config
Browse files Browse the repository at this point in the history
Signed-off-by: ctartici <[email protected]>
Signed-off-by: ubuntu <[email protected]>
  • Loading branch information
ctartici committed Feb 5, 2025
1 parent 2a9e854 commit 50d9b8b
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 0 deletions.
16 changes: 16 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,22 @@ Note the quotes around the value of `spec.values.pilot.env.PILOT_ENABLE_STATUS`.

Sail Operator's Istio resource does not have a `spec.components` field. Instead, you can enable and disable components directly by setting `spec.values.<component>.enabled: true/false`. Other functionality exposed through `spec.components` like the k8s overlays is not currently available.

### Converter Script
This script is used to convert an Istio in-cluster operator configuration to a Sail Operator configuration. Upon execution, a new YAML file will be created in the same directory which ISTIO-OPERATOR-CONFIG-YAML is present. The new file will be named: sail-operator-config.yaml

#### Usage
It is necessary to set ISTIO_VERSION and ISTIO_NAMESPACE as environment variables to be able to run the script.

```bash
export ISTIO_VERSION=v1.23.0
export ISTIO_NAMESPACE=istio-system
./tools/configuration-converter.sh <ISTIO_OPERATOR_CONFIG_YAML_WITH_PATH>
```

> [!WARNING]
> This script is still under development.
> Please verify the resulting configuration carefully after conversion to ensure it meets your expectations and requirements.

### CNI

The CNI plugin's lifecycle is managed separately from the control plane. You will have to create a [IstioCNI resource](#istiocni-resource) to use CNI.
Expand Down
83 changes: 83 additions & 0 deletions tools/configuration-converter.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#!/bin/bash

# Copyright Istio Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# This script is used to convert istio configuration to sail operator configuration.
# 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"

if [[ -z $ISTIO_VERSION || -z $ISTIO_NAMESPACE ]]; then
echo "ISTIO_VERSION and ISTIO_NAMESPACE should be set as environment variable to execute converter."
exit
fi

WORKDIR=$(dirname "$1")
ISTIO_CONFIG_FILE=$(basename "$1")
SAIL_CONFIG_FILE="sail-operator-config.yaml"

cd "$WORKDIR" || exit
cp "$ISTIO_CONFIG_FILE" "$SAIL_CONFIG_FILE"

function add_mandatory_fields(){
sail_api=".apiVersion=\"sailoperator.io/v1alpha1\""
sail_kind=".kind=\"Istio\""
sail_metadata_name=".metadata.name=\"default\""
sail_istio_version=".spec.version=\"$ISTIO_VERSION\""
sail_istio_namespace=".spec.namespace=\"$ISTIO_NAMESPACE\""
sail_config_array=("$sail_api" "$sail_kind" "$sail_istio_version" "$sail_istio_namespace" "$sail_metadata_name")
for i in "${sail_config_array[@]}";
do
cat $SAIL_CONFIG_FILE | yq "$i" > tmp.yaml
mv tmp.yaml $SAIL_CONFIG_FILE
done
}

#Convert boolean values to string if they are under *.env
function boolean_2_string(){
SPEC_FIELDS="$(yq -r $SAIL_CONFIG_FILE | yq '(.spec.values.[].env)')"
if [ -n "$SPEC_FIELDS" ] ;then
cat $SAIL_CONFIG_FILE | yq '(.spec.values.[].env.[] | select(. == true)) |= "true"' > tmp.yaml
mv tmp.yaml $SAIL_CONFIG_FILE
cat $SAIL_CONFIG_FILE | yq '(.spec.values.[].env.[] | select(. == false)) |= "false"' | sed '/env: \[\]/d' > tmp.yaml
mv tmp.yaml $SAIL_CONFIG_FILE
rm tmp.yaml
fi
}

# 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(){
COMPONENTS="$(yq -r $SAIL_CONFIG_FILE 2>/dev/null | yq '(.spec.components)' 2>/dev/null)"
if [ "$COMPONENTS" == null ] ;then
return 1
else
COMPONENTS_FIELDS="$(yq -r $SAIL_CONFIG_FILE 2>/dev/null | yq '(.spec.components.[] | keys[])' 2>/dev/null)"
if [[ -n "$COMPONENTS_FIELDS" && "$COMPONENTS_FIELDS" =~ "enabled" ]] ;then
cat $SAIL_CONFIG_FILE | yq 'del(.spec.components.[] | keys[] | select(. != "enabled"))' | yq '.spec.values *= .spec.components | del (.spec.components)' > tmp.yaml
mv tmp.yaml $SAIL_CONFIG_FILE
echo "Converter can only be used values with spec.components.<component>.enabled: true/false. Please see https://github.com/istio-ecosystem/sail-operator/tree/main/docs#components-field"
else
cat $SAIL_CONFIG_FILE | yq 'del (.spec.components)' > tmp.yaml
mv tmp.yaml $SAIL_CONFIG_FILE
echo "Converter can only be used values with spec.components.<component>.enabled: true/false. Please see https://github.com/istio-ecosystem/sail-operator/tree/main/docs#components-field"
fi
fi
}

add_mandatory_fields
boolean_2_string
validate_spec_components

chmod +x $SAIL_CONFIG_FILE
echo "Sail configuration file created with name: ${SAIL_CONFIG_FILE}"

0 comments on commit 50d9b8b

Please sign in to comment.