MCPcopy
hub / github.com/baetyl/baetyl / collect

Method collect

initz/activate_collector.go:33–94  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

31)
32
33func (active *Activate) collect() (string, error) {
34 var info interface{}
35 var ok bool
36 fs := active.cfg.Init.Active.Collector.Fingerprints
37 if len(fs) == 0 {
38 return "", nil
39 }
40 infos, err := active.ami.CollectNodeInfo()
41 if err != nil {
42 return "", errors.Trace(err)
43 }
44 mode := os.Getenv(context.KeyRunMode)
45 if mode == context.RunModeKube {
46 info, ok = infos[os.Getenv(kube.KubeNodeName)]
47 if !ok {
48 return "", errors.Trace(ErrGetMasterNodeInfo)
49 }
50 } else if mode == context.RunModeNative {
51 ho, herr := host.Info()
52 if herr != nil {
53 return "", errors.Trace(err)
54 }
55 info, ok = infos[ho.Hostname]
56 if !ok {
57 return "", errors.Trace(ErrGetMasterNodeInfo)
58 }
59 }
60
61 nodeInfo, ok := info.(*specV1.NodeInfo)
62 if !ok {
63 return "", errors.Trace(ErrGetMasterNodeInfo)
64 }
65 for _, f := range fs {
66 switch f.Proof {
67 case config.ProofInput:
68 if active.attrs != nil && active.attrs[f.Value] != "" {
69 // input get fv, sn is not empty
70 return active.attrs[f.Value], nil
71 } else {
72 // auto get fv, sn is empty
73 return nodeInfo.SystemUUID, nil
74 }
75 case config.ProofSN:
76 snByte, err := os.ReadFile(path.Join(defaultSNPath, f.Value))
77 if err != nil {
78 return "", errors.Trace(err)
79 }
80 return strings.TrimSpace(string(snByte)), nil
81 case config.ProofHostName:
82 return nodeInfo.Hostname, nil
83 case config.ProofMachineID:
84 return nodeInfo.MachineID, nil
85 case config.ProofSystemUUID:
86 return nodeInfo.SystemUUID, nil
87 case config.ProofBootID:
88 return nodeInfo.BootID, nil
89 default:
90 return "", errors.Trace(ErrProofTypeNotSupported)

Callers 3

activateMethod · 0.95
TestActivate_Err_AmiFunction · 0.80

Calls 1

CollectNodeInfoMethod · 0.65

Tested by 2

TestActivate_Err_AmiFunction · 0.64