-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
converter for istio in-cluster operator config to sail operator config
Signed-off-by: ctartici <[email protected]> Signed-off-by: ubuntu <[email protected]>
- Loading branch information
Showing
2 changed files
with
99 additions
and
0 deletions.
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
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 |
---|---|---|
@@ -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}" |