Skip to content

Commit

Permalink
Added option to read input runtime ids from text file (one runtimeID …
Browse files Browse the repository at this point in the history
…per raw)
  • Loading branch information
akgalwas authored and m00g3n committed Nov 14, 2024
1 parent d2efa17 commit 4b5a7a2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
26 changes: 19 additions & 7 deletions hack/runtime-migrator/cmd/main.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package main

import (
"bufio"
"encoding/json"
"fmt"
"log"
"log/slog"
"os"
"time"
Expand Down Expand Up @@ -68,7 +68,14 @@ func main() {
os.Exit(1)
}

err = migrator.Do(getRuntimeIDsFromStdin(cfg))
slog.Info("Reading runtimeIds from stdin")
runtimeIds, err := getRuntimeIDsFromStdin(cfg)
if err != nil {
slog.Error("Failed to read runtime Ids from input: %v", slog.Any("error", err))
os.Exit(1)
}

err = migrator.Do(runtimeIds)
if err != nil {
slog.Error(fmt.Sprintf("Failed to migrate runtimes: %v", slog.Any("error", err)))
os.Exit(1)
Expand Down Expand Up @@ -105,16 +112,21 @@ func setupKubernetesKubeconfigProvider(kubeconfigPath string, namespace string,
int64(expirationTime.Seconds())), nil
}

func getRuntimeIDsFromStdin(cfg config.Config) []string {
func getRuntimeIDsFromStdin(cfg config.Config) ([]string, error) {
var runtimeIDs []string
var err error

if cfg.InputType == config.InputTypeJSON {
decoder := json.NewDecoder(os.Stdin)
slog.Info("Reading runtimeIds from stdin")
if err := decoder.Decode(&runtimeIDs); err != nil {
log.Printf("Could not load list of RuntimeIds - %s", err)
err = decoder.Decode(&runtimeIDs)
} else if cfg.InputType == config.InputTypeTxt {
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
runtimeIDs = append(runtimeIDs, scanner.Text())
}
err = scanner.Err()
}
return runtimeIDs
return runtimeIDs, err
}

func setupGardenerShootClient(kubeconfigPath, gardenerNamespace string) (gardener_types.ShootInterface, error) {
Expand Down
2 changes: 1 addition & 1 deletion hack/runtime-migrator/internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type Config struct {
}

const (
InputTypeAll = "all"
InputTypeTxt = "txt"
InputTypeJSON = "json"
)

Expand Down

0 comments on commit 4b5a7a2

Please sign in to comment.