diff --git a/pkg/registry/flowcontrol/ensurer/flowschema.go b/pkg/registry/flowcontrol/ensurer/flowschema.go index 4dbfb19c456..6cad99ffd91 100644 --- a/pkg/registry/flowcontrol/ensurer/flowschema.go +++ b/pkg/registry/flowcontrol/ensurer/flowschema.go @@ -118,7 +118,10 @@ type fsEnsurer struct { func (e *fsEnsurer) Ensure(flowSchemas []*flowcontrolv1beta3.FlowSchema) error { for _, flowSchema := range flowSchemas { - if err := ensureConfiguration(e.wrapper, e.strategy, flowSchema); err != nil { + // This code gets called by different goroutines. To avoid race conditions when + // https://github.com/kubernetes/kubernetes/blob/330b5a2b8dbd681811cb8235947557c99dd8e593/staging/src/k8s.io/apimachinery/pkg/runtime/helper.go#L221-L243 + // temporarily modifies the TypeMeta, we have to make a copy here. + if err := ensureConfiguration(e.wrapper, e.strategy, flowSchema.DeepCopy()); err != nil { return err } } diff --git a/pkg/registry/flowcontrol/ensurer/prioritylevelconfiguration.go b/pkg/registry/flowcontrol/ensurer/prioritylevelconfiguration.go index 4da5bc92c4c..a536d649d4c 100644 --- a/pkg/registry/flowcontrol/ensurer/prioritylevelconfiguration.go +++ b/pkg/registry/flowcontrol/ensurer/prioritylevelconfiguration.go @@ -119,7 +119,10 @@ type plEnsurer struct { func (e *plEnsurer) Ensure(priorityLevels []*flowcontrolv1beta3.PriorityLevelConfiguration) error { for _, priorityLevel := range priorityLevels { - if err := ensureConfiguration(e.wrapper, e.strategy, priorityLevel); err != nil { + // This code gets called by different goroutines. To avoid race conditions when + // https://github.com/kubernetes/kubernetes/blob/330b5a2b8dbd681811cb8235947557c99dd8e593/staging/src/k8s.io/apimachinery/pkg/runtime/helper.go#L221-L243 + // temporarily modifies the TypeMeta, we have to make a copy here. + if err := ensureConfiguration(e.wrapper, e.strategy, priorityLevel.DeepCopy()); err != nil { return err } }