MCPcopy Index your code
hub / github.com/devspace-sh/devspace / Purge

Method Purge

pkg/devspace/deploy/deploy.go:257–375  ·  view source on GitHub ↗

Purge removes all deployments or a set of deployments from the cluster

(ctx devspacecontext.Context, deployments []string, options *PurgeOptions)

Source from the content-addressed store, hash-verified

255
256// Purge removes all deployments or a set of deployments from the cluster
257func (c *controller) Purge(ctx devspacecontext.Context, deployments []string, options *PurgeOptions) error {
258 if options == nil {
259 options = &PurgeOptions{}
260 }
261 if deployments != nil && len(deployments) == 0 {
262 deployments = nil
263 }
264
265 // Execute before deployments purge hook
266 err := hook.ExecuteHooks(ctx, nil, "before:purge")
267 if err != nil {
268 return err
269 }
270
271 // Check if root name is defined
272 rootName, ok := values.RootNameFrom(ctx.Context())
273 if !ok {
274 options.ForcePurge = true
275 }
276
277 // Reverse them
278 deploymentCaches := ctx.Config().RemoteCache().ListDeployments()
279 for i := len(deploymentCaches) - 1; i >= 0; i-- {
280 // Deployment cache
281 deploymentCache := deploymentCaches[i]
282
283 // Check if we should skip deleting deployment
284 if deployments != nil {
285 found := false
286 for _, value := range deployments {
287 if value == deploymentCache.Name {
288 found = true
289 break
290 }
291 }
292
293 if !found {
294 continue
295 }
296 }
297 ctx := ctx.WithLogger(ctx.Log().WithPrefix("purge:" + deploymentCache.Name + " "))
298
299 // Execute before deployment purge hook
300 err = hook.ExecuteHooks(ctx, map[string]interface{}{
301 "DEPLOY_NAME": deploymentCache.Name,
302 "DEPLOY_CONFIG": deploymentCache,
303 }, hook.EventsForSingle("before:purge", deploymentCache.Name).With("deploy.beforePurge")...)
304 if err != nil {
305 return err
306 }
307
308 // Check if we should skip deletion
309 if !options.ForcePurge && len(deploymentCache.Projects) > 0 && (len(deploymentCache.Projects) > 1 || deploymentCache.Projects[0] != rootName) {
310 newProjects := []string{}
311 for _, p := range deploymentCache.Projects {
312 if p == rootName {
313 continue
314 }

Callers

nothing calls this directly

Calls 15

ExecuteHooksFunction · 0.92
RootNameFromFunction · 0.92
EventsForSingleFunction · 0.92
WithMethod · 0.80
ContextMethod · 0.65
ListDeploymentsMethod · 0.65
RemoteCacheMethod · 0.65
ConfigMethod · 0.65
WithLoggerMethod · 0.65
WithPrefixMethod · 0.65
LogMethod · 0.65
SetDeploymentMethod · 0.65

Tested by

no test coverage detected