Skip to content

Commit

Permalink
Update migration start logic so an automated run will only happen if …
Browse files Browse the repository at this point in the history
…another run has not completed
  • Loading branch information
crobby committed Aug 4, 2023
1 parent 7e620d5 commit 9d82578
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
2 changes: 1 addition & 1 deletion cmd/agent/main.go
Expand Up @@ -81,7 +81,7 @@ func main() {
}
err = bindingErr
} else if os.Getenv("AD_GUID_CLEANUP") == "true" {
err = clean.ListAdUsers(nil)
err = clean.UnmigrateAdGUIDUsers(nil, false)
} else {
err = run(ctx)
}
Expand Down
21 changes: 18 additions & 3 deletions pkg/agent/clean/active_directory.go
Expand Up @@ -292,9 +292,24 @@ func prepareClientContexts(clientConfig *restclient.Config) (*config.ScaledConte
return sc, adConfig, nil
}

// ListAdUsers is purely for debugging. If this is still here, fail the PR. :P
func ListAdUsers(clientConfig *restclient.Config) error {
if os.Getenv("DRY_RUN") == "true" {
// UnmigrateAdGUIDUsersOnce will ensure that the migration script will run only once. cycle through all users, ctrb, ptrb, tokens and migrate them to an
// appropriate DN-based PrincipalID.
func UnmigrateAdGUIDUsersOnce(sc *config.ScaledContext) error {
migrationConfigMap, _ := sc.Core.ConfigMaps("cattle-system").GetNamespaced("cattle-system", "ad-guid-migration", metav1.GetOptions{})
if migrationConfigMap != nil {
migrationStatus := migrationConfigMap.Data["ad-guid-migration-status"]
if migrationStatus == StatusMigrationFinished {
logrus.Infof("The migration has already been completed")
return nil
}
}
return UnmigrateAdGUIDUsers(&sc.RESTConfig, false)
}

// UnmigrateAdGUIDUsers will cycle through all users, ctrb, ptrb, tokens and migrate them to an
// appropriate DN-based PrincipalID.
func UnmigrateAdGUIDUsers(clientConfig *restclient.Config, dryRun bool) error {
if dryRun || os.Getenv("DRY_RUN") == "true" {
logrus.Infof("[%v] DRY_RUN is true, no objects will be deleted/modified", listAdUsersOperation)
dryRun = true
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/multiclustermanager/app.go
Expand Up @@ -214,7 +214,7 @@ func (m *mcm) Start(ctx context.Context) error {
return errors.Wrap(err, "failed to telemetry")
}

clean.ListAdUsers(&m.ScaledContext.RESTConfig)
clean.UnmigrateAdGUIDUsersOnce(m.ScaledContext)
tokens.StartPurgeDaemon(ctx, management)
providerrefresh.StartRefreshDaemon(ctx, m.ScaledContext, management)
managementdata.CleanupOrphanedSystemUsers(ctx, management)
Expand Down

0 comments on commit 9d82578

Please sign in to comment.