From a5e28f06dfb56ac3c8cc5dbf81f56cbfacfef36a Mon Sep 17 00:00:00 2001 From: Arkadiusz Galwas Date: Thu, 6 Feb 2025 14:56:55 +0100 Subject: [PATCH] Remove comparator references in the migrator --- .../cmd/migration/migration.go | 30 ------------ .../internal/migration/output.go | 47 ------------------- 2 files changed, 77 deletions(-) diff --git a/hack/runtime-migrator/cmd/migration/migration.go b/hack/runtime-migrator/cmd/migration/migration.go index c7c8bf96..ac6bc9f6 100644 --- a/hack/runtime-migrator/cmd/migration/migration.go +++ b/hack/runtime-migrator/cmd/migration/migration.go @@ -20,7 +20,6 @@ import ( type Migration struct { runtimeMigrator migration.Migrator - runtimeVerifier migration.Verifier kcpClient client.Client shootClient gardener_types.ShootInterface outputWriter migration.OutputWriter @@ -40,7 +39,6 @@ func NewMigration(migratorConfig initialisation.Config, converterConfig config.C return Migration{ runtimeMigrator: migration.NewMigrator(migratorConfig, kubeconfigProvider, kcpClient), - runtimeVerifier: migration.NewVerifier(converterConfig, auditLogConfig), kcpClient: kcpClient, shootClient: shootClient, outputWriter: outputWriter, @@ -69,17 +67,6 @@ func (m Migration) Do(ctx context.Context, runtimeIDs []string) error { slog.Error(msg, "runtimeID", runtimeID) } - reportValidationError := func(runtimeID, shootName string, msg string, err error) { - errorMsg := fmt.Sprintf("%s: %v", msg, err) - results.ValidationErrorOccurred(runtimeID, shootName, errorMsg) - slog.Error(msg, "runtimeID", runtimeID) - } - - reportUnwantedUpdateDetected := func(runtimeID, shootName string, msg string) { - results.ValidationDetectedUnwantedUpdate(runtimeID, shootName) - slog.Warn(msg, "runtimeID", runtimeID) - } - reportSuccess := func(runtimeID, shootName string, msg string) { results.OperationSucceeded(runtimeID, shootName) slog.Info(msg, "runtimeID", runtimeID) @@ -113,23 +100,6 @@ func (m Migration) Do(ctx context.Context, runtimeIDs []string) error { return } - shootComparisonResult, err := m.runtimeVerifier.Do(runtime, *shootToMigrate) - if err != nil { - reportValidationError(runtimeID, shootToMigrate.Name, "Failed to verify runtime", err) - return - } - - if !shootComparisonResult.IsEqual() { - err = m.outputWriter.SaveComparisonResult(shootComparisonResult) - if err != nil { - reportError(runtimeID, shootToMigrate.Name, "Failed to save comparison result", err) - return - } - - reportUnwantedUpdateDetected(runtimeID, shootToMigrate.Name, "Runtime CR can cause unwanted update in Gardener") - return - } - if m.isDryRun { reportSuccess(runtimeID, shootToMigrate.Name, "Runtime processed successfully (dry-run)") } else { diff --git a/hack/runtime-migrator/internal/migration/output.go b/hack/runtime-migrator/internal/migration/output.go index 71cd728d..77357637 100644 --- a/hack/runtime-migrator/internal/migration/output.go +++ b/hack/runtime-migrator/internal/migration/output.go @@ -66,53 +66,6 @@ func (ow OutputWriter) SaveRuntimeCR(runtime v1.Runtime) error { return saveYaml(runtime, fmt.Sprintf("%s/%s.yaml", ow.RuntimeDir, runtime.Name)) } -func (ow OutputWriter) SaveComparisonResult(comparisonResult ShootComparisonResult) error { - comparisonResultsForRuntimeDir := path.Join(ow.ComparisonResultsDir, comparisonResult.RuntimeID) - err := os.MkdirAll(comparisonResultsForRuntimeDir, os.ModePerm) - if err != nil { - return err - } - - if comparisonResult.Diff != nil { - err = writeResultsToDiffFile(comparisonResult.OriginalShoot.Name, comparisonResult.Diff, comparisonResultsForRuntimeDir) - if err != nil { - return err - } - } - - err = saveYaml(comparisonResult.OriginalShoot, path.Join(comparisonResultsForRuntimeDir, "original-shoot.yaml")) - if err != nil { - return err - } - - return saveYaml(comparisonResult.ConvertedShoot, path.Join(comparisonResultsForRuntimeDir, "converted-shoot.yaml")) -} - -func writeResultsToDiffFile(shootName string, difference *Difference, resultsDir string) error { - writeAndCloseFunc := func(filePath string, text string) error { - file, err := os.Create(filePath) - if err != nil { - return err - } - defer func() { - if file != nil { - err := file.Close() - if err != nil { - fmt.Printf("failed to close file: %v", err) - } - } - }() - - _, err = file.Write([]byte(text)) - - return err - } - - diffFile := path.Join(resultsDir, fmt.Sprintf("%s.diff", shootName)) - - return writeAndCloseFunc(diffFile, string(*difference)) -} - func saveYaml[T any](object T, path string) error { yamlBytes, err := yaml.Marshal(object) if err != nil {