MCPcopy
hub / github.com/istio/istio / NewWebhook

Function NewWebhook

pkg/kube/inject/webhook.go:202–247  ·  view source on GitHub ↗

NewWebhook creates a new instance of a mutating webhook for automatic sidecar injection.

(p WebhookParameters)

Source from the content-addressed store, hash-verified

200
201// NewWebhook creates a new instance of a mutating webhook for automatic sidecar injection.
202func NewWebhook(p WebhookParameters) (*Webhook, error) {
203 if p.Mux == nil {
204 return nil, errors.New("expected mux to be passed, but was not passed")
205 }
206
207 wh := &Webhook{
208 watcher: p.Watcher,
209 meshConfig: p.Env.Mesh(),
210 env: p.Env,
211 revision: p.Revision,
212 }
213
214 if p.MultiCluster != nil {
215 if platform.IsOpenShift() {
216 wh.namespaces = multicluster.BuildMultiClusterKclientComponent[*corev1.Namespace](p.MultiCluster, kubetypes.Filter{})
217 }
218 }
219
220 if features.EnableNativeSidecars != features.NativeSidecarModeDisabled {
221 wh.nodes = multicluster.BuildMultiClusterKclientComponent[*corev1.Node](p.MultiCluster, kubetypes.Filter{
222 ObjectTransform: kube.StripNodeUnusedFields,
223 })
224 }
225
226 mc := NewMulticast(p.Watcher, wh.GetConfig)
227 mc.AddHandler(wh.updateConfig)
228 wh.MultiCast = mc
229 sidecarConfig, valuesConfig, err := p.Watcher.Get()
230 if err != nil {
231 return nil, fmt.Errorf("failed to get initial configuration: %v", err)
232 }
233 if err := wh.updateConfig(sidecarConfig, valuesConfig); err != nil {
234 return nil, fmt.Errorf("failed to process webhook config: %v", err)
235 }
236
237 p.Mux.HandleFunc("/inject", wh.serveInject)
238 p.Mux.HandleFunc("/inject/", wh.serveInject)
239
240 p.Env.Watcher.AddMeshHandler(func() {
241 wh.mu.Lock()
242 wh.meshConfig = p.Env.Mesh()
243 wh.mu.Unlock()
244 })
245
246 return wh, nil
247}
248
249// Run implements the webhook server
250func (wh *Webhook) Run(stop <-chan struct{}) {

Callers 4

initSidecarInjectorMethod · 0.92
createWebhookFunction · 0.85

Calls 10

updateConfigMethod · 0.95
IsOpenShiftFunction · 0.92
NewMulticastFunction · 0.85
NewMethod · 0.65
MeshMethod · 0.65
AddHandlerMethod · 0.65
GetMethod · 0.65
ErrorfMethod · 0.65
AddMeshHandlerMethod · 0.65

Tested by 3

createWebhookFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…