Skip to content

Commit eb12e96

Browse files
committed
Fix panic in webhook configuration merge during operator upgrades
Fixes an index out of bounds panic in MergeWebhookConfigurationForUpdate that occurs when the updated webhook configuration contains more webhooks than the current configuration. This can happen during operator upgrades when new webhooks are added. The fix adds bounds checking to skip copying clientConfig for new webhooks that don't exist in the current configuration, allowing the merge to complete successfully.
1 parent 8452bdf commit eb12e96

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

internal/operator/bindata/merge.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,18 @@ func MergeWebhookConfigurationForUpdate(current, updated *uns.Unstructured) erro
6060
gvk := updated.GroupVersionKind()
6161

6262
if gvk.Group == "admissionregistration.k8s.io" && (gvk.Kind == "MutatingWebhookConfiguration" || gvk.Kind == "ValidatingWebhookConfiguration") {
63+
currentWebhooks, currentExists := current.Object["webhooks"].([]interface{})
64+
if !currentExists {
65+
return nil
66+
}
6367

6468
for i, webhook := range updated.Object["webhooks"].([]interface{}) {
69+
// Check if the index exists in the current webhooks list
70+
if i >= len(currentWebhooks) {
71+
continue
72+
}
6573

66-
currentClientConfig := current.Object["webhooks"].([]interface{})[i].(map[string]interface{})["clientConfig"].(map[string]interface{})
74+
currentClientConfig := currentWebhooks[i].(map[string]interface{})["clientConfig"].(map[string]interface{})
6775
if currentClientConfig != nil {
6876
webhook.(map[string]interface{})["clientConfig"] = currentClientConfig
6977
}

0 commit comments

Comments
 (0)