mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-20 01:01:22 +00:00
Pre-allocate webhook accessors arrays for mutating and validating
webhooks
This commit is contained in:
parent
0695853a30
commit
49d0346802
@ -119,7 +119,12 @@ func (m *mutatingWebhookConfigurationManager) getMutatingWebhookConfigurations(c
|
|||||||
// but configurations themselves can be in any order. As we are going to run these
|
// but configurations themselves can be in any order. As we are going to run these
|
||||||
// webhooks in serial, they are sorted here to have a deterministic order.
|
// webhooks in serial, they are sorted here to have a deterministic order.
|
||||||
sort.SliceStable(configurations, MutatingWebhookConfigurationSorter(configurations).ByName)
|
sort.SliceStable(configurations, MutatingWebhookConfigurationSorter(configurations).ByName)
|
||||||
accessors := []webhook.WebhookAccessor{}
|
size := 0
|
||||||
|
for _, cfg := range configurations {
|
||||||
|
size += len(cfg.Webhooks)
|
||||||
|
}
|
||||||
|
accessors := make([]webhook.WebhookAccessor, 0, size)
|
||||||
|
|
||||||
for _, c := range configurations {
|
for _, c := range configurations {
|
||||||
cachedConfigurationAccessors, ok := m.configurationsCache.Load(c.Name)
|
cachedConfigurationAccessors, ok := m.configurationsCache.Load(c.Name)
|
||||||
if ok {
|
if ok {
|
||||||
@ -131,7 +136,7 @@ func (m *mutatingWebhookConfigurationManager) getMutatingWebhookConfigurations(c
|
|||||||
// webhook names are not validated for uniqueness, so we check for duplicates and
|
// webhook names are not validated for uniqueness, so we check for duplicates and
|
||||||
// add a int suffix to distinguish between them
|
// add a int suffix to distinguish between them
|
||||||
names := map[string]int{}
|
names := map[string]int{}
|
||||||
configurationAccessors := []webhook.WebhookAccessor{}
|
configurationAccessors := make([]webhook.WebhookAccessor, 0, len(c.Webhooks))
|
||||||
for i := range c.Webhooks {
|
for i := range c.Webhooks {
|
||||||
n := c.Webhooks[i].Name
|
n := c.Webhooks[i].Name
|
||||||
uid := fmt.Sprintf("%s/%s/%d", c.Name, n, names[n])
|
uid := fmt.Sprintf("%s/%s/%d", c.Name, n, names[n])
|
||||||
|
@ -116,7 +116,12 @@ func (v *validatingWebhookConfigurationManager) getConfiguration() ([]webhook.We
|
|||||||
// recreating them, which can be expessive (requiring CEL expression recompilation).
|
// recreating them, which can be expessive (requiring CEL expression recompilation).
|
||||||
func (v *validatingWebhookConfigurationManager) getValidatingWebhookConfigurations(configurations []*v1.ValidatingWebhookConfiguration) []webhook.WebhookAccessor {
|
func (v *validatingWebhookConfigurationManager) getValidatingWebhookConfigurations(configurations []*v1.ValidatingWebhookConfiguration) []webhook.WebhookAccessor {
|
||||||
sort.SliceStable(configurations, ValidatingWebhookConfigurationSorter(configurations).ByName)
|
sort.SliceStable(configurations, ValidatingWebhookConfigurationSorter(configurations).ByName)
|
||||||
accessors := []webhook.WebhookAccessor{}
|
size := 0
|
||||||
|
for _, cfg := range configurations {
|
||||||
|
size += len(cfg.Webhooks)
|
||||||
|
}
|
||||||
|
accessors := make([]webhook.WebhookAccessor, 0, size)
|
||||||
|
|
||||||
for _, c := range configurations {
|
for _, c := range configurations {
|
||||||
cachedConfigurationAccessors, ok := v.configurationsCache.Load(c.Name)
|
cachedConfigurationAccessors, ok := v.configurationsCache.Load(c.Name)
|
||||||
if ok {
|
if ok {
|
||||||
@ -128,7 +133,7 @@ func (v *validatingWebhookConfigurationManager) getValidatingWebhookConfiguratio
|
|||||||
// webhook names are not validated for uniqueness, so we check for duplicates and
|
// webhook names are not validated for uniqueness, so we check for duplicates and
|
||||||
// add a int suffix to distinguish between them
|
// add a int suffix to distinguish between them
|
||||||
names := map[string]int{}
|
names := map[string]int{}
|
||||||
configurationAccessors := []webhook.WebhookAccessor{}
|
configurationAccessors := make([]webhook.WebhookAccessor, 0, len(c.Webhooks))
|
||||||
for i := range c.Webhooks {
|
for i := range c.Webhooks {
|
||||||
n := c.Webhooks[i].Name
|
n := c.Webhooks[i].Name
|
||||||
uid := fmt.Sprintf("%s/%s/%d", c.Name, n, names[n])
|
uid := fmt.Sprintf("%s/%s/%d", c.Name, n, names[n])
|
||||||
|
Loading…
Reference in New Issue
Block a user