Skip to content

Commit

Permalink
Backport of [NET-8412] Fix APIGW policy creation ordering for upgrade…
Browse files Browse the repository at this point in the history
… path into release/1.3.x (#3926)

* backport of commit 09cc033

* Added changelog

---------

Co-authored-by: jm96441n <john.maguire@hashicorp.com>
  • Loading branch information
hc-github-team-consul-core and jm96441n authored Apr 19, 2024
1 parent cf76890 commit 9b2f810
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .changelog/3918.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
api-gateway: Fix order of initialization for creating ACL role/policy to avoid error logs in consul when upgrading between versions.
```
8 changes: 7 additions & 1 deletion control-plane/api-gateway/cache/consul.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,9 @@ func (c *Cache) ensurePolicy(client *api.Client, gatewayName string) (string, er
if err != nil {
return "", err
}

// on an upgrade the cache will be empty so we need to write the policy to the cache
c.gatewayNameToPolicy[gatewayName] = existing
return existing.ID, nil
}

Expand Down Expand Up @@ -389,6 +392,8 @@ func (c *Cache) ensurePolicy(client *api.Client, gatewayName string) (string, er
return "", err
}

// update cache with existing policy
c.gatewayNameToPolicy[gatewayName] = existing
return existing.ID, nil
}

Expand Down Expand Up @@ -429,7 +434,8 @@ func (c *Cache) ensureRole(client *api.Client, gatewayName string) (string, erro
}

if aclRole != nil {
return cachedRole.Name, nil
c.gatewayNameToRole[gatewayName] = aclRole
return aclRole.Name, nil
}

return createRole()
Expand Down

0 comments on commit 9b2f810

Please sign in to comment.