Skip to content

Commit

Permalink
Remove comparator references in the migrator
Browse files Browse the repository at this point in the history
  • Loading branch information
akgalwas committed Feb 6, 2025
1 parent c67026b commit a5e28f0
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 77 deletions.
30 changes: 0 additions & 30 deletions hack/runtime-migrator/cmd/migration/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (

type Migration struct {
runtimeMigrator migration.Migrator
runtimeVerifier migration.Verifier
kcpClient client.Client
shootClient gardener_types.ShootInterface
outputWriter migration.OutputWriter
Expand All @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
47 changes: 0 additions & 47 deletions hack/runtime-migrator/internal/migration/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit a5e28f0

Please sign in to comment.