Run executes the command logic
(f factory.Factory, args []string)
| 91 | |
| 92 | // Run executes the command logic |
| 93 | func (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 | } |
no test coverage detected