Skip to content

Commit 3b0d3de

Browse files
committed
BUG/MAJOR: configuration: add nil checks when deprecating users
1 parent 8335a87 commit 3b0d3de

File tree

2 files changed

+41
-37
lines changed

2 files changed

+41
-37
lines changed

configuration/configuration_deprecated.go

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -73,40 +73,42 @@ func (c *Configuration) migrateUsers() ([]string, error) {
7373
clusterModeStoragePath := path.Join(c.HAProxy.DataplaneStorageDir, storage.ClusterModeDataFileName)
7474

7575
usersToMigrate := make([]storagetype.User, 0)
76-
for _, singleModeUser := range dapiCfgStorage.Dataplaneapi.Users {
77-
found := false
78-
// Only migrate cluster users
79-
if !singleModeUser.IsClusterUser() {
80-
continue
81-
}
76+
if dapiCfgStorage.Dataplaneapi != nil {
77+
for _, singleModeUser := range dapiCfgStorage.Dataplaneapi.Users {
78+
found := false
79+
// Only migrate cluster users
80+
if !singleModeUser.IsClusterUser() {
81+
continue
82+
}
8283

83-
var muser storagetype.User
84-
for _, muser = range dapiStorageUsers {
85-
if muser.Name == singleModeUser.Name {
86-
found = true
87-
break
84+
var muser storagetype.User
85+
for _, muser = range dapiStorageUsers {
86+
if muser.Name == singleModeUser.Name {
87+
found = true
88+
break
89+
}
8890
}
89-
}
9091

91-
// Already migrated
92-
if found {
93-
msg := fmt.Sprintf("[CFG DEPRECATED] [SKIP] [User] [%s]: already migrated. Old location [%s] New location [%s]. Use only new location",
94-
singleModeUser.Name,
95-
c.HAProxy.DataplaneConfig,
96-
clusterModeStoragePath)
97-
// Logging is not done here as at startup, the logger is not yet initialized
98-
// so it's done later on
99-
deprecationInfoMsg = append(deprecationInfoMsg, msg)
100-
} else {
101-
// If not already migrated, then migrate it
102-
msg := fmt.Sprintf("[CFG DEPRECATED] [MIGRATE] [User] [%s]: migrating. Old location [%s] New location [%s]. Use only new location",
103-
singleModeUser.Name,
104-
c.HAProxy.DataplaneConfig,
105-
clusterModeStoragePath)
106-
// Logging is not done here as at startup, the logger is not yet initialized
107-
// so it's done later on
108-
deprecationInfoMsg = append(deprecationInfoMsg, msg)
109-
usersToMigrate = append(usersToMigrate, singleModeUser)
92+
// Already migrated
93+
if found {
94+
msg := fmt.Sprintf("[CFG DEPRECATED] [SKIP] [User] [%s]: already migrated. Old location [%s] New location [%s]. Use only new location",
95+
singleModeUser.Name,
96+
c.HAProxy.DataplaneConfig,
97+
clusterModeStoragePath)
98+
// Logging is not done here as at startup, the logger is not yet initialized
99+
// so it's done later on
100+
deprecationInfoMsg = append(deprecationInfoMsg, msg)
101+
} else {
102+
// If not already migrated, then migrate it
103+
msg := fmt.Sprintf("[CFG DEPRECATED] [MIGRATE] [User] [%s]: migrating. Old location [%s] New location [%s]. Use only new location",
104+
singleModeUser.Name,
105+
c.HAProxy.DataplaneConfig,
106+
clusterModeStoragePath)
107+
// Logging is not done here as at startup, the logger is not yet initialized
108+
// so it's done later on
109+
deprecationInfoMsg = append(deprecationInfoMsg, msg)
110+
usersToMigrate = append(usersToMigrate, singleModeUser)
111+
}
110112
}
111113
}
112114
if err := c.clusterModeStorage.AddUsersAndStore(usersToMigrate); err != nil {

configuration/configuration_storage.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -382,14 +382,16 @@ func copyConfigurationToStorage(cfg *Configuration) {
382382
func (cfgStorage *StorageDataplaneAPIConfiguration) emptyDeprecatedSections() {
383383
cfgStorage.DeprecatedBootstrapKey = nil
384384
// Remove Cluster Users from dapi configuration file
385-
for i := 0; i < len(cfgStorage.Dataplaneapi.Users); {
386-
if cfgStorage.Dataplaneapi.Users[i].IsClusterUser() {
387-
if len(cfgStorage.Dataplaneapi.Users) > i {
388-
cfgStorage.Dataplaneapi.Users = append(cfgStorage.Dataplaneapi.Users[:i], cfgStorage.Dataplaneapi.Users[i+1:]...)
389-
continue
385+
if cfgStorage.Dataplaneapi != nil {
386+
for i := 0; i < len(cfgStorage.Dataplaneapi.Users); {
387+
if cfgStorage.Dataplaneapi.Users[i].IsClusterUser() {
388+
if len(cfgStorage.Dataplaneapi.Users) > i {
389+
cfgStorage.Dataplaneapi.Users = append(cfgStorage.Dataplaneapi.Users[:i], cfgStorage.Dataplaneapi.Users[i+1:]...)
390+
continue
391+
}
390392
}
393+
i++
391394
}
392-
i++
393395
}
394396
// Remove Cluster
395397
cfgStorage.DeprecatedCluster = nil

0 commit comments

Comments
 (0)