Backport of state: canonicalize namespace on restore into release/1.6.x (#18018)

This pull request was automerged via backport-assistant
This commit is contained in:
hc-github-team-nomad-core 2023-07-20 15:05:16 -05:00 committed by GitHub
parent e891026755
commit 30260f06e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 0 deletions

3
.changelog/18017.txt Normal file
View File

@ -0,0 +1,3 @@
```release-note:bug
core: Fixed a bug where namespaces were not canonicalized on snapshot restore, resulting in potential nil access panic
```

View File

@ -205,6 +205,8 @@ func (r *StateRestore) ScalingEventsRestore(jobEvents *structs.JobScalingEvents)
// NamespaceRestore is used to restore a namespace
func (r *StateRestore) NamespaceRestore(ns *structs.Namespace) error {
// Handle upgrade path.
ns.Canonicalize()
if err := r.txn.Insert(TableNamespaces, ns); err != nil {
return fmt.Errorf("namespace insert failed: %v", err)
}