RunLogs executes the functionality devspace logs
(f factory.Factory)
| 79 | |
| 80 | // RunLogs executes the functionality devspace logs |
| 81 | func (cmd *LogsCmd) RunLogs(f factory.Factory) error { |
| 82 | // Set config root |
| 83 | log := f.GetLog() |
| 84 | configOptions := cmd.ToConfigOptions() |
| 85 | configLoader, err := f.NewConfigLoader(cmd.ConfigPath) |
| 86 | if err != nil { |
| 87 | return err |
| 88 | } |
| 89 | configExists, err := configLoader.SetDevSpaceRoot(log) |
| 90 | if err != nil { |
| 91 | return err |
| 92 | } |
| 93 | |
| 94 | // Get kubectl client |
| 95 | client, err := f.NewKubeClientFromContext(cmd.KubeContext, cmd.Namespace) |
| 96 | if err != nil { |
| 97 | return errors.Wrap(err, "create kube client") |
| 98 | } |
| 99 | |
| 100 | // Load generated config if possible |
| 101 | if configExists { |
| 102 | localCache, err := configLoader.LoadLocalCache() |
| 103 | if err != nil { |
| 104 | return err |
| 105 | } |
| 106 | |
| 107 | // If the current kube context or namespace is different from old, |
| 108 | // show warnings and reset kube client if necessary |
| 109 | client, err = kubectl.CheckKubeContext(client, localCache, cmd.NoWarn, cmd.SwitchContext, false, log) |
| 110 | if err != nil { |
| 111 | return err |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | // create the context |
| 116 | ctx := devspacecontext.NewContext(context.Background(), nil, log).WithKubeClient(client) |
| 117 | |
| 118 | // Execute plugin hook |
| 119 | err = hook.ExecuteHooks(ctx, nil, "logs") |
| 120 | if err != nil { |
| 121 | return err |
| 122 | } |
| 123 | |
| 124 | // get image selector if specified |
| 125 | imageSelector, err := getImageSelector(ctx, configLoader, configOptions, cmd.ImageSelector) |
| 126 | if err != nil { |
| 127 | return err |
| 128 | } |
| 129 | |
| 130 | // Build options |
| 131 | options := targetselector.NewOptionsFromFlags(cmd.Container, cmd.LabelSelector, imageSelector, cmd.Namespace, cmd.Pod). |
| 132 | WithPick(cmd.Pick). |
| 133 | WithWait(cmd.Wait). |
| 134 | WithContainerFilter(selector.FilterTerminatingContainers) |
| 135 | if cmd.Wait { |
| 136 | options = options.WithWaitingStrategy(targetselector.NewUntilNotWaitingStrategy(time.Second * 2)) |
| 137 | } |
| 138 |
no test coverage detected