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

Method Run

cmd/restart.go:73–192  ·  view source on GitHub ↗

Run executes the purge command logic

(f factory.Factory)

Source from the content-addressed store, hash-verified

71
72// Run executes the purge command logic
73func (cmd *RestartCmd) Run(f factory.Factory) error {
74 // Set config root
75 cmd.log = f.GetLog()
76 configOptions := cmd.ToConfigOptions()
77 configLoader, err := f.NewConfigLoader(cmd.ConfigPath)
78 if err != nil {
79 return err
80 }
81 configExists, err := configLoader.SetDevSpaceRoot(cmd.log)
82 if err != nil {
83 return err
84 } else if !configExists || cmd.Pod != "" || cmd.LabelSelector != "" || cmd.Pick {
85 client, err := f.NewKubeClientFromContext(cmd.KubeContext, cmd.Namespace)
86 if err != nil {
87 return errors.Wrap(err, "create kube client")
88 }
89
90 // Create context
91 ctx := devspacecontext.NewContext(context.Background(), nil, cmd.log).
92 WithKubeClient(client)
93
94 return restartContainer(ctx, targetselector.NewOptionsFromFlags(cmd.Container, cmd.LabelSelector, nil, cmd.Namespace, cmd.Pod).WithPick(cmd.Pick))
95 }
96
97 log.StartFileLogging()
98
99 client, err := f.NewKubeClientFromContext(cmd.KubeContext, cmd.Namespace)
100 if err != nil {
101 return errors.Wrap(err, "create kube client")
102 }
103
104 localCache, err := configLoader.LoadLocalCache()
105 if err != nil {
106 return err
107 }
108
109 // If the current kube context or namespace is different from old,
110 // show warnings and reset kube client if necessary
111 client, err = kubectl.CheckKubeContext(client, localCache, cmd.NoWarn, cmd.SwitchContext, false, cmd.log)
112 if err != nil {
113 return err
114 }
115
116 // Get config with adjusted cluster config
117 config, err := configLoader.LoadWithCache(context.Background(), localCache, client, configOptions, cmd.log)
118 if err != nil {
119 return err
120 }
121
122 // Create context
123 ctx := devspacecontext.NewContext(context.Background(), config.Variables(), cmd.log).
124 WithConfig(config).
125 WithKubeClient(client)
126
127 // Execute plugin hook
128 err = hook.ExecuteHooks(ctx, nil, "restart")
129 if err != nil {
130 return err

Callers 1

NewRestartCmdFunction · 0.95

Calls 15

SetDevSpaceRootMethod · 0.95
LoadLocalCacheMethod · 0.95
LoadWithCacheMethod · 0.95
NewOptionsFromFlagsFunction · 0.92
StartFileLoggingFunction · 0.92
CheckKubeContextFunction · 0.92
ExecuteHooksFunction · 0.92
EachDevContainerFunction · 0.92
restartContainerFunction · 0.85
ToConfigOptionsMethod · 0.80
WithPickMethod · 0.80
ApplyConfigParameterMethod · 0.80

Tested by

no test coverage detected