RunResetPods executes the reset pods command logic
(f factory.Factory, cobraCmd *cobra.Command, args []string)
| 54 | |
| 55 | // RunResetPods executes the reset pods command logic |
| 56 | func (cmd *podsCmd) RunResetPods(f factory.Factory, cobraCmd *cobra.Command, args []string) error { |
| 57 | // Set config root |
| 58 | cmd.log = f.GetLog() |
| 59 | configOptions := cmd.ToConfigOptions() |
| 60 | configLoader, err := f.NewConfigLoader(cmd.ConfigPath) |
| 61 | if err != nil { |
| 62 | return err |
| 63 | } |
| 64 | configExists, err := configLoader.SetDevSpaceRoot(cmd.log) |
| 65 | if err != nil { |
| 66 | return err |
| 67 | } |
| 68 | if !configExists { |
| 69 | return errors.New(message.ConfigNotFound) |
| 70 | } |
| 71 | |
| 72 | client, err := f.NewKubeClientFromContext(cmd.KubeContext, cmd.Namespace) |
| 73 | if err != nil { |
| 74 | return errors.Wrap(err, "create kube client") |
| 75 | } |
| 76 | |
| 77 | // Get config with adjusted cluster config |
| 78 | localCache, err := configLoader.LoadLocalCache() |
| 79 | if err != nil { |
| 80 | return err |
| 81 | } |
| 82 | |
| 83 | // If the current kube context or namespace is different from old, |
| 84 | // show warnings and reset kube client if necessary |
| 85 | client, err = kubectl.CheckKubeContext(client, localCache, cmd.NoWarn, cmd.SwitchContext, false, cmd.log) |
| 86 | if err != nil { |
| 87 | return err |
| 88 | } |
| 89 | |
| 90 | // Get config with adjusted cluster config |
| 91 | conf, err := configLoader.LoadWithCache(context.Background(), localCache, client, configOptions, cmd.log) |
| 92 | if err != nil { |
| 93 | return err |
| 94 | } |
| 95 | |
| 96 | // create devspace context |
| 97 | ctx := devspacecontext.NewContext(context.Background(), conf.Variables(), cmd.log). |
| 98 | WithConfig(conf). |
| 99 | WithKubeClient(client) |
| 100 | |
| 101 | // Resolve dependencies |
| 102 | dependencies, err := f.NewDependencyManager(ctx, configOptions).ResolveAll(ctx, dependency.ResolveOptions{}) |
| 103 | if err != nil { |
| 104 | cmd.log.Warnf("Error resolving dependencies: %v", err) |
| 105 | } |
| 106 | ctx = ctx.WithDependencies(dependencies) |
| 107 | |
| 108 | // reset the pods |
| 109 | ResetPods(ctx, true, cmd.Force) |
| 110 | return nil |
| 111 | } |
| 112 | |
| 113 | // ResetPods deletes the pods created by dev.replacePods |
no test coverage detected