Skip to content

Commit c564fb4

Browse files
committed
prevent race between reading and writing the state
On-behalf-of: @SAP [email protected]
1 parent 885c7ba commit c564fb4

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

pkg/reconciler/dynamicrestmapper/dynamicrestmapper_builtin_controller.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,6 @@ func (c *BuiltinTypesController) gatherGVKRsForCRD(crd *apiextensionsv1.CustomRe
201201
}
202202

203203
func (c *BuiltinTypesController) gatherGVKRsForMappedGroupResource(gr schema.GroupResource) ([]typeMeta, error) {
204-
c.state.lock.RLock()
205-
defer c.state.lock.RUnlock()
206-
207204
gvkrs, err := c.state.builtin.getGVKRs(gr)
208205
if err != nil {
209206
if meta.IsNoMatchError(err) {
@@ -230,6 +227,9 @@ func (c *BuiltinTypesController) process(ctx context.Context, key string) error
230227
return err
231228
}
232229

230+
c.state.lock.Lock()
231+
defer c.state.lock.Unlock()
232+
233233
// Remove and add the mapping -- this way we can refresh any existing mappings.
234234
typeMetaToRemove, err := c.gatherGVKRsForMappedGroupResource(gr)
235235
if err != nil {
@@ -239,8 +239,6 @@ func (c *BuiltinTypesController) process(ctx context.Context, key string) error
239239

240240
logger.V(4).Info("applying mappings")
241241

242-
c.state.lock.Lock()
243-
defer c.state.lock.Unlock()
244242
c.state.builtin.apply(typeMetaToRemove, typeMetaToAdd)
245243
return nil
246244
}

0 commit comments

Comments
 (0)