-
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: ctartici <[email protected]>
- Loading branch information
Showing
5 changed files
with
327 additions
and
3 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
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,96 @@ | ||
//go:build e2e | ||
|
||
// 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. | ||
|
||
package configconverter | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
|
||
"github.com/istio-ecosystem/sail-operator/pkg/test/project" | ||
"github.com/istio-ecosystem/sail-operator/tests/e2e/util/shell" | ||
) | ||
|
||
func SetEnvVariables(envKey, envValue string) error { | ||
err := os.Setenv(envKey, envValue) | ||
if err != nil { | ||
return fmt.Errorf("failed to set env variable: %w", err) | ||
} | ||
return nil | ||
} | ||
|
||
// saveYamlToFile writes the given YAML content to IstioConfig.yaml | ||
func SaveYamlToFile(yamlText string) (string, error) { | ||
// Create file in the same directory with the converter | ||
istioYamlFile := "istioConfig.yaml" | ||
istioYamlFileWithPath := filepath.Join(project.RootDir, "tools", istioYamlFile) | ||
|
||
// Write to file | ||
if err := os.WriteFile(istioYamlFileWithPath, []byte(yamlText), 0o644); err != nil { | ||
return "", fmt.Errorf("failed to write YAML file: %w", err) | ||
} | ||
|
||
return istioYamlFileWithPath, nil | ||
} | ||
|
||
func ExecuteConfigConverter(istioYamlFilePath string) error { | ||
// Define file path | ||
configConverterPath := filepath.Join(project.RootDir, "tools", "configuration-converter.sh") | ||
|
||
_, err := shell.ExecuteBashScript(configConverterPath, istioYamlFilePath) | ||
if err != nil { | ||
return fmt.Errorf("error in execution of %s %s: %w", configConverterPath, istioYamlFilePath, err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// compareYamlContent checks if the provided YAML string matches the content of converted config | ||
func ValidateYamlContent(yamlString string) (bool, error) { | ||
sailYamlWithPath := filepath.Join(project.RootDir, "tools", "sail-operator-config.yaml") | ||
|
||
// Write the input YAML string to a temporary file | ||
tmpFile := filepath.Join(project.RootDir, "tools", "temp.yaml") | ||
err := os.WriteFile(tmpFile, []byte(yamlString), 0o644) | ||
if err != nil { | ||
return false, fmt.Errorf("failed to write temporary YAML file: %w", err) | ||
} | ||
defer os.Remove(tmpFile) | ||
|
||
// The command will check if the files are equal, ignoring order | ||
cmd := fmt.Sprintf("yq eval 'diff %s %s' > /dev/null 2>&1", sailYamlWithPath, tmpFile) | ||
output, err := shell.ExecuteCommand(cmd) | ||
if err != nil { | ||
if strings.Contains(output, "diff") { | ||
return false, nil | ||
} | ||
return false, fmt.Errorf("error executing yq comparison: %w", err) | ||
} | ||
|
||
// If no output from yq, the files are considered equal | ||
return true, nil | ||
} | ||
|
||
func DeleteFile(fileName string) error { | ||
fileWithPath := filepath.Join(project.RootDir, "tools", fileName) | ||
err := os.Remove(fileWithPath) | ||
if err != nil { | ||
return fmt.Errorf("failed to delete file %s: %w", fileWithPath, err) | ||
} | ||
return nil | ||
} |
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.