MCPcopy Create free account
hub / github.com/devspace-sh/devspace / RunCleanupImages

Method RunCleanupImages

cmd/cleanup/images.go:43–132  ·  view source on GitHub ↗

RunCleanupImages executes the cleanup images command logic

(f factory.Factory, cobraCmd *cobra.Command, args []string)

Source from the content-addressed store, hash-verified

41
42// RunCleanupImages executes the cleanup images command logic
43func (cmd *imagesCmd) RunCleanupImages(f factory.Factory, cobraCmd *cobra.Command, args []string) error {
44 // Set config root
45 ctx := context.Background()
46 log := f.GetLog()
47
48 configLoader, err := f.NewConfigLoader(cmd.ConfigPath)
49 if err != nil {
50 return err
51 }
52
53 configExists, err := configLoader.SetDevSpaceRoot(log)
54 if err != nil {
55 return err
56 }
57
58 if !configExists {
59 return errors.New(message.ConfigNotFound)
60 }
61
62 kubeClient, err := f.NewKubeClientFromContext(cmd.KubeContext, cmd.Namespace)
63 if err != nil {
64 return errors.Wrap(err, "new kube client")
65 }
66
67 // Create docker client
68 client, err := docker.NewClientWithMinikube(ctx, kubeClient, true, log)
69 if err != nil {
70 return err
71 }
72
73 // Load config
74 configInterface, err := configLoader.Load(ctx, kubeClient, cmd.ToConfigOptions(), log)
75 if err != nil {
76 return err
77 }
78
79 config := configInterface.Config()
80 if len(config.Images) == 0 {
81 log.Done("No images found in config to delete")
82 return nil
83 }
84
85 _, err = client.Ping(ctx)
86 if err != nil {
87 return errors.Errorf("Docker seems to be not running: %v", err)
88 }
89
90 // Delete all images
91 for _, imageConfig := range config.Images {
92 log.Info("Deleting local image " + imageConfig.Image + "...")
93
94 response, err := client.DeleteImageByName(ctx, imageConfig.Image, log)
95 if err != nil {
96 return err
97 }
98
99 for _, t := range response {
100 if t.Deleted != "" {

Callers 1

newImagesCmdFunction · 0.95

Calls 15

SetDevSpaceRootMethod · 0.95
LoadMethod · 0.95
NewClientWithMinikubeFunction · 0.92
ToConfigOptionsMethod · 0.80
GetLogMethod · 0.65
NewConfigLoaderMethod · 0.65
ConfigMethod · 0.65
DoneMethod · 0.65
PingMethod · 0.65
DeleteImageByNameMethod · 0.65
DeleteImageByFilterMethod · 0.65

Tested by

no test coverage detected