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

Method Run

cmd/attach.go:64–121  ·  view source on GitHub ↗

Run executes the command logic

(f factory.Factory, cobraCmd *cobra.Command, args []string)

Source from the content-addressed store, hash-verified

62
63// Run executes the command logic
64func (cmd *AttachCmd) Run(f factory.Factory, cobraCmd *cobra.Command, args []string) error {
65 // Set config root
66 log := f.GetLog()
67 configOptions := cmd.ToConfigOptions()
68 configLoader, err := f.NewConfigLoader(cmd.ConfigPath)
69 if err != nil {
70 return err
71 }
72 configExists, err := configLoader.SetDevSpaceRoot(log)
73 if err != nil {
74 return err
75 }
76
77 // Get kubectl client
78 client, err := f.NewKubeClientFromContext(cmd.KubeContext, cmd.Namespace)
79 if err != nil {
80 return errors.Wrap(err, "new kube client")
81 }
82
83 // Load generated config if possible
84 if configExists {
85 localCache, err := configLoader.LoadLocalCache()
86 if err != nil {
87 return err
88 }
89
90 // If the current kube context or namespace is different from old,
91 // show warnings and reset kube client if necessary
92 client, err = kubectl.CheckKubeContext(client, localCache, cmd.NoWarn, cmd.SwitchContext, false, log)
93 if err != nil {
94 return err
95 }
96 }
97
98 // create the context
99 ctx := devspacecontext.NewContext(context.Background(), nil, log).WithKubeClient(client)
100
101 // Execute plugin hook
102 err = hook.ExecuteHooks(ctx, nil, "attach")
103 if err != nil {
104 return err
105 }
106
107 // get image selector if specified
108 imageSelector, err := getImageSelector(ctx, configLoader, configOptions, cmd.ImageSelector)
109 if err != nil {
110 return err
111 }
112
113 // Build params
114 options := targetselector.NewOptionsFromFlags(cmd.Container, cmd.LabelSelector, imageSelector, cmd.Namespace, cmd.Pod).
115 WithPick(cmd.Pick).
116 WithWait(false).
117 WithQuestion("Which pod do you want to attach to?")
118
119 // Start attach
120 return attach.StartAttachFromCMD(ctx, targetselector.NewTargetSelector(options))
121}

Callers 1

NewAttachCmdFunction · 0.95

Calls 15

SetDevSpaceRootMethod · 0.95
LoadLocalCacheMethod · 0.95
CheckKubeContextFunction · 0.92
ExecuteHooksFunction · 0.92
NewOptionsFromFlagsFunction · 0.92
StartAttachFromCMDFunction · 0.92
NewTargetSelectorFunction · 0.92
getImageSelectorFunction · 0.85
ToConfigOptionsMethod · 0.80
WithQuestionMethod · 0.80
WithWaitMethod · 0.80
WithPickMethod · 0.80

Tested by

no test coverage detected