Skip to content

Commit

Permalink
Added flags for including RBAC and OIDC
Browse files Browse the repository at this point in the history
  • Loading branch information
akgalwas committed Jan 4, 2025
1 parent f2deb7d commit 423b782
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
6 changes: 5 additions & 1 deletion hack/runtime-migrator/internal/initialisation/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ func GetRuntimeIDsFromInputFile(cfg Config) ([]string, error) {

type RestoreConfig struct {
Config
BackupDir string
BackupDir string
RestoreCRB bool
RestoreOIDC bool
}

func NewRestoreConfig() RestoreConfig {
Expand All @@ -96,6 +98,8 @@ func NewRestoreConfig() RestoreConfig {
flag.StringVar(&restoreConfig.InputType, "input-type", InputTypeJSON, "Type of input to be used. Possible values: **txt** (see the example hack/runtime-migrator/input/runtimeids_sample.txt), and **json** (see the example hack/runtime-migrator/input/runtimeids_sample.json).")
flag.StringVar(&restoreConfig.InputFilePath, "input-file-path", "/path/to/input/file", "Path to the input file containing RuntimeCRs to be migrated.")
flag.StringVar(&restoreConfig.BackupDir, "backup-path", "/path/to/backup/dir", "Path to the directory containing backup.")
flag.BoolVar(&restoreConfig.RestoreCRB, "restore-crbs", true, "Flag determining whether CRBs should be restored")
flag.BoolVar(&restoreConfig.RestoreOIDC, "restore-oidcs", true, "Flag determining whether OIDCs should be restored")
flag.Parse()

return restoreConfig
Expand Down
34 changes: 23 additions & 11 deletions hack/runtime-migrator/internal/restore/restorer.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@ import (
)

type Restorer struct {
backupDir string
backupDir string
restoreCRB bool
restoreOIDC bool
}

func NewRestorer(backupDir string) Restorer {
func NewRestorer(backupDir string, restoreCRB, restoreOIDC bool) Restorer {
return Restorer{
backupDir: backupDir,
backupDir: backupDir,
restoreCRB: restoreCRB,
restoreOIDC: restoreOIDC,
}
}

Expand All @@ -32,16 +36,24 @@ func (r Restorer) Do(runtimeID string, shootName string) (backup.RuntimeBackup,
return backup.RuntimeBackup{}, err
}

crbsDir := path.Join(r.backupDir, fmt.Sprintf("backup/%s/crb", runtimeID))
crbs, err := getObjectsFromToRestore[rbacv1.ClusterRoleBinding](crbsDir)
if err != nil {
return backup.RuntimeBackup{}, err
var crbs []rbacv1.ClusterRoleBinding

if r.restoreCRB {
crbsDir := path.Join(r.backupDir, fmt.Sprintf("backup/%s/crb", runtimeID))
crbs, err = getObjectsFromToRestore[rbacv1.ClusterRoleBinding](crbsDir)
if err != nil {
return backup.RuntimeBackup{}, err
}
}

oidcDir := path.Join(r.backupDir, fmt.Sprintf("backup/%s/oidc", runtimeID))
oidcConfig, err := getObjectsFromToRestore[authenticationv1alpha1.OpenIDConnect](oidcDir)
if err != nil {
return backup.RuntimeBackup{}, err
var oidcConfig []authenticationv1alpha1.OpenIDConnect

if r.restoreOIDC {
oidcDir := path.Join(r.backupDir, fmt.Sprintf("backup/%s/oidc", runtimeID))
oidcConfig, err = getObjectsFromToRestore[authenticationv1alpha1.OpenIDConnect](oidcDir)
if err != nil {
return backup.RuntimeBackup{}, err
}
}

return backup.RuntimeBackup{
Expand Down

0 comments on commit 423b782

Please sign in to comment.