Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport of NET-9178-Consul-api-gateway-not-starting-after-restart into release/1.3.x #3986

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/3978.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
connect-inject: Fixed issue where on restart, if a managed-gateway-acl-role already existed the container would error
```
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ BUG FIXES:
* api-gateway: Fix order of initialization for creating ACL role/policy to avoid error logs in consul when upgrading between versions. [[GH-3918](https://github.com/hashicorp/consul-k8s/issues/3918)]
* api-gateway: fix bug where multiple logical APIGateways would share the same ACL policy. [[GH-4001](https://github.com/hashicorp/consul-k8s/issues/4001)]
* control-plane: fix a panic when an upstream annotation is malformed. [[GH-3956](https://github.com/hashicorp/consul-k8s/issues/3956)]
* connect-inject: Fixed issue where on restart, if a managed-gateway-acl-role already existed the container would error [[GH-3978](https://github.com/hashicorp/consul-k8s/issues/3978)]

## 1.3.4 (March 28, 2024)

Expand Down
8 changes: 6 additions & 2 deletions control-plane/api-gateway/cache/consul.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,10 @@ func (c *Cache) ensurePolicy(client *api.Client, gatewayName string) (string, er
return existing.ID, nil
}

func getACLRoleName(gatewayName string) string {
return fmt.Sprint("managed-gateway-acl-role-", gatewayName)
}

func (c *Cache) ensureRole(client *api.Client, gatewayName string) (string, error) {
policyID, err := c.ensurePolicy(client, gatewayName)
if err != nil {
Expand All @@ -407,7 +411,7 @@ func (c *Cache) ensureRole(client *api.Client, gatewayName string) (string, erro
defer c.aclRoleMutex.Unlock()

createRole := func() (string, error) {
aclRoleName := fmt.Sprint("managed-gateway-acl-role-", gatewayName)
aclRoleName := getACLRoleName(gatewayName)
role := &api.ACLRole{
Name: aclRoleName,
Description: "ACL Role for Managed API Gateways",
Expand Down Expand Up @@ -437,7 +441,7 @@ func (c *Cache) ensureRole(client *api.Client, gatewayName string) (string, erro
}

c.gatewayNameToRole[gatewayName] = role
return aclRoleName, err
return aclRoleName, nil
}

cachedRole, found := c.gatewayNameToRole[gatewayName]
Expand Down
Loading