Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add deep copy calls to bound gateway retrieval
Browse files Browse the repository at this point in the history
sarahalsmiller committed Oct 26, 2023

Verified

This commit was signed with the committer’s verified signature.
1 parent 2a19dd3 commit 83ff292
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions agent/consul/gateways/controller_gateways.go
Original file line number Diff line number Diff line change
@@ -229,8 +229,14 @@ func (r *apiGatewayReconciler) reconcileGateway(_ context.Context, req controlle
return err
}

var bound structs.ConfigEntry
// construct the tuple we'll be working on to update state
_, bound, err := store.ConfigEntry(nil, structs.BoundAPIGateway, req.Name, req.Meta)
_, rawBoundGateway, err := store.ConfigEntry(nil, structs.BoundAPIGateway, req.Name, req.Meta)
if rawBoundGateway != nil { // for singular returns
boundGateway := bound.(*structs.BoundAPIGatewayConfigEntry)
bound = boundGateway.DeepCopy()
}
// or for the slice returns do a slice copy with a DeepCopy of all elements
if err != nil {
logger.Warn("error retrieving bound api gateway", "error", err)
return err
@@ -606,11 +612,20 @@ func getAllGatewayMeta(store *state.Store) ([]*gatewayMeta, error) {
if err != nil {
return nil, err
}
_, boundGateways, err := store.ConfigEntriesByKind(nil, structs.BoundAPIGateway, wildcardMeta())
_, rawBoundGateways, err := store.ConfigEntriesByKind(nil, structs.BoundAPIGateway, wildcardMeta())
if err != nil {
return nil, err
}

boundGateways := make([]structs.ConfigEntry, len(rawBoundGateways))

for i, gw := range rawBoundGateways {
if gw != nil { // for singular returns
boundGateway := gw.(*structs.BoundAPIGatewayConfigEntry)
boundGateways[i] = boundGateway.DeepCopy()
}
}

_, jwtProvidersConfigEntries, err := store.ConfigEntriesByKind(nil, structs.JWTProvider, wildcardMeta())
if err != nil {
return nil, err

0 comments on commit 83ff292

Please sign in to comment.