From 517cb92d02b7212a0e8c56062220a697f0807029 Mon Sep 17 00:00:00 2001 From: Arkadiusz Galwas Date: Sun, 27 Oct 2024 10:23:53 +0100 Subject: [PATCH] Saving runtimeCR working --- hack/runtime-migrator/cmd/main.go | 1 + hack/runtime-migrator/cmd/migration.go | 8 ++++---- .../runtime-migrator/internal/migration/output.go | 15 ++++++++++----- .../internal/migration/results.go | 2 +- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/hack/runtime-migrator/cmd/main.go b/hack/runtime-migrator/cmd/main.go index a48da88e..23af4373 100644 --- a/hack/runtime-migrator/cmd/main.go +++ b/hack/runtime-migrator/cmd/main.go @@ -18,6 +18,7 @@ import ( ) const ( + contextTimeout = 5 * time.Minute expirationTime = 60 * time.Minute runtimeIDAnnotation = "kcp.provisioner.kyma-project.io/runtime-id" ) diff --git a/hack/runtime-migrator/cmd/migration.go b/hack/runtime-migrator/cmd/migration.go index b62a6b97..cd553419 100644 --- a/hack/runtime-migrator/cmd/migration.go +++ b/hack/runtime-migrator/cmd/migration.go @@ -38,18 +38,18 @@ type Migration struct { func (m Migration) Do(runtimeIDs []string) (migration.MigrationResults, error) { - shootList, err := m.shootClient.List(context.Background(), v1.ListOptions{}) + outputWriter, err := migration.NewOutputWriter(m.migrationConfig.OutputPath) if err != nil { return migration.MigrationResults{}, err } - results := migration.NewMigratorResults(m.migrationConfig.OutputPath) - - outputWriter, err := migration.NewOutputWriter(m.migrationConfig.OutputPath) + shootList, err := m.shootClient.List(context.Background(), v1.ListOptions{}) if err != nil { return migration.MigrationResults{}, err } + results := migration.NewMigratorResults(m.migrationConfig.OutputPath) + for _, runtimeID := range runtimeIDs { slog.Info(fmt.Sprintf("Migrating runtime with ID: %s", runtimeID)) shoot := findShoot(runtimeID, shootList) diff --git a/hack/runtime-migrator/internal/migration/output.go b/hack/runtime-migrator/internal/migration/output.go index 9c775a76..e146a3f6 100644 --- a/hack/runtime-migrator/internal/migration/output.go +++ b/hack/runtime-migrator/internal/migration/output.go @@ -7,28 +7,32 @@ import ( "os" "path" "sigs.k8s.io/yaml" + "time" ) type OutputWriter struct { outputDir string + runtimeDir string comparisonResultsDir string } func NewOutputWriter(outputDir string) (OutputWriter, error) { - err := os.MkdirAll(outputDir, os.ModePerm) + newResultsDir := path.Join(outputDir, fmt.Sprintf("migration-%s", time.Now().Format(time.RFC3339))) + + err := os.MkdirAll(newResultsDir, os.ModePerm) if err != nil { return OutputWriter{}, fmt.Errorf("failed to create results directory: %v", err) } - runtimesDir := path.Join(outputDir, "runtimes") + runtimesDir := path.Join(newResultsDir, "runtimes") err = os.MkdirAll(runtimesDir, os.ModePerm) if err != nil { return OutputWriter{}, fmt.Errorf("failed to create runtimes directory: %v", err) } - comparisonResultsDir := path.Join(outputDir, "comparison-results") + comparisonResultsDir := path.Join(newResultsDir, "comparison-results") err = os.MkdirAll(comparisonResultsDir, os.ModePerm) if err != nil { @@ -37,6 +41,7 @@ func NewOutputWriter(outputDir string) (OutputWriter, error) { return OutputWriter{ outputDir: outputDir, + runtimeDir: runtimesDir, comparisonResultsDir: comparisonResultsDir, }, nil } @@ -51,7 +56,7 @@ func (ow OutputWriter) SaveRuntimeCR(runtime v1.Runtime) error { return err } - return writeSpecToFile(ow.outputDir, runtime.Name, runtimeAsYaml) + return writeSpecToFile(ow.runtimeDir, runtime.Name, runtimeAsYaml) } func getYamlSpec(shoot v1.Runtime) ([]byte, error) { @@ -60,7 +65,7 @@ func getYamlSpec(shoot v1.Runtime) ([]byte, error) { } func writeSpecToFile(outputPath, runtimeID string, shootAsYaml []byte) error { - var fileName = fmt.Sprintf(runtimeCrFullPath, outputPath, runtimeID) + var fileName = fmt.Sprintf("%s/%s", outputPath, runtimeID) const writePermissions = 0644 return os.WriteFile(fileName, shootAsYaml, writePermissions) diff --git a/hack/runtime-migrator/internal/migration/results.go b/hack/runtime-migrator/internal/migration/results.go index de69f588..2741cfd1 100644 --- a/hack/runtime-migrator/internal/migration/results.go +++ b/hack/runtime-migrator/internal/migration/results.go @@ -5,7 +5,7 @@ import ( migrator "github.com/kyma-project/infrastructure-manager/hack/runtime-migrator-app/internal" ) -const runtimeCrFullPath = "%sshoot-%s.yaml" +const runtimeCrFullPath = "%sshoot-dd%s.yaml" type MigrationResults struct { Results []migrator.MigrationResult