MCPcopy Create free account
hub / github.com/helm/helm / InvokeHook

Method InvokeHook

internal/plugin/runtime_subprocess.go:135–166  ·  view source on GitHub ↗
(event string)

Source from the content-addressed store, hash-verified

133}
134
135func (r *SubprocessPluginRuntime) InvokeHook(event string) error {
136 cmds := r.RuntimeConfig.PlatformHooks[event]
137
138 if len(cmds) == 0 {
139 return nil
140 }
141
142 env := ParseEnv(os.Environ())
143 maps.Insert(env, maps.All(r.EnvVars))
144 env["HELM_PLUGIN_NAME"] = r.metadata.Name
145 env["HELM_PLUGIN_DIR"] = r.pluginDir
146
147 main, argv, err := PrepareCommands(cmds, r.RuntimeConfig.expandHookArgs, []string{}, env)
148 if err != nil {
149 return err
150 }
151
152 cmd := exec.Command(main, argv...)
153 cmd.Env = FormatEnv(env)
154 cmd.Stdout = os.Stdout
155 cmd.Stderr = os.Stderr
156
157 slog.Debug("executing plugin hook command", slog.String("pluginName", r.metadata.Name), slog.String("command", cmd.String()))
158 if err := cmd.Run(); err != nil {
159 if eerr, ok := err.(*exec.ExitError); ok {
160 os.Stderr.Write(eerr.Stderr)
161 return fmt.Errorf("plugin %s hook for %q exited with error", event, r.metadata.Name)
162 }
163 return err
164 }
165 return nil
166}
167
168// TODO decide the best way to handle this code
169// right now we implement status and error return in 3 slightly different ways in this file

Callers

nothing calls this directly

Calls 7

ParseEnvFunction · 0.85
PrepareCommandsFunction · 0.85
FormatEnvFunction · 0.85
AllMethod · 0.80
RunMethod · 0.65
StringMethod · 0.45
WriteMethod · 0.45

Tested by

no test coverage detected