MCPcopy
hub / github.com/istio/istio / createWebhook

Function createWebhook

pkg/kube/inject/webhook_test.go:882–940  ·  view source on GitHub ↗
(t testing.TB, cfg *Config, pcResources int)

Source from the content-addressed store, hash-verified

880}
881
882func createWebhook(t testing.TB, cfg *Config, pcResources int) *Webhook {
883 t.Helper()
884 dir := t.TempDir()
885
886 configBytes, err := yaml.Marshal(cfg)
887 if err != nil {
888 t.Fatalf("Could not marshal test injection config: %v", err)
889 }
890 _, values, _ := getInjectionSettings(t, nil, "")
891 var (
892 configFile = filepath.Join(dir, "config-file.yaml")
893 valuesFile = filepath.Join(dir, "values-file.yaml")
894 port = 0
895 )
896
897 if err := os.WriteFile(configFile, configBytes, 0o644); err != nil { // nolint: vetshadow
898 t.Fatalf("WriteFile(%v) failed: %v", configFile, err)
899 }
900
901 if err := os.WriteFile(valuesFile, []byte(values.raw), 0o644); err != nil { // nolint: vetshadow
902 t.Fatalf("WriteFile(%v) failed: %v", valuesFile, err)
903 }
904
905 // mesh config
906 m := mesh.DefaultMeshConfig()
907 store := model.NewFakeStore()
908 for i := 0; i < pcResources; i++ {
909 store.Create(newProxyConfig(fmt.Sprintf("pc-%d", i), "istio-system", &v1beta12.ProxyConfig{
910 Concurrency: &wrapperspb.Int32Value{Value: int32(i % 5)},
911 EnvironmentVariables: map[string]string{
912 fmt.Sprintf("VAR_%d", i): fmt.Sprint(i),
913 },
914 }))
915 }
916 pcs := model.GetProxyConfigs(store, m)
917 env := model.Environment{
918 Watcher: meshwatcher.NewTestWatcher(m),
919 ConfigStore: store,
920 }
921 env.SetPushContext(&model.PushContext{
922 ProxyConfigs: pcs,
923 })
924 watcher, err := NewFileWatcher(configFile, valuesFile)
925 if err != nil {
926 t.Fatalf("NewFileWatcher() failed: %v", err)
927 }
928
929 wh, err := NewWebhook(WebhookParameters{
930 Watcher: watcher,
931 Port: port,
932 Env: &env,
933 Mux: http.NewServeMux(),
934 MultiCluster: multicluster.NewFakeController(),
935 })
936 if err != nil {
937 t.Fatalf("NewWebhook() failed: %v", err)
938 }
939 return wh

Callers 2

TestRunAndServeFunction · 0.85
benchmarkInjectServeFunction · 0.85

Calls 15

CreateMethod · 0.95
SetPushContextMethod · 0.95
DefaultMeshConfigFunction · 0.92
NewFakeStoreFunction · 0.92
GetProxyConfigsFunction · 0.92
NewTestWatcherFunction · 0.92
NewFakeControllerFunction · 0.92
getInjectionSettingsFunction · 0.85
NewFileWatcherFunction · 0.85
NewWebhookFunction · 0.85
MarshalMethod · 0.80
newProxyConfigFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…