MCPcopy
hub / github.com/helm/helm / RunWithContext

Method RunWithContext

pkg/action/upgrade.go:170–218  ·  view source on GitHub ↗

RunWithContext executes the upgrade on the given release with context.

(ctx context.Context, name string, ch chart.Charter, vals map[string]any)

Source from the content-addressed store, hash-verified

168
169// RunWithContext executes the upgrade on the given release with context.
170func (u *Upgrade) RunWithContext(ctx context.Context, name string, ch chart.Charter, vals map[string]any) (ri.Releaser, error) {
171 if err := u.cfg.KubeClient.IsReachable(); err != nil {
172 return nil, err
173 }
174
175 var chrt *chartv2.Chart
176 switch c := ch.(type) {
177 case *chartv2.Chart:
178 chrt = c
179 case chartv2.Chart:
180 chrt = &c
181 default:
182 return nil, errors.New("invalid chart apiVersion")
183 }
184
185 // Make sure wait is set if RollbackOnFailure. This makes it so
186 // the user doesn't have to specify both
187 if u.WaitStrategy == kube.HookOnlyStrategy && u.RollbackOnFailure {
188 u.WaitStrategy = kube.StatusWatcherStrategy
189 }
190
191 if err := chartutil.ValidateReleaseName(name); err != nil {
192 return nil, fmt.Errorf("release name is invalid: %s", name)
193 }
194
195 u.cfg.Logger().Debug("preparing upgrade", "name", name)
196 currentRelease, upgradedRelease, serverSideApply, err := u.prepareUpgrade(name, chrt, vals)
197 if err != nil {
198 return nil, err
199 }
200
201 u.cfg.Releases.MaxHistory = u.MaxHistory
202
203 u.cfg.Logger().Debug("performing update", "name", name)
204 res, err := u.performUpgrade(ctx, currentRelease, upgradedRelease, serverSideApply)
205 if err != nil {
206 return res, err
207 }
208
209 // Do not update for dry runs
210 if !isDryRun(u.DryRunStrategy) {
211 u.cfg.Logger().Debug("updating status for upgraded release", "name", name)
212 if err := u.cfg.Releases.Update(upgradedRelease); err != nil {
213 return res, err
214 }
215 }
216
217 return res, nil
218}
219
220// prepareUpgrade builds an upgraded release for an upgrade operation.
221func (u *Upgrade) prepareUpgrade(name string, chart *chartv2.Chart, vals map[string]any) (*release.Release, *release.Release, bool, error) {

Callers 2

RunMethod · 0.95
newUpgradeCmdFunction · 0.95

Calls 6

prepareUpgradeMethod · 0.95
performUpgradeMethod · 0.95
isDryRunFunction · 0.85
IsReachableMethod · 0.65
LoggerMethod · 0.65
UpdateMethod · 0.65

Tested by

no test coverage detected