MCPcopy Create free account
hub / github.com/eth-easl/dirigent / NewWorkerNode

Function NewWorkerNode

internal/worker_node/worker_node.go:70–128  ·  view source on GitHub ↗
(cpApi proto.CpiInterfaceClient, config config.WorkerNodeConfig, name ...string)

Source from the content-addressed store, hash-verified

68}
69
70func NewWorkerNode(cpApi proto.CpiInterfaceClient, config config.WorkerNodeConfig, name ...string) *WorkerNode {
71 hostName, err := os.Hostname()
72 if err != nil {
73 logrus.Warn("Error fetching host name.")
74 }
75
76 if len(name) > 0 {
77 hostName = name[0]
78 }
79
80 nodeName := fmt.Sprintf("%s-%d", hostName, rand.Int())
81
82 sandboxManager := managers.NewSandboxManager(nodeName)
83
84 if _, isRoot := isUserRoot(); !isRoot {
85 logrus.Fatal("Cannot create a worker daemon without sudo.")
86 }
87
88 var runtimeInterface sandbox.RuntimeInterface
89 switch config.CRIType {
90 case "containerd":
91 runtimeInterface = containerd.NewContainerdRuntime(
92 cpApi,
93 config,
94 sandboxManager,
95 )
96 case "firecracker":
97 runtimeInterface = firecracker.NewFirecrackerRuntime(
98 cpApi,
99 sandboxManager,
100 config.FirecrackerKernel,
101 config.FirecrackerFileSystem,
102 config.FirecrackerInternalIPPrefix,
103 config.FirecrackerExposedIPPrefix,
104 config.FirecrackerVMDebugMode,
105 config.FirecrackerUseSnapshots,
106 config.FirecrackerNetworkPoolSize,
107 )
108 case "scalability_test":
109 runtimeInterface = fake_snapshot.NewFakeSnapshotRuntime()
110 default:
111 logrus.Fatal("Unsupported sandbox type.")
112 }
113
114 if !runtimeInterface.ValidateHostConfig() {
115 logrus.Fatal("The host machine configuration is invalid or it does not support required features. Terminating worker daemon.")
116 }
117
118 workerNode := &WorkerNode{
119 cpApi: cpApi,
120 SandboxRuntime: runtimeInterface,
121
122 SandboxManager: sandboxManager,
123
124 Name: nodeName,
125 }
126
127 return workerNode

Callers 3

mainFunction · 0.92
mainFunction · 0.92
TestCreationWorkerNodeFunction · 0.70

Calls 7

ValidateHostConfigMethod · 0.95
NewSandboxManagerFunction · 0.92
NewContainerdRuntimeFunction · 0.92
NewFirecrackerRuntimeFunction · 0.92
NewFakeSnapshotRuntimeFunction · 0.92
isUserRootFunction · 0.85
IntMethod · 0.80

Tested by 1

TestCreationWorkerNodeFunction · 0.56