Skip to content

Commit

Permalink
Saving runtimeCR working
Browse files Browse the repository at this point in the history
  • Loading branch information
akgalwas committed Oct 27, 2024
1 parent 3799c09 commit 517cb92
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
1 change: 1 addition & 0 deletions hack/runtime-migrator/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
)

const (
contextTimeout = 5 * time.Minute
expirationTime = 60 * time.Minute
runtimeIDAnnotation = "kcp.provisioner.kyma-project.io/runtime-id"
)
Expand Down
8 changes: 4 additions & 4 deletions hack/runtime-migrator/cmd/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 10 additions & 5 deletions hack/runtime-migrator/internal/migration/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -37,6 +41,7 @@ func NewOutputWriter(outputDir string) (OutputWriter, error) {

return OutputWriter{
outputDir: outputDir,
runtimeDir: runtimesDir,
comparisonResultsDir: comparisonResultsDir,
}, nil
}
Expand All @@ -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) {
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion hack/runtime-migrator/internal/migration/results.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 517cb92

Please sign in to comment.