MCPcopy
hub / github.com/kubesphere/kubekey / ModuleSetup

Function ModuleSetup

pkg/modules/setup/setup.go:30–57  ·  view source on GitHub ↗

* Module Setup This module is used to set up the connection to a remote host and gather facts about it. It performs the following operations: 1. Establishes a connection to the specified host using the appropriate connector 2. If the connector supports fact gathering (implements GatherFacts interfa

(ctx context.Context, opts internal.ExecOptions)

Source from the content-addressed store, hash-verified

28// ModuleSetup establishes a connection to a remote host and gathers facts about it.
29// It returns StdoutSuccess if successful, or an error message if any step fails.
30func ModuleSetup(ctx context.Context, opts internal.ExecOptions) (string, string, error) {
31 ha, err := opts.GetAllVariables()
32 if err != nil {
33 return internal.StdoutFailed, internal.StderrGetHostVariable, err
34 }
35 args := variable.Extension2Variables(opts.Args)
36 if force, err := variable.BoolVar(ha, args, "force"); err == nil && *force {
37 ctx = context.WithValue(ctx, _const.CTXSetupForceKey, true)
38 }
39 // get connector
40 conn, err := opts.GetConnector(ctx)
41 if err != nil {
42 return internal.StdoutFailed, internal.StderrGetConnector, nil
43 }
44 defer conn.Close(ctx)
45
46 if gf, ok := conn.(connector.GatherFacts); ok {
47 remoteInfo, err := gf.HostInfo(ctx)
48 if err != nil {
49 return internal.StdoutFailed, "failed to get host info", err
50 }
51 if err := opts.Merge(variable.MergeRemoteVariable(remoteInfo, opts.Host)); err != nil {
52 return internal.StdoutFailed, "failed to merge setup variable", err
53 }
54 }
55
56 return internal.StdoutSuccess, "", nil
57}

Callers

nothing calls this directly

Calls 7

Extension2VariablesFunction · 0.92
BoolVarFunction · 0.92
GetAllVariablesMethod · 0.80
GetConnectorMethod · 0.80
CloseMethod · 0.65
HostInfoMethod · 0.65
MergeMethod · 0.65

Tested by

no test coverage detected