Skip to content

Commit

Permalink
BUG/MAJOR: configuration: add nil checks when deprecating users
Browse files Browse the repository at this point in the history
  • Loading branch information
mjuraga committed Sep 20, 2024
1 parent 8335a87 commit 3b0d3de
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 37 deletions.
64 changes: 33 additions & 31 deletions configuration/configuration_deprecated.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,40 +73,42 @@ func (c *Configuration) migrateUsers() ([]string, error) {
clusterModeStoragePath := path.Join(c.HAProxy.DataplaneStorageDir, storage.ClusterModeDataFileName)

usersToMigrate := make([]storagetype.User, 0)
for _, singleModeUser := range dapiCfgStorage.Dataplaneapi.Users {
found := false
// Only migrate cluster users
if !singleModeUser.IsClusterUser() {
continue
}
if dapiCfgStorage.Dataplaneapi != nil {
for _, singleModeUser := range dapiCfgStorage.Dataplaneapi.Users {
found := false
// Only migrate cluster users
if !singleModeUser.IsClusterUser() {
continue
}

var muser storagetype.User
for _, muser = range dapiStorageUsers {
if muser.Name == singleModeUser.Name {
found = true
break
var muser storagetype.User
for _, muser = range dapiStorageUsers {
if muser.Name == singleModeUser.Name {
found = true
break
}
}
}

// Already migrated
if found {
msg := fmt.Sprintf("[CFG DEPRECATED] [SKIP] [User] [%s]: already migrated. Old location [%s] New location [%s]. Use only new location",
singleModeUser.Name,
c.HAProxy.DataplaneConfig,
clusterModeStoragePath)
// Logging is not done here as at startup, the logger is not yet initialized
// so it's done later on
deprecationInfoMsg = append(deprecationInfoMsg, msg)
} else {
// If not already migrated, then migrate it
msg := fmt.Sprintf("[CFG DEPRECATED] [MIGRATE] [User] [%s]: migrating. Old location [%s] New location [%s]. Use only new location",
singleModeUser.Name,
c.HAProxy.DataplaneConfig,
clusterModeStoragePath)
// Logging is not done here as at startup, the logger is not yet initialized
// so it's done later on
deprecationInfoMsg = append(deprecationInfoMsg, msg)
usersToMigrate = append(usersToMigrate, singleModeUser)
// Already migrated
if found {
msg := fmt.Sprintf("[CFG DEPRECATED] [SKIP] [User] [%s]: already migrated. Old location [%s] New location [%s]. Use only new location",
singleModeUser.Name,
c.HAProxy.DataplaneConfig,
clusterModeStoragePath)
// Logging is not done here as at startup, the logger is not yet initialized
// so it's done later on
deprecationInfoMsg = append(deprecationInfoMsg, msg)
} else {
// If not already migrated, then migrate it
msg := fmt.Sprintf("[CFG DEPRECATED] [MIGRATE] [User] [%s]: migrating. Old location [%s] New location [%s]. Use only new location",
singleModeUser.Name,
c.HAProxy.DataplaneConfig,
clusterModeStoragePath)
// Logging is not done here as at startup, the logger is not yet initialized
// so it's done later on
deprecationInfoMsg = append(deprecationInfoMsg, msg)
usersToMigrate = append(usersToMigrate, singleModeUser)
}
}
}
if err := c.clusterModeStorage.AddUsersAndStore(usersToMigrate); err != nil {
Expand Down
14 changes: 8 additions & 6 deletions configuration/configuration_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,14 +382,16 @@ func copyConfigurationToStorage(cfg *Configuration) {
func (cfgStorage *StorageDataplaneAPIConfiguration) emptyDeprecatedSections() {
cfgStorage.DeprecatedBootstrapKey = nil
// Remove Cluster Users from dapi configuration file
for i := 0; i < len(cfgStorage.Dataplaneapi.Users); {
if cfgStorage.Dataplaneapi.Users[i].IsClusterUser() {
if len(cfgStorage.Dataplaneapi.Users) > i {
cfgStorage.Dataplaneapi.Users = append(cfgStorage.Dataplaneapi.Users[:i], cfgStorage.Dataplaneapi.Users[i+1:]...)
continue
if cfgStorage.Dataplaneapi != nil {
for i := 0; i < len(cfgStorage.Dataplaneapi.Users); {
if cfgStorage.Dataplaneapi.Users[i].IsClusterUser() {
if len(cfgStorage.Dataplaneapi.Users) > i {
cfgStorage.Dataplaneapi.Users = append(cfgStorage.Dataplaneapi.Users[:i], cfgStorage.Dataplaneapi.Users[i+1:]...)
continue
}
}
i++
}
i++
}
// Remove Cluster
cfgStorage.DeprecatedCluster = nil
Expand Down

0 comments on commit 3b0d3de

Please sign in to comment.