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

Method Run

cmd/enter.go:93–173  ·  view source on GitHub ↗

Run executes the command logic

(f factory.Factory, args []string)

Source from the content-addressed store, hash-verified

91
92// Run executes the command logic
93func (cmd *EnterCmd) Run(f factory.Factory, args []string) error {
94 // Set config root
95 logger := f.GetLog()
96 configOptions := cmd.ToConfigOptions()
97 configLoader, err := f.NewConfigLoader(cmd.ConfigPath)
98 if err != nil {
99 return err
100 }
101 configExists, err := configLoader.SetDevSpaceRoot(logger)
102 if err != nil {
103 return err
104 }
105
106 // Get kubectl client
107 client, err := f.NewKubeClientFromContext(cmd.KubeContext, cmd.Namespace)
108 if err != nil {
109 return errors.Wrap(err, "new kube client")
110 }
111
112 // Load generated config if possible
113 if configExists {
114 localCache, err := configLoader.LoadLocalCache()
115 if err != nil {
116 return err
117 }
118
119 // If the current kube context or namespace is different from old,
120 // show warnings and reset kube client if necessary
121 client, err = kubectl.CheckKubeContext(client, localCache, cmd.NoWarn, cmd.SwitchContext, false, logger)
122 if err != nil {
123 return err
124 }
125 }
126
127 // create the context
128 ctx := devspacecontext.NewContext(context.Background(), nil, logger).WithKubeClient(client)
129
130 // Execute plugin hook
131 err = hook.ExecuteHooks(ctx, nil, "enter")
132 if err != nil {
133 return err
134 }
135
136 // get image selector if specified
137 imageSelector, err := getImageSelector(ctx, configLoader, configOptions, cmd.ImageSelector)
138 if err != nil {
139 return err
140 }
141
142 // Build params
143 selectorOptions := targetselector.NewOptionsFromFlags(cmd.Container, cmd.LabelSelector, imageSelector, cmd.Namespace, cmd.Pod).
144 WithPick(cmd.Pick).
145 WithWait(cmd.Wait).
146 WithQuestion("Which pod do you want to open the terminal for?")
147 if cmd.Wait {
148 selectorOptions = selectorOptions.WithContainerFilter(selector.FilterTerminatingContainers)
149 selectorOptions = selectorOptions.WithWaitingStrategy(targetselector.NewUntilNewestRunningWaitingStrategy(time.Second))
150 }

Callers 1

NewEnterCmdFunction · 0.95

Calls 15

SetDevSpaceRootMethod · 0.95
LoadLocalCacheMethod · 0.95
CheckKubeContextFunction · 0.92
ExecuteHooksFunction · 0.92
NewOptionsFromFlagsFunction · 0.92
StartTerminalFromCMDFunction · 0.92
NewTargetSelectorFunction · 0.92
getImageSelectorFunction · 0.85
defaultStdStreamsFunction · 0.85
ToConfigOptionsMethod · 0.80
WithQuestionMethod · 0.80

Tested by

no test coverage detected